GhsController.php 6.3 KB

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