SysUserAccountServiceImpl.java 33 KB

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