CustomController.php 54 KB

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