CustomController.php 39 KB

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