liugc 1 год назад
Родитель
Сommit
d5019b159d
1 измененных файлов с 19 добавлено и 6 удалено
  1. 19 6
      app/adminapi/logic/works/ServiceWorkLogic.php

+ 19 - 6
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -16,6 +16,8 @@ namespace app\adminapi\logic\works;
 
 
 use app\api\logic\PerformanceLogic;
+use app\common\enum\worker\WorkerAccountLogEnum;
+use app\common\logic\WorkerAccountLogLogic;
 use app\common\model\dict\DictData;
 use app\common\model\master_worker\MasterWorker;
 use app\common\model\master_worker\MasterWorkerAccountLog;
@@ -36,6 +38,7 @@ use app\workerapi\logic\ServiceWorkLogLogic;
 use think\db\Query;
 use think\Exception;
 use think\facade\Db;
+use think\facade\Log;
 
 
 /**
@@ -573,31 +576,41 @@ class ServiceWorkLogic extends BaseLogic
     {
         Db::startTrans();
         try {
+            // 04-11-12 不做任何限制强制取消,已支付的费用给工程师余额
             $serviceWorkInfo = ServiceWork::find($params['id']);
-            if((int)$serviceWorkInfo['work_status'] !== 0){
-                throw new \Exception('该工单不可取消');
+            if((int)$serviceWorkInfo['user_confirm_status'] === 5 || (int)$serviceWorkInfo['service_status'] > 2){
+                throw new \Exception('用户已完结该工单或已取消,已退款,不可执行取消');
             }
             ServiceWork::where('id', $params['id'])->update([
-                'work_status' => 9,
+                //'work_status' => 9,
+                'service_status' => 4,
                 'remark' => $params['remark']??''
             ]);
-            // 对应订单状态修改
+            /*// 对应订单状态修改
             RechargeOrder::where('work_id', $params['id'])->update([
                 'pay_status' => 2
-            ]);
+            ]);*/
             ServiceWorkLog::create([
                 'work_id' => $params['id'],
                 'master_worker_id' => $serviceWorkInfo['master_worker_id'],
                 'opera_log' => "工单:{$serviceWorkInfo['work_sn']}已取消"
             ]);
 
-            // 退款
+            $paid_amount = RechargeOrder::where('work_id', $params['id'])->where('payment_type', 1)->where('order_type', 0)->where('pay_status', 1)->value('paid_amount');
+            if($paid_amount > 0){
+                // 4=已上门,5=服务中,6=待结算, 即工程师已上门服务过
+                if(in_array((int)$serviceWorkInfo['work_status'], [4,5,6])){
+                    WorkerAccountLogLogic::addAccountLog($serviceWorkInfo,$paid_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC,$params['remark']??'');
+                }
+            }
 
             Db::commit();
+            Log::info('取消工单'.json_encode([$serviceWorkInfo]));
             return true;
         } catch (\Exception $e) {
             Db::rollback();
             self::setError($e->getMessage());
+            Log::info('取消工单-Error'.json_encode([$e->getMessage()]));
             return false;
         }
     }