Jelajahi Sumber

商品信息

shish 3 tahun lalu
induk
melakukan
0fe853abf9
1 mengubah file dengan 62 tambahan dan 15 penghapusan
  1. 62 15
      app-hd/controllers/MtController.php

+ 62 - 15
app-hd/controllers/MtController.php

@@ -28,28 +28,75 @@ class MtController extends PublicController
 
     public function actionGoodsAdd()
     {
-        $post = Yii::$app->request->post();
-        Yii::info('confirmOrderData: ' . Json::encode($post));
-        if(isset($post['retail_data'])){
-            Yii::info('confirmOrderData: ' . $post['retail_data']);
+        //$post = Yii::$app->request->post();
+
+        $str = '{"sig":"3595534244c625331cb9e8b35cc63b13","app_id":"119094","retail_data":"%5B%257B%2522app_food_code%2522%253A%2522mtcode_1568954379552215085%2522%252C%2522app_id%2522%253A119094%252C%2522app_poi_code%2522%253A%252236524%2522%252C%2522app_spu_code%2522%253A%2522mtcode_1568954379552215085%2522%252C%2522categoryList%2522%253A%255B%257B%2522categoryCode%2522%253A%2522%2522%252C%2522categoryName%2522%253A%2522%25E6%259C%25AA%25E5%2588%2586%25E7%25B1%25BB%2522%257D%255D%252C%2522categoryName%2522%253A%2522%25E6%259C%25AA%25E5%2588%2586%25E7%25B1%25BB%2522%252C%2522createAppKey%2522%253A%2522%25E5%2595%2586%25E5%25AE%25B6%25E7%25AB%25AF_%25E7%25A7%25BB%25E5%258A%25A8%25E7%25AB%25AF%2522%252C%2522ctime%2522%253A1662902846%252C%2522name%2522%253A%25229%25E6%259C%25B5%25E7%25BA%25A2%25E7%258E%25AB%25E7%2591%25B0%25E6%2590%25AD%25E9%2585%258D%25E6%25BB%25A1%25E5%25A4%25A9%25E6%2598%259F%25E9%25B2%259C%25E8%258A%25B1%25E8%258A%25B1%25E6%259D%259F%2522%252C%2522opName%2522%253A%2522%25E5%2595%2586%25E5%25AE%25B6%25E8%25B4%25A6%25E5%258F%25B7112823666%2522%252C%2522timestamp%2522%253A1662902848%252C%2522utime%2522%253A1662902846%257D%5D","timestamp":"1662902848"}';
+        $post = json_decode($str, true);
+
+        if (isset($post['retail_data']) == false) {
+            noticeUtil::push("美团添加商品,通知我们时出错了,没有获取到相应信息", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $retailData = $post['retail_data'];
+        $retail = urldecode(urldecode($retailData));
+        $shopId = $retail['app_poi_code'] ?? 0;
+        $shop = ShopClass::getById($shopId, true);
+        if (empty($shop)) {
+            noticeUtil::push("美团添加商品,通知我们时出错了,没有找到门店", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+        if (empty($ext)) {
+            noticeUtil::push("美团添加商品,通知我们时出错了,没有找到门店拓展信息", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $mainId = $shop->mainId ?? 0;
+        if (empty($mainId)) {
+            noticeUtil::push("美团添加商品,通知我们时出错了,没有main信息", '15280215347');
+            return Json::encode(['data' => 'ok']);
         }
+        $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
+        if (empty($mtCategory)) {
+            $sjId = $shop->sjId ?? 0;
+            $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
+        }
+        $catId = $mtCategory->id ?? 0;
+        if (empty($catId)) {
+            noticeUtil::push("美团添加商品,通知我们时出错了,没有美团的分类id", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+
+        $config = dict::getDict('mtConfig');
+        $app = new Application($config);
+        $accessToken = mtUtil::getAccessToken($ext);
+
+        $app_spu_code = $retail['app_spu_code'] ?? '';
 
+        $params = ['app_poi_code' => $shopId, 'app_spu_code' => $app_spu_code, 'access_token' => $accessToken];
+        $mgGoodsDetail = $app->retail->getDetail($params);
+        Yii::info('获取商品详情:' . $mgGoodsDetail . ' ' . json_encode($params));
         return Json::encode(['data' => 'ok']);
 
-        $str = '{"sig":"3595534244c625331cb9e8b35cc63b13","app_id":"119094","retail_data":"%5B%257B%2522app_food_code%2522%253A%2522mtcode_1568954379552215085%2522%252C%2522app_id%2522%253A119094%252C%2522app_poi_code%2522%253A%252236524%2522%252C%2522app_spu_code%2522%253A%2522mtcode_1568954379552215085%2522%252C%2522categoryList%2522%253A%255B%257B%2522categoryCode%2522%253A%2522%2522%252C%2522categoryName%2522%253A%2522%25E6%259C%25AA%25E5%2588%2586%25E7%25B1%25BB%2522%257D%255D%252C%2522categoryName%2522%253A%2522%25E6%259C%25AA%25E5%2588%2586%25E7%25B1%25BB%2522%252C%2522createAppKey%2522%253A%2522%25E5%2595%2586%25E5%25AE%25B6%25E7%25AB%25AF_%25E7%25A7%25BB%25E5%258A%25A8%25E7%25AB%25AF%2522%252C%2522ctime%2522%253A1662902846%252C%2522name%2522%253A%25229%25E6%259C%25B5%25E7%25BA%25A2%25E7%258E%25AB%25E7%2591%25B0%25E6%2590%25AD%25E9%2585%258D%25E6%25BB%25A1%25E5%25A4%25A9%25E6%2598%259F%25E9%25B2%259C%25E8%258A%25B1%25E8%258A%25B1%25E6%259D%259F%2522%252C%2522opName%2522%253A%2522%25E5%2595%2586%25E5%25AE%25B6%25E8%25B4%25A6%25E5%258F%25B7112823666%2522%252C%2522timestamp%2522%253A1662902848%252C%2522utime%2522%253A1662902846%257D%5D","timestamp":"1662902848"}';
-        $arr = json_decode($str, true);
-        echo '<pre>';print_r($arr);die;
-        if (isset($arr['retail_data']) == false) {
-            noticeUtil::push("美团添加商品,通知我们时出错了,没有获取到相应信息", '15280215347');
+        $mgGoodsDetail = json_decode($mgGoodsDetail, true);
+        if (isset($mgGoodsDetail['error'])) {
+            noticeUtil::push("美团添加商品,通知我们时出错了,没有找到商品图片", '15280215347');
+            return Json::encode(['data' => 'ok']);
+        }
+        $imgString = $mgGoodsDetail['data']['picture'] ?? '';
+        if (empty($imgString)) {
+            noticeUtil::push("美团添加商品,通知我们时出错了,,没有商品图片...", '15280215347');
             return Json::encode(['data' => 'ok']);
         }
-        $retailData = $arr['retail_data'];
-        echo $retailData;die;
-        $retail = json_decode($retailData,true);
-        echo "<pre>";
-        print_r($retail);die;
-        die;
+        noticeUtil::push("美团添加商品,通知我们,商品图片:" . $imgString, '15280215347');
+
+        $goodsName = $mtGoods['food_name'] ?? '';
+        $goodsPrice = $mtGoods['price'] ?? 0;
+        $hasGoods = GoodsClass::getByCondition(['spu' => $mtGoodsSpu], true);
 
+        $imgArr = explode(',', $imgString);
+        foreach ($imgArr as $imgUrl) {
+            $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
+        }
         return Json::encode(['data' => 'ok']);
     }