CustomController.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  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 2025312
  293. public function actionModifyShortName()
  294. {
  295. $get = Yii::$app->request->get();
  296. $id = $get['id'] ?? 0;
  297. $shortName = $get['shortName'] ?? 0;
  298. $custom = CustomClass::getById($id, true);
  299. if (empty($custom) || $custom->ownMainId != $this->mainId) {
  300. util::fail('修改失败');
  301. }
  302. $custom->shortName = $shortName;
  303. $custom->save();
  304. util::complete('修改成功');
  305. }
  306. //修改物流信息 ssh 20230105
  307. public function actionChangeWl()
  308. {
  309. util::fail('修改失败');
  310. }
  311. //修改名称 ssh 2022096
  312. public function actionChangeName()
  313. {
  314. $get = Yii::$app->request->get();
  315. $name = $get['name'] ?? '';
  316. $id = $get['id'] ?? 0;
  317. if (empty($name)) {
  318. util::fail('请填写名称');
  319. }
  320. $py = stringUtil::py($name);
  321. $custom = CustomClass::getById($id, true);
  322. CustomClass::valid($custom, $this->shopId);
  323. $custom->name = $name;
  324. $custom->py = $py;
  325. $custom->save();
  326. OrderClass::updateByCondition(['customId' => $id], ['customName' => $name, 'customNamePy' => $py]);
  327. $customShopId = $custom->shopId ?? 0;
  328. //在首店修改客户名称,直营店自动同步
  329. $masterShop = $this->shop;
  330. if (isset($masterShop->default) && $masterShop->default == 1) {
  331. $sjId = $masterShop->sjId ?? 0;
  332. $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  333. foreach ($shopList as $shop) {
  334. $shopId = $shop->id ?? 0;
  335. if (isset($shop->join) && $shop->join == 1) {
  336. //加盟店不同步修改
  337. continue;
  338. }
  339. if ($shopId == $masterShop->id) {
  340. //前面已经同步修改过了
  341. continue;
  342. }
  343. $custom = CustomClass::getByCondition(['ownShopId' => $shopId, 'shopId' => $customShopId], true);
  344. if (empty($custom)) {
  345. continue;
  346. }
  347. $custom->name = $name;
  348. $custom->py = $py;
  349. $custom->save();
  350. }
  351. }
  352. util::complete('修改成功');
  353. }
  354. //帮客户添加员工 ssh 20220613
  355. public function actionAddStaff()
  356. {
  357. $post = Yii::$app->request->post();
  358. $customId = $post['id'] ?? 0;
  359. $mobile = $post['mobile'] ?? 0;
  360. if (stringUtil::isMobile($mobile) == false) {
  361. util::fail('手机号填写错误');
  362. }
  363. $info = CustomService::getById($customId, true);
  364. CustomClass::valid($info, $this->shopId);
  365. $connection = Yii::$app->db;
  366. $transaction = $connection->beginTransaction();
  367. try {
  368. $shopId = $info->shopId ?? 0;
  369. $customShop = ShopClass::getById($shopId, true);
  370. if (empty($customShop)) {
  371. util::fail('没有找到客户的门店');
  372. }
  373. $mainId = $customShop->mainId ?? 0;
  374. $ptStyle = dict::getDict('ptStyle', 'hd');
  375. $adminInfo = ['name' => $mobile, 'mobile' => $mobile, 'style' => $ptStyle, 'currentShopId' => $shopId];
  376. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  377. $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
  378. $roleList = AdminRoleClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  379. if (empty($roleList)) {
  380. util::fail('客户门店没有员工角色');
  381. }
  382. $currentRoleId = 0;
  383. foreach ($roleList as $role) {
  384. $roleId = $role->id ?? 0;
  385. $currentRoleId = $roleId;
  386. if ($role->roleName == '员工') {
  387. break;
  388. }
  389. }
  390. $params = [
  391. 'shopId' => $shopId,
  392. 'mobile' => $mobile,
  393. 'roleId' => $currentRoleId,
  394. ];
  395. \bizHd\staff\classes\StaffClass::appGenerateStaff($params, $admin);
  396. $transaction->commit();
  397. util::complete('添加成功');
  398. } catch (\Exception $e) {
  399. $transaction->rollBack();
  400. util::fail('添加失败');
  401. }
  402. }
  403. //添加新花店 ssh 2021.1.8
  404. public function actionAdd()
  405. {
  406. $post = Yii::$app->request->post();
  407. $post['style'] = SjClass::STYLE_RETAIL;
  408. $post['introSjId'] = $this->sjId;
  409. $post['introStyle'] = SjClass::STYLE_SUPPLIER;
  410. $mobile = $post['mobile'] ?? '';
  411. $confirmMobile = $post['confirmMobile'];
  412. $address = $post['address'] ?? '';
  413. util::fail('功能已停用');
  414. if (stringUtil::isMobile($mobile) == false) {
  415. util::fail(' 请填写正确的手机号');
  416. }
  417. if ($mobile != $confirmMobile) {
  418. util::fail('二次号码填写不一致');
  419. }
  420. $name = $post['name'] ?? '';
  421. if (empty($name)) {
  422. util::fail('名称不能为空');
  423. }
  424. if (stringUtil::getWordNum($name) > 15) {
  425. util::fail('名称不能超过15个汉字');
  426. }
  427. $has = SjClass::getByCondition(['name' => $name, 'style' => SjClass::STYLE_RETAIL]);
  428. if (!empty($has)) {
  429. util::fail('名称已经存在');
  430. }
  431. $has = ApplyClass::getByCondition(['mobile' => $mobile, 'style' => SjClass::STYLE_RETAIL]);
  432. if (!empty($has)) {
  433. util::fail('手机号已经添加过');
  434. }
  435. if (empty($address)) {
  436. util::fail('请填写地址');
  437. }
  438. $connection = Yii::$app->db;
  439. $transaction = $connection->beginTransaction();
  440. try {
  441. $shop = $this->shop;
  442. $sjId = $this->sjId;
  443. $shopId = $this->shopId;
  444. $sjName = $this->sj->name ?? '';
  445. $city = $shop->city ?? '';
  446. $dist = $shop->dist ?? '';
  447. $applyData = [
  448. 'name' => $name,
  449. 'licenseNo' => $mobile,
  450. 'certType' => ApplyClass::CERT_TYPE_MOBILE,
  451. 'mobile' => $mobile,
  452. 'introSjId' => $sjId,
  453. 'introSjName' => $sjName,
  454. 'introShopId' => $shopId,
  455. 'introStyle' => SjClass::STYLE_SUPPLIER,
  456. 'from' => ApplyClass::FROM_GHS,
  457. 'style' => SjClass::STYLE_RETAIL,
  458. 'province' => $shop->province ?? '',
  459. 'city' => $city,
  460. 'dist' => $dist,
  461. 'address' => $address,
  462. 'status' => ApplyClass::STATUS_PASS,
  463. 'replace' => 1,//1表示供货商添加的客户
  464. ];
  465. $apply = ApplyService::replaceRetail($applyData);
  466. $id = $apply['id'] ?? 0;
  467. $respond = ApplyService::pass($id);
  468. $shop = $respond['shop'] ?? [];
  469. $sj = $respond['sj'] ?? [];
  470. $hdSjId = $sj['id'] ?? 0;
  471. $hdShopId = $shop->id ?? 0;
  472. ApplyClass::updateById($id, ['sjId' => $hdSjId, 'shopId' => $hdShopId]);
  473. if (empty($hdShopId)) {
  474. util::fail('客户没有添加成功!');
  475. }
  476. $custom = CustomClass::build($this->shopId, $hdShopId);
  477. $custom['avatar'] = imgUtil::groupImg($custom['avatar']);
  478. //客户欠款额度设置
  479. $debt = isset($post['debt']) && $post['debt'] == CustomClass::IS_DEBT_YES ? CustomClass::IS_DEBT_YES : CustomClass::IS_DEBT_NO;
  480. $customId = $custom['id'] ?? 0;
  481. $debtLimit = isset($post['debtLimit']) && is_numeric($post['debtLimit']) ? $post['debtLimit'] : 5000;
  482. CustomClass::updateById($customId, ['debtLimit' => $debtLimit, 'debt' => $debt]);
  483. $transaction->commit();
  484. util::success($custom);
  485. } catch (\Exception $exception) {
  486. $transaction->rollBack();
  487. Yii::info("添加客户没有成功:" . $exception->getMessage());
  488. util::fail('添加客户没有成功');
  489. }
  490. }
  491. //向队列写入新花店数据 shizhongqi 2022.6.8
  492. public function actionCreateCustomers()
  493. {
  494. $post = Yii::$app->request->post();
  495. $virtual = $post['virtual'] ?? 0;
  496. $arr = [];
  497. for ($i = 1; $i <= 5; $i++) {
  498. $name = $post['name' . $i] ?? '';
  499. $mobile = $post['mobile' . $i] ?? '';
  500. $confirmMobile = $post['confirmMobile' . $i] ?? '';
  501. if (empty($name) && empty($mobile) && empty($confirmMobile)) {
  502. continue;
  503. }
  504. if (empty($name)) {
  505. util::fail('花店名称不能为空');
  506. }
  507. if (stringUtil::getWordNum($name) > 15) {
  508. util::fail('名称不能超过15个汉字');
  509. }
  510. if (empty($mobile)) {
  511. //添加虚拟客户
  512. if ($virtual == 1) {
  513. $mobile = orderSn::getMobileSn();
  514. $confirmMobile = $mobile;
  515. } else {
  516. util::fail($name . " 手机号不能为空");
  517. }
  518. }
  519. if (stringUtil::isMobile($mobile) == false) {
  520. util::fail($name . " 手机号格式不正确");
  521. }
  522. if ($mobile != $confirmMobile) {
  523. util::fail($name . " 二次手机号不一致");
  524. }
  525. $hasShop = ShopClass::getByCondition(['mobile' => $mobile], true);
  526. if (!empty($hasShop)) {
  527. $shop = ShopClass::getByCondition(['mobile' => $mobile, 'ptStyle' => 1], true);
  528. if (!empty($shop)) {
  529. $ghsShopId = $this->shopId;
  530. $hdShopId = $shop->id;
  531. $custom = CustomClass::build($ghsShopId, $hdShopId);
  532. $customId = $custom['id'] ?? 0;
  533. $custom = CustomClass::getById($customId, true);
  534. if (!empty($custom)) {
  535. $custom->name = $name;
  536. $py = stringUtil::py($name);
  537. $custom->py = $py;
  538. $custom->save();
  539. }
  540. util::complete($shop->merchantName . ' 添加成功');
  541. }
  542. util::fail($mobile . "手机号已经添加过了");
  543. }
  544. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  545. if (!empty($has)) {
  546. util::fail($mobile . "手机号已经申请添加过了");
  547. }
  548. $arr[] = ['name' => $name, 'mobile' => $mobile];
  549. }
  550. if (empty($arr)) {
  551. util::fail('请填写客户');
  552. }
  553. foreach ($arr as $item) {
  554. $name = $item['name'] ?? '';
  555. $mobile = $item['mobile'] ?? '';
  556. //队列方式去处理
  557. $customerCachedKey = 'batch_create_customer_list';
  558. $value = $name . '_' . $mobile . '_' . $this->sjId . '_' . $this->shop->id . '_' . $this->sj->name . '_' . $this->shopAdminId;
  559. Yii::$app->redis->executeCommand('LPUSH', [$customerCachedKey, $value]);
  560. Yii::info("供货商添加客户:name - " . $name . ' == mobile - ' . $mobile);
  561. Yii::info("shopAdminId: " . $this->shopAdminId);
  562. }
  563. util::complete('已提交,15秒后生效');
  564. }
  565. //从其它店同步客户 shizhongqi 2022.6.9
  566. public function actionCopyCustomers()
  567. {
  568. $get = Yii::$app->request->get();
  569. $fromShopId = $get['fromShopId'] ?? 0;
  570. $fromShop = ShopClass::getById($fromShopId, true);
  571. if (empty($fromShop)) {
  572. util::fail('门店不存在');
  573. }
  574. $toShopId = $this->shopId;
  575. if ($fromShopId == $toShopId) {
  576. util::fail('本店无需同步');
  577. }
  578. $fromShopName = $fromShop->shopName ?? '';
  579. if ($fromShop->syncCustom == 0) {
  580. util::fail('不允许从' . $fromShopName . '同步客户');
  581. }
  582. $toShop = $this->shop;
  583. $toShopName = $toShop->shopName ?? '';
  584. if ($toShop->syncCustom == 0) {
  585. util::fail($toShopName . '已关闭同步功能');
  586. }
  587. $toSjId = $toShop->sjId ?? 0;
  588. $fromSjId = $fromShop->sjId ?? 0;
  589. if ($toSjId != $fromSjId) {
  590. util::fail('不是您的门店');
  591. }
  592. $cachedKey = 'copy_other_shop_customers';
  593. Yii::$app->redis->executeCommand('LPUSH', [$cachedKey, $toShopId . '_' . $fromShopId]);
  594. Yii::info("从其他门店同步客户:目标门店id = " . $toShopId . ' 来源门店id = ' . $fromShopId);
  595. util::complete('已提交,1分钟后生效');
  596. }
  597. //客户列表 ssh 2021.7.8
  598. public function actionList()
  599. {
  600. $staff = $this->shopAdmin;
  601. if (isset($staff->identity) && $staff->identity == 2) {
  602. util::success(['list' => []]);
  603. }
  604. $get = Yii::$app->request->get();
  605. $type = isset($get['type']) ? $get['type'] : 0;
  606. $name = isset($get['name']) ? $get['name'] : '';
  607. $export = $get['export'] ?? 0;
  608. $mainId = $this->mainId;
  609. $isCashier = $get['isCashier'] ?? 0;
  610. if ($isCashier == 1) {
  611. //去掉收银台提示价格更新
  612. $staffId = $this->shopAdminId;
  613. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  614. }
  615. $where = ['ownMainId' => $this->mainId];
  616. $sort = 'visitTime DESC';
  617. if ($type == 1) {
  618. //消费排行
  619. $sort = 'buyAmount DESC';
  620. } else if ($type == 2) {
  621. //欠款客户
  622. $where['isDebt'] = 1;
  623. $sort = '(debtAmount-balance) DESC';
  624. } else if ($type == 3) {
  625. $where['level'] = 0;
  626. } else if ($type == 4) {
  627. //最近未下单
  628. $recentDay = isset($get['recentDay']) && is_numeric($get['recentDay']) ? (int)$get['recentDay'] : 7;
  629. $totalSecond = bcmul(86400, $recentDay);
  630. $currentSecond = bcsub(time(), $totalSecond);
  631. $currentDate = date("Y-m-d H:i:s", $currentSecond);
  632. $where['recentExpend<'] = $currentDate;
  633. $sort = 'recentExpend desc';
  634. }
  635. $name = trim($name);
  636. if (!empty($name)) {
  637. if (is_numeric($name)) {
  638. if (stringUtil::isMobile($name)) {
  639. $where['mobile'] = $name;
  640. } else {
  641. $shop = $this->shop;
  642. //如果花大苪,搜索数字还是优先搜索客户名称,因为客户名称经常会编号
  643. if ($shop->id == 8249) {
  644. $where['name'] = ['like', $name];
  645. } else {
  646. $where['mobile'] = ['like', $name];
  647. }
  648. }
  649. } else if (stringUtil::isLetter($name)) {
  650. $where['py'] = ['like', $name];
  651. } else {
  652. $where['name'] = ['like', $name];
  653. }
  654. }
  655. if ($export == 1) {
  656. ini_set('memory_limit', '2045M');
  657. set_time_limit(0);
  658. CustomClass::exportCustom($where, $sort, $this->mainId);
  659. util::stop();
  660. }
  661. $list = CustomService::getCustomSortList($where, $sort);
  662. $main = $this->main;
  663. $list['totalUser'] = $main->totalUser ?? 0;
  664. $list['mayGatheringNum'] = $main->mayGatheringNum ?? 0;
  665. $list['shopInfo'] = $this->shop;
  666. util::success($list);
  667. }
  668. //今日访客 ssh 20211022
  669. public function actionGetVisit()
  670. {
  671. $ids = StatVisitClass::getVisitCustomIds($this->shop);
  672. if (empty($ids)) {
  673. util::success(['list' => []]);
  674. }
  675. $sort = 'visitTime DESC';
  676. $where = ['id' => ['in', $ids]];
  677. $respond = CustomService::getCustomSortList($where, $sort);
  678. util::success($respond);
  679. }
  680. //客户详情 ssh 2021.1.8
  681. public function actionDetail()
  682. {
  683. $get = Yii::$app->request->get();
  684. $customId = $get['id'] ?? 0;
  685. $info = CustomService::getCustomInfo($customId);
  686. CustomClass::valid($info, $this->shopId);
  687. $mainId = $info['mainId'] ?? 0;
  688. //超管的信息
  689. $superInfo = ShopAdminClass::getManager($mainId);
  690. $superName = $superInfo['name'] ?? '';
  691. $currentSuper = ['name' => $superName];
  692. $info['superInfo'] = $currentSuper;
  693. util::success($info);
  694. }
  695. //修改是否显示库存 ssh 20221022
  696. public function actionChangeShowStock()
  697. {
  698. $get = Yii::$app->request->get();
  699. $showStock = isset($get['showStock']) ? $get['showStock'] : 0;
  700. $customId = isset($get['customId']) ? $get['customId'] : 0;
  701. $custom = CustomClass::getById($customId, true);
  702. CustomClass::valid($custom, $this->shopId);
  703. $ghsId = $custom->ghsId ?? 0;
  704. $ghs = GhsClass::getById($ghsId, true);
  705. if (empty($ghs)) {
  706. util::fail('没有找到供货商');
  707. }
  708. $ghs->showStock = $showStock;
  709. $ghs->save();
  710. $custom->showStock = $showStock;
  711. $custom->save();
  712. util::complete();
  713. }
  714. //修改状态 ssh 20240924
  715. public function actionChangePassStatus()
  716. {
  717. $get = Yii::$app->request->get();
  718. $passStatus = isset($get['passStatus']) ? $get['passStatus'] : 0;
  719. $customId = isset($get['customId']) ? $get['customId'] : 0;
  720. $custom = CustomClass::getById($customId, true);
  721. CustomClass::valid($custom, $this->shopId);
  722. $ghsId = $custom->ghsId ?? 0;
  723. $ghs = GhsClass::getById($ghsId, true);
  724. if (empty($ghs)) {
  725. util::fail('没有找到供货商');
  726. }
  727. $ghs->passStatus = $passStatus;
  728. $ghs->save();
  729. $custom->passStatus = $passStatus;
  730. $custom->save();
  731. util::complete();
  732. }
  733. //允许月结开关 ssh 2021.1.8
  734. public function actionDebt()
  735. {
  736. if (getenv('YII_ENV') == 'production') {
  737. if ($this->mainId == 4884) {
  738. if ($this->shopAdminId != 130738) {
  739. util::fail('只有倩姐才能修改');
  740. }
  741. }
  742. }
  743. $get = Yii::$app->request->get();
  744. $debt = isset($get['debt']) ? $get['debt'] : 0;
  745. $customId = isset($get['customId']) ? $get['customId'] : 0;
  746. $custom = CustomClass::getById($customId);
  747. CustomClass::valid($custom, $this->shopId);
  748. CustomClass::debt($custom, $debt);
  749. util::complete();
  750. }
  751. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  752. public function actionSetBlack()
  753. {
  754. $black = Yii::$app->request->get('black', 2);
  755. $customId = Yii::$app->request->get('customId', 0);
  756. $custom = CustomClass::getById($customId, true);
  757. CustomClass::valid($custom, $this->shopId);
  758. $custom->black = $black;
  759. $custom->save();
  760. $ghsId = $custom->ghsId ?? 0;
  761. $ghs = GhsClass::getById($ghsId, true);
  762. if (empty($ghs)) {
  763. util::fail('出错了');
  764. }
  765. $ghs->black = $black;
  766. $ghs->save();
  767. util::complete();
  768. }
  769. //欠款客户 ssh 2021.2.4
  770. public function actionDebtList()
  771. {
  772. $get = Yii::$app->request->get();
  773. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  774. if (isset($get['name']) && !empty($get['name'])) {
  775. $where['name'] = ['like', $get['name']];
  776. }
  777. $list = CustomService::getDebtList($where);
  778. //共X个客户,合计欠款XXX元
  779. $main = $this->main;
  780. $list['customNum'] = $main->mayGatheringNum ?? 0;
  781. $list['debtAmount'] = $main->mayGathering ?? 0.00;
  782. util::success($list);
  783. }
  784. //修改欠款额度 ssh 20210625
  785. public function actionUpdateDebtLimit()
  786. {
  787. $shopAdmin = $this->shopAdmin;
  788. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  789. util::fail('管理员才能操作');
  790. }
  791. if (getenv('YII_ENV') == 'production') {
  792. if ($this->mainId == 4884) {
  793. if ($this->shopAdminId != 130738) {
  794. util::fail('请倩姐修改');
  795. }
  796. }
  797. if ($this->mainId == 10536) {
  798. if ($this->shopAdminId != 136416 && $this->shopAdminId != 136419) {
  799. util::fail('请闵总修改');
  800. }
  801. }
  802. }
  803. $get = Yii::$app->request->get();
  804. $id = $get['id'] ?? 0;
  805. $debtLimit = $get['debtLimit'] ?? 0;
  806. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  807. util::fail('请填写金额');
  808. }
  809. $custom = CustomClass::getById($id, true);
  810. CustomClass::valid($custom, $this->shopId);
  811. $custom->debtLimit = $debtLimit;
  812. $custom->save();
  813. util::complete();
  814. }
  815. //修改货位名称 ssh 20241006
  816. public function actionUpdateSeatSnName()
  817. {
  818. $get = Yii::$app->request->get();
  819. $id = $get['id'] ?? 0;
  820. $seatSnName = $get['seatSnName'] ?? '';
  821. $custom = CustomClass::getById($id, true);
  822. CustomClass::valid($custom, $this->shopId);
  823. $custom->seatSnName = $seatSnName;
  824. $custom->save();
  825. util::complete();
  826. }
  827. //修改折扣 ssh 20210913
  828. public function actionChangeDiscount()
  829. {
  830. $shopAdmin = $this->shopAdmin;
  831. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  832. util::fail('管理员才能操作');
  833. }
  834. $get = Yii::$app->request->get();
  835. $id = $get['id'] ?? 0;
  836. $discount = $get['discount'] ?? 0;
  837. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  838. util::fail('请填写小数值');
  839. }
  840. $custom = CustomClass::getById($id, true);
  841. CustomClass::valid($custom, $this->shopId);
  842. $custom->discount = $discount;
  843. $custom->save();
  844. $ghsId = $custom->ghsId ?? 0;
  845. $ghs = GhsClass::getById($ghsId, true);
  846. $ghs->giveDiscount = $discount;
  847. $ghs->save();
  848. util::complete();
  849. }
  850. //修改客户等级 ssh 20211007
  851. public function actionChangeLevel()
  852. {
  853. $shopAdmin = $this->shopAdmin;
  854. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  855. util::fail('超管才能修改');
  856. }
  857. //泉城的只有苏小娟才能修改
  858. if (getenv('YII_ENV') == 'production') {
  859. if ($this->mainId == 60) {
  860. if (in_array($this->adminId, [2499, 4]) == false) {
  861. util::fail('请小娟修改');
  862. }
  863. }
  864. }
  865. $get = Yii::$app->request->get();
  866. $customId = $get['customId'] ?? 0;
  867. $level = $get['level'] ?? 1;
  868. $custom = CustomClass::getById($customId, true);
  869. CustomClass::valid($custom, $this->shopId);
  870. $custom->level = $level;
  871. $custom->save();
  872. $ghsId = $custom->ghsId ?? 0;
  873. $ghs = GhsClass::getById($ghsId, true);
  874. if (empty($ghs)) {
  875. util::fail('出错了');
  876. }
  877. $ghs->giveLevel = $level;
  878. $ghs->save();
  879. $map = CustomClass::$levelMap;
  880. $name = $map[$level] ?? '';
  881. util::success(['levelName' => $name]);
  882. }
  883. //打印货位号 ssh 20241006
  884. public function actionPrintSeatSn()
  885. {
  886. $get = Yii::$app->request->get();
  887. $customId = $get['id'] ?? 0;
  888. $custom = CustomClass::getById($customId, true);
  889. CustomClass::valid($custom, $this->shopId);
  890. $seatSn = $custom->seatSn ?? 0;
  891. if ($seatSn == 0) {
  892. util::fail('没有货位');
  893. }
  894. $customName = $custom->name ?? '';
  895. if (isset($custom->seatSnName) && !empty($custom->seatSnName)) {
  896. $customName = $custom->seatSnName ?? '';
  897. }
  898. $customName = stringUtil::subStringUtf8($customName, 7, '..');
  899. $a4Print = [
  900. 'customName' => $customName,
  901. 'seatSn' => $seatSn,
  902. ];
  903. $info['printData'] = $a4Print;
  904. $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}}]}';
  905. $info['template'] = $template;
  906. $custom->printSeatSn = 1;
  907. $custom->save();
  908. util::success($info);
  909. }
  910. }