CustomController.php 22 KB

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