CustomController.php 56 KB

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