Explorar o código

up - 退款暂时:组件退款--后台退款--退款通知

liugc hai 9 meses
pai
achega
b354ac5310
Modificáronse 2 ficheiros con 83 adicións e 10 borrados
  1. 9 3
      app/api/controller/DouYinController.php
  2. 74 7
      app/api/service/DouYinService.php

+ 9 - 3
app/api/controller/DouYinController.php

@@ -226,7 +226,7 @@ class DouYinController extends BaseApiController
             Log::info('submitOrderNotify:'.formatLogData($params));
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
             if($params['type'] == 'pre_create_order') $res = DouYinService::submitOrderNotify($msg);
-            //if($params['type'] == 'pre_create_refund') $res = DouYinService::refundOrderNotify($msg);
+            if($params['type'] == 'pre_create_refund') $res = DouYinService::refundOrderNotify($msg);
             Log::info("submitOrderNotify:".formatLogData($res));
             if($res){
                 return json(["err_no"=>0,"err_tips"=>"","data"=>$res], 200);
@@ -248,7 +248,10 @@ class DouYinController extends BaseApiController
             $params = $this->request->post();
             Log::info('payNotify:'.formatLogData($params));
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
-            if(DouYinService::payNotify($msg)){
+            if($params['type'] == 'payment' && DouYinService::payNotify($msg)){
+                return json(["err_no"=>0,"err_tips"=>""], 200);
+            }
+            if($params['type'] == 'refund'){
                 return json(["err_no"=>0,"err_tips"=>""], 200);
             }
         } catch (\Exception $e) {
@@ -261,7 +264,10 @@ class DouYinController extends BaseApiController
             $params = $this->request->post();
             Log::info('payTailNotify:'.formatLogData($params));
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
-            if(DouYinService::payTailNotify($msg)){
+            if($params['type'] == 'payment' && DouYinService::payTailNotify($msg)){
+                return json(["err_no"=>0,"err_tips"=>""], 200);
+            }
+            if($params['type'] == 'refund'){
                 return json(["err_no"=>0,"err_tips"=>""], 200);
             }
         } catch (\Exception $e) {

+ 74 - 7
app/api/service/DouYinService.php

@@ -19,6 +19,7 @@ use app\common\model\recharge\RechargeOrder;
 use app\common\model\user\User;
 use app\common\model\user\UserAuth;
 use app\common\model\works\ServiceWork;
+use app\common\model\works\ServiceWorkLog;
 use app\common\service\ConfigService;
 use app\common\service\FileService;
 use GuzzleHttp\Client;
@@ -440,6 +441,48 @@ class DouYinService
             throw new \Exception($e->getMessage());
         }
     }
+
+
+    public static function refundOrderNotify($params = [])
+    {
+        try {
+            // 抖音单取消
+            $douyinOrder = DouyinOrder::where(['order_number'=>$params['out_order_no']??0])->findOrEmpty();
+            if(!$douyinOrder->isEmpty()){
+                $douyinOrder->status = 4;
+                $douyinOrder->save();
+                // 有工单则工单取消
+                if($douyinOrder->work_id){
+                    // 工单信息
+                    $service_work = ServiceWork::where('id',$douyinOrder->work_id)->findOrEmpty();
+                    if($service_work->isEmpty()) return true;
+                    // 取消工单
+                    if($service_work->work_status < 7){
+                        //更新工单状态为已取消并退款
+                        $service_work->service_status = 4;
+                        $service_work->work_status = 9;
+                        $service_work->user_confirm_status = 5;
+                        $service_work->save();
+                        ServiceWorkLog::create([
+                            'work_id' => $service_work->id,
+                            'master_worker_id' => $service_work->master_worker_id,
+                            'opera_log' => "工单:{$service_work->work_sn} 取消并终止结束服务"
+                        ]);
+                    }
+                }
+            }
+            return [
+                "out_order_no" => $params['out_order_no'],
+                "order_entry_schema" => [
+                    "path" => "pages/order/detail",
+                    "params" => json_encode(['order_number' => $params['out_order_no']])
+                ]
+            ];
+        } catch (\Exception $e) {
+            throw new \Exception($e->getMessage());
+        }
+    }
+
     // ++++++++++++++++++++ 首次创单
     /**
      * 预下单扩展点-子
@@ -817,22 +860,43 @@ class DouYinService
         // $params['order_number']
         Db::startTrans();
         try {
-            $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
-            if(!$order->isEmpty()){
-                if($order->order_status == 1 && $order->pay_status == 0){
-                    $order->order_status = 4;
-                    $order->save();
+            $douyinOrder = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
+            if(!$douyinOrder->isEmpty()){
+                if($douyinOrder->order_status == 1 && $douyinOrder->pay_status == 0){
+                    $douyinOrder->order_status = 4;
+                    $douyinOrder->save();
+
+                    // 有工单则工单取消
+                    if($douyinOrder->work_id){
+                        // 工单信息
+                        $service_work = ServiceWork::where('id',$douyinOrder->work_id)->findOrEmpty();
+                        if($service_work->isEmpty()) return true;
+                        // 取消工单
+                        if($service_work->work_status < 7){
+                            //更新工单状态为已取消并退款
+                            $service_work->service_status = 4;
+                            $service_work->work_status = 9;
+                            $service_work->user_confirm_status = 5;
+                            $service_work->save();
+                            ServiceWorkLog::create([
+                                'work_id' => $service_work->id,
+                                'master_worker_id' => $service_work->master_worker_id,
+                                'opera_log' => "工单:{$service_work->work_sn} 取消并终止结束服务"
+                            ]);
+                        }
+                    }
                 }else{
                     throw new \Exception('订单状态不可取消!');
                 }
             }
             Db::commit();
-            return $order['id'];
+            return $douyinOrder['id'];
         } catch (\Exception $e) {
             Db::rollback();
             throw new \Exception($e->getMessage());
         }
     }
+    // 申请退款
     public static function refund($params)
     {
         Db::startTrans();
@@ -859,13 +923,15 @@ class DouYinService
             ]);
 
             Db::commit();
-
+            // 默认审核通过
+            self::refundExamine(['is_examine_ok'=>'pass','order_number'=>$params['order_number']]);
             return true;
         } catch (\Exception $e) {
             Db::rollback();
             throw new \Exception($e->getMessage());
         }
     }
+    // 后台退款审核
     public static function refundExamine($params)
     {
         Db::startTrans();
@@ -908,6 +974,7 @@ class DouYinService
             throw new \Exception($e->getMessage());
         }
     }
+    // 后台审核通过 - 发送抖音退款申请
     public static function sendRefundCreate($order_number)
     {
         try {