CustomController.php 38 KB

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