|
|
@@ -468,10 +468,17 @@ class WorkOrderProcess extends Api
|
|
|
$params['coefficient'] = 'C';
|
|
|
}
|
|
|
|
|
|
+ $process = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('id', intval($params['id']))
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->find();
|
|
|
+ if (empty($process)) {
|
|
|
+ $this->error('工艺不存在');
|
|
|
+ }
|
|
|
+
|
|
|
$data = [
|
|
|
'part_code' => $params['part_code'],
|
|
|
'part_name' => $params['part_name'],
|
|
|
- 'process_code' => $params['process_code'],
|
|
|
'standard_minutes' => $params['standard_minutes'],
|
|
|
'money' => $params['money'],
|
|
|
'remark' => $params['remark'],
|
|
|
@@ -480,20 +487,92 @@ class WorkOrderProcess extends Api
|
|
|
'standard_hour' => $params['standard_hour'],
|
|
|
'standard_score' => $params['standard_score'],
|
|
|
'coefficient' => $params['coefficient'],
|
|
|
- 'remark' => $params['remark'],
|
|
|
'mod_id' => $params['mod_id'],
|
|
|
'mod_rq' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
|
- $result = db('工单_基础工艺资料')
|
|
|
- ->where('id', intval($params['id']))
|
|
|
- ->whereNull('del_rq')
|
|
|
- ->update($data);
|
|
|
- if ($result === false) {
|
|
|
- $this->error('更新失败');
|
|
|
+
|
|
|
+ $fieldLabels = [
|
|
|
+ 'part_code' => '部件编号',
|
|
|
+ 'part_name' => '部件名称',
|
|
|
+ 'process_code' => '工序编号',
|
|
|
+ 'standard_minutes' => '分',
|
|
|
+ 'money' => '金额',
|
|
|
+ 'remark' => '备注',
|
|
|
+ 'process_name' => '工序名称',
|
|
|
+ 'big_process' => '大工序',
|
|
|
+ 'standard_hour' => '秒',
|
|
|
+ 'standard_score' => '定额分',
|
|
|
+ 'coefficient' => '难度系数',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $operTime = date('Y-m-d H:i:s');
|
|
|
+ $logList = [];
|
|
|
+ foreach ($fieldLabels as $field => $label) {
|
|
|
+ $oldValue = isset($process[$field]) ? $process[$field] : '';
|
|
|
+ $newValue = $data[$field];
|
|
|
+ if ((string)$oldValue === (string)$newValue) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $logList[] = [
|
|
|
+ 'order_no' => $process['work_order'],
|
|
|
+ 'process_code' => $process['process_code'],
|
|
|
+ 'change_field' => $label,
|
|
|
+ 'old_value' => $oldValue === null ? '' : (string)$oldValue,
|
|
|
+ 'new_value' => (string)$newValue,
|
|
|
+ 'oper_type' => '修改工单工艺',
|
|
|
+ 'oper_user_name' => $params['mod_id'],
|
|
|
+ 'oper_time' => $operTime,
|
|
|
+ ];
|
|
|
}
|
|
|
- if ($result === 0) {
|
|
|
+
|
|
|
+ if (empty($logList)) {
|
|
|
$this->error('未找到可更新的工艺或数据无变化');
|
|
|
}
|
|
|
+
|
|
|
+ $standardScoreChanged = (string)$process['standard_score'] !== (string)$params['standard_score'];
|
|
|
+ if ($standardScoreChanged && (string)$process['status'] === '0') {
|
|
|
+ $workOrder = Db::table('工单_基本资料')
|
|
|
+ ->where('订单编号', $process['work_order'])
|
|
|
+ ->where('Mod_rq', null)
|
|
|
+ ->field('计划制造工分')
|
|
|
+ ->find();
|
|
|
+ if (empty($workOrder)) {
|
|
|
+ $this->error('工单不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $totalStandardScore = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('work_order', $process['work_order'])
|
|
|
+ ->where('status', 0)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->sum('standard_score');
|
|
|
+ $totalStandardScore = $totalStandardScore ? floatval($totalStandardScore) : 0;
|
|
|
+ $newTotal = $totalStandardScore - floatval($process['standard_score']) + floatval($params['standard_score']);
|
|
|
+ if ($newTotal > floatval($workOrder['计划制造工分'])) {
|
|
|
+ $this->error('工序定额分和大于制造工分,请确认之后再修改');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $updateResult = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('id', intval($params['id']))
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->update($data);
|
|
|
+ if ($updateResult === false) {
|
|
|
+ throw new \Exception('更新工艺失败');
|
|
|
+ }
|
|
|
+ if ($updateResult === 0) {
|
|
|
+ throw new \Exception('未找到可更新的工艺');
|
|
|
+ }
|
|
|
+ $logResult = Db::name('work_order_operation_log')->insertAll($logList);
|
|
|
+ if ($logResult === false) {
|
|
|
+ throw new \Exception('写入操作日志失败');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('更新失败');
|
|
|
+ }
|
|
|
$this->success('更新成功');
|
|
|
}
|
|
|
|