84 lines
2.8 KiB
PHP
84 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace app\action;
|
||
|
||
use Exception;
|
||
use stdClass;
|
||
use libs\db\Db;
|
||
|
||
class GetTrayInfo
|
||
{
|
||
public function execute($post)
|
||
{
|
||
// 验证数据
|
||
$param = check_valid($post['action'], [
|
||
['workingsubclass', 'string', '工序单元'],
|
||
['device_code', 'string', '设备编码'],
|
||
['tray', 'string', '托盘号']
|
||
], $post['param']);
|
||
|
||
try {
|
||
$sql = sprintf(
|
||
"SELECT tray,lot,batch,subbatch
|
||
FROM hf_mes_production_tray_map
|
||
WHERE tray='%s' AND active=1 LIMIT 1;",
|
||
$param['tray']
|
||
);
|
||
$ret = Db::fetch($sql);
|
||
if (empty($ret)) {
|
||
throw new Exception("托盘[{$param['tray']}]不是激活状态");
|
||
}
|
||
$batch = $ret['batch'];
|
||
|
||
$sql = sprintf(
|
||
"SELECT battery_id,active,class,classname,process_code,next_process_code
|
||
FROM \"%s\"
|
||
WHERE tray='%s' AND lot='%s' ORDER BY id ASC;",
|
||
config('app.bkv_prefix') . $ret['subbatch'],
|
||
$ret['tray'],
|
||
$ret['lot']
|
||
);
|
||
$ret = Db::fetchAll($sql);
|
||
if (empty($ret)) {
|
||
throw new Exception("托盘[{$param['tray']}]的电池数据不存在[bkv]");
|
||
}
|
||
} catch (Exception $e) {
|
||
throw new Exception($e->getMessage());
|
||
}
|
||
|
||
$obj = new stdClass();
|
||
$obj->batch = $batch;
|
||
$obj->tray = $param['tray'];
|
||
$obj->battery_ids = array_map(function ($value) {
|
||
// 如果为空,统一返回字符串空
|
||
return empty($value) ? '' : $value;
|
||
}, array_column($ret, 'battery_id'));
|
||
|
||
$obj->active = array_map(function ($value) {
|
||
// 如果为空,统一返回整数0
|
||
return empty($value) ? 0 : $value;
|
||
}, array_column($ret, 'active'));
|
||
|
||
$obj->class = array_map(function ($value) {
|
||
// 如果为空,统一返回字符串空
|
||
return empty($value) ? '' : $value;
|
||
}, array_column($ret, 'class'));
|
||
|
||
$obj->classname = array_map(function ($value) {
|
||
// 如果为空,统一返回字符串空
|
||
return empty($value) ? '' : $value;
|
||
}, array_column($ret, 'classname'));
|
||
|
||
$obj->process_code = array_map(function ($value) {
|
||
// 如果为空,统一返回字符串空
|
||
return empty($value) ? '' : $value;
|
||
}, array_column($ret, 'process_code'));
|
||
|
||
$obj->next_process_code = array_map(function ($value) {
|
||
// 如果为空,统一返回字符串空
|
||
return empty($value) ? '' : $value;
|
||
}, array_column($ret, 'next_process_code'));
|
||
return $obj;
|
||
}
|
||
}
|