CustomController.php 23 KB

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