GhsController.php 7.3 KB

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