MtController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace console\controllers;
  3. use common\components\noticeUtil;
  4. use common\components\oss;
  5. use common\components\util;
  6. use yii\console\Controller;
  7. use biz\shop\classes\ShopClass;
  8. use biz\shop\classes\ShopExtClass;
  9. use bizHd\goods\classes\CategoryClass;
  10. use bizHd\goods\classes\GoodsClass;
  11. use common\components\dict;
  12. use common\components\httpUtil;
  13. use common\components\mtUtil;
  14. use Shishaoqi\MeituanFlashPurchase\Application;
  15. class MtController extends Controller
  16. {
  17. //同步商品 ssh 20220801
  18. public function actionSyncGoods()
  19. {
  20. global $argv;
  21. ini_set('memory_limit', '2045M');
  22. set_time_limit(0);
  23. $shopId = $argv[2] ?? 0;
  24. if (empty($shopId)) {
  25. util::stop('请填写门店id');
  26. }
  27. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  28. if (empty($ext)) {
  29. util::stop('没有找到门店相信息');
  30. }
  31. $shop = ShopClass::getById($shopId, true);
  32. if (empty($shop)) {
  33. util::stop('没有找到门店');
  34. }
  35. $mainId = $shop->mainId ?? 0;
  36. $sjId = $shop->sjId ?? 0;
  37. $config = dict::getDict('mtConfig');
  38. $app = new Application($config);
  39. $accessToken = mtUtil::getAccessToken($ext);
  40. $params = ['app_poi_code' => $shopId, 'access_token' => $accessToken];
  41. $json = $app->retail->retailList($params);
  42. $arr = json_decode($json, true);
  43. if (isset($arr['data']) == false || empty($arr['data'])) {
  44. util::stop('没有商品');
  45. }
  46. $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
  47. if (empty($mtCategory)) {
  48. $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
  49. }
  50. $catId = $mtCategory->id ?? 0;
  51. if (empty($catId)) {
  52. util::stop('没有找到美团的商品分类');
  53. }
  54. $goodsList = $arr['data'];
  55. foreach ($goodsList as $key => $val) {
  56. $picture = $val['picture'] ?? '';
  57. $price = $val['price'] ?? 0;
  58. $name = $val['name'] ?? '';
  59. $mtGoodsSpu = $val['app_spu_code'] ?? '';
  60. $imgArr = explode(',', $picture);
  61. if (empty($mtGoodsSpu)) {
  62. noticeUtil::push('商家有商品没有spuId,' . $name, '15280215347');
  63. continue;
  64. }
  65. $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $mtGoodsSpu], true);
  66. if (!empty($current)) {
  67. } else {
  68. $shopImg = [];
  69. foreach ($imgArr as $imgUrl) {
  70. $shortUrl = httpUtil::downloadRemoteImg($sjId, $shopId, $imgUrl);
  71. $shopImg[] = $shortUrl;
  72. }
  73. $cover = $shopImg[0];
  74. $goodsData = [
  75. 'spu' => $mtGoodsSpu,
  76. 'shopImg' => $shopImg,
  77. 'name' => $name,
  78. 'sjId' => $sjId,
  79. 'mainId' => $mainId,
  80. 'shopId' => $shopId,
  81. 'catId' => $catId,
  82. 'cover' => $cover,
  83. 'unitGoodsPrice' => $price,
  84. ];
  85. GoodsClass::orderCreateGoods($goodsData);
  86. }
  87. }
  88. }
  89. //同步商品 ssh 20220801
  90. public function actionBc()
  91. {
  92. global $argv;
  93. ini_set('memory_limit', '2045M');
  94. set_time_limit(0);
  95. $shopId = $argv[2] ?? 0;
  96. if (empty($shopId)) {
  97. util::stop('请填写门店id');
  98. }
  99. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  100. if (empty($ext)) {
  101. util::stop('没有找到门店相信息');
  102. }
  103. $shop = ShopClass::getById($shopId, true);
  104. if (empty($shop)) {
  105. util::stop('没有找到门店');
  106. }
  107. $mainId = $shop->mainId ?? 0;
  108. $sjId = $shop->sjId ?? 0;
  109. $config = dict::getDict('mtConfig');
  110. $app = new Application($config);
  111. $accessToken = mtUtil::getAccessToken($ext);
  112. $params = ['app_poi_code' => $shopId, 'access_token' => $accessToken];
  113. $json = $app->retail->retailList($params);
  114. $arr = json_decode($json, true);
  115. if (isset($arr['data']) == false || empty($arr['data'])) {
  116. util::stop('没有商品');
  117. }
  118. $mtCategory = CategoryClass::getByCondition(['mainId' => $mainId, 'style' => 1], true);
  119. if (empty($mtCategory)) {
  120. $mtCategory = CategoryClass::add(['style' => 1, 'categoryName' => '美团', 'mainId' => $mainId, 'sjId' => $sjId], true);
  121. }
  122. $catId = $mtCategory->id ?? 0;
  123. if (empty($catId)) {
  124. util::stop('没有找到美团的商品分类');
  125. }
  126. $goodsList = $arr['data'];
  127. foreach ($goodsList as $key => $val) {
  128. $picture = $val['picture'] ?? '';
  129. $price = $val['price'] ?? 0;
  130. $name = $val['name'] ?? '';
  131. $mtGoodsSpu = $val['app_spu_code'] ?? '';
  132. $imgArr = explode(',', $picture);
  133. if (empty($mtGoodsSpu)) {
  134. noticeUtil::push('商家有商品没有spuId,' . $name, '15280215347');
  135. continue;
  136. }
  137. $current = GoodsClass::getByCondition(['mainId' => $mainId, 'spu' => $mtGoodsSpu], true);
  138. if (!empty($current)) {
  139. $current->price = $price;
  140. $current->save();
  141. }
  142. }
  143. }
  144. public function actionCs()
  145. {
  146. $res = oss::getFile('/uploads/13116/764/202208/01/bec92376ed441fa79ae76abb3f277975.jpg');
  147. echo "\n";
  148. print_r($res);
  149. echo "\n";
  150. $res = oss::getFile('/uploads/13116/764/202208/01/98041ccb5eb3444d36e51122f88fb329.jpg');
  151. print_r($res);
  152. }
  153. }