49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\action;
|
||
|
|
||
|
use Exception;
|
||
|
use libs\db\Db;
|
||
|
|
||
|
class SetDeviceThisTray
|
||
|
{
|
||
|
public function execute($post)
|
||
|
{
|
||
|
// 验证数据
|
||
|
$param = check_valid($post['action'], [
|
||
|
['tray', 'string', '托盘号'],
|
||
|
['device_code', 'string', '设备号'],
|
||
|
], $post['param']);
|
||
|
list($tray, $device_code) = [$param['tray'], $param['device_code']];
|
||
|
try {
|
||
|
$sql = "SELECT id,status from hf_mes_device WHERE code = '$device_code' LIMIT 1;";
|
||
|
$ret = Db::fetch($sql);
|
||
|
|
||
|
if (empty($ret)) {
|
||
|
throw new Exception("不存在设备号【{$device_code}】,不允许入库托盘");
|
||
|
}
|
||
|
if ($ret['status'] != 'IDLE') {
|
||
|
throw new Exception("设备【{$device_code}】非【待料】状态,不允许入库托盘");
|
||
|
}
|
||
|
|
||
|
$sql = "SELECT id FROM hf_mes_production_tray_map WHERE tray='$tray' AND active=1 LIMIT 1";
|
||
|
$ret = Db::fetch($sql);
|
||
|
if (empty($ret)) {
|
||
|
throw new Exception("托盘【{$tray}】处于【未激活】状态,不允许入库托盘");
|
||
|
}
|
||
|
|
||
|
$date = date('Y-m-d H:i:s');
|
||
|
$sql = "INSERT INTO hf_mes_device_this_tray (code, tray, finish, create_date) VALUES ('{$param['device_code']}', '{$param['tray']}', 0, '$date');";
|
||
|
$ret = Db::query($sql);
|
||
|
|
||
|
if ($ret === NULL) {
|
||
|
throw new Exception("写入托盘【{$tray}】到库位记录表失败!");
|
||
|
}
|
||
|
|
||
|
} catch (Exception $e) {
|
||
|
throw new Exception($e->getMessage());
|
||
|
}
|
||
|
return '';
|
||
|
}
|
||
|
}
|