CustomController.php 33 KB

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