CustomController.php 25 KB

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