GhsController.php 19 KB

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