CustomController.php 36 KB

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