Selaa lähdekoodia

Merge branch 'dev' into 'mp-server-test'

提现列表

See merge request quanshu/mp-server!234
zhong chunping 3 vuotta sitten
vanhempi
commit
9fcc0f2f57

+ 99 - 0
mp-admin/src/main/java/com/qs/mp/web/controller/api/admin/ChannelWithdrawMgrController.java

@@ -0,0 +1,99 @@
+package com.qs.mp.web.controller.api.admin;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qs.mp.channel.domain.ChannelOrder;
+import com.qs.mp.channel.domain.ChannelOrderItem;
+import com.qs.mp.channel.domain.ChannelWithdraw;
+import com.qs.mp.channel.domain.vo.ChannelOrderVO;
+import com.qs.mp.channel.domain.vo.ChannelWithdrawVO;
+import com.qs.mp.channel.service.IChannelOrderItemService;
+import com.qs.mp.channel.service.IChannelOrderService;
+import com.qs.mp.channel.service.IChannelWithdrawService;
+import com.qs.mp.common.core.domain.AjaxResult;
+import com.qs.mp.common.core.page.TableDataInfo;
+import com.qs.mp.common.core.redis.RedisCache;
+import com.qs.mp.common.enums.ChannelWithdrawStatusEnum;
+import com.qs.mp.common.enums.ErrorCodeEnum;
+import com.qs.mp.common.utils.DateUtils;
+import com.qs.mp.web.controller.common.BaseApiController;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import java.util.Date;
+import java.util.List;
+import lombok.AllArgsConstructor;
+import ma.glasnost.orika.MapperFacade;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+@RestController
+@RequestMapping("/api/v1/admin/channel/withdraw")
+@Api(tags = "渠道提现申请管理接口")
+@AllArgsConstructor
+public class ChannelWithdrawMgrController extends BaseApiController {
+
+  @Autowired
+  private IChannelWithdrawService channelWithdrawService;
+
+  @Autowired
+  private MapperFacade mapperFacade;
+
+  /**
+   * 提现申请列表
+   */
+  @PostMapping("/list")
+  @ApiOperation(value = "提现申请列表" , notes = "获取所有提现信息")
+  public TableDataInfo list(@RequestBody JSONObject param) {
+    Integer status = param.getInteger("status");
+    String name = param.getString("name");
+    Date startDay = param.getDate("startDay");
+    Date endDay = param.getDate("endDay");
+    startPage();
+    List<ChannelWithdrawVO> withdrawList = channelWithdrawService.listWithdrawVO(new QueryWrapper<ChannelWithdraw>()
+        .eq(null != status && status != 0, "t1.status", status)
+        .eq(StringUtils.isNotBlank(name), "t2.name", name)
+        .ge(null != startDay, "t1.created_time", startDay)
+        .lt(null != endDay, "t1.created_time", DateUtils.addDays(endDay, 1))
+        .orderByDesc("t1.created_time"));
+    return getDataTable(withdrawList);
+  }
+
+  /**
+   * 提现申请详情
+   */
+  @PostMapping("/detail")
+  @ApiOperation(value = "申请详情" , notes = "在提现列表页面查看详情")
+  public AjaxResult query(@RequestBody JSONObject param) {
+    Long id = param.getLong("id");
+    if (null == id || 0 == id) {
+      return error(ErrorCodeEnum.ERROR_CODE_1001);
+    }
+    List<ChannelWithdrawVO> withdrawList = channelWithdrawService.listWithdrawVO(new QueryWrapper<ChannelWithdraw>()
+        .eq("t1.id", id));
+    return AjaxResult.success(withdrawList.get(0));
+  }
+
+  /**
+   * 提现申请审核结果
+   */
+  @PostMapping("/verify")
+  @ApiOperation(value = "申请审核" , notes = "在提现详情页面审核")
+  public AjaxResult verify(@RequestBody ChannelWithdraw withdraw) {
+    if (null == withdraw.getId() || null == withdraw.getStatus()) {
+      return error(ErrorCodeEnum.ERROR_CODE_1001);
+    }
+    ChannelWithdraw channelWithdraw = channelWithdrawService.getById(withdraw.getId());
+    if (channelWithdraw.getStatus() != ChannelWithdrawStatusEnum.WITHDRAWING) {
+      return error("提现申请状态异常,不是提现中");
+    }
+    channelWithdrawService.verify(channelWithdraw, withdraw.getStatus(), withdraw.getVerifyContent());
+    return AjaxResult.success("操作成功");
+  }
+
+}

+ 3 - 2
mp-common/src/main/java/com/qs/mp/common/enums/ChannelMoneyEnum.java

@@ -11,10 +11,11 @@ import com.baomidou.mybatisplus.annotation.IEnum;
 public enum ChannelMoneyEnum implements IEnum<Integer> {
 
   COMMISSION(1, "佣金收入"),
-  WITHDRAW(2, "提现"),
+  WITHDRAW(2, "余额提现"),
   WITHDRAW_FEE(3, "提现手续费"),
   PURCHASE(4, "进票"),
-  COUPON(5, "优惠券核销结算");
+  COUPON(5, "优惠券核销结算"),
+  WITHDRAW_BACK(6, "余额提现退回");
 
 
   private final int value;

+ 1 - 1
mp-common/src/main/java/com/qs/mp/common/enums/ChannelWithdrawStatusEnum.java

@@ -26,7 +26,7 @@ public enum ChannelWithdrawStatusEnum implements IEnum<Integer> {
     this.desc = desc;
   }
 
-  public static ChannelWithdrawStatusEnum getChannelMoneyTypeEnum(int value) {
+  public static ChannelWithdrawStatusEnum getChannelWithdrawStatusEnum(int value) {
     for (ChannelWithdrawStatusEnum channelMoneyTypeEnum : ChannelWithdrawStatusEnum.values()) {
       if (channelMoneyTypeEnum.getValue() == value) {
         return channelMoneyTypeEnum;

+ 6 - 0
mp-service/src/main/java/com/qs/mp/channel/domain/ChannelWithdraw.java

@@ -92,6 +92,12 @@ public class ChannelWithdraw implements Serializable {
   @TableField("transfer_img")
   private String transferImg;
 
+  /**
+   * 转账时间
+   */
+  @TableField("transfer_time")
+  private Date transferTime;
+
   /**
    * 审核内容备注
    */

+ 27 - 0
mp-service/src/main/java/com/qs/mp/channel/domain/vo/ChannelWithdrawVO.java

@@ -0,0 +1,27 @@
+package com.qs.mp.channel.domain.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.qs.mp.channel.domain.ChannelWithdraw;
+import lombok.Data;
+
+/**
+ * @author zhongcp
+ * @Date 2022/3/21
+ */
+@Data
+public class ChannelWithdrawVO extends ChannelWithdraw {
+  /**
+   * 渠道名称
+   */
+  private String name;
+
+  /**
+   * 渠道级别,0:经销商;1:一级渠道;2:二级渠道
+   */
+  private Integer level;
+
+  /**
+   * 手机号
+   */
+  private String mobile;
+}

+ 8 - 1
mp-service/src/main/java/com/qs/mp/channel/mapper/ChannelWithdrawMapper.java

@@ -1,7 +1,14 @@
 package com.qs.mp.channel.mapper;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.qs.mp.channel.domain.ChannelCart;
 import com.qs.mp.channel.domain.ChannelWithdraw;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qs.mp.channel.domain.vo.ChannelCartVO;
+import com.qs.mp.channel.domain.vo.ChannelWithdrawVO;
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * @auther quanshu
@@ -9,5 +16,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @describe 渠道提现表mapper类
  */
 public interface ChannelWithdrawMapper extends BaseMapper<ChannelWithdraw> {
-
+  List<ChannelWithdrawVO> listWithdrawVO(@Param(Constants.WRAPPER) Wrapper<ChannelWithdraw> queryWrapper);
 }

+ 22 - 0
mp-service/src/main/java/com/qs/mp/channel/service/IChannelWithdrawService.java

@@ -1,8 +1,14 @@
 package com.qs.mp.channel.service;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.ChannelWithdraw;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qs.mp.channel.domain.vo.ChannelWithdrawVO;
+import com.qs.mp.common.enums.ChannelWithdrawStatusEnum;
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -21,4 +27,20 @@ public interface IChannelWithdrawService extends IService<ChannelWithdraw> {
    * @return
    */
   boolean apply(Channel channel, ChannelWithdraw channelWithdraw);
+
+  /**
+   * 查询提现申请记录
+   * @param queryWrapper
+   * @return
+   */
+  List<ChannelWithdrawVO> listWithdrawVO(Wrapper<ChannelWithdraw> queryWrapper);
+
+  /**
+   * 提现申请审核
+   * @param withdraw
+   * @param status
+   * @param verifyContent
+   * @return
+   */
+  boolean verify(ChannelWithdraw withdraw, ChannelWithdrawStatusEnum status, String verifyContent);
 }

+ 3 - 2
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelMoneyLogServiceImpl.java

@@ -65,7 +65,8 @@ public class ChannelMoneyLogServiceImpl extends ServiceImpl<ChannelMoneyLogMappe
 
     //1、更新渠道余额表
     boolean rtn = channelService.update(new LambdaUpdateWrapper<Channel>().set(Channel::getMoney, money)
-            .set(ChannelMoneyEnum.WITHDRAW == moneyLog.getType() || ChannelMoneyEnum.WITHDRAW_FEE == moneyLog.getType(), Channel::getFrozenMoney, channel.getFrozenMoney() + logMoney)
+        .set(ChannelMoneyEnum.WITHDRAW == moneyLog.getType() || ChannelMoneyEnum.WITHDRAW_FEE == moneyLog.getType(), Channel::getFrozenMoney, channel.getFrozenMoney() + logMoney)
+        .set(ChannelMoneyEnum.WITHDRAW_BACK == moneyLog.getType(), Channel::getFrozenMoney, channel.getFrozenMoney() - logMoney)
         .eq(Channel::getChannelId, channel.getChannelId()).eq(Channel::getMoney, channel.getMoney()));
     Assert.isTrue(rtn, "渠道余额更新失败,channelId:" + channel.getChannelId());
 
@@ -81,7 +82,7 @@ public class ChannelMoneyLogServiceImpl extends ServiceImpl<ChannelMoneyLogMappe
 
   private boolean checkIncome(ChannelMoneyEnum bizType){
     //判断收支类型是否符合预定义类型
-    if(ChannelMoneyEnum.COMMISSION == bizType){
+    if(ChannelMoneyEnum.COMMISSION == bizType || ChannelMoneyEnum.COUPON == bizType || ChannelMoneyEnum.WITHDRAW_BACK == bizType){
       return true;
     }else if(ChannelMoneyEnum.WITHDRAW == bizType || ChannelMoneyEnum.WITHDRAW_FEE == bizType
     || ChannelMoneyEnum.PURCHASE == bizType ){

+ 56 - 0
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelWithdrawServiceImpl.java

@@ -1,11 +1,13 @@
 package com.qs.mp.channel.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.ChannelBankCard;
 import com.qs.mp.channel.domain.ChannelMoneyLog;
 import com.qs.mp.channel.domain.ChannelWithdraw;
+import com.qs.mp.channel.domain.vo.ChannelWithdrawVO;
 import com.qs.mp.channel.mapper.ChannelWithdrawMapper;
 import com.qs.mp.channel.service.IChannelBankCardService;
 import com.qs.mp.channel.service.IChannelMoneyLogService;
@@ -13,10 +15,14 @@ import com.qs.mp.channel.service.IChannelService;
 import com.qs.mp.channel.service.IChannelWithdrawService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qs.mp.common.enums.ChannelMoneyEnum;
+import com.qs.mp.common.enums.ChannelWithdrawStatusEnum;
+import com.qs.mp.common.utils.LogUtil;
 import java.util.Date;
+import java.util.List;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
 
 /**
  * <p>
@@ -84,4 +90,54 @@ public class ChannelWithdrawServiceImpl extends ServiceImpl<ChannelWithdrawMappe
     // 创建提现记录
     return rst;
   }
+
+  @Override
+  public List<ChannelWithdrawVO> listWithdrawVO(Wrapper<ChannelWithdraw> queryWrapper) {
+    return getBaseMapper().listWithdrawVO(queryWrapper);
+  }
+
+  @Override
+  @Transactional
+  public boolean verify(ChannelWithdraw withdraw, ChannelWithdrawStatusEnum status, String verifyContent) {
+    if (status == ChannelWithdrawStatusEnum.FINISHED) {
+      boolean rtn = update(new LambdaUpdateWrapper<ChannelWithdraw>()
+          .set(ChannelWithdraw::getStatus, status)
+          .set(ChannelWithdraw::getTransferTime, new Date())
+          .eq(ChannelWithdraw::getId, withdraw.getId())
+          .eq(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAWING));
+      Assert.isTrue(rtn, "提现申请审核通过,更新提现申请状态失败。id:" + withdraw.getId());
+
+      // 更新冻结金额
+      Channel channel = channelService.getById(withdraw.getChannelId());
+      Assert.isTrue(channel.getFrozenMoney() >= withdraw.getMoney() + withdraw.getChargeAmt(),
+          "提现申请审核通过,更新冻结金额时冻结金额为:" + channel.getFrozenMoney() + ",本次要释放冻结金额为:" + withdraw.getMoney() + withdraw.getChargeAmt());
+
+      boolean updateRtn = channelService.update(new LambdaUpdateWrapper<Channel>()
+          .set(Channel::getFrozenMoney, channel.getFrozenMoney() - withdraw.getMoney() - withdraw.getChargeAmt())
+          .eq(Channel::getChannelId, withdraw.getChannelId())
+          .eq(Channel::getFrozenMoney, channel.getFrozenMoney()));
+      Assert.isTrue(updateRtn, "提现申请审核通过,更新账号冻结金额。channelId:" + channel.getChannelId());
+    } else if (status == ChannelWithdrawStatusEnum.FAILED) {
+      boolean rtn = update(new LambdaUpdateWrapper<ChannelWithdraw>()
+          .set(ChannelWithdraw::getStatus, status)
+          .set(ChannelWithdraw::getVerifyContent, verifyContent)
+          .eq(ChannelWithdraw::getId, withdraw.getId())
+          .eq(ChannelWithdraw::getStatus, ChannelWithdrawStatusEnum.WITHDRAWING));
+      Assert.isTrue(rtn, "提现申请审核不通过,更新提现申请状态失败。id:" + withdraw.getId());
+
+      // 退回冻结金额
+      Channel channel = channelService.getById(withdraw.getChannelId());
+      Assert.isTrue(channel.getFrozenMoney() >= withdraw.getMoney() + withdraw.getChargeAmt(),
+          "提现申请审核不通过,解冻冻结金额时冻结金额为:" + channel.getFrozenMoney() + ",本次要解冻金额为:" + withdraw.getMoney() + withdraw.getChargeAmt());
+      ChannelMoneyLog moneyLog = new ChannelMoneyLog();
+      moneyLog.setChannelId(channel.getChannelId());
+      moneyLog.setType(ChannelMoneyEnum.WITHDRAW_BACK);
+      moneyLog.setLogMoney(withdraw.getMoney() + withdraw.getChargeAmt());
+      moneyLog.setBizTime(new Date());
+      moneyLog.setRefId(String.valueOf(withdraw.getId()));
+      moneyLog.setLogText(null);
+      channelMoneyLogService.changeMoney(moneyLog);
+    }
+    return true;
+  }
 }

+ 9 - 1
mp-service/src/main/resources/mapper/channel/ChannelWithdrawMapper.xml

@@ -16,6 +16,7 @@
         <result column="branch_name" property="branchName" />
         <result column="status" property="status" />
         <result column="transfer_img" property="transferImg" />
+        <result column="transfer_time" property="transferTime" />
         <result column="verify_content" property="verifyContent" />
         <result column="verifier" property="verifier" />
         <result column="create_time" property="createTime" />
@@ -24,7 +25,14 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, channel_id, money, charge_amt, available_money, pay_type, user_name, card_no, bank_name, branch_name, status, transfer_img, verify_content, verifier, create_time, update_time
+        id, channel_id, money, charge_amt, available_money, pay_type, user_name, card_no, bank_name, branch_name, status, transfer_img, transfer_time, verify_content, verifier, create_time, update_time
     </sql>
 
+    <select id="listWithdrawVO" resultType="com.qs.mp.channel.domain.vo.ChannelWithdrawVO">
+        select t1.*, t2.name, t2.level, t2.mobile
+        from mp_channel_withdraw t1
+                 left join mp_channel t2 on t1.channel_id = t2.channel_id
+            ${ew.customSqlSegment}
+    </select>
+
 </mapper>