CustomController.php 25 KB

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