SysUserAccountServiceImpl.java 94 KB

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