CustomController.php 25 KB

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