GhsController.php 8.0 KB

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