GhsController.php 18 KB

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