$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'] ?? ''; $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; } $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'] ?? ''; $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)) { $current->price = $price; $current->save(); } } } public function actionCs() { $res = oss::getFile('/uploads/13116/764/202208/01/bec92376ed441fa79ae76abb3f277975.jpg'); echo "\n"; print_r($res); echo "\n"; $res = oss::getFile('/uploads/13116/764/202208/01/98041ccb5eb3444d36e51122f88fb329.jpg'); print_r($res); } }