CustomController.php 34 KB

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