CustomController.php 25 KB

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