CustomController.php 23 KB

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