GhsController.php 17 KB

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