GhsController.php 9.1 KB

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