SCTMES_V5/mes_in_sct/app/action/SetTrayProcessStart.php

92 lines
3.2 KiB
PHP
Raw Permalink Normal View History

2025-06-14 18:55:09 +08:00
<?php
namespace app\action;
use Exception;
use libs\db\Db;
class SetTrayProcessStart
{
public function execute($post)
{
// 验证数据
$param = check_valid($post['action'], [
['tray', 'string', '托盘号'],
['workstation', 'string', '工作站'],
['workingsubclass', 'string', '工序单元'],
['device_code', 'string', '设备编码']
], $post['param']);
$workstation = $param['workstation']; // 获取传入的工作站参数
try {
$sql = sprintf(
"SELECT a.tray, a.lot, a.batch, a.subbatch, a.next_process_code, a.date_log,
b.flow_id, g.code AS next_workstation
FROM hf_mes_production_tray_map AS a
INNER JOIN hf_mes_production_planning_management_batch AS b
ON b.batch = a.batch
INNER JOIN hf_mes_technology_process c
ON c.code = a.next_process_code
INNER JOIN hf_mes_process_workingsubclass e
ON e.id = c.workingsubclass_id
INNER JOIN hf_mes_device_category g
ON g.id = e.device_category_id
WHERE a.tray='%s' AND a.active=1
LIMIT 1;",
$param['tray']
);
$ret = Db::fetch($sql);
if (empty($ret)) {
throw new Exception("托盘[{$param['tray']}]不是激活状态");
}
$batch = $ret['batch'];
$subbatch = $ret['subbatch'];
// 追加工作站判断逻辑
if ($workstation !== $ret['next_workstation']) {
throw new Exception("托盘【{$param['tray']}】:不在本工作站异常!,当前设备工作站为[{$workstation}],托盘工作站在[{$ret['next_workstation']}]");
}
$current_process_code = "{$ret['flow_id']}_{$param['workingsubclass']}";
$date = date('Y-m-d H:i:s');
// BKV修改开始时间
Db::update(
config('app.bkv_prefix') . $ret['subbatch'],
[
"{$current_process_code}.START_TIME" => $date
],
[
'tray' => $ret['tray'],
'lot' => $ret['lot'],
'active' => 1
]
);
// 修改tray_map表的date_log
$date_log = json_decode($ret['date_log'], true);
foreach ($date_log as $k => $v) {
if ($v['flow_process_code'] == $current_process_code) {
$date_log[$k]['beginTime'] = $date;
$date_log[$k]['device_code'] = $param['device_code'];
break;
}
}
Db::update(
'hf_mes_production_tray_map',
[
'date_log' => json_encode($date_log, JSON_UNESCAPED_UNICODE)
],
[
'tray' => $ret['tray'],
'lot' => $ret['lot'],
'active' => 1
]
);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
return '';
}
}