Răsfoiți Sursa

add - 尾款状态更新

liugc 9 luni în urmă
părinte
comite
0d37fc76fc
1 a modificat fișierele cu 68 adăugiri și 3 ștergeri
  1. 68 3
      app/api/service/DouYinService.php

+ 68 - 3
app/api/service/DouYinService.php

@@ -4,6 +4,8 @@ namespace app\api\service;
 
 use app\adminapi\logic\external\ExternalConsultationLogic;
 use app\api\logic\ServiceOrderLogic;
+use app\common\enum\PayEnum;
+use app\common\logic\PayNotifyLogic;
 use app\common\model\Config;
 use app\common\model\external\DouyinOrder;
 use app\common\model\external\DouyinRefundOrder;
@@ -146,7 +148,16 @@ class DouYinService
         empty($orderInfo['serviceWork']) && $orderInfo['serviceWork'] = [];
         empty($orderInfo['douyinRefundOrder']) && $orderInfo['douyinRefundOrder'] = [];
         $orderInfo['book_info'] = json_decode($orderInfo['book_info']?:'{}',true);
-
+        $rechargeOrder = RechargeOrder::where(['work_id'=>$orderInfo['work_id']?:0,'payment_type'=>2])->findOrEmpty();
+        if($rechargeOrder->isEmpty()){
+            $orderInfo['tail_order'] = [];
+        }else{
+            $orderInfo['tail_order'] = $rechargeOrder->toArray();
+            // 尾款未支付时 展示尾单信息加入临时总金额用于展示
+            if(isset($orderInfo['tail_order']['pay_status']) && $orderInfo['tail_order']['pay_status'] == 0){
+                $orderInfo['total_amount'] += $orderInfo['tail_order']['order_amount'];
+            }
+        }
         $work_status = $orderInfo['serviceWork']['work_status']??0;
         $performance = [];
         // tmp
@@ -213,7 +224,7 @@ class DouYinService
                 "total_amount" => $platformGoods['service_fee'] * $quantity * 100,
                 "open_id" => $open_id,
                 "out_order_no" => $order_number,
-                "order_entry_schema" => ['path'=>'pages/detail','params'=>json_encode(['goods_id'=>$goods['id']??0])],
+                "order_entry_schema" => ['path'=>'pages/order/detail','params'=>json_encode(['order_number'=>$order_number??0])],
                 "cp_extra" => json_encode([
                     "outShopId" => self::EXTERNAL_PLATFORM_ID,
                     "skuId" => (string)$platformGoods['external_goods_sn'],
@@ -533,6 +544,8 @@ class DouYinService
                     'pay_way' => 4
                 ];
                 RechargeOrder::create($order_data);
+            }else{
+                $sn = $rechargeOrder->sn;
             }
             Db::commit();
             return $sn;
@@ -553,6 +566,7 @@ class DouYinService
             $pay_time = time();
             $params['cp_extra'] = json_decode($params['cp_extra'], true);
             $work_id = DouyinOrder::where(['id'=>$params['cp_extra']['douyinOrderId']])->value('work_id')??0;
+
             $rechargeOrder = RechargeOrder::where(['work_id'=>$work_id,'sn'=>$out_order_no,'payment_type'=>2])->findOrEmpty();
             if(!$rechargeOrder->isEmpty()){
                 // 更新充值订单状态
@@ -563,6 +577,15 @@ class DouYinService
                 $rechargeOrder->save();
 
                 // 尾款订单支付成功后续操作 fun
+                //抖音订单服务完成
+                $order = DouyinOrder::where('id', $params['cp_extra']['douyinOrderId'])->findOrEmpty();
+                $order->order_status = 4;
+                $order->pay_status = 1;
+                $order->total_amount += $paid_amount;
+                $order->paid_amount += $paid_amount;
+                $order->save();
+                //工单完结
+                self::paymentSuccessful(['sn'=>$out_order_no,'pay_way'=>4]);
                 return true;
             }
         }elseif ($params['status'] === 'CANCEL' && $params['message'] == 'TIME_OUT'){
@@ -572,7 +595,49 @@ class DouYinService
         }
         return false;
     }
-
+    public static function paymentSuccessful($data = [])
+    {
+        try {
+            $params = $data;
+            $params['sn'] = mb_substr($params['sn'], 0, 18);
+            $order = RechargeOrder::where(['sn' => $params['sn']])->findOrEmpty();
+            if($order->isEmpty()) {
+                throw new \Exception('内部订单不存在:'.$params['sn'],404);
+            }
+            if($order->pay_status == PayEnum::ISPAID) {
+                return true;
+            }
+            if(!empty($params['pay_way']??'')) $params['extra']['pay_way'] = $params['pay_way'];
+            $payNotifyLogic = PayNotifyLogic::handle('goods', $params['sn'], $params['extra']??[]);
+            if($payNotifyLogic === true){
+                // 用户下单后,给订单运营专员(配置固定ID)发送公众号提醒(订单信息)
+                $order = RechargeOrder::where('sn', $params['sn'])
+                    ->where('payment_type','IN',[0,1])
+                    ->where('pay_status','=',1)
+                    ->findOrEmpty();
+                if(!$order->isEmpty()){
+                    $workDetail = ServiceWork::findOrEmpty($order->work_id);
+                    if(!$workDetail->isEmpty()){
+                        event('Notice',  [
+                            'scene_id' => 100,
+                            'params' => [
+                                'user_id' => 0,
+                                'order_id' => $workDetail['id'],
+                                'thing3' => $workDetail['title'],
+                                'time6' => $workDetail['appointment_time'],
+                                'phone_number8' => asteriskString($workDetail['mobile']),
+                                'thing5' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
+                            ]
+                        ]);
+                    }
+                }
+                return true;
+            }
+            throw new \Exception($payNotifyLogic,404);
+        }catch(\Exception $e){
+            throw new \Exception($e->getMessage());
+        }
+    }
     // ++++++++++++++++++++ 尾款创单 end