GhsController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. $respond = GhsClass::getGhsList($where);
  41. util::success($respond);
  42. }
  43. //详情 ssh 2021.4.11
  44. public function actionDetail()
  45. {
  46. $id = Yii::$app->request->get('id');
  47. $info = GhsClass::getGhsInfo($id);
  48. $giveLevel = $info['giveLevel'] ?? 0;
  49. $levelMap = CustomClass::$nickNameMap;
  50. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  51. $info['giveLevelName'] = $giveLevelName;
  52. GhsClass::valid($info, $this->shopId);
  53. //是否有充值送红包活动
  54. $ghsShopId = $info['shopId'] ?? 0;
  55. $ghsShop = ShopClass::getById($ghsShopId, true);
  56. $info['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  57. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  58. $info['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  59. $info['xrFl'] = $ghsShop->xrFl ?? 0;
  60. $info['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  61. $info['tjFl'] = $ghsShop->tjFl ?? 0;
  62. $info['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  63. //预订单的最低公斤数和每公斤服务费
  64. $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
  65. $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
  66. util::success($info);
  67. }
  68. //根据门店获取供货商信息 ssh 2021.4.14
  69. public function actionInfo()
  70. {
  71. $shopId = Yii::$app->request->get('shopId');
  72. if (isset($this->shopId) && !empty($this->shopId)) {
  73. $ghs = GhsClass::build($shopId, $this->shopId);
  74. //是否有充值送红包活动
  75. $ghsShopId = $ghs['shopId'] ?? 0;
  76. $ghsShop = ShopClass::getById($ghsShopId, true);
  77. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  78. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  79. $ghs['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  80. $avatar = $ghs['avatar'] ?? '';
  81. $ghs['avatar'] = imgUtil::groupImg($avatar);
  82. $map = CustomClass::$nickNameMap;
  83. $giveLevel = $ghs['giveLevel'] ?? 0;
  84. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  85. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  86. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  87. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  88. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  89. } else {
  90. //没有开店也给显示供货商信息
  91. $shop = ShopClass::getShopInfo($shopId);
  92. $shopName = $shop['shopName'] ?? '';
  93. $sjName = $shop['merchantName'] ?? '';
  94. $avatar = $shop['avatar'] ?? '';
  95. $default = $shop['default'] ?? 0;
  96. $name = $default == 1 ? $sjName : $sjName . ' ' . $shopName;
  97. $ghs = [
  98. 'id' => 0,
  99. 'name' => $name,
  100. 'debtAmount' => 0.00,
  101. 'expendAmount' => 0.00,
  102. 'giveLevel' => 0,
  103. 'giveLevelName' => '普通',
  104. 'xrFl' => 0,
  105. 'xrFlAmount' => 0,
  106. 'tjFl' => 0,
  107. 'tjFlAmount' => 0,
  108. 'avatar' => $avatar,
  109. ];
  110. }
  111. util::success($ghs);
  112. }
  113. //获取客户等级 ssh 20211016
  114. public function actionGetCustomLevel()
  115. {
  116. $id = Yii::$app->request->get('id');
  117. $info = GhsClass::getById($id, true);
  118. GhsClass::valid($info, $this->shopId);
  119. $ghsShopId = $info->shopId ?? 0;
  120. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  121. $map = self::$levelMap;
  122. foreach ($map as $key => $val) {
  123. $flag = $val['key'] ?? '';
  124. if (empty($flag)) {
  125. $map[$key]['num'] = $info["num"] ?? 0;
  126. $map[$key]['amount'] = $info["amount"] ?? 0;
  127. } else {
  128. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  129. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  130. }
  131. }
  132. util::success(['list' => $map]);
  133. }
  134. //访问供货商的商城 ssh 20211022
  135. public function actionVisitMall()
  136. {
  137. $id = Yii::$app->request->get('id');
  138. $info = GhsClass::getById($id, true);
  139. GhsClass::valid($info, $this->shopId);
  140. $customId = $info->customId ?? 0;
  141. $custom = CustomClass::getById($customId, true);
  142. if (empty($custom)) {
  143. util::fail('没有找到客户');
  144. }
  145. StatVisitClass::addGhsCustomVisit($info, $custom);
  146. util::complete();
  147. }
  148. //补充缺失的供货商 ssh 20211027
  149. public function actionBcGhs()
  150. {
  151. util::fail('过几天再试');
  152. GhsClass::bcGhs($this->shopId);
  153. util::complete('载入成功');
  154. }
  155. }