|
|
@@ -1118,9 +1118,10 @@ class WorkOrderProcess extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 确认拆分工序:母工序置为已拆分,按数量生成子工序
|
|
|
+ * 确认拆分工序:number>0 时母工序置为已拆分并生成子工序(子工序 pid 为母工序 id);
|
|
|
+ * number=0 时恢复母工序 status=0 并软删除其子工序
|
|
|
* @param id 工艺ID
|
|
|
- * @param number 拆分数量
|
|
|
+ * @param number 拆分数量(0 表示取消拆分)
|
|
|
* @param sys_id 操作人员
|
|
|
* @param sys_rq 操作时间(可选,默认当前时间)
|
|
|
*/
|
|
|
@@ -1133,7 +1134,7 @@ class WorkOrderProcess extends Api
|
|
|
if (empty($params['id'])) {
|
|
|
$this->error('工艺ID不能为空');
|
|
|
}
|
|
|
- if (empty($params['number']) ) {
|
|
|
+ if (!isset($params['number']) || $params['number'] === '' || $params['number'] === null) {
|
|
|
$this->error('拆分工序数量不能为空');
|
|
|
}
|
|
|
if (empty($params['sys_id'])) {
|
|
|
@@ -1142,16 +1143,92 @@ class WorkOrderProcess extends Api
|
|
|
|
|
|
$splitCount = intval($params['number']);
|
|
|
$operTime = !empty($params['sys_rq']) ? $params['sys_rq'] : date('Y-m-d H:i:s');
|
|
|
+ $processId = intval($params['id']);
|
|
|
|
|
|
$process = Db::table('工单_基础工艺资料')
|
|
|
- ->where('id', intval($params['id']))
|
|
|
- ->where('status', 'in', [0, '0'])
|
|
|
+ ->where('id', $processId)
|
|
|
+ ->whereNull('del_rq')
|
|
|
->find();
|
|
|
if (empty($process)) {
|
|
|
- $this->error('工序不存在或已确认拆分');
|
|
|
+ $this->error('工序不存在');
|
|
|
}
|
|
|
|
|
|
$workorder = $process['work_order'];
|
|
|
+
|
|
|
+ if ($splitCount === 0) {
|
|
|
+ $children = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('pid', $processId)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->field('id,process_code')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $logList = [
|
|
|
+ [
|
|
|
+ 'order_no' => $workorder,
|
|
|
+ 'process_code' => $process['process_code'],
|
|
|
+ 'change_field' => '状态',
|
|
|
+ 'old_value' => '1',
|
|
|
+ 'new_value' => '0',
|
|
|
+ 'oper_type' => '取消拆分工序',
|
|
|
+ 'oper_user_name' => $params['sys_id'],
|
|
|
+ 'oper_time' => $operTime,
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ foreach ($children as $child) {
|
|
|
+ $logList[] = [
|
|
|
+ 'order_no' => $workorder,
|
|
|
+ 'process_code' => $child['process_code'],
|
|
|
+ 'change_field' => '工序拆分',
|
|
|
+ 'old_value' => (string)$process['process_code'],
|
|
|
+ 'new_value' => '删除子工序',
|
|
|
+ 'oper_type' => '取消拆分工序',
|
|
|
+ 'oper_user_name' => $params['sys_id'],
|
|
|
+ 'oper_time' => $operTime,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ if (!empty($children)) {
|
|
|
+ $deleteResult = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('pid', $processId)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->update(['del_rq' => $operTime]);
|
|
|
+ if ($deleteResult === false) {
|
|
|
+ throw new \Exception('删除子工序失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $updateResult = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('id', $processId)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->update(['status' => 0]);
|
|
|
+ if ($updateResult === false) {
|
|
|
+ throw new \Exception('恢复母工序状态失败');
|
|
|
+ }
|
|
|
+ if (!empty($logList)) {
|
|
|
+ $logResult = Db::name('work_order_operation_log')->insertAll($logList);
|
|
|
+ if ($logResult === false || $logResult === 0) {
|
|
|
+ throw new \Exception('写入操作日志失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ } catch (\think\exception\HttpResponseException $e) {
|
|
|
+ throw $e;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('取消拆分失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ $this->success('取消拆分工序成功', ['count' => count($children)]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($splitCount < 1) {
|
|
|
+ $this->error('拆分工序数量必须大于0');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!in_array($process['status'], [0, '0'], true)) {
|
|
|
+ $this->error('工序不存在或已确认拆分');
|
|
|
+ }
|
|
|
$processCodes = Db::table('工单_基础工艺资料')
|
|
|
->where('work_order', $workorder)
|
|
|
->whereNull('del_rq')
|
|
|
@@ -1200,6 +1277,7 @@ class WorkOrderProcess extends Api
|
|
|
? $process['coefficient'] : 'C',
|
|
|
'remark' => isset($process['remark']) && $process['remark'] !== null ? $process['remark'] : '',
|
|
|
'status' => 0,
|
|
|
+ 'pid' => $processId,
|
|
|
'sys_id' => $params['sys_id'],
|
|
|
'sys_rq' => $operTime,
|
|
|
];
|