GhsController.php 18 KB

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