CustomController.php 34 KB

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