CustomController.php 27 KB

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