88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace app\action;
|
|
|
|
use Exception;
|
|
use stdClass;
|
|
use libs\db\Db;
|
|
|
|
class GetBatteryInfo
|
|
{
|
|
public function execute($post)
|
|
{
|
|
// 验证数据
|
|
$param = check_valid($post['action'], [
|
|
['workingsubclass', 'string', '工序单元'],
|
|
['device_code', 'string', '设备编码'],
|
|
['battery_ids', 'array', '电池条码数组']
|
|
], $post['param']);
|
|
|
|
$battery_ids = $param['battery_ids'];
|
|
|
|
$batteryItems = [];
|
|
|
|
try {
|
|
foreach ($battery_ids as $k => $battery_id) {
|
|
// 判断电池是否为空
|
|
if (empty($battery_id)) {
|
|
throw new Exception("电池条码数组第[{$k}]位置的电池条码不能是:[0, '0', '', null, NAN]等,请上传电池条码");
|
|
}
|
|
|
|
$sql = sprintf(
|
|
"SELECT tray,lot,batch,subbatch
|
|
FROM hf_mes_production_battery_map
|
|
WHERE battery_id='%s' ORDER BY id DESC LIMIT 1;",
|
|
$battery_id
|
|
);
|
|
$ret = Db::fetch($sql);
|
|
|
|
list($tray, $lot, $batch, $subbatch) = [
|
|
$ret['tray'],
|
|
$ret['lot'],
|
|
$ret['batch'],
|
|
$ret['subbatch']
|
|
];
|
|
|
|
$sql = sprintf(
|
|
"SELECT flow_id
|
|
FROM hf_mes_production_planning_management_batch
|
|
WHERE batch='%s' LIMIT 1;",
|
|
$batch
|
|
);
|
|
$ret = Db::fetch($sql);
|
|
$flow_id = $ret['flow_id'];
|
|
|
|
$sql = sprintf(
|
|
"SELECT class,classname,next_process_code
|
|
FROM \"%s\"
|
|
WHERE battery_id='%s' AND tray='%s' AND lot='%s' LIMIT 1;",
|
|
config('app.bkv_prefix') . $subbatch,
|
|
$battery_id,
|
|
$tray,
|
|
$lot
|
|
);
|
|
$ret = Db::fetch($sql);
|
|
|
|
// 判断当前工序单元与下一个工序单元是否一致
|
|
$current_process_code = "{$flow_id}_{$param['workingsubclass']}";
|
|
if ($current_process_code != $ret['next_process_code']) {
|
|
throw new Exception("电池条码[{$battery_id}]当前工序[{$current_process_code}]与系统当前工序[{$ret['next_process_code']}]不一致");
|
|
}
|
|
|
|
$batteryItems[$k]['class'] = $ret['class'] ?? '';
|
|
$batteryItems[$k]['classname'] = $ret['classname'] ?? '';
|
|
}
|
|
} catch (Exception $e) {
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
|
|
$obj = new stdClass();
|
|
|
|
$obj->battery_ids = $battery_ids;
|
|
$obj->class = array_column($batteryItems, 'class');
|
|
$obj->classname = array_column($batteryItems, 'classname');
|
|
|
|
return $obj;
|
|
}
|
|
}
|