|
@@ -9,15 +9,22 @@ import cn.newfeifan.mall.module.distri.dal.dataobject.applicationforwithdrawal.A
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.integral.IntegralDO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.ptdailywithdrawal.PtDailyWithdrawalDO;
|
|
|
import cn.newfeifan.mall.module.distri.enums.PtSettlemntStatusEnum;
|
|
|
+import cn.newfeifan.mall.module.distri.enums.WithdrawalEnum;
|
|
|
import cn.newfeifan.mall.module.distri.enums.WithdrawalResultEnum;
|
|
|
import cn.newfeifan.mall.module.distri.service.applicationforwithdrawal.ApplicationForWithdrawalService;
|
|
|
import cn.newfeifan.mall.module.distri.service.integral.IntegralService;
|
|
|
import cn.newfeifan.mall.module.distri.service.ptdailywithdrawal.PtDailyWithdrawalService;
|
|
|
import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
|
+import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
|
|
|
+import cn.newfeifan.mall.module.member.service.user.MemberUserService;
|
|
|
+import cn.newfeifan.mall.module.system.api.sms.SmsCodeApi;
|
|
|
+import cn.newfeifan.mall.module.system.api.sms.dto.code.SmsCodeSendReqDTO;
|
|
|
+import cn.newfeifan.mall.module.system.enums.sms.SmsSceneEnum;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import cn.newfeifan.mall.module.distri.controller.admin.applicationforwithdrawalchannel.vo.*;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.applicationforwithdrawalchannel.ApplicationForWithdrawalChannelDO;
|
|
@@ -26,10 +33,13 @@ import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
|
|
|
|
|
|
import cn.newfeifan.mall.module.distri.dal.mysql.applicationforwithdrawalchannel.ApplicationForWithdrawalChannelMapper;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.newfeifan.mall.framework.common.util.servlet.ServletUtils.getClientIP;
|
|
|
import static cn.newfeifan.mall.module.distri.constant.DistriConstants.MILLION;
|
|
|
import static cn.newfeifan.mall.module.distri.enums.CaclEnum.WITHDRAWAL_ERROR;
|
|
|
import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.*;
|
|
@@ -58,6 +68,12 @@ public class ApplicationForWithdrawalChannelServiceImpl implements ApplicationFo
|
|
|
@Resource
|
|
|
private PtProfitLogService ptProfitLogService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SmsCodeApi smsCodeApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private MemberUserService memberUserService;
|
|
|
+
|
|
|
@Override
|
|
|
public Long createApplicationForWithdrawalChannel(ApplicationForWithdrawalChannelSaveReqVO createReqVO) {
|
|
|
// 插入
|
|
@@ -110,7 +126,11 @@ public class ApplicationForWithdrawalChannelServiceImpl implements ApplicationFo
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public List<ApplicationForWithdrawalChannelImportExcelVO> importExcel(List<ApplicationForWithdrawalChannelImportExcelVO> list, Long id) {
|
|
|
+ // 格式化时间
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
// 用来记录错误的记录
|
|
|
List<ApplicationForWithdrawalChannelImportExcelVO> errorList = new ArrayList<>();
|
|
|
|
|
@@ -118,32 +138,52 @@ public class ApplicationForWithdrawalChannelServiceImpl implements ApplicationFo
|
|
|
|
|
|
// 异常判断
|
|
|
if (withdrawalList.isEmpty()) {
|
|
|
- ErrorCode ERROR = new ErrorCode(1_002_030_034, "选中行的记录为空");
|
|
|
+ ErrorCode ERROR = new ErrorCode(1_002_030_034, "选中行的记录为空!");
|
|
|
throw exception(ERROR);
|
|
|
}
|
|
|
if (list.isEmpty()) {
|
|
|
- ErrorCode ERROR = new ErrorCode(1_002_030_035, "上传的Excel文件中没有数据");
|
|
|
+ ErrorCode ERROR = new ErrorCode(1_002_030_035, "上传的Excel文件中没有数据!");
|
|
|
+ throw exception(ERROR);
|
|
|
+ }
|
|
|
+ if (list.get(0).getMoney() == null || list.get(0).getAccountName() == null || list.get(0).getAccountNumber() == null) {
|
|
|
+ ErrorCode ERROR = new ErrorCode(1_002_030_036, "Excel文件中的信息内容不正确!");
|
|
|
throw exception(ERROR);
|
|
|
}
|
|
|
|
|
|
+ ApplicationForWithdrawalChannelDO applicationForWithdrawalChannelDO = applicationForWithdrawalChannelMapper.selectById(id);
|
|
|
+ PtDailyWithdrawalDO ptDailyWithdrawal = ptDailyWithdrawalService.getPtDailyWithdrawal(applicationForWithdrawalChannelDO.getPtDailyWithdrawalId());
|
|
|
+
|
|
|
for (ApplicationForWithdrawalChannelImportExcelVO importVO : list) {
|
|
|
|
|
|
+ String withdrawalTime = importVO.getPostscript().substring(importVO.getPostscript().indexOf("提现日期: ") + "提现日期: ".length()).trim();
|
|
|
+ LocalDateTime withdrawalDateTime = LocalDateTime.parse(withdrawalTime, formatter);
|
|
|
+
|
|
|
+ if (ptDailyWithdrawal.getStartTime().isAfter(withdrawalDateTime) || ptDailyWithdrawal.getEndTime().isBefore(withdrawalDateTime)) {
|
|
|
+ ErrorCode ERROR = new ErrorCode(1_002_030_036, "Excel文件中的日期与选择行的日期不匹配!");
|
|
|
+ throw exception(ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ Double money = Double.parseDouble(importVO.getMoney());
|
|
|
+
|
|
|
for (ApplicationForWithdrawalDO withdrawalDO : withdrawalList) {
|
|
|
+ Double amount = Double.parseDouble(withdrawalDO.getAmount().toString());
|
|
|
|
|
|
// 当前提提现记录的金额和账号与Excel中的金额和账号一致时
|
|
|
- if (withdrawalDO.getAmount().toString().equals(importVO.getMoney()) &&
|
|
|
- withdrawalDO.getWithdrawalAccount().equals(importVO.getAccountNumber())) {
|
|
|
-
|
|
|
- if(importVO.getPayResult().equals(WithdrawalResultEnum.SUCCESS.getResult())){
|
|
|
- withdrawalDO.setStatus(true);
|
|
|
- }else{
|
|
|
- withdrawalDO.setStatus(false);
|
|
|
+ if (money.equals(amount) &&
|
|
|
+ withdrawalDO.getWithdrawalAccount().equals(importVO.getAccountNumber()) &&
|
|
|
+ withdrawalTime.equals(formatter.format(withdrawalDO.getCreateTime()))
|
|
|
+ ) {
|
|
|
+
|
|
|
+ if (importVO.getPayResult().equals(WithdrawalResultEnum.SUCCESS.getResult())) {
|
|
|
+ withdrawalDO.setStatus(WithdrawalEnum.WITHDRAWAL_SUCCESS.getStatus());
|
|
|
+ } else {
|
|
|
+ withdrawalDO.setStatus(WithdrawalEnum.WITHDRAWAL_FAIL.getStatus());
|
|
|
// 记录提现失败的记录
|
|
|
errorList.add(importVO);
|
|
|
|
|
|
// 退回用户提现积分数量
|
|
|
IntegralDO integralDO = integralService.selectByUser(withdrawalDO.getUserId());
|
|
|
- Long integral = Long.parseLong(importVO.getMoney()) * MILLION;
|
|
|
+ Long integral = money.longValue() * MILLION;
|
|
|
|
|
|
integralDO.setCurrentQuota(integralDO.getCurrentQuota() + integral);
|
|
|
integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
|
|
@@ -158,7 +198,15 @@ public class ApplicationForWithdrawalChannelServiceImpl implements ApplicationFo
|
|
|
.build();
|
|
|
ptProfitLogService.createPtProfitLog(ptProfitLogSaveReqVO);
|
|
|
|
|
|
+ MemberUserDO user = memberUserService.getUser(withdrawalDO.getUserId());
|
|
|
// 发送短信通知用户提现失败
|
|
|
+ SmsCodeSendReqDTO smsCodeSendReqDTO = SmsCodeSendReqDTO.builder()
|
|
|
+ .mobile(user.getMobile())
|
|
|
+ .scene(SmsSceneEnum.MEMBER_WITHDRAWAL_ERROR.getScene())
|
|
|
+ .createIp(getClientIP())
|
|
|
+ .sendTime(withdrawalDO.getCreateTime())
|
|
|
+ .build();
|
|
|
+ smsCodeApi.sendSmsCode(smsCodeSendReqDTO);
|
|
|
}
|
|
|
|
|
|
withdrawalService.updateApplicationForWithdrawal(BeanUtils.toBean(withdrawalDO, ApplicationForWithdrawalSaveReqVO.class));
|
|
@@ -167,14 +215,12 @@ public class ApplicationForWithdrawalChannelServiceImpl implements ApplicationFo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- ApplicationForWithdrawalChannelDO applicationForWithdrawalChannelDO = applicationForWithdrawalChannelMapper.selectById(id);
|
|
|
-
|
|
|
// 根据导入的记录判断提现结果
|
|
|
- if(errorList.isEmpty()){
|
|
|
+ if (errorList.isEmpty()) {
|
|
|
applicationForWithdrawalChannelDO.setStatus(PtSettlemntStatusEnum.SETTLEMENT.getStatus());
|
|
|
- }else if (errorList.size() < withdrawalList.size()){
|
|
|
+ } else if (errorList.size() < withdrawalList.size()) {
|
|
|
applicationForWithdrawalChannelDO.setStatus(PtSettlemntStatusEnum.SETTLEMENT_ERROR.getStatus());
|
|
|
- }else if(errorList.size() == withdrawalList.size()){
|
|
|
+ } else if (errorList.size() == withdrawalList.size()) {
|
|
|
applicationForWithdrawalChannelDO.setStatus(PtSettlemntStatusEnum.SETTLEMENT_SUCCESS.getStatus());
|
|
|
}
|
|
|
|
|
@@ -182,17 +228,16 @@ public class ApplicationForWithdrawalChannelServiceImpl implements ApplicationFo
|
|
|
applicationForWithdrawalChannelMapper.updateById(applicationForWithdrawalChannelDO);
|
|
|
|
|
|
Long allCount = applicationForWithdrawalChannelMapper.selectCount(ApplicationForWithdrawalChannelDO::getPtDailyWithdrawalId, applicationForWithdrawalChannelDO.getPtDailyWithdrawalId());
|
|
|
- Long successCount = applicationForWithdrawalChannelMapper.selectCount(PtSettlemntStatusEnum.SETTLEMENT.getStatus(),applicationForWithdrawalChannelDO.getPtDailyWithdrawalId());
|
|
|
-
|
|
|
- PtDailyWithdrawalDO ptDailyWithdrawal = ptDailyWithdrawalService.getPtDailyWithdrawal(applicationForWithdrawalChannelDO.getPtDailyWithdrawalId());
|
|
|
+ Long liteSuccessCount = applicationForWithdrawalChannelMapper.selectCount(PtSettlemntStatusEnum.SETTLEMENT_ERROR.getStatus(), applicationForWithdrawalChannelDO.getPtDailyWithdrawalId());
|
|
|
+ Long successCount = applicationForWithdrawalChannelMapper.selectCount(PtSettlemntStatusEnum.SETTLEMENT.getStatus(), applicationForWithdrawalChannelDO.getPtDailyWithdrawalId());
|
|
|
|
|
|
// 更新一级记录的提现状态
|
|
|
- if(allCount.equals(successCount)){
|
|
|
+ if (allCount.equals(successCount)) {
|
|
|
ptDailyWithdrawal.setStatus(PtSettlemntStatusEnum.SETTLEMENT.getStatus());
|
|
|
- }else if(successCount == 0) {
|
|
|
- ptDailyWithdrawal.setStatus(PtSettlemntStatusEnum.SETTLEMENT_SUCCESS.getStatus());
|
|
|
- }else {
|
|
|
+ } else if (liteSuccessCount > 0) {
|
|
|
ptDailyWithdrawal.setStatus(PtSettlemntStatusEnum.SETTLEMENT_ERROR.getStatus());
|
|
|
+ } else {
|
|
|
+ ptDailyWithdrawal.setStatus(PtSettlemntStatusEnum.SETTLEMENT_SUCCESS.getStatus());
|
|
|
}
|
|
|
|
|
|
// 更新状态
|