CustomController.php 54 KB

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