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