CustomController.php 27 KB

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