CustomController.php 36 KB

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