SCTMES_V5/mes_in_sct/app/action/SetTrayInactivity.php
2025-06-14 18:55:09 +08:00

50 lines
1.7 KiB
PHP

<?php
namespace app\action;
use Exception;
use libs\db\Db;
class SetTrayInactivity
{
public function execute($post)
{
// 验证数据
$param = check_valid($post['action'], [
['tray', 'string', '托盘条码']
], $post['param']);
// 开启事务
Db::beginTrans();
try {
$tray = $param['tray'];
$sql = "SELECT batch,subbatch,lot FROM hf_mes_production_tray_map WHERE tray='$tray' AND active=1";
$ret = Db::fetch($sql);
if (empty($ret)) {
throw new Exception("该托盘[$tray]没有激活,无法进行托盘停止操作!");
}
$batch = $ret['batch'];
$subbatch = $ret['subbatch'];
$lot = $ret['lot'];
$updateTime = date('Y-m-d H:i:s');
$sql = "UPDATE hf_mes_production_tray_map
SET active=0, update_time='$updateTime'
WHERE batch='$batch' AND tray='$tray' AND lot='$lot' AND active=1";
$ret = Db::query($sql);
if ($ret === NULL) {
throw new Exception("Record Update failed:[hf_mes_production_tray_map]");
}
$sql = "UPDATE \"hf_mes_tmp_bkv_$subbatch\" SET active=0 WHERE tray='$tray' AND lot='$lot' AND active=1";
$ret = Db::query($sql);
if ($ret === NULL) {
throw new Exception("Record Update failed:[hf_mes_tmp_bkv_$subbatch]");
}
} catch (Exception $e) {
//回滚
Db::rollBackTrans();
throw new Exception($e->getMessage());
}
Db::commitTrans();
return '';
}
}