CustomController.php 36 KB

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