Commit a2da5974 authored by licc's avatar licc

上传返佣接口实现

parent 525ecf3c
...@@ -35,4 +35,11 @@ public interface AccountMapper extends BaseMapper<AccountInfo> { ...@@ -35,4 +35,11 @@ public interface AccountMapper extends BaseMapper<AccountInfo> {
*/ */
int delById(@Param("id") Integer id); int delById(@Param("id") Integer id);
/**
* 通过userId获取账户信息
* @param userId 用户id
* @return 账户信息
*/
AccountInfo getByUserId(@Param("userId") Integer userId);
} }
...@@ -29,4 +29,11 @@ public interface RebateMapper extends BaseMapper<Rebate> { ...@@ -29,4 +29,11 @@ public interface RebateMapper extends BaseMapper<Rebate> {
*/ */
int delById(@Param("id") Integer id); int delById(@Param("id") Integer id);
/**
* 获取会员等级对应的返佣比例
* @param userLevel 会员等级
* @return 返佣比例
*/
Rebate getByLevel(@Param("userLevel") Integer userLevel);
} }
...@@ -74,4 +74,14 @@ ...@@ -74,4 +74,14 @@
where id = #{id} where id = #{id}
</delete> </delete>
<select id="getByUserId" resultType="cn.wisenergy.model.app.AccountInfo">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -67,4 +67,14 @@ ...@@ -67,4 +67,14 @@
where id = #{id} where id = #{id}
</delete> </delete>
<select id="getByLevel" resultType="cn.wisenergy.model.app.Rebate">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_level=#{userLevel}
</where>
</select>
</mapper> </mapper>
...@@ -109,7 +109,7 @@ public class OrderInfo { ...@@ -109,7 +109,7 @@ public class OrderInfo {
* 返佣状态 * 返佣状态
*/ */
@ApiModelProperty(name = "rebateStatus", value = "返佣状态") @ApiModelProperty(name = "rebateStatus", value = "返佣状态")
private int rebateStatus; private Integer rebateStatus;
/** /**
* 当月订单处理状态 * 当月订单处理状态
......
...@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
/** /**
...@@ -32,7 +33,7 @@ public class Rebate implements Serializable { ...@@ -32,7 +33,7 @@ public class Rebate implements Serializable {
* 等级对应的返佣比例 * 等级对应的返佣比例
*/ */
@ApiModelProperty(name = "", value = "") @ApiModelProperty(name = "", value = "")
private Integer percent; private BigDecimal percent;
/** /**
* 创建时间 * 创建时间
......
...@@ -28,7 +28,7 @@ public class TradeRecord implements Serializable { ...@@ -28,7 +28,7 @@ public class TradeRecord implements Serializable {
* 用户id * 用户id
*/ */
@ApiModelProperty(name = "userId", value = "用户id") @ApiModelProperty(name = "userId", value = "用户id")
private Integer userId; private String userId;
/** /**
* 交易类型 1:提现 2:订单返佣 3:订单下单 4:月度肥料 5:培育奖 6:工资 * 交易类型 1:提现 2:订单返佣 3:订单下单 4:月度肥料 5:培育奖 6:工资
......
...@@ -2,17 +2,19 @@ package cn.wisenergy.service.app; ...@@ -2,17 +2,19 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AccountInfo; import cn.wisenergy.model.app.OrderInfo;
import java.util.List;
/** /**
* @author 86187 * @author 86187
*/ */
public interface AccountService { public interface AccountService {
R<AccountInfo> getById(Integer userId);
/** /**
* 返佣统计 * 订单返佣
* @return * @param list 订单信息
* @return true or false
*/ */
R<Boolean> rebateCount(); R<Boolean> orderRebate(List<OrderInfo> list);
} }
...@@ -2,14 +2,22 @@ package cn.wisenergy.service.app.impl; ...@@ -2,14 +2,22 @@ package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.utils.R; import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.AccountMapper; import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.mapper.RebateMapper;
import cn.wisenergy.mapper.UsersMapper;
import cn.wisenergy.model.app.AccountInfo; import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.OrderInfo;
import cn.wisenergy.model.app.Rebate;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.AccountService; import cn.wisenergy.service.app.AccountService;
import cn.wisenergy.service.common.AccountManager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
/** /**
...@@ -17,17 +25,55 @@ import org.springframework.stereotype.Service; ...@@ -17,17 +25,55 @@ import org.springframework.stereotype.Service;
*/ */
@Slf4j @Slf4j
@Service @Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper,AccountInfo>implements AccountService { public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo> implements AccountService {
@Autowired
private UsersMapper usersMapper;
@Autowired
private AccountMapper accountMapper;
@Autowired
private RebateMapper rebateMapper;
@Autowired
private AccountManager accountManager;
@Override @Override
public R<AccountInfo> getById(Integer userId) { public R<Boolean> orderRebate(List<OrderInfo> list) {
return null; log.info("shop-mall[]AccountServiceImpl[]orderRebate[]input.param.list:{}", list.size());
if (CollectionUtils.isEmpty(list)) {
return R.ok(0, true);
} }
@Override //遍历订单,返佣
public R<AccountInfo> rebateCount() { for (OrderInfo orderInfo : list) {
log.info("shop-mall[]AccountServiceImpl[]rebateCount"); //订单状态是未返佣,完成时间小于当前时间
return null; long successTime = orderInfo.getSuccessTime().getTime();
long time = System.currentTimeMillis();
if (orderInfo.getRebateStatus() == 0 && successTime <= time) {
//获取用户信息
User user = usersMapper.selectById(orderInfo.getBuyerId());
if (null == user) {
continue;
}
//获取账户信息
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
if (null == accountInfo) {
continue;
}
//获取返佣比例
Rebate rebate = rebateMapper.getByLevel(user.getUserLevel());
if (null == rebate) {
continue;
}
//修改订单状态为已返佣,账户可用金额增加
accountManager.updateOrderAddMoney(orderInfo, accountInfo, rebate);
}
}
return R.ok(0, true);
} }
} }
package cn.wisenergy.service.common;
import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.mapper.OrderMapper;
import cn.wisenergy.mapper.TradeRecordMapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.OrderInfo;
import cn.wisenergy.model.app.Rebate;
import cn.wisenergy.model.app.TradeRecord;
import io.undertow.security.idm.Account;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
/**
* @author 86187
* @ Description: 账户管理公共类
* @ Author : 86187
* @ Date : 2021/2/23 10:43
*/
@Component
@Slf4j
public class AccountManager {
@Autowired
private OrderMapper orderMapper;
@Autowired
private AccountMapper accountMapper;
@Autowired
private TradeRecordMapper recordMapper;
@Transactional(rollbackFor = Exception.class)
public Boolean updateOrderAddMoney(OrderInfo orderInfo, AccountInfo accountInfo, Rebate rebate) {
//1、计算返佣金额
BigDecimal bigDecimal = orderInfo.getPayment().multiply(rebate.getPercent());
BigDecimal extractMoney = accountInfo.getExtractMoney().add(bigDecimal);
accountInfo.setExtractMoney(extractMoney);
//2、修改订单返佣状态:已返佣 1
orderInfo.setRebateStatus(1);
int count = orderMapper.updateById(orderInfo);
if (count == 0) {
return false;
}
//3、增加账户可用金额
int sum = accountMapper.updateById(accountInfo);
//4、添加交易流水记录
TradeRecord tradeRecord = new TradeRecord();
tradeRecord.setUserId(orderInfo.getBuyerId());
tradeRecord.setTradeType(2);
tradeRecord.setTradeNo(orderInfo.getTid());
int number = recordMapper.add(tradeRecord);
if (number == 0) {
return false;
}
return true;
}
}
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