GhsController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php
  2. namespace hd\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\shop\classes\ShopClass;
  5. use bizGhs\custom\classes\AccountMoneyClass;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\custom\classes\CustomLevelClass;
  8. use bizGhs\merchant\classes\WlClass;
  9. use bizGhs\order\classes\ShMethodClass;
  10. use bizGhs\shop\classes\GhsNoticeClass;
  11. use bizHd\purchase\classes\PurchaseClass;
  12. use bizHd\shop\classes\ShopExtClass;
  13. use bizGhs\stat\classes\StatVisitClass;
  14. use common\components\dict;
  15. use common\components\imgUtil;
  16. use common\components\mapUtil;
  17. use common\components\noticeUtil;
  18. use common\components\qrCodeUtil;
  19. use common\components\stringUtil;
  20. use common\components\util;
  21. use Yii;
  22. class GhsController extends BaseController
  23. {
  24. public $guestAccess = ['info', 'get-ghs-data', 'detail', 'common-info', 'ghs-notice-detail'];
  25. //根据自定义价格,计算跑腿费用 ssh 20270730
  26. public function actionCalcCustomPtFee()
  27. {
  28. $get = Yii::$app->request->get();
  29. $id = $get['id'] ?? 0;
  30. $sendType = $get['sendType'] ?? 2;
  31. $ghs = GhsClass::getById($id, true);
  32. if (empty($ghs)) {
  33. util::fail('没有找到批发店');
  34. }
  35. if (!isset($ghs->ownShopId) || $ghs->ownShopId != $this->shopId) {
  36. util::fail('不是你的批发店');
  37. }
  38. $customId = $ghs->customId ?? 0;
  39. $custom = CustomClass::getById($customId, true);
  40. if (empty($custom)) {
  41. util::success(['sendCost' => 0, 'sendDistance' => 0]);
  42. }
  43. $ghsShopId = $ghs->shopId ?? 0;
  44. $ghsMainId = $ghs->mainId ?? 0;
  45. $shCurrentConfig = shMethodClass::getConfig($ghsShopId, $ghsMainId, $sendType);
  46. //使用自定义计算费用
  47. $startKm = $shCurrentConfig['startKm'] ?? 0;
  48. $startPrice = $shCurrentConfig['startPrice'] ?? 0;
  49. $perKmPrice = $shCurrentConfig['perKmPrice'] ?? 0;//超出起步,每公里加收金额
  50. $changeRate = $shCurrentConfig['changeRate'] ?? 0;//负值时为降价百分比,正值时为涨价百分比
  51. if ($startKm <= 0 || $startPrice <= 0 || $perKmPrice <= 0) {
  52. util::success(['sendCost' => 0, 'distanceKm' => 0, 'distance' => 0]);
  53. }
  54. //计算客户到店的距离,骑电动车
  55. $distanceRespond = mapUtil::calcShopDistanceByEleBike($custom, $ghs, 0);
  56. $sendDistance = $distanceRespond['distanceKm'] ?? 0;
  57. $distance = $distanceRespond['distance'] ?? 0;
  58. $distance = floatval($distance);
  59. $sendDistance = floatval($sendDistance);
  60. if ($sendDistance <= 0) {
  61. util::success(['sendCost' => 0, 'distanceKm' => 0, 'distance' => 0]);
  62. }
  63. // 计算运费逻辑
  64. $sendCost = $startPrice;
  65. if ($sendDistance > $startKm) {
  66. $extraDistance = bcsub($sendDistance, $startKm, 2);
  67. $extraCost = bcmul($extraDistance, $perKmPrice, 2);
  68. $sendCost = bcadd($sendCost, $extraCost, 2);
  69. }
  70. if ($changeRate != 0) {
  71. // 临时涨价/降价百分比
  72. $rate = bcadd(1, bcdiv($changeRate, 100, 4), 4);
  73. $sendCost = bcmul($sendCost, $rate, 2);
  74. }
  75. $sendCost = floatval($sendCost);
  76. util::success(['sendCost' => $sendCost, 'distanceKm' => $sendDistance, 'distance' => $distance]);
  77. }
  78. //提示花店有多个供货商
  79. public function actionRemindMoreGhs()
  80. {
  81. $where = [];
  82. $where['ownShopId'] = $this->shopId;
  83. $where['delStatus'] = 0;
  84. $count = GhsClass::getCount($where);
  85. $needNotice = 0;
  86. if ($count > 1) {
  87. $admin = $this->admin;
  88. $noticeHasMoreGhs = $admin->noticeHasMoreGhs ?? 0;
  89. if ($noticeHasMoreGhs == 0) {
  90. $needNotice = 1;
  91. }
  92. }
  93. util::success(['needNotice' => $needNotice]);
  94. }
  95. public static $levelMap = [
  96. 'pt' => ['name' => '普店', 'num' => 0, 'amount' => 0, 'key' => ''],
  97. 'hj' => ['name' => '银店', 'num' => 0, 'amount' => 0, 'key' => 'hj'],
  98. 'zs' => ['name' => '金店', 'num' => 0, 'amount' => 0, 'key' => 'zs'],
  99. ];
  100. //未登录获取供货商信息 ssh 20240507
  101. public function actionGetGhsData()
  102. {
  103. $get = Yii::$app->request->get();
  104. $id = $get['id'] ?? 0;
  105. $salt = $get['salt'] ?? '';
  106. $ghs = GhsClass::getById($id);
  107. if (empty($ghs)) {
  108. util::fail('没有找到供货商的信息哦');
  109. }
  110. if (!empty($salt)) {
  111. if (!isset($ghs['salt']) || $ghs['salt'] != $salt) {
  112. util::fail('不是您的供货商哈');
  113. }
  114. } else {
  115. if (!isset($ghs['ownShopId']) || $ghs['ownShopId'] != $this->shopId) {
  116. util::fail('不是你的供货商呢');
  117. }
  118. }
  119. $customId = $ghs['customId'] ?? 0;
  120. $custom = CustomClass::getById($customId);
  121. if (empty($custom)) {
  122. util::fail('供货商信息不完整');
  123. }
  124. // 挂账已并入净 balance:按 appVersion 格式化金额字段(v3 下 balance 负值=待结)
  125. $ghs = AccountMoneyClass::formatMoneyForClient(is_array($ghs) ? $ghs : $ghs->getAttributes());
  126. $custom = AccountMoneyClass::formatMoneyForClient(is_array($custom) ? $custom : $custom->getAttributes());
  127. //有同个地方要同步修改,关键词 custom_go_ghs_gathering_code
  128. if (getenv('YII_ENV') == 'production') {
  129. $url = "https://mall.huahb.cn/#/admin/ghs/pay?id={$id}&salt={$salt}";
  130. } else {
  131. $url = "https://mall.huaml.com/#/admin/ghs/pay?id={$id}&salt={$salt}";
  132. }
  133. $unique = "recharge_to_ghs_" . $id;
  134. $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
  135. $imageUrl = imgUtil::groupImg($imgUrl);
  136. util::success(['ghs' => $ghs, 'custom' => $custom, 'imgUrl' => $imageUrl]);
  137. }
  138. //获取物流列表 ssh 20230608
  139. public function actionGetWlList()
  140. {
  141. $get = Yii::$app->request->get();
  142. $id = $get['id'] ?? 0;
  143. $ghs = GhsClass::getById($id, true);
  144. if (empty($ghs)) {
  145. util::success(['list' => []]);
  146. }
  147. $mainId = $ghs->mainId ?? 0;
  148. $list = WlClass::getAllByCondition(['mainId' => $mainId, 'delStatus' => 0], null, '*');
  149. util::success(['list' => $list]);
  150. }
  151. //添加虚拟的供货商 ssh 20230305
  152. public function actionAddGhs()
  153. {
  154. $post = Yii::$app->request->post();
  155. $name = $post['name'] ?? '';
  156. if (empty($name)) {
  157. util::fail('请填写名称');
  158. }
  159. if (stringUtil::getWordNum($name) > 8) {
  160. util::fail('名称不能超过8个汉字');
  161. }
  162. $connection = Yii::$app->db;
  163. $transaction = $connection->beginTransaction();
  164. try {
  165. $shopId = $this->shopId;
  166. $has = GhsClass::getByCondition(['ownShopId' => $shopId, 'name' => $name], true);
  167. if (!empty($has)) {
  168. util::fail($name . ' 已经存在了');
  169. }
  170. \bizHd\ghs\services\GhsService::addVirtualGhs($post, $this->shop);
  171. $transaction->commit();
  172. util::complete('添加成功');
  173. } catch (\Exception $e) {
  174. $transaction->rollBack();
  175. Yii::error("添加失败原因:" . $e->getMessage());
  176. util::fail('添加失败');
  177. }
  178. }
  179. //是否屏蔽 ssh 20230226
  180. public function actionChangeDelStatus()
  181. {
  182. $get = Yii::$app->request->get();
  183. $ghsId = $get['ghsId'] ?? 0;
  184. $delStatus = $get['delStatus'] ?? 0;
  185. $ghs = GhsClass::getById($ghsId, true);
  186. if (empty($ghs)) {
  187. util::fail('没有找到供货商');
  188. }
  189. $ownMainId = $ghs->ownMainId ?? 0;
  190. if ($ownMainId != $this->mainId) {
  191. util::fail('不是你的供货商,无法操作');
  192. }
  193. $ghs->delStatus = $delStatus;
  194. $ghs->save();
  195. util::complete('操作成功');
  196. }
  197. //获取供货商物流 ssh 20230105
  198. public function actionGetAllWl()
  199. {
  200. $get = Yii::$app->request->get();
  201. $id = $get['id'] ?? 0;
  202. $ghs = GhsClass::getById($id, true);
  203. if (empty($ghs) || $ghs->ownMainId != $this->mainId) {
  204. util::success(['list' => []]);
  205. }
  206. $ghsMainId = $ghs->mainId ?? 0;
  207. $list = \bizGhs\merchant\classes\WlClass::getAllByCondition(['mainId' => $ghsMainId, 'delStatus' => 0], 'inTurn DESC', 'id,name');
  208. util::success(['list' => $list]);
  209. }
  210. //采购选分类有变化通知
  211. public function actionGetClassRemind()
  212. {
  213. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  214. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  215. $hasStatus = !empty($has) ? 1 : 0;
  216. util::success(['hasRemind' => $hasStatus]);
  217. }
  218. //采购选分类有变化通知
  219. public function actionHasClassRemind()
  220. {
  221. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  222. Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
  223. util::complete();
  224. }
  225. //供货商列表 ssh 2021.1.24
  226. public function actionList()
  227. {
  228. $get = Yii::$app->request->get();
  229. $delStatus = isset($get['delStatus']) && is_numeric($get['delStatus']) ? $get['delStatus'] : 0;
  230. $where = [];
  231. $where['ownShopId'] = $this->shopId;
  232. $where['delStatus'] = $delStatus;
  233. $name = $get['name'] ?? '';
  234. if (stringUtil::isLetter($name)) {
  235. $where['py'] = ['like', $name];
  236. } else {
  237. $where['name'] = ['like', $name];
  238. }
  239. $respond = GhsClass::getGhsList($where);
  240. //广告列表
  241. $apiHost = Yii::$app->params['hdImgHost'];
  242. //$ad = [['banner' => $apiHost . '/ljh/banner2.jpg', 'url' => '/admin/ljh/info']];
  243. $ad = [];
  244. $respond['ad'] = $ad;
  245. //默认显示广告
  246. $showAd = 1;
  247. if (isset($respond['list']) && !empty($respond['list'])) {
  248. foreach ($respond['list'] as $key => $ghs) {
  249. if (getenv('YII_ENV') == 'production') {
  250. //海翔、源花汇先不显示广告
  251. $noAdShopId = [42345, 10649];
  252. } else {
  253. $noAdShopId = [0];
  254. }
  255. if (isset($ghs['shopId']) && in_array($ghs['shopId'], $noAdShopId)) {
  256. $showAd = 0;
  257. }
  258. }
  259. }
  260. $respond['showAd'] = $showAd;
  261. //请搜索关键词 on_warning
  262. $warning = '';
  263. $warningUrl = '';
  264. //$warning = '挂账和结账重大调整';
  265. //$warningUrl = '/admin/notice/warning';
  266. $respond['warning'] = $warning;
  267. $respond['warningUrl'] = $warningUrl;
  268. util::success($respond);
  269. }
  270. //详情 ssh 2021.4.11
  271. public function actionDetail()
  272. {
  273. $id = Yii::$app->request->get('id');
  274. $salt = Yii::$app->request->get('salt');
  275. $ghsInfo = GhsClass::getGhsInfo($id);
  276. $giveLevel = $ghsInfo['giveLevel'] ?? 0;
  277. $levelMap = CustomClass::$nickNameMap;
  278. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  279. $ghsInfo['giveLevelName'] = $giveLevelName;
  280. if (!empty($salt)) {
  281. if (!isset($ghsInfo['salt']) || $ghsInfo['salt'] != $salt) {
  282. util::fail('不是您的批发店哈');
  283. }
  284. } else {
  285. if (!isset($ghsInfo['ownShopId']) || $ghsInfo['ownShopId'] != $this->shopId) {
  286. util::fail('不是你的批发店呢');
  287. }
  288. }
  289. //是否有充值送红包活动
  290. $ghsShopId = $ghsInfo['shopId'] ?? 0;
  291. $ghsShop = ShopClass::getById($ghsShopId, true);
  292. $ghsInfo['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  293. $ghsInfo['hasRechargeHbAmount'] = 0;
  294. $ghsInfo['xrFl'] = $ghsShop->xrFl ?? 0;
  295. $ghsInfo['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  296. $ghsInfo['tjFl'] = $ghsShop->tjFl ?? 0;
  297. $ghsInfo['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  298. $ghsInfo['packCost'] = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
  299. $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
  300. $customId = $ghsInfo['customId'] ?? 0;
  301. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShop, $customId, 4);
  302. //昆明批发,需要算打包费和运费
  303. $needAddPackFreight = 1;
  304. if (!$needAdd) {
  305. $lackExpend = 0;
  306. //昆明批发,不需要算打包费和运费
  307. $needAddPackFreight = 0;
  308. }
  309. $ghsInfo['needAddPackFreight'] = $needAddPackFreight;
  310. $ghsInfo['lackExpend'] = $lackExpend;
  311. $ghsInfo['showSold'] = $ghsShop->showSold ?? 0;
  312. $ghsInfo['lsShopId'] = $ghsShop->lsShopId ?? 0;
  313. //预订单的最低公斤数和每公斤服务费
  314. $ghsInfo['kiloFee'] = $ghsShop->kiloFee ?? 0;
  315. $ghsInfo['miniKilo'] = $ghsShop->miniKilo ?? 0;
  316. //这个多处要补充的地方 add_pfLevel_many_place
  317. $ghsInfo['pfLevel'] = $ghsShop->pfLevel ?? 0;
  318. $ghsInfo['afterSale'] = $ghsShop->afterSale ?? 1;
  319. //联系电话
  320. $ghsInfo['telephone'] = $ghsShop->telephone ?? '';
  321. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  322. if (!empty($ghsShop->shareLogo)) {
  323. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  324. }
  325. $ghsInfo['shareLogo'] = $shareLogo;
  326. $ghsInfo['superWx'] = '';
  327. if (!empty($ghsShop->superWx)) {
  328. $ghsInfo['superWx'] = imgUtil::groupImg($ghsShop->superWx) . "?x-oss-process=image/resize,w_150";
  329. }
  330. $ghsMainId = $ghsShop->mainId ?? 0;
  331. $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
  332. $ghsInfo['kmPackCost'] = $kmPackCost;
  333. $ghsInfo['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  334. //杭州斗南鲜花批发 免运费活动
  335. if (isset($ghsInfo['shopId']) && $ghsInfo['shopId'] == 4608) {
  336. $current = time();
  337. if ($current < strtotime('2023-4-8 00:00:00')) {
  338. $ghsInfo['hasAct'] = 1;
  339. }
  340. }
  341. /*****此区域部分可以考虑删除******/
  342. $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], false, false, 'purchaseGuide,purchaseGuideText,hcFreeKm,hcMap');
  343. $ghsInfo['buyNotice'] = $ghsShop->buyNotice ?? 0;
  344. $ghsInfo['buyNoticeText'] = $shopExt['purchaseGuideText'] ?? '';
  345. //判断是否开启同城配送功能
  346. $intraCityRet = ShopClass::hasIntraCity($ghsShop);
  347. $openIntraCity = $intraCityRet['openIntraCity'];
  348. $ghsInfo['openIntraCity'] = $openIntraCity;
  349. //花材的免费配送设置
  350. $hcFreeKm = $shopExt['hcFreeKm'] ?? 0;
  351. $ghsInfo['hcFreeKm'] = $hcFreeKm;
  352. $hcMapString = $shopExt['hcMap'] ?? '';
  353. $hcMap = [];
  354. if (!empty($hcMapString)) {
  355. $hcMap = json_decode($hcMapString, true);
  356. }
  357. $ghsInfo['hcMap'] = $hcMap;
  358. /*****此区域部分可以考虑删除******/
  359. //是否使用新的配送方式,关键词 sh_method_area
  360. $newStatus = dict::getNewMethod($ghsShopId);
  361. $ghsInfo['useNewShMethod'] = $newStatus ? 1 : 0;
  362. util::success($ghsInfo);
  363. }
  364. //根据门店获取供货商信息 ssh 2021.4.14
  365. public function actionInfo()
  366. {
  367. $shopId = Yii::$app->request->get('shopId');
  368. if (!empty($this->shopId)) {
  369. $current = ShopClass::getById($shopId, true);
  370. if (empty($current)) {
  371. util::fail('没有找到批发店,rid-186-' . $shopId);
  372. }
  373. if ($current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
  374. util::fail('没有找到批发店,rid-195-' . $shopId);
  375. }
  376. $ghs = GhsClass::build($shopId, $this->shopId);
  377. //是否有充值送红包活动
  378. $ghsShopId = $ghs['shopId'] ?? 0;
  379. $ghsShop = ShopClass::getById($ghsShopId, true);
  380. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  381. $ghs['hasRechargeHbAmount'] = 0;
  382. $avatar = $ghs['avatar'] ?? '';
  383. $ghs['avatar'] = imgUtil::groupImg($avatar);
  384. $map = CustomClass::$nickNameMap;
  385. $giveLevel = $ghs['giveLevel'] ?? 0;
  386. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  387. $ghs['showSold'] = $ghsShop->showSold ?? 0;
  388. $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
  389. $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, false, 'id,shopId,purchaseGuideText');
  390. $ghs['buyNoticeText'] = $shopExt->purchaseGuideText ?? '';
  391. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  392. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  393. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  394. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  395. $ghs['lsShopId'] = $ghsShop->lsShopId ?? 0;
  396. $ghs['presell'] = $ghsShop->presell ?? 0;
  397. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  398. if (isset($ghsShop->shareLogo) && !empty($ghsShop->shareLogo)) {
  399. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  400. }
  401. $ghs['shareLogo'] = $shareLogo;
  402. $ghs['telephone'] = $ghsShop->telephone ?? '';
  403. $ghs['superWx'] = '';
  404. if (!empty($ghsShop->superWx)) {
  405. $ghs['superWx'] = imgUtil::groupImg($ghsShop->superWx);
  406. }
  407. $ghs['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  408. //这个多处要补充的地方 add_pfLevel_many_place
  409. $ghs['pfLevel'] = $ghsShop->pfLevel ?? 0;
  410. //是否使用新的配送方式,关键词 sh_method_area
  411. $newStatus = dict::getNewMethod($ghsShopId);
  412. $ghs['useNewShMethod'] = $newStatus ? 1 : 0;
  413. } else {
  414. //没有开店也给显示供货商信息
  415. $shop = ShopClass::getShopInfo($shopId);
  416. $shopName = $shop['shopName'] ?? '';
  417. $sjName = $shop['merchantName'] ?? '';
  418. $avatar = $shop['avatar'] ?? '';
  419. $default = $shop['default'] ?? 0;
  420. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  421. $ghs = [
  422. 'id' => 0,
  423. 'name' => $name,
  424. 'debtAmount' => 0.00,
  425. 'expendAmount' => 0.00,
  426. 'giveLevel' => 0,
  427. 'giveLevelName' => '普通',
  428. 'xrFl' => 0,
  429. 'xrFlAmount' => 0,
  430. 'tjFl' => 0,
  431. 'tjFlAmount' => 0,
  432. 'avatar' => $avatar,
  433. 'showSold' => 0,
  434. 'buyNotice' => 0,
  435. 'lsShopId' => 0,
  436. 'presell' => 0,
  437. 'shareLogo' => '',
  438. 'superWx' => '',
  439. 'transCost' => [],
  440. ];
  441. }
  442. util::success($ghs);
  443. }
  444. //获取客户等级 ssh 20211016
  445. public function actionGetCustomLevel()
  446. {
  447. $id = Yii::$app->request->get('id');
  448. $info = GhsClass::getById($id, true);
  449. GhsClass::valid($info, $this->shopId);
  450. $ghsShopId = $info->shopId ?? 0;
  451. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  452. $map = self::$levelMap;
  453. foreach ($map as $key => $val) {
  454. $flag = $val['key'] ?? '';
  455. if (empty($flag)) {
  456. $map[$key]['num'] = $info["num"] ?? 0;
  457. $map[$key]['amount'] = $info["amount"] ?? 0;
  458. } else {
  459. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  460. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  461. }
  462. }
  463. util::success(['list' => $map]);
  464. }
  465. //访问供货商的商城 ssh 20211022
  466. public function actionVisitMall()
  467. {
  468. $id = Yii::$app->request->get('id');
  469. $info = GhsClass::getById($id, true);
  470. GhsClass::valid($info, $this->shopId);
  471. $customId = $info->customId ?? 0;
  472. $custom = CustomClass::getById($customId, true);
  473. if (empty($custom)) {
  474. util::fail('没有找到客户');
  475. }
  476. if ($custom->black == 1) {
  477. //没有列入黑名单的,增加访客记录
  478. StatVisitClass::addGhsCustomVisit($info, $custom);
  479. }
  480. util::complete();
  481. }
  482. //补充缺失的供货商 ssh 20211027
  483. public function actionBcGhs()
  484. {
  485. util::fail('过几天再试');
  486. GhsClass::bcGhs($this->shopId);
  487. util::complete('载入成功');
  488. }
  489. //寻找附近批发店
  490. public function actionSearchNearbyGhs()
  491. {
  492. //util::complete();
  493. $get = Yii::$app->request->get();
  494. $locationType = $get['locationType'];
  495. $toLat = $get['lat'] ?? '';
  496. $toLnt = $get['long'] ?? '';
  497. if ($toLat == '' || $toLnt == '') {
  498. util::fail('未获取到定位数据');
  499. }
  500. if ($locationType == 'wgs84') {
  501. // WGS84 → GCJ-02 转换
  502. $re = mapUtil::wgs84ToGcj02($toLnt, $toLat);
  503. $toLat = $re['lat'];
  504. $toLnt = $re['lng'];
  505. }
  506. $gs = GhsClass::getByCondition(['ownShopId' => $this->shopId], true);
  507. if (!empty($gs)) {
  508. util::fail('已有批发商了');
  509. }
  510. $shop = $this->shop;
  511. $mobile = $shop->mobile;
  512. $name = $shop->merchantName ?? '';
  513. $city = $shop->city ?? '';
  514. $address = $shop->address ?? '';
  515. noticeUtil::push("有新花店上来 {$this->shopId} {$toLat} {$toLnt} {$locationType} {$city}{$address}", '15280215347');
  516. // 找出附近批发店,之后自动给建立关系,然后补充二个店之间的距离
  517. GhsClass::buildNearbyGhsRelations($this->shopId, $this->shop->pfShopId ?? 0, $toLat, $toLnt);
  518. noticeUtil::push("花店 {$name} {$mobile} 新注册,已推荐批发店", '15280215347');
  519. util::complete();
  520. }
  521. public function actionCommonInfo()
  522. {
  523. $get = Yii::$app->request->get();
  524. $ghsId = intval($get['ghsId'] ?? 0);
  525. $ghs = GhsClass::getById($ghsId);
  526. if (empty($ghs)) {
  527. util::fail('没有找到批发店');
  528. }
  529. if ($ghs['ownMainId'] != $this->mainId) {
  530. util::fail('不是你的批发店');
  531. }
  532. $mainId = $ghs['mainId'] ?? 0;
  533. // 通用接口返回全部有效公告,前端按 positions 字段筛选展示位置
  534. $ghsNoticeList = GhsNoticeClass::getClientNoticeList($mainId);
  535. util::success(['ghsNoticeList' => $ghsNoticeList]);
  536. }
  537. /**
  538. * 批发商公告详情(零售端采购页查看)
  539. */
  540. public function actionGhsNoticeDetail()
  541. {
  542. $id = intval(Yii::$app->request->get('id', 0));
  543. if ($id <= 0) {
  544. util::fail('公告id不对');
  545. }
  546. util::success(GhsNoticeClass::getClientDetail($id));
  547. }
  548. }