CustomController.php 36 KB

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