CustomController.php 35 KB

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