Browse Source

收益提现

liaoyongfei 4 years ago
parent
commit
8d6ca960b4

+ 1 - 1
ymall/src/main/java/com/liangjian11/ymall/controller/CashOutController.java

@@ -153,7 +153,7 @@ public class CashOutController {
    */
   @PostMapping("/v1_0/editState")
   public ResultData editState(@RequestBody CashOutRecordStateReq req){
-    return ResultData.getSuccessResult("修改成功");
+    return userAccountProfitService.editCashOutState(req);
   }
 
   /**

+ 2 - 0
ymall/src/main/java/com/liangjian11/ymall/mapper/CalculationProfitMapper.java

@@ -89,4 +89,6 @@ public interface CalculationProfitMapper extends BaseMapper<CalculationProfit> {
 
   List<CalculationProfit> getCanCashOut(@Param("accountId")String accountId);
 
+  List<CalculationProfit> getListOfCashOutId(@Param("cashOutId")Integer cashOutId);
+
 }

+ 3 - 0
ymall/src/main/java/com/liangjian11/ymall/service/UserAccountProfitService.java

@@ -3,6 +3,7 @@ package com.liangjian11.ymall.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.liangjian11.ymall.model.UserAccountProfit;
 import com.liangjian11.ymall.utils.ResultData;
+import com.liangjian11.ymall.view.CashOutRecordStateReq;
 import com.liangjian11.ymall.view.CashOutReq;
 import com.liangjian11.ymall.view.PrepareCashOutRsp;
 
@@ -13,4 +14,6 @@ public interface UserAccountProfitService extends IService<UserAccountProfit> {
   PrepareCashOutRsp prepareCashOut(String unionId);
 
   ResultData cashOut(CashOutReq cashOutReq);
+
+  ResultData editCashOutState(CashOutRecordStateReq req);
 }

+ 42 - 2
ymall/src/main/java/com/liangjian11/ymall/service/impl/UserAccountProfitServiceImpl.java

@@ -10,6 +10,7 @@ import com.liangjian11.ymall.service.UserAccountProfitService;
 import com.liangjian11.ymall.service.thirdapi.MQMessageService;
 import com.liangjian11.ymall.utils.DataChangeUtil;
 import com.liangjian11.ymall.utils.ResultData;
+import com.liangjian11.ymall.view.CashOutRecordStateReq;
 import com.liangjian11.ymall.view.CashOutReq;
 import com.liangjian11.ymall.view.PrepareCashOutRsp;
 import org.apache.commons.lang.StringUtils;
@@ -70,6 +71,7 @@ public class UserAccountProfitServiceImpl extends ServiceImpl<UserAccountProfitM
 
 
   @Transactional(rollbackFor = Exception.class)
+  @Override
   public synchronized ResultData cashOut(CashOutReq cashOutReq) {
     //QueryWrapper<UserAccountProfit> profitQuery = new QueryWrapper<>();
     UserAccountProfit accountProfit = userAccountProfitMapper.selectById(cashOutReq.getAccountProfitId());
@@ -77,6 +79,8 @@ public class UserAccountProfitServiceImpl extends ServiceImpl<UserAccountProfitM
       return ResultData.getFailResult("未找到用户账户");
     if (!cashOutReq.getUnionid().equals(accountProfit.getUnionid()))
       return ResultData.getFailResult("用户账户与提交信息不匹配");
+    if(cashOutReq.getCashOutAmount()==null || cashOutReq.getCashOutAmount()<=0)
+      return ResultData.getFailResult("提现金额要大于0");
     if (!cashOutReq.getCashOutAmount().equals(accountProfit.getCurrentAmount()))
       return ResultData.getFailResult("提现金额与账户剩余金额不匹配");
     QueryWrapper<UserAccountBank> bankQuery = new QueryWrapper<>();
@@ -114,9 +118,46 @@ public class UserAccountProfitServiceImpl extends ServiceImpl<UserAccountProfitM
     }
     count= calculationProfitMapper.askForCashOut(cashOutRecord.getId(),actionTime,userId);
     //发送提现的消息队列
+    this.sendCashOutMQ(cashOutRecord,actionTime,profitList);
+    return ResultData.getSuccessResult("申请成功");
+  }
+
+  @Override
+  public ResultData editCashOutState(CashOutRecordStateReq req){
+    if(req.getId()==null|| req.getId()<=0)
+      return ResultData.getFailResult("id不能为空");
+    if(req.getState()==null)
+      return ResultData.getFailResult("state不能为空");
+    CashOutRecord cashOutRecord=new CashOutRecord();
+    cashOutRecord.setId(req.getId());
+    if(req.getState().equals(Short.valueOf("5"))){//拒绝提现
+      cashOutRecord.setState(req.getState());
+      cashOutRecord.setReviewRemarks(req.getReviewRemarks());
+      cashOutRecordMapper.updateById(cashOutRecord);
+    }else if(req.getState().equals(Short.valueOf("1"))){//从新发起钉钉审批
+      cashOutRecord.setState((short)2);
+      cashOutRecord.setProcessInstanceId("");
+      cashOutRecordMapper.updateById(cashOutRecord);
+      CashOutRecord existCashOutRecord=cashOutRecordMapper.selectById(req.getId());
+      List<CalculationProfit> profitList=calculationProfitMapper.getListOfCashOutId(req.getId());
+      this.sendCashOutMQ(existCashOutRecord,new Date(),profitList);
+    }else if(req.getState().equals(Short.valueOf("2"))){//审批中
+      cashOutRecord.setState(req.getState());
+      cashOutRecord.setProcessInstanceId(req.getProcessInstanceId());
+      cashOutRecordMapper.updateById(cashOutRecord);
+    }else {
+      cashOutRecord.setState(req.getState());
+      cashOutRecordMapper.updateById(cashOutRecord);
+    }
+    return ResultData.getSuccessResult("操作成功");
+  }
+
+  public void sendCashOutMQ(CashOutRecord cashOutRecord,Date cashOutTime,List<CalculationProfit> profitList){
+    if(cashOutRecord==null ||profitList==null || profitList.size()==0)
+      return;
     JSONObject mqJo=new JSONObject();
     mqJo.put("cashOutId",cashOutRecord.getId().toString());
-    mqJo.put("createTime",df.format(actionTime));
+    mqJo.put("createTime",df.format(cashOutTime));
     mqJo.put("userName",cashOutRecord.getUserName());
     mqJo.put("userPhone", DataChangeUtil.ljDecode(cashOutRecord.getUserPhone()));
     mqJo.put("amount",decimalFormat.format(cashOutRecord.getAmount()/100D));
@@ -134,7 +175,6 @@ public class UserAccountProfitServiceImpl extends ServiceImpl<UserAccountProfitM
     }
     mqJo.put("orderNews",jsonArray.toString());
     mqMessageService.sendCashOut(mqJo);
-    return ResultData.getSuccessResult("申请成功");
   }
 
 

+ 12 - 0
ymall/src/main/java/com/liangjian11/ymall/view/CashOutRecordStateReq.java

@@ -1,9 +1,13 @@
 package com.liangjian11.ymall.view;
 
 public class CashOutRecordStateReq {
+  /**
+   * 提现id
+   */
   private Integer id;
   private Short state;
   private String reviewRemarks;
+  private String processInstanceId;
 
   public Integer getId() {
     return id;
@@ -28,4 +32,12 @@ public class CashOutRecordStateReq {
   public void setReviewRemarks(String reviewRemarks) {
     this.reviewRemarks = reviewRemarks;
   }
+
+  public String getProcessInstanceId() {
+    return processInstanceId;
+  }
+
+  public void setProcessInstanceId(String processInstanceId) {
+    this.processInstanceId = processInstanceId;
+  }
 }

+ 4 - 0
ymall/src/main/resources/mapper/CalculationProfitMapper.xml

@@ -280,4 +280,8 @@
   <select id="getCanCashOut" resultMap="baseMap">
     SELECT * from calculation_profit WHERE status=1  and  account_id=#{accountId}  order by entry_time asc
   </select>
+
+  <select id="getListOfCashOutId" resultMap="baseMap">
+    select * from calculation_profit where cash_out_id=#{cashOutId}
+  </select>
 </mapper>