|
@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.agent.domain.Agent;
|
|
import com.ruoyi.agent.domain.Agent;
|
|
|
|
|
+import com.ruoyi.agent.domain.bo.AgentBalanceRecordBo;
|
|
|
import com.ruoyi.agent.domain.bo.AgentBo;
|
|
import com.ruoyi.agent.domain.bo.AgentBo;
|
|
|
|
|
+import com.ruoyi.agent.domain.bo.AgentChangeBalanceBo;
|
|
|
import com.ruoyi.agent.domain.vo.AgentAmountStatisticsVo;
|
|
import com.ruoyi.agent.domain.vo.AgentAmountStatisticsVo;
|
|
|
import com.ruoyi.agent.domain.vo.AgentVo;
|
|
import com.ruoyi.agent.domain.vo.AgentVo;
|
|
|
import com.ruoyi.agent.enums.AgentLevel;
|
|
import com.ruoyi.agent.enums.AgentLevel;
|
|
@@ -20,6 +22,7 @@ import com.ruoyi.agent.service.IAgentService;
|
|
|
import com.ruoyi.business.service.IBusinessService;
|
|
import com.ruoyi.business.service.IBusinessService;
|
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
|
|
+import com.ruoyi.common.enums.ExceptionEnum;
|
|
|
import com.ruoyi.common.enums.InviteType;
|
|
import com.ruoyi.common.enums.InviteType;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.BeanCopyUtils;
|
|
import com.ruoyi.common.utils.BeanCopyUtils;
|
|
@@ -29,9 +32,12 @@ import com.ruoyi.tool.service.ApplySignService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -157,16 +163,16 @@ public class AgentServiceImpl implements IAgentService {
|
|
|
//生成邀请码
|
|
//生成邀请码
|
|
|
String inviteCode = ShareCodeUtils.idToCode(Long.parseLong(add.getPhone()));
|
|
String inviteCode = ShareCodeUtils.idToCode(Long.parseLong(add.getPhone()));
|
|
|
add.setInviteCode(InviteType.AGENT.getCode() + inviteCode);
|
|
add.setInviteCode(InviteType.AGENT.getCode() + inviteCode);
|
|
|
- //签合同
|
|
|
|
|
- Boolean signFlag = applySignService.uploadPersSign(bo.getIdCard(), bo.getSignImage());
|
|
|
|
|
- if(!signFlag){
|
|
|
|
|
- throw new ServiceException(AgentExceptionEnum.Agent_SIGN_FAIL);
|
|
|
|
|
- }
|
|
|
|
|
- String contractNo = applySignService.applySign();
|
|
|
|
|
- if (StringUtils.isEmpty(contractNo)) {
|
|
|
|
|
- throw new ServiceException(AgentExceptionEnum.Agent_SIGN_CONTRACT_FAIL);
|
|
|
|
|
- }
|
|
|
|
|
- add.setContractNo(contractNo);
|
|
|
|
|
|
|
+ //签合同 TODO
|
|
|
|
|
+// Boolean signFlag = applySignService.uploadPersSign(bo.getIdCard(), bo.getSignImage());
|
|
|
|
|
+// if(!signFlag){
|
|
|
|
|
+// throw new ServiceException(AgentExceptionEnum.Agent_SIGN_FAIL);
|
|
|
|
|
+// }
|
|
|
|
|
+// String contractNo = applySignService.applySign();
|
|
|
|
|
+// if (StringUtils.isEmpty(contractNo)) {
|
|
|
|
|
+// throw new ServiceException(AgentExceptionEnum.Agent_SIGN_CONTRACT_FAIL);
|
|
|
|
|
+// }
|
|
|
|
|
+// add.setContractNo(contractNo);
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
bo.setAgentId(add.getAgentId());
|
|
bo.setAgentId(add.getAgentId());
|
|
@@ -273,4 +279,42 @@ public class AgentServiceImpl implements IAgentService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void changeAgentBalance(AgentChangeBalanceBo bo) {
|
|
|
|
|
+ Agent agent = loadById(bo.getAgentId(), true);
|
|
|
|
|
+ BigDecimal entryValue = bo.getEntryValue();
|
|
|
|
|
+ if (entryValue.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal balance = agent.getBalance();
|
|
|
|
|
+ if (bo.getIsAdd()) {
|
|
|
|
|
+ //收入
|
|
|
|
|
+ agent.setBalance(balance.add(entryValue));
|
|
|
|
|
+ agent.setTotalAmount(agent.getTotalAmount().add(entryValue));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //支出
|
|
|
|
|
+ BigDecimal subtract = balance.subtract(entryValue);
|
|
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
+ throw new ServiceException(ExceptionEnum.AGENT_BALANCE_IS_LACK);
|
|
|
|
|
+ }
|
|
|
|
|
+ agent.setBalance(subtract);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.baseMapper.updateById(agent);
|
|
|
|
|
+ //新增积分记录
|
|
|
|
|
+ AgentBalanceRecordBo recordBo = new AgentBalanceRecordBo();
|
|
|
|
|
+ recordBo.setAgentId(agent.getAgentId());
|
|
|
|
|
+ recordBo.setBillType(bo.getIsAdd() ? BillType.INNER : BillType.OUTER);
|
|
|
|
|
+ recordBo.setEntryValue(entryValue);
|
|
|
|
|
+ // 保存收入积分记录
|
|
|
|
|
+ recordBo.setEntryBeforeBalance(balance);
|
|
|
|
|
+ recordBo.setEntryAfterBalance(agent.getBalance());
|
|
|
|
|
+ recordBo.setCreateTime(new Date());
|
|
|
|
|
+ recordBo.setSourceType(bo.getSourceType());
|
|
|
|
|
+ recordBo.setSourceId(bo.getSourceId());
|
|
|
|
|
+ recordBo.setSourceCode(bo.getSourceCode());
|
|
|
|
|
+ recordBo.setRemark(bo.getRemark());
|
|
|
|
|
+ agentBalanceRecordService.insertByBo(recordBo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|