CustomController.php 54 KB

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