SysUserAccountServiceImpl.java 91 KB

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