CustomController.php 54 KB

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