Jelajahi Sumber

up - 调试参数

liugc 9 bulan lalu
induk
melakukan
64f6777058

+ 4 - 3
app/adminapi/controller/external/ExternalConsultationController.php

@@ -79,10 +79,11 @@ class ExternalConsultationController extends BaseAdminController
     {
         $params = (new ExternalConsultationValidate())->post()->goCheck('edit');
         $result = ExternalConsultationLogic::order($params);
-        if (true === $result) {
-            return $this->success('下单成功', [], 1, 1);
+        if (false === $result) {
+            return $this->fail(ExternalConsultationLogic::getError());
+
         }
-        return $this->fail(ExternalConsultationLogic::getError());
+        return $this->success('下单成功', [], 1, 1);
     }
 
 

+ 2 - 2
app/adminapi/logic/external/ExternalConsultationLogic.php

@@ -156,7 +156,7 @@ class ExternalConsultationLogic extends BaseLogic
                 //'work_id' => $work_id,
                 'remark' => $params['remark']
             ]);
-            ExternalConsultationOrder::create([
+            $consultationOrder = ExternalConsultationOrder::create([
                 'consultation_id' => $params['id'],
                 'user_address' => $params['user_address'],
                 'lon' => $params['lon'],
@@ -171,7 +171,7 @@ class ExternalConsultationLogic extends BaseLogic
 
             // 分配客服派单
             OnlineCustomerService::serviceWorkMessage($work_id);
-            return true;
+            return $consultationOrder['id'];
         } catch (\Exception $e) {
             Db::rollback();
             self::setError($e->getMessage());

+ 2 - 4
app/api/controller/DouYinController.php

@@ -34,7 +34,7 @@ use think\facade\Log;
 class DouYinController extends BaseApiController
 {
 
-    public array $notNeedLogin = ['testNotify','getClientToken','register','account','getAllGoods','getGoodsDetail','payNotify'];
+    public array $notNeedLogin = ['testNotify','getClientToken','register','account','getAllGoods','getGoodsDetail','submitOrderNotify','payNotify'];
 
     /**
      * 手机号注册
@@ -170,7 +170,7 @@ class DouYinController extends BaseApiController
             $params = $this->request->post();
             $params['user_id'] = $this->userId;
             $params['user_info'] = $this->userInfo;
-            $requestOrderData = DouYinService::getPluginCreateOrderData($params['goods_id']??'',$params['quantity']??1,$params['douyin_order_id']??'');
+            $requestOrderData = DouYinService::getPluginCreateOrderData($params['goods_id']??'',$params['quantity']??1,$params['douyin_order_id']??'',$params);
             return $this->success('',$requestOrderData);
         } catch (\Exception $e) {
             return $this->fail($e->getMessage());
@@ -181,8 +181,6 @@ class DouYinController extends BaseApiController
         try {
             $params = $this->request->post();
             $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
-            $msg['user_id'] = $this->userId;
-            $msg['user_info'] = $this->userInfo;
             $res = DouYinService::submitOrderNotify($msg);
             if($res){
                 return json(["err_no"=>0,"err_tips"=>"success","data"=>$res], 200);

+ 75 - 23
app/api/service/DouYinService.php

@@ -7,6 +7,7 @@ use app\api\logic\ServiceOrderLogic;
 use app\common\model\Config;
 use app\common\model\external\DouyinOrder;
 use app\common\model\external\DouyinRefundOrder;
+use app\common\model\external\DouyinUserAuth;
 use app\common\model\external\ExternalConsultation;
 use app\common\model\external\ExternalConsultationOrder;
 use app\common\model\external\ExternalPlatformGoods;
@@ -82,6 +83,41 @@ class DouYinService
         }
     }
 
+
+    public static function getDouyinUserByOpenId(array $openId)
+    {
+        try {
+            $user = DouyinUserAuth::where('openid',$openId)->findOrEmpty();
+            if ($user->isEmpty()) {
+                //直接注册用户
+                $params['channel'] = self::$terminal;
+                $user = self::register($params);
+            }
+            //更新登录信息
+            $user->login_time = time();
+            $user->login_ip = request()->ip();
+            $user->save();
+
+            $userInfo = UserTokenService::setToken($user->id, self::$terminal);
+
+            //返回登录信息
+            $avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
+            $avatar = FileService::getFileUrl($avatar);
+
+            return [
+                'nickname' => $userInfo['nickname'],
+                'sn' => $userInfo['sn'],
+                'mobile' => $userInfo['mobile'],
+                'avatar' => $avatar,
+                'token' => $userInfo['token'],
+            ];
+        } catch (\Exception $e) {
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+
+
     // **************************** 商品管理 goods_category_id goods_id external_platform_id
     public static function addProduct($params)
     {
@@ -143,7 +179,7 @@ class DouYinService
     }
 
     // 预下单接口 - 前端  首次/尾款
-    public static function getPluginCreateOrderData($goods_id, $quantity, $douyinOrderId)
+    public static function getPluginCreateOrderData($goods_id, $quantity, $douyinOrderId,$params)
     {
         try {
             $goods = Goods::where('id',$goods_id)->findOrEmpty();
@@ -170,7 +206,7 @@ class DouYinService
                     [
                         "quantity" => $quantity,
                         "skuId" => (string)$platformGoods['external_goods_sn'],
-                        "skuType" => 2,
+                        "skuType" => 1, // 1:商品库商品  2:非商品库商品(融合预约品走加价时,固定传2)
                         "price" => $platformGoods['service_fee'] * 100,
                     ]
                 ],
@@ -194,6 +230,7 @@ class DouYinService
                     "outShopId" => self::EXTERNAL_PLATFORM_ID,
                     "skuId" => (string)$platformGoods['external_goods_sn'],
                     "quantity" => $quantity,
+                    "user_id" => $params['user_id'],
                     "douyinOrderId" => $douyinOrderId?:0,
                 ],
                 /*"tradeOption" => json_encode([
@@ -237,11 +274,8 @@ class DouYinService
         try {
             $params['external_platform_id'] = self::EXTERNAL_PLATFORM_ID;
             // order_id goods  total_amount discount cp_extra create_order_time phone_num contact_name open_id
-            if(empty($params['phone_num'])){
-                throw new \Exception('手机号不能为空!');
-            }
-            $user_id = $params['user_id'];
-
+            $user_id = $params['cp_extra']['user_id'];
+            $user = User::where('id',$user_id)->findOrEmpty();
             if($params['cp_extra']['douyinOrderId']>0){ // 说明是尾款单
                 // 创建尾款单
                 $order_number = self::tailOrder([
@@ -254,9 +288,11 @@ class DouYinService
             }else{
                 // 创建首单 goods_id  user_info.mobile  user_id quantity
                 $order_number = self::submitOrder([
+                    'open_id'=>$params['open_id'],
+                    'order_id'=>$params['order_id'], // 抖音订单号
                     'goods_id'=>$params['cp_extra']['skuId'],
                     'user_id'=>$user_id??0,
-                    'mobile'=>$params['phone_num'],
+                    'mobile'=>$user['mobile']??'',
                     'quantity'=>$params['cp_extra']['quantity']
                 ]);
             }
@@ -287,6 +323,10 @@ class DouYinService
             if($goods->isEmpty()){
                 throw new \Exception('产品不存在!');
             }
+            $platformGoods = ExternalPlatformGoods::where('goods_id', $params['goods_id'])->where('external_platform_id', self::EXTERNAL_PLATFORM_ID)->findOrEmpty();
+            if($platformGoods->isEmpty()){
+                throw new \Exception('产品不存在!');
+            }
             if(empty($params['mobile'])){
                 throw new \Exception('请先补充您的联系方式后在提交订单');
             }
@@ -300,12 +340,14 @@ class DouYinService
             $create_data = [
                 'user_id' => $params['user_id'],
                 'mobile' => $params['mobile'],
+                'open_id' => $params['open_id'],
+                'goods_id'=>$goods['id'],
                 'title' => $goods['goods_name'],
 
-                'goods_id'=>$goods['id'],
-                'unit_price' => $goods['service_fee'],
+                'unit_price' => $platformGoods['service_fee'],
                 'quantity' => $quantity,
-                'total_amount' => $goods['service_fee'] * $quantity,
+                'total_amount' => $platformGoods['service_fee'] * $quantity,
+                'dy_order_id' => $params['order_id']??'',
                 'order_number' => generate_sn(DouyinOrder::class, 'order_number'),
             ];
             $order = DouyinOrder::create($create_data);
@@ -448,18 +490,21 @@ class DouYinService
                 $consultation['lon'] = $params['lon'];
                 $consultation['lat'] = $params['lat'];
                 $consultation['appointment_time'] = $params['appointment_time'];
-                $result = ExternalConsultationLogic::order($consultation);
-                if (false === $result) {
+                $consultationOrderId = ExternalConsultationLogic::order($consultation);
+                if (false === $consultationOrderId) {
                     throw new \Exception('预约失败');
                 }
-                if(!empty($result)){
-                    $consultationOrder = ExternalConsultationOrder::where('consultation_id', $order->consultation_id)->where('goods_id', $order->goods_id)->where('amount', $order->paid_amount)
-                        ->findOrEmpty()->toArray();
+                if(!empty($consultationOrderId)){
+                    $consultationOrder = ExternalConsultationOrder::where('id', $consultationOrderId)->findOrEmpty()->toArray();
                     $work_status = ServiceWork::where('id', $consultationOrder['work_id'])->value('work_status');
                     $order->work_id = $consultationOrder['work_id'];
                     $order->fulfillment_status = $work_status;
                     $order->save();
                 }
+                $params['dy_order_id'] = $order->dy_order_id;
+                $params['consultationOrderId'] = $consultationOrderId;
+                $params['open_id'] = $order->open_id;
+                $params['goods_id'] = $order->goods_id;
             }
             Db::commit();
 
@@ -484,18 +529,25 @@ class DouYinService
     public static function getCreateBookParams($params)
     {
         try {
+            $platformGoods = ExternalPlatformGoods::where('goods_id', $params['goods_id'])->where('external_platform_id', self::EXTERNAL_PLATFORM_ID)->findOrEmpty();
+            if($platformGoods->isEmpty()){
+                throw new \Exception('产品不存在!');
+            }
+            $appointment_time = strtotime($params['appointment_time']);
+            $book_start_time = $appointment_time * 1000;
+            $book_end_time = ($appointment_time + (2 * 86400)) * 1000;
             $data = [
-                "order_id"=> $params['order_number']??'',
-                "out_book_no"=> time()??'',
-                "open_id"=> $params['open_id']??'',
+                "order_id"=> (string)$params['dy_order_id']??'',
+                "out_book_no"=> (string)$params['consultationOrderId']??'',
+                "open_id"=> (string)$params['open_id']??'',
                 "item_book_info_list" => [
                     [
                         "poi_id" => '7511543640776017961',
                         "shop_name" => '亿蜂快修·武汉市',
-                        "ext_shop_id" => self::EXTERNAL_PLATFORM_ID,
-                        "goods_id" => (string)$params['external_goods_sn'],
-                        "book_start_time" => $params['book_start_time']??'',
-                        "book_end_time" => $params['book_end_time']??'',
+                        "ext_shop_id" => (string)self::EXTERNAL_PLATFORM_ID,
+                        "goods_id" => (string)$platformGoods->external_goods_sn,
+                        "book_start_time" => (int)$book_start_time??0,
+                        "book_end_time" => (int)$book_end_time??0,
                     ]
                 ]
             ];

+ 10 - 0
app/common/model/external/DouyinUserAuth.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace app\common\model\external;
+
+use app\common\model\BaseModel;
+
+class DouyinUserAuth extends BaseModel
+{
+    protected $name = 'douyin_user_auth';
+}