CustomController.php 51 KB

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