CustomController.php 56 KB

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