SysUserAccountServiceImpl.java 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  1. package com.ydtech.modules.admin.service.impl;
  2. import cn.hutool.extra.spring.SpringUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.ydtech.core.page.HttpResult;
  7. import com.ydtech.exception.SystemException;
  8. import com.ydtech.modules.admin.constants.ManagementSource;
  9. import com.ydtech.modules.admin.constants.MoneyAttrConstants;
  10. import com.ydtech.modules.admin.constants.WithdrawTypeConstants;
  11. import com.ydtech.modules.admin.dao.SysUserAccountMapper;
  12. import com.ydtech.modules.admin.dao.SysUserBankCardMapper;
  13. import com.ydtech.modules.admin.dao.SysUserMapper;
  14. import com.ydtech.modules.admin.model.SysDept;
  15. import com.ydtech.modules.admin.model.SysUser;
  16. import com.ydtech.modules.admin.model.dto.*;
  17. import com.ydtech.modules.admin.model.po.*;
  18. import com.ydtech.modules.admin.model.vo.MyIncomeAndExpensesNewPageVo;
  19. import com.ydtech.modules.admin.model.vo.SubOrder;
  20. import com.ydtech.modules.admin.model.vo.SysUserAccountVo;
  21. import com.ydtech.modules.admin.model.vo.SysUserBaseVO;
  22. import com.ydtech.modules.admin.service.*;
  23. import com.ydtech.modules.admin.utils.SliceUpDateUtil;
  24. import com.ydtech.modules.base.controller.BaseController;
  25. import com.ydtech.modules.fee.service.FeeDisplayService;
  26. import com.ydtech.modules.message.constants.MessageTypeConstants;
  27. import com.ydtech.modules.message.service.MessageSecretaryService;
  28. import com.ydtech.modules.order.dao.InsAreaCompanyMapper;
  29. import com.ydtech.modules.order.entity.BasePageResult;
  30. import com.ydtech.modules.order.entity.InsOrders;
  31. import com.ydtech.modules.order.service.InsAreaCompanyService;
  32. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  33. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  34. import com.ydtech.modules.ttqf.entity.vo.UserWithdrawal;
  35. import com.ydtech.modules.ttqf.service.TtqfService;
  36. import org.apache.commons.lang3.ObjectUtils;
  37. import org.apache.commons.lang3.StringUtils;
  38. import org.springframework.beans.BeanUtils;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.stereotype.Service;
  41. import org.springframework.transaction.annotation.Transactional;
  42. import org.springframework.util.CollectionUtils;
  43. import java.math.BigDecimal;
  44. import java.text.SimpleDateFormat;
  45. import java.util.*;
  46. /**
  47. * @author Administrator
  48. * @description 针对表【sys_user_account(用户账户表)】的数据库操作Service实现
  49. * @createDate 2024-03-05 11:52:30
  50. */
  51. @Service
  52. public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper, SysUserAccount> implements SysUserAccountService {
  53. @Autowired
  54. private SysUserAccountHistoryService sysUserAccountHistoryService;
  55. @Autowired
  56. private SysUserAccountService sysUserAccountService;
  57. @Autowired
  58. private SysAmountAuditingService sysAmountAuditingService;
  59. @Autowired
  60. private SysUserBankCardService sysUserBankCardService;
  61. @Autowired
  62. private InsAreaCompanyService insAreaCompanyService;
  63. @Autowired
  64. private InsFeeOrderNewService insFeeOrderNewService;
  65. @Autowired
  66. private MessageSecretaryService messageSecretaryService;
  67. @Autowired
  68. private InsAreaCompanyMapper insAreaCompanyMapper;
  69. @Autowired
  70. private SysUserService sysUserService;
  71. @Autowired
  72. private SysAmountAuditingHistoryService sysAmountAuditingHistoryService;
  73. @Autowired
  74. private SysUserMapper sysUserMapper;
  75. @Autowired
  76. private SysDeptService sysDeptService;
  77. @Autowired
  78. private FeeDisplayService feeDisplayService;
  79. @Autowired
  80. private SysSwitchConfigService sysSwitchConfigService;
  81. @Autowired
  82. private TtqfService ttqfService;
  83. @Override
  84. @Transactional
  85. public void addOrUpdate(SysUserAccount sysUserAccount) {
  86. //SysUserAccount newSysAccount = baseMapper.getById(sysUserAccount.getUserId());
  87. // 初始化
  88. if (sysUserAccount.getHandlingFee() == null) {
  89. sysUserAccount.setHandlingFee(BigDecimal.ZERO);
  90. }
  91. if (sysUserAccount.getDocumentary() == null) {
  92. sysUserAccount.setDocumentary(BigDecimal.ZERO);
  93. }
  94. if (sysUserAccount.getPromotion() == null) {
  95. sysUserAccount.setPromotion(BigDecimal.ZERO);
  96. }
  97. //添加总金额 = 手续费+跟单费+推广费
  98. BigDecimal sumAmount = BigDecimal.ZERO;
  99. sumAmount = sumAmount.add(sysUserAccount.getHandlingFee() == null ? BigDecimal.ZERO : sysUserAccount.getHandlingFee())
  100. .add(sysUserAccount.getDocumentary() == null ? BigDecimal.ZERO : sysUserAccount.getDocumentary())
  101. .add(sysUserAccount.getPromotion() == null ? BigDecimal.ZERO : sysUserAccount.getPromotion());
  102. // 如果用户id有值则累加 没有则 新增
  103. String userId = sysUserAccount.getUserId();
  104. SysUserAccount sysUserAccountEntity = baseMapper.getById(userId);
  105. //SysUserAccount newAccount = new SysUserAccount();
  106. if (ObjectUtils.isNotEmpty(sysUserAccountEntity)) {
  107. sysUserAccountEntity.setHandlingFee(sysUserAccount.getHandlingFee().add(sysUserAccountEntity.getHandlingFee()));
  108. sysUserAccountEntity.setDocumentary(sysUserAccount.getDocumentary().add(sysUserAccountEntity.getDocumentary()));
  109. sysUserAccountEntity.setPromotion(sysUserAccount.getPromotion().add(sysUserAccountEntity.getPromotion()));
  110. if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
  111. sysUserAccountEntity.setDocumentaryStatus(sysUserAccount.getDocumentaryStatus());
  112. }
  113. // add by hxl 2024-06-18 插入总金额
  114. sysUserAccountEntity.setSumAmount((sysUserAccountEntity.getSumAmount() == null ? BigDecimal.ZERO : sysUserAccountEntity.getSumAmount()).add(sumAmount));
  115. baseMapper.updateById(sysUserAccountEntity);
  116. } else {
  117. sysUserAccountEntity = new SysUserAccount();
  118. sysUserAccountEntity.setUserId(userId);
  119. sysUserAccountEntity.setDocumentary(sysUserAccount.getDocumentary());
  120. sysUserAccountEntity.setPromotion(sysUserAccount.getPromotion());
  121. sysUserAccountEntity.setHandlingFee(sysUserAccount.getHandlingFee());
  122. BigDecimal zero = BigDecimal.ZERO;
  123. sysUserAccountEntity.setHandlingAmountAccount(zero);
  124. sysUserAccountEntity.setHandlingAmountWithdrawal(zero);
  125. sysUserAccountEntity.setHandlingAmountPayment(zero);
  126. sysUserAccountEntity.setDocumentaryAmountAccount(zero);
  127. sysUserAccountEntity.setDocumentaryAmountWithdrawal(zero);
  128. sysUserAccountEntity.setDocumentaryAmountpayment(zero);
  129. sysUserAccountEntity.setPromotionAmountWithdrawal(zero);
  130. sysUserAccountEntity.setPromotionAmountAccount(zero);
  131. sysUserAccountEntity.setPromotionAmountPayment(zero);
  132. sysUserAccountEntity.setSumAmount(zero);
  133. sysUserAccountEntity.setSumAmountWithdrawal(zero);
  134. sysUserAccountEntity.setSumAmountAccount(zero);
  135. sysUserAccountEntity.setSumAmountPayment(zero);
  136. sysUserAccountEntity.setCreateTime(new Date());
  137. if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
  138. sysUserAccountEntity.setDocumentaryStatus(sysUserAccount.getDocumentaryStatus());
  139. }
  140. // add by hxl 2024-06-18 插入总金额
  141. sysUserAccountEntity.setSumAmount((sysUserAccountEntity.getSumAmount() == null ? BigDecimal.ZERO : sysUserAccountEntity.getSumAmount()).add(sumAmount));
  142. baseMapper.insert(sysUserAccountEntity);
  143. }
  144. StringBuilder commissionMessage = new StringBuilder();
  145. BigDecimal beforeAmount;
  146. BigDecimal afterAmount;
  147. if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
  148. //提现前的金额
  149. beforeAmount = sysUserAccountEntity.getSumAmount() == null ? BigDecimal.ZERO : sysUserAccountEntity.getSumAmount();
  150. // 判断是否是一级二级三级
  151. SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory();
  152. sysUserAccountHistory.setUserId(sysUserAccount.getUserId());
  153. sysUserAccountHistory.setDocumentary(Integer.valueOf(sysUserAccount.getDocumentaryStatus()));
  154. sysUserAccountHistory.setSuborder(sysUserAccount.getSuborderId());
  155. sysUserAccountHistory.setCreateTime(new Date());
  156. //跟单费
  157. if (sysUserAccount.getDocumentary() != null && sysUserAccount.getDocumentary().compareTo(BigDecimal.ZERO) != 0) {
  158. sysUserAccountHistory.setAmount(sysUserAccount.getDocumentary());
  159. sysUserAccountHistory.setProperty(MoneyAttrConstants.M_2.getCode());
  160. commissionMessage.append(MoneyAttrConstants.M_2.getDesc() + ":" + sysUserAccount.getDocumentary() + "元 ");
  161. if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
  162. sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getDocumentary());
  163. }
  164. sysUserAccountHistory.setBusinessSegmentsType(1);
  165. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  166. }
  167. //手续费
  168. if (sysUserAccount.getHandlingFee() != null && sysUserAccount.getHandlingFee().compareTo(BigDecimal.ZERO) != 0) {
  169. sysUserAccountHistory.setId(null);
  170. sysUserAccountHistory.setAmount(sysUserAccount.getHandlingFee());
  171. sysUserAccountHistory.setProperty(MoneyAttrConstants.M_1.getCode());
  172. commissionMessage.append(MoneyAttrConstants.M_1.getDesc() + ":" + sysUserAccount.getHandlingFee() + "元 ");
  173. if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
  174. sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getHandlingFee());
  175. }
  176. sysUserAccountHistory.setBusinessSegmentsType(1);
  177. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  178. }
  179. //推广费
  180. if (sysUserAccount.getPromotion() != null && sysUserAccount.getPromotion().compareTo(BigDecimal.ZERO) != 0) {
  181. sysUserAccountHistory.setId(null);
  182. sysUserAccountHistory.setAmount(sysUserAccount.getPromotion());
  183. sysUserAccountHistory.setProperty(MoneyAttrConstants.M_3.getCode());
  184. commissionMessage.append(MoneyAttrConstants.M_3.getDesc() + ":" + sysUserAccount.getPromotion() + "元 ");
  185. if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
  186. //提现后的金额
  187. afterAmount = beforeAmount.subtract(sysUserAccount.getPromotion());
  188. sysUserAccountHistory.setSurplusAmount(afterAmount); //改变后金额
  189. sysUserAccountHistory.setUserAmount(beforeAmount); //改变前金额
  190. }
  191. sysUserAccountHistory.setBusinessSegmentsType(1);
  192. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  193. }
  194. //手续费+跟单费用
  195. BigDecimal amount_SX_GD = BigDecimal.ZERO;
  196. amount_SX_GD = amount_SX_GD.add(sysUserAccount.getHandlingFee() == null ? BigDecimal.ZERO : sysUserAccount.getHandlingFee())
  197. .add(sysUserAccount.getDocumentary() == null ? BigDecimal.ZERO : sysUserAccount.getDocumentary());
  198. //历史记录表添加手续费+跟单费用 add by hxl 2024-06-18
  199. if (amount_SX_GD.compareTo(BigDecimal.ZERO) != 0) {
  200. sysUserAccountHistory.setId(null);
  201. sysUserAccountHistory.setAmount(amount_SX_GD);
  202. sysUserAccountHistory.setProperty(MoneyAttrConstants.M_4.getCode());
  203. if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
  204. afterAmount = beforeAmount.subtract(amount_SX_GD);
  205. sysUserAccountHistory.setSurplusAmount(afterAmount); //改变后金额
  206. sysUserAccountHistory.setUserAmount(beforeAmount); //改变前金额
  207. sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getSumAmount());
  208. sysUserAccountHistory.setBusinessSegmentsType(1);
  209. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  210. }
  211. }
  212. }
  213. //添加佣金消息
  214. messageSecretaryService.addMessage(MessageTypeConstants.M_5, sysUserAccount.getUserId(), "你有一条佣金消息," + commissionMessage.toString());
  215. }
  216. @Override
  217. public BasePageResult<SysUserAccount> queryByVo(SysUserAccountVo sysUserAccountVo) {
  218. Page<SysUserAccount> page = new Page<>(sysUserAccountVo.getPageNum(), sysUserAccountVo.getPageSize());
  219. Page<SysUserAccount> sysUserAccountHistoryPage = baseMapper.queryPageOrder(sysUserAccountVo, page);
  220. return new BasePageResult<>(sysUserAccountVo.getPageNum(), page.getSize(), sysUserAccountHistoryPage.getTotal(), page.getPages(),
  221. sysUserAccountHistoryPage.getRecords());
  222. }
  223. //
  224. @Override
  225. public BasePageResult<SysUserAccount> queryByVo1(SysUserAccountVo sysUserAccountVo) {
  226. Page<SysUserAccount> page = new Page<>(sysUserAccountVo.getPageNum(), sysUserAccountVo.getPageSize());
  227. Page<SysUserAccount> sysUserAccountHistoryPage = baseMapper.queryPageOrder1(sysUserAccountVo,page);
  228. if(sysUserAccountHistoryPage!=null){
  229. List<SysUserAccount> records = sysUserAccountHistoryPage.getRecords();
  230. List<SysUserAccount> newRecords = new ArrayList<>();
  231. if(records!=null && !records.isEmpty()){
  232. for(SysUserAccount sysUserAccount :records){
  233. //重新赋值总金额 - 已提现金额 支付中金额
  234. MySumAmountQueryDto mySumAmountQueryDto =new MySumAmountQueryDto();
  235. mySumAmountQueryDto.setUserId(sysUserAccount.getUserId());
  236. //出单员是19 且是渠道的话,给渠道团队长
  237. if ("21".equals(sysUserAccount.getRoleId()) && "1".equals(sysUserAccount.getManagementSource())) {
  238. mySumAmountQueryDto.setDeptId(sysUserAccount.getDeptId());
  239. }
  240. //如果是电销组长,将组员的数据算进来
  241. if ("72".equals(sysUserAccount.getRoleId()) && "3".equals(sysUserAccount.getManagementSource())) {
  242. mySumAmountQueryDto.setGroupFlag(true);
  243. }
  244. // 已提现金额 查询历史表中的审核状态为3的数据
  245. BigDecimal ysTXAmount = insFeeOrderNewService.findMyAmountYTXmount(mySumAmountQueryDto.getUserId(), "3",mySumAmountQueryDto.getGroupFlag());
  246. // 提现中
  247. BigDecimal txzTXAmount = insFeeOrderNewService.findMyAmountYTXmount(mySumAmountQueryDto.getUserId(), "2",mySumAmountQueryDto.getGroupFlag());
  248. // 可提现
  249. BigDecimal ssKTAmount = sysUserAccount.getSumAmount()==null?BigDecimal.ZERO:sysUserAccount.getSumAmount();
  250. //总的 = 已提现金额+ 可提现金额 + 提现中
  251. BigDecimal sumAmount = ysTXAmount.add(ssKTAmount).add(txzTXAmount);
  252. sysUserAccount.setSumAmountWithdrawal(sumAmount);
  253. sysUserAccount.setSumAmountAccount(ysTXAmount);
  254. sysUserAccount.setSumAmountPayment(txzTXAmount);
  255. newRecords.add(sysUserAccount);
  256. }
  257. }
  258. sysUserAccountHistoryPage.setRecords(newRecords);
  259. }
  260. return new BasePageResult<>(sysUserAccountVo.getPageNum(), page.getSize(), sysUserAccountHistoryPage.getTotal(), page.getPages(),
  261. sysUserAccountHistoryPage.getRecords());
  262. }
  263. @Override
  264. @Transactional
  265. public HttpResult<Object> inert(SysUserAccountVo sysUserAccountVo) {
  266. String userId = BaseController.getUser().getId();
  267. if (isManagement(userId) && sysSwitchConfigService.getBalanceExtractStatus()){
  268. // 个代走线上付款
  269. UserWithdrawal withdrawal = new UserWithdrawal();
  270. withdrawal.setUserId(userId);
  271. withdrawal.setAmount(sysUserAccountVo.getAmount());
  272. withdrawal.setBankNumber(sysUserAccountVo.getFromBankCardId());
  273. return ttqfService.userCashOut(withdrawal);
  274. }
  275. //add by hxl 2024-09-26 添加电销组员开关
  276. boolean flag = sysSwitchConfigService.dxtxDisplaySwitches();
  277. if(flag){
  278. // add by hxl 2024-09-25 电销组员无法提现
  279. SysUser user = sysUserService.getById(userId);
  280. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(userId);
  281. SysDept dept = sysDeptService.getById(user.getDeptId());
  282. if("3".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())){
  283. throw new SystemException("电销组员不能提现");
  284. }
  285. }
  286. // add by hxl 2024-09-12 =============== 添加提现用户是渠道的话,只能提现100的整数金额
  287. BigDecimal amount = sysUserAccountVo.getAmount();
  288. // judgeAmount(amount, userId); 注释掉 2024-09-18
  289. // add by hxl end =============================
  290. BigDecimal zero = BigDecimal.ZERO;
  291. BigDecimal beforeAmount;
  292. BigDecimal afterAmount;
  293. // 用户当前金额
  294. // BigDecimal amount = sysUserAccountVo.getAmount();
  295. SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory(); // 记录
  296. sysUserAccountHistory.setDocumentary(1); // 1提现
  297. sysUserAccountHistory.setUserId(userId);
  298. sysUserAccountHistory.setProperty(6);
  299. sysUserAccountHistory.setBusinessSegmentsType(1);
  300. SysAmountAuditingEntity sysAmountAuditingEntity = new SysAmountAuditingEntity();//审核记录表
  301. sysAmountAuditingEntity.setUserId(userId);
  302. sysAmountAuditingEntity.setAmount(sysUserAccountVo.getAmount());
  303. sysUserAccountHistory.setCreateTime(new Date());
  304. // SysAmountAuditingEntity judge = sysAmountAuditingService.getByUserId(userId, sysUserAccountVo.getAmountStatus());
  305. // if (ObjectUtils.isNotEmpty(judge)) {
  306. // return HttpResult.ok("有未提现审核单据, 请审核完成之后再提现");
  307. // }
  308. // 通过银行卡id 查询卡包
  309. String fromBankCardId = sysUserAccountVo.getFromBankCardId();
  310. if (fromBankCardId != null) {
  311. // SysUserBankCard byId = sysUserBankCardService.getById(fromBankCardId);
  312. SysUserBankCard byId = sysUserBankCardService.getByBankNumber(fromBankCardId, userId);
  313. if (byId == null) {
  314. throw new SystemException("该卡未绑定此账号,或输入卡号错误,或该账号尚未审核通过,请检查");
  315. }
  316. byId.setIsDefault(1);
  317. sysAmountAuditingEntity.setBankNumber(byId.getBankNumber());
  318. sysUserAccountHistory.setFromBankCard(byId.getBankNumber());
  319. sysUserBankCardService.updateById(byId);
  320. }
  321. if (StringUtils.isNotEmpty(userId)) {
  322. SysUserAccount sysUserAccount = baseMapper.getById(userId);
  323. //if (StringUtils.isNotEmpty(sysUserAccountVo.getAmountStatus())) {
  324. //sysUserAccountHistory.setProperty(Integer.valueOf(sysUserAccountVo.getAmountStatus())); //金额类型
  325. /**
  326. if ("1".equals(sysUserAccountVo.getAmountStatus())) {
  327. // 用户当前费用金
  328. beforeAmount = sysUserAccount.getHandlingFee();
  329. afterAmount = beforeAmount.subtract(amount);
  330. sysUserAccount.setHandlingFee(afterAmount);
  331. sysUserAccount.setHandlingAmountPayment(sysUserAccount.getHandlingAmountPayment().add(amount));
  332. sysUserAccount.setHandlingAmountWithdrawal(sysUserAccount.getHandlingAmountWithdrawal().add(amount));
  333. } else if ("2".equals(sysUserAccountVo.getAmountStatus())) {
  334. // 用户当前 非跟单佣金
  335. beforeAmount = sysUserAccount.getDocumentary();
  336. afterAmount = beforeAmount.subtract(amount);
  337. sysUserAccount.setDocumentary(afterAmount);
  338. sysUserAccount.setDocumentaryAmountpayment(sysUserAccount.getDocumentaryAmountpayment().add(amount));
  339. sysUserAccount.setDocumentaryAmountWithdrawal(sysUserAccount.getDocumentaryAmountWithdrawal().add(amount));
  340. } else {
  341. beforeAmount = sysUserAccount.getPromotion();
  342. afterAmount = beforeAmount.subtract(amount);
  343. sysUserAccount.setPromotion(afterAmount);
  344. sysUserAccount.setPromotionAmountPayment(sysUserAccount.getPromotionAmountPayment().add(amount));
  345. sysUserAccount.setPromotionAmountWithdrawal(sysUserAccount.getPromotionAmountWithdrawal().add(amount));
  346. }
  347. **/
  348. //提现前的金额
  349. beforeAmount = sysUserAccount.getSumAmount() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmount();
  350. //提现后的金额
  351. afterAmount = beforeAmount.subtract(amount);
  352. sysUserAccount.setSumAmount(afterAmount);
  353. //支付中总金额 = 原先的支付金额 + 提现的金额
  354. sysUserAccount.setSumAmountPayment((sysUserAccount.getSumAmountPayment() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmountPayment()).add(amount));
  355. //提现的总金额 = 原先的提现总金额 + 提现的金额
  356. sysUserAccount.setSumAmountWithdrawal((sysUserAccount.getSumAmountWithdrawal() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmountWithdrawal().add(amount)));
  357. // 用户相差
  358. if (beforeAmount.compareTo(zero) == 0 || afterAmount.compareTo(zero) < 0) {
  359. return HttpResult.ok("余额不足");
  360. }
  361. sysUserAccountHistory.setAmount(amount); // 金额
  362. sysUserAccountHistory.setSurplusAmount(afterAmount); // 剩余金额
  363. sysUserAccountHistory.setUserAmount(beforeAmount); // 用户剩余金额
  364. sysAmountAuditingEntity.setCreateTime(new Date());
  365. sysAmountAuditingEntity.setAuditingStatus("2"); // 2 为待审核 3 审核通过
  366. // sysAmountAuditingEntity.setAmountStatus(sysUserAccountVo.getAmountStatus());
  367. // 新增金额记录
  368. sysAmountAuditingService.save(sysAmountAuditingEntity);
  369. sysUserAccountHistory.setAuditiingId(sysAmountAuditingEntity.getId());
  370. sysUserAccountService.updateById(sysUserAccount);
  371. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  372. // }
  373. // 提现审核插入轨迹表 待审核数据 和审核处理中的数据
  374. // Calendar calendar = Calendar.getInstance();
  375. Date date = new Date();
  376. //calendar.add(Calendar.MINUTE, 1);
  377. // Date afterDate = calendar.getTime();
  378. SysAmountAuditingHistory sysAmountAuditingHistory = new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId, date, "1", "1", sysUserAccountHistory.getId());
  379. SysAmountAuditingHistory sysAmountAuditingHistoryTwo = new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId, date, "2", "1", sysUserAccountHistory.getId());
  380. sysAmountAuditingHistoryService.save(sysAmountAuditingHistory);
  381. sysAmountAuditingHistoryService.save(sysAmountAuditingHistoryTwo);
  382. }
  383. return HttpResult.ok("提现成功,等待审核");
  384. }
  385. public boolean isManagement(String userId) {
  386. SysUser sysUser = SpringUtil.getBean(SysUserBankCardMapper.class).selectByIdPay(userId);
  387. if (ManagementSource.MS_02.getCode().equals(sysUser.getManagementSource())){
  388. return true;
  389. }
  390. return false;
  391. }
  392. /**
  393. * @version
  394. * @author: hxl
  395. * @Date: 2024/6/18 17:30
  396. * @Description: 提现修改为总金额
  397. */
  398. @Override
  399. @Transactional
  400. public HttpResult withdraw(SysUserAccountVo sysUserAccountVo) {
  401. String userId = sysUserAccountVo.getUserId();
  402. //add by hxl 2024-09-26 添加电销组员开关
  403. boolean flag = sysSwitchConfigService.dxtxDisplaySwitches();
  404. if(flag){
  405. // add by hxl 2024-09-25 电销组员无法提现
  406. SysUser user = sysUserService.getById(userId);
  407. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(userId);
  408. SysDept dept = sysDeptService.getById(user.getDeptId());
  409. if("3".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())){
  410. throw new SystemException("电销组员不能提现");
  411. }
  412. }
  413. // add by hxl 2024-09-12 =============== 添加提现用户是渠道的话,只能提现100的整数金额
  414. BigDecimal amount = sysUserAccountVo.getAmount();
  415. // judgeAmount(amount, userId); 注释掉 2024-09-18
  416. // add by hxl end =============================
  417. BigDecimal zero = BigDecimal.ZERO;
  418. BigDecimal beforeAmount;
  419. BigDecimal afterAmount;
  420. // 用户当前金额
  421. // BigDecimal amount = sysUserAccountVo.getAmount();
  422. SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory(); // 记录
  423. sysUserAccountHistory.setDocumentary(1); // 1支出
  424. sysUserAccountHistory.setUserId(userId);
  425. sysUserAccountHistory.setProperty(6); //3提现
  426. sysUserAccountHistory.setBusinessSegmentsType(1);
  427. SysAmountAuditingEntity sysAmountAuditingEntity = new SysAmountAuditingEntity();//审核记录表
  428. sysAmountAuditingEntity.setUserId(userId);
  429. sysAmountAuditingEntity.setAmount(sysUserAccountVo.getAmount());
  430. sysUserAccountHistory.setCreateTime(new Date());
  431. // SysAmountAuditingEntity judge = sysAmountAuditingService.getByUserId(userId, sysUserAccountVo.getAmountStatus());
  432. // if (ObjectUtils.isNotEmpty(judge)) {
  433. // throw new SystemException("有未提现审核单据, 请审核完成之后再提现");
  434. // }
  435. // 通过银行卡id 查询卡包
  436. String fromBankCardId = sysUserAccountVo.getFromBankCardId();
  437. SysUserBankCard byId = sysUserBankCardService.getByBankNumber(fromBankCardId, userId);
  438. if (byId == null) {
  439. throw new SystemException("该卡未绑定此账号,或输入卡号错误,或该账号尚未审核通过,请检查");
  440. }
  441. if (fromBankCardId != null && byId.getUserId().equals(userId)) {
  442. byId.setIsDefault(1);
  443. sysAmountAuditingEntity.setBankNumber(byId.getBankNumber());
  444. sysUserAccountHistory.setFromBankCard(byId.getBankNumber());
  445. sysUserBankCardService.updateById(byId);
  446. }
  447. if (StringUtils.isNotEmpty(userId)) {
  448. SysUserAccount sysUserAccount = baseMapper.getById(userId);
  449. //if (StringUtils.isNotEmpty(sysUserAccountVo.getAmountStatus())) {
  450. //sysUserAccountHistory.setProperty(Integer.valueOf(sysUserAccountVo.getAmountStatus())); //金额类型
  451. //注释掉类型提现,直接提现总金额
  452. /**
  453. if ("1".equals(sysUserAccountVo.getAmountStatus())) {
  454. // 用户当前费用金
  455. beforeAmount = sysUserAccount.getHandlingFee();
  456. afterAmount = beforeAmount.subtract(amount);
  457. sysUserAccount.setHandlingFee(afterAmount);
  458. sysUserAccount.setHandlingAmountPayment(sysUserAccount.getHandlingAmountPayment().add(amount));
  459. sysUserAccount.setHandlingAmountWithdrawal(sysUserAccount.getHandlingAmountWithdrawal().add(amount));
  460. } else if ("2".equals(sysUserAccountVo.getAmountStatus())) {
  461. // 用户当前 非跟单佣金
  462. beforeAmount = sysUserAccount.getDocumentary();
  463. afterAmount = beforeAmount.subtract(amount);
  464. sysUserAccount.setDocumentary(afterAmount);
  465. sysUserAccount.setDocumentaryAmountpayment(sysUserAccount.getDocumentaryAmountpayment().add(amount));
  466. sysUserAccount.setDocumentaryAmountWithdrawal(sysUserAccount.getDocumentaryAmountWithdrawal().add(amount));
  467. } else {
  468. beforeAmount = sysUserAccount.getPromotion();
  469. afterAmount = beforeAmount.subtract(amount);
  470. sysUserAccount.setPromotion(afterAmount);
  471. sysUserAccount.setPromotionAmountPayment(sysUserAccount.getPromotionAmountPayment().add(amount));
  472. sysUserAccount.setPromotionAmountWithdrawal(sysUserAccount.getPromotionAmountWithdrawal().add(amount));
  473. }
  474. **/
  475. //提现前的金额
  476. beforeAmount = sysUserAccount.getSumAmount() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmount();
  477. //提现后的金额
  478. afterAmount = beforeAmount.subtract(amount);
  479. sysUserAccount.setSumAmount(afterAmount);
  480. //支付中总金额 = 原先的支付金额 + 提现的金额
  481. sysUserAccount.setSumAmountPayment((sysUserAccount.getSumAmountPayment() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmountPayment()).add(amount));
  482. //提现的总金额 = 原先的提现总金额 + 提现的金额
  483. sysUserAccount.setSumAmountWithdrawal((sysUserAccount.getSumAmountWithdrawal() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmountWithdrawal().add(amount)));
  484. // 用户相差
  485. if (beforeAmount.compareTo(zero) == 0 || afterAmount.compareTo(zero) < 0) {
  486. return HttpResult.error("余额不足");
  487. }
  488. sysUserAccountHistory.setAmount(amount); // 金额
  489. sysUserAccountHistory.setSurplusAmount(afterAmount); // 剩余金额
  490. sysUserAccountHistory.setUserAmount(beforeAmount); // 用户剩余金额
  491. sysAmountAuditingEntity.setCreateTime(new Date());
  492. sysAmountAuditingEntity.setAuditingStatus("2"); // 2 为待审核 3 审核通过
  493. sysAmountAuditingEntity.setAmountStatus(sysUserAccountVo.getAmountStatus());
  494. // 新增金额记录
  495. sysAmountAuditingService.save(sysAmountAuditingEntity);
  496. sysUserAccountHistory.setAuditiingId(sysAmountAuditingEntity.getId());
  497. sysUserAccountService.updateById(sysUserAccount);
  498. sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
  499. //}
  500. // 提现审核插入轨迹表 待审核数据 和审核处理中的数据
  501. Calendar calendar = Calendar.getInstance();
  502. Date date = calendar.getTime();
  503. calendar.add(Calendar.MINUTE, 1);
  504. Date afterDate = calendar.getTime();
  505. SysAmountAuditingHistory sysAmountAuditingHistory = new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId, date, "1", "1", sysUserAccountHistory.getId());
  506. SysAmountAuditingHistory sysAmountAuditingHistoryTwo = new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId, afterDate, "2", "1", sysUserAccountHistory.getId());
  507. sysAmountAuditingHistoryService.save(sysAmountAuditingHistory);
  508. sysAmountAuditingHistoryService.save(sysAmountAuditingHistoryTwo);
  509. }
  510. return HttpResult.ok("提现成功,等待审核");
  511. }
  512. @Override
  513. public SysUserAccount getSysUserAmount(String userid) {
  514. SysUserAccount sysUserAccount = baseMapper.getById(userid);
  515. return sysUserAccount;
  516. }
  517. /**
  518. * @version
  519. * @author: hxl
  520. * @Date: 2024/6/11 16:05
  521. * @Description: 注释掉实收的总金额提升查询效率
  522. */
  523. @Override
  524. public SysUserAccountVo getSysAllAmount(String userId) {
  525. SysUserAccountVo sysUserAccountVo = new SysUserAccountVo();
  526. SysUserAccount sysUserAccount = baseMapper.getById(userId);
  527. // 验证账户信息是否有值
  528. if (ObjectUtils.isEmpty(sysUserAccount)) {
  529. return sysUserAccountVo;
  530. }
  531. BeanUtils.copyProperties(sysUserAccount, sysUserAccountVo);
  532. BigDecimal willHalding = BigDecimal.ZERO; //预收手续费佣金
  533. BigDecimal willDocumentary = BigDecimal.ZERO; //预收 非跟单佣金
  534. BigDecimal willPromotion = BigDecimal.ZERO; //预收 推广
  535. //BigDecimal receivedWillHalding = BigDecimal.ZERO; //实收手续费佣金
  536. // BigDecimal receivedWillDocumentary = BigDecimal.ZERO; //实收非跟单佣金
  537. // BigDecimal receivedWillPromotion = BigDecimal.ZERO; //实收推广费
  538. // 预收手续费佣金
  539. willPromotion = this.willPromotionAll(willPromotion, userId, "1");
  540. // 实收手续费佣金
  541. //receivedWillPromotion = this.willPromotionAll(willPromotion, userId,"2");
  542. // add by hxl 修改sql 添加承保状态和不在审核表中的条件 begin ===============
  543. List<InsFeeOrderNew> willList = insFeeOrderNewService.getByUserIdAndOrderStatusAndNoCheckType(userId, "1");
  544. //List<InsFeeOrderNew> willListnew = insFeeOrderNewService.getByUserIdAndOrderStatusAndNoCheckType(userId,"2");
  545. if (!CollectionUtils.isEmpty(willList)) {
  546. for (InsFeeOrderNew item : willList) {
  547. if (ObjectUtils.isNotEmpty(item)) {
  548. //1.预收手续费佣金 2. 预收非跟单佣金
  549. willHalding = willHalding.add(this.willAmountNew(item, 1));
  550. willDocumentary = willDocumentary.add(this.willAmountNew(item, 2));
  551. }
  552. }
  553. }
  554. /**
  555. if (!CollectionUtils.isEmpty(willListnew)) {
  556. for (InsFeeOrderNew item : willListnew) {
  557. if (ObjectUtils.isNotEmpty(item)) {
  558. //1.实收手续费佣金 2. 实收非跟单佣金
  559. receivedWillHalding = willHalding.add(this.willAmountNew(item,1));
  560. receivedWillDocumentary = willDocumentary.add(this.willAmountNew(item,2));
  561. }
  562. }
  563. }
  564. **/
  565. //预收手续费佣金
  566. sysUserAccountVo.setWillHalding(willHalding);
  567. //预收非跟单佣金
  568. sysUserAccountVo.setWillDocumentary(willDocumentary);
  569. //实收手续费佣金
  570. //sysUserAccountVo.setReceivedWillHalding(receivedWillHalding);
  571. //实收非跟单佣金
  572. //sysUserAccountVo.setReceivedWillDocumentary(receivedWillDocumentary);
  573. //提现现中 手续费、非跟单、推广费
  574. HashMap<String, Object> params = new HashMap<>();
  575. params.put("auditingStatus", "2"); // 待审核
  576. params.put("userId", userId);
  577. List<SysAmountAuditingEntity> sysAmountAuditingProgressIng = sysAmountAuditingService.getProgressIng(params);
  578. this.judge(sysAmountAuditingProgressIng, sysUserAccountVo);
  579. params.clear();
  580. params.put("auditingStatus", "3"); // 已审核审核
  581. params.put("userId", userId);
  582. //已提现 手续费、非跟单、推广费
  583. List<SysAmountAuditingEntity> sysAmountAuditingApproved = sysAmountAuditingService.getProgressIng(params);
  584. this.judgeSysAmountAuditing(sysAmountAuditingApproved, sysUserAccountVo);
  585. //预收手续费佣金
  586. sysUserAccountVo.setWillPromotion(willPromotion);
  587. //实收手续费佣金
  588. // sysUserAccountVo.setReceivedWillPromotion(receivedWillPromotion);
  589. return sysUserAccountVo;
  590. }
  591. @Override
  592. public SysUserAccountVo getInsOrders(SysUserAccountVo sysUserAccountVo) {
  593. ArrayList<InsFeeOrderNew> resultList = new ArrayList<>();
  594. HashMap<String, Object> params = new HashMap<>();
  595. params.put("userId", BaseController.getUser().getId());
  596. //日期
  597. params.put("timeFiltering", sysUserAccountVo.getTimeFiltering());
  598. //1预收2.实收
  599. params.put("type", sysUserAccountVo.getSearchType());
  600. sysUserAccountVo.setInsFeeOrderNewList(null);
  601. //金额类型 1. 手续费金额 2. 跟单金额 3. 推广金额
  602. if ("3".equals(sysUserAccountVo.getAmountType())) {
  603. List<InsFeeOrderNew> sumWillAmountGeneralization = insFeeOrderNewService.getSumWillAmountGeneralizationNew(params);
  604. sysUserAccountVo.setInsFeeOrderNewList(sumWillAmountGeneralization);
  605. } else {
  606. List<InsFeeOrderNew> resultInsFeeOrderNew = insFeeOrderNewService.getSumWillAmountNew(params);
  607. if (resultInsFeeOrderNew != null && resultInsFeeOrderNew.size() > 0) {
  608. for (InsFeeOrderNew item : resultInsFeeOrderNew) {
  609. BigDecimal willPromotion = BigDecimal.ZERO;
  610. if ("1".equals(sysUserAccountVo.getAmountType())) {
  611. //手续费出口预收
  612. willPromotion = willPromotion.add(item.getJqExportSuperviseCostsPremiums()).add(item.getSyExportSuperviseCostsPremiums()).add(item.getNoExportSuperviseCostsPremiums());
  613. } else if ("2".equals(sysUserAccountVo.getAmountType())) {
  614. willPromotion = willPromotion.add(item.getJqExportOtherCostsPremiums()).add(item.getSyExportOtherCostsPremiums()).add(item.getNoExportOtherCostsPremiums());
  615. }
  616. item.setWillAmount(willPromotion);
  617. if (willPromotion.compareTo(BigDecimal.ZERO) != 0) {
  618. resultList.add(item);
  619. }
  620. }
  621. sysUserAccountVo.setInsFeeOrderNewList(resultList);
  622. }
  623. }
  624. return sysUserAccountVo;
  625. }
  626. private void getWillAmount(InsFeeOrderNew insFeeOrderNew) {
  627. if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
  628. //交强手续费出口比例
  629. BigDecimal jqExportProceduresFee =
  630. insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqSuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  631. //商业手续费出口比例
  632. BigDecimal syExportProceduresFee =
  633. insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSySuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  634. //非车手续费出口比例
  635. BigDecimal noExportProceduresFee =
  636. insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoSuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  637. //非车出口比例
  638. //总机构 交强管理比例
  639. BigDecimal sumJqDeptProportion = insFeeOrderNew.getJqDeptProportionLevel1()
  640. .add(insFeeOrderNew.getJqDeptProportionLevel2())
  641. .add(insFeeOrderNew.getJqDeptProportionLevel3())
  642. .add(insFeeOrderNew.getJqDeptProportionLevel4())
  643. .add(insFeeOrderNew.getJqDeptProportionLevel5());
  644. //总机构 商业管理比例
  645. BigDecimal sumSyDeptProportion = insFeeOrderNew.getSyDeptProportionLevel1()
  646. .add(insFeeOrderNew.getSyDeptProportionLevel2())
  647. .add(insFeeOrderNew.getSyDeptProportionLevel3())
  648. .add(insFeeOrderNew.getSyDeptProportionLevel4())
  649. .add(insFeeOrderNew.getSyDeptProportionLevel5());
  650. //总机构 非车管理比例
  651. BigDecimal sumNoDeptProportion = insFeeOrderNew.getNoDeptProportionLevel1()
  652. .add(insFeeOrderNew.getNoDeptProportionLevel2())
  653. .add(insFeeOrderNew.getNoDeptProportionLevel3())
  654. .add(insFeeOrderNew.getNoDeptProportionLevel4())
  655. .add(insFeeOrderNew.getNoDeptProportionLevel5());
  656. BigDecimal noExportProceduresProportion = new BigDecimal(0);
  657. //总分销比例
  658. BigDecimal sumRetail =
  659. insFeeOrderNew.getFirstDetailProportion().add(insFeeOrderNew.getSecondDetailProportion()).add(insFeeOrderNew.getThirdDetailProportion());
  660. if (insFeeOrderNew.getNoCostsProportion().compareTo(sumNoDeptProportion.add(sumRetail)) > 0) {
  661. noExportProceduresProportion = insFeeOrderNew.getNoCostsProportion().subtract(sumNoDeptProportion).subtract(sumRetail);
  662. }
  663. //商业出口比例
  664. BigDecimal syExportProceduresProportion = new BigDecimal(0);
  665. if (insFeeOrderNew.getSyCostsProportion().compareTo(sumSyDeptProportion.add(sumRetail)) > 0) {
  666. syExportProceduresProportion = insFeeOrderNew.getSyCostsProportion().subtract(sumSyDeptProportion).subtract(sumRetail);
  667. }
  668. //交强出口比例
  669. BigDecimal jqExportProceduresProportion = new BigDecimal(0);
  670. if (insFeeOrderNew.getJqCostsProportion().compareTo(sumJqDeptProportion.add(sumRetail)) > 0) {
  671. jqExportProceduresProportion = insFeeOrderNew.getJqCostsProportion().subtract(sumJqDeptProportion).subtract(sumRetail);
  672. }
  673. //交强跟单出口费用
  674. BigDecimal jqExportOtherFee = insFeeOrderNew.getJqPremium()
  675. .multiply(jqExportProceduresProportion
  676. .subtract(insFeeOrderNew.getJqSuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
  677. BigDecimal.ROUND_DOWN);
  678. //商业跟单出口比例
  679. BigDecimal syExportOtherFee = insFeeOrderNew.getSyPremium()
  680. .multiply(syExportProceduresProportion
  681. .subtract(insFeeOrderNew.getSySuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
  682. BigDecimal.ROUND_DOWN);
  683. //非车跟单出口比例
  684. BigDecimal noExportOtherFee = insFeeOrderNew.getNoPremium()
  685. .multiply(noExportProceduresProportion
  686. .subtract(insFeeOrderNew.getNoSuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
  687. BigDecimal.ROUND_DOWN);
  688. if (StringUtils.isNotEmpty(insFeeOrderNew.getAmountType())) {
  689. if ("1".equals(insFeeOrderNew.getAmountType())) {
  690. //用户出口手续费
  691. insFeeOrderNew.setWillAmount(jqExportProceduresFee.add(syExportProceduresFee).add(noExportProceduresFee));
  692. }
  693. if ("2".equals(insFeeOrderNew.getAmountType())) {
  694. //用户出口跟单费
  695. insFeeOrderNew.setWillAmount(jqExportOtherFee.add(syExportOtherFee).add(noExportOtherFee));
  696. }
  697. }
  698. }
  699. }
  700. private BigDecimal getWillPromotion(InsFeeOrderNew insFeeOrderNew, BigDecimal willPromotion) {
  701. InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNew(insFeeOrderNew);
  702. if (ObjectUtils.isNotEmpty(InsOrders)) {
  703. BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
  704. // 累加保费
  705. willPromotion = willPromotion.add(willFirstPremiums);
  706. }
  707. return willPromotion;
  708. }
  709. private void judgeSysAmountAuditing(List<SysAmountAuditingEntity> sysAmountAuditingApproved, SysUserAccountVo sysUserAccountVo) {
  710. if (!CollectionUtils.isEmpty(sysAmountAuditingApproved)) {
  711. for (SysAmountAuditingEntity item : sysAmountAuditingApproved) {
  712. if ("1".equals(item.getAmountStatus())) { //手续费
  713. BigDecimal amount = item.getAmount();
  714. sysUserAccountVo.setApprovedHalding(amount);
  715. }
  716. if ("2".equals(item.getAmountStatus())) { //非跟单
  717. BigDecimal amount = item.getAmount();
  718. sysUserAccountVo.setApprovedDocumentary(amount);
  719. }
  720. if ("3".equals(item.getAmountStatus())) { //推广费
  721. BigDecimal amount = item.getAmount();
  722. sysUserAccountVo.setApprovedPromotion(amount);
  723. }
  724. }
  725. }
  726. }
  727. private void judge(List<SysAmountAuditingEntity> sysAmountAuditingProgressIng, SysUserAccountVo sysUserAccountVo) {
  728. if (!CollectionUtils.isEmpty(sysAmountAuditingProgressIng)) {
  729. for (SysAmountAuditingEntity item : sysAmountAuditingProgressIng) {
  730. if ("1".equals(item.getAmountStatus())) { //手续费
  731. BigDecimal amount = item.getAmount();
  732. sysUserAccountVo.setWithdrawalHalding(amount);
  733. }
  734. if ("2".equals(item.getAmountStatus())) { //非跟单
  735. BigDecimal amount = item.getAmount();
  736. sysUserAccountVo.setWithdrawalDocumentary(amount);
  737. }
  738. if ("3".equals(item.getAmountStatus())) { //推广费
  739. BigDecimal amount = item.getAmount();
  740. sysUserAccountVo.setWithdrawalPromotion(amount);
  741. }
  742. }
  743. }
  744. }
  745. private BigDecimal willPromotion(BigDecimal willPromotion, String userId) {
  746. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  747. insFeeOrderNew.setUserId(userId);
  748. InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNew(insFeeOrderNew);
  749. if (ObjectUtils.isNotEmpty(InsOrders)) {
  750. BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
  751. // 累加保费
  752. willPromotion = willPromotion.add(willFirstPremiums);
  753. }
  754. return willPromotion;
  755. }
  756. private void willAmount(InsFeeOrderNew insFeeOrderNew, BigDecimal willHalding, BigDecimal willDocumentary,
  757. SysUserAccountVo sysUserAccountVo) {
  758. if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
  759. //交强手续费
  760. BigDecimal jqExportProceduresFee = insFeeOrderNew.getJqExportSuperviseCostsPremiums();
  761. //商业手续费
  762. BigDecimal syExportProceduresFee = insFeeOrderNew.getSyExportSuperviseCostsPremiums();
  763. //非车手续费
  764. BigDecimal noExportProceduresFee = insFeeOrderNew.getNoExportSuperviseCostsPremiums();
  765. if (sysUserAccountVo.getWillHalding() == null) {
  766. sysUserAccountVo.setWillHalding(BigDecimal.ZERO);
  767. }
  768. sysUserAccountVo.setWillHalding(sysUserAccountVo.getWillHalding().add(jqExportProceduresFee).add(syExportProceduresFee).add(noExportProceduresFee));
  769. //交强跟单出口费用
  770. BigDecimal jqExportOtherCostsPremiums = insFeeOrderNew.getJqExportOtherCostsPremiums();
  771. //商业跟单出口费用
  772. BigDecimal syExportOtherCostsPremiums = insFeeOrderNew.getSyExportOtherCostsPremiums();
  773. //非车跟单出口费用
  774. BigDecimal noExportOtherCostsPremiums = insFeeOrderNew.getNoExportOtherCostsPremiums();
  775. //用户出口跟单费
  776. if (sysUserAccountVo.getWillDocumentary() == null) {
  777. sysUserAccountVo.setWillDocumentary(BigDecimal.ZERO);
  778. }
  779. sysUserAccountVo.setWillDocumentary(sysUserAccountVo.getWillDocumentary().add(jqExportOtherCostsPremiums).add(syExportOtherCostsPremiums).add(noExportOtherCostsPremiums));
  780. }
  781. }
  782. /**
  783. * @version
  784. * @author: hxl
  785. * @Date: 2024/6/3 11:20
  786. * @Description: 通过类型查询预收、实收的金额
  787. */
  788. private BigDecimal willPromotionAll(BigDecimal willPromotion, String userId, String type) {
  789. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  790. insFeeOrderNew.setUserId(userId);
  791. InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNewByType(insFeeOrderNew, type);
  792. if (ObjectUtils.isNotEmpty(InsOrders)) {
  793. BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
  794. // 累加保费
  795. willPromotion = willPromotion.add(willFirstPremiums);
  796. }
  797. return willPromotion;
  798. }
  799. /**
  800. * @version
  801. * @author: hxl
  802. * @Date: 2024/6/4 11:51
  803. * @Description: 获取费用
  804. */
  805. private BigDecimal willAmountNew(InsFeeOrderNew insFeeOrderNew, int type) {
  806. BigDecimal val = BigDecimal.ZERO;
  807. if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
  808. if (type == 1) {
  809. // 交强手续费+商业手续费+非车手续费
  810. val = val.add(insFeeOrderNew.getJqExportSuperviseCostsPremiums()).add(insFeeOrderNew.getSyExportSuperviseCostsPremiums()).add(insFeeOrderNew.getNoExportSuperviseCostsPremiums());
  811. } else {
  812. // 交强跟单出口费用+商业跟单出口费用+非车跟单出口费用
  813. val = val.add(insFeeOrderNew.getJqExportOtherCostsPremiums()).add(insFeeOrderNew.getSyExportOtherCostsPremiums()).add(insFeeOrderNew.getNoExportOtherCostsPremiums());
  814. }
  815. }
  816. return val;
  817. }
  818. /**
  819. * @version
  820. * @author: hxl
  821. * @Date: 2024/6/3 15:16
  822. * @Description: 查询子订单的详细信息
  823. */
  824. @Override
  825. public SubOrder getSubOrderDetails(String subOrderId, String userId) {
  826. SubOrder subOrder = insAreaCompanyMapper.getSubOrderDetails(subOrderId);
  827. subOrder.setAgentName(this.getUserName(subOrder.getUserId()));
  828. subOrder.setAgentLevel("");
  829. //根据用户id查询分销等级
  830. InsFeeOrderNew insFeeOrderNew = insFeeOrderNewService.getOne(new LambdaQueryWrapper<InsFeeOrderNew>()
  831. .eq(InsFeeOrderNew::getInsOrderNo, subOrder.getSubOrderId()));
  832. if (userId.equals(insFeeOrderNew.getFirstLevelUserId())) {
  833. //subOrder.setAgentName(this.getUserName(insFeeOrderNew.getFirstLevelUserId()));
  834. subOrder.setAgentLevel("一级分销代理");
  835. }
  836. if (userId.equals(insFeeOrderNew.getTwoLevelUserId())) {
  837. //subOrder.setAgentName(this.getUserName(insFeeOrderNew.getTwoLevelUserId()));
  838. subOrder.setAgentLevel("二级分销代理");
  839. }
  840. if (userId.equals(insFeeOrderNew.getThreeLevelUserId())) {
  841. //subOrder.setAgentName(this.getUserName(insFeeOrderNew.getThreeLevelUserId()));
  842. subOrder.setAgentLevel("三级分销代理");
  843. }
  844. return subOrder;
  845. }
  846. /**
  847. * @version
  848. * @author: hxl
  849. * @Date: 2024/6/3 16:34
  850. * @Description: 查询分销人名称
  851. */
  852. private String getUserName(String userId) {
  853. if (StringUtils.isNotEmpty(userId)) {
  854. SysUser sysUser = sysUserService.getBaseMapper().selectById(userId);
  855. if (ObjectUtils.isNotEmpty(sysUser)) {
  856. return sysUser.getName();
  857. }
  858. }
  859. return "";
  860. }
  861. /**
  862. * @version
  863. * @author: hxl
  864. * @Date: 2024/6/19 9:04
  865. * @Description: 查询我的账户总金额
  866. */
  867. @Override
  868. public BigDecimal getUserSumAmountByUserId(String userId) {
  869. if (StringUtils.isBlank(userId)) {
  870. throw new SystemException("用户id-userId不能为空");
  871. }
  872. //通过用户id查询用户账户的总金额
  873. LambdaQueryWrapper<SysUserAccount> queryWrapper = new LambdaQueryWrapper<>();
  874. queryWrapper.eq(SysUserAccount::getUserId, userId);
  875. SysUserAccount sysUserAccount = sysUserAccountService.getOne(queryWrapper);
  876. if (sysUserAccount == null) {
  877. return BigDecimal.ZERO;
  878. }
  879. return sysUserAccount.getSumAmount() == null ? BigDecimal.ZERO : sysUserAccount.getSumAmount();
  880. }
  881. /**
  882. * @version
  883. * @author: hxl
  884. * @Date: 2024/6/19 11:04
  885. * @Description: 查询预收数据明细
  886. */
  887. @Override
  888. public MyCollectInAdvanceAllDto findMyCollectInAdvanceByUserId(MyCollectInAdvanceQueryDto myCollectInAdvanceQueryDto) {
  889. if (StringUtils.isBlank(myCollectInAdvanceQueryDto.getUserId())) {
  890. throw new SystemException("用户id-userId不能为空");
  891. }
  892. BigDecimal sumAmount = BigDecimal.ZERO;
  893. //判断时间类型 1.一周内 2. 一月内 3. 三月内 4. 三月内
  894. HashMap<String, String> dateMap = getDateMapByType(myCollectInAdvanceQueryDto.getDateQueryType(), myCollectInAdvanceQueryDto.getStartDate(), myCollectInAdvanceQueryDto.getEndDate());
  895. myCollectInAdvanceQueryDto.setStartDate(dateMap.get("startDate"));
  896. myCollectInAdvanceQueryDto.setEndDate(dateMap.get("endDate"));
  897. if (myCollectInAdvanceQueryDto.getBusinessSegmentsType() == null || "".equals(myCollectInAdvanceQueryDto.getBusinessSegmentsType())) {
  898. myCollectInAdvanceQueryDto.setBusinessSegmentsType("1");
  899. }
  900. if (myCollectInAdvanceQueryDto.getTransactionType() == null || "".equals(myCollectInAdvanceQueryDto.getTransactionType())) {
  901. myCollectInAdvanceQueryDto.setTransactionType("1");
  902. }
  903. if (StringUtils.isEmpty(myCollectInAdvanceQueryDto.getAuditstatus())) {
  904. myCollectInAdvanceQueryDto.setAuditstatus("0");
  905. }
  906. Page<MyCollectInAdvanceDto> page = new Page<>(myCollectInAdvanceQueryDto.getPageNum(), myCollectInAdvanceQueryDto.getPageSize());
  907. // page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
  908. Page<MyCollectInAdvanceDto> orderVoPage = new Page<>();
  909. // 1为车险板块
  910. if ("1".equals(myCollectInAdvanceQueryDto.getBusinessSegmentsType())) {
  911. //金额类型 1. 手续费金额 +跟单金额 2. 推广金额
  912. if ("2".equals(myCollectInAdvanceQueryDto.getTransactionType())) {
  913. orderVoPage = insFeeOrderNewService.findMyCollectInAdvanceWillAmountByUserId(page, myCollectInAdvanceQueryDto);
  914. // Long total=insFeeOrderNewService.findMyCollectInAdvanceWillAmountByUserIdCount(myCollectInAdvanceQueryDto);
  915. // orderVoPage.setTotal(total);
  916. sumAmount = insFeeOrderNewService.findSumWillAmount(myCollectInAdvanceQueryDto);
  917. } else {
  918. orderVoPage = insFeeOrderNewService.findMyCollectInAdvanceSumByUserId(page, myCollectInAdvanceQueryDto);
  919. // Long total=insFeeOrderNewService.findMyCollectInAdvanceSumByUserIdCount(myCollectInAdvanceQueryDto);
  920. // orderVoPage.setTotal(total);
  921. sumAmount = insFeeOrderNewService.findSumAmount(myCollectInAdvanceQueryDto);
  922. }
  923. } else {
  924. //其他板块预留逻辑处理
  925. }
  926. List<MyCollectInAdvanceDto> recordsNew = new ArrayList<>();
  927. if (orderVoPage.getRecords() != null && !orderVoPage.getRecords().isEmpty()) {
  928. for (MyCollectInAdvanceDto dto : orderVoPage.getRecords()) {
  929. //车险的显示且收入
  930. if ("1".equals(dto.getBusinessSegmentsType())) {
  931. if ("4".equals(dto.getTransactionType())) {
  932. dto.setTransactionType("1");
  933. } else if ("3".equals(dto.getTransactionType())) {
  934. dto.setTransactionType("2");
  935. }
  936. }
  937. recordsNew.add(dto);
  938. }
  939. }
  940. boolean b = feeDisplayService.setWithdrawals(recordsNew);
  941. orderVoPage.setRecords(recordsNew);
  942. BasePageResult<MyCollectInAdvanceDto> myCollectInAdvanceDtoBasePageResult = new BasePageResult<>(myCollectInAdvanceQueryDto.getPageNum(), myCollectInAdvanceQueryDto.getPageSize(), orderVoPage.getTotal(),
  943. orderVoPage.getPages()
  944. , orderVoPage.getRecords());
  945. return new MyCollectInAdvanceAllDto(sumAmount, myCollectInAdvanceDtoBasePageResult, b);
  946. }
  947. /**
  948. * @version
  949. * @author: hxl
  950. * @Date: 2024/6/19 11:57
  951. * @Description: 通过时间类型判断
  952. */
  953. private static HashMap<String, String> getDateMapByType(String type, String startDate, String endDate) {
  954. HashMap<String, String> map = new HashMap<>();
  955. String startDateStr = "";
  956. String endDateStr = "";
  957. if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
  958. startDateStr = StringUtils.isNotBlank(startDate) ? startDate + " 00:00:00" : null;
  959. endDateStr = StringUtils.isNotBlank(endDate) ? endDate + " 23:59:59" : null;
  960. } else {
  961. if ("0".equals(type)) {
  962. //全部
  963. startDateStr = null;
  964. endDateStr = null;
  965. } else if ("1".equals(type)) {
  966. // 一周内
  967. startDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 1) + " 00:00:00";
  968. endDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 0) + " 23:59:59";
  969. } else if ("2".equals(type)) {
  970. // 一月内
  971. startDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 2) + " 00:00:00";
  972. endDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 0) + " 23:59:59";
  973. } else if ("3".equals(type)) {
  974. // 三月内
  975. startDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 3) + " 00:00:00";
  976. endDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 0) + " 23:59:59";
  977. } else if ("4".equals(type)) {
  978. // 三月内
  979. startDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 4) + " 00:00:00";
  980. endDateStr = SliceUpDateUtil.getBeforeDay(new Date(), 0) + " 23:59:59";
  981. } else {
  982. startDateStr = StringUtils.isNotBlank(startDate) ? startDate + " 00:00:00" : null;
  983. endDateStr = StringUtils.isNotBlank(endDate) ? endDate + " 23:59:59" : null;
  984. }
  985. }
  986. map.put("startDate", startDateStr);
  987. map.put("endDate", endDateStr);
  988. return map;
  989. }
  990. /**
  991. * @version
  992. * @author: hxl
  993. * @Date: 2024/6/19 11:04
  994. * @Description: 查询收支数据明细
  995. */
  996. @Override
  997. public MyCollectInAdvanceAllDto findIncomeAndExpensesByUserId(MyIncomeAndExpensesQueryDto myIncomeAndExpensesQueryDto) {
  998. if (StringUtils.isBlank(myIncomeAndExpensesQueryDto.getUserId())) {
  999. throw new SystemException("用户id-userId不能为空");
  1000. }
  1001. BigDecimal sumAmountSR = BigDecimal.ZERO;
  1002. BigDecimal sumAmountZC = BigDecimal.ZERO;
  1003. BasePageResult<MyCollectInAdvanceDto> myCollectInAdvanceDtoBasePageResult = new BasePageResult<MyCollectInAdvanceDto>();
  1004. //判断时间类型 1.一周内 2. 一月内 3. 三月内 4. 三月内
  1005. HashMap<String, String> dateMap = getDateMapByType(myIncomeAndExpensesQueryDto.getDateQueryType(), myIncomeAndExpensesQueryDto.getStartDate(), myIncomeAndExpensesQueryDto.getEndDate());
  1006. myIncomeAndExpensesQueryDto.setStartDate(dateMap.get("startDate"));
  1007. myIncomeAndExpensesQueryDto.setEndDate(dateMap.get("endDate"));
  1008. Page<MyCollectInAdvanceDto> page = new Page<>(myIncomeAndExpensesQueryDto.getPageNum(), myIncomeAndExpensesQueryDto.getPageSize());
  1009. //page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
  1010. Page<MyCollectInAdvanceDto> orderVoPage = new Page<>();
  1011. if ("0".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType())) {
  1012. myIncomeAndExpensesQueryDto.setBusinessSegmentsType(null);
  1013. }
  1014. if ("0".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1015. myIncomeAndExpensesQueryDto.setTransactionType(null);
  1016. }
  1017. if ("0".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
  1018. myIncomeAndExpensesQueryDto.setIncomeAndExpensesType(null);
  1019. }
  1020. // 1为车险板块 1 收入时
  1021. if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) && StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) && "1".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) && "1".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
  1022. //判断收入类型 1 收入
  1023. if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && "3".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1024. throw new SystemException("收入类型不能选择提现类型");
  1025. }
  1026. }
  1027. if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) && "2".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
  1028. //判断支出类型
  1029. if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && !"3".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1030. throw new SystemException("支出类型不能选择(手续+跟单)或者手续费、退款类型");
  1031. }
  1032. }
  1033. if ((StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) && StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) && "2".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) && "1".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()))
  1034. ||
  1035. (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) && ("2".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType())))) {
  1036. //判断退款类型
  1037. if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && !"4".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1038. throw new SystemException("退款板块只能选择退款类型");
  1039. }
  1040. }
  1041. //处理 手续费+跟单、推广费类型转换
  1042. if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && "2".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1043. myIncomeAndExpensesQueryDto.setTransactionType("3");
  1044. } else if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && "1".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1045. myIncomeAndExpensesQueryDto.setTransactionType("4");
  1046. } else if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && "4".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1047. myIncomeAndExpensesQueryDto.setTransactionType("5");
  1048. } else if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && "3".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
  1049. myIncomeAndExpensesQueryDto.setTransactionType("6");
  1050. }
  1051. //处理收入和支出类型转换
  1052. if (myIncomeAndExpensesQueryDto.getIncomeAndExpensesType() != null && "0".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
  1053. myIncomeAndExpensesQueryDto.setIncomeAndExpensesType(null);
  1054. } else if (myIncomeAndExpensesQueryDto.getIncomeAndExpensesType() != null && "1".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
  1055. myIncomeAndExpensesQueryDto.setIncomeAndExpensesType("2");
  1056. } else if (myIncomeAndExpensesQueryDto.getIncomeAndExpensesType() != null && "2".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
  1057. myIncomeAndExpensesQueryDto.setIncomeAndExpensesType("1");
  1058. }
  1059. orderVoPage = sysUserAccountHistoryService.findMyIncomeAndExpensesAmountByUserId(page, myIncomeAndExpensesQueryDto);
  1060. // Long total=sysUserAccountHistoryService.findMyIncomeAndExpensesAmountByUserIdCount(myIncomeAndExpensesQueryDto);
  1061. // orderVoPage.setTotal(total);
  1062. List<MyCollectInAdvanceDto> recordsNew = new ArrayList<>();
  1063. if (orderVoPage.getRecords() != null && orderVoPage.getRecords().size() > 0) {
  1064. for (MyCollectInAdvanceDto dto : orderVoPage.getRecords()) {
  1065. //车险的显示且收入
  1066. if ("1".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())) {
  1067. if ("4".equals(dto.getTransactionType())) {
  1068. dto.setTransactionType("1");
  1069. } else if ("3".equals(dto.getTransactionType())) {
  1070. dto.setTransactionType("2");
  1071. }
  1072. dto.setIncomeAndExpensesType("1");
  1073. //退款 且退款
  1074. } else if ("2".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())) {
  1075. dto.setIncomeAndExpensesType("1");
  1076. dto.setTransactionType("4");
  1077. //退款设置为空
  1078. dto.setAuditingStatus("");
  1079. //提现
  1080. } else if ("6".equals(dto.getTransactionType()) && "1".equals(dto.getIncomeAndExpensesType())) {
  1081. dto.setIncomeAndExpensesType("2");
  1082. dto.setTransactionType("3");
  1083. }
  1084. recordsNew.add(dto);
  1085. }
  1086. }
  1087. orderVoPage.setRecords(recordsNew);
  1088. boolean b = feeDisplayService.setWithdrawals(recordsNew);
  1089. myCollectInAdvanceDtoBasePageResult = new BasePageResult<>(myIncomeAndExpensesQueryDto.getPageNum(), myIncomeAndExpensesQueryDto.getPageSize(), orderVoPage.getTotal(),
  1090. orderVoPage.getPages()
  1091. , orderVoPage.getRecords());
  1092. //
  1093. sumAmountSR = sysUserAccountHistoryService.findSumAmountByUserId(myIncomeAndExpensesQueryDto.getUserId(), "2");
  1094. sumAmountZC = sysUserAccountHistoryService.findSumAmountByUserId(myIncomeAndExpensesQueryDto.getUserId(), "1");
  1095. return new MyCollectInAdvanceAllDto(sumAmountSR, sumAmountZC, myCollectInAdvanceDtoBasePageResult, b);
  1096. }
  1097. /**
  1098. * @version
  1099. * @author: hxl
  1100. * @Date: 2024/6/20 13:48
  1101. * @Description: 提现详情
  1102. */
  1103. @Override
  1104. public WithdrawalDetalsDto findDetailById(String id) {
  1105. //id为历史表的id
  1106. //通过历史记录表查询数据
  1107. SysUserAccountHistory his = sysUserAccountHistoryService.getById(id);
  1108. LambdaQueryWrapper<SysAmountAuditingHistory> lqw = new LambdaQueryWrapper<>();
  1109. lqw.eq(SysAmountAuditingHistory::getHistoryId, id);
  1110. lqw.orderByAsc(SysAmountAuditingHistory::getCreateTime);
  1111. List<SysAmountAuditingHistory> listAll = sysAmountAuditingHistoryService.list(lqw);
  1112. SysAmountAuditingEntity audi = sysAmountAuditingService.getById(his.getAuditiingId());
  1113. WithdrawalDetalsDto withdrawalDetalsDto = new WithdrawalDetalsDto();
  1114. if (audi != null) {
  1115. withdrawalDetalsDto.setBankNumber(audi.getBankNumber());
  1116. withdrawalDetalsDto.setTransactionNumber(audi.getId());
  1117. withdrawalDetalsDto.setWithdrawalAmount(audi.getAmount());
  1118. withdrawalDetalsDto.setBankAccount(audi.getBankAccount());
  1119. }
  1120. List<WithdrawalDetalsRecordDto> recordList = new ArrayList<WithdrawalDetalsRecordDto>();
  1121. if (listAll != null && listAll.size() > 0) {
  1122. SysAmountAuditingHistory first = listAll.get(0);
  1123. SysAmountAuditingHistory last = listAll.get(listAll.size() - 1);
  1124. //申请时间
  1125. Date createTime = first.getCreateTime();
  1126. withdrawalDetalsDto.setApplicationDate(createTime);
  1127. String auditingStatus = last.getAuditingStatus();
  1128. withdrawalDetalsDto.setWithdrawalStatus(auditingStatus);
  1129. String auditingStatusName = "";
  1130. if ("1".equals(auditingStatus)) {
  1131. auditingStatusName = "提现申请";
  1132. } else if ("2".equals(auditingStatus)) {
  1133. auditingStatusName = "处理中";
  1134. } else if ("3".equals(auditingStatus)) {
  1135. auditingStatusName = "提现失败";
  1136. } else if ("4".equals(auditingStatus)) {
  1137. auditingStatusName = "提现成功";
  1138. withdrawalDetalsDto.setPaymentDate(last.getCreateTime());
  1139. }
  1140. withdrawalDetalsDto.setWithdrawalStatusName(auditingStatusName);
  1141. WithdrawalDetalsRecordDto dto1 = new WithdrawalDetalsRecordDto("1", false, "提现申请", null);
  1142. WithdrawalDetalsRecordDto dto2 = new WithdrawalDetalsRecordDto("2", false, "处理中", null);
  1143. WithdrawalDetalsRecordDto dto3 = null;
  1144. WithdrawalDetalsRecordDto dto4 = new WithdrawalDetalsRecordDto("4", false, "提现成功", null);
  1145. for (SysAmountAuditingHistory sysAmountAuditingHistory : listAll) {
  1146. if ("1".equals(sysAmountAuditingHistory.getAuditingStatus())) {
  1147. dto1.setProcessingStatusFlag(true);
  1148. dto1.setProcessingDate(sysAmountAuditingHistory.getCreateTime());
  1149. } else if ("2".equals(sysAmountAuditingHistory.getAuditingStatus())) {
  1150. dto2.setProcessingStatusFlag(true);
  1151. dto2.setProcessingDate(sysAmountAuditingHistory.getCreateTime());
  1152. } else if ("3".equals(sysAmountAuditingHistory.getAuditingStatus())) {
  1153. dto3 = new WithdrawalDetalsRecordDto("3", true, "提现失败", sysAmountAuditingHistory.getCreateTime());
  1154. } else if ("4".equals(sysAmountAuditingHistory.getAuditingStatus())) {
  1155. dto4.setProcessingStatusFlag(true);
  1156. dto4.setProcessingDate(sysAmountAuditingHistory.getCreateTime());
  1157. }
  1158. }
  1159. recordList.add(dto1);
  1160. recordList.add(dto2);
  1161. if (dto3 != null) {
  1162. recordList.add(dto3);
  1163. withdrawalDetalsDto.setRejectReason(audi.getRejectReason() == null ? "" : audi.getRejectReason());
  1164. } else {
  1165. //add by hxl 2024-07-09 添加银行回单的路径
  1166. if (audi != null && StringUtils.isNotBlank(audi.getPicId())) {
  1167. //add by hxl 2024-08-15 屏蔽银行回单的路径
  1168. // InsUploadFiles insUploadFiles = insUploadFilesMapper.selectById(audi.getPicId());
  1169. // withdrawalDetalsDto.setBankReceipt(insUploadFiles==null?"":insUploadFiles.getUrl());
  1170. }
  1171. recordList.add(dto4);
  1172. }
  1173. withdrawalDetalsDto.setRecord(recordList);
  1174. }
  1175. return withdrawalDetalsDto;
  1176. }
  1177. @Override
  1178. public OrderDetalsDto findOrderDetailById(String subOrderId) {
  1179. return null;
  1180. }
  1181. /**
  1182. * @version
  1183. * @author: hxl
  1184. * @Date: 2024/6/21 18:27
  1185. * @Description: 查看退款详情
  1186. */
  1187. @Override
  1188. public RefundDetalsDto findRefundDetailById(String id) {
  1189. //id为历史表的id
  1190. //通过历史记录表查询数据
  1191. SysUserAccountHistory his = sysUserAccountHistoryService.getById(id);
  1192. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1193. String dateStr = sdf.format(his.getCreateTime());
  1194. return new RefundDetalsDto(dateStr, his.getAmount(), his.getAuditiingId());
  1195. }
  1196. /**
  1197. * @version
  1198. * @author: hxl
  1199. * @Date: 2024/6/30 15:28
  1200. * @Description: 查询车险明细
  1201. */
  1202. @Override
  1203. public MyIncomeAndExpensesNewPageVo<ExportExpenditureTypeDetalsDto> findMyInsuranceByUserId(MyInsuranceQueryDto myInsuranceQueryDto) {
  1204. Page<ExportExpenditureTypeDetalsDto> page = new Page<>(myInsuranceQueryDto.getPageNum(),
  1205. myInsuranceQueryDto.getPageSize());
  1206. List<String> userList = getStrings(myInsuranceQueryDto);
  1207. //赋值开始和结束时间
  1208. if (StringUtils.isNotBlank(myInsuranceQueryDto.getStartDate())) {
  1209. myInsuranceQueryDto.setStartDate(myInsuranceQueryDto.getStartDate() + " 00:00:00");
  1210. }
  1211. if (StringUtils.isNotBlank(myInsuranceQueryDto.getEndDate())) {
  1212. myInsuranceQueryDto.setEndDate(myInsuranceQueryDto.getEndDate() + " 23:59:59");
  1213. }
  1214. //如果是电销组长,统计电销组长和他组员的信息
  1215. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(myInsuranceQueryDto.getUserId());
  1216. SysUser user = sysUserService.getById(myInsuranceQueryDto.getUserId());
  1217. SysDept dept = sysDeptService.getById(user.getDeptId());
  1218. if ("72".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())) {
  1219. userList = sysUserService.getGroupByUserId(myInsuranceQueryDto.getUserId());
  1220. }
  1221. Page<ExportExpenditureTypeDetalsDto> pageList = insFeeOrderNewService.findMyInsuranceByUserId(page, myInsuranceQueryDto, userList);
  1222. boolean b = feeDisplayService.setCarInsurance(pageList.getRecords());
  1223. return new MyIncomeAndExpensesNewPageVo<>(myInsuranceQueryDto.getPageNum(), myInsuranceQueryDto.getPageSize(), pageList.getTotal(),
  1224. pageList.getPages()
  1225. , pageList.getRecords(), b);
  1226. }
  1227. /**
  1228. * @version
  1229. * @author: hxl
  1230. * @Date: 2024/6/30 17:59
  1231. * @Description: 获取渠道团队长管理的下级人
  1232. */
  1233. private List<String> getStrings(MyInsuranceQueryDto myInsuranceQueryDto) {
  1234. //查询当前管理的代理人信息
  1235. LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>();
  1236. lqw.eq(SysUser::getStatus, 1);
  1237. lqw.eq(SysUser::getOperatorCode, myInsuranceQueryDto.getUserId());
  1238. List<SysUser> users = sysUserMapper.selectList(lqw);
  1239. List<String> userList = new ArrayList<>();
  1240. if (users != null && users.size() > 0) {
  1241. for (SysUser user : users) {
  1242. userList.add(user.getId());
  1243. }
  1244. }
  1245. return userList;
  1246. }
  1247. /**
  1248. * @version
  1249. * @author: hxl
  1250. * @Date: 2024/6/30 18:05
  1251. * @Description: 查询推广费分页
  1252. */
  1253. @Override
  1254. public BasePageResult<ExportExpenditureTypeDetalsTGDto> findMyInsuranceTGByUserId(MyInsuranceTgQueryDto myInsuranceTgQueryDto) {
  1255. Page<ExportExpenditureTypeDetalsTGDto> page = new Page<>(myInsuranceTgQueryDto.getPageNum(),
  1256. myInsuranceTgQueryDto.getPageSize());
  1257. //赋值开始和结束时间
  1258. if (StringUtils.isNotBlank(myInsuranceTgQueryDto.getStartDate())) {
  1259. myInsuranceTgQueryDto.setStartDate(myInsuranceTgQueryDto.getStartDate() + " 00:00:00");
  1260. }
  1261. if (StringUtils.isNotBlank(myInsuranceTgQueryDto.getEndDate())) {
  1262. myInsuranceTgQueryDto.setEndDate(myInsuranceTgQueryDto.getEndDate() + " 23:59:59");
  1263. }
  1264. //如果是电销组长,统计电销组长和他组员的信息
  1265. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(myInsuranceTgQueryDto.getUserId());
  1266. SysUser user = sysUserService.getById(myInsuranceTgQueryDto.getUserId());
  1267. SysDept dept = sysDeptService.getById(user.getDeptId());
  1268. if ("72".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())) {
  1269. myInsuranceTgQueryDto.setGroupFlag(true);
  1270. }
  1271. Page<ExportExpenditureTypeDetalsTGDto> pageList = insFeeOrderNewService.findMyInsuranceTGByUserId(page, myInsuranceTgQueryDto);
  1272. BasePageResult<ExportExpenditureTypeDetalsTGDto> result = new BasePageResult<>(myInsuranceTgQueryDto.getPageNum(), myInsuranceTgQueryDto.getPageSize(), pageList.getTotal(),
  1273. pageList.getPages()
  1274. , pageList.getRecords());
  1275. return result;
  1276. }
  1277. /**
  1278. * @version
  1279. * @author: hxl
  1280. * @Date: 2024/6/30 18:05
  1281. * @Description: 查询车险导出数据
  1282. */
  1283. @Override
  1284. public List<ExportExpenditureTypeDetalsDto> exportMyInsuranceByUserId(MyInsuranceQueryDto myInsuranceQueryDto) {
  1285. List<String> userList = getStrings(myInsuranceQueryDto);
  1286. //赋值开始和结束时间
  1287. if (StringUtils.isNotBlank(myInsuranceQueryDto.getStartDate())) {
  1288. myInsuranceQueryDto.setStartDate(myInsuranceQueryDto.getStartDate() + " 00:00:00");
  1289. }
  1290. if (StringUtils.isNotBlank(myInsuranceQueryDto.getEndDate())) {
  1291. myInsuranceQueryDto.setEndDate(myInsuranceQueryDto.getEndDate() + " 23:59:59");
  1292. }
  1293. //如果是电销组长,统计电销组长和他组员的信息
  1294. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(myInsuranceQueryDto.getUserId());
  1295. SysUser user = sysUserService.getById(myInsuranceQueryDto.getUserId());
  1296. SysDept dept = sysDeptService.getById(user.getDeptId());
  1297. if ("72".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())) {
  1298. userList = sysUserService.getGroupByUserId(myInsuranceQueryDto.getUserId());
  1299. }
  1300. return insFeeOrderNewService.exportMyInsuranceByUserId(myInsuranceQueryDto, userList);
  1301. }
  1302. /**
  1303. * @version
  1304. * @author: hxl
  1305. * @Date: 2024/6/30 18:05
  1306. * @Description: 查询推广导出数据
  1307. */
  1308. @Override
  1309. public List<ExportExpenditureTypeDetalsTGDto> exportMyInsuranceTGByUserId(MyInsuranceTgQueryDto myInsuranceTgQueryDto) {
  1310. //赋值开始和结束时间
  1311. if (StringUtils.isNotBlank(myInsuranceTgQueryDto.getStartDate())) {
  1312. myInsuranceTgQueryDto.setStartDate(myInsuranceTgQueryDto.getStartDate() + " 00:00:00");
  1313. }
  1314. if (StringUtils.isNotBlank(myInsuranceTgQueryDto.getEndDate())) {
  1315. myInsuranceTgQueryDto.setEndDate(myInsuranceTgQueryDto.getEndDate() + " 23:59:59");
  1316. }
  1317. return insFeeOrderNewService.exportMyInsuranceTGByUserId(myInsuranceTgQueryDto);
  1318. }
  1319. /**
  1320. * @version
  1321. * @author: hxl
  1322. * @Date: 2024/7/1 9:02
  1323. * @Description: 查询收支明细数据
  1324. */
  1325. @Override
  1326. public MyIncomeAndExpensesNewPageVo<ExportExpenditureTypeDetalsSZDto> findMyIncomeAndExpensesNewByUserId(MyCollectInAdvanceQueryNewDto myCollectInAdvanceQueryNewDto) {
  1327. //校验数据
  1328. myCollectInAdvanceQueryNewDto = checkData(myCollectInAdvanceQueryNewDto);
  1329. Page<ExportExpenditureTypeDetalsSZDto> page = new Page<>(myCollectInAdvanceQueryNewDto.getPageNum(), myCollectInAdvanceQueryNewDto.getPageSize());
  1330. //判断如果是电销组长查询组员数据
  1331. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(myCollectInAdvanceQueryNewDto.getUserId());
  1332. SysUser user = sysUserService.getById(myCollectInAdvanceQueryNewDto.getUserId());
  1333. SysDept dept = sysDeptService.getById(user.getDeptId());
  1334. //如果是电销组长,将组员的数据算进来
  1335. if ("72".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())) {
  1336. myCollectInAdvanceQueryNewDto.setGroupFlag(true);
  1337. }
  1338. Page<ExportExpenditureTypeDetalsSZDto> orderVoPage = sysUserAccountHistoryService.findMyIncomeAndExpensesAmountNewByUserId(page, myCollectInAdvanceQueryNewDto);
  1339. List<ExportExpenditureTypeDetalsSZDto> recordsNew = new ArrayList<>();
  1340. //格式化数据
  1341. if (orderVoPage.getRecords() != null && orderVoPage.getRecords().size() > 0) {
  1342. for (ExportExpenditureTypeDetalsSZDto dto : orderVoPage.getRecords()) {
  1343. //车险的显示且收入
  1344. if ("1".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())) {
  1345. if ("4".equals(dto.getTransactionType())) {
  1346. dto.setTransactionType("1");
  1347. } else if ("3".equals(dto.getTransactionType())) {
  1348. dto.setTransactionType("2");
  1349. }
  1350. dto.setIncomeAndExpensesType("1");
  1351. //退款 且退款
  1352. } else if ("2".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())) {
  1353. dto.setIncomeAndExpensesType("1");
  1354. dto.setTransactionType("4");
  1355. //退款设置为空
  1356. dto.setAuditingStatus("");
  1357. //提现
  1358. } else if ("6".equals(dto.getTransactionType()) && "1".equals(dto.getIncomeAndExpensesType())) {
  1359. dto.setIncomeAndExpensesType("2");
  1360. dto.setTransactionType("3");
  1361. }
  1362. recordsNew.add(dto);
  1363. }
  1364. }
  1365. boolean b = feeDisplayService.setWithdrawalsPc(recordsNew);
  1366. orderVoPage.setRecords(recordsNew);
  1367. return new MyIncomeAndExpensesNewPageVo<>(myCollectInAdvanceQueryNewDto.getPageNum(), myCollectInAdvanceQueryNewDto.getPageSize(), orderVoPage.getTotal(),
  1368. orderVoPage.getPages()
  1369. , orderVoPage.getRecords(), b);
  1370. }
  1371. /**
  1372. * @version
  1373. * @author: hxl
  1374. * @Date: 2024/7/1 9:06
  1375. * @Description: 校验数据
  1376. */
  1377. private static MyCollectInAdvanceQueryNewDto checkData(MyCollectInAdvanceQueryNewDto myCollectInAdvanceQueryNewDto) {
  1378. if (StringUtils.isBlank(myCollectInAdvanceQueryNewDto.getUserId())) {
  1379. throw new SystemException("用户id-userId不能为空");
  1380. }
  1381. //判断时间类型 1.一周内 2. 一月内 3. 三月内 4. 三月内
  1382. HashMap<String, String> dateMap = getDateMapByType(myCollectInAdvanceQueryNewDto.getDateQueryType(), myCollectInAdvanceQueryNewDto.getStartDate(), myCollectInAdvanceQueryNewDto.getEndDate());
  1383. myCollectInAdvanceQueryNewDto.setStartDate(dateMap.get("startDate"));
  1384. myCollectInAdvanceQueryNewDto.setEndDate(dateMap.get("endDate"));
  1385. if ("0".equals(myCollectInAdvanceQueryNewDto.getBusinessSegmentsType())) {
  1386. myCollectInAdvanceQueryNewDto.setBusinessSegmentsType(null);
  1387. }
  1388. if ("0".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1389. myCollectInAdvanceQueryNewDto.setTransactionType(null);
  1390. }
  1391. if ("0".equals(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType())) {
  1392. myCollectInAdvanceQueryNewDto.setIncomeAndExpensesType(null);
  1393. }
  1394. // 1为车险板块 1 收入时
  1395. if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getBusinessSegmentsType()) && StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType()) && "1".equals(myCollectInAdvanceQueryNewDto.getBusinessSegmentsType()) && "1".equals(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType())) {
  1396. //判断收入类型 1 收入
  1397. if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getTransactionType()) && "3".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1398. throw new SystemException("收入类型不能选择提现类型");
  1399. }
  1400. }
  1401. if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType()) && "2".equals(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType())) {
  1402. //判断支出类型
  1403. if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getTransactionType()) && !"3".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1404. throw new SystemException("支出类型不能选择(手续+跟单)或者手续费、退款类型");
  1405. }
  1406. }
  1407. if ((StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getBusinessSegmentsType()) && StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType()) && "2".equals(myCollectInAdvanceQueryNewDto.getBusinessSegmentsType()) && "1".equals(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType()))
  1408. ||
  1409. (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType()) && ("2".equals(myCollectInAdvanceQueryNewDto.getBusinessSegmentsType())))) {
  1410. //判断退款类型
  1411. if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getTransactionType()) && !"4".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1412. throw new SystemException("退款板块只能选择退款类型");
  1413. }
  1414. }
  1415. //处理 手续费+跟单、推广费类型转换
  1416. if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getTransactionType()) && "2".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1417. myCollectInAdvanceQueryNewDto.setTransactionType("3");
  1418. } else if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getTransactionType()) && "1".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1419. myCollectInAdvanceQueryNewDto.setTransactionType("4");
  1420. } else if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getTransactionType()) && "4".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1421. myCollectInAdvanceQueryNewDto.setTransactionType("5");
  1422. } else if (StringUtils.isNotBlank(myCollectInAdvanceQueryNewDto.getTransactionType()) && "3".equals(myCollectInAdvanceQueryNewDto.getTransactionType())) {
  1423. myCollectInAdvanceQueryNewDto.setTransactionType("6");
  1424. }
  1425. //处理收入和支出类型转换
  1426. if (myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType() != null && "0".equals(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType())) {
  1427. myCollectInAdvanceQueryNewDto.setIncomeAndExpensesType(null);
  1428. } else if (myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType() != null && "1".equals(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType())) {
  1429. myCollectInAdvanceQueryNewDto.setIncomeAndExpensesType("2");
  1430. } else if (myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType() != null && "2".equals(myCollectInAdvanceQueryNewDto.getIncomeAndExpensesType())) {
  1431. myCollectInAdvanceQueryNewDto.setIncomeAndExpensesType("1");
  1432. }
  1433. return myCollectInAdvanceQueryNewDto;
  1434. }
  1435. /**
  1436. * @version
  1437. * @author: hxl
  1438. * @Date: 2024/7/1 9:03
  1439. * @Description: 查询导出收支明细
  1440. */
  1441. @Override
  1442. public List<ExportExpenditureTypeDetalsSZDto> exportMyIncomeAndExpensesNewByUserId(MyCollectInAdvanceQueryNewDto myCollectInAdvanceQueryNewDto) {
  1443. //校验数据
  1444. myCollectInAdvanceQueryNewDto = checkData(myCollectInAdvanceQueryNewDto);
  1445. String userId = myCollectInAdvanceQueryNewDto.getUserId();
  1446. //添加预收明细 如果是渠道团队长查询管理下级的出单员
  1447. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(userId);
  1448. SysUser user = sysUserService.getById(userId);
  1449. SysDept dept = sysDeptService.getById(user.getDeptId());
  1450. //如果是电销组长,将组员的数据算进来
  1451. if ("72".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())) {
  1452. myCollectInAdvanceQueryNewDto.setGroupFlag(true);
  1453. }
  1454. //查询数据
  1455. List<ExportExpenditureTypeDetalsSZDto> list = sysUserAccountHistoryService.exportMyIncomeAndExpensesAmountNewByUserId(myCollectInAdvanceQueryNewDto);
  1456. List<ExportExpenditureTypeDetalsSZDto> recordsNew = new ArrayList<>();
  1457. //格式化数据
  1458. if (list != null && list.size() > 0) {
  1459. for (ExportExpenditureTypeDetalsSZDto dto : list) {
  1460. //车险的显示且收入
  1461. if ("1".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())) {
  1462. if ("4".equals(dto.getTransactionType())) {
  1463. dto.setTransactionType("手续费+跟单");
  1464. } else if ("3".equals(dto.getTransactionType())) {
  1465. dto.setTransactionType("推广");
  1466. }
  1467. dto.setIncomeAndExpensesType("收入");
  1468. dto.setBusinessSegmentsType("车险");
  1469. //退款 且退款
  1470. } else if ("2".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())) {
  1471. dto.setIncomeAndExpensesType("收入");
  1472. dto.setTransactionType("退款");
  1473. //退款设置为空
  1474. dto.setAuditingStatus("");
  1475. dto.setBusinessSegmentsType("退款");
  1476. //提现
  1477. } else if ("6".equals(dto.getTransactionType()) && "1".equals(dto.getIncomeAndExpensesType())) {
  1478. dto.setIncomeAndExpensesType("支出");
  1479. dto.setTransactionType("提现");
  1480. dto.setBusinessSegmentsType("车险");
  1481. }
  1482. recordsNew.add(dto);
  1483. }
  1484. }
  1485. return recordsNew;
  1486. }
  1487. /**
  1488. * @version
  1489. * @author: hxl
  1490. * @Date: 2024/6/30 18:55
  1491. * @Description: 查询页面总金额
  1492. */
  1493. @Override
  1494. public MySumAmountDto findMyAmount(MySumAmountQueryDto mySumAmountQueryDto) {
  1495. //赋值开始和结束时间
  1496. if (StringUtils.isNotBlank(mySumAmountQueryDto.getStartDate())) {
  1497. mySumAmountQueryDto.setStartDate(mySumAmountQueryDto.getStartDate() + " 00:00:00");
  1498. }
  1499. if (StringUtils.isNotBlank(mySumAmountQueryDto.getEndDate())) {
  1500. mySumAmountQueryDto.setEndDate(mySumAmountQueryDto.getEndDate() + " 23:59:59");
  1501. }
  1502. String userId = mySumAmountQueryDto.getUserId();
  1503. //添加预收明细 如果是渠道团队长查询管理下级的出单员
  1504. SysUserBaseVO sysUserBaseVO = sysUserService.selectUserById(userId);
  1505. SysUser user = sysUserService.getById(userId);
  1506. SysDept dept = sysDeptService.getById(user.getDeptId());
  1507. String deptId = "";
  1508. //出单员是19 且是渠道的话,给渠道团队长
  1509. if ("21".equals(sysUserBaseVO.getRoleId()) && "1".equals(dept.getManagementSource())) {
  1510. deptId = dept.getId();
  1511. mySumAmountQueryDto.setDeptId(deptId);
  1512. }
  1513. //如果是电销组长,将组员的数据算进来
  1514. if ("72".equals(sysUserBaseVO.getRoleId()) && "3".equals(dept.getManagementSource())) {
  1515. mySumAmountQueryDto.setGroupFlag(true);
  1516. }
  1517. //查询预收和实收的总金额
  1518. mySumAmountQueryDto.setAuditstatus("0");
  1519. BigDecimal ysAmount = insFeeOrderNewService.findMyAmountYSOrSSCXAmount(mySumAmountQueryDto);
  1520. mySumAmountQueryDto.setAuditstatus("1");
  1521. BigDecimal ssAmount = insFeeOrderNewService.findMyAmountYSOrSSCXAmount(mySumAmountQueryDto);
  1522. BigDecimal ysAndSsAmount = ysAmount.add(ssAmount);
  1523. mySumAmountQueryDto.setAuditstatus("0");
  1524. BigDecimal ysTGAmount = insFeeOrderNewService.findMyAmountYSOrSSTGAmount(mySumAmountQueryDto);
  1525. mySumAmountQueryDto.setAuditstatus("1");
  1526. BigDecimal ssTGAmount = insFeeOrderNewService.findMyAmountYSOrSSTGAmount(mySumAmountQueryDto);
  1527. BigDecimal ysAndSsTGAmount = ysTGAmount.add(ssTGAmount);
  1528. // 已提现金额 查询历史表中的审核状态为3的数据
  1529. BigDecimal ysTXAmount = insFeeOrderNewService.findMyAmountYTXmount(mySumAmountQueryDto.getUserId(), "3",mySumAmountQueryDto.getGroupFlag());
  1530. // 可提现金额 查询账户的钱
  1531. mySumAmountQueryDto.setAuditstatus("1");
  1532. SysUserAccount sysUserAccountEntity = baseMapper.getById(mySumAmountQueryDto.getUserId());
  1533. // 提现中
  1534. BigDecimal txzTXAmount = insFeeOrderNewService.findMyAmountYTXmount(mySumAmountQueryDto.getUserId(), "2",mySumAmountQueryDto.getGroupFlag());
  1535. // 可提现
  1536. BigDecimal ssKTAmount = BigDecimal.ZERO;
  1537. //if(mySumAmountQueryDto.getGroupFlag()){
  1538. // ssKTAmount = baseMapper.getGroupById(mySumAmountQueryDto.getUserId());
  1539. //}else {
  1540. if (sysUserAccountEntity != null) {
  1541. ssKTAmount = sysUserAccountEntity.getSumAmount() == null ? BigDecimal.ZERO : sysUserAccountEntity.getSumAmount();
  1542. }
  1543. //}
  1544. //总的 = 已提现金额+ 可提现金额 + 提现中
  1545. BigDecimal sumAmount = ysTXAmount.add(ssKTAmount).add(txzTXAmount);
  1546. return new MySumAmountDto(ysAmount, ssAmount, ysAndSsAmount, ysTGAmount, ssTGAmount, ysAndSsTGAmount, ysTXAmount, ssKTAmount, sumAmount, txzTXAmount);
  1547. }
  1548. /**
  1549. * @version
  1550. * @author: hxl
  1551. * @Date: 2024/9/12 9:46
  1552. * @Description: 判断渠道金额
  1553. */
  1554. private void judgeAmount(BigDecimal amount, String userId) {
  1555. if (amount == null) {
  1556. throw new SystemException("提现金额不能为空");
  1557. } else if (amount.compareTo(BigDecimal.ZERO) <= 0) {
  1558. throw new SystemException("提现金额不能小于0");
  1559. }
  1560. SysUser sysUser = sysUserMapper.selectById(userId);
  1561. SysDept dept = sysDeptService.getById(sysUser.getDeptId());
  1562. //渠道
  1563. if("1".equals(dept.getManagementSource())){
  1564. BigDecimal remainder = amount.remainder(new BigDecimal("100"));
  1565. if(remainder.compareTo(BigDecimal.ZERO) > 0){
  1566. throw new SystemException("提现金额必须为100的倍数");
  1567. }
  1568. }
  1569. }
  1570. }