CustomController.php 37 KB

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