|
|
@@ -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,91 @@ 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' => '部件名称',
|
|
|
+ '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' => $params['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('更新成功');
|
|
|
}
|
|
|
|
|
|
@@ -1044,4 +1122,209 @@ class WorkOrderProcess extends Api
|
|
|
$this->success('修改成功');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拆分工序时判断工序是否存在报工
|
|
|
+ * @param workorder 工单编号
|
|
|
+ * @param process_code 工艺编号
|
|
|
+ * @return array
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function checkProcessReport()
|
|
|
+ {
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
+ $this->error('请求方法错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->post();
|
|
|
+ if (empty($params['workorder'])) {
|
|
|
+ $this->error('工单编号不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['process_code'])) {
|
|
|
+ $this->error('工艺编号不能为空');
|
|
|
+ }
|
|
|
+ $process = db('设备_工分计酬')
|
|
|
+ ->where('work_order', $params['workorder'])
|
|
|
+ ->where('process_code', $params['process_code'])
|
|
|
+ ->find();
|
|
|
+ if (!empty($process)) {
|
|
|
+ $this->error('');
|
|
|
+ }
|
|
|
+ $this->success('工序不存在报工,可以拆分');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认拆分工序:母工序置为已拆分,按数量生成子工序
|
|
|
+ * @param id 工艺ID
|
|
|
+ * @param number 拆分数量
|
|
|
+ * @param sys_id 操作人员
|
|
|
+ * @param sys_rq 操作时间(可选,默认当前时间)
|
|
|
+ */
|
|
|
+ public function confirmProcessSplit()
|
|
|
+ {
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
+ $this->error('请求方法错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->post();
|
|
|
+ if (empty($params['id'])) {
|
|
|
+ $this->error('工艺ID不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['number']) || intval($params['number']) < 2) {
|
|
|
+ $this->error('拆分工序数量不能小于2');
|
|
|
+ }
|
|
|
+ if (empty($params['sys_id'])) {
|
|
|
+ $this->error('操作人不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ $splitCount = intval($params['number']);
|
|
|
+ $operTime = !empty($params['sys_rq']) ? $params['sys_rq'] : date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ $process = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('id', intval($params['id']))
|
|
|
+ ->where('status', 'in', [0, '0'])
|
|
|
+ ->find();
|
|
|
+ if (empty($process)) {
|
|
|
+ $this->error('工序不存在或已确认拆分');
|
|
|
+ }
|
|
|
+
|
|
|
+ $workorder = $process['work_order'];
|
|
|
+ $processCodes = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('work_order', $workorder)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->column('process_code');
|
|
|
+ $maxNumeric = 0;
|
|
|
+ foreach ($processCodes as $code) {
|
|
|
+ if (preg_match('/^(\d+)/', (string)$code, $match)) {
|
|
|
+ $num = intval($match[1]);
|
|
|
+ if ($num > $maxNumeric) {
|
|
|
+ $maxNumeric = $num;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $baseCode = $maxNumeric + 1;
|
|
|
+
|
|
|
+ $splitFields = ['standard_hour', 'standard_minutes', 'standard_score', 'money'];
|
|
|
+ $splitValues = [];
|
|
|
+ foreach ($splitFields as $field) {
|
|
|
+ $splitValues[$field] = $this->splitNumericValue($process[$field], $splitCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ $insertList = [];
|
|
|
+ for ($i = 1; $i <= $splitCount; $i++) {
|
|
|
+ $newProcessCode = $baseCode + $i - 1;
|
|
|
+ $exists = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('work_order', $workorder)
|
|
|
+ ->where('process_code', $newProcessCode)
|
|
|
+ ->whereNull('del_rq')
|
|
|
+ ->count();
|
|
|
+ if ($exists > 0) {
|
|
|
+ $this->error('工序编号已存在:' . $newProcessCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ $insertList[] = [
|
|
|
+ 'work_order' => $workorder,
|
|
|
+ 'part_code' => $process['part_code'],
|
|
|
+ 'part_name' => isset($process['part_name']) ? $process['part_name'] : '',
|
|
|
+ 'process_code' => $newProcessCode,
|
|
|
+ 'process_name' => $process['process_name'] . '-' . $i,
|
|
|
+ 'big_process' => $process['big_process'],
|
|
|
+ 'standard_hour' => $splitValues['standard_hour'][$i - 1],
|
|
|
+ 'standard_minutes' => $splitValues['standard_minutes'][$i - 1],
|
|
|
+ 'standard_score' => $splitValues['standard_score'][$i - 1],
|
|
|
+ 'money' => $splitValues['money'][$i - 1],
|
|
|
+ 'coefficient' => isset($process['coefficient']) && $process['coefficient'] !== '' && $process['coefficient'] !== null
|
|
|
+ ? $process['coefficient'] : 'C',
|
|
|
+ 'remark' => isset($process['remark']) && $process['remark'] !== null ? $process['remark'] : '',
|
|
|
+ 'status' => 0,
|
|
|
+ 'sys_id' => $params['sys_id'],
|
|
|
+ 'sys_rq' => $operTime,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $logList = [
|
|
|
+ [
|
|
|
+ 'order_no' => $workorder,
|
|
|
+ 'process_code' => $process['process_code'],
|
|
|
+ 'change_field' => '状态',
|
|
|
+ 'old_value' => '0',
|
|
|
+ 'new_value' => '1',
|
|
|
+ 'oper_type' => '确认拆分工序',
|
|
|
+ 'oper_user_name' => $params['sys_id'],
|
|
|
+ 'oper_time' => $operTime,
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ foreach ($insertList as $row) {
|
|
|
+ $logList[] = [
|
|
|
+ 'order_no' => $workorder,
|
|
|
+ 'process_code' => $row['process_code'],
|
|
|
+ 'change_field' => '工序拆分',
|
|
|
+ 'old_value' => (string)$process['process_code'],
|
|
|
+ 'new_value' => sprintf(
|
|
|
+ '秒:%s,分:%s,定额分:%s,金额:%s',
|
|
|
+ $row['standard_hour'],
|
|
|
+ $row['standard_minutes'],
|
|
|
+ $row['standard_score'],
|
|
|
+ $row['money']
|
|
|
+ ),
|
|
|
+ 'oper_type' => '确认拆分工序',
|
|
|
+ 'oper_user_name' => $params['sys_id'],
|
|
|
+ 'oper_time' => $operTime,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $updateResult = Db::table('工单_基础工艺资料')
|
|
|
+ ->where('id', $process['id'])
|
|
|
+ ->where('status', 'in', [0, '0'])
|
|
|
+ ->update(['status' => 1]);
|
|
|
+ if ($updateResult === false) {
|
|
|
+ throw new \Exception('更新母工序状态失败');
|
|
|
+ }
|
|
|
+ if ($updateResult === 0) {
|
|
|
+ throw new \Exception('母工序状态已变更,请刷新后重试');
|
|
|
+ }
|
|
|
+ $insertResult = Db::name('工单_基础工艺资料')->insertAll($insertList);
|
|
|
+ if ($insertResult === false || $insertResult === 0) {
|
|
|
+ throw new \Exception('拆分工序新增失败');
|
|
|
+ }
|
|
|
+ $logResult = Db::name('work_order_operation_log')->insertAll($logList);
|
|
|
+ if ($logResult === false || $logResult === 0) {
|
|
|
+ throw new \Exception('写入操作日志失败,请确认日志表已包含 process_code 字段');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ } catch (\think\exception\HttpResponseException $e) {
|
|
|
+ throw $e;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('修改失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ $this->success('确认拆分工序成功', ['count' => $splitCount]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按拆分数量分配数值:不能整除时第一条为剩余后的最大值,其余为向下取整的平均值
|
|
|
+ * @param mixed $total
|
|
|
+ * @param int $count
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ private function splitNumericValue($total, $count)
|
|
|
+ {
|
|
|
+ $count = intval($count);
|
|
|
+ if ($count <= 0) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $total = floatval($total);
|
|
|
+ $avg = floor($total / $count * 100) / 100;
|
|
|
+ $first = round($total - $avg * ($count - 1), 2);
|
|
|
+ $values = [$first];
|
|
|
+ for ($i = 1; $i < $count; $i++) {
|
|
|
+ $values[] = $avg;
|
|
|
+ }
|
|
|
+ return $values;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|