GhsController.php 8.9 KB

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