liugc 9 месяцев назад
Родитель
Сommit
82c2a06f7b
1 измененных файлов с 12 добавлено и 11 удалено
  1. 12 11
      app/api/service/DouYinService.php

+ 12 - 11
app/api/service/DouYinService.php

@@ -902,20 +902,20 @@ class DouYinService
         Db::startTrans();
         try {
             // $params['order_number']  user_id
-            $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
+            $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->findOrEmpty();
             if($order->isEmpty()){
                 throw new \Exception('订单不存在');
             }
             $orderInfo = $order->toArray();
             $work_status = $orderInfo['serviceWork']['work_status']??0;
             if(3 < $work_status){
-                throw new \Exception('该订单禁止退款');
+                //throw new \Exception('该订单禁止退款');
             }
 
             DouyinRefundOrder::create([
                 'refund_number' => generate_sn(DouyinRefundOrder::class, 'refund_number'),
                 'order_number' => $orderInfo['order_number'],
-                'transaction_id' => $orderInfo['transaction_id'],
+                'transaction_id' => $params['transaction_id']??'',
                 'reason' => $params['reason']??'',
                 'refund_status' => 0,
                 'user_id' => $orderInfo['user_id'],
@@ -924,7 +924,7 @@ class DouYinService
 
             Db::commit();
             // 默认审核通过
-            self::refundExamine(['is_examine_ok'=>'pass','order_number'=>$params['order_number']]);
+            //self::refundExamine(['is_examine_ok'=>'pass','order_number'=>$params['order_number']]);
             return true;
         } catch (\Exception $e) {
             Db::rollback();
@@ -1052,17 +1052,21 @@ class DouYinService
     }
 
 
-
+    // 抖音申请退款回调
     public static function refundNotify($params)
     {
         Db::startTrans();
         try {
-            $douyinRefundOrder = DouyinRefundOrder::where('refund_number', $params['out_refund_no'])->findOrEmpty();
+            // $params['refund_id']  $params['out_order_no']
+            // 前端组件申请退款---抖音回调申请退款通知---我方生成退款订单并审核---审核通过通知抖音“同意退款”---完成
+            $douyinRefundOrder = DouyinRefundOrder::where('transaction_id', $params['refund_id'])->order('id', 'desc')->findOrEmpty();
             if($douyinRefundOrder->isEmpty()){
-                throw new \Exception('退款订单不存在');
+                // transaction_id order_number reason
+                self::refund(['order_number'=>$params['out_order_no'],'transaction_id'=>$params['refund_id'],'reason'=>is_array($params['refund_reason']??[])?$params['refund_reason'][0]??'':'']);
+                $douyinRefundOrder = DouyinRefundOrder::where('transaction_id', $params['refund_id'])->order('id', 'desc')->findOrEmpty();
             }
             if($douyinRefundOrder->refund_status == 0){
-
+                $douyinRefundOrder->transaction_id = 3;
                 $douyinRefundOrder->refund_status = 3;
                 DouyinOrder::where('order_number', $douyinRefundOrder->order_number)->update([
                     'order_status' => 4,
@@ -1083,9 +1087,6 @@ class DouYinService
                 $douyinRefundOrder->save();
             }
             Db::commit();
-
-            //通过后同意退款审核结果
-            self::sendRefundMerchant($douyinRefundOrder->order_number);
             return true;
         } catch (\Exception $e) {
             Db::rollback();