68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\action;
|
||
|
|
||
|
use Exception;
|
||
|
use stdClass;
|
||
|
use libs\db\Db;
|
||
|
|
||
|
class GetTrayProcessSetting
|
||
|
{
|
||
|
public function execute($post)
|
||
|
{
|
||
|
// 验证数据
|
||
|
$param = check_valid($post['action'], [
|
||
|
['workingsubclass', 'string', '工序单元'],
|
||
|
['device_code', 'string', '设备编码'],
|
||
|
['tray', 'string', '托盘号']
|
||
|
], $post['param']);
|
||
|
|
||
|
try {
|
||
|
$sql = sprintf(
|
||
|
"SELECT a.next_process_code,b.flow_id
|
||
|
FROM hf_mes_production_tray_map AS a
|
||
|
INNER JOIN hf_mes_production_planning_management_batch AS b ON b.batch = a.batch
|
||
|
WHERE a.tray='%s' AND a.active=1 LIMIT 1;",
|
||
|
$param['tray']
|
||
|
);
|
||
|
$ret = Db::fetch($sql);
|
||
|
if (empty($ret)) {
|
||
|
throw new Exception("托盘[{$param['tray']}]不是激活状态");
|
||
|
}
|
||
|
|
||
|
// 判断当前工序单元与下一个工序单元是否一致
|
||
|
$current_process_code = "{$ret['flow_id']}_{$param['workingsubclass']}";
|
||
|
if ($ret['next_process_code'] !== $current_process_code) {
|
||
|
throw new Exception("设备当前工序[{$current_process_code}]与系统当前工序[{$ret['next_process_code']}]不一致");
|
||
|
}
|
||
|
|
||
|
// 获取setting
|
||
|
$sql = sprintf(
|
||
|
"SELECT setting
|
||
|
FROM hf_mes_technology_process
|
||
|
WHERE code='%s' LIMIT 1;",
|
||
|
$current_process_code
|
||
|
);
|
||
|
$ret = Db::fetch($sql);
|
||
|
|
||
|
if (empty($ret)) {
|
||
|
throw new Exception("托盘[{$param['tray']}]不存在工序设定值,请检查");
|
||
|
}
|
||
|
if (empty($ret['setting'])) {
|
||
|
throw new Exception("托盘[{$param['tray']}]不存在工序设定值,请检查[setting]");
|
||
|
}
|
||
|
|
||
|
$obj = $ret['setting'] ? json_decode($ret['setting'], true) : new stdClass();
|
||
|
|
||
|
$obj['process_code'] = $current_process_code;
|
||
|
|
||
|
$obj["ntp"] = date("Y-m-d H:i:s");
|
||
|
|
||
|
} catch (Exception $e) {
|
||
|
throw new Exception($e->getMessage());
|
||
|
}
|
||
|
|
||
|
return $obj;
|
||
|
}
|
||
|
}
|