SCTMES_V5/mes_in_sct/app/action/GetBatteryProcessSetting.php

120 lines
3.7 KiB
PHP
Raw Normal View History

2025-06-14 18:55:09 +08:00
<?php
namespace app\action;
use Exception;
use stdClass;
use libs\db\Db;
class GetBatteryProcessSetting
{
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 = [];
$battery_id = $battery_ids[0];
// 判断电池是否为空
if (empty($battery_id)) {
throw new Exception("电池条码数组第[1]位置的电池条码不能是:[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);
if (is_null($ret)) {
throw new Exception("电池条码[{$battery_id}]不存在");
}
list($tray, $lot, $batch, $subbatch) = [
$ret['tray'],
$ret['lot'],
$ret['batch'],
$ret['subbatch']
];
$sql = sprintf(
"SELECT a.flow_id , b.process , b.name as flow_name
FROM hf_mes_production_planning_management_batch a
INNER JOIN hf_mes_technology_flow b ON b.id = a.flow_id
WHERE batch='%s' LIMIT 1;",
$batch
);
$ret = Db::fetch($sql);
$flow_id = $ret['flow_id'];
$flow_name = $ret['flow_name'];
$process_obj = json_decode($ret['process']);
if (is_null($process_obj)) {
throw new Exception("{$flow_name} 工序流程setting解析为空");
}
$sql = sprintf(
"SELECT class,classname,next_process_code,active
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);
// 判断电池是否没有激活
if ($ret['active'] != 1) {
throw new Exception("电池条码{$battery_id}:是未激活电池");
}
// 判断当前工序单元与下一个工序单元是否一致
$current_process_code = "{$flow_id}_{$param['workingsubclass']}";
if ($current_process_code != $ret['next_process_code']) {
throw new Exception("工序上传校验失败[{$current_process_code}],电池[{$battery_id}]当前MES工序[{$ret['next_process_code']}]");
}
$last_process_idx = -1;
foreach($process_obj as $val){
if($val[2] == $current_process_code){
$last_process_idx = $val[0];
}
}
$sql = sprintf(
"SELECT a.setting, b.code as workingsubclass , c.code as workingclass
FROM hf_mes_technology_process a
INNER JOIN hf_mes_process_workingsubclass b ON a.workingsubclass_id = b.id
INNER JOIN hf_mes_device_category c ON b.device_category_id = c.id
WHERE a.code='%s' LIMIT 1;",
$current_process_code
);
$ret = Db::fetch($sql);
$obj = $ret['setting'] ? json_decode($ret['setting'], true) : new stdClass();
$obj["batch"] = $batch;
$obj["process_idx"] = $last_process_idx;
$obj["process_code"] = $current_process_code;
$obj["workingclass"] = $ret['workingclass'];
$obj["workingsubclass"] = $ret['workingsubclass'];
$obj["ntp"] = date('Y-m-d H:i:s');
return $obj;
}
}