SCTMES_V5/mes_in_sct/app/action/SetBatteryProcessStart.php

88 lines
3.0 KiB
PHP
Raw Normal View History

2025-06-14 18:55:09 +08:00
<?php
namespace app\action;
use Exception;
use libs\db\Db;
class SetBatteryProcessStart
{
public function execute($post)
{
// 验证数据
$param = check_valid($post['action'], [
['workingsubclass', 'string', '工序单元'],
['device_code', 'string', '设备编码'],
['battery_ids', 'array', '电池条码数组']
], $post['param']);
$battery_ids = $param['battery_ids'];
$date = date('Y-m-d H:i:s');
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']}]不一致");
}
$sql = sprintf(
"UPDATE \"%s\" SET \"{$current_process_code}.START_TIME\"='%s'
WHERE battery_id='%s' AND tray='%s' AND lot='%s';",
config('app.bkv_prefix') . $subbatch,
$date,
$battery_id,
$tray,
$lot
);
Db::query($sql);
}
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
return '';
}
}