Commit b9749a7d authored by licc's avatar licc

钱包接口,提现记录接口实现

parent d9bae3fc
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.LastMonthAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
public interface LastAccountMapper extends BaseMapper<LastMonthAccount> {
/**
* 通过userId 和 yearMonth获取账户信息
*
* @param userId 用户id
* @param yearMonth 年月
* @return 账户信息
*/
LastMonthAccount getByUserIdAndTime(@Param("userId") String userId, @Param("yearMonth") String yearMonth);
}
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.TradeRecord;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.WithdrawalRecordVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
......@@ -44,5 +47,21 @@ public interface TradeRecordMapper extends BaseMapper<TradeRecord> {
* @param userId 用户id
* @return 用户交易列表
*/
List<TradeRecord> getByUserIdAndTime(@Param("userId") String userId,@Param("yearMonth") String yearMonth);
List<TradeRecord> getByUserIdAndTime(@Param("userId") String userId,@Param("yearMonth") Date yearMonth);
/**
* 获取不包括本月的六个月的累计收益
* @param userId 用户id
* @return 累计收益
*/
List<AccumulatedIncomeVo> getSixMonthIncome(@Param("userId") String userId);
/**
* 根据用户id 或 年月 ,获取用户本月交易提现列表
* @param userId 用户id
* @param yearMonth 年月
* @return 交易列表
*/
List<WithdrawalRecordVo> getWithdrawalRecord(@Param("userId") String userId, Date yearMonth);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wisenergy.mapper.LastAccountMapper">
<resultMap id="AccountMap" type="cn.wisenergy.model.app.LastMonthAccount">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="user_level" property="userLevel"/>
<result column="year_month" property="yearMonth"/>
<result column="extract_money" property="extractMoney"/>
<result column="earnings_month" property="earningsMonth"/>
<result column="frozen_money" property="frozenMoney"/>
<result column="earnings_total" property="earningsTotal"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
last_month_account_info
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
user_id,user_level,year_month,extract_money,earnings_month,frozen_money,earnings_total,create_time,update_time
</sql>
<sql id="vals">
#{userId},#{userLevel},#{yearMonth},#{extractMoney},#{earningsMonth},#{frozenMoney},
#{earningsTotal},now(),now()
</sql>
<sql id="updateCondition">
<if test="userId != null">user_id = #{userId},</if>
<if test="userLevel != null">user_level = #{userLevel},</if>
<if test="yearMonth != null">year_month =#{yearMonth},</if>
<if test="extractMoney != null">extract_money =#{extractMoney},</if>
<if test="earningsMonth != null">earnings_month =#{earningsMonth},</if>
<if test="frozenMoney != null">frozen_money =#{frozenMoney},</if>
<if test="earningsTotal != null">earnings_total =#{earningsTotal},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="id != null">id = #{id}</if>
<if test="userId != null">and user_id = #{userId}</if>
<if test="userLevel != null">and user_level = #{userLevel}</if>
<if test="yearMonth != null">and year_month =#{yearMonth}</if>
<if test="extractMoney != null">and extract_money =#{extractMoney}</if>
<if test="earningsMonth != null">and earnings_month =#{earningsMonth}</if>
<if test="frozenMoney != null">and frozen_money =#{frozenMoney}</if>
<if test="earningsTotal != null">and earnings_total =#{earningsTotal}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
<select id="getByUserIdAndTime" resultType="cn.wisenergy.model.app.LastMonthAccount">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
and year_month=#{yearMonth}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -90,8 +90,41 @@
from
<include refid="table"/>
<where>
user_id=#{userId}
and year_time=#{yearTime}
<if test="userId">
user_id=#{userId}
</if>
<if test="yearMonth != null">
AND(
YEAR(year_month) = YEAR(#{yearMonth})
AND MONTH(year_month) = MONTH(#{yearMonth}))
</if>
</where>
</select>
<select id="getSixMonthIncome" resultType="cn.wisenergy.model.vo.AccumulatedIncomeVo">
SELECT user_id as userId,sum(money) as income ,
date_format(create_time,'%Y-%m') as yearMonth
FROM
<include refid="table"/>
WHERE date_format(create_time,'%Y-%m') &lt; date_format(now(),'%Y-%m')
and date_format(create_time,'%Y-%m') >= date_format(now() - interval 7 month,'%Y-%m')
and (status=1 or status=3)
group by user_id ,create_time desc;
</select>
<select id="getWithdrawalRecord" resultType="cn.wisenergy.model.vo.WithdrawalRecordVo">
select user_id as userId, status as status, money as money, update_time as moneyTime
from
<include refid="table"/>
<where>
<if test="userId">
user_id=#{userId}
</if>
<if test="yearMonth != null">
AND(
YEAR(update_time) = YEAR(#{yearMonth})
AND MONTH(update_time) = MONTH(#{yearMonth}))
</if>
</where>
</select>
......
package cn.wisenergy.model.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
*@ Description: 上月账户实体类
*@ Author : 86187
*@ Date : 2021/3/3 11:24
* @author 86187
*/
@Data
@ApiModel
public class LastMonthAccount implements Serializable {
/**
* 账户主键id
*/
@ApiModelProperty(name = "id", value = "管理员主键id")
private Integer id;
/**
* 用户id
*/
@ApiModelProperty(name = "userId", value = "用户id")
private String userId;
/**
* 用户等级
*/
@ApiModelProperty(name = "userLevel", value = "用户等级")
private Integer userLevel;
/**
* 年月
*/
@ApiModelProperty(name = "yearMonth", value = "年月")
private String yearMonth;
/**
* 可提现金额
*/
@ApiModelProperty(name = "extractMoney", value = "可提现金额")
private BigDecimal extractMoney;
/**
* 本月收益
*/
@ApiModelProperty(name = "earningsMonth", value = "本月收益")
private BigDecimal earningsMonth;
/**
* 冻结金额
*/
@ApiModelProperty(name = "frozenMoney", value = "冻结金额")
private BigDecimal frozenMoney;
/**
* 累计收益
*/
@ApiModelProperty(name = "earningsTotal", value = "累计收益")
private BigDecimal earningsTotal;
/**
* 创建时间
*/
@ApiModelProperty(name = "createTime", value = "创建时间")
private Date createTime;
/**
* 修改时间
*/
@ApiModelProperty(name = "updateTime", value = "修改时间")
private Date updateTime;
}
......@@ -25,14 +25,21 @@ public class WithdrawalAmountVo {
/**
* 上月未提
*/
@ApiModelProperty(value = "上月未提",name = "lastMoneyNot")
@ApiModelProperty(value = "上月未提", name = "lastMoneyNot")
private BigDecimal lastMoneyNot;
/**
* 本月可提现
*/
@ApiModelProperty(value = "本月可提现",name = "currentMoneyCan")
@ApiModelProperty(value = "本月可提现", name = "currentMoneyCan")
private BigDecimal currentMoneyCan;
/**
* 提现规则
*/
@ApiModelProperty(value = "提现规则", name = "withdrawRule")
private String withdrawRule;
}
package cn.wisenergy.model.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
*@ Description: 提现记录Vo
*@ Author : 86187
*@ Date : 2021/3/3 14:51
* @author 86187
*/
@Data
@ApiModel("WithdrawalRecordVo")
public class WithdrawalRecordVo {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id",name = "userId")
private String userId;
/**
* 提现状态 2:银行处理中 3 :提现成功
*/
@ApiModelProperty(value = "提现状态 2:银行处理中 3 :提现成功",name = "status")
private Integer status;
/**
* 提现金额
*/
@ApiModelProperty(value = "提现金额",name = "money")
private BigDecimal money;
/**
* 提现时间
*/
@ApiModelProperty(value = "提现时间",name = "moneyTime")
private Date moneyTime;
}
package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.MoneyPackageDetailVo;
import cn.wisenergy.model.vo.MoneyPackageVo;
import cn.wisenergy.model.vo.WithdrawalAmountVo;
import cn.wisenergy.model.vo.*;
import java.util.List;
......@@ -46,4 +43,13 @@ public interface WalletService {
* @return 当月总收益
*/
R<MoneyPackageDetailVo> queryIncomeDetail(String userId);
/**
* 获取提现记录 userId 为空 查全部 不为空,查当前用户
*
* @param userId 用户唯一标识
* @param yearMonth 年月
* @return 提现记录列表
*/
R<List<WithdrawalRecordVo>> getWithdrawalRecord(String userId, String yearMonth);
}
......@@ -3,8 +3,10 @@ package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.mapper.LastAccountMapper;
import cn.wisenergy.mapper.TradeRecordMapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.LastMonthAccount;
import cn.wisenergy.model.app.TradeRecord;
import cn.wisenergy.model.enums.TradeRecordEnum;
import cn.wisenergy.model.vo.*;
......@@ -18,6 +20,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
......@@ -35,6 +38,9 @@ public class WalletServiceImpl implements WalletService {
@Autowired
private TradeRecordMapper tradeRecordMapper;
@Autowired
private LastAccountMapper lastAccountMapper;
@Override
public R<MoneyPackageVo> getMoneyPackage(String userId) {
......@@ -70,17 +76,29 @@ public class WalletServiceImpl implements WalletService {
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
WithdrawalAmountVo withdrawalAmountVo = new WithdrawalAmountVo();
withdrawalAmountVo.setUserId(userId);
//1、获取用户账户信息
AccountInfo accountInfo = accountMapper.getByUserIdAndTime(userId, yearMonth);
if (null == accountInfo) {
return R.error("用户账户信息不存在!");
withdrawalAmountVo.setCurrentMoneyCan(new BigDecimal(0));
} else {
withdrawalAmountVo.setCurrentMoneyCan(accountInfo.getExtractMoney());
}
WithdrawalAmountVo withdrawalAmountVo = new WithdrawalAmountVo();
withdrawalAmountVo.setUserId(userId);
withdrawalAmountVo.setCurrentMoneyCan(accountInfo.getExtractMoney());
//TODO 获取上月为提现
withdrawalAmountVo.setLastMoneyNot(new BigDecimal(0));
//2、 获取上月未提现
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MONTH, -1);
Date lastDate = cal.getTime();
String lastMonthTime = DateUtil.convertDateToStr(lastDate, PATTERN);
LastMonthAccount lastMonthAccount = lastAccountMapper.getByUserIdAndTime(userId, lastMonthTime);
if (null == lastMonthAccount) {
withdrawalAmountVo.setLastMoneyNot(new BigDecimal(0));
} else {
withdrawalAmountVo.setLastMoneyNot(lastMonthAccount.getExtractMoney());
}
return R.ok(withdrawalAmountVo);
}
......@@ -91,22 +109,9 @@ public class WalletServiceImpl implements WalletService {
return R.error("入参为空!");
}
List<TradeRecord> list = tradeRecordMapper.getByUserId(userId);
if (CollectionUtils.isEmpty(list)) {
return R.ok(new ArrayList<>());
}
List<AccumulatedIncomeVo> result = new ArrayList<>();
for (TradeRecord tradeRecord : list) {
AccumulatedIncomeVo incomeVo = new AccumulatedIncomeVo();
incomeVo.setUserId(tradeRecord.getUserId());
String yearMonth = DateUtil.convertDateToStr(tradeRecord.getCreateTime(), PATTERN);
incomeVo.setYearMonth(yearMonth);
incomeVo.setIncome(tradeRecord.getMoney());
result.add(incomeVo);
}
return R.ok(result);
//获取不包括本月在内的六个月的收益
List<AccumulatedIncomeVo> list = tradeRecordMapper.getSixMonthIncome(userId);
return R.ok(list);
}
@Override
......@@ -125,7 +130,7 @@ public class WalletServiceImpl implements WalletService {
}
//获取本月交易记录
List<TradeRecord> list = tradeRecordMapper.getByUserIdAndTime(userId, yearMonth);
List<TradeRecord> list = tradeRecordMapper.getByUserIdAndTime(userId, date);
if (CollectionUtils.isEmpty(list)) {
return R.ok(new MoneyPackageDetailVo());
}
......@@ -149,4 +154,16 @@ public class WalletServiceImpl implements WalletService {
return R.ok(detailVo);
}
@Override
public R<List<WithdrawalRecordVo>> getWithdrawalRecord(String userId, String yearMonth) {
log.info("shop-mall[]WalletServiceImpl[]queryIncomeDetail[]input.param.yearMonth:" + yearMonth);
if (StringUtils.isBlank(yearMonth)) {
return R.error("入参为空!");
}
Date date = DateUtil.convertStrToDate(yearMonth, PATTERN);
List<WithdrawalRecordVo> list = tradeRecordMapper.getWithdrawalRecord(userId, date);
return R.ok(list);
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.vo.AccumulatedIncomeVo;
import cn.wisenergy.model.vo.MoneyPackageDetailVo;
import cn.wisenergy.model.vo.MoneyPackageVo;
import cn.wisenergy.model.vo.WithdrawalAmountVo;
import cn.wisenergy.model.vo.*;
import cn.wisenergy.service.app.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -77,4 +75,19 @@ public class WalletController {
return walletService.queryIncomeDetail(userId);
}
@ApiOperation(value = "提现记录", notes = "提现记录", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "String"),
@ApiImplicitParam(name = "yearMonth", value = "时间(yyyy-MM-dd)", dataType = "String", required = true)
})
@GetMapping("/getWithdrawalRecord")
public R<List<WithdrawalRecordVo>> getWithdrawalRecord(String userId, String yearMonth) {
log.info("shop-mall[]WalletController[]getWithdrawalRecord[]input.param.userId:{},yearMonth:" + userId, yearMonth);
if (StringUtils.isBlank(yearMonth)) {
return R.error("入参不能为空!");
}
return walletService.getWithdrawalRecord(userId, yearMonth);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment