CustomController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. //客户列表 ssh 2021.7.8
  107. public function actionList()
  108. {
  109. $get = Yii::$app->request->get();
  110. $type = isset($get['type']) ? $get['type'] : 0;
  111. $name = isset($get['name']) ? $get['name'] : '';
  112. $where = ['ownMainId' => $this->mainId];
  113. $sort = 'visitTime DESC';
  114. if ($type == 1) {
  115. //消费排行
  116. $sort = 'buyAmount DESC';
  117. } else if ($type == 2) {
  118. //欠款客户
  119. $where['isDebt'] = 1;
  120. $sort = 'debtAmount DESC';
  121. }
  122. if (!empty($name)) {
  123. if (stringUtil::isLetter($name)) {
  124. $where['py'] = ['like', $name];
  125. } else {
  126. $where['name'] = ['like', $name];
  127. }
  128. }
  129. $list = CustomService::getCustomSortList($where, $sort);
  130. $shop = $this->shop;
  131. $list['totalUser'] = $shop->totalUser ?? 0;
  132. $list['mayGatheringNum'] = $shop->mayGatheringNum ?? 0;
  133. util::success($list);
  134. }
  135. //今日访客 ssh 20211022
  136. public function actionGetVisit()
  137. {
  138. $ids = StatVisitClass::getVisitCustomIds($this->shop);
  139. if (empty($ids)) {
  140. util::success(['list' => []]);
  141. }
  142. $sort = 'visitTime DESC';
  143. $where = ['id' => ['in', $ids]];
  144. $respond = CustomService::getCustomSortList($where, $sort);
  145. util::success($respond);
  146. }
  147. //客户详情 ssh 2021.1.8
  148. public function actionDetail()
  149. {
  150. $get = Yii::$app->request->get();
  151. $customId = $get['id'] ?? 0;
  152. $info = CustomService::getCustomInfo($customId);
  153. CustomClass::valid($info, $this->shopId);
  154. //手动添加的客户经纬度不完善不显示地址,引导完善客户地址
  155. if (isset($info['lat']) && empty($info['lat'])) {
  156. $info['address'] = '';
  157. }
  158. if (isset($info['long']) && empty($info['long'])) {
  159. $info['address'] = '';
  160. }
  161. $shopId = $info['shopId'] ?? 0;
  162. //超管的信息
  163. $superInfo = ShopAdminClass::getManager($shopId);
  164. $superName = $superInfo['name'] ?? '';
  165. $currentSuper = ['name' => $superName];
  166. $info['superInfo'] = $currentSuper;
  167. util::success($info);
  168. }
  169. //允许月结开关 ssh 2021.1.8
  170. public function actionDebt()
  171. {
  172. $get = Yii::$app->request->get();
  173. $debt = isset($get['debt']) ? $get['debt'] : 0;
  174. $customId = isset($get['customId']) ? $get['customId'] : 0;
  175. $custom = CustomClass::getById($customId);
  176. CustomClass::valid($custom, $this->shopId);
  177. CustomClass::debt($custom, $debt);
  178. util::complete();
  179. }
  180. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  181. public function actionSetBlack()
  182. {
  183. $black = Yii::$app->request->get('black', 2);
  184. $customId = Yii::$app->request->get('customId', 0);
  185. $custom = CustomClass::getById($customId, true);
  186. CustomClass::valid($custom, $this->shopId);
  187. $custom->black = $black;
  188. $custom->save();
  189. $ghsId = $custom->ghsId ?? 0;
  190. $ghs = GhsClass::getById($ghsId, true);
  191. if (empty($ghs)) {
  192. util::fail('出错了');
  193. }
  194. $ghs->black = $black;
  195. $ghs->save();
  196. util::complete();
  197. }
  198. //欠款客户 ssh 2021.2.4
  199. public function actionDebtList()
  200. {
  201. $get = Yii::$app->request->get();
  202. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  203. if (isset($get['name']) && !empty($get['name'])) {
  204. $where['name'] = ['like', $get['name']];
  205. }
  206. $list = CustomService::getDebtList($where);
  207. //共X个客户,合计欠款XXX元
  208. $shop = $this->shop;
  209. $list['customNum'] = $shop->mayGatheringNum ?? 0;
  210. $list['debtAmount'] = $shop->mayGathering ?? 0.00;
  211. util::success($list);
  212. }
  213. //修改欠款额度 ssh 20210625
  214. public function actionUpdateDebtLimit()
  215. {
  216. $shopAdmin = $this->shopAdmin;
  217. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  218. util::fail('管理员才能操作');
  219. }
  220. $get = Yii::$app->request->get();
  221. $id = $get['id'] ?? 0;
  222. $debtLimit = $get['debtLimit'] ?? 0;
  223. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  224. util::fail('请填写金额');
  225. }
  226. $custom = CustomClass::getById($id, true);
  227. CustomClass::valid($custom, $this->shopId);
  228. $custom->debtLimit = $debtLimit;
  229. $custom->save();
  230. util::complete();
  231. }
  232. //修改折扣 ssh 20210913
  233. public function actionChangeDiscount()
  234. {
  235. $shopAdmin = $this->shopAdmin;
  236. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  237. util::fail('管理员才能操作');
  238. }
  239. $get = Yii::$app->request->get();
  240. $id = $get['id'] ?? 0;
  241. $discount = $get['discount'] ?? 0;
  242. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  243. util::fail('请填写小数值');
  244. }
  245. $custom = CustomClass::getById($id, true);
  246. CustomClass::valid($custom, $this->shopId);
  247. $custom->discount = $discount;
  248. $custom->save();
  249. $ghsId = $custom->ghsId ?? 0;
  250. $ghs = GhsClass::getById($ghsId, true);
  251. $ghs->giveDiscount = $discount;
  252. $ghs->save();
  253. util::complete();
  254. }
  255. //修改客户等级 ssh 20211007
  256. public function actionChangeLevel()
  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. $customId = $get['customId'] ?? 0;
  264. $level = $get['level'] ?? 1;
  265. $custom = CustomClass::getById($customId, true);
  266. CustomClass::valid($custom, $this->shopId);
  267. $custom->level = $level;
  268. $custom->save();
  269. $ghsId = $custom->ghsId ?? 0;
  270. $ghs = GhsClass::getById($ghsId, true);
  271. if (empty($ghs)) {
  272. util::fail('出错了');
  273. }
  274. $ghs->giveLevel = $level;
  275. $ghs->save();
  276. $map = CustomClass::$levelMap;
  277. $name = $map[$level] ?? '';
  278. util::success(['levelName' => $name]);
  279. }
  280. }