CustomController.php 35 KB

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