CustomController.php 56 KB

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