CustomController.php 37 KB

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