GhsController.php 18 KB

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