liugc 9 months ago
parent
commit
35d2df14a7
2 changed files with 79 additions and 0 deletions
  1. 14 0
      app/api/controller/DouYinController.php
  2. 65 0
      app/api/service/DouYinService.php

+ 14 - 0
app/api/controller/DouYinController.php

@@ -185,6 +185,20 @@ class DouYinController extends BaseApiController
 
 
 
 
     // ******************************** 订单业务
     // ******************************** 订单业务
+    public function createOrder()
+    {
+        try {
+            $params = $this->request->post();
+            $params['user_id'] = $this->userId;
+            $params['user_info'] = $this->userInfo;
+            $requestOrderData = DouYinService::createOrder($params);
+            return $this->success('',$requestOrderData);
+        } catch (\Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
+
+
     /**
     /**
      * 拉起支付所需参数
      * 拉起支付所需参数
      * @return \think\response\Json
      * @return \think\response\Json

+ 65 - 0
app/api/service/DouYinService.php

@@ -179,6 +179,71 @@ class DouYinService
         return $orderInfo;
         return $orderInfo;
     }
     }
 
 
+
+    public static function createOrder($params)
+    {
+        try {
+            $goods_id = $params['goods_id']??0;
+            $open_id = '_000o7ntqTR--_hCTBOBCSR_NJkyp_hiqlEK';
+            $goods = Goods::where('id',$goods_id)->findOrEmpty();
+            if($goods->isEmpty()){
+                throw new \Exception('商品不存在!');
+            }
+            $goods = $goods->toArray();
+            $platformGoods = ExternalPlatformGoods::where('goods_id', $goods_id)->where('external_platform_id', self::EXTERNAL_PLATFORM_ID)->findOrEmpty();
+            if($platformGoods->isEmpty()){
+                throw new \Exception('外部商品不存在!');
+            }
+            $platformGoods = $platformGoods->toArray();
+            $quantity = $params['quantity']?:1;
+            $appointment_time = strtotime($params['appointment_time']??date('Y-m-d H:i:s',time()));
+            $bookStartTime = $appointment_time * 1000;
+            $bookEndTime = ($appointment_time + (2 * 86400)) * 1000;
+
+            $order_number = self::submitOrder([
+                'open_id'=>$open_id,
+                'goods_id'=>$goods_id,
+                'user_id'=>$params['user_id']??0,
+                'mobile'=>$params['user_info']['mobile']??'',
+                'quantity'=>$quantity
+            ]);
+
+            $data = [
+                "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])],
+                "cp_extra" => json_encode([
+                    "outShopId" => self::EXTERNAL_PLATFORM_ID,
+                    "skuId" => (string)$platformGoods['external_goods_sn'],
+                    "quantity" => $quantity,
+                    "user_id" => $params['user_id']
+                ]),
+                "goods_list" => [
+                    [
+                        "goods_id_type" => 1,
+                        "goods_id" => (string)$platformGoods['external_goods_sn'],
+                        "quantity" => 1
+                    ]
+                ],
+                "goods_book_info" => [
+                    "book_type" => 2,
+                    "cancel_policy" => 3,
+                    "cancel_advance_hour" => 5
+                ],
+            ];
+            // 服务器向抖音发起创建订单
+            $url = 'api/apps/trade/v2/order/create_order';
+            $resData = self::toDyRequestUrl($url,$data);
+
+            return $resData;
+        } catch (\Exception $e) {
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+
+
     // 预下单接口 - 前端  首次/尾款
     // 预下单接口 - 前端  首次/尾款
     public static function getPluginCreateOrderData($goods_id, $quantity, $douyinOrderId,$params)
     public static function getPluginCreateOrderData($goods_id, $quantity, $douyinOrderId,$params)
     {
     {