shish il y a 3 ans
Parent
commit
81a28db4bc
1 fichiers modifiés avec 39 ajouts et 137 suppressions
  1. 39 137
      console/controllers/MtController.php

+ 39 - 137
console/controllers/MtController.php

@@ -2,8 +2,6 @@
 
 namespace console\controllers;
 
-use common\components\noticeUtil;
-use common\components\oss;
 use common\components\util;
 use yii\console\Controller;
 use biz\shop\classes\ShopClass;
@@ -14,25 +12,11 @@ use common\components\dict;
 use common\components\httpUtil;
 use common\components\mtUtil;
 use Shishaoqi\MeituanFlashPurchase\Application;
-use linslin\yii2\curl;
 
 class MtController extends Controller
 {
 
-    public function actionCs()
-    {
-        $thirdOrderId = '82628691127252763';
-        $ext = ShopExtClass::getByCondition(['shopId' => 764], true);
-        $config = dict::getDict('mtConfig');
-        $app = new Application($config);
-        $accessToken = mtUtil::getAccessToken($ext);
-        $params = ['order_id' => $thirdOrderId, 'access_token' => $accessToken];
-        $mtRes = $app->order->logisticsPush($params);
-        $mtRes = json_decode($mtRes, true);
-        print_r($mtRes);
-    }
-
-    //同步商品 ssh 20220801
+    //美团里有的商品,但没同步到系统的进行同步;同时美团没有app_spu_code的,补充app_spu_code ssh 20220914
     public function actionSyncGoods()
     {
         global $argv;
@@ -63,7 +47,6 @@ class MtController extends Controller
         if (isset($arr['data']) == false || empty($arr['data'])) {
             util::stop('没有商品');
         }
-
         $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
         if (empty($mtCategory)) {
             $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
@@ -72,135 +55,54 @@ class MtController extends Controller
         if (empty($catId)) {
             util::stop('没有找到美团的商品分类');
         }
-
         $goodsList = $arr['data'];
         foreach ($goodsList as $key => $val) {
-
             $picture = $val['picture'] ?? '';
             $price = $val['price'] ?? 0;
             $name = $val['name'] ?? '';
-            $mtGoodsSpu = $val['app_spu_code'] ?? '';
-            $imgArr = explode(',', $picture);
-            if (empty($mtGoodsSpu)) {
-                noticeUtil::push('商家有商品没有spuId,' . $name, '15280215347');
-                continue;
-            }
-            $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $mtGoodsSpu], true);
-            if (!empty($current)) {
-
-            } else {
-                $shopImg = [];
-                foreach ($imgArr as $imgUrl) {
-                    $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
-                    $shopImg[] = $shortUrl;
+            $appSpuCode = $val['app_spu_code'] ?? '';
+            if (!empty($appSpuCode)) {
+                $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $appSpuCode], true);
+                if (!empty($current)) {
+                    continue;
                 }
-                $cover = $shopImg[0];
-                $goodsData = [
-                    'spu' => $mtGoodsSpu,
-                    'shopImg' => $shopImg,
-                    'name' => $name,
-                    'sjId' => $sjId,
-                    'mainId' => $mainId,
-                    'shopId' => $shopId,
-                    'catId' => $catId,
-                    'cover' => $cover,
-                    'unitGoodsPrice' => $price,
-                ];
-                GoodsClass::orderCreateGoods($goodsData);
             }
-        }
-    }
-
-    //同步商品 ssh 20220801
-    public function actionBc()
-    {
-        global $argv;
-
-        ini_set('memory_limit', '2045M');
-        set_time_limit(0);
-
-        $shopId = $argv[2] ?? 0;
-        if (empty($shopId)) {
-            util::stop('请填写门店id');
-        }
-        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
-        if (empty($ext)) {
-            util::stop('没有找到门店相信息');
-        }
-        $shop = ShopClass::getById($shopId, true);
-        if (empty($shop)) {
-            util::stop('没有找到门店');
-        }
-        $mainId = $shop->mainId ?? 0;
-        $sjId = $shop->sjId ?? 0;
-        $config = dict::getDict('mtConfig');
-        $app = new Application($config);
-        $accessToken = mtUtil::getAccessToken($ext);
-        $params = ['app_poi_code' => $shopId, 'access_token' => $accessToken];
-        $json = $app->retail->retailList($params);
-        $arr = json_decode($json, true);
-        if (isset($arr['data']) == false || empty($arr['data'])) {
-            util::stop('没有商品');
-        }
-
-        $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
-        if (empty($mtCategory)) {
-            $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
-        }
-        $catId = $mtCategory->id ?? 0;
-        if (empty($catId)) {
-            util::stop('没有找到美团的商品分类');
-        }
-
-        $goodsList = $arr['data'];
-        foreach ($goodsList as $key => $val) {
-            $picture = $val['picture'] ?? '';
-            $name = $val['name'] ?? '';
-            $mtGoodsSpu = $val['app_spu_code'] ?? '';
             $imgArr = explode(',', $picture);
-            if (empty($mtGoodsSpu)) {
-                noticeUtil::push('商家有商品没有spuId,' . $name, '15280215347');
-                continue;
+            $shopImg = [];
+            foreach ($imgArr as $imgUrl) {
+                $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
+                $shopImg[] = $shortUrl;
             }
-            $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $mtGoodsSpu], true);
-            if (!empty($current)) {
-                $shopImg = $current->shopImg;
-                $picArr = json_decode($shopImg, true);
-                $hasErr = false;
-                if (is_array($picArr)) {
-                    foreach ($picArr as $item) {
-                        $url = "https://img.wixhb.com/" . $item . '?x-oss-process=image/info';
-                        $curl = new curl\Curl();
-                        $result = $curl->get($url);
-                        $res = json_decode($result, true);
-                        if (isset($res['FileSize']) == false) {
-                            $hasErr = true;
-                        }
-                    }
-                }
-
-                $cover = $current->cover;
-                $url = "https://img.wixhb.com/" . $cover . '?x-oss-process=image/info';
-                $curl = new curl\Curl();
-                $result = $curl->get($url);
-                $res = json_decode($result, true);
-                if (isset($res['FileSize']) == false) {
-                    $hasErr = true;
-                }
-
-                if ($hasErr == true) {
-                    $newShopImg = [];
-                    foreach ($imgArr as $imgUrl) {
-                        $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
-                        $newShopImg[] = $shortUrl;
-                    }
-                    $current->shopImg = json_encode($newShopImg);
-                    $current->cover = $newShopImg[0];
-                    $current->save();
-                    print_r($imgArr);
-                    echo "\n";
-                    echo $current->name . " ok \n";
+            $cover = $shopImg[0];
+            $catIds = [$catId];
+            $addData = [
+                'name' => $name,
+                'flower' => 1,
+                'property' => 0,
+                'price' => $price,
+                'sjId' => $sjId,
+                'mainId' => $mainId,
+                'shopId' => $shopId,
+                'status' => 0,
+                'delStatus' => 0,
+                'shopImg' => $shopImg,
+                'catIds' => $catIds,
+                'cover' => $cover,
+                'spu' => $appSpuCode,
+            ];
+            $goods = GoodsClass::addGoods($addData);
+            $goodsId = $goods->id ?? 0;
+            if (empty($appSpuCode)) {
+                $newSpuCode = 'hzg_' . $mainId . '_' . $goodsId;
+                $end_category_code = $val['category_code'] ?? '';
+                if (isset($val['secondary_category_code']) && !empty($val['secondary_category_code'])) {
+                    $end_category_code = $val['secondary_category_code'];
                 }
+                $name = $val['name'] ?? '';
+                $params = ['app_poi_code' => $shopId, 'access_token' => $accessToken, 'name' => $name, 'category_code' => $end_category_code, 'app_spu_code' => $newSpuCode];
+                $app->retail->updateAppFoodCodeByNameAndSpec($params);
+                $goods->spu = $newSpuCode;
+                $goods->save();
             }
         }
     }