CustomController.php 34 KB

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