GhsController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. util::success($respond);
  262. }
  263. //详情 ssh 2021.4.11
  264. public function actionDetail()
  265. {
  266. $id = Yii::$app->request->get('id');
  267. $salt = Yii::$app->request->get('salt');
  268. $ghsInfo = GhsClass::getGhsInfo($id);
  269. $giveLevel = $ghsInfo['giveLevel'] ?? 0;
  270. $levelMap = CustomClass::$nickNameMap;
  271. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  272. $ghsInfo['giveLevelName'] = $giveLevelName;
  273. if (!empty($salt)) {
  274. if (!isset($ghsInfo['salt']) || $ghsInfo['salt'] != $salt) {
  275. util::fail('不是您的批发店哈');
  276. }
  277. } else {
  278. if (!isset($ghsInfo['ownShopId']) || $ghsInfo['ownShopId'] != $this->shopId) {
  279. util::fail('不是你的批发店呢');
  280. }
  281. }
  282. //是否有充值送红包活动
  283. $ghsShopId = $ghsInfo['shopId'] ?? 0;
  284. $ghsShop = ShopClass::getById($ghsShopId, true);
  285. $ghsInfo['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  286. $ghsInfo['hasRechargeHbAmount'] = 0;
  287. $ghsInfo['xrFl'] = $ghsShop->xrFl ?? 0;
  288. $ghsInfo['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  289. $ghsInfo['tjFl'] = $ghsShop->tjFl ?? 0;
  290. $ghsInfo['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  291. $ghsInfo['packCost'] = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
  292. $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
  293. $customId = $ghsInfo['customId'] ?? 0;
  294. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShop, $customId, 4);
  295. //昆明批发,需要算打包费和运费
  296. $needAddPackFreight = 1;
  297. if (!$needAdd) {
  298. $lackExpend = 0;
  299. //昆明批发,不需要算打包费和运费
  300. $needAddPackFreight = 0;
  301. }
  302. $ghsInfo['needAddPackFreight'] = $needAddPackFreight;
  303. $ghsInfo['lackExpend'] = $lackExpend;
  304. $ghsInfo['showSold'] = $ghsShop->showSold ?? 0;
  305. $ghsInfo['lsShopId'] = $ghsShop->lsShopId ?? 0;
  306. //预订单的最低公斤数和每公斤服务费
  307. $ghsInfo['kiloFee'] = $ghsShop->kiloFee ?? 0;
  308. $ghsInfo['miniKilo'] = $ghsShop->miniKilo ?? 0;
  309. //这个多处要补充的地方 add_pfLevel_many_place
  310. $ghsInfo['pfLevel'] = $ghsShop->pfLevel ?? 0;
  311. $ghsInfo['afterSale'] = $ghsShop->afterSale ?? 1;
  312. //联系电话
  313. $ghsInfo['telephone'] = $ghsShop->telephone ?? '';
  314. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  315. if (!empty($ghsShop->shareLogo)) {
  316. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  317. }
  318. $ghsInfo['shareLogo'] = $shareLogo;
  319. $ghsInfo['superWx'] = '';
  320. if (!empty($ghsShop->superWx)) {
  321. $ghsInfo['superWx'] = imgUtil::groupImg($ghsShop->superWx) . "?x-oss-process=image/resize,w_150";
  322. }
  323. $ghsMainId = $ghsShop->mainId ?? 0;
  324. $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
  325. $ghsInfo['kmPackCost'] = $kmPackCost;
  326. $ghsInfo['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  327. //杭州斗南鲜花批发 免运费活动
  328. if (isset($ghsInfo['shopId']) && $ghsInfo['shopId'] == 4608) {
  329. $current = time();
  330. if ($current < strtotime('2023-4-8 00:00:00')) {
  331. $ghsInfo['hasAct'] = 1;
  332. }
  333. }
  334. /*****此区域部分可以考虑删除******/
  335. $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], false, false, 'purchaseGuide,purchaseGuideText,hcFreeKm,hcMap');
  336. $ghsInfo['buyNotice'] = $ghsShop->buyNotice ?? 0;
  337. $ghsInfo['buyNoticeText'] = $shopExt['purchaseGuideText'] ?? '';
  338. //判断是否开启同城配送功能
  339. $intraCityRet = ShopClass::hasIntraCity($ghsShop);
  340. $openIntraCity = $intraCityRet['openIntraCity'];
  341. $ghsInfo['openIntraCity'] = $openIntraCity;
  342. //花材的免费配送设置
  343. $hcFreeKm = $shopExt['hcFreeKm'] ?? 0;
  344. $ghsInfo['hcFreeKm'] = $hcFreeKm;
  345. $hcMapString = $shopExt['hcMap'] ?? '';
  346. $hcMap = [];
  347. if (!empty($hcMapString)) {
  348. $hcMap = json_decode($hcMapString, true);
  349. }
  350. $ghsInfo['hcMap'] = $hcMap;
  351. /*****此区域部分可以考虑删除******/
  352. //是否使用新的配送方式,关键词 sh_method_area
  353. $newShMethod = dict::getNewMethodShop();
  354. $ghsInfo['useNewShMethod'] = in_array($ghsShopId, $newShMethod) ? 1 : 0;
  355. util::success($ghsInfo);
  356. }
  357. //根据门店获取供货商信息 ssh 2021.4.14
  358. public function actionInfo()
  359. {
  360. $shopId = Yii::$app->request->get('shopId');
  361. if (!empty($this->shopId)) {
  362. $current = ShopClass::getById($shopId, true);
  363. if (empty($current)) {
  364. util::fail('没有找到批发店,rid-186-' . $shopId);
  365. }
  366. if ($current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
  367. util::fail('没有找到批发店,rid-195-' . $shopId);
  368. }
  369. $ghs = GhsClass::build($shopId, $this->shopId);
  370. //是否有充值送红包活动
  371. $ghsShopId = $ghs['shopId'] ?? 0;
  372. $ghsShop = ShopClass::getById($ghsShopId, true);
  373. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  374. $ghs['hasRechargeHbAmount'] = 0;
  375. $avatar = $ghs['avatar'] ?? '';
  376. $ghs['avatar'] = imgUtil::groupImg($avatar);
  377. $map = CustomClass::$nickNameMap;
  378. $giveLevel = $ghs['giveLevel'] ?? 0;
  379. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  380. $ghs['showSold'] = $ghsShop->showSold ?? 0;
  381. $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
  382. $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, false, 'id,shopId,purchaseGuideText');
  383. $ghs['buyNoticeText'] = $shopExt->purchaseGuideText ?? '';
  384. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  385. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  386. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  387. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  388. $ghs['lsShopId'] = $ghsShop->lsShopId ?? 0;
  389. $ghs['presell'] = $ghsShop->presell ?? 0;
  390. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  391. if (isset($ghsShop->shareLogo) && !empty($ghsShop->shareLogo)) {
  392. $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
  393. }
  394. $ghs['shareLogo'] = $shareLogo;
  395. $ghs['telephone'] = $ghsShop->telephone ?? '';
  396. $ghs['superWx'] = '';
  397. if (!empty($ghsShop->superWx)) {
  398. $ghs['superWx'] = imgUtil::groupImg($ghsShop->superWx);
  399. }
  400. $ghs['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
  401. //这个多处要补充的地方 add_pfLevel_many_place
  402. $ghs['pfLevel'] = $ghsShop->pfLevel ?? 0;
  403. //是否使用新的配送方式,关键词 sh_method_area
  404. $newShMethod = dict::getNewMethodShop();
  405. $ghs['useNewShMethod'] = in_array($ghsShopId, $newShMethod) ? 1 : 0;
  406. } else {
  407. //没有开店也给显示供货商信息
  408. $shop = ShopClass::getShopInfo($shopId);
  409. $shopName = $shop['shopName'] ?? '';
  410. $sjName = $shop['merchantName'] ?? '';
  411. $avatar = $shop['avatar'] ?? '';
  412. $default = $shop['default'] ?? 0;
  413. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  414. $ghs = [
  415. 'id' => 0,
  416. 'name' => $name,
  417. 'debtAmount' => 0.00,
  418. 'expendAmount' => 0.00,
  419. 'giveLevel' => 0,
  420. 'giveLevelName' => '普通',
  421. 'xrFl' => 0,
  422. 'xrFlAmount' => 0,
  423. 'tjFl' => 0,
  424. 'tjFlAmount' => 0,
  425. 'avatar' => $avatar,
  426. 'showSold' => 0,
  427. 'buyNotice' => 0,
  428. 'lsShopId' => 0,
  429. 'presell' => 0,
  430. 'shareLogo' => '',
  431. 'superWx' => '',
  432. 'transCost' => [],
  433. ];
  434. }
  435. util::success($ghs);
  436. }
  437. //获取客户等级 ssh 20211016
  438. public function actionGetCustomLevel()
  439. {
  440. $id = Yii::$app->request->get('id');
  441. $info = GhsClass::getById($id, true);
  442. GhsClass::valid($info, $this->shopId);
  443. $ghsShopId = $info->shopId ?? 0;
  444. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  445. $map = self::$levelMap;
  446. foreach ($map as $key => $val) {
  447. $flag = $val['key'] ?? '';
  448. if (empty($flag)) {
  449. $map[$key]['num'] = $info["num"] ?? 0;
  450. $map[$key]['amount'] = $info["amount"] ?? 0;
  451. } else {
  452. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  453. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  454. }
  455. }
  456. util::success(['list' => $map]);
  457. }
  458. //访问供货商的商城 ssh 20211022
  459. public function actionVisitMall()
  460. {
  461. $id = Yii::$app->request->get('id');
  462. $info = GhsClass::getById($id, true);
  463. GhsClass::valid($info, $this->shopId);
  464. $customId = $info->customId ?? 0;
  465. $custom = CustomClass::getById($customId, true);
  466. if (empty($custom)) {
  467. util::fail('没有找到客户');
  468. }
  469. if ($custom->black == 1) {
  470. //没有列入黑名单的,增加访客记录
  471. StatVisitClass::addGhsCustomVisit($info, $custom);
  472. }
  473. util::complete();
  474. }
  475. //补充缺失的供货商 ssh 20211027
  476. public function actionBcGhs()
  477. {
  478. util::fail('过几天再试');
  479. GhsClass::bcGhs($this->shopId);
  480. util::complete('载入成功');
  481. }
  482. //寻找附近批发店
  483. public function actionSearchNearbyGhs()
  484. {
  485. //util::complete();
  486. $get = Yii::$app->request->get();
  487. $locationType = $get['locationType'];
  488. $toLat = $get['lat'] ?? '';
  489. $toLnt = $get['long'] ?? '';
  490. if ($toLat == '' || $toLnt == '') {
  491. util::fail('未获取到定位数据');
  492. }
  493. if ($locationType == 'wgs84') {
  494. // WGS84 → GCJ-02 转换
  495. $re = mapUtil::wgs84ToGcj02($toLnt, $toLat);
  496. $toLat = $re['lat'];
  497. $toLnt = $re['lng'];
  498. }
  499. $gs = GhsClass::getByCondition(['ownShopId' => $this->shopId], true);
  500. if (!empty($gs)) {
  501. util::fail('已有批发商了');
  502. }
  503. $shop = $this->shop;
  504. $mobile = $shop->mobile;
  505. $name = $shop->merchantName ?? '';
  506. $city = $shop->city ?? '';
  507. $address = $shop->address ?? '';
  508. noticeUtil::push("有新花店上来 {$this->shopId} {$toLat} {$toLnt} {$locationType} {$city}{$address}", '15280215347');
  509. // 找出附近批发店,之后自动给建立关系,然后补充二个店之间的距离
  510. GhsClass::buildNearbyGhsRelations($this->shopId, $this->shop->pfShopId ?? 0, $toLat, $toLnt);
  511. noticeUtil::push("花店 {$name} {$mobile} 新注册,已推荐批发店", '15280215347');
  512. util::complete();
  513. }
  514. public function actionCommonInfo()
  515. {
  516. $get = Yii::$app->request->get();
  517. $ghsId = intval($get['ghsId'] ?? 0);
  518. $ghs = GhsClass::getById($ghsId);
  519. if (empty($ghs)) {
  520. util::fail('没有找到批发店');
  521. }
  522. if ($ghs['ownMainId'] != $this->mainId) {
  523. util::fail('不是你的批发店');
  524. }
  525. $mainId = $ghs['mainId'] ?? 0;
  526. // 通用接口返回全部有效公告,前端按 positions 字段筛选展示位置
  527. $ghsNoticeList = GhsNoticeClass::getClientNoticeList($mainId);
  528. util::success(['ghsNoticeList' => $ghsNoticeList]);
  529. }
  530. /**
  531. * 批发商公告详情(零售端采购页查看)
  532. */
  533. public function actionGhsNoticeDetail()
  534. {
  535. $id = intval(Yii::$app->request->get('id', 0));
  536. if ($id <= 0) {
  537. util::fail('公告id不对');
  538. }
  539. util::success(GhsNoticeClass::getClientDetail($id));
  540. }
  541. }