GhsController.php 15 KB

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