CustomController.php 26 KB

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