CustomController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\ghs\classes\GhsClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\sj\classes\SjClass;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\custom\services\CustomService;
  9. use bizHd\saas\classes\ApplyClass;
  10. use bizHd\saas\services\ApplyService;
  11. use bizHd\stat\classes\StatVisitClass;
  12. use common\components\imgUtil;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use Yii;
  16. class CustomController extends BaseController
  17. {
  18. //添加新花店 ssh 2021.1.8
  19. public function actionAdd()
  20. {
  21. $post = Yii::$app->request->post();
  22. $post['style'] = SjClass::STYLE_RETAIL;
  23. $post['introSjId'] = $this->sjId;
  24. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  25. $mobile = $post['mobile'] ?? '';
  26. $confirmMobile = $post['confirmMobile'];
  27. $address = $post['address'] ?? '';
  28. util::fail('功能已停用');
  29. if (stringUtil::isMobile($mobile) == false) {
  30. util::fail(' 请填写正确的手机号');
  31. }
  32. if ($mobile != $confirmMobile) {
  33. util::fail('二次号码填写不一致');
  34. }
  35. $name = $post['name'] ?? '';
  36. if (empty($name)) {
  37. util::fail('名称不能为空');
  38. }
  39. if (stringUtil::getWordNum($name) > 8) {
  40. util::fail('名称不能超过8个汉字');
  41. }
  42. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  43. if (!empty($has)) {
  44. util::fail('名称已经存在');
  45. }
  46. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  47. if (!empty($has)) {
  48. util::fail('手机号已经添加过');
  49. }
  50. if (empty($address)) {
  51. util::fail('请填写地址');
  52. }
  53. $connection = Yii::$app->db;
  54. $transaction = $connection->beginTransaction();
  55. try {
  56. $shop = $this->shop;
  57. $sjId = $this->sjId;
  58. $shopId = $this->shopId;
  59. $sjName = $this->sj->name ?? '';
  60. $city = $shop->city ?? '';
  61. $dist = $shop->dist ?? '';
  62. $applyData = [
  63. 'name' => $name,
  64. 'licenseNo' => $mobile,
  65. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  66. 'mobile' => $mobile,
  67. 'introSjId' => $sjId,
  68. 'introSjName' => $sjName,
  69. 'introShopId' => $shopId,
  70. 'introStyle' => SjClass::STYLE_SUPPLIER,
  71. 'from' => ApplyClass::FROM_GHS,
  72. 'style' => SjClass::STYLE_RETAIL,
  73. 'province' => $shop->province ?? '',
  74. 'city' => $city,
  75. 'dist' => $dist,
  76. 'address' => $address,
  77. 'status' => ApplyClass::STATUS_PASS,
  78. 'replace' => 1,//1表示供应商添加的客户
  79. ];
  80. $apply = ApplyService::replaceRetail($applyData);
  81. $id = $apply['id'] ?? 0;
  82. $respond = ApplyService::pass($id);
  83. $shop = $respond['shop'] ?? [];
  84. $sj = $respond['sj'] ?? [];
  85. $hdSjId = $sj['id'] ?? 0;
  86. $hdShopId = $shop->id ?? 0;
  87. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  88. if (empty($hdShopId)) {
  89. util::fail('客户没有添加成功!');
  90. }
  91. $custom = CustomClass::build($this->shopId, $hdShopId);
  92. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  93. //客户欠款额度设置
  94. $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  95. $customId = $custom['id'] ?? 0;
  96. $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000;
  97. CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]);
  98. $transaction->commit();
  99. util::success($custom);
  100. } catch (\Exception $exception) {
  101. $transaction->rollBack();
  102. Yii::info("添加客户没有成功:" . $exception->getMessage());
  103. util::fail('添加客户没有成功');
  104. }
  105. }
  106. //向队列写入新花店数据 shizhongqi 2022.6.8
  107. public function actionCreateCustomers()
  108. {
  109. $post = Yii::$app->request->post();
  110. $post['style'] = SjClass::STYLE_RETAIL;
  111. $sjId = $this->sjId;
  112. $shopId = $this->shopId;
  113. for($i = 1; $i <= 5; $i++) {
  114. $name = $post['name' . $i];
  115. $mobile = $post['mobile' . $i];
  116. $confirmMobile = $post['confirmMobile' . $i];
  117. if ($mobile != $confirmMobile) {
  118. Yii::info("添加客户失败:mobile " . $mobile . ' != confirmMobile ' . $confirmMobile);
  119. continue;
  120. }
  121. //队列方式去处理
  122. $customerCachedKey = 'customers_list';
  123. $value = $name . '_' . $mobile . '_' . $this->sjId;
  124. Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
  125. Yii::info("添加客户:name - " . $name . ' == mobile - ' . $mobile);
  126. }
  127. util::complete();
  128. }
  129. //客户列表 ssh 2021.7.8
  130. public function actionList()
  131. {
  132. $get = Yii::$app->request->get();
  133. $type = isset($get['type']) ? $get['type'] : 0;
  134. $name = isset($get['name']) ? $get['name'] : '';
  135. $where = ['ownMainId' => $this->mainId];
  136. $sort = 'visitTime DESC';
  137. if ($type == 1) {
  138. //消费排行
  139. $sort = 'buyAmount DESC';
  140. } else if ($type == 2) {
  141. //欠款客户
  142. $where['isDebt'] = 1;
  143. $sort = 'debtAmount DESC';
  144. }
  145. if (!empty($name)) {
  146. if (stringUtil::isLetter($name)) {
  147. $where['py'] = ['like', $name];
  148. } else {
  149. $where['name'] = ['like', $name];
  150. }
  151. }
  152. $list = CustomService::getCustomSortList($where, $sort);
  153. $main = $this->main;
  154. $list['totalUser'] = $main->totalUser ?? 0;
  155. $list['mayGatheringNum'] = $main->mayGatheringNum ?? 0;
  156. util::success($list);
  157. }
  158. //今日访客 ssh 20211022
  159. public function actionGetVisit()
  160. {
  161. $ids = StatVisitClass::getVisitCustomIds($this->shop);
  162. if (empty($ids)) {
  163. util::success(['list' => []]);
  164. }
  165. $sort = 'visitTime DESC';
  166. $where = ['id' => ['in', $ids]];
  167. $respond = CustomService::getCustomSortList($where, $sort);
  168. util::success($respond);
  169. }
  170. //客户详情 ssh 2021.1.8
  171. public function actionDetail()
  172. {
  173. $get = Yii::$app->request->get();
  174. $customId = $get['id'] ?? 0;
  175. $info = CustomService::getCustomInfo($customId);
  176. CustomClass::valid($info, $this->shopId);
  177. //手动添加的客户经纬度不完善不显示地址,引导完善客户地址
  178. if (isset($info['lat']) && empty($info['lat'])) {
  179. $info['address'] = '';
  180. }
  181. if (isset($info['long']) && empty($info['long'])) {
  182. $info['address'] = '';
  183. }
  184. $mainId = $info['mainId'] ?? 0;
  185. //超管的信息
  186. $superInfo = ShopAdminClass::getManager($mainId);
  187. $superName = $superInfo['name'] ?? '';
  188. $currentSuper = ['name' => $superName];
  189. $info['superInfo'] = $currentSuper;
  190. util::success($info);
  191. }
  192. //允许月结开关 ssh 2021.1.8
  193. public function actionDebt()
  194. {
  195. $get = Yii::$app->request->get();
  196. $debt = isset($get['debt']) ? $get['debt'] : 0;
  197. $customId = isset($get['customId']) ? $get['customId'] : 0;
  198. $custom = CustomClass::getById($customId);
  199. CustomClass::valid($custom, $this->shopId);
  200. CustomClass::debt($custom, $debt);
  201. util::complete();
  202. }
  203. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  204. public function actionSetBlack()
  205. {
  206. $black = Yii::$app->request->get('black', 2);
  207. $customId = Yii::$app->request->get('customId', 0);
  208. $custom = CustomClass::getById($customId, true);
  209. CustomClass::valid($custom, $this->shopId);
  210. $custom->black = $black;
  211. $custom->save();
  212. $ghsId = $custom->ghsId ?? 0;
  213. $ghs = GhsClass::getById($ghsId, true);
  214. if (empty($ghs)) {
  215. util::fail('出错了');
  216. }
  217. $ghs->black = $black;
  218. $ghs->save();
  219. util::complete();
  220. }
  221. //欠款客户 ssh 2021.2.4
  222. public function actionDebtList()
  223. {
  224. $get = Yii::$app->request->get();
  225. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  226. if (isset($get['name']) && !empty($get['name'])) {
  227. $where['name'] = ['like', $get['name']];
  228. }
  229. $list = CustomService::getDebtList($where);
  230. //共X个客户,合计欠款XXX元
  231. $main = $this->main;
  232. $list['customNum'] = $main->mayGatheringNum ?? 0;
  233. $list['debtAmount'] = $main->mayGathering ?? 0.00;
  234. util::success($list);
  235. }
  236. //修改欠款额度 ssh 20210625
  237. public function actionUpdateDebtLimit()
  238. {
  239. $shopAdmin = $this->shopAdmin;
  240. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  241. util::fail('管理员才能操作');
  242. }
  243. $get = Yii::$app->request->get();
  244. $id = $get['id'] ?? 0;
  245. $debtLimit = $get['debtLimit'] ?? 0;
  246. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  247. util::fail('请填写金额');
  248. }
  249. $custom = CustomClass::getById($id, true);
  250. CustomClass::valid($custom, $this->shopId);
  251. $custom->debtLimit = $debtLimit;
  252. $custom->save();
  253. util::complete();
  254. }
  255. //修改折扣 ssh 20210913
  256. public function actionChangeDiscount()
  257. {
  258. $shopAdmin = $this->shopAdmin;
  259. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  260. util::fail('管理员才能操作');
  261. }
  262. $get = Yii::$app->request->get();
  263. $id = $get['id'] ?? 0;
  264. $discount = $get['discount'] ?? 0;
  265. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  266. util::fail('请填写小数值');
  267. }
  268. $custom = CustomClass::getById($id, true);
  269. CustomClass::valid($custom, $this->shopId);
  270. $custom->discount = $discount;
  271. $custom->save();
  272. $ghsId = $custom->ghsId ?? 0;
  273. $ghs = GhsClass::getById($ghsId, true);
  274. $ghs->giveDiscount = $discount;
  275. $ghs->save();
  276. util::complete();
  277. }
  278. //修改客户等级 ssh 20211007
  279. public function actionChangeLevel()
  280. {
  281. $shopAdmin = $this->shopAdmin;
  282. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  283. util::fail('超管才能修改');
  284. }
  285. $get = Yii::$app->request->get();
  286. $customId = $get['customId'] ?? 0;
  287. $level = $get['level'] ?? 1;
  288. $custom = CustomClass::getById($customId, true);
  289. CustomClass::valid($custom, $this->shopId);
  290. $custom->level = $level;
  291. $custom->save();
  292. $ghsId = $custom->ghsId ?? 0;
  293. $ghs = GhsClass::getById($ghsId, true);
  294. if (empty($ghs)) {
  295. util::fail('出错了');
  296. }
  297. $ghs->giveLevel = $level;
  298. $ghs->save();
  299. $map = CustomClass::$levelMap;
  300. $name = $map[$level] ?? '';
  301. util::success(['levelName' => $name]);
  302. }
  303. }