|
|
@@ -1125,7 +1125,7 @@ class WorkOrderSpotCheck extends Api{
|
|
|
->where('c.工序名称', $params['code'])
|
|
|
->where('c.sczl_jtbh', $params['sys_sbID'])
|
|
|
->whereNull('c.mod_rq') // 查询未删除数据
|
|
|
- ->order('UniqId desc')
|
|
|
+ ->order('UniqId desc')
|
|
|
->select();
|
|
|
// 初始化返回数据的结构
|
|
|
$reslist = [];
|
|
|
@@ -2592,94 +2592,130 @@ class WorkOrderSpotCheck extends Api{
|
|
|
// 将 $param['UniqId'] 的值按逗号分割成数组
|
|
|
$printIdArray = explode(',', $param['UniqId']);
|
|
|
|
|
|
- // 初始化失败计数器
|
|
|
- $failureCount = 0;
|
|
|
+ if (isset($param['sys_id']) && strpos($param['sys_id'], '裁剪') !== false) {
|
|
|
+ // 初始化失败计数器
|
|
|
+ $failureCount = 0;
|
|
|
|
|
|
- foreach ($printIdArray as $uniqId) {
|
|
|
- // 根据 UniqId 查询 设备_产量计酬 表中的订单编号、尺码和数量
|
|
|
- $result = \db('设备_产量计酬')->where('UniqId', $uniqId)
|
|
|
- ->field('订单编号,尺码,数量')
|
|
|
- ->find();
|
|
|
+ foreach ($printIdArray as $uniqId) {
|
|
|
+
|
|
|
+ // 根据 UniqId 查询 设备_产量计酬 表中的订单编号、尺码和数量
|
|
|
+ $result = \db('设备_产量计酬')->where('UniqId', $uniqId)
|
|
|
+ ->field('子订单编号,订单编号,尺码,数量,sczl_bh')
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ // 根据订单编号查询工单_印件资料表,并排除有修改日期的记录
|
|
|
+ $yresult = \db('工单_印件资料')->where('子订单编号', $result['子订单编号'])
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ // 检查是否找到结果
|
|
|
+ if (!$result) {
|
|
|
+ $failureCount++;
|
|
|
+ continue; // 跳过当前循环,处理下一个 UniqId
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取 result 中的尺码和数量
|
|
|
+ $size = $result['尺码'];
|
|
|
+ $quantity = $result['数量'];
|
|
|
+
|
|
|
+ // 遍历 yresult 中的 cm1 到 cm10 字段,查找匹配的尺码
|
|
|
+ for ($i = 1; $i <= 10; $i++) {
|
|
|
+ $cmField = 'cm' . $i;
|
|
|
+ $scslField = 'scsl' . $i;
|
|
|
+
|
|
|
+ // 检查 yresult 中是否存在对应的尺码字段,且值等于 result 中的尺码
|
|
|
+ if (isset($yresult[$cmField]) && $yresult[$cmField] === $size) {
|
|
|
+ // 找到对应 scsl 字段并进行数量减法
|
|
|
+ if (isset($yresult[$scslField])) {
|
|
|
+ $yresult[$scslField] -= $quantity;
|
|
|
+
|
|
|
+ // 防止数量变成负数
|
|
|
+ if ($yresult[$scslField] < 0) {
|
|
|
+ $yresult[$scslField] = 0;
|
|
|
+ }
|
|
|
|
|
|
- // 检查是否找到结果
|
|
|
- if (!$result) {
|
|
|
- $failureCount++;
|
|
|
- continue; // 跳过当前循环,处理下一个 UniqId
|
|
|
+ // 清除更新后的数量字段,避免旧的值影响
|
|
|
+ $updateData[$scslField] = $yresult[$scslField];
|
|
|
+ }
|
|
|
+ break; // 找到并处理后,跳出循环
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算 scsl1 到 scsl10 的总和并更新 sctotal 字段
|
|
|
+ $newTotal = 0;
|
|
|
+ for ($i = 1; $i <= 10; $i++) {
|
|
|
+ $scslField = 'scsl' . $i;
|
|
|
+ if (isset($yresult[$scslField])) {
|
|
|
+ $newTotal += $yresult[$scslField];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新工单_印件资料表的 sctotal 字段
|
|
|
+ \db('工单_印件资料')
|
|
|
+ ->where('子订单编号', $result['子订单编号'])
|
|
|
+ ->update(['sctotal' => $newTotal] + $updateData);
|
|
|
+
|
|
|
+ // 更新设备_产量计酬表的 mod_rq 和 delsys_id 字段
|
|
|
+ $updateData = [
|
|
|
+ 'mod_rq' => date('Y-m-d H:i:s'),
|
|
|
+ 'delsys_id' => $param['sys_id']
|
|
|
+ ];
|
|
|
+ $updateResult = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
|
|
|
+ $sql = \db()->query($updateResult);
|
|
|
+
|
|
|
+ // 检查更新是否成功
|
|
|
+ if ($sql === false) {
|
|
|
+ $failureCount++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-// // 根据订单编号查询工单_印件资料表,并排除有修改日期的记录
|
|
|
-// $yresult = \db('工单_印件资料')->where('订单编号', $result['订单编号'])
|
|
|
-// ->whereNull('Mod_rq')
|
|
|
-// ->find();
|
|
|
-//
|
|
|
-// // 检查是否找到结果
|
|
|
-// if (!$yresult) {
|
|
|
-// $failureCount++;
|
|
|
-// continue; // 跳过当前循环,处理下一个 UniqId
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 获取 result 中的尺码和数量
|
|
|
-// $size = $result['尺码'];
|
|
|
-// $quantity = $result['数量'];
|
|
|
-//
|
|
|
-// // 遍历 yresult 中的 cm1 到 cm10 字段,查找匹配的尺码
|
|
|
-// for ($i = 1; $i <= 10; $i++) {
|
|
|
-// $cmField = 'cm' . $i;
|
|
|
-// $scslField = 'scsl' . $i;
|
|
|
-//
|
|
|
-// // 检查 yresult 中是否存在对应的尺码字段,且值等于 result 中的尺码
|
|
|
-// if (isset($yresult[$cmField]) && $yresult[$cmField] === $size) {
|
|
|
-// // 找到对应 scsl 字段并进行数量减法
|
|
|
-// if (isset($yresult[$scslField])) {
|
|
|
-// $yresult[$scslField] -= $quantity;
|
|
|
-//
|
|
|
-// // 防止数量变成负数
|
|
|
-// if ($yresult[$scslField] < 0) {
|
|
|
-// $yresult[$scslField] = 0;
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 更新数据库中的 scsl 字段
|
|
|
-// \db('工单_印件资料')
|
|
|
-// ->where('订单编号', $result['订单编号'])
|
|
|
-// ->update([$scslField => $yresult[$scslField]]);
|
|
|
-// }
|
|
|
-// break; // 找到并处理后,跳出循环
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 重新计算 scsl1 到 scsl10 的总和并更新 sctotal 字段
|
|
|
-// $newTotal = 0;
|
|
|
-// for ($i = 1; $i <= 10; $i++) {
|
|
|
-// $scslField = 'scsl' . $i;
|
|
|
-// if (isset($yresult[$scslField])) {
|
|
|
-// $newTotal += $yresult[$scslField];
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 更新 sctotal 的最新值到数据库
|
|
|
-// \db('工单_印件资料')
|
|
|
-// ->where('订单编号', $result['订单编号'])
|
|
|
-// ->update(['sctotal' => $newTotal]);
|
|
|
+ // 返回最终的操作结果
|
|
|
+ if ($failureCount === 0) {
|
|
|
+ return $this->success('删除成功');
|
|
|
+ } else {
|
|
|
+ return $this->error("操作完成,但有 {$failureCount} 条记录更新失败");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 初始化失败计数器
|
|
|
+ $failureCount = 0;
|
|
|
|
|
|
- // 更新设备_产量计酬表的mod_rq和delsys_id字段
|
|
|
- $updateData = [
|
|
|
- 'mod_rq' => date('Y-m-d H:i:s'),
|
|
|
- 'delsys_id' => $param['sys_id']
|
|
|
- ];
|
|
|
- $result = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
|
|
|
- $sql = \db()->query($result);
|
|
|
+ foreach ($printIdArray as $uniqId) {
|
|
|
+ // 根据 UniqId 查询 设备_产量计酬 表中的订单编号、尺码和数量
|
|
|
+ $result = \db('设备_产量计酬')->where('UniqId', $uniqId)
|
|
|
+ ->field('订单编号,尺码,数量,sczl_bh')
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ // 判断是否是本组机台
|
|
|
+ if ($result['sczl_bh'] != $param['sys_id']) {
|
|
|
+ return $this->error("当前选择包含 {$result['sczl_bh']},请选择本组机台 {$param['sys_id']} 进行删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否找到结果
|
|
|
+ if (!$result) {
|
|
|
+ $failureCount++;
|
|
|
+ continue; // 跳过当前循环,处理下一个 UniqId
|
|
|
+ }
|
|
|
|
|
|
- // 检查更新是否成功
|
|
|
- if ($sql === false) {
|
|
|
- $failureCount++;
|
|
|
+ // 更新设备_产量计酬表的mod_rq和delsys_id字段
|
|
|
+ $updateData = [
|
|
|
+ 'mod_rq' => date('Y-m-d H:i:s'),
|
|
|
+ 'delsys_id' => $param['sys_id']
|
|
|
+ ];
|
|
|
+ $result = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
|
|
|
+ $sql = \db()->query($result);
|
|
|
+
|
|
|
+ // 检查更新是否成功
|
|
|
+ if ($sql === false) {
|
|
|
+ $failureCount++;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 如果没有失败记录,则表示删除成功
|
|
|
- if ($failureCount === 0) {
|
|
|
- return $this->success('删除成功');
|
|
|
- } else {
|
|
|
- return $this->error("操作完成,但有 {$failureCount} 条记录更新失败");
|
|
|
+ // 如果没有失败记录,则表示删除成功
|
|
|
+ if ($failureCount === 0) {
|
|
|
+ return $this->success('删除成功');
|
|
|
+ } else {
|
|
|
+ return $this->error("操作完成,但有 {$failureCount} 条记录更新失败");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|