liugc 1 rok pred
rodič
commit
623f75b528
1 zmenil súbory, kde vykonal 45 pridanie a 11 odobranie
  1. 45 11
      app/common/controller/InternalApiController.php

+ 45 - 11
app/common/controller/InternalApiController.php

@@ -5,10 +5,13 @@ namespace app\common\controller;
 
 use app\api\logic\ServiceOrderLogic;
 use app\common\enum\PayEnum;
+use app\common\enum\worker\WorkerAccountLogEnum;
 use app\common\logic\PayNotifyLogic;
+use app\common\logic\WorkerAccountLogLogic;
 use app\common\model\external\ExternalPlatform;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\works\ServiceWork;
+use app\common\model\works\ServiceWorkLog;
 use think\facade\Config;
 use think\facade\Log;
 
@@ -114,17 +117,48 @@ class InternalApiController extends BaseLikeAdminController
             $service_work = ServiceWork::where('work_sn',$params['work_sn'])->findOrEmpty();
             if($service_work->isEmpty()) throw new \Exception('工单不存在',404);
 
-            //取消订单
-            RechargeOrder::where(['user_id'=>$service_work->user_id,'work_id'=>$service_work->id])->update([
-                'pay_status' => 2,
-            ]);
-            //更新工单状态为已取消
-            $service_work->service_status = 4;
-            $service_work->save();
-
-            // 若存在结算则先退回
-
-
+            // 取消工单
+            if($service_work->work_status < 7){
+                //更新工单状态为已取消
+                $service_work->service_status = 4;
+                // 是否存在退款
+                if($service_work->work_pay_status == 1 && (int)$params['is_refund'] == 1){
+                    $service_work->service_status = 5;
+                    $service_work->work_pay_status = 2;
+                    //取消订单
+                    RechargeOrder::where(['user_id'=>$service_work->user_id,'work_id'=>$service_work->id])->update([
+                        'pay_status' => 2,
+                    ]);
+                }else if($service_work->work_pay_status == 1 && (int)$params['is_refund'] == 0){
+                    $paid_amount = RechargeOrder::where('work_id', $service_work->id)->where('payment_type', 1)->value('paid_amount');
+                    if($paid_amount > 0){
+                        // 存在上门费给工程师
+                        Log::info('内部取消并终止结束服务工单'.$service_work->id.',上门费:'.$paid_amount);
+                        WorkerAccountLogLogic::addAccountLog($service_work,$paid_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);
+                    }
+                    ServiceWork::where('id', $params['id'])->update([
+                        'work_status' => 7,
+                        'user_confirm_status' => 5,
+                        'service_status' => 3,
+                        'work_pay_status' => 2, // 已结算则不执行 onAfterUpdate
+                        'settlement_amount' => $paid_amount??0,
+                        'worker_price' => $paid_amount??0,
+                        'remark' => ($service_work->remark?:'')." | 内部取消并终止结束服务:上门费-{$paid_amount}"
+                    ]);
+
+                    ServiceWorkLog::create([
+                        'work_id' => $service_work->id,
+                        'master_worker_id' => $service_work->master_worker_id,
+                        'opera_log' => "工单:{$service_work->work_sn} 内部取消并终止结束服务"
+                    ]);
+                }
+                $service_work->work_status = 7;
+                $service_work->user_confirm_status = 5;
+                $service_work->save();
+            }
+            /*else{
+                // 若存在结算则先退回
+            }*/
             return $this->success('内部取消工单完成', [], 0, 1);
         }catch(\Exception $e){
             return $this->fail($e->getMessage(),[],$e->getCode());