CustomController.php 26 KB

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