提交 277a8cbb 作者: xiaowang

用户钱包

上级 47feccc6
package com.mmc.iuav.user.model.dto.wallet;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author 作者 lw
* @version 创建时间:2023.08.18 下午13:31:12
* @explain 类说明
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PayWalletDTO implements Serializable {
private static final long serialVersionUID = 75097833899496576L;
@ApiModelProperty(value = "id")
private Integer id;
@ApiModelProperty(value = "用户ID")
private Integer userAccountId;
@ApiModelProperty(value = "用户姓名")
private String userName;
@ApiModelProperty(value = "云享金余额")
private BigDecimal cashAmt;
@ApiModelProperty(value = "已消耗云享金")
private BigDecimal cashPaid;
@ApiModelProperty(value = "云享金总金额")
private BigDecimal totalCash;
@ApiModelProperty(value = "已冻结云享金")
private BigDecimal cashFreeze;
@ApiModelProperty(value = "佣金余额")
private BigDecimal salaryAmt;
@ApiModelProperty(value = "已消耗佣金")
private BigDecimal salaryPaid;
@ApiModelProperty(value = "已冻结佣金")
private BigDecimal salaryFreeze;
@ApiModelProperty(value = "佣金总额度")
private BigDecimal totalSalary;
@ApiModelProperty(value = "已提现的金额")
private BigDecimal rebateWdl;
@ApiModelProperty(value = "冻结总额")
private BigDecimal totalFreeze;
@ApiModelProperty(value = "总金额")
private BigDecimal totalAmount;
public void mathTotal() {
// 总冻结余额
this.totalFreeze = BigDecimal.ZERO;
if (this.cashFreeze != null) {
this.totalFreeze = this.totalFreeze.add(this.cashFreeze);
}
if (this.salaryFreeze != null) {
this.totalFreeze = this.totalFreeze.add(this.salaryFreeze);
}
// 总云享金余额
this.totalCash = BigDecimal.ZERO;
if (this.cashAmt != null) {
this.totalCash = this.totalCash.add(this.cashAmt);
}
if (this.cashFreeze != null) {
this.totalCash = this.totalCash.add(this.cashFreeze);
}
// 总佣金余额
this.totalSalary = BigDecimal.ZERO;
if (this.salaryAmt != null) {
this.totalSalary = this.totalSalary.add(this.salaryAmt);
}
if (this.salaryFreeze != null) {
this.totalSalary = this.totalSalary.add(this.salaryFreeze);
}
// 总金额
this.totalAmount = BigDecimal.ZERO;
this.totalAmount = this.totalAmount.add(this.totalCash);
this.totalAmount = this.totalAmount.add(this.totalSalary);
}
}
package com.mmc.iuav.user.controller.wallet;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.controller.BaseController;
import com.mmc.iuav.user.model.dto.wallet.PayWalletDTO;
import com.mmc.iuav.user.service.wallet.PayWalletService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* @Author LW
* @date 2023/8/18 11:33
* 概要:
*/
@Api(tags = "V1.0.3-用户钱包-相关接口")
@RequestMapping("/pay/")
@RestController
public class PayWalletController extends BaseController {
@Resource
PayWalletService payWalletService;
@ApiOperation(value = "获取当前用户消费(钱包)信息")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = PayWalletDTO.class)})
@GetMapping("getCurrentUserPayWalletInfo")
public ResultBody getCurrentUserPayWalletInfo(HttpServletRequest request) {
return payWalletService.getPayWalletInfo(this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
@ApiOperation(value = "获取用户消费(钱包)信息")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = PayWalletDTO.class)})
@GetMapping("getPayWalletInfo")
public ResultBody getPayWalletInfo(
@ApiParam(value = "用户userAccountId", required = true) @RequestParam Integer userAccountId) {
return ResultBody.success(payWalletService.getPayWalletInfo(userAccountId));
}
@ApiOperation(value = "feign-初始化钱包")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@ApiIgnore
@GetMapping("feignInitPayWallet")
public ResultBody feignInitPayWallet(@RequestParam Integer userAccountId) {
return payWalletService.initPayWallet(userAccountId);
}
}
package com.mmc.iuav.user.dao.wallet;
import com.mmc.iuav.user.entity.wallet.PayWalletDO;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author LW
* @date 2023/8/18 11:37
* 概要:
*/
@Mapper
public interface PayWalletDao {
PayWalletDO getPayWalletByUser(Integer userAccountId);
void insertPayWalletInfo(PayWalletDO wallet);
}
package com.mmc.iuav.user.entity.wallet;
import java.io.Serializable;
import java.util.Date;
/**
* 现金流水表(PayLogDO)实体类
*
* @author makejava
* @since 2023-08-18 16:18:01
*/
public class PayLogDO implements Serializable {
private static final long serialVersionUID = 752682324297846133L;
private Integer id;
/**
* 支付人的userId
*/
private Integer userAccountId;
/**
* 订单编号
*/
private Integer orderNo;
/**
* 支付流水号(T202109031615XXXX)XXXX随机数
*/
private String payNo;
/**
* 0手动变更(大于0充值or小于0扣除) 100订单扣除 150订单冻结 200订单完成 250提现扣除
*/
private Integer payMethod;
/**
* 云享金变动金额(正数充值,负数扣除)
*/
private Double cashAmtPaid;
/**
* 佣金变动金额(正数入账,负数扣除)
*/
private Double salaryAmtPaid;
/**
* 支付时间
*/
private Date payTime;
/**
* 备注
*/
private String remark;
/**
* 操作用户id
*/
private Integer operateUser;
private Date createTime;
private Date updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserAccountId() {
return userAccountId;
}
public void setUserAccountId(Integer userAccountId) {
this.userAccountId = userAccountId;
}
public Integer getOrderNo() {
return orderNo;
}
public void setOrderNo(Integer orderNo) {
this.orderNo = orderNo;
}
public String getPayNo() {
return payNo;
}
public void setPayNo(String payNo) {
this.payNo = payNo;
}
public Integer getPayMethod() {
return payMethod;
}
public void setPayMethod(Integer payMethod) {
this.payMethod = payMethod;
}
public Double getCashAmtPaid() {
return cashAmtPaid;
}
public void setCashAmtPaid(Double cashAmtPaid) {
this.cashAmtPaid = cashAmtPaid;
}
public Double getSalaryAmtPaid() {
return salaryAmtPaid;
}
public void setSalaryAmtPaid(Double salaryAmtPaid) {
this.salaryAmtPaid = salaryAmtPaid;
}
public Date getPayTime() {
return payTime;
}
public void setPayTime(Date payTime) {
this.payTime = payTime;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Integer getOperateUser() {
return operateUser;
}
public void setOperateUser(Integer operateUser) {
this.operateUser = operateUser;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
package com.mmc.iuav.user.entity.wallet;
import com.mmc.iuav.user.model.dto.wallet.PayWalletDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 用户钱包(PayWalletDO)实体类
*
* @author makejava
* @since 2023-08-18 13:23:57
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PayWalletDO implements Serializable {
private static final long serialVersionUID = 234037599702985920L;
private Integer id;
/**
* 版本号
*/
private Integer pid;
private Integer userAccountId;
/**
* 云享金余额
*/
private BigDecimal cashAmt;
/**
* 已付云享金
*/
private BigDecimal cashPaid;
/**
* 已冻结云享金
*/
private BigDecimal cashFreeze;
/**
* 佣金余额
*/
private BigDecimal salaryAmt;
/**
* 已付佣金
*/
private BigDecimal salaryPaid;
/**
* 已冻结佣金
*/
private BigDecimal salaryFreeze;
/**
* 提现总额
*/
private BigDecimal salaryWdl;
private Date createTime;
private Date updateTime;
public PayWalletDTO buildPayWalletDTO() {
return PayWalletDTO.builder().id(this.id).userAccountId(this.userAccountId)
.cashAmt(this.cashAmt).cashFreeze(this.cashFreeze)
.cashPaid(this.cashPaid).salaryAmt(this.salaryAmt)
.salaryFreeze(this.salaryFreeze).salaryPaid(this.salaryPaid)
.rebateWdl(this.salaryWdl).build();
}
public void defaultValue() {
this.cashAmt = BigDecimal.ZERO;
this.cashPaid = BigDecimal.ZERO;
this.cashFreeze = BigDecimal.ZERO;
this.salaryAmt = BigDecimal.ZERO;
this.salaryPaid = BigDecimal.ZERO;
this.salaryFreeze = BigDecimal.ZERO;
this.salaryWdl = BigDecimal.ZERO;
}
}
package com.mmc.iuav.user.service.wallet;
import com.mmc.iuav.response.ResultBody;
/**
* @Author LW
* @date 2023/8/18 11:36
* 概要:
*/
public interface PayWalletService {
ResultBody getPayWalletInfo(Integer userAccountId);
ResultBody initPayWallet(Integer userAccountId);
}
package com.mmc.iuav.user.service.wallet.impl;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.dao.wallet.PayWalletDao;
import com.mmc.iuav.user.entity.wallet.PayWalletDO;
import com.mmc.iuav.user.model.dto.wallet.PayWalletDTO;
import com.mmc.iuav.user.service.wallet.PayWalletService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @Author LW
* @date 2023/8/18 11:36
* 概要:
*/
@Service
public class PayWalletServiceImpl implements PayWalletService {
@Resource
PayWalletDao payWalletDao;
@Override
public ResultBody getPayWalletInfo(Integer userAccountId) {
PayWalletDO wallet = payWalletDao.getPayWalletByUser(userAccountId);
if (wallet == null) {
return null;
}
PayWalletDTO pd = wallet.buildPayWalletDTO();
pd.mathTotal();
return ResultBody.success(pd);
}
@Override
public ResultBody initPayWallet(Integer userAccountId) {
PayWalletDO wallet = new PayWalletDO();
wallet.defaultValue();
wallet.setUserAccountId(userAccountId);
payWalletDao.insertPayWalletInfo(wallet);
return ResultBody.success();
}
}
<?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="com.mmc.iuav.user.dao.wallet.PayWalletDao">
<insert id="insertPayWalletInfo">
insert into pay_wallet
(user_account_id, cash_amt, cash_paid, cash_freeze, salary_amt,
salary_paid, salary_freeze, salary_wdl)
values (#{userAccountId}, #{cashAmt}, #{cashPaid}, #{cashFreeze}, #{salaryAmt}, #{salaryPaid}, #{salaryFreeze},
#{salaryWdl})
</insert>
<select id="getPayWalletByUser" resultType="com.mmc.iuav.user.entity.wallet.PayWalletDO">
select id,
pid,
user_account_id,
cash_amt,
cash_paid,
cash_freeze,
salary_amt,
salary_paid,
salary_freeze,
salary_wdl,
create_time
from pay_wallet
where user_account_id = #{userAccountId}
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论