CustomController.php 37 KB

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