|
@@ -1123,4 +1123,270 @@ class WorkOrderProcess extends Api
|
|
|
$this->success('修改成功');
|
|
$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 workorder 工单编号
|
|
|
|
|
+ * @param process_code 工艺编号
|
|
|
|
|
+ * @param sys_id 操作人
|
|
|
|
|
+ */
|
|
|
|
|
+ public function confirmProcessSplit()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
|
|
+ $this->error('请求方法错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $params = $this->request->post();
|
|
|
|
|
+ if (empty($params['workorder'])) {
|
|
|
|
|
+ $this->error('工单编号不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($params['process_code'])) {
|
|
|
|
|
+ $this->error('工艺编号不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (empty($params['sys_id'])) {
|
|
|
|
|
+ $this->error('操作人不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $process = Db::table('工单_基础工艺资料')
|
|
|
|
|
+ ->where('work_order', $params['workorder'])
|
|
|
|
|
+ ->where('process_code', $params['process_code'])
|
|
|
|
|
+ ->where('status', 0)
|
|
|
|
|
+ ->whereNull('del_rq')
|
|
|
|
|
+ ->find();
|
|
|
|
|
+ if (empty($process)) {
|
|
|
|
|
+ $this->error('工序不存在或已确认拆分');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $operTime = date('Y-m-d H:i:s');
|
|
|
|
|
+ $logData = [
|
|
|
|
|
+ 'order_no' => $params['workorder'],
|
|
|
|
|
+ 'process_code' => $params['process_code'],
|
|
|
|
|
+ 'change_field' => '状态',
|
|
|
|
|
+ 'old_value' => '0',
|
|
|
|
|
+ 'new_value' => '1',
|
|
|
|
|
+ 'oper_type' => '确认拆分工序',
|
|
|
|
|
+ 'oper_user_name' => $params['sys_id'],
|
|
|
|
|
+ 'oper_time' => $operTime,
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $updateResult = Db::table('工单_基础工艺资料')
|
|
|
|
|
+ ->where('id', $process['id'])
|
|
|
|
|
+ ->where('status', 0)
|
|
|
|
|
+ ->whereNull('del_rq')
|
|
|
|
|
+ ->update(['status' => 1]);
|
|
|
|
|
+ if ($updateResult === false) {
|
|
|
|
|
+ throw new \Exception('更新工序状态失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($updateResult === 0) {
|
|
|
|
|
+ throw new \Exception('工序不存在或已确认拆分');
|
|
|
|
|
+ }
|
|
|
|
|
+ $logResult = Db::name('work_order_operation_log')->insert($logData);
|
|
|
|
|
+ if ($logResult === false) {
|
|
|
|
|
+ throw new \Exception('写入操作日志失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ $this->error('修改失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('确认拆分工序成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取工单最大工序编号
|
|
|
|
|
+ * @param workorder 工单编号
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getMaxProcessCode()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
|
|
+ $this->error('请求方法错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $params = $this->request->param();
|
|
|
|
|
+ if (empty($params['workorder'])) {
|
|
|
|
|
+ $this->error('工单编号不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+ $processCode = db('工单_基础工艺资料')
|
|
|
|
|
+ ->where('work_order', $params['workorder'])
|
|
|
|
|
+ ->max('process_code');
|
|
|
|
|
+ $this->success('最大工序编号', $processCode);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 批量新增工序资料(请求体为 JSON 数组,每条含 work_order 等字段)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function batchAddProcess()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
|
|
+ $this->error('请求方法错误');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $processList = [];
|
|
|
|
|
+ $params = $this->request->post();
|
|
|
|
|
+ if (isset($params[0]) && is_array($params[0])) {
|
|
|
|
|
+ $processList = $params;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $rawBody = file_get_contents('php://input');
|
|
|
|
|
+ $decoded = json_decode($rawBody, true);
|
|
|
|
|
+ if (is_array($decoded) && isset($decoded[0]) && is_array($decoded[0])) {
|
|
|
|
|
+ $processList = $decoded;
|
|
|
|
|
+ } elseif (is_string($params) || (count($params) === 1 && is_string(reset($params)))) {
|
|
|
|
|
+ $jsonStr = is_string($params) ? $params : reset($params);
|
|
|
|
|
+ $decoded = json_decode($jsonStr, true);
|
|
|
|
|
+ if (is_array($decoded)) {
|
|
|
|
|
+ $processList = $decoded;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!is_array($processList) || empty($processList)) {
|
|
|
|
|
+ $this->error('工艺数据不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $requiredFields = [
|
|
|
|
|
+ 'work_order' => '工单编号',
|
|
|
|
|
+ 'part_code' => '部件编号',
|
|
|
|
|
+ 'part_name' => '部件名称',
|
|
|
|
|
+ 'process_code' => '工序编号',
|
|
|
|
|
+ 'process_name' => '工序名称',
|
|
|
|
|
+ 'big_process' => '大工序',
|
|
|
|
|
+ 'standard_hour' => '秒',
|
|
|
|
|
+ 'standard_score' => '定额分',
|
|
|
|
|
+ 'coefficient' => '难度系数',
|
|
|
|
|
+ 'standard_minutes' => '分',
|
|
|
|
|
+ 'money' => '金额',
|
|
|
|
|
+ 'remark' => '备注',
|
|
|
|
|
+ 'sys_id' => '操作人员',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $workorder = '';
|
|
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
|
|
+ $insertList = [];
|
|
|
|
|
+ $processCodes = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($processList as $index => $process) {
|
|
|
|
|
+ if (!is_array($process)) {
|
|
|
|
|
+ $this->error('第' . ($index + 1) . '条工艺数据格式错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ foreach ($requiredFields as $field => $label) {
|
|
|
|
|
+ if (!isset($process[$field]) || $process[$field] === '' || $process[$field] === null) {
|
|
|
|
|
+ $this->error('第' . ($index + 1) . '条' . $label . '不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $itemWorkOrder = trim($process['work_order']);
|
|
|
|
|
+ if ($workorder === '') {
|
|
|
|
|
+ $workorder = $itemWorkOrder;
|
|
|
|
|
+ } elseif ($itemWorkOrder !== $workorder) {
|
|
|
|
|
+ $this->error('第' . ($index + 1) . '条工单编号与其它数据不一致');
|
|
|
|
|
+ }
|
|
|
|
|
+ $processCode = $process['process_code'];
|
|
|
|
|
+ if (in_array((string)$processCode, $processCodes, true)) {
|
|
|
|
|
+ $this->error('批量数据中存在重复的工序编号:' . $processCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ $processCodes[] = (string)$processCode;
|
|
|
|
|
+
|
|
|
|
|
+ $exists = Db::table('工单_基础工艺资料')
|
|
|
|
|
+ ->where('work_order', $workorder)
|
|
|
|
|
+ ->where('process_code', $processCode)
|
|
|
|
|
+ ->whereNull('del_rq')
|
|
|
|
|
+ ->count();
|
|
|
|
|
+ if ($exists > 0) {
|
|
|
|
|
+ $this->error('工序编号已存在:' . $processCode);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $insertList[] = [
|
|
|
|
|
+ 'work_order' => $workorder,
|
|
|
|
|
+ 'part_code' => $process['part_code'],
|
|
|
|
|
+ 'part_name' => $process['part_name'],
|
|
|
|
|
+ 'process_code' => $processCode,
|
|
|
|
|
+ 'process_name' => $process['process_name'],
|
|
|
|
|
+ 'big_process' => $process['big_process'],
|
|
|
|
|
+ 'standard_hour' => $process['standard_hour'],
|
|
|
|
|
+ 'standard_minutes' => $process['standard_minutes'],
|
|
|
|
|
+ 'standard_score' => $process['standard_score'],
|
|
|
|
|
+ 'coefficient' => $process['coefficient'],
|
|
|
|
|
+ 'money' => $process['money'],
|
|
|
|
|
+ 'remark' => $process['remark'],
|
|
|
|
|
+ 'status' => isset($process['status']) ? $process['status'] : 0,
|
|
|
|
|
+ 'sys_id' => $process['sys_id'],
|
|
|
|
|
+ 'sys_rq' => $now,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $workOrder = Db::table('工单_基本资料')
|
|
|
|
|
+ ->where('订单编号', $workorder)
|
|
|
|
|
+ ->where('Mod_rq', null)
|
|
|
|
|
+ ->field('订单编号,计划制造工分')
|
|
|
|
|
+ ->find();
|
|
|
|
|
+ if (empty($workOrder)) {
|
|
|
|
|
+ $this->error('工单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $existingTotal = Db::table('工单_基础工艺资料')
|
|
|
|
|
+ ->where('work_order', $workorder)
|
|
|
|
|
+ ->where('status', 0)
|
|
|
|
|
+ ->whereNull('del_rq')
|
|
|
|
|
+ ->sum('standard_score');
|
|
|
|
|
+ $existingTotal = $existingTotal ? floatval($existingTotal) : 0;
|
|
|
|
|
+ $newBatchStatus0Sum = 0;
|
|
|
|
|
+ foreach ($insertList as $row) {
|
|
|
|
|
+ if ((string)$row['status'] === '0' || $row['status'] === 0) {
|
|
|
|
|
+ $newBatchStatus0Sum += floatval($row['standard_score']);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $newTotal = $existingTotal + $newBatchStatus0Sum;
|
|
|
|
|
+ if ($newTotal > floatval($workOrder['计划制造工分'])) {
|
|
|
|
|
+ $this->error('工序定额分和大于制造工分,请确认之后再修改');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $insertResult = Db::name('工单_基础工艺资料')->insertAll($insertList);
|
|
|
|
|
+ if ($insertResult === false) {
|
|
|
|
|
+ throw new \Exception('拆分工序失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ $this->error('拆分工序资料失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('拆分工序资料成功', ['count' => count($insertList)]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|