CustomController.php 41 KB

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