CustomController.php 25 KB

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