CustomController.php 27 KB

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