GhsController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. util::success($respond);
  81. }
  82. //详情 ssh 2021.4.11
  83. public function actionDetail()
  84. {
  85. $id = Yii::$app->request->get('id');
  86. $info = GhsClass::getGhsInfo($id);
  87. $giveLevel = $info['giveLevel'] ?? 0;
  88. $levelMap = CustomClass::$nickNameMap;
  89. $giveLevelName = $levelMap[$giveLevel] ?? '散客';
  90. $info['giveLevelName'] = $giveLevelName;
  91. GhsClass::valid($info, $this->shopId);
  92. //是否有充值送红包活动
  93. $ghsShopId = $info['shopId'] ?? 0;
  94. $ghsShop = ShopClass::getById($ghsShopId, true);
  95. $info['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  96. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  97. $info['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  98. $info['xrFl'] = $ghsShop->xrFl ?? 0;
  99. $info['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  100. $info['tjFl'] = $ghsShop->tjFl ?? 0;
  101. $info['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  102. $info['packCost'] = $ghsShop->packCost ?? 0;
  103. $info['buyNotice'] = $ghsShop->buyNotice ?? 0;
  104. //预订单的最低公斤数和每公斤服务费
  105. $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
  106. $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
  107. util::success($info);
  108. }
  109. //根据门店获取供货商信息 ssh 2021.4.14
  110. public function actionInfo()
  111. {
  112. $shopId = Yii::$app->request->get('shopId');
  113. if (isset($this->shopId) && !empty($this->shopId)) {
  114. $current = ShopClass::getById($shopId, true);
  115. if (isset($current->ptStyle) == false || $current->ptStyle != dict::getDict('ptStyle', 'ghs')) {
  116. util::fail('没有找到批发店');
  117. }
  118. $ghs = GhsClass::build($shopId, $this->shopId);
  119. //是否有充值送红包活动
  120. $ghsShopId = $ghs['shopId'] ?? 0;
  121. $ghsShop = ShopClass::getById($ghsShopId, true);
  122. $ghs['hasRechargeHb'] = $ghsShop->recharge ?? 0;
  123. $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
  124. $ghs['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
  125. $avatar = $ghs['avatar'] ?? '';
  126. $ghs['avatar'] = imgUtil::groupImg($avatar);
  127. $map = CustomClass::$nickNameMap;
  128. $giveLevel = $ghs['giveLevel'] ?? 0;
  129. $ghs['giveLevelName'] = $map[$giveLevel] ?? '';
  130. $ghs['buyNotice'] = $ghsShop->buyNotice ?? 0;
  131. $ghs['xrFl'] = $ghsShop->xrFl ?? 0;
  132. $ghs['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
  133. $ghs['tjFl'] = $ghsShop->tjFl ?? 0;
  134. $ghs['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
  135. } else {
  136. //没有开店也给显示供货商信息
  137. $shop = ShopClass::getShopInfo($shopId);
  138. $shopName = $shop['shopName'] ?? '';
  139. $sjName = $shop['merchantName'] ?? '';
  140. $avatar = $shop['avatar'] ?? '';
  141. $default = $shop['default'] ?? 0;
  142. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  143. $ghs = [
  144. 'id' => 0,
  145. 'name' => $name,
  146. 'debtAmount' => 0.00,
  147. 'expendAmount' => 0.00,
  148. 'giveLevel' => 0,
  149. 'giveLevelName' => '普通',
  150. 'xrFl' => 0,
  151. 'xrFlAmount' => 0,
  152. 'tjFl' => 0,
  153. 'tjFlAmount' => 0,
  154. 'avatar' => $avatar,
  155. 'buyNotice' => 0,
  156. ];
  157. }
  158. util::success($ghs);
  159. }
  160. //获取客户等级 ssh 20211016
  161. public function actionGetCustomLevel()
  162. {
  163. $id = Yii::$app->request->get('id');
  164. $info = GhsClass::getById($id, true);
  165. GhsClass::valid($info, $this->shopId);
  166. $ghsShopId = $info->shopId ?? 0;
  167. $info = CustomLevelClass::getByCondition(['shopId' => $ghsShopId]);
  168. $map = self::$levelMap;
  169. foreach ($map as $key => $val) {
  170. $flag = $val['key'] ?? '';
  171. if (empty($flag)) {
  172. $map[$key]['num'] = $info["num"] ?? 0;
  173. $map[$key]['amount'] = $info["amount"] ?? 0;
  174. } else {
  175. $map[$key]['num'] = $info[$flag . "Num"] ?? 0;
  176. $map[$key]['amount'] = $info[$flag . "Amount"] ?? 0;
  177. }
  178. }
  179. util::success(['list' => $map]);
  180. }
  181. //访问供货商的商城 ssh 20211022
  182. public function actionVisitMall()
  183. {
  184. $id = Yii::$app->request->get('id');
  185. $info = GhsClass::getById($id, true);
  186. GhsClass::valid($info, $this->shopId);
  187. $customId = $info->customId ?? 0;
  188. $custom = CustomClass::getById($customId, true);
  189. if (empty($custom)) {
  190. util::fail('没有找到客户');
  191. }
  192. StatVisitClass::addGhsCustomVisit($info, $custom);
  193. util::complete();
  194. }
  195. //补充缺失的供货商 ssh 20211027
  196. public function actionBcGhs()
  197. {
  198. util::fail('过几天再试');
  199. GhsClass::bcGhs($this->shopId);
  200. util::complete('载入成功');
  201. }
  202. }