|
|
@@ -5774,4 +5774,96 @@ class WorkOrder extends Api
|
|
|
$this->success('成功', $list);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改订单备注和完工日期
|
|
|
+ * @param id 工单ID
|
|
|
+ * @param remark 备注
|
|
|
+ * @param finish_date 工单完工日期
|
|
|
+ * @param sys_id 操作人
|
|
|
+ */
|
|
|
+ public function updateOrderRemarkAndFinishDate()
|
|
|
+ {
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
+ $this->error('请求方式错误');
|
|
|
+ }
|
|
|
+ $params = $this->request->post();
|
|
|
+ if (empty($params['id'])) {
|
|
|
+ $this->error('工单ID不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['sys_id'])) {
|
|
|
+ $this->error('操作人不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ $workOrder = Db::table('工单_基本资料')
|
|
|
+ ->where('Uniqid', intval($params['id']))
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
+ ->field('Uniqid,订单编号,remark,工单完工日期')
|
|
|
+ ->find();
|
|
|
+ if (empty($workOrder)) {
|
|
|
+ $this->error('工单不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $remark = isset($params['remark']) ? $params['remark'] : '';
|
|
|
+ $finishDate = isset($params['工单完工日期']) ? $params['工单完工日期'] : '';
|
|
|
+ $updateData = [];
|
|
|
+ $logList = [];
|
|
|
+ $operTime = date('Y-m-d H:i:s');
|
|
|
+ $orderNo = $workOrder['订单编号'];
|
|
|
+
|
|
|
+ $fieldMap = [
|
|
|
+ 'remark' => ['label' => '备注', 'new' => $remark],
|
|
|
+ '工单完工日期' => ['label' => '工单完工日期', 'new' => $finishDate],
|
|
|
+ ];
|
|
|
+ foreach ($fieldMap as $field => $item) {
|
|
|
+ $oldValue = isset($workOrder[$field]) ? $workOrder[$field] : '';
|
|
|
+ $newValue = $item['new'];
|
|
|
+ if ((string)$oldValue === (string)$newValue) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $updateData[$field] = $newValue;
|
|
|
+ $logList[] = [
|
|
|
+ 'order_no' => $orderNo,
|
|
|
+ 'change_field' => $item['label'],
|
|
|
+ 'old_value' => $oldValue === null ? '' : (string)$oldValue,
|
|
|
+ 'new_value' => (string)$newValue,
|
|
|
+ 'oper_type' => '修改工单备注和完工日期',
|
|
|
+ 'oper_user_name' => $params['sys_id'],
|
|
|
+ 'oper_time' => $operTime,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($updateData)) {
|
|
|
+ $this->error('数据未发生变化');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $updateSql = Db::table('工单_基本资料')
|
|
|
+ ->where('Uniqid', intval($params['id']))
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
+ ->fetchSql(true)
|
|
|
+ ->update($updateData);
|
|
|
+ $updateResult = db()->query($updateSql);
|
|
|
+ if ($updateResult === false) {
|
|
|
+ throw new \Exception('更新工单失败');
|
|
|
+ }
|
|
|
+ if ($updateResult === 0) {
|
|
|
+ throw new \Exception('未找到可更新的工单');
|
|
|
+ }
|
|
|
+ $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('修改成功');
|
|
|
+ }
|
|
|
+
|
|
|
}
|