CustomController.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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. 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'] : 5000;
  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 = isset($get['type']) ? $get['type'] : 0;
  629. $name = isset($get['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. if ($type == 1) {
  641. //消费排行
  642. $sort = 'buyAmount DESC';
  643. } else if ($type == 2) {
  644. //欠款客户
  645. $where['isDebt'] = 1;
  646. $sort = '(debtAmount-balance) DESC';
  647. } else if ($type == 3) {
  648. $where['level'] = 0;
  649. } else if ($type == 4) {
  650. //最近未下单
  651. $recentDay = isset($get['recentDay']) && is_numeric($get['recentDay']) ? (int)$get['recentDay'] : 7;
  652. $totalSecond = bcmul(86400, $recentDay);
  653. $currentSecond = bcsub(time(), $totalSecond);
  654. $currentDate = date("Y-m-d H:i:s", $currentSecond);
  655. $where['recentExpend<'] = $currentDate;
  656. $sort = 'recentExpend desc';
  657. }
  658. $name = trim($name);
  659. if (!empty($name)) {
  660. if (is_numeric($name)) {
  661. if (stringUtil::isMobile($name)) {
  662. $where['mobile'] = $name;
  663. } else {
  664. $shop = $this->shop;
  665. //如果花大苪,搜索数字还是优先搜索客户名称,因为客户名称经常会编号
  666. if ($shop->id == 8249) {
  667. $where['name'] = ['like', $name];
  668. } else {
  669. $where['mobile'] = ['like', $name];
  670. }
  671. }
  672. } else if (stringUtil::isLetter($name)) {
  673. $where['py'] = ['like', $name];
  674. } else {
  675. $where['name'] = ['like', $name];
  676. }
  677. }
  678. if ($export == 1) {
  679. ini_set('memory_limit', '2045M');
  680. set_time_limit(0);
  681. CustomClass::exportCustom($where, $sort, $this->mainId);
  682. util::stop();
  683. }
  684. $list = CustomService::getCustomSortList($where, $sort);
  685. $main = $this->main;
  686. $list['totalUser'] = $main->totalUser ?? 0;
  687. $list['mayGatheringNum'] = $main->mayGatheringNum ?? 0;
  688. $list['shopInfo'] = $this->shop;
  689. util::success($list);
  690. }
  691. //今日访客 ssh 20211022
  692. public function actionGetVisit()
  693. {
  694. $ids = StatVisitClass::getVisitCustomIds($this->shop);
  695. if (empty($ids)) {
  696. util::success(['list' => []]);
  697. }
  698. $sort = 'visitTime DESC';
  699. $where = ['id' => ['in', $ids]];
  700. $respond = CustomService::getCustomSortList($where, $sort);
  701. util::success($respond);
  702. }
  703. //客户详情 ssh 2021.1.8
  704. public function actionDetail()
  705. {
  706. $get = Yii::$app->request->get();
  707. $customId = $get['id'] ?? 0;
  708. $info = CustomService::getCustomInfo($customId);
  709. CustomClass::valid($info, $this->shopId);
  710. $mainId = $info['mainId'] ?? 0;
  711. //超管的信息
  712. $superInfo = ShopAdminClass::getManager($mainId);
  713. $superName = $superInfo['name'] ?? '';
  714. $currentSuper = ['name' => $superName];
  715. $info['superInfo'] = $currentSuper;
  716. util::success($info);
  717. }
  718. //修改是否显示库存 ssh 20221022
  719. public function actionChangeShowStock()
  720. {
  721. $get = Yii::$app->request->get();
  722. $showStock = isset($get['showStock']) ? $get['showStock'] : 0;
  723. $customId = isset($get['customId']) ? $get['customId'] : 0;
  724. $custom = CustomClass::getById($customId, true);
  725. CustomClass::valid($custom, $this->shopId);
  726. $ghsId = $custom->ghsId ?? 0;
  727. $ghs = GhsClass::getById($ghsId, true);
  728. if (empty($ghs)) {
  729. util::fail('没有找到供货商');
  730. }
  731. $ghs->showStock = $showStock;
  732. $ghs->save();
  733. $custom->showStock = $showStock;
  734. $custom->save();
  735. util::complete();
  736. }
  737. //修改状态 ssh 20240924
  738. public function actionChangePassStatus()
  739. {
  740. $get = Yii::$app->request->get();
  741. $passStatus = isset($get['passStatus']) ? $get['passStatus'] : 0;
  742. $customId = isset($get['customId']) ? $get['customId'] : 0;
  743. $custom = CustomClass::getById($customId, true);
  744. CustomClass::valid($custom, $this->shopId);
  745. $ghsId = $custom->ghsId ?? 0;
  746. $ghs = GhsClass::getById($ghsId, true);
  747. if (empty($ghs)) {
  748. util::fail('没有找到供货商');
  749. }
  750. $ghs->passStatus = $passStatus;
  751. $ghs->save();
  752. $custom->passStatus = $passStatus;
  753. $custom->save();
  754. util::complete();
  755. }
  756. public function actionChangeHome()
  757. {
  758. $get = Yii::$app->request->get();
  759. $home = isset($get['home']) ? $get['home'] : 0;
  760. $customId = !empty($get['customId']) ? $get['customId'] : 0;
  761. $custom = CustomClass::getById($customId, true);
  762. if (empty($custom)) {
  763. util::fail('没有找到客户呢');
  764. }
  765. if ($custom->ownShopId != $this->shopId) {
  766. util::fail('不是你的客户');
  767. }
  768. $ghsId = $custom->ghsId ?? 0;
  769. $ghs = GhsClass::getById($ghsId, true);
  770. if (empty($ghs)) {
  771. util::fail('没有找到供货商');
  772. }
  773. $ghs->home = $home;
  774. $ghs->save();
  775. $custom->home = $home;
  776. $custom->save();
  777. util::complete();
  778. }
  779. public function actionModifyHomeAmount()
  780. {
  781. $get = Yii::$app->request->get();
  782. $id = $get['id'] ?? 0;
  783. $homeAmount = $get['homeAmount'] ?? 0;
  784. $homeType = $get['homeType'] ?? 0;
  785. $custom = CustomClass::getById($id, true);
  786. if (empty($custom)) {
  787. util::fail('没有找到客户');
  788. }
  789. if ($custom->ownMainId != $this->mainId) {
  790. util::fail('不是你的客户');
  791. }
  792. $ghsId = $custom->ghsId ?? 0;
  793. $ghs = GhsClass::getById($ghsId, true);
  794. if (empty($ghs)) {
  795. util::fail('没有找到供货商');
  796. }
  797. $custom->homeAmount = $homeAmount;
  798. $custom->homeType = $homeType;
  799. $custom->save();
  800. $ghs->homeAmount = $homeAmount;
  801. $ghs->homeType = $homeType;
  802. $ghs->save();
  803. util::complete('修改成功');
  804. }
  805. //允许月结开关 ssh 2021.1.8
  806. public function actionDebt()
  807. {
  808. if (getenv('YII_ENV') == 'production') {
  809. if ($this->mainId == 4884) {
  810. if ($this->shopAdminId != 130738) {
  811. util::fail('只有倩姐才能修改');
  812. }
  813. }
  814. }
  815. $get = Yii::$app->request->get();
  816. $debt = isset($get['debt']) ? $get['debt'] : 0;
  817. $customId = isset($get['customId']) ? $get['customId'] : 0;
  818. $custom = CustomClass::getById($customId);
  819. CustomClass::valid($custom, $this->shopId);
  820. CustomClass::debt($custom, $debt);
  821. util::complete();
  822. }
  823. //采购查看权限的黑白名单开关 shizhongqi 2021.08.08
  824. public function actionSetBlack()
  825. {
  826. $black = Yii::$app->request->get('black', 2);
  827. $customId = Yii::$app->request->get('customId', 0);
  828. $custom = CustomClass::getById($customId, true);
  829. CustomClass::valid($custom, $this->shopId);
  830. $custom->black = $black;
  831. $custom->save();
  832. $ghsId = $custom->ghsId ?? 0;
  833. $ghs = GhsClass::getById($ghsId, true);
  834. if (empty($ghs)) {
  835. util::fail('出错了');
  836. }
  837. $ghs->black = $black;
  838. $ghs->save();
  839. util::complete();
  840. }
  841. //欠款客户 ssh 2021.2.4
  842. public function actionDebtList()
  843. {
  844. $get = Yii::$app->request->get();
  845. $where = ['ownShopId' => $this->shopId, 'isDebt' => 1];
  846. if (isset($get['name']) && !empty($get['name'])) {
  847. $where['name'] = ['like', $get['name']];
  848. }
  849. $list = CustomService::getDebtList($where);
  850. //共X个客户,合计欠款XXX元
  851. $main = $this->main;
  852. $list['customNum'] = $main->mayGatheringNum ?? 0;
  853. $list['debtAmount'] = $main->mayGathering ?? 0.00;
  854. util::success($list);
  855. }
  856. //修改欠款额度 ssh 20210625
  857. public function actionUpdateDebtLimit()
  858. {
  859. $shopAdmin = $this->shopAdmin;
  860. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  861. util::fail('管理员才能操作');
  862. }
  863. if (getenv('YII_ENV') == 'production') {
  864. if ($this->mainId == 4884) {
  865. if ($this->shopAdminId != 130738) {
  866. util::fail('请倩姐修改');
  867. }
  868. }
  869. if ($this->mainId == 10536) {
  870. if ($this->shopAdminId != 136416 && $this->shopAdminId != 136419) {
  871. util::fail('请闵总修改');
  872. }
  873. }
  874. }
  875. $get = Yii::$app->request->get();
  876. $id = $get['id'] ?? 0;
  877. $debtLimit = $get['debtLimit'] ?? 0;
  878. if (is_numeric($debtLimit) == false || $debtLimit <= 0) {
  879. util::fail('请填写金额');
  880. }
  881. $custom = CustomClass::getById($id, true);
  882. CustomClass::valid($custom, $this->shopId);
  883. $custom->debtLimit = $debtLimit;
  884. $custom->save();
  885. util::complete();
  886. }
  887. //修改货位名称 ssh 20241006
  888. public function actionUpdateSeatSnName()
  889. {
  890. $get = Yii::$app->request->get();
  891. $id = $get['id'] ?? 0;
  892. $seatSnName = $get['seatSnName'] ?? '';
  893. $custom = CustomClass::getById($id, true);
  894. CustomClass::valid($custom, $this->shopId);
  895. $custom->seatSnName = $seatSnName;
  896. $custom->save();
  897. util::complete();
  898. }
  899. //修改折扣 ssh 20210913
  900. public function actionChangeDiscount()
  901. {
  902. $shopAdmin = $this->shopAdmin;
  903. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  904. util::fail('管理员才能操作');
  905. }
  906. $get = Yii::$app->request->get();
  907. $id = $get['id'] ?? 0;
  908. $discount = $get['discount'] ?? 0;
  909. if (is_numeric($discount) == false || $discount > 1 || $discount == 0) {
  910. util::fail('请填写小数值');
  911. }
  912. $custom = CustomClass::getById($id, true);
  913. CustomClass::valid($custom, $this->shopId);
  914. $custom->discount = $discount;
  915. $custom->save();
  916. $ghsId = $custom->ghsId ?? 0;
  917. $ghs = GhsClass::getById($ghsId, true);
  918. $ghs->giveDiscount = $discount;
  919. $ghs->save();
  920. util::complete();
  921. }
  922. //修改客户等级 ssh 20211007
  923. public function actionChangeLevel()
  924. {
  925. $shopAdmin = $this->shopAdmin;
  926. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  927. util::fail('超管才能修改');
  928. }
  929. //泉城的只有苏小娟才能修改
  930. if (getenv('YII_ENV') == 'production') {
  931. if ($this->mainId == 60) {
  932. if (in_array($this->adminId, [2499, 4]) == false) {
  933. util::fail('请小娟修改');
  934. }
  935. }
  936. }
  937. $get = Yii::$app->request->get();
  938. $customId = $get['customId'] ?? 0;
  939. $level = $get['level'] ?? 1;
  940. $custom = CustomClass::getById($customId, true);
  941. CustomClass::valid($custom, $this->shopId);
  942. $custom->level = $level;
  943. $custom->save();
  944. $ghsId = $custom->ghsId ?? 0;
  945. $ghs = GhsClass::getById($ghsId, true);
  946. if (empty($ghs)) {
  947. util::fail('出错了');
  948. }
  949. $ghs->giveLevel = $level;
  950. $ghs->save();
  951. $map = CustomClass::$levelMap;
  952. $name = $map[$level] ?? '';
  953. util::success(['levelName' => $name]);
  954. }
  955. //打印货位号 ssh 20241006
  956. public function actionPrintSeatSn()
  957. {
  958. $get = Yii::$app->request->get();
  959. $customId = $get['id'] ?? 0;
  960. $custom = CustomClass::getById($customId, true);
  961. CustomClass::valid($custom, $this->shopId);
  962. $seatSn = $custom->seatSn ?? 0;
  963. if ($seatSn == 0) {
  964. util::fail('没有货位');
  965. }
  966. $customName = $custom->name ?? '';
  967. if (isset($custom->seatSnName) && !empty($custom->seatSnName)) {
  968. $customName = $custom->seatSnName ?? '';
  969. }
  970. $customName = stringUtil::subStringUtf8($customName, 7, '..');
  971. $a4Print = [
  972. 'customName' => $customName,
  973. 'seatSn' => $seatSn,
  974. ];
  975. $info['printData'] = $a4Print;
  976. $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}}]}';
  977. $info['template'] = $template;
  978. $custom->printSeatSn = 1;
  979. $custom->save();
  980. util::success($info);
  981. }
  982. }