2 Commits 5f86753662 ... 1f8fd5d4f0

Author SHA1 Message Date
  wangwl 1f8fd5d4f0 Merge branch 'dev-1.2.1-wwlong' into dev-1.2.1 3 months ago
  wangwl 2cfdf3c88e 余额提现优化 3 months ago

+ 4 - 0
leromro-core/src/main/java/com/leromro/core/controller/VolunteerAccountController.java

@@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.List;
 
 
 /**
 /**
@@ -76,6 +77,9 @@ public class VolunteerAccountController extends BaseController {
             if (StrUtil.isBlank(dto.getAlipayAccountNo())) {
             if (StrUtil.isBlank(dto.getAlipayAccountNo())) {
                 return R.fail("支付宝名称不能为空");
                 return R.fail("支付宝名称不能为空");
             }
             }
+            if  (dto.getTakeAmount().compareTo(new BigDecimal("20")) < 0) {
+                return R.fail("提现申请金额最小值为20");
+            }
         }
         }
         return volunteerAccountFacade.submitAmountApply(dto);
         return volunteerAccountFacade.submitAmountApply(dto);
     }
     }

+ 7 - 12
leromro-core/src/main/java/com/leromro/core/controller/VolunteerTakeRecordController.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.leromro.common.core.domain.entity.SysUser;
 import com.leromro.common.core.domain.entity.SysUser;
 import com.leromro.common.utils.SecurityUtils;
 import com.leromro.common.utils.SecurityUtils;
 import com.leromro.core.domain.VolunteerInfo;
 import com.leromro.core.domain.VolunteerInfo;
+import com.leromro.core.facade.VolunteerPaymentRecordsFacade;
 import com.leromro.system.mapper.SysUserMapper;
 import com.leromro.system.mapper.SysUserMapper;
 import com.leromro.system.service.impl.SysUserServiceImpl;
 import com.leromro.system.service.impl.SysUserServiceImpl;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
@@ -46,6 +47,9 @@ public class VolunteerTakeRecordController extends BaseController
     @Autowired
     @Autowired
     private IVolunteerTakeRecordService volunteerTakeRecordService;
     private IVolunteerTakeRecordService volunteerTakeRecordService;
 
 
+    @Autowired
+    private VolunteerPaymentRecordsFacade volunteerPaymentRecordsFacade;
+
 
 
     /**
     /**
      * 查询志愿者提现申请记录列表
      * 查询志愿者提现申请记录列表
@@ -75,18 +79,9 @@ public class VolunteerTakeRecordController extends BaseController
      */
      */
     @ApiOperation(value = "提现审批",notes = "传入当前行主键volunteerTakeRecordId,审批状态appStatus:2通过,3拒绝,驳回原因rejectReason,状态为3则必填")
     @ApiOperation(value = "提现审批",notes = "传入当前行主键volunteerTakeRecordId,审批状态appStatus:2通过,3拒绝,驳回原因rejectReason,状态为3则必填")
     @PostMapping("/approval")
     @PostMapping("/approval")
-    public R approval(@RequestBody VolunteerTakeRecord takeRecord){
-        String appStatus = takeRecord.getAppStatus();
-        if ("3".equals(appStatus) && StrUtil.isBlank(takeRecord.getRejectReason())){
-            return R.fail("请填写驳回原因");
-        }
-        volunteerTakeRecordService.update(new LambdaUpdateWrapper<VolunteerTakeRecord>()
-                .eq(VolunteerTakeRecord::getVolunteerTakeRecordId,takeRecord.getVolunteerTakeRecordId())
-                .set(VolunteerTakeRecord::getAppStatus,takeRecord.getAppStatus())
-                .set(StrUtil.isNotBlank(takeRecord.getRejectReason()),VolunteerTakeRecord::getRejectReason,takeRecord.getRejectReason())
-                .set(VolunteerTakeRecord::getAppUserId, SecurityUtils.getUserId())
-                .set(VolunteerTakeRecord::getAppUserName,SecurityUtils.getUsername()));
-        return R.ok();
+    public R<String> approval(@RequestBody VolunteerTakeRecord takeRecord){
+
+        return volunteerPaymentRecordsFacade.approval(takeRecord);
     }
     }
 
 
 }
 }

+ 73 - 0
leromro-core/src/main/java/com/leromro/core/facade/VolunteerPaymentRecordsFacade.java

@@ -2,29 +2,102 @@ package com.leromro.core.facade;
 
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.leromro.common.core.domain.R;
 import com.leromro.common.core.domain.R;
 import com.leromro.common.core.domain.entity.SysUser;
 import com.leromro.common.core.domain.entity.SysUser;
 import com.leromro.common.core.redis.RedisCache;
 import com.leromro.common.core.redis.RedisCache;
 import com.leromro.common.enums.ConstantsKey;
 import com.leromro.common.enums.ConstantsKey;
 import com.leromro.common.exception.ServiceException;
 import com.leromro.common.exception.ServiceException;
 import com.leromro.common.utils.SecurityUtils;
 import com.leromro.common.utils.SecurityUtils;
+import com.leromro.core.domain.VolunteerAccount;
+import com.leromro.core.domain.VolunteerAccountChange;
 import com.leromro.core.domain.VolunteerPaymentRecords;
 import com.leromro.core.domain.VolunteerPaymentRecords;
+import com.leromro.core.domain.VolunteerTakeRecord;
 import com.leromro.core.domain.dto.WithdrawPaymentDTO;
 import com.leromro.core.domain.dto.WithdrawPaymentDTO;
+import com.leromro.core.service.IVolunteerAccountChangeService;
+import com.leromro.core.service.IVolunteerAccountService;
 import com.leromro.core.service.IVolunteerPaymentRecordsService;
 import com.leromro.core.service.IVolunteerPaymentRecordsService;
+import com.leromro.core.service.IVolunteerTakeRecordService;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 
 import java.util.Date;
 import java.util.Date;
 
 
+/**
+ * 处理提现打款相关业务
+ */
 @Service
 @Service
 public class VolunteerPaymentRecordsFacade {
 public class VolunteerPaymentRecordsFacade {
 
 
+    @Autowired
+    private IVolunteerAccountService  volunteerAccountService;
+
+    @Autowired
+    private IVolunteerAccountChangeService volunteerAccountChangeService;
+
+    @Autowired
+    private IVolunteerTakeRecordService volunteerTakeRecordService;
+
     @Autowired
     @Autowired
     private IVolunteerPaymentRecordsService volunteerPaymentRecordsService;
     private IVolunteerPaymentRecordsService volunteerPaymentRecordsService;
 
 
     @Autowired
     @Autowired
     private RedisCache redisCache;
     private RedisCache redisCache;
 
 
+    /**
+     * 提现审批
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public R<String> approval(@RequestBody VolunteerTakeRecord takeRecord){
+        String appStatus = takeRecord.getAppStatus();
+        if ("3".equals(appStatus)){
+            if (StrUtil.isBlank(takeRecord.getRejectReason())) {
+                return R.fail("请填写驳回原因");
+            }
+            //查询提现申请单
+            VolunteerTakeRecord oldTakeRecord = volunteerTakeRecordService.getById(takeRecord.getVolunteerTakeRecordId());
+            //修改志愿者账户表
+            VolunteerAccount volunteerAccount = volunteerAccountService.getById(oldTakeRecord.getVolunteerAccountId());
+            if (ObjectUtil.isNull(volunteerAccount)){
+                return R.fail("账户不存在");
+            }
+            volunteerAccountService.update(new LambdaUpdateWrapper<VolunteerAccount>()
+                    .eq(VolunteerAccount::getVolunteerAccountId,volunteerAccount.getVolunteerAccountId())
+                    .set(VolunteerAccount::getBalance,volunteerAccount.getBalance().add(oldTakeRecord.getTakeAmount()))
+                    .set(VolunteerAccount::getBeBalance,volunteerAccount.getBeBalance().subtract(oldTakeRecord.getTakeAmount())));
+            //修改志愿者账户变动表
+            VolunteerAccountChange volunteerAccountChange = volunteerAccountChangeService.getOne(new LambdaQueryWrapper<VolunteerAccountChange>()
+                    .eq(VolunteerAccountChange::getVolunteerId,volunteerAccount.getVolunteerId())
+                    .orderByDesc(VolunteerAccountChange::getCreateTime)
+                    .last("limit 1"));
+            VolunteerAccountChange changeBuilder = VolunteerAccountChange.builder()
+                    .volunteerId(volunteerAccountChange.getVolunteerId())
+                    .changeType("1")
+                    .sourceType("11")
+                    .changeMoney(oldTakeRecord.getTakeAmount())
+                    .beforeBalance(volunteerAccountChange.getAfterBalance())
+                    .afterBalance(volunteerAccountChange.getAfterBalance().add(oldTakeRecord.getTakeAmount()))
+                    .sourceId(oldTakeRecord.getVolunteerTakeRecordId())
+                    .build();
+            volunteerAccountChangeService.save(changeBuilder);
+        }
+        //修改提现申请单
+        volunteerTakeRecordService.update(new LambdaUpdateWrapper<VolunteerTakeRecord>()
+                .eq(VolunteerTakeRecord::getVolunteerTakeRecordId,takeRecord.getVolunteerTakeRecordId())
+                .set(VolunteerTakeRecord::getAppStatus,takeRecord.getAppStatus())
+                .set(StrUtil.isNotBlank(takeRecord.getRejectReason()),VolunteerTakeRecord::getRejectReason,takeRecord.getRejectReason())
+                .set(VolunteerTakeRecord::getAppUserId, SecurityUtils.getUserId())
+                .set(VolunteerTakeRecord::getAppUserName,SecurityUtils.getUsername()));
+
+
+        return R.ok();
+    }
+
     /**
     /**
      * 打款单验证
      * 打款单验证
      */
      */