GhsController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 bizHd\stat\classes\StatVisitClass;
  9. use common\components\imgUtil;
  10. use common\components\util;
  11. use Yii;
  12. class GhsController extends BaseController
  13. {
  14. public $guestAccess = ['info'];
  15. public static $levelMap = [
  16. 'pt' => ['name' => '普店', 'num' => 0, 'amount' => 0, 'key' => ''],
  17. 'hj' => ['name' => '银店', 'num' => 0, 'amount' => 0, 'key' => 'hj'],
  18. 'zs' => ['name' => '金店', 'num' => 0, 'amount' => 0, 'key' => 'zs'],
  19. ];
  20. //采购选分类有变化通知
  21. public function actionGetClassRemind()
  22. {
  23. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  24. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  25. $hasStatus = !empty($has) ? 1 : 0;
  26. util::success(['hasRemind' => $hasStatus]);
  27. }
  28. //采购选分类有变化通知
  29. public function actionHasClassRemind()
  30. {
  31. $cacheKey = 'class_change_remind_' . $this->shopAdminId;
  32. Yii::$app->redis->executeCommand('SET', [$cacheKey, 'has']);
  33. util::complete();
  34. }
  35. //供货商列表 ssh 2021.1.24
  36. public function actionList()
  37. {
  38. $where = [];
  39. $where['ownShopId'] = $this->shopId;
  40. $where['delStatus'] = 0;
  41. $respond = GhsClass::getGhsList($where);
  42. util::success($respond);
  43. }
  44. //详情 ssh 2021.4.11
  45. public function actionDetail()
  46. {
  47. $id = Yii::$app->request->get('id');
  48. $info = GhsClass::getGhsInfo($id);
  49. $giveLevel = $info['giveLevel'] ?? 0;
  50. $levelMap = CustomClass::$nickNameMap;
  51. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  52. $info['giveLevelName'] = $giveLevelName;
  53. GhsClass::valid($info, $this->shopId);
  54. //是否有充值送红包活动
  55. $ghsShopId = $info['shopId'] ?? 0;
  56. $ghsShop = ShopClass::getById($ghsShopId, true);
  57. $info['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  58. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  59. $info['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  60. $info['xrFl'] = $ghsShop->xrFl ?? 0;
  61. $info['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  62. $info['tjFl'] = $ghsShop->tjFl ?? 0;
  63. $info['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  64. //预订单的最低公斤数和每公斤服务费
  65. $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
  66. $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
  67. util::success($info);
  68. }
  69. //根据门店获取供货商信息 ssh 2021.4.14
  70. public function actionInfo()
  71. {
  72. $shopId = Yii::$app->request->get('shopId');
  73. if (isset($this->shopId) && !empty($this->shopId)) {
  74. $ghs = GhsClass::build($shopId, $this->shopId);
  75. //是否有充值送红包活动
  76. $ghsShopId = $ghs['shopId'] ?? 0;
  77. $ghsShop = ShopClass::getById($ghsShopId, true);
  78. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  79. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  80. $ghs['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  81. $avatar = $ghs['avatar'] ?? '';
  82. $ghs['avatar'] = imgUtil::groupImg($avatar);
  83. $map = CustomClass::$nickNameMap;
  84. $giveLevel = $ghs['giveLevel'] ?? 0;
  85. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  86. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  87. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  88. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  89. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  90. } else {
  91. //没有开店也给显示供货商信息
  92. $shop = ShopClass::getShopInfo($shopId);
  93. $shopName = $shop['shopName'] ?? '';
  94. $sjName = $shop['merchantName'] ?? '';
  95. $avatar = $shop['avatar'] ?? '';
  96. $default = $shop['default'] ?? 0;
  97. $name = $default == 1 ? $sjName : $sjName . ' ' . $shopName;
  98. $ghs = [
  99. 'id' => 0,
  100. 'name' => $name,
  101. 'debtAmount' => 0.00,
  102. 'expendAmount' => 0.00,
  103. 'giveLevel' => 0,
  104. 'giveLevelName' => '普通',
  105. 'xrFl' => 0,
  106. 'xrFlAmount' => 0,
  107. 'tjFl' => 0,
  108. 'tjFlAmount' => 0,
  109. 'avatar' => $avatar,
  110. ];
  111. }
  112. util::success($ghs);
  113. }
  114. //获取客户等级 ssh 20211016
  115. public function actionGetCustomLevel()
  116. {
  117. $id = Yii::$app->request->get('id');
  118. $info = GhsClass::getById($id, true);
  119. GhsClass::valid($info, $this->shopId);
  120. $ghsShopId = $info->shopId ?? 0;
  121. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  122. $map = self::$levelMap;
  123. foreach ($map as $key => $val) {
  124. $flag = $val['key'] ?? '';
  125. if (empty($flag)) {
  126. $map[$key]['num'] = $info["num"] ?? 0;
  127. $map[$key]['amount'] = $info["amount"] ?? 0;
  128. } else {
  129. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  130. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  131. }
  132. }
  133. util::success(['list' => $map]);
  134. }
  135. //访问供货商的商城 ssh 20211022
  136. public function actionVisitMall()
  137. {
  138. $id = Yii::$app->request->get('id');
  139. $info = GhsClass::getById($id, true);
  140. GhsClass::valid($info, $this->shopId);
  141. $customId = $info->customId ?? 0;
  142. $custom = CustomClass::getById($customId, true);
  143. if (empty($custom)) {
  144. util::fail('没有找到客户');
  145. }
  146. StatVisitClass::addGhsCustomVisit($info, $custom);
  147. util::complete();
  148. }
  149. //补充缺失的供货商 ssh 20211027
  150. public function actionBcGhs()
  151. {
  152. util::fail('过几天再试');
  153. GhsClass::bcGhs($this->shopId);
  154. util::complete('载入成功');
  155. }
  156. }