| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166 |
- package com.ydtech.modules.admin.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.core.page.PageRequest;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.admin.constants.MoneyAttrConstants;
- import com.ydtech.modules.admin.constants.WithdrawTypeConstants;
- import com.ydtech.modules.admin.dao.SysUserAccountMapper;
- import com.ydtech.modules.admin.model.SysUser;
- import com.ydtech.modules.admin.model.dto.*;
- import com.ydtech.modules.admin.model.po.*;
- import com.ydtech.modules.admin.model.vo.SubOrder;
- import com.ydtech.modules.admin.model.vo.SysUserAccountVo;
- import com.ydtech.modules.admin.service.*;
- import com.ydtech.modules.admin.utils.SliceUpDateUtil;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.esm.service.EsmUserReferrerService;
- import com.ydtech.modules.message.constants.MessageTypeConstants;
- import com.ydtech.modules.message.service.MessageSecretaryService;
- import com.ydtech.modules.order.dao.InsAreaCompanyMapper;
- import com.ydtech.modules.order.dao.InsOrdersMapper;
- import com.ydtech.modules.order.entity.BasePageResult;
- import com.ydtech.modules.order.entity.InsOrders;
- import com.ydtech.modules.order.service.InsAreaCompanyService;
- import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
- import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
- import org.apache.commons.lang3.ObjectUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.CollectionUtils;
- import java.math.BigDecimal;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @author Administrator
- * @description 针对表【sys_user_account(用户账户表)】的数据库操作Service实现
- * @createDate 2024-03-05 11:52:30
- */
- @Service
- public class SysUserAccountServiceImpl extends ServiceImpl<SysUserAccountMapper, SysUserAccount> implements SysUserAccountService {
- @Autowired
- private SysUserAccountHistoryService sysUserAccountHistoryService;
- @Autowired
- private SysUserAccountService sysUserAccountService;
- @Autowired
- private EsmUserReferrerService esmUserReferrerService;
- @Autowired
- private SysAmountAuditingService sysAmountAuditingService;
- @Autowired
- private SysUserBankCardService sysUserBankCardService;
- @Autowired
- private InsAreaCompanyService insAreaCompanyService;
- @Autowired
- private InsFeeOrderNewService insFeeOrderNewService;
- @Autowired
- private InsOrdersMapper insOrdersMapper;
- @Autowired
- private MessageSecretaryService messageSecretaryService;
- @Autowired
- private InsAreaCompanyMapper insAreaCompanyMapper;
- @Autowired
- private SysUserService sysUserService;
- @Autowired
- private SysAmountAuditingHistoryService sysAmountAuditingHistoryService;
- @Override
- @Transactional
- public void addOrUpdate(SysUserAccount sysUserAccount) {
- //SysUserAccount newSysAccount = baseMapper.getById(sysUserAccount.getUserId());
- // 初始化
- if (sysUserAccount.getHandlingFee() == null) {
- sysUserAccount.setHandlingFee(BigDecimal.ZERO);
- }
- if (sysUserAccount.getDocumentary() == null) {
- sysUserAccount.setDocumentary(BigDecimal.ZERO);
- }
- if (sysUserAccount.getPromotion() == null) {
- sysUserAccount.setPromotion(BigDecimal.ZERO);
- }
- //添加总金额 = 手续费+跟单费+推广费
- BigDecimal sumAmount=BigDecimal.ZERO;
- sumAmount= sumAmount.add(sysUserAccount.getHandlingFee()==null?BigDecimal.ZERO:sysUserAccount.getHandlingFee())
- .add(sysUserAccount.getDocumentary()==null?BigDecimal.ZERO:sysUserAccount.getDocumentary())
- .add(sysUserAccount.getPromotion()==null?BigDecimal.ZERO:sysUserAccount.getPromotion());
- // 如果用户id有值则累加 没有则 新增
- String userId = sysUserAccount.getUserId();
- SysUserAccount sysUserAccountEntity = baseMapper.getById(userId);
- //SysUserAccount newAccount = new SysUserAccount();
- if (ObjectUtils.isNotEmpty(sysUserAccountEntity)) {
- sysUserAccountEntity.setHandlingFee(sysUserAccount.getHandlingFee().add(sysUserAccountEntity.getHandlingFee()));
- sysUserAccountEntity.setDocumentary(sysUserAccount.getDocumentary().add(sysUserAccountEntity.getDocumentary()));
- sysUserAccountEntity.setPromotion(sysUserAccount.getPromotion().add(sysUserAccountEntity.getPromotion()));
- if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
- sysUserAccountEntity.setDocumentaryStatus(sysUserAccount.getDocumentaryStatus());
- }
- // add by hxl 2024-06-18 插入总金额
- sysUserAccountEntity.setSumAmount((sysUserAccountEntity.getSumAmount()==null?BigDecimal.ZERO:sysUserAccountEntity.getSumAmount()).add(sumAmount));
- baseMapper.updateById(sysUserAccountEntity);
- } else {
- sysUserAccountEntity = new SysUserAccount();
- sysUserAccountEntity.setUserId(userId);
- sysUserAccountEntity.setDocumentary(sysUserAccount.getDocumentary());
- sysUserAccountEntity.setPromotion(sysUserAccount.getPromotion());
- sysUserAccountEntity.setHandlingFee(sysUserAccount.getHandlingFee());
- BigDecimal zero = BigDecimal.ZERO;
- sysUserAccountEntity.setHandlingAmountAccount(zero);
- sysUserAccountEntity.setHandlingAmountWithdrawal(zero);
- sysUserAccountEntity.setHandlingAmountPayment(zero);
- sysUserAccountEntity.setDocumentaryAmountAccount(zero);
- sysUserAccountEntity.setDocumentaryAmountWithdrawal(zero);
- sysUserAccountEntity.setDocumentaryAmountpayment(zero);
- sysUserAccountEntity.setPromotionAmountWithdrawal(zero);
- sysUserAccountEntity.setPromotionAmountAccount(zero);
- sysUserAccountEntity.setPromotionAmountPayment(zero);
- sysUserAccountEntity.setSumAmount(zero);
- sysUserAccountEntity.setSumAmountWithdrawal(zero);
- sysUserAccountEntity.setSumAmountAccount(zero);
- sysUserAccountEntity.setSumAmountPayment(zero);
- sysUserAccountEntity.setCreateTime(new Date());
- if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
- sysUserAccountEntity.setDocumentaryStatus(sysUserAccount.getDocumentaryStatus());
- }
- // add by hxl 2024-06-18 插入总金额
- sysUserAccountEntity.setSumAmount((sysUserAccountEntity.getSumAmount()==null?BigDecimal.ZERO:sysUserAccountEntity.getSumAmount()).add(sumAmount));
- baseMapper.insert(sysUserAccountEntity);
- }
- StringBuilder commissionMessage = new StringBuilder();
- BigDecimal beforeAmount;
- BigDecimal afterAmount;
- if (StringUtils.isNotEmpty(sysUserAccount.getDocumentaryStatus())) {
- //提现前的金额
- beforeAmount = sysUserAccountEntity.getSumAmount()==null?BigDecimal.ZERO:sysUserAccountEntity.getSumAmount();
- // 判断是否是一级二级三级
- SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory();
- sysUserAccountHistory.setUserId(sysUserAccount.getUserId());
- sysUserAccountHistory.setDocumentary(Integer.valueOf(sysUserAccount.getDocumentaryStatus()));
- sysUserAccountHistory.setSuborder(sysUserAccount.getSuborderId());
- sysUserAccountHistory.setCreateTime(new Date());
- //跟单费
- if (sysUserAccount.getDocumentary() != null && sysUserAccount.getDocumentary().compareTo(BigDecimal.ZERO) != 0) {
- sysUserAccountHistory.setAmount(sysUserAccount.getDocumentary());
- sysUserAccountHistory.setProperty(MoneyAttrConstants.M_2.getCode());
- commissionMessage.append(MoneyAttrConstants.M_2.getDesc() + ":" + sysUserAccount.getDocumentary() + "元 ");
- if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
- sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getDocumentary());
- }
- sysUserAccountHistory.setBusinessSegmentsType(1);
- sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
- }
- //手续费
- if (sysUserAccount.getHandlingFee() != null && sysUserAccount.getHandlingFee().compareTo(BigDecimal.ZERO) != 0) {
- sysUserAccountHistory.setId(null);
- sysUserAccountHistory.setAmount(sysUserAccount.getHandlingFee());
- sysUserAccountHistory.setProperty(MoneyAttrConstants.M_1.getCode());
- commissionMessage.append(MoneyAttrConstants.M_1.getDesc() + ":" + sysUserAccount.getHandlingFee() + "元 ");
- if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
- sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getHandlingFee());
- }
- sysUserAccountHistory.setBusinessSegmentsType(1);
- sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
- }
- //推广费
- if (sysUserAccount.getPromotion() != null && sysUserAccount.getPromotion().compareTo(BigDecimal.ZERO) != 0) {
- sysUserAccountHistory.setId(null);
- sysUserAccountHistory.setAmount(sysUserAccount.getPromotion());
- sysUserAccountHistory.setProperty(MoneyAttrConstants.M_3.getCode());
- commissionMessage.append(MoneyAttrConstants.M_3.getDesc() + ":" + sysUserAccount.getPromotion() + "元 ");
- if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
- //提现后的金额
- afterAmount = beforeAmount.subtract(sysUserAccount.getPromotion());
- sysUserAccountHistory.setSurplusAmount(afterAmount); //改变后金额
- sysUserAccountHistory.setUserAmount(beforeAmount); //改变前金额
- }
- sysUserAccountHistory.setBusinessSegmentsType(1);
- sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
- }
- //手续费+跟单费用
- BigDecimal amount_SX_GD=BigDecimal.ZERO;
- amount_SX_GD= amount_SX_GD.add(sysUserAccount.getHandlingFee()==null?BigDecimal.ZERO:sysUserAccount.getHandlingFee())
- .add(sysUserAccount.getDocumentary()==null?BigDecimal.ZERO:sysUserAccount.getDocumentary());
- //历史记录表添加手续费+跟单费用 add by hxl 2024-06-18
- if(amount_SX_GD.compareTo(BigDecimal.ZERO) != 0){
- sysUserAccountHistory.setId(null);
- sysUserAccountHistory.setAmount(amount_SX_GD);
- sysUserAccountHistory.setProperty(MoneyAttrConstants.M_4.getCode());
- if (WithdrawTypeConstants.WT_2.getCode().equals(sysUserAccount.getDocumentaryStatus())) { // 收入 相加
- afterAmount = beforeAmount.subtract(amount_SX_GD);
- sysUserAccountHistory.setSurplusAmount(afterAmount); //改变后金额
- sysUserAccountHistory.setUserAmount(beforeAmount); //改变前金额
- sysUserAccountHistory.setSurplusAmount(sysUserAccountEntity.getSumAmount());
- sysUserAccountHistory.setBusinessSegmentsType(1);
- sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
- }
- }
- }
- //添加佣金消息
- messageSecretaryService.addMessage(MessageTypeConstants.M_5,sysUserAccount.getUserId(),"你有一条佣金消息," + commissionMessage.toString());
- }
- @Override
- public BasePageResult<SysUserAccount> queryByVo(SysUserAccountVo sysUserAccountVo) {
- Page<SysUserAccount> page = new Page<>(sysUserAccountVo.getPageNum(), sysUserAccountVo.getPageSize());
- Page<SysUserAccount> sysUserAccountHistoryPage = baseMapper.queryPageOrder(sysUserAccountVo, page);
- return new BasePageResult<>(sysUserAccountVo.getPageNum(), page.getSize(), sysUserAccountHistoryPage.getTotal(), page.getPages(),
- sysUserAccountHistoryPage.getRecords());
- }
- //
- @Override
- public IPage<SysUserAccount> queryByVo1(SysUserAccountVo sysUserAccountVo) {
- PageRequest pageRequest = new PageRequest();
- pageRequest.setPageNum(sysUserAccountVo.getPageNum());
- pageRequest.setPageSize(sysUserAccountVo.getPageSize());
- List<SysUserAccount> sysUserAccountHistoryPage = baseMapper.queryPageOrder1(sysUserAccountVo);
- IPage ipage = PageRequest.buildPageRequest(pageRequest);
- ipage.setRecords(sysUserAccountHistoryPage.stream().skip((sysUserAccountVo.getPageNum() - 1) * sysUserAccountVo.getPageSize()).limit(sysUserAccountVo.getPageSize()).
- collect(Collectors.toList()));
- ipage.setTotal(sysUserAccountHistoryPage.size());
- return ipage;
- }
- @Override
- @Transactional
- public HttpResult<Object> inert(SysUserAccountVo sysUserAccountVo) {
- String userId = BaseController.getUser().getId();
- BigDecimal zero = BigDecimal.ZERO;
- BigDecimal beforeAmount;
- BigDecimal afterAmount;
- // 用户当前金额
- BigDecimal amount = sysUserAccountVo.getAmount();
- SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory(); // 记录
- sysUserAccountHistory.setDocumentary(1); // 1提现
- sysUserAccountHistory.setUserId(userId);
- sysUserAccountHistory.setProperty(6);
- sysUserAccountHistory.setBusinessSegmentsType(1);
- SysAmountAuditingEntity sysAmountAuditingEntity = new SysAmountAuditingEntity();//审核记录表
- sysAmountAuditingEntity.setUserId(userId);
- sysAmountAuditingEntity.setAmount(sysUserAccountVo.getAmount());
- sysUserAccountHistory.setCreateTime(new Date());
- // SysAmountAuditingEntity judge = sysAmountAuditingService.getByUserId(userId, sysUserAccountVo.getAmountStatus());
- // if (ObjectUtils.isNotEmpty(judge)) {
- // return HttpResult.ok("有未提现审核单据, 请审核完成之后再提现");
- // }
- // 通过银行卡id 查询卡包
- String fromBankCardId = sysUserAccountVo.getFromBankCardId();
- if (fromBankCardId != null) {
- // SysUserBankCard byId = sysUserBankCardService.getById(fromBankCardId);
- SysUserBankCard byId = sysUserBankCardService.getByBankNumber(fromBankCardId);
- if (byId == null) {
- throw new SystemException("该卡未绑定此账号,或输入卡号错误,或该账号尚未审核通过,请检查");
- }
- byId.setIsDefault(1);
- sysAmountAuditingEntity.setBankNumber(byId.getBankNumber());
- sysUserAccountHistory.setFromBankCard(byId.getBankNumber());
- sysUserBankCardService.updateById(byId);
- }
- if (StringUtils.isNotEmpty(userId)) {
- SysUserAccount sysUserAccount = baseMapper.getById(userId);
- //if (StringUtils.isNotEmpty(sysUserAccountVo.getAmountStatus())) {
- //sysUserAccountHistory.setProperty(Integer.valueOf(sysUserAccountVo.getAmountStatus())); //金额类型
- /**
- if ("1".equals(sysUserAccountVo.getAmountStatus())) {
- // 用户当前费用金
- beforeAmount = sysUserAccount.getHandlingFee();
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setHandlingFee(afterAmount);
- sysUserAccount.setHandlingAmountPayment(sysUserAccount.getHandlingAmountPayment().add(amount));
- sysUserAccount.setHandlingAmountWithdrawal(sysUserAccount.getHandlingAmountWithdrawal().add(amount));
- } else if ("2".equals(sysUserAccountVo.getAmountStatus())) {
- // 用户当前 非跟单佣金
- beforeAmount = sysUserAccount.getDocumentary();
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setDocumentary(afterAmount);
- sysUserAccount.setDocumentaryAmountpayment(sysUserAccount.getDocumentaryAmountpayment().add(amount));
- sysUserAccount.setDocumentaryAmountWithdrawal(sysUserAccount.getDocumentaryAmountWithdrawal().add(amount));
- } else {
- beforeAmount = sysUserAccount.getPromotion();
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setPromotion(afterAmount);
- sysUserAccount.setPromotionAmountPayment(sysUserAccount.getPromotionAmountPayment().add(amount));
- sysUserAccount.setPromotionAmountWithdrawal(sysUserAccount.getPromotionAmountWithdrawal().add(amount));
- }
- **/
- //提现前的金额
- beforeAmount = sysUserAccount.getSumAmount()==null?BigDecimal.ZERO:sysUserAccount.getSumAmount();
- //提现后的金额
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setSumAmount(afterAmount);
- //支付中总金额 = 原先的支付金额 + 提现的金额
- sysUserAccount.setSumAmountPayment((sysUserAccount.getSumAmountPayment()==null?BigDecimal.ZERO:sysUserAccount.getSumAmountPayment()).add(amount));
- //提现的总金额 = 原先的提现总金额 + 提现的金额
- sysUserAccount.setSumAmountWithdrawal((sysUserAccount.getSumAmountWithdrawal()==null?BigDecimal.ZERO:sysUserAccount.getSumAmountWithdrawal().add(amount)));
- // 用户相差
- if (beforeAmount.compareTo(zero) == 0 || afterAmount.compareTo(zero) < 0) {
- return HttpResult.ok("余额不足");
- }
- sysUserAccountHistory.setAmount(amount); // 金额
- sysUserAccountHistory.setSurplusAmount(afterAmount); // 剩余金额
- sysUserAccountHistory.setUserAmount(beforeAmount); // 用户剩余金额
- sysAmountAuditingEntity.setCreateTime(new Date());
- sysAmountAuditingEntity.setAuditingStatus("2"); // 2 为待审核 3 审核通过
- // sysAmountAuditingEntity.setAmountStatus(sysUserAccountVo.getAmountStatus());
- // 新增金额记录
- sysAmountAuditingService.save(sysAmountAuditingEntity);
- sysUserAccountHistory.setAuditiingId(sysAmountAuditingEntity.getId());
- sysUserAccountService.updateById(sysUserAccount);
- sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
- // }
- // 提现审核插入轨迹表 待审核数据 和审核处理中的数据
- // Calendar calendar = Calendar.getInstance();
- Date date = new Date();
- //calendar.add(Calendar.MINUTE, 1);
- // Date afterDate = calendar.getTime();
- SysAmountAuditingHistory sysAmountAuditingHistory =new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId,date,"1", "1",sysUserAccountHistory.getId());
- SysAmountAuditingHistory sysAmountAuditingHistoryTwo =new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId,date, "2", "1",sysUserAccountHistory.getId());
- sysAmountAuditingHistoryService.save(sysAmountAuditingHistory);
- sysAmountAuditingHistoryService.save(sysAmountAuditingHistoryTwo);
- }
- return HttpResult.ok("提现成功,等待审核");
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/18 17:30
- * @Description: 提现修改为总金额
- */
- @Override
- @Transactional
- public HttpResult withdraw(SysUserAccountVo sysUserAccountVo) {
- String userId = sysUserAccountVo.getUserId();
- BigDecimal zero = BigDecimal.ZERO;
- BigDecimal beforeAmount;
- BigDecimal afterAmount;
- // 用户当前金额
- BigDecimal amount = sysUserAccountVo.getAmount();
- SysUserAccountHistory sysUserAccountHistory = new SysUserAccountHistory(); // 记录
- sysUserAccountHistory.setDocumentary(1); // 1支出
- sysUserAccountHistory.setUserId(userId);
- sysUserAccountHistory.setProperty(6); //3提现
- sysUserAccountHistory.setBusinessSegmentsType(1);
- SysAmountAuditingEntity sysAmountAuditingEntity = new SysAmountAuditingEntity();//审核记录表
- sysAmountAuditingEntity.setUserId(userId);
- sysAmountAuditingEntity.setAmount(sysUserAccountVo.getAmount());
- sysUserAccountHistory.setCreateTime(new Date());
- // SysAmountAuditingEntity judge = sysAmountAuditingService.getByUserId(userId, sysUserAccountVo.getAmountStatus());
- // if (ObjectUtils.isNotEmpty(judge)) {
- // throw new SystemException("有未提现审核单据, 请审核完成之后再提现");
- // }
- // 通过银行卡id 查询卡包
- String fromBankCardId = sysUserAccountVo.getFromBankCardId();
- SysUserBankCard byId = sysUserBankCardService.getByBankNumber(fromBankCardId);
- if (byId == null) {
- throw new SystemException("该卡未绑定此账号,或输入卡号错误,或该账号尚未审核通过,请检查");
- }
- if (fromBankCardId != null && byId.getUserId().equals(userId)) {
- byId.setIsDefault(1);
- sysAmountAuditingEntity.setBankNumber(byId.getBankNumber());
- sysUserAccountHistory.setFromBankCard(byId.getBankNumber());
- sysUserBankCardService.updateById(byId);
- }
- if (StringUtils.isNotEmpty(userId)) {
- SysUserAccount sysUserAccount = baseMapper.getById(userId);
- //if (StringUtils.isNotEmpty(sysUserAccountVo.getAmountStatus())) {
- //sysUserAccountHistory.setProperty(Integer.valueOf(sysUserAccountVo.getAmountStatus())); //金额类型
- //注释掉类型提现,直接提现总金额
- /**
- if ("1".equals(sysUserAccountVo.getAmountStatus())) {
- // 用户当前费用金
- beforeAmount = sysUserAccount.getHandlingFee();
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setHandlingFee(afterAmount);
- sysUserAccount.setHandlingAmountPayment(sysUserAccount.getHandlingAmountPayment().add(amount));
- sysUserAccount.setHandlingAmountWithdrawal(sysUserAccount.getHandlingAmountWithdrawal().add(amount));
- } else if ("2".equals(sysUserAccountVo.getAmountStatus())) {
- // 用户当前 非跟单佣金
- beforeAmount = sysUserAccount.getDocumentary();
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setDocumentary(afterAmount);
- sysUserAccount.setDocumentaryAmountpayment(sysUserAccount.getDocumentaryAmountpayment().add(amount));
- sysUserAccount.setDocumentaryAmountWithdrawal(sysUserAccount.getDocumentaryAmountWithdrawal().add(amount));
- } else {
- beforeAmount = sysUserAccount.getPromotion();
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setPromotion(afterAmount);
- sysUserAccount.setPromotionAmountPayment(sysUserAccount.getPromotionAmountPayment().add(amount));
- sysUserAccount.setPromotionAmountWithdrawal(sysUserAccount.getPromotionAmountWithdrawal().add(amount));
- }
- **/
- //提现前的金额
- beforeAmount = sysUserAccount.getSumAmount()==null?BigDecimal.ZERO:sysUserAccount.getSumAmount();
- //提现后的金额
- afterAmount = beforeAmount.subtract(amount);
- sysUserAccount.setSumAmount(afterAmount);
- //支付中总金额 = 原先的支付金额 + 提现的金额
- sysUserAccount.setSumAmountPayment((sysUserAccount.getSumAmountPayment()==null?BigDecimal.ZERO:sysUserAccount.getSumAmountPayment()).add(amount));
- //提现的总金额 = 原先的提现总金额 + 提现的金额
- sysUserAccount.setSumAmountWithdrawal((sysUserAccount.getSumAmountWithdrawal()==null?BigDecimal.ZERO:sysUserAccount.getSumAmountWithdrawal().add(amount)));
- // 用户相差
- if (beforeAmount.compareTo(zero) == 0 || afterAmount.compareTo(zero) < 0) {
- return HttpResult.error("余额不足");
- }
- sysUserAccountHistory.setAmount(amount); // 金额
- sysUserAccountHistory.setSurplusAmount(afterAmount); // 剩余金额
- sysUserAccountHistory.setUserAmount(beforeAmount); // 用户剩余金额
- sysAmountAuditingEntity.setCreateTime(new Date());
- sysAmountAuditingEntity.setAuditingStatus("2"); // 2 为待审核 3 审核通过
- sysAmountAuditingEntity.setAmountStatus(sysUserAccountVo.getAmountStatus());
- // 新增金额记录
- sysAmountAuditingService.save(sysAmountAuditingEntity);
- sysUserAccountHistory.setAuditiingId(sysAmountAuditingEntity.getId());
- sysUserAccountService.updateById(sysUserAccount);
- sysUserAccountHistoryService.updayteByUserAccount(sysUserAccountHistory);
- //}
- // 提现审核插入轨迹表 待审核数据 和审核处理中的数据
- Calendar calendar = Calendar.getInstance();
- Date date = calendar.getTime();
- calendar.add(Calendar.MINUTE, 1);
- Date afterDate = calendar.getTime();
- SysAmountAuditingHistory sysAmountAuditingHistory =new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId,date,"1", "1",sysUserAccountHistory.getId());
- SysAmountAuditingHistory sysAmountAuditingHistoryTwo =new SysAmountAuditingHistory(null, sysAmountAuditingEntity.getId(), amount, userId,afterDate, "2", "1",sysUserAccountHistory.getId());
- sysAmountAuditingHistoryService.save(sysAmountAuditingHistory);
- sysAmountAuditingHistoryService.save(sysAmountAuditingHistoryTwo);
- }
- return HttpResult.ok("提现成功,等待审核");
- }
- @Override
- public SysUserAccount getSysUserAmount(String userid) {
- SysUserAccount sysUserAccount = baseMapper.getById(userid);
- return sysUserAccount;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/11 16:05
- * @Description: 注释掉实收的总金额提升查询效率
- */
- @Override
- public SysUserAccountVo getSysAllAmount(String userId) {
- SysUserAccountVo sysUserAccountVo = new SysUserAccountVo();
- SysUserAccount sysUserAccount = baseMapper.getById(userId);
- // 验证账户信息是否有值
- if (ObjectUtils.isEmpty(sysUserAccount)) {
- return sysUserAccountVo;
- }
- BeanUtils.copyProperties(sysUserAccount, sysUserAccountVo);
- BigDecimal willHalding = BigDecimal.ZERO; //预收手续费佣金
- BigDecimal willDocumentary = BigDecimal.ZERO; //预收 非跟单佣金
- BigDecimal willPromotion = BigDecimal.ZERO; //预收 推广
- //BigDecimal receivedWillHalding = BigDecimal.ZERO; //实收手续费佣金
- // BigDecimal receivedWillDocumentary = BigDecimal.ZERO; //实收非跟单佣金
- // BigDecimal receivedWillPromotion = BigDecimal.ZERO; //实收推广费
- // 预收手续费佣金
- willPromotion = this.willPromotionAll(willPromotion, userId,"1");
- // 实收手续费佣金
- //receivedWillPromotion = this.willPromotionAll(willPromotion, userId,"2");
- // add by hxl 修改sql 添加承保状态和不在审核表中的条件 begin ===============
- List<InsFeeOrderNew> willList = insFeeOrderNewService.getByUserIdAndOrderStatusAndNoCheckType(userId,"1");
- //List<InsFeeOrderNew> willListnew = insFeeOrderNewService.getByUserIdAndOrderStatusAndNoCheckType(userId,"2");
- if (!CollectionUtils.isEmpty(willList)) {
- for (InsFeeOrderNew item : willList) {
- if (ObjectUtils.isNotEmpty(item)) {
- //1.预收手续费佣金 2. 预收非跟单佣金
- willHalding = willHalding.add(this.willAmountNew(item,1));
- willDocumentary = willDocumentary.add(this.willAmountNew(item,2));
- }
- }
- }
- /**
- if (!CollectionUtils.isEmpty(willListnew)) {
- for (InsFeeOrderNew item : willListnew) {
- if (ObjectUtils.isNotEmpty(item)) {
- //1.实收手续费佣金 2. 实收非跟单佣金
- receivedWillHalding = willHalding.add(this.willAmountNew(item,1));
- receivedWillDocumentary = willDocumentary.add(this.willAmountNew(item,2));
- }
- }
- }
- **/
- //预收手续费佣金
- sysUserAccountVo.setWillHalding(willHalding);
- //预收非跟单佣金
- sysUserAccountVo.setWillDocumentary(willDocumentary);
- //实收手续费佣金
- //sysUserAccountVo.setReceivedWillHalding(receivedWillHalding);
- //实收非跟单佣金
- //sysUserAccountVo.setReceivedWillDocumentary(receivedWillDocumentary);
- //提现现中 手续费、非跟单、推广费
- HashMap<String, Object> params = new HashMap<>();
- params.put("auditingStatus", "2"); // 待审核
- params.put("userId", userId);
- List<SysAmountAuditingEntity> sysAmountAuditingProgressIng = sysAmountAuditingService.getProgressIng(params);
- this.judge(sysAmountAuditingProgressIng, sysUserAccountVo);
- params.clear();
- params.put("auditingStatus", "3"); // 已审核审核
- params.put("userId", userId);
- //已提现 手续费、非跟单、推广费
- List<SysAmountAuditingEntity> sysAmountAuditingApproved = sysAmountAuditingService.getProgressIng(params);
- this.judgeSysAmountAuditing(sysAmountAuditingApproved, sysUserAccountVo);
- //预收手续费佣金
- sysUserAccountVo.setWillPromotion(willPromotion);
- //实收手续费佣金
- // sysUserAccountVo.setReceivedWillPromotion(receivedWillPromotion);
- return sysUserAccountVo;
- }
- @Override
- public SysUserAccountVo getInsOrders(SysUserAccountVo sysUserAccountVo) {
- ArrayList<InsFeeOrderNew> resultList = new ArrayList<>();
- HashMap<String, Object> params = new HashMap<>();
- params.put("userId", BaseController.getUser().getId());
- //日期
- params.put("timeFiltering", sysUserAccountVo.getTimeFiltering());
- //1预收2.实收
- params.put("type",sysUserAccountVo.getSearchType());
- sysUserAccountVo.setInsFeeOrderNewList(null);
- //金额类型 1. 手续费金额 2. 跟单金额 3. 推广金额
- if ("3".equals(sysUserAccountVo.getAmountType())) {
- List<InsFeeOrderNew> sumWillAmountGeneralization = insFeeOrderNewService.getSumWillAmountGeneralizationNew(params);
- sysUserAccountVo.setInsFeeOrderNewList(sumWillAmountGeneralization);
- } else {
- List<InsFeeOrderNew> resultInsFeeOrderNew = insFeeOrderNewService.getSumWillAmountNew(params);
- if (resultInsFeeOrderNew!=null && resultInsFeeOrderNew.size()>0) {
- for (InsFeeOrderNew item : resultInsFeeOrderNew) {
- BigDecimal willPromotion = BigDecimal.ZERO;
- if ("1".equals(sysUserAccountVo.getAmountType())) {
- //手续费出口预收
- willPromotion = willPromotion.add(item.getJqExportSuperviseCostsPremiums()).add(item.getSyExportSuperviseCostsPremiums()).add(item.getNoExportSuperviseCostsPremiums());
- } else if ("2".equals(sysUserAccountVo.getAmountType())) {
- willPromotion = willPromotion.add(item.getJqExportOtherCostsPremiums()).add(item.getSyExportOtherCostsPremiums()).add(item.getNoExportOtherCostsPremiums());
- }
- item.setWillAmount(willPromotion);
- if (willPromotion.compareTo(BigDecimal.ZERO) != 0) {
- resultList.add(item);
- }
- }
- sysUserAccountVo.setInsFeeOrderNewList(resultList);
- }
- }
- return sysUserAccountVo;
- }
- private void getWillAmount(InsFeeOrderNew insFeeOrderNew) {
- if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
- //交强手续费出口比例
- BigDecimal jqExportProceduresFee =
- insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqSuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- //商业手续费出口比例
- BigDecimal syExportProceduresFee =
- insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSySuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- //非车手续费出口比例
- BigDecimal noExportProceduresFee =
- insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoSuperviseCostsProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- //非车出口比例
- //总机构 交强管理比例
- BigDecimal sumJqDeptProportion = insFeeOrderNew.getJqDeptProportionLevel1()
- .add(insFeeOrderNew.getJqDeptProportionLevel2())
- .add(insFeeOrderNew.getJqDeptProportionLevel3())
- .add(insFeeOrderNew.getJqDeptProportionLevel4())
- .add(insFeeOrderNew.getJqDeptProportionLevel5());
- //总机构 商业管理比例
- BigDecimal sumSyDeptProportion = insFeeOrderNew.getSyDeptProportionLevel1()
- .add(insFeeOrderNew.getSyDeptProportionLevel2())
- .add(insFeeOrderNew.getSyDeptProportionLevel3())
- .add(insFeeOrderNew.getSyDeptProportionLevel4())
- .add(insFeeOrderNew.getSyDeptProportionLevel5());
- //总机构 非车管理比例
- BigDecimal sumNoDeptProportion = insFeeOrderNew.getNoDeptProportionLevel1()
- .add(insFeeOrderNew.getNoDeptProportionLevel2())
- .add(insFeeOrderNew.getNoDeptProportionLevel3())
- .add(insFeeOrderNew.getNoDeptProportionLevel4())
- .add(insFeeOrderNew.getNoDeptProportionLevel5());
- BigDecimal noExportProceduresProportion = new BigDecimal(0);
- //总分销比例
- BigDecimal sumRetail =
- insFeeOrderNew.getFirstDetailProportion().add(insFeeOrderNew.getSecondDetailProportion()).add(insFeeOrderNew.getThirdDetailProportion());
- if (insFeeOrderNew.getNoCostsProportion().compareTo(sumNoDeptProportion.add(sumRetail)) > 0) {
- noExportProceduresProportion = insFeeOrderNew.getNoCostsProportion().subtract(sumNoDeptProportion).subtract(sumRetail);
- }
- //商业出口比例
- BigDecimal syExportProceduresProportion = new BigDecimal(0);
- if (insFeeOrderNew.getSyCostsProportion().compareTo(sumSyDeptProportion.add(sumRetail)) > 0) {
- syExportProceduresProportion = insFeeOrderNew.getSyCostsProportion().subtract(sumSyDeptProportion).subtract(sumRetail);
- }
- //交强出口比例
- BigDecimal jqExportProceduresProportion = new BigDecimal(0);
- if (insFeeOrderNew.getJqCostsProportion().compareTo(sumJqDeptProportion.add(sumRetail)) > 0) {
- jqExportProceduresProportion = insFeeOrderNew.getJqCostsProportion().subtract(sumJqDeptProportion).subtract(sumRetail);
- }
- //交强跟单出口费用
- BigDecimal jqExportOtherFee = insFeeOrderNew.getJqPremium()
- .multiply(jqExportProceduresProportion
- .subtract(insFeeOrderNew.getJqSuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
- BigDecimal.ROUND_DOWN);
- //商业跟单出口比例
- BigDecimal syExportOtherFee = insFeeOrderNew.getSyPremium()
- .multiply(syExportProceduresProportion
- .subtract(insFeeOrderNew.getSySuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
- BigDecimal.ROUND_DOWN);
- //非车跟单出口比例
- BigDecimal noExportOtherFee = insFeeOrderNew.getNoPremium()
- .multiply(noExportProceduresProportion
- .subtract(insFeeOrderNew.getNoSuperviseCostsProportion()).divide(new BigDecimal(100))).setScale(2,
- BigDecimal.ROUND_DOWN);
- if (StringUtils.isNotEmpty(insFeeOrderNew.getAmountType())) {
- if ("1".equals(insFeeOrderNew.getAmountType())) {
- //用户出口手续费
- insFeeOrderNew.setWillAmount(jqExportProceduresFee.add(syExportProceduresFee).add(noExportProceduresFee));
- }
- if ("2".equals(insFeeOrderNew.getAmountType())) {
- //用户出口跟单费
- insFeeOrderNew.setWillAmount(jqExportOtherFee.add(syExportOtherFee).add(noExportOtherFee));
- }
- }
- }
- }
- private BigDecimal getWillPromotion(InsFeeOrderNew insFeeOrderNew, BigDecimal willPromotion) {
- InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNew(insFeeOrderNew);
- if (ObjectUtils.isNotEmpty(InsOrders)) {
- BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
- // 累加保费
- willPromotion = willPromotion.add(willFirstPremiums);
- }
- return willPromotion;
- }
- private void judgeSysAmountAuditing(List<SysAmountAuditingEntity> sysAmountAuditingApproved, SysUserAccountVo sysUserAccountVo) {
- if (!CollectionUtils.isEmpty(sysAmountAuditingApproved)) {
- for (SysAmountAuditingEntity item : sysAmountAuditingApproved) {
- if ("1".equals(item.getAmountStatus())) { //手续费
- BigDecimal amount = item.getAmount();
- sysUserAccountVo.setApprovedHalding(amount);
- }
- if ("2".equals(item.getAmountStatus())) { //非跟单
- BigDecimal amount = item.getAmount();
- sysUserAccountVo.setApprovedDocumentary(amount);
- }
- if ("3".equals(item.getAmountStatus())) { //推广费
- BigDecimal amount = item.getAmount();
- sysUserAccountVo.setApprovedPromotion(amount);
- }
- }
- }
- }
- private void judge(List<SysAmountAuditingEntity> sysAmountAuditingProgressIng, SysUserAccountVo sysUserAccountVo) {
- if (!CollectionUtils.isEmpty(sysAmountAuditingProgressIng)) {
- for (SysAmountAuditingEntity item : sysAmountAuditingProgressIng) {
- if ("1".equals(item.getAmountStatus())) { //手续费
- BigDecimal amount = item.getAmount();
- sysUserAccountVo.setWithdrawalHalding(amount);
- }
- if ("2".equals(item.getAmountStatus())) { //非跟单
- BigDecimal amount = item.getAmount();
- sysUserAccountVo.setWithdrawalDocumentary(amount);
- }
- if ("3".equals(item.getAmountStatus())) { //推广费
- BigDecimal amount = item.getAmount();
- sysUserAccountVo.setWithdrawalPromotion(amount);
- }
- }
- }
- }
- private BigDecimal willPromotion(BigDecimal willPromotion, String userId) {
- InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
- insFeeOrderNew.setUserId(userId);
- InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNew(insFeeOrderNew);
- if (ObjectUtils.isNotEmpty(InsOrders)) {
- BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
- // 累加保费
- willPromotion = willPromotion.add(willFirstPremiums);
- }
- return willPromotion;
- }
- private void willAmount(InsFeeOrderNew insFeeOrderNew, BigDecimal willHalding, BigDecimal willDocumentary,
- SysUserAccountVo sysUserAccountVo) {
- if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
- //交强手续费
- BigDecimal jqExportProceduresFee = insFeeOrderNew.getJqExportSuperviseCostsPremiums();
- //商业手续费
- BigDecimal syExportProceduresFee = insFeeOrderNew.getSyExportSuperviseCostsPremiums();
- //非车手续费
- BigDecimal noExportProceduresFee = insFeeOrderNew.getNoExportSuperviseCostsPremiums();
- if (sysUserAccountVo.getWillHalding() == null) {
- sysUserAccountVo.setWillHalding(BigDecimal.ZERO);
- }
- sysUserAccountVo.setWillHalding(sysUserAccountVo.getWillHalding().add(jqExportProceduresFee).add(syExportProceduresFee).add(noExportProceduresFee));
- //交强跟单出口费用
- BigDecimal jqExportOtherCostsPremiums = insFeeOrderNew.getJqExportOtherCostsPremiums();
- //商业跟单出口费用
- BigDecimal syExportOtherCostsPremiums = insFeeOrderNew.getSyExportOtherCostsPremiums();
- //非车跟单出口费用
- BigDecimal noExportOtherCostsPremiums = insFeeOrderNew.getNoExportOtherCostsPremiums();
- //用户出口跟单费
- if (sysUserAccountVo.getWillDocumentary() == null) {
- sysUserAccountVo.setWillDocumentary(BigDecimal.ZERO);
- }
- sysUserAccountVo.setWillDocumentary(sysUserAccountVo.getWillDocumentary().add(jqExportOtherCostsPremiums).add(syExportOtherCostsPremiums).add(noExportOtherCostsPremiums));
- }
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/3 11:20
- * @Description: 通过类型查询预收、实收的金额
- */
- private BigDecimal willPromotionAll(BigDecimal willPromotion, String userId,String type) {
- InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
- insFeeOrderNew.setUserId(userId);
- InsOrders InsOrders = insAreaCompanyService.selectByInFeeOrderNewByType(insFeeOrderNew,type);
- if (ObjectUtils.isNotEmpty(InsOrders)) {
- BigDecimal willFirstPremiums = ObjectUtils.defaultIfNull(InsOrders.getWillFirstPremiums(), BigDecimal.ZERO);
- // 累加保费
- willPromotion = willPromotion.add(willFirstPremiums);
- }
- return willPromotion;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/4 11:51
- * @Description: 获取费用
- */
- private BigDecimal willAmountNew(InsFeeOrderNew insFeeOrderNew, int type) {
- BigDecimal val= BigDecimal.ZERO;
- if (ObjectUtils.isNotEmpty(insFeeOrderNew)) {
- if(type==1){
- // 交强手续费+商业手续费+非车手续费
- val= val.add(insFeeOrderNew.getJqExportSuperviseCostsPremiums()).add(insFeeOrderNew.getSyExportSuperviseCostsPremiums()).add(insFeeOrderNew.getNoExportSuperviseCostsPremiums());
- }else{
- // 交强跟单出口费用+商业跟单出口费用+非车跟单出口费用
- val= val.add(insFeeOrderNew.getJqExportOtherCostsPremiums()).add(insFeeOrderNew.getSyExportOtherCostsPremiums()).add(insFeeOrderNew.getNoExportOtherCostsPremiums());
- }
- }
- return val;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/3 15:16
- * @Description: 查询子订单的详细信息
- */
- @Override
- public SubOrder getSubOrderDetails(String subOrderId, String userId) {
- SubOrder subOrder=insAreaCompanyMapper.getSubOrderDetails(subOrderId);
- subOrder.setAgentName(this.getUserName(subOrder.getUserId()));
- subOrder.setAgentLevel("");
- //根据用户id查询分销等级
- InsFeeOrderNew insFeeOrderNew = insFeeOrderNewService.getOne(new LambdaQueryWrapper<InsFeeOrderNew>()
- .eq(InsFeeOrderNew::getInsOrderNo, subOrder.getSubOrderId()));
- if(userId.equals(insFeeOrderNew.getFirstLevelUserId())){
- //subOrder.setAgentName(this.getUserName(insFeeOrderNew.getFirstLevelUserId()));
- subOrder.setAgentLevel("一级分销代理");
- }
- if(userId.equals(insFeeOrderNew.getTwoLevelUserId())){
- //subOrder.setAgentName(this.getUserName(insFeeOrderNew.getTwoLevelUserId()));
- subOrder.setAgentLevel("二级分销代理");
- }
- if(userId.equals(insFeeOrderNew.getThreeLevelUserId())){
- //subOrder.setAgentName(this.getUserName(insFeeOrderNew.getThreeLevelUserId()));
- subOrder.setAgentLevel("三级分销代理");
- }
- return subOrder;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/3 16:34
- * @Description: 查询分销人名称
- */
- private String getUserName(String userId) {
- if(StringUtils.isNotEmpty(userId)){
- SysUser sysUser = sysUserService.getBaseMapper().selectById(userId);
- if(ObjectUtils.isNotEmpty(sysUser)){
- return sysUser.getName();
- }
- }
- return "";
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/19 9:04
- * @Description: 查询我的账户总金额
- */
- @Override
- public BigDecimal getUserSumAmountByUserId(String userId) {
- if(StringUtils.isBlank(userId)){
- throw new SystemException("用户id-userId不能为空");
- }
- //通过用户id查询用户账户的总金额
- LambdaQueryWrapper<SysUserAccount> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(SysUserAccount::getUserId, userId);
- SysUserAccount sysUserAccount = sysUserAccountService.getOne(queryWrapper);
- if(sysUserAccount==null){
- return BigDecimal.ZERO;
- }
- return sysUserAccount.getSumAmount()==null?BigDecimal.ZERO:sysUserAccount.getSumAmount();
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/19 11:04
- * @Description: 查询预收数据明细
- */
- @Override
- public MyCollectInAdvanceAllDto findMyCollectInAdvanceByUserId(MyCollectInAdvanceQueryDto myCollectInAdvanceQueryDto) {
- if(StringUtils.isBlank(myCollectInAdvanceQueryDto.getUserId())){
- throw new SystemException("用户id-userId不能为空");
- }
- BigDecimal sumAmount=BigDecimal.ZERO;
- //判断时间类型 1.一周内 2. 一月内 3. 三月内 4. 三月内
- HashMap<String, String> dateMap = getDateMapByType(myCollectInAdvanceQueryDto.getDateQueryType(),myCollectInAdvanceQueryDto.getStartDate(),myCollectInAdvanceQueryDto.getEndDate());
- myCollectInAdvanceQueryDto.setStartDate(dateMap.get("startDate"));
- myCollectInAdvanceQueryDto.setEndDate(dateMap.get("endDate"));
- if(myCollectInAdvanceQueryDto.getBusinessSegmentsType()==null || "".equals(myCollectInAdvanceQueryDto.getBusinessSegmentsType())){
- myCollectInAdvanceQueryDto.setBusinessSegmentsType("1");
- }
- if(myCollectInAdvanceQueryDto.getTransactionType()==null || "".equals(myCollectInAdvanceQueryDto.getTransactionType())){
- myCollectInAdvanceQueryDto.setTransactionType("1");
- }
- Page<MyCollectInAdvanceDto> page = new Page<>(myCollectInAdvanceQueryDto.getPageNum(), myCollectInAdvanceQueryDto.getPageSize());
- // page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
- Page<MyCollectInAdvanceDto> orderVoPage = new Page<>();
- // 1为车险板块
- if ("1".equals(myCollectInAdvanceQueryDto.getBusinessSegmentsType())) {
- //金额类型 1. 手续费金额 +跟单金额 2. 推广金额
- if("2".equals(myCollectInAdvanceQueryDto.getTransactionType())){
- orderVoPage = insFeeOrderNewService.findMyCollectInAdvanceWillAmountByUserId(page,myCollectInAdvanceQueryDto);
- // Long total=insFeeOrderNewService.findMyCollectInAdvanceWillAmountByUserIdCount(myCollectInAdvanceQueryDto);
- // orderVoPage.setTotal(total);
- sumAmount = insFeeOrderNewService.findSumWillAmount(myCollectInAdvanceQueryDto);
- }else{
- orderVoPage = insFeeOrderNewService.findMyCollectInAdvanceSumByUserId(page,myCollectInAdvanceQueryDto);
- // Long total=insFeeOrderNewService.findMyCollectInAdvanceSumByUserIdCount(myCollectInAdvanceQueryDto);
- // orderVoPage.setTotal(total);
- sumAmount = insFeeOrderNewService.findSumAmount(myCollectInAdvanceQueryDto);
- }
- } else {
- //其他板块预留逻辑处理
- }
- List<MyCollectInAdvanceDto> recordsNew =new ArrayList<>();
- if(orderVoPage.getRecords()!=null && orderVoPage.getRecords().size()>0){
- for(MyCollectInAdvanceDto dto :orderVoPage.getRecords()) {
- //车险的显示且收入
- if ("1".equals(dto.getBusinessSegmentsType())) {
- if ("4".equals(dto.getTransactionType())) {
- dto.setTransactionType("1");
- } else if ("3".equals(dto.getTransactionType())) {
- dto.setTransactionType("2");
- }
- }
- recordsNew.add(dto);
- }
- }
- orderVoPage.setRecords(recordsNew);
- BasePageResult<MyCollectInAdvanceDto> myCollectInAdvanceDtoBasePageResult = new BasePageResult<>(myCollectInAdvanceQueryDto.getPageNum(), myCollectInAdvanceQueryDto.getPageSize(), orderVoPage.getTotal(),
- orderVoPage.getPages()
- , orderVoPage.getRecords());
- return new MyCollectInAdvanceAllDto(sumAmount,myCollectInAdvanceDtoBasePageResult);
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/19 11:57
- * @Description: 通过时间类型判断
- */
- private static HashMap<String,String> getDateMapByType(String type,String startDate,String endDate) {
- HashMap<String,String> map =new HashMap<>();
- String startDateStr="";
- String endDateStr="";
- if(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)){
- startDateStr= StringUtils.isNotBlank(startDate)?startDate+" 00:00:00":null;
- endDateStr= StringUtils.isNotBlank(endDate)?endDate+" 23:59:59":null;
- }else{
- if("0".equals(type)){
- //全部
- startDateStr=null;
- endDateStr=null;
- }else if("1".equals(type)){
- // 一周内
- startDateStr=SliceUpDateUtil.getBeforeDay(new Date(),1)+" 00:00:00";
- endDateStr=SliceUpDateUtil.getBeforeDay(new Date(),0)+" 23:59:59";
- }else if("2".equals(type)){
- // 一月内
- startDateStr=SliceUpDateUtil.getBeforeDay(new Date(),2)+" 00:00:00";
- endDateStr=SliceUpDateUtil.getBeforeDay(new Date(),0)+" 23:59:59";
- }else if("3".equals(type)){
- // 三月内
- startDateStr=SliceUpDateUtil.getBeforeDay(new Date(),3)+" 00:00:00";
- endDateStr=SliceUpDateUtil.getBeforeDay(new Date(),0)+" 23:59:59";
- }else if("4".equals(type)){
- // 三月内
- startDateStr=SliceUpDateUtil.getBeforeDay(new Date(),4)+" 00:00:00";
- endDateStr=SliceUpDateUtil.getBeforeDay(new Date(),0)+" 23:59:59";
- }else{
- startDateStr= StringUtils.isNotBlank(startDate)?startDate+" 00:00:00":null;
- endDateStr= StringUtils.isNotBlank(endDate)?endDate+" 23:59:59":null;
- }
- }
- map.put("startDate",startDateStr);
- map.put("endDate",endDateStr);
- return map;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/19 11:04
- * @Description: 查询收支数据明细
- */
- @Override
- public MyCollectInAdvanceAllDto findIncomeAndExpensesByUserId(MyIncomeAndExpensesQueryDto myIncomeAndExpensesQueryDto) {
- if (StringUtils.isBlank(myIncomeAndExpensesQueryDto.getUserId())) {
- throw new SystemException("用户id-userId不能为空");
- }
- BigDecimal sumAmountSR = BigDecimal.ZERO;
- BigDecimal sumAmountZC = BigDecimal.ZERO;
- BasePageResult<MyCollectInAdvanceDto> myCollectInAdvanceDtoBasePageResult = new BasePageResult<MyCollectInAdvanceDto>();
- //判断时间类型 1.一周内 2. 一月内 3. 三月内 4. 三月内
- HashMap<String, String> dateMap = getDateMapByType(myIncomeAndExpensesQueryDto.getDateQueryType(), myIncomeAndExpensesQueryDto.getStartDate(), myIncomeAndExpensesQueryDto.getEndDate());
- myIncomeAndExpensesQueryDto.setStartDate(dateMap.get("startDate"));
- myIncomeAndExpensesQueryDto.setEndDate(dateMap.get("endDate"));
- Page<MyCollectInAdvanceDto> page = new Page<>(myIncomeAndExpensesQueryDto.getPageNum(), myIncomeAndExpensesQueryDto.getPageSize());
- //page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
- Page<MyCollectInAdvanceDto> orderVoPage = new Page<>();
- if ("0".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType())) {
- myIncomeAndExpensesQueryDto.setBusinessSegmentsType(null);
- }
- if ("0".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
- myIncomeAndExpensesQueryDto.setTransactionType(null);
- }
- if ("0".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
- myIncomeAndExpensesQueryDto.setIncomeAndExpensesType(null);
- }
- // 1为车险板块 1 收入时
- if ( StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) && StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) &&"1".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) &&"1".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
- //判断收入类型 1 收入
- if(StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && "3".equals(myIncomeAndExpensesQueryDto.getTransactionType())){
- throw new SystemException("收入类型不能选择提现类型");
- }
- }
- if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) &&"2".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
- //判断支出类型
- if(StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && !"3".equals(myIncomeAndExpensesQueryDto.getTransactionType())){
- throw new SystemException("支出类型不能选择(手续+跟单)或者手续费、退款类型");
- }
- }
- if ( (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) && StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) && "2".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType()) &&"1".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()))
- ||
- (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType()) && ("2".equals(myIncomeAndExpensesQueryDto.getBusinessSegmentsType())))){
- //判断退款类型
- if(StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) &&!"4".equals(myIncomeAndExpensesQueryDto.getTransactionType())){
- throw new SystemException("退款板块只能选择退款类型");
- }
- }
- //处理 手续费+跟单、推广费类型转换
- if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) && "2".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
- myIncomeAndExpensesQueryDto.setTransactionType("3");
- } else if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) &&"1".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
- myIncomeAndExpensesQueryDto.setTransactionType("4");
- } else if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) &&"4".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
- myIncomeAndExpensesQueryDto.setTransactionType("5");
- } else if (StringUtils.isNotBlank(myIncomeAndExpensesQueryDto.getTransactionType()) &&"3".equals(myIncomeAndExpensesQueryDto.getTransactionType())) {
- myIncomeAndExpensesQueryDto.setTransactionType("6");
- }
- //处理收入和支出类型转换
- if (myIncomeAndExpensesQueryDto.getIncomeAndExpensesType() != null && "0".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
- myIncomeAndExpensesQueryDto.setIncomeAndExpensesType(null);
- } else if (myIncomeAndExpensesQueryDto.getIncomeAndExpensesType() != null && "1".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())) {
- myIncomeAndExpensesQueryDto.setIncomeAndExpensesType("2");
- } else if (myIncomeAndExpensesQueryDto.getIncomeAndExpensesType() != null && "2".equals(myIncomeAndExpensesQueryDto.getIncomeAndExpensesType())){
- myIncomeAndExpensesQueryDto.setIncomeAndExpensesType("1");
- }
- orderVoPage = sysUserAccountHistoryService.findMyIncomeAndExpensesAmountByUserId(page,myIncomeAndExpensesQueryDto);
- // Long total=sysUserAccountHistoryService.findMyIncomeAndExpensesAmountByUserIdCount(myIncomeAndExpensesQueryDto);
- // orderVoPage.setTotal(total);
- List<MyCollectInAdvanceDto> recordsNew =new ArrayList<>();
- if(orderVoPage.getRecords()!=null && orderVoPage.getRecords().size()>0){
- for(MyCollectInAdvanceDto dto :orderVoPage.getRecords()) {
- //车险的显示且收入
- if ("1".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())) {
- if ("4".equals(dto.getTransactionType())) {
- dto.setTransactionType("1");
- } else if ("3".equals(dto.getTransactionType())) {
- dto.setTransactionType("2");
- }
- dto.setIncomeAndExpensesType("1");
- //退款 且退款
- } else if ("2".equals(dto.getBusinessSegmentsType()) && "2".equals(dto.getIncomeAndExpensesType())){
- dto.setIncomeAndExpensesType("1");
- dto.setTransactionType("4");
- //退款设置为空
- dto.setAuditingStatus("");
- //提现
- }else if("6".equals(dto.getTransactionType()) && "1".equals(dto.getIncomeAndExpensesType())){
- dto.setIncomeAndExpensesType("2");
- dto.setTransactionType("3");
- }
- recordsNew.add(dto);
- }
- }
- orderVoPage.setRecords(recordsNew);
- myCollectInAdvanceDtoBasePageResult = new BasePageResult<>(myIncomeAndExpensesQueryDto.getPageNum(), myIncomeAndExpensesQueryDto.getPageSize(), orderVoPage.getTotal(),
- orderVoPage.getPages()
- , orderVoPage.getRecords());
- //
- sumAmountSR=sysUserAccountHistoryService.findSumAmountByUserId(myIncomeAndExpensesQueryDto.getUserId(),"2");
- sumAmountZC=sysUserAccountHistoryService.findSumAmountByUserId(myIncomeAndExpensesQueryDto.getUserId(),"1");
- return new MyCollectInAdvanceAllDto(sumAmountSR,sumAmountZC,myCollectInAdvanceDtoBasePageResult);
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/20 13:48
- * @Description: 提现详情
- */
- @Override
- public WithdrawalDetalsDto findDetailById(String id) {
- //id为历史表的id
- //通过历史记录表查询数据
- SysUserAccountHistory his = sysUserAccountHistoryService.getById(id);
- LambdaQueryWrapper<SysAmountAuditingHistory> lqw = new LambdaQueryWrapper<>();
- lqw.eq(SysAmountAuditingHistory::getHistoryId, id);
- lqw.orderByAsc(SysAmountAuditingHistory::getCreateTime);
- List<SysAmountAuditingHistory> listAll = sysAmountAuditingHistoryService.list(lqw);
- SysAmountAuditingEntity audi = sysAmountAuditingService.getById(his.getAuditiingId());
- WithdrawalDetalsDto withdrawalDetalsDto=new WithdrawalDetalsDto();
- if(audi!=null){
- withdrawalDetalsDto.setBankNumber(audi.getBankNumber());
- withdrawalDetalsDto.setTransactionNumber(audi.getId());
- withdrawalDetalsDto.setWithdrawalAmount(audi.getAmount());
- withdrawalDetalsDto.setBankAccount(audi.getBankAccount());
- }
- List<WithdrawalDetalsRecordDto> recordList =new ArrayList<WithdrawalDetalsRecordDto>();
- if(listAll!=null && listAll.size()>0){
- SysAmountAuditingHistory first = listAll.get(0);
- SysAmountAuditingHistory last = listAll.get(listAll.size() - 1);
- //申请时间
- Date createTime = first.getCreateTime();
- withdrawalDetalsDto.setApplicationDate(createTime);
- String auditingStatus = last.getAuditingStatus();
- withdrawalDetalsDto.setWithdrawalStatus(auditingStatus);
- String auditingStatusName="";
- if("1".equals(auditingStatus)){
- auditingStatusName="提现申请";
- }else if("2".equals(auditingStatus)){
- auditingStatusName="处理中";
- }else if("3".equals(auditingStatus)){
- auditingStatusName="提现失败";
- }else if("4".equals(auditingStatus)){
- auditingStatusName="提现成功";
- withdrawalDetalsDto.setPaymentDate(last.getCreateTime());
- }
- withdrawalDetalsDto.setWithdrawalStatusName(auditingStatusName);
- WithdrawalDetalsRecordDto dto1 = new WithdrawalDetalsRecordDto("1", false, "提现申请", null);
- WithdrawalDetalsRecordDto dto2 = new WithdrawalDetalsRecordDto("2", false, "处理中", null);
- WithdrawalDetalsRecordDto dto3 = null;
- WithdrawalDetalsRecordDto dto4 = new WithdrawalDetalsRecordDto("4", false, "提现成功", null);
- for(SysAmountAuditingHistory sysAmountAuditingHistory:listAll){
- if("1".equals(sysAmountAuditingHistory.getAuditingStatus())){
- dto1.setProcessingStatusFlag(true);
- dto1.setProcessingDate(sysAmountAuditingHistory.getCreateTime());
- }else if("2".equals(sysAmountAuditingHistory.getAuditingStatus())){
- dto2.setProcessingStatusFlag(true);
- dto2.setProcessingDate(sysAmountAuditingHistory.getCreateTime());
- }else if("3".equals(sysAmountAuditingHistory.getAuditingStatus())){
- dto3 =new WithdrawalDetalsRecordDto("3", true, "提现失败", sysAmountAuditingHistory.getCreateTime());
- }else if("4".equals(sysAmountAuditingHistory.getAuditingStatus())){
- dto4.setProcessingStatusFlag(true);
- dto4.setProcessingDate(sysAmountAuditingHistory.getCreateTime());
- }
- }
- recordList.add(dto1);
- recordList.add(dto2);
- if(dto3!=null){
- recordList.add(dto3);
- withdrawalDetalsDto.setRejectReason(audi.getRejectReason()==null?"":audi.getRejectReason());
- }else{
- recordList.add(dto4);
- }
- withdrawalDetalsDto.setRecord(recordList);
- }
- return withdrawalDetalsDto;
- }
- @Override
- public OrderDetalsDto findOrderDetailById(String subOrderId) {
- return null;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/6/21 18:27
- * @Description: 查看退款详情
- */
- @Override
- public RefundDetalsDto findRefundDetailById(String id) {
- //id为历史表的id
- //通过历史记录表查询数据
- SysUserAccountHistory his = sysUserAccountHistoryService.getById(id);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String dateStr = sdf.format(his.getCreateTime());
- return new RefundDetalsDto(dateStr,his.getAmount(),his.getAuditiingId());
- }
- }
|