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