CustomController.php 22 KB

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