SysUserAccountServiceImpl.java 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. package com.ydtech.modules.admin.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.ydtech.core.page.HttpResult;
  6. import com.ydtech.exception.SystemException;
  7. import com.ydtech.modules.admin.constants.MoneyAttrConstants;
  8. import com.ydtech.modules.admin.constants.WithdrawTypeConstants;
  9. import com.ydtech.modules.admin.dao.SysUserAccountMapper;
  10. import com.ydtech.modules.admin.model.SysUser;
  11. import com.ydtech.modules.admin.model.po.SysAmountAuditingEntity;
  12. import com.ydtech.modules.admin.model.po.SysUserAccount;
  13. import com.ydtech.modules.admin.model.po.SysUserAccountHistory;
  14. import com.ydtech.modules.admin.model.po.SysUserBankCard;
  15. import com.ydtech.modules.admin.model.vo.SubOrder;
  16. import com.ydtech.modules.admin.model.vo.SysUserAccountVo;
  17. import com.ydtech.modules.admin.service.*;
  18. import com.ydtech.modules.base.controller.BaseController;
  19. import com.ydtech.modules.esm.service.EsmUserReferrerService;
  20. import com.ydtech.modules.message.constants.MessageTypeConstants;
  21. import com.ydtech.modules.message.service.MessageSecretaryService;
  22. import com.ydtech.modules.order.dao.InsAreaCompanyMapper;
  23. import com.ydtech.modules.order.dao.InsOrdersMapper;
  24. import com.ydtech.modules.order.entity.BasePageResult;
  25. import com.ydtech.modules.order.entity.InsOrders;
  26. import com.ydtech.modules.order.service.InsAreaCompanyService;
  27. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  28. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  29. import org.apache.commons.lang3.ObjectUtils;
  30. import org.apache.commons.lang3.StringUtils;
  31. import org.springframework.beans.BeanUtils;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.stereotype.Service;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import org.springframework.util.CollectionUtils;
  36. import java.math.BigDecimal;
  37. import java.util.ArrayList;
  38. import java.util.Date;
  39. import java.util.HashMap;
  40. import java.util.List;
  41. /**
  42. * @author Administrator
  43. * @description 针对表【sys_user_account(用户账户表)】的数据库操作Service实现
  44. * @createDate 2024-03-05 11:52:30
  45. */
  46. @Service
  47. public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper, SysUserAccount> implements SysUserAccountService {
  48. @Autowired
  49. private SysUserAccountHistoryService sysUserAccountHistoryService;
  50. @Autowired
  51. private SysUserAccountService sysUserAccountService;
  52. @Autowired
  53. private EsmUserReferrerService esmUserReferrerService;
  54. @Autowired
  55. private SysAmountAuditingService sysAmountAuditingService;
  56. @Autowired
  57. private SysUserBankCardService sysUserBankCardService;
  58. @Autowired
  59. private InsAreaCompanyService insAreaCompanyService;
  60. @Autowired
  61. private InsFeeOrderNewService insFeeOrderNewService;
  62. @Autowired
  63. private InsOrdersMapper insOrdersMapper;
  64. @Autowired
  65. private MessageSecretaryService messageSecretaryService;
  66. @Autowired
  67. private InsAreaCompanyMapper insAreaCompanyMapper;
  68. @Autowired
  69. private SysUserService sysUserService;
  70. @Override
  71. @Transactional
  72. public void addOrUpdate(SysUserAccount sysUserAccount) {
  73. SysUserAccount newSysAccount = baseMapper.getById(sysUserAccount.getUserId());
  74. // 初始化
  75. if (sysUserAccount.getHandlingFee() == null) {
  76. sysUserAccount.setHandlingFee(BigDecimal.ZERO);
  77. }
  78. if (sysUserAccount.getDocumentary() == null) {
  79. sysUserAccount.setDocumentary(BigDecimal.ZERO);
  80. }
  81. if (sysUserAccount.getPromotion() == null) {
  82. sysUserAccount.setPromotion(BigDecimal.ZERO);
  83. }
  84. // 如果用户id有值则累加 没有则 新增
  85. String userId = sysUserAccount.getUserId();
  86. SysUserAccount sysUserAccountEntity = super.getById(userId);
  87. SysUserAccount newAccount = new SysUserAccount();
  88. if (ObjectUtils.isNotEmpty(sysUserAccountEntity)) {
  89. sysUserAccountEntity.setHandlingFee(sysUserAccount.getHandlingFee().add(sysUserAccountEntity.getHandlingFee()));
  90. sysUserAccountEntity.setDocumentary(sysUserAccount.getDocumentary().add(sysUserAccountEntity.getDocumentary()));
  91. sysUserAccountEntity.setPromotion(sysUserAccount.getPromotion().add(sysUserAccountEntity.getPromotion()));
  92. if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
  93. sysUserAccountEntity.setDocumentaryStatus(sysUserAccount.getDocumentaryStatus());
  94. }
  95. baseMapper.updateById(sysUserAccountEntity);
  96. } else {
  97. sysUserAccountEntity = new SysUserAccount();
  98. sysUserAccountEntity.setUserId(userId);
  99. sysUserAccountEntity.setDocumentary(sysUserAccount.getDocumentary());
  100. sysUserAccountEntity.setPromotion(sysUserAccount.getPromotion());
  101. sysUserAccountEntity.setHandlingFee(sysUserAccount.getHandlingFee());
  102. BigDecimal zero = BigDecimal.ZERO;
  103. sysUserAccountEntity.setHandlingAmountAccount(zero);
  104. sysUserAccountEntity.setHandlingAmountWithdrawal(zero);
  105. sysUserAccountEntity.setHandlingAmountPayment(zero);
  106. sysUserAccountEntity.setDocumentaryAmountAccount(zero);
  107. sysUserAccountEntity.setDocumentaryAmountWithdrawal(zero);
  108. sysUserAccountEntity.setDocumentaryAmountpayment(zero);
  109. sysUserAccountEntity.setPromotionAmountWithdrawal(zero);
  110. sysUserAccountEntity.setPromotionAmountAccount(zero);
  111. sysUserAccountEntity.setPromotionAmountPayment(zero);
  112. sysUserAccountEntity.setCreateTime(new Date());
  113. if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
  114. sysUserAccountEntity.setDocumentaryStatus(sysUserAccount.getDocumentaryStatus());
  115. }
  116. baseMapper.insert(sysUserAccountEntity);
  117. }
  118. if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
  119. // 判断是否是一级二级三级
  120. SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory();
  121. sysUserAccountHistory.setUserId(sysUserAccount.getUserId());
  122. sysUserAccountHistory.setDocumentary(Integer.valueOf(sysUserAccount.getDocumentaryStatus()));
  123. sysUserAccountHistory.setSuborder(sysUserAccount.getSuborderId());
  124. //跟单费
  125. if (sysUserAccount.getDocumentary() != null && sysUserAccount.getDocumentary().compareTo(BigDecimal.ZERO) != 0) {
  126. sysUserAccountHistory.setAmount(sysUserAccount.getDocumentary());
  127. sysUserAccountHistory.setProperty(MoneyAttrConstants.M_2.getCode());
  128. if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
  129. sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getDocumentary());
  130. } else {
  131. BigDecimal subtract = newSysAccount.getDocumentary().subtract(sysUserAccount.getDocumentary());
  132. sysUserAccountHistory.setSurplusAmount(subtract);
  133. }
  134. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  135. }
  136. //手续费
  137. if (sysUserAccount.getHandlingFee() != null && sysUserAccount.getHandlingFee().compareTo(BigDecimal.ZERO) != 0) {
  138. sysUserAccountHistory.setId(null);
  139. sysUserAccountHistory.setAmount(sysUserAccount.getHandlingFee());
  140. sysUserAccountHistory.setProperty(MoneyAttrConstants.M_1.getCode());
  141. if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
  142. sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getHandlingFee());
  143. } else {
  144. BigDecimal subtract = newSysAccount.getHandlingFee().subtract(sysUserAccount.getHandlingFee());
  145. sysUserAccountHistory.setSurplusAmount(subtract);
  146. }
  147. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  148. }
  149. //推广费
  150. if (sysUserAccount.getPromotion() != null && sysUserAccount.getPromotion().compareTo(BigDecimal.ZERO) != 0) {
  151. sysUserAccountHistory.setId(null);
  152. sysUserAccountHistory.setAmount(sysUserAccount.getPromotion());
  153. sysUserAccountHistory.setProperty(MoneyAttrConstants.M_3.getCode());
  154. if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
  155. sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getPromotion());
  156. } else {
  157. BigDecimal subtract = newSysAccount.getPromotion().subtract(sysUserAccount.getPromotion());
  158. sysUserAccountHistory.setSurplusAmount(subtract);
  159. }
  160. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  161. }
  162. }
  163. //添加佣金消息
  164. messageSecretaryService.addMessage(MessageTypeConstants.M_5,sysUserAccount.getUserId(),"您有一条佣金消息,请及时查看");
  165. }
  166. @Override
  167. public BasePageResult<SysUserAccount> queryByVo(SysUserAccountVo sysUserAccountVo) {
  168. Page<SysUserAccount> page = new Page<>(sysUserAccountVo.getPageNum(), sysUserAccountVo.getPageSize());
  169. Page<SysUserAccount> sysUserAccountHistoryPage = baseMapper.queryPageOrder(sysUserAccountVo, page);
  170. return new BasePageResult<>(sysUserAccountVo.getPageNum(), page.getSize(), sysUserAccountHistoryPage.getTotal(), page.getPages(),
  171. sysUserAccountHistoryPage.getRecords());
  172. }
  173. //
  174. @Override
  175. public BasePageResult<SysUserAccount> queryByVo1(SysUserAccountVo sysUserAccountVo) {
  176. Page<SysUserAccount> page = new Page<>(sysUserAccountVo.getPageNum(), sysUserAccountVo.getPageSize());
  177. Page<SysUserAccount> sysUserAccountHistoryPage = baseMapper.queryPageOrder1(sysUserAccountVo, page);
  178. return new BasePageResult<>(sysUserAccountVo.getPageNum(), page.getSize(), sysUserAccountHistoryPage.getTotal(), page.getPages(),
  179. sysUserAccountHistoryPage.getRecords());
  180. }
  181. @Override
  182. @Transactional
  183. public HttpResult<Object> inert(SysUserAccountVo sysUserAccountVo) {
  184. String userId = BaseController.getUser().getId();
  185. BigDecimal zero = BigDecimal.ZERO;
  186. BigDecimal beforeAmount;
  187. BigDecimal afterAmount;
  188. // 用户当前金额
  189. BigDecimal amount = sysUserAccountVo.getAmount();
  190. SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory(); // 记录
  191. sysUserAccountHistory.setDocumentary(1); // 1提现
  192. sysUserAccountHistory.setUserId(userId);
  193. SysAmountAuditingEntity sysAmountAuditingEntity = new SysAmountAuditingEntity();//审核记录表
  194. sysAmountAuditingEntity.setUserId(userId);
  195. sysAmountAuditingEntity.setAmount(sysUserAccountVo.getAmount());
  196. // SysAmountAuditingEntity judge = sysAmountAuditingService.getByUserId(userId, sysUserAccountVo.getAmountStatus());
  197. // if (ObjectUtils.isNotEmpty(judge)) {
  198. // return HttpResult.ok("有未提现审核单据, 请审核完成之后再提现");
  199. // }
  200. // 通过银行卡id 查询卡包
  201. String fromBankCardId = sysUserAccountVo.getFromBankCardId();
  202. if (fromBankCardId != null) {
  203. SysUserBankCard byId = sysUserBankCardService.getById(fromBankCardId);
  204. // String bankUserId = byId.getUserId();
  205. // if (!userId.equals(bankUserId)) {
  206. // return HttpResult.ok("非本人提现");
  207. // }
  208. byId.setIsDefault(1);
  209. sysAmountAuditingEntity.setBankNumber(byId.getBankNumber());
  210. sysUserAccountHistory.setFromBankCard(byId.getBankNumber());
  211. sysUserBankCardService.updateById(byId);
  212. }
  213. if (StringUtils.isNotEmpty(userId)) {
  214. SysUserAccount sysUserAccount = baseMapper.getById(userId);
  215. if (StringUtils.isNotEmpty(sysUserAccountVo.getAmountStatus())) {
  216. sysUserAccountHistory.setProperty(Integer.valueOf(sysUserAccountVo.getAmountStatus())); //金额类型
  217. if ("1".equals(sysUserAccountVo.getAmountStatus())) {
  218. // 用户当前费用金
  219. beforeAmount = sysUserAccount.getHandlingFee();
  220. afterAmount = beforeAmount.subtract(amount);
  221. sysUserAccount.setHandlingFee(afterAmount);
  222. sysUserAccount.setHandlingAmountPayment(sysUserAccount.getHandlingAmountPayment().add(amount));
  223. sysUserAccount.setHandlingAmountWithdrawal(sysUserAccount.getHandlingAmountWithdrawal().add(amount));
  224. } else if ("2".equals(sysUserAccountVo.getAmountStatus())) {
  225. // 用户当前 非跟单佣金
  226. beforeAmount = sysUserAccount.getDocumentary();
  227. afterAmount = beforeAmount.subtract(amount);
  228. sysUserAccount.setDocumentary(afterAmount);
  229. sysUserAccount.setDocumentaryAmountpayment(sysUserAccount.getDocumentaryAmountpayment().add(amount));
  230. sysUserAccount.setDocumentaryAmountWithdrawal(sysUserAccount.getDocumentaryAmountWithdrawal().add(amount));
  231. } else {
  232. beforeAmount = sysUserAccount.getPromotion();
  233. afterAmount = beforeAmount.subtract(amount);
  234. sysUserAccount.setPromotion(afterAmount);
  235. sysUserAccount.setPromotionAmountPayment(sysUserAccount.getPromotionAmountPayment().add(amount));
  236. sysUserAccount.setPromotionAmountWithdrawal(sysUserAccount.getPromotionAmountWithdrawal().add(amount));
  237. }
  238. // 用户相差
  239. if (beforeAmount.compareTo(zero) == 0 || afterAmount.compareTo(zero) < 0) {
  240. return HttpResult.ok("余额不足");
  241. }
  242. sysUserAccountHistory.setAmount(amount); // 金额
  243. sysUserAccountHistory.setSurplusAmount(afterAmount); // 剩余金额
  244. sysUserAccountHistory.setUserAmount(beforeAmount); // 用户剩余金额
  245. sysAmountAuditingEntity.setCreateTime(new Date());
  246. sysAmountAuditingEntity.setAuditingStatus("2"); // 2 为待审核 3 审核通过
  247. sysAmountAuditingEntity.setAmountStatus(sysUserAccountVo.getAmountStatus());
  248. // 新增金额记录
  249. sysAmountAuditingService.save(sysAmountAuditingEntity);
  250. sysUserAccountHistory.setAuditiingId(sysAmountAuditingEntity.getId());
  251. sysUserAccountService.updateById(sysUserAccount);
  252. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  253. }
  254. }
  255. return HttpResult.ok("提现成功,等待审核");
  256. }
  257. @Override
  258. @Transactional
  259. public HttpResult withdraw(SysUserAccountVo sysUserAccountVo) {
  260. String userId = sysUserAccountVo.getUserId();
  261. BigDecimal zero = BigDecimal.ZERO;
  262. BigDecimal beforeAmount;
  263. BigDecimal afterAmount;
  264. // 用户当前金额
  265. BigDecimal amount = sysUserAccountVo.getAmount();
  266. SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory(); // 记录
  267. sysUserAccountHistory.setDocumentary(1); // 1提现
  268. sysUserAccountHistory.setUserId(userId);
  269. SysAmountAuditingEntity sysAmountAuditingEntity = new SysAmountAuditingEntity();//审核记录表
  270. sysAmountAuditingEntity.setUserId(userId);
  271. sysAmountAuditingEntity.setAmount(sysUserAccountVo.getAmount());
  272. // SysAmountAuditingEntity judge = sysAmountAuditingService.getByUserId(userId, sysUserAccountVo.getAmountStatus());
  273. // if (ObjectUtils.isNotEmpty(judge)) {
  274. // throw new SystemException("有未提现审核单据, 请审核完成之后再提现");
  275. // }
  276. // 通过银行卡id 查询卡包
  277. String fromBankCardId = sysUserAccountVo.getFromBankCardId();
  278. SysUserBankCard byId = sysUserBankCardService.getByBankNumber(fromBankCardId);
  279. if (byId == null) {
  280. throw new SystemException("该卡未绑定此账号,或输入卡号错误,或该账号尚未审核通过,请检查");
  281. }
  282. if (fromBankCardId != null && byId.getUserId().equals(userId)) {
  283. byId.setIsDefault(1);
  284. sysAmountAuditingEntity.setBankNumber(byId.getBankNumber());
  285. sysUserAccountHistory.setFromBankCard(byId.getBankNumber());
  286. sysUserBankCardService.updateById(byId);
  287. }
  288. if (StringUtils.isNotEmpty(userId)) {
  289. SysUserAccount sysUserAccount = baseMapper.getById(userId);
  290. if (StringUtils.isNotEmpty(sysUserAccountVo.getAmountStatus())) {
  291. sysUserAccountHistory.setProperty(Integer.valueOf(sysUserAccountVo.getAmountStatus())); //金额类型
  292. if ("1".equals(sysUserAccountVo.getAmountStatus())) {
  293. // 用户当前费用金
  294. beforeAmount = sysUserAccount.getHandlingFee();
  295. afterAmount = beforeAmount.subtract(amount);
  296. sysUserAccount.setHandlingFee(afterAmount);
  297. sysUserAccount.setHandlingAmountPayment(sysUserAccount.getHandlingAmountPayment().add(amount));
  298. sysUserAccount.setHandlingAmountWithdrawal(sysUserAccount.getHandlingAmountWithdrawal().add(amount));
  299. } else if ("2".equals(sysUserAccountVo.getAmountStatus())) {
  300. // 用户当前 非跟单佣金
  301. beforeAmount = sysUserAccount.getDocumentary();
  302. afterAmount = beforeAmount.subtract(amount);
  303. sysUserAccount.setDocumentary(afterAmount);
  304. sysUserAccount.setDocumentaryAmountpayment(sysUserAccount.getDocumentaryAmountpayment().add(amount));
  305. sysUserAccount.setDocumentaryAmountWithdrawal(sysUserAccount.getDocumentaryAmountWithdrawal().add(amount));
  306. } else {
  307. beforeAmount = sysUserAccount.getPromotion();
  308. afterAmount = beforeAmount.subtract(amount);
  309. sysUserAccount.setPromotion(afterAmount);
  310. sysUserAccount.setPromotionAmountPayment(sysUserAccount.getPromotionAmountPayment().add(amount));
  311. sysUserAccount.setPromotionAmountWithdrawal(sysUserAccount.getPromotionAmountWithdrawal().add(amount));
  312. }
  313. // 用户相差
  314. if (beforeAmount.compareTo(zero) == 0 || afterAmount.compareTo(zero) < 0) {
  315. return HttpResult.ok("余额不足");
  316. }
  317. sysUserAccountHistory.setAmount(amount); // 金额
  318. sysUserAccountHistory.setSurplusAmount(afterAmount); // 剩余金额
  319. sysUserAccountHistory.setUserAmount(beforeAmount); // 用户剩余金额
  320. sysAmountAuditingEntity.setCreateTime(new Date());
  321. sysAmountAuditingEntity.setAuditingStatus("2"); // 2 为待审核 3 审核通过
  322. sysAmountAuditingEntity.setAmountStatus(sysUserAccountVo.getAmountStatus());
  323. // 新增金额记录
  324. sysAmountAuditingService.save(sysAmountAuditingEntity);
  325. sysUserAccountHistory.setAuditiingId(sysAmountAuditingEntity.getId());
  326. sysUserAccountService.updateById(sysUserAccount);
  327. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  328. }
  329. }
  330. return HttpResult.ok("提现成功,等待审核");
  331. }
  332. @Override
  333. public SysUserAccount getSysUserAmount(String userid) {
  334. SysUserAccount sysUserAccount = baseMapper.getById(userid);
  335. return sysUserAccount;
  336. }
  337. @Override
  338. public SysUserAccountVo getSysAllAmount(String userId) {
  339. SysUserAccountVo sysUserAccountVo = new SysUserAccountVo();
  340. SysUserAccount sysUserAccount = baseMapper.getById(userId);
  341. // 验证账户信息是否有值
  342. if (ObjectUtils.isEmpty(sysUserAccount)) {
  343. return sysUserAccountVo;
  344. }
  345. BeanUtils.copyProperties(sysUserAccount, sysUserAccountVo);
  346. BigDecimal willHalding = BigDecimal.ZERO; //预收手续费佣金
  347. BigDecimal willDocumentary = BigDecimal.ZERO; //预收 非跟单佣金
  348. BigDecimal willPromotion = BigDecimal.ZERO; //预收 推广
  349. BigDecimal receivedWillHalding = BigDecimal.ZERO; //实收手续费佣金
  350. BigDecimal receivedWillDocumentary = BigDecimal.ZERO; //实收非跟单佣金
  351. BigDecimal receivedWillPromotion = BigDecimal.ZERO; //实收推广费
  352. // 预收手续费佣金
  353. willPromotion = this.willPromotionAll(willPromotion, userId,"1");
  354. // 实收手续费佣金
  355. receivedWillPromotion = this.willPromotionAll(willPromotion, userId,"2");
  356. // add by hxl 修改sql 添加承保状态和不在审核表中的条件 begin ===============
  357. List<InsFeeOrderNew> willList = insFeeOrderNewService.getByUserIdAndOrderStatusAndNoCheckType(userId,"1");
  358. List<InsFeeOrderNew> willListnew = insFeeOrderNewService.getByUserIdAndOrderStatusAndNoCheckType(userId,"2");
  359. if (!CollectionUtils.isEmpty(willList)) {
  360. for (InsFeeOrderNew item : willList) {
  361. if (ObjectUtils.isNotEmpty(item)) {
  362. //1.预收手续费佣金 2. 预收非跟单佣金
  363. willHalding = willHalding.add(this.willAmountNew(item,1));
  364. willDocumentary = willDocumentary.add(this.willAmountNew(item,2));
  365. }
  366. }
  367. }
  368. if (!CollectionUtils.isEmpty(willListnew)) {
  369. for (InsFeeOrderNew item : willListnew) {
  370. if (ObjectUtils.isNotEmpty(item)) {
  371. //1.实收手续费佣金 2. 实收非跟单佣金
  372. receivedWillHalding = willHalding.add(this.willAmountNew(item,1));
  373. receivedWillDocumentary = willDocumentary.add(this.willAmountNew(item,2));
  374. }
  375. }
  376. }
  377. //预收手续费佣金
  378. sysUserAccountVo.setWillHalding(willPromotion);
  379. //预收非跟单佣金
  380. sysUserAccountVo.setWillDocumentary(willDocumentary);
  381. //实收手续费佣金
  382. sysUserAccountVo.setReceivedWillHalding(receivedWillHalding);
  383. //实收非跟单佣金
  384. sysUserAccountVo.setReceivedWillDocumentary(receivedWillDocumentary);
  385. //提现现中 手续费、非跟单、推广费
  386. HashMap<String, Object> params = new HashMap<>();
  387. params.put("auditingStatus", "2"); // 待审核
  388. params.put("userId", userId);
  389. List<SysAmountAuditingEntity> sysAmountAuditingProgressIng = sysAmountAuditingService.getProgressIng(params);
  390. this.judge(sysAmountAuditingProgressIng, sysUserAccountVo);
  391. params.clear();
  392. params.put("auditingStatus", "3"); // 已审核审核
  393. params.put("userId", userId);
  394. //已提现 手续费、非跟单、推广费
  395. List<SysAmountAuditingEntity> sysAmountAuditingApproved = sysAmountAuditingService.getProgressIng(params);
  396. this.judgeSysAmountAuditing(sysAmountAuditingApproved, sysUserAccountVo);
  397. //预收手续费佣金
  398. sysUserAccountVo.setWillPromotion(willPromotion);
  399. //实收手续费佣金
  400. sysUserAccountVo.setReceivedWillPromotion(receivedWillPromotion);
  401. return sysUserAccountVo;
  402. }
  403. @Override
  404. public SysUserAccountVo getInsOrders(SysUserAccountVo sysUserAccountVo) {
  405. ArrayList<InsFeeOrderNew> resultList = new ArrayList<>();
  406. HashMap<String, Object> params = new HashMap<>();
  407. params.put("userId", BaseController.getUser().getId());
  408. //日期
  409. params.put("timeFiltering", sysUserAccountVo.getTimeFiltering());
  410. //1预收2.实收
  411. params.put("type",sysUserAccountVo.getSearchType());
  412. sysUserAccountVo.setInsFeeOrderNewList(null);
  413. //金额类型 1. 手续费金额 2. 跟单金额 3. 推广金额
  414. if ("3".equals(sysUserAccountVo.getAmountType())) {
  415. List<InsFeeOrderNew> sumWillAmountGeneralization = insFeeOrderNewService.getSumWillAmountGeneralizationNew(params);
  416. sysUserAccountVo.setInsFeeOrderNewList(sumWillAmountGeneralization);
  417. } else {
  418. List<InsFeeOrderNew> resultInsFeeOrderNew = insFeeOrderNewService.getSumWillAmountNew(params);
  419. if (resultInsFeeOrderNew!=null && resultInsFeeOrderNew.size()>0) {
  420. for (InsFeeOrderNew item : resultInsFeeOrderNew) {
  421. BigDecimal willPromotion = BigDecimal.ZERO;
  422. if ("1".equals(sysUserAccountVo.getAmountType())) {
  423. //手续费出口预收
  424. willPromotion = willPromotion.add(item.getJqExportSuperviseCostsPremiums()).add(item.getSyExportSuperviseCostsPremiums()).add(item.getNoExportSuperviseCostsPremiums());
  425. } else if ("2".equals(sysUserAccountVo.getAmountType())) {
  426. willPromotion = willPromotion.add(item.getJqExportOtherCostsPremiums()).add(item.getSyExportOtherCostsPremiums()).add(item.getNoExportOtherCostsPremiums());
  427. }
  428. item.setWillAmount(willPromotion);
  429. if (willPromotion.compareTo(BigDecimal.ZERO) != 0) {
  430. resultList.add(item);
  431. }
  432. }
  433. sysUserAccountVo.setInsFeeOrderNewList(resultList);
  434. }
  435. }
  436. return sysUserAccountVo;
  437. }
  438. private void getWillAmount(InsFeeOrderNew insFeeOrderNew) {
  439. if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
  440. //交强手续费出口比例
  441. BigDecimal jqExportProceduresFee =
  442. insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqSuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  443. //商业手续费出口比例
  444. BigDecimal syExportProceduresFee =
  445. insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSySuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  446. //非车手续费出口比例
  447. BigDecimal noExportProceduresFee =
  448. insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoSuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  449. //非车出口比例
  450. //总机构 交强管理比例
  451. BigDecimal sumJqDeptProportion = insFeeOrderNew.getJqDeptProportionLevel1()
  452. .add(insFeeOrderNew.getJqDeptProportionLevel2())
  453. .add(insFeeOrderNew.getJqDeptProportionLevel3())
  454. .add(insFeeOrderNew.getJqDeptProportionLevel4())
  455. .add(insFeeOrderNew.getJqDeptProportionLevel5());
  456. //总机构 商业管理比例
  457. BigDecimal sumSyDeptProportion = insFeeOrderNew.getSyDeptProportionLevel1()
  458. .add(insFeeOrderNew.getSyDeptProportionLevel2())
  459. .add(insFeeOrderNew.getSyDeptProportionLevel3())
  460. .add(insFeeOrderNew.getSyDeptProportionLevel4())
  461. .add(insFeeOrderNew.getSyDeptProportionLevel5());
  462. //总机构 非车管理比例
  463. BigDecimal sumNoDeptProportion = insFeeOrderNew.getNoDeptProportionLevel1()
  464. .add(insFeeOrderNew.getNoDeptProportionLevel2())
  465. .add(insFeeOrderNew.getNoDeptProportionLevel3())
  466. .add(insFeeOrderNew.getNoDeptProportionLevel4())
  467. .add(insFeeOrderNew.getNoDeptProportionLevel5());
  468. BigDecimal noExportProceduresProportion = new BigDecimal(0);
  469. //总分销比例
  470. BigDecimal sumRetail =
  471. insFeeOrderNew.getFirstDetailProportion().add(insFeeOrderNew.getSecondDetailProportion()).add(insFeeOrderNew.getThirdDetailProportion());
  472. if (insFeeOrderNew.getNoCostsProportion().compareTo(sumNoDeptProportion.add(sumRetail)) > 0) {
  473. noExportProceduresProportion = insFeeOrderNew.getNoCostsProportion().subtract(sumNoDeptProportion).subtract(sumRetail);
  474. }
  475. //商业出口比例
  476. BigDecimal syExportProceduresProportion = new BigDecimal(0);
  477. if (insFeeOrderNew.getSyCostsProportion().compareTo(sumSyDeptProportion.add(sumRetail)) > 0) {
  478. syExportProceduresProportion = insFeeOrderNew.getSyCostsProportion().subtract(sumSyDeptProportion).subtract(sumRetail);
  479. }
  480. //交强出口比例
  481. BigDecimal jqExportProceduresProportion = new BigDecimal(0);
  482. if (insFeeOrderNew.getJqCostsProportion().compareTo(sumJqDeptProportion.add(sumRetail)) > 0) {
  483. jqExportProceduresProportion = insFeeOrderNew.getJqCostsProportion().subtract(sumJqDeptProportion).subtract(sumRetail);
  484. }
  485. //交强跟单出口费用
  486. BigDecimal jqExportOtherFee = insFeeOrderNew.getJqPremium()
  487. .multiply(jqExportProceduresProportion
  488. .subtract(insFeeOrderNew.getJqSuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
  489. BigDecimal.ROUND_DOWN);
  490. //商业跟单出口比例
  491. BigDecimal syExportOtherFee = insFeeOrderNew.getSyPremium()
  492. .multiply(syExportProceduresProportion
  493. .subtract(insFeeOrderNew.getSySuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
  494. BigDecimal.ROUND_DOWN);
  495. //非车跟单出口比例
  496. BigDecimal noExportOtherFee = insFeeOrderNew.getNoPremium()
  497. .multiply(noExportProceduresProportion
  498. .subtract(insFeeOrderNew.getNoSuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
  499. BigDecimal.ROUND_DOWN);
  500. if (StringUtils.isNotEmpty(insFeeOrderNew.getAmountType())) {
  501. if ("1".equals(insFeeOrderNew.getAmountType())) {
  502. //用户出口手续费
  503. insFeeOrderNew.setWillAmount(jqExportProceduresFee.add(syExportProceduresFee).add(noExportProceduresFee));
  504. }
  505. if ("2".equals(insFeeOrderNew.getAmountType())) {
  506. //用户出口跟单费
  507. insFeeOrderNew.setWillAmount(jqExportOtherFee.add(syExportOtherFee).add(noExportOtherFee));
  508. }
  509. }
  510. }
  511. }
  512. private BigDecimal getWillPromotion(InsFeeOrderNew insFeeOrderNew, BigDecimal willPromotion) {
  513. InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNew(insFeeOrderNew);
  514. if (ObjectUtils.isNotEmpty(InsOrders)) {
  515. BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
  516. // 累加保费
  517. willPromotion = willPromotion.add(willFirstPremiums);
  518. }
  519. return willPromotion;
  520. }
  521. private void judgeSysAmountAuditing(List<SysAmountAuditingEntity> sysAmountAuditingApproved, SysUserAccountVo sysUserAccountVo) {
  522. if (!CollectionUtils.isEmpty(sysAmountAuditingApproved)) {
  523. for (SysAmountAuditingEntity item : sysAmountAuditingApproved) {
  524. if ("1".equals(item.getAmountStatus())) { //手续费
  525. BigDecimal amount = item.getAmount();
  526. sysUserAccountVo.setApprovedHalding(amount);
  527. }
  528. if ("2".equals(item.getAmountStatus())) { //非跟单
  529. BigDecimal amount = item.getAmount();
  530. sysUserAccountVo.setApprovedDocumentary(amount);
  531. }
  532. if ("3".equals(item.getAmountStatus())) { //推广费
  533. BigDecimal amount = item.getAmount();
  534. sysUserAccountVo.setApprovedPromotion(amount);
  535. }
  536. }
  537. }
  538. }
  539. private void judge(List<SysAmountAuditingEntity> sysAmountAuditingProgressIng, SysUserAccountVo sysUserAccountVo) {
  540. if (!CollectionUtils.isEmpty(sysAmountAuditingProgressIng)) {
  541. for (SysAmountAuditingEntity item : sysAmountAuditingProgressIng) {
  542. if ("1".equals(item.getAmountStatus())) { //手续费
  543. BigDecimal amount = item.getAmount();
  544. sysUserAccountVo.setWithdrawalHalding(amount);
  545. }
  546. if ("2".equals(item.getAmountStatus())) { //非跟单
  547. BigDecimal amount = item.getAmount();
  548. sysUserAccountVo.setWithdrawalDocumentary(amount);
  549. }
  550. if ("3".equals(item.getAmountStatus())) { //推广费
  551. BigDecimal amount = item.getAmount();
  552. sysUserAccountVo.setWithdrawalPromotion(amount);
  553. }
  554. }
  555. }
  556. }
  557. private BigDecimal willPromotion(BigDecimal willPromotion, String userId) {
  558. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  559. insFeeOrderNew.setUserId(userId);
  560. InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNew(insFeeOrderNew);
  561. if (ObjectUtils.isNotEmpty(InsOrders)) {
  562. BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
  563. // 累加保费
  564. willPromotion = willPromotion.add(willFirstPremiums);
  565. }
  566. return willPromotion;
  567. }
  568. private void willAmount(InsFeeOrderNew insFeeOrderNew, BigDecimal willHalding, BigDecimal willDocumentary,
  569. SysUserAccountVo sysUserAccountVo) {
  570. if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
  571. //交强手续费
  572. BigDecimal jqExportProceduresFee = insFeeOrderNew.getJqExportSuperviseCostsPremiums();
  573. //商业手续费
  574. BigDecimal syExportProceduresFee = insFeeOrderNew.getSyExportSuperviseCostsPremiums();
  575. //非车手续费
  576. BigDecimal noExportProceduresFee = insFeeOrderNew.getNoExportSuperviseCostsPremiums();
  577. if (sysUserAccountVo.getWillHalding() == null) {
  578. sysUserAccountVo.setWillHalding(BigDecimal.ZERO);
  579. }
  580. sysUserAccountVo.setWillHalding(sysUserAccountVo.getWillHalding().add(jqExportProceduresFee).add(syExportProceduresFee).add(noExportProceduresFee));
  581. //交强跟单出口费用
  582. BigDecimal jqExportOtherCostsPremiums = insFeeOrderNew.getJqExportOtherCostsPremiums();
  583. //商业跟单出口费用
  584. BigDecimal syExportOtherCostsPremiums = insFeeOrderNew.getSyExportOtherCostsPremiums();
  585. //非车跟单出口费用
  586. BigDecimal noExportOtherCostsPremiums = insFeeOrderNew.getNoExportOtherCostsPremiums();
  587. //用户出口跟单费
  588. if (sysUserAccountVo.getWillDocumentary() == null) {
  589. sysUserAccountVo.setWillDocumentary(BigDecimal.ZERO);
  590. }
  591. sysUserAccountVo.setWillDocumentary(sysUserAccountVo.getWillDocumentary().add(jqExportOtherCostsPremiums).add(syExportOtherCostsPremiums).add(noExportOtherCostsPremiums));
  592. }
  593. }
  594. /**
  595. * @version
  596. * @author: hxl
  597. * @Date: 2024/6/3 11:20
  598. * @Description: 通过类型查询预收、实收的金额
  599. */
  600. private BigDecimal willPromotionAll(BigDecimal willPromotion, String userId,String type) {
  601. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  602. insFeeOrderNew.setUserId(userId);
  603. InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNewByType(insFeeOrderNew,type);
  604. if (ObjectUtils.isNotEmpty(InsOrders)) {
  605. BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
  606. // 累加保费
  607. willPromotion = willPromotion.add(willFirstPremiums);
  608. }
  609. return willPromotion;
  610. }
  611. /**
  612. * @version
  613. * @author: hxl
  614. * @Date: 2024/6/4 11:51
  615. * @Description: 获取费用
  616. */
  617. private BigDecimal willAmountNew(InsFeeOrderNew insFeeOrderNew, int type) {
  618. BigDecimal val= BigDecimal.ZERO;
  619. if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
  620. if(type==1){
  621. // 交强手续费+商业手续费+非车手续费
  622. val= val.add(insFeeOrderNew.getJqExportSuperviseCostsPremiums()).add(insFeeOrderNew.getSyExportSuperviseCostsPremiums()).add(insFeeOrderNew.getNoExportSuperviseCostsPremiums());
  623. }else{
  624. // 交强跟单出口费用+商业跟单出口费用+非车跟单出口费用
  625. val= val.add(insFeeOrderNew.getJqExportOtherCostsPremiums()).add(insFeeOrderNew.getSyExportOtherCostsPremiums()).add(insFeeOrderNew.getNoExportOtherCostsPremiums());
  626. }
  627. }
  628. return val;
  629. }
  630. /**
  631. * @version
  632. * @author: hxl
  633. * @Date: 2024/6/3 15:16
  634. * @Description: 查询子订单的详细信息
  635. */
  636. @Override
  637. public SubOrder getSubOrderDetails(String subOrderId, String userId) {
  638. SubOrder subOrder=insAreaCompanyMapper.getSubOrderDetails(subOrderId);
  639. subOrder.setAgentName("");
  640. subOrder.setAgentLevel("");
  641. //根据用户id查询分销等级
  642. InsFeeOrderNew insFeeOrderNew = insFeeOrderNewService.getOne(new LambdaQueryWrapper<InsFeeOrderNew>()
  643. .eq(InsFeeOrderNew::getInsOrderNo, subOrder.getSubOrderId()));
  644. if(userId.equals(insFeeOrderNew.getFirstLevelUserId())){
  645. subOrder.setAgentName(this.getUserName(insFeeOrderNew.getFirstLevelUserId()));
  646. subOrder.setAgentLevel("一级分销代理");
  647. }
  648. if(userId.equals(insFeeOrderNew.getTwoLevelUserId())){
  649. subOrder.setAgentName(this.getUserName(insFeeOrderNew.getTwoLevelUserId()));
  650. subOrder.setAgentLevel("二级分销代理");
  651. }
  652. if(userId.equals(insFeeOrderNew.getThreeLevelUserId())){
  653. subOrder.setAgentName(this.getUserName(insFeeOrderNew.getThreeLevelUserId()));
  654. subOrder.setAgentLevel("三级分销代理");
  655. }
  656. return subOrder;
  657. }
  658. /**
  659. * @version
  660. * @author: hxl
  661. * @Date: 2024/6/3 16:34
  662. * @Description: 查询分销人名称
  663. */
  664. private String getUserName(String userId) {
  665. if(StringUtils.isNotEmpty(userId)){
  666. SysUser sysUser = sysUserService.getBaseMapper().selectById(userId);
  667. if(ObjectUtils.isNotEmpty(sysUser)){
  668. return sysUser.getName();
  669. }
  670. }
  671. return "";
  672. }
  673. }