package com.yeshi.makemoney.app.utils.factory;
|
|
import com.ks.lib.common.exception.ParamsException;
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord;
|
import com.yeshi.makemoney.app.entity.money.Extract;
|
import com.yeshi.makemoney.app.entity.money.UserMoneyRecord;
|
import com.yeshi.makemoney.app.entity.money.UserMoneyType;
|
import com.yeshi.makemoney.app.entity.user.UserInfo;
|
import org.yeshi.utils.StringUtil;
|
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.Date;
|
|
/**
|
* @author hxh
|
* @title: UserMoneyRecordFactory
|
* @description: 用户资金记录工厂
|
* @date 2022/4/1 17:57
|
*/
|
public class UserMoneyRecordFactory {
|
|
public static UserMoneyRecord createExtract(Extract extract) throws ParamsException {
|
if (extract == null) {
|
throw new ParamsException(1, "提现记录不能为空");
|
}
|
if (extract.getId() == null) {
|
throw new ParamsException(1, "提现记录主键不能为空");
|
}
|
if (extract.getMoney() == null) {
|
throw new ParamsException(1, "提现金额不能为空");
|
}
|
if (extract.getUser() == null || extract.getUser().getId() == null) {
|
throw new ParamsException(1, "提现用户不能为空");
|
}
|
|
UserMoneyRecord detail = new UserMoneyRecord();
|
detail.setCreateTime(new Date());
|
detail.setSerialNo(UserMoneyType.extract.name() + "_" + extract.getId());
|
detail.setMoney(new BigDecimal("0").subtract(extract.getMoney()));
|
detail.setType(UserMoneyType.extract);
|
detail.setUpdateTime(new Date());
|
detail.setUser(extract.getUser());
|
detail.setShow(false);
|
detail.setAdd(false);
|
return detail;
|
}
|
|
|
public static UserMoneyRecord createExtractReject(Extract extract) throws ParamsException {
|
if (extract == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现记录不能为空");
|
}
|
if (extract.getId() == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现记录主键不能为空");
|
}
|
if (extract.getMoney() == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现金额不能为空");
|
}
|
if (extract.getUser() == null || extract.getUser().getId() == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "提现用户不能为空");
|
}
|
UserMoneyRecord detail = new UserMoneyRecord();
|
detail.setCreateTime(new Date());
|
detail.setSerialNo(UserMoneyType.extractReject.name().toLowerCase() + "_" + extract.getId());
|
detail.setMoney(extract.getMoney());
|
detail.setType(UserMoneyType.extractReject);
|
detail.setUpdateTime(new Date());
|
detail.setUser(extract.getUser());
|
// 隐藏提现失败记录
|
detail.setShow(false);
|
detail.setAdd(true);
|
return detail;
|
}
|
|
|
public static UserMoneyRecord createGoldCornExchange(GoldCornConsumeRecord record) throws ParamsException {
|
if (record == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "金币兑换记录不能为空");
|
}
|
if (record.getId() == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "金币兑换记录主键不能为空");
|
}
|
if (record.getMoney() == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "兑换金额不能为空");
|
}
|
if (record.getUid() == null) {
|
throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "兑换用户不能为空");
|
}
|
UserMoneyRecord detail = new UserMoneyRecord();
|
detail.setCreateTime(new Date());
|
detail.setSerialNo(UserMoneyType.goldCorn.name().toLowerCase() + "_" + record.getId());
|
detail.setMoney(new BigDecimal(record.getMoney()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR));
|
detail.setType(UserMoneyType.goldCorn);
|
detail.setUpdateTime(new Date());
|
detail.setUser(new UserInfo(record.getUid()));
|
detail.setShow(true);
|
detail.setAdd(true);
|
return detail;
|
}
|
|
|
}
|