CustomController.php 28 KB

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