CustomController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 bizGhs\merchant\classes\WlClass;
  10. use bizGhs\order\classes\OrderClass;
  11. use bizHd\saas\classes\ApplyClass;
  12. use bizHd\saas\services\ApplyService;
  13. use bizHd\shop\classes\ShopClass;
  14. use bizHd\stat\classes\StatVisitClass;
  15. use common\components\dict;
  16. use common\components\imgUtil;
  17. use common\components\orderSn;
  18. use common\components\stringUtil;
  19. use common\components\util;
  20. use Yii;
  21. class CustomController extends BaseController
  22. {
  23. //修改客户地址 ssh 20230929
  24. public function actionModifyAddress()
  25. {
  26. $post = Yii::$app->request->post();
  27. $id = $post['id'] ?? 0;
  28. unset($post['id']);
  29. $custom = CustomClass::getById($id, true);
  30. if ($custom->ownMainId != $this->mainId) {
  31. util::fail('没有权限修改');
  32. }
  33. $shopId = $custom->shopId ?? 0;
  34. $where = ['shopId' => $shopId];
  35. ShopClass::updateById($shopId, $post);
  36. CustomClass::updateByCondition($where, $post);
  37. util::complete('修改成功');
  38. }
  39. //修改花店散客身份 ssh 20230216
  40. public function actionChangeIsHd()
  41. {
  42. $get = Yii::$app->request->get();
  43. $id = $get['customId'] ?? 0;
  44. $isHd = $get['isHd'] ?? 1;
  45. $custom = CustomClass::getById($id, true);
  46. if (empty($custom)) {
  47. util::fail('没有找到客户');
  48. }
  49. if ($custom->ownMainId != $this->mainId) {
  50. util::fail('没有权限');
  51. }
  52. $ghsId = $custom->ghsId ?? 0;
  53. $ghs = GhsClass::getById($ghsId, true);
  54. if (empty($ghs)) {
  55. util::fail('修改失败了');
  56. }
  57. $ghs->isHd = $isHd;
  58. $ghs->save();
  59. $custom->isHd = $isHd;
  60. $custom->save();
  61. util::complete('修改成功');
  62. }
  63. //修改物流名称 ssh 20230112
  64. public function actionChangeWlName()
  65. {
  66. $get = Yii::$app->request->get();
  67. $id = $get['id'] ?? 0;
  68. $wlName = $get['wlName'] ?? 0;
  69. $custom = CustomClass::getById($id, true);
  70. if (empty($custom) || $custom->ownMainId != $this->mainId) {
  71. util::fail('修改失败');
  72. }
  73. $ghsId = $custom->ghsId ?? 0;
  74. $ghs = GhsClass::getById($ghsId, true);
  75. if (empty($ghs)) {
  76. util::fail('修改失败');
  77. }
  78. $ghs->customWlName = $wlName;
  79. $ghs->save();
  80. $custom->wlName = $wlName;
  81. $custom->save();
  82. util::complete('已修改');
  83. }
  84. //修改物流信息 ssh 20230105
  85. public function actionChangeWl()
  86. {
  87. util::fail('修改失败');
  88. }
  89. //修改名称 ssh 2022096
  90. public function actionChangeName()
  91. {
  92. $get = Yii::$app->request->get();
  93. $name = $get['name'] ?? '';
  94. $id = $get['id'] ?? 0;
  95. if (empty($name)) {
  96. util::fail('请填写名称');
  97. }
  98. $py = stringUtil::py($name);
  99. $custom = CustomClass::getById($id, true);
  100. CustomClass::valid($custom, $this->shopId);
  101. $custom->name = $name;
  102. $custom->py = $py;
  103. $custom->save();
  104. OrderClass::updateByCondition(['customId' => $id], ['customName' => $name, 'customNamePy' => $py]);
  105. $customShopId = $custom->shopId ?? 0;
  106. //在首店修改客户名称,直营店自动同步
  107. $masterShop = $this->shop;
  108. if (isset($masterShop->default) && $masterShop->default == 1) {
  109. $sjId = $masterShop->sjId ?? 0;
  110. $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  111. foreach ($shopList as $shop) {
  112. $shopId = $shop->id ?? 0;
  113. if (isset($shop->join) && $shop->join == 1) {
  114. //加盟店不同步修改
  115. continue;
  116. }
  117. if ($shopId == $masterShop->id) {
  118. //前面已经同步修改过了
  119. continue;
  120. }
  121. $custom = CustomClass::getByCondition(['ownShopId' => $shopId, 'shopId' => $customShopId], true);
  122. if (empty($custom)) {
  123. continue;
  124. }
  125. $custom->name = $name;
  126. $custom->py = $py;
  127. $custom->save();
  128. }
  129. }
  130. util::complete('修改成功');
  131. }
  132. //帮客户添加员工 ssh 20220613
  133. public function actionAddStaff()
  134. {
  135. $post = Yii::$app->request->post();
  136. $customId = $post['id'] ?? 0;
  137. $mobile = $post['mobile'] ?? 0;
  138. if (stringUtil::isMobile($mobile) == false) {
  139. util::fail('手机号填写错误');
  140. }
  141. $info = CustomService::getById($customId, true);
  142. CustomClass::valid($info, $this->shopId);
  143. $connection = Yii::$app->db;
  144. $transaction = $connection->beginTransaction();
  145. try {
  146. $shopId = $info->shopId ?? 0;
  147. $customShop = ShopClass::getById($shopId, true);
  148. if (empty($customShop)) {
  149. util::fail('没有找到客户的门店');
  150. }
  151. $mainId = $customShop->mainId ?? 0;
  152. $ptStyle = dict::getDict('ptStyle', 'hd');
  153. $adminInfo = ['name' => $mobile, 'mobile' => $mobile, 'style' => $ptStyle, 'currentShopId' => $shopId];
  154. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  155. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  156. $roleList = AdminRoleClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  157. if (empty($roleList)) {
  158. util::fail('客户门店没有员工角色');
  159. }
  160. $currentRoleId = 0;
  161. foreach ($roleList as $role) {
  162. $roleId = $role->id ?? 0;
  163. $currentRoleId = $roleId;
  164. if ($role->roleName == '员工') {
  165. break;
  166. }
  167. }
  168. $params = [
  169. 'shopId' => $shopId,
  170. 'mobile' => $mobile,
  171. 'roleId' => $currentRoleId,
  172. ];
  173. \bizHd\staff\classes\StaffClass::appGenerateStaff($params, $admin);
  174. $transaction->commit();
  175. util::complete('添加成功');
  176. } catch (\Exception $e) {
  177. $transaction->rollBack();
  178. util::fail('添加失败');
  179. }
  180. }
  181. //添加新花店 ssh 2021.1.8
  182. public function actionAdd()
  183. {
  184. $post = Yii::$app->request->post();
  185. $post['style'] = SjClass::STYLE_RETAIL;
  186. $post['introSjId'] = $this->sjId;
  187. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  188. $mobile = $post['mobile'] ?? '';
  189. $confirmMobile = $post['confirmMobile'];
  190. $address = $post['address'] ?? '';
  191. util::fail('功能已停用');
  192. if (stringUtil::isMobile($mobile) == false) {
  193. util::fail(' 请填写正确的手机号');
  194. }
  195. if ($mobile != $confirmMobile) {
  196. util::fail('二次号码填写不一致');
  197. }
  198. $name = $post['name'] ?? '';
  199. if (empty($name)) {
  200. util::fail('名称不能为空');
  201. }
  202. if (stringUtil::getWordNum($name) > 8) {
  203. util::fail('名称不能超过8个汉字');
  204. }
  205. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  206. if (!empty($has)) {
  207. util::fail('名称已经存在');
  208. }
  209. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  210. if (!empty($has)) {
  211. util::fail('手机号已经添加过');
  212. }
  213. if (empty($address)) {
  214. util::fail('请填写地址');
  215. }
  216. $connection = Yii::$app->db;
  217. $transaction = $connection->beginTransaction();
  218. try {
  219. $shop = $this->shop;
  220. $sjId = $this->sjId;
  221. $shopId = $this->shopId;
  222. $sjName = $this->sj->name ?? '';
  223. $city = $shop->city ?? '';
  224. $dist = $shop->dist ?? '';
  225. $applyData = [
  226. 'name' => $name,
  227. 'licenseNo' => $mobile,
  228. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  229. 'mobile' => $mobile,
  230. 'introSjId' => $sjId,
  231. 'introSjName' => $sjName,
  232. 'introShopId' => $shopId,
  233. 'introStyle' => SjClass::STYLE_SUPPLIER,
  234. 'from' => ApplyClass::FROM_GHS,
  235. 'style' => SjClass::STYLE_RETAIL,
  236. 'province' => $shop->province ?? '',
  237. 'city' => $city,
  238. 'dist' => $dist,
  239. 'address' => $address,
  240. 'status' => ApplyClass::STATUS_PASS,
  241. 'replace' => 1,//1表示供货商添加的客户
  242. ];
  243. $apply = ApplyService::replaceRetail($applyData);
  244. $id = $apply['id'] ?? 0;
  245. $respond = ApplyService::pass($id);
  246. $shop = $respond['shop'] ?? [];
  247. $sj = $respond['sj'] ?? [];
  248. $hdSjId = $sj['id'] ?? 0;
  249. $hdShopId = $shop->id ?? 0;
  250. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  251. if (empty($hdShopId)) {
  252. util::fail('客户没有添加成功!');
  253. }
  254. $custom = CustomClass::build($this->shopId, $hdShopId);
  255. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  256. //客户欠款额度设置
  257. $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  258. $customId = $custom['id'] ?? 0;
  259. $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000;
  260. CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]);
  261. $transaction->commit();
  262. util::success($custom);
  263. } catch (\Exception $exception) {
  264. $transaction->rollBack();
  265. Yii::info("添加客户没有成功:" . $exception->getMessage());
  266. util::fail('添加客户没有成功');
  267. }
  268. }
  269. //向队列写入新花店数据 shizhongqi 2022.6.8
  270. public function actionCreateCustomers()
  271. {
  272. $post = Yii::$app->request->post();
  273. $virtual = $post['virtual'] ?? 0;
  274. $arr = [];
  275. for ($i = 1; $i <= 5; $i++) {
  276. $name = $post['name' . $i] ?? '';
  277. $mobile = $post['mobile' . $i] ?? '';
  278. $confirmMobile = $post['confirmMobile' . $i] ?? '';
  279. if (empty($name) && empty($mobile) && empty($confirmMobile)) {
  280. continue;
  281. }
  282. if (empty($name)) {
  283. util::fail('花店名称不能为空');
  284. }
  285. if (stringUtil::getWordNum($name) > 8) {
  286. util::fail('名称不能超过8个汉字');
  287. }
  288. if (empty($mobile)) {
  289. //添加虚拟客户
  290. if ($virtual == 1) {
  291. $mobile = orderSn::getMobileSn();
  292. $confirmMobile = $mobile;
  293. } else {
  294. util::fail($name . " 手机号不能为空");
  295. }
  296. }
  297. if (stringUtil::isMobile($mobile) == false) {
  298. util::fail($name . " 手机号格式不正确");
  299. }
  300. if ($mobile != $confirmMobile) {
  301. util::fail($name . " 二次手机号不一致");
  302. }
  303. $hasShop = ShopClass::getByCondition(['mobile' => $mobile], true);
  304. if (!empty($hasShop)) {
  305. $shop = ShopClass::getByCondition(['mobile' => $mobile, 'ptStyle' => 1], true);
  306. if (!empty($shop)) {
  307. $ghsShopId = $this->shopId;
  308. $hdShopId = $shop->id;
  309. $custom = CustomClass::build($ghsShopId, $hdShopId);
  310. $customId = $custom['id'] ?? 0;
  311. $custom = CustomClass::getById($customId, true);
  312. if (!empty($custom)) {
  313. $custom->name = $name;
  314. $py = stringUtil::py($name);
  315. $custom->py = $py;
  316. $custom->save();
  317. }
  318. util::complete($shop->merchantName . ' 添加成功');
  319. }
  320. util::fail($mobile . "手机号已经添加过了");
  321. }
  322. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  323. if (!empty($has)) {
  324. util::fail($mobile . "手机号已经申请添加过了");
  325. }
  326. $arr[] = ['name' => $name, 'mobile' => $mobile];
  327. }
  328. if (empty($arr)) {
  329. util::fail('请填写客户');
  330. }
  331. foreach ($arr as $item) {
  332. $name = $item['name'] ?? '';
  333. $mobile = $item['mobile'] ?? '';
  334. //队列方式去处理
  335. $customerCachedKey = 'batch_create_customer_list';
  336. $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop->id . '_' . $this->sj->name . '_' . $this->shopAdminId;
  337. Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
  338. Yii::info("供货商添加客户:name - " . $name . ' == mobile - ' . $mobile);
  339. Yii::info("shopAdminId: " . $this->shopAdminId);
  340. }
  341. util::complete('已提交,30秒后生效');
  342. }
  343. //从其它店同步客户 shizhongqi 2022.6.9
  344. public function actionCopyCustomers()
  345. {
  346. $get = Yii::$app->request->get();
  347. $fromShopId = $get['fromShopId'] ?? 0;
  348. $fromShop = ShopClass::getById($fromShopId, true);
  349. if (empty($fromShop)) {
  350. util::fail('门店不存在');
  351. }
  352. $toShopId = $this->shopId;
  353. if ($fromShopId == $toShopId) {
  354. util::fail('本店无需同步');
  355. }
  356. $fromShopName = $fromShop->shopName ?? '';
  357. if ($fromShop->syncCustom == 0) {
  358. util::fail('不允许从' . $fromShopName . '同步客户');
  359. }
  360. $toShop = $this->shop;
  361. $toShopName = $toShop->shopName ?? '';
  362. if ($toShop->syncCustom == 0) {
  363. util::fail($toShopName . '已关闭同步功能');
  364. }
  365. $toSjId = $toShop->sjId ?? 0;
  366. $fromSjId = $fromShop->sjId ?? 0;
  367. if ($toSjId != $fromSjId) {
  368. util::fail('不是您的门店');
  369. }
  370. $cachedKey = 'copy_other_shop_customers';
  371. Yii::$app->redis->executeCommand('LPUSH', [$cachedKey, $toShopId . '_' . $fromShopId]);
  372. Yii::info("从其他门店同步客户:目标门店id = " . $toShopId . ' 来源门店id = ' . $fromShopId);
  373. util::complete('已提交,1分钟后生效');
  374. }
  375. //客户列表 ssh 2021.7.8
  376. public function actionList()
  377. {
  378. $get = Yii::$app->request->get();
  379. $type = isset($get['type']) ? $get['type'] : 0;
  380. $name = isset($get['name']) ? $get['name'] : '';
  381. $mainId = $this->mainId;
  382. $isCashier = $get['isCashier'] ?? 0;
  383. if ($isCashier == 1) {
  384. //去掉收银台提示价格更新
  385. $staffId = $this->shopAdminId;
  386. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  387. }
  388. $where = ['ownMainId' => $this->mainId];
  389. $sort = 'visitTime DESC';
  390. if ($type == 1) {
  391. //消费排行
  392. $sort = 'buyAmount DESC';
  393. } else if ($type == 2) {
  394. //欠款客户
  395. $where['isDebt'] = 1;
  396. $sort = 'debtAmount DESC';
  397. } else if ($type == 3) {
  398. $where['isHd'] = 0;
  399. }
  400. $name = trim($name);
  401. if (!empty($name)) {
  402. if (is_numeric($name) && strlen($name) > 4) {
  403. if (stringUtil::isMobile($name)) {
  404. $where['mobile'] = $name;
  405. } else {
  406. $where['mobile'] = ['like', $name];
  407. }
  408. } else if (stringUtil::isLetter($name)) {
  409. $where['py'] = ['like', $name];
  410. } else {
  411. $where['name'] = ['like', $name];
  412. }
  413. }
  414. $list = CustomService::getCustomSortList($where, $sort);
  415. $main = $this->main;
  416. $list['totalUser'] = $main->totalUser ?? 0;
  417. $list['mayGatheringNum'] = $main->mayGatheringNum ?? 0;
  418. util::success($list);
  419. }
  420. //今日访客 ssh 20211022
  421. public function actionGetVisit()
  422. {
  423. $ids = StatVisitClass::getVisitCustomIds($this->shop);
  424. if (empty($ids)) {
  425. util::success(['list' => []]);
  426. }
  427. $sort = 'visitTime DESC';
  428. $where = ['id' => ['in', $ids]];
  429. $respond = CustomService::getCustomSortList($where, $sort);
  430. util::success($respond);
  431. }
  432. //客户详情 ssh 2021.1.8
  433. public function actionDetail()
  434. {
  435. $get = Yii::$app->request->get();
  436. $customId = $get['id'] ?? 0;
  437. $info = CustomService::getCustomInfo($customId);
  438. CustomClass::valid($info, $this->shopId);
  439. //手动添加的客户经纬度不完善不显示地址,引导完善客户地址
  440. if (isset($info['lat']) && empty($info['lat'])) {
  441. $info['address'] = '';
  442. }
  443. if (isset($info['long']) && empty($info['long'])) {
  444. $info['address'] = '';
  445. }
  446. $mainId = $info['mainId'] ?? 0;
  447. //超管的信息
  448. $superInfo = ShopAdminClass::getManager($mainId);
  449. $superName = $superInfo['name'] ?? '';
  450. $currentSuper = ['name' => $superName];
  451. $info['superInfo'] = $currentSuper;
  452. util::success($info);
  453. }
  454. //修改是否显示库存 ssh 20221022
  455. public function actionChangeShowStock()
  456. {
  457. $get = Yii::$app->request->get();
  458. $showStock = isset($get['showStock']) ? $get['showStock'] : 0;
  459. $customId = isset($get['customId']) ? $get['customId'] : 0;
  460. $custom = CustomClass::getById($customId, true);
  461. CustomClass::valid($custom, $this->shopId);
  462. $ghsId = $custom->ghsId ?? 0;
  463. $ghs = GhsClass::getById($ghsId, true);
  464. if (empty($ghs)) {
  465. util::fail('没有找到供货商');
  466. }
  467. $ghs->showStock = $showStock;
  468. $ghs->save();
  469. $custom->showStock = $showStock;
  470. $custom->save();
  471. util::complete();
  472. }
  473. //允许月结开关 ssh 2021.1.8
  474. public function actionDebt()
  475. {
  476. $get = Yii::$app->request->get();
  477. $debt = isset($get['debt']) ? $get['debt'] : 0;
  478. $customId = isset($get['customId']) ? $get['customId'] : 0;
  479. $custom = CustomClass::getById($customId);
  480. CustomClass::valid($custom, $this->shopId);
  481. CustomClass::debt($custom, $debt);
  482. util::complete();
  483. }
  484. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  485. public function actionSetBlack()
  486. {
  487. $black = Yii::$app->request->get('black', 2);
  488. $customId = Yii::$app->request->get('customId', 0);
  489. $custom = CustomClass::getById($customId, true);
  490. CustomClass::valid($custom, $this->shopId);
  491. $custom->black = $black;
  492. $custom->save();
  493. $ghsId = $custom->ghsId ?? 0;
  494. $ghs = GhsClass::getById($ghsId, true);
  495. if (empty($ghs)) {
  496. util::fail('出错了');
  497. }
  498. $ghs->black = $black;
  499. $ghs->save();
  500. util::complete();
  501. }
  502. //欠款客户 ssh 2021.2.4
  503. public function actionDebtList()
  504. {
  505. $get = Yii::$app->request->get();
  506. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  507. if (isset($get['name']) && !empty($get['name'])) {
  508. $where['name'] = ['like', $get['name']];
  509. }
  510. $list = CustomService::getDebtList($where);
  511. //共X个客户,合计欠款XXX元
  512. $main = $this->main;
  513. $list['customNum'] = $main->mayGatheringNum ?? 0;
  514. $list['debtAmount'] = $main->mayGathering ?? 0.00;
  515. util::success($list);
  516. }
  517. //修改欠款额度 ssh 20210625
  518. public function actionUpdateDebtLimit()
  519. {
  520. $shopAdmin = $this->shopAdmin;
  521. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  522. util::fail('管理员才能操作');
  523. }
  524. $get = Yii::$app->request->get();
  525. $id = $get['id'] ?? 0;
  526. $debtLimit = $get['debtLimit'] ?? 0;
  527. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  528. util::fail('请填写金额');
  529. }
  530. $custom = CustomClass::getById($id, true);
  531. CustomClass::valid($custom, $this->shopId);
  532. $custom->debtLimit = $debtLimit;
  533. $custom->save();
  534. util::complete();
  535. }
  536. //修改折扣 ssh 20210913
  537. public function actionChangeDiscount()
  538. {
  539. $shopAdmin = $this->shopAdmin;
  540. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  541. util::fail('管理员才能操作');
  542. }
  543. $get = Yii::$app->request->get();
  544. $id = $get['id'] ?? 0;
  545. $discount = $get['discount'] ?? 0;
  546. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  547. util::fail('请填写小数值');
  548. }
  549. $custom = CustomClass::getById($id, true);
  550. CustomClass::valid($custom, $this->shopId);
  551. $custom->discount = $discount;
  552. $custom->save();
  553. $ghsId = $custom->ghsId ?? 0;
  554. $ghs = GhsClass::getById($ghsId, true);
  555. $ghs->giveDiscount = $discount;
  556. $ghs->save();
  557. util::complete();
  558. }
  559. //修改客户等级 ssh 20211007
  560. public function actionChangeLevel()
  561. {
  562. $shopAdmin = $this->shopAdmin;
  563. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  564. util::fail('超管才能修改');
  565. }
  566. $get = Yii::$app->request->get();
  567. $customId = $get['customId'] ?? 0;
  568. $level = $get['level'] ?? 1;
  569. $custom = CustomClass::getById($customId, true);
  570. CustomClass::valid($custom, $this->shopId);
  571. $custom->level = $level;
  572. $custom->save();
  573. $ghsId = $custom->ghsId ?? 0;
  574. $ghs = GhsClass::getById($ghsId, true);
  575. if (empty($ghs)) {
  576. util::fail('出错了');
  577. }
  578. $ghs->giveLevel = $level;
  579. $ghs->save();
  580. $map = CustomClass::$levelMap;
  581. $name = $map[$level] ?? '';
  582. util::success(['levelName' => $name]);
  583. }
  584. }