CustomController.php 24 KB

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