CustomController.php 30 KB

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