会员积分代码提交
This commit is contained in:
@@ -87,8 +87,8 @@ public class MemberPointsController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("payedDeductPoints")
|
@PostMapping("payedDeductPoints")
|
||||||
public CzgResult<Boolean> deductPoints(@RequestBody PayedDeductPointsParam param) {
|
public CzgResult<Boolean> deductPoints(@RequestBody PayedDeductPointsParam param) {
|
||||||
boolean ret = memberPointsService.deductPoints(param.getUserId(), param.getPoints(), param.getContent(), param.getOrderId());
|
//boolean ret = memberPointsService.deductPoints(param.getUserId(), param.getPoints(), param.getContent(), param.getOrderId());
|
||||||
return CzgResult.success(ret);
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,7 +96,7 @@ public class MemberPointsController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("consumeAwardPoints")
|
@PostMapping("consumeAwardPoints")
|
||||||
public CzgResult<Void> consumeAwardPoints(@RequestBody ConsumeAwardPointsParam param) {
|
public CzgResult<Void> consumeAwardPoints(@RequestBody ConsumeAwardPointsParam param) {
|
||||||
memberPointsService.consumeAwardPoints(param.getUserId(), param.getOrderId());
|
//memberPointsService.consumeAwardPoints(param.getUserId(), param.getOrderId());
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,10 @@ public class UMemberPointsController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 003-根据积分计算可抵扣金额
|
* 003-根据积分计算可抵扣金额
|
||||||
* @param userId 用户id
|
*
|
||||||
* @param orderAmount 订单金额
|
* @param userId 用户id
|
||||||
* @param points 使用积分
|
* @param orderAmount 订单金额
|
||||||
|
* @param points 使用积分
|
||||||
*/
|
*/
|
||||||
@GetMapping("calcDeductionAmount")
|
@GetMapping("calcDeductionAmount")
|
||||||
public CzgResult<BigDecimal> calcDeductionAmount(@RequestParam Long userId, @RequestParam BigDecimal orderAmount, @RequestParam Integer points) {
|
public CzgResult<BigDecimal> calcDeductionAmount(@RequestParam Long userId, @RequestParam BigDecimal orderAmount, @RequestParam Integer points) {
|
||||||
@@ -94,8 +95,8 @@ public class UMemberPointsController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("payedDeductPoints")
|
@PostMapping("payedDeductPoints")
|
||||||
public CzgResult<Boolean> deductPoints(@RequestBody PayedDeductPointsParam param) {
|
public CzgResult<Boolean> deductPoints(@RequestBody PayedDeductPointsParam param) {
|
||||||
boolean ret = memberPointsService.deductPoints(param.getUserId(), param.getPoints(), param.getContent(), param.getOrderId());
|
//boolean ret = memberPointsService.deductPoints(param.getUserId(), param.getPoints(), param.getContent(), param.getOrderId());
|
||||||
return CzgResult.success(ret);
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +104,7 @@ public class UMemberPointsController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("consumeAwardPoints")
|
@PostMapping("consumeAwardPoints")
|
||||||
public CzgResult<Void> consumeAwardPoints(@RequestBody ConsumeAwardPointsParam param) {
|
public CzgResult<Void> consumeAwardPoints(@RequestBody ConsumeAwardPointsParam param) {
|
||||||
memberPointsService.consumeAwardPoints(param.getUserId(), param.getOrderId());
|
//memberPointsService.consumeAwardPoints(param.getUserId(), param.getOrderId());
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.czg.account.service;
|
|||||||
import com.czg.account.dto.points.OrderDeductionPointsDTO;
|
import com.czg.account.dto.points.OrderDeductionPointsDTO;
|
||||||
import com.czg.account.entity.MemberPoints;
|
import com.czg.account.entity.MemberPoints;
|
||||||
import com.czg.account.param.MemberPointsParam;
|
import com.czg.account.param.MemberPointsParam;
|
||||||
|
import com.czg.order.entity.OrderInfo;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
|
|
||||||
@@ -73,9 +74,9 @@ public interface MemberPointsService extends IService<MemberPoints> {
|
|||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param points 积分
|
* @param points 积分
|
||||||
* @param content 摘要信息(如:兑换积分商品/积分抵扣账单/消费赠送积分/新会员送积分/储值赠送积分)
|
* @param content 摘要信息(如:兑换积分商品/积分抵扣账单/消费赠送积分/新会员送积分/储值赠送积分)
|
||||||
* @param orderId 订单id,可以为空
|
* @param orderInfo 订单信息,可以为空
|
||||||
*/
|
*/
|
||||||
boolean deductPoints(Long userId, int points, String content, Long orderId);
|
boolean deductPoints(Long userId, int points, String content, OrderInfo orderInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 追加积分
|
* 追加积分
|
||||||
@@ -83,17 +84,17 @@ public interface MemberPointsService extends IService<MemberPoints> {
|
|||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param points 积分
|
* @param points 积分
|
||||||
* @param content 摘要信息(如:兑换积分商品/积分抵扣账单/消费赠送积分/新会员送积分/储值赠送积分)
|
* @param content 摘要信息(如:兑换积分商品/积分抵扣账单/消费赠送积分/新会员送积分/储值赠送积分)
|
||||||
* @param orderId 订单id,可以为空
|
* @param orderInfo 订单信息,可以为空
|
||||||
* @return 成功/失败
|
* @return 成功/失败
|
||||||
*/
|
*/
|
||||||
boolean addPoints(Long userId, int points, String content, Long orderId);
|
boolean addPoints(Long userId, int points, String content, OrderInfo orderInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费赠送积分
|
* 消费赠送积分
|
||||||
*
|
*
|
||||||
* @param userId 用户id
|
* @param userId 用户id
|
||||||
* @param orderId 订单id
|
* @param orderInfo 订单信息,可以为空
|
||||||
*/
|
*/
|
||||||
void consumeAwardPoints(Long userId, Long orderId);
|
void consumeAwardPoints(Long userId, OrderInfo orderInfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,6 @@ import com.czg.account.service.MemberPointsService;
|
|||||||
import com.czg.enums.YesNoEnum;
|
import com.czg.enums.YesNoEnum;
|
||||||
import com.czg.exception.CzgException;
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.order.entity.OrderInfo;
|
import com.czg.order.entity.OrderInfo;
|
||||||
import com.czg.order.service.OrderInfoService;
|
|
||||||
import com.czg.sa.StpKit;
|
import com.czg.sa.StpKit;
|
||||||
import com.czg.service.account.mapper.MemberPointsLogMapper;
|
import com.czg.service.account.mapper.MemberPointsLogMapper;
|
||||||
import com.czg.service.account.mapper.MemberPointsMapper;
|
import com.czg.service.account.mapper.MemberPointsMapper;
|
||||||
@@ -23,7 +22,6 @@ import com.mybatisflex.core.paginate.Page;
|
|||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -44,8 +42,6 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
|||||||
private PointsBasicSettingMapper pointsBasicSettingMapper;
|
private PointsBasicSettingMapper pointsBasicSettingMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private MemberPointsLogMapper memberPointsLogMapper;
|
private MemberPointsLogMapper memberPointsLogMapper;
|
||||||
@DubboReference
|
|
||||||
private OrderInfoService orderInfoService;
|
|
||||||
|
|
||||||
private QueryWrapper buildQueryWrapper(MemberPointsParam param) {
|
private QueryWrapper buildQueryWrapper(MemberPointsParam param) {
|
||||||
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
|
||||||
@@ -190,7 +186,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deductPoints(Long userId, int points, String content, Long orderId) {
|
public boolean deductPoints(Long userId, int points, String content, OrderInfo orderInfo) {
|
||||||
MemberPoints entity = initMemberPoints(userId);
|
MemberPoints entity = initMemberPoints(userId);
|
||||||
// 扣除账户积分
|
// 扣除账户积分
|
||||||
entity.setAccountPoints(entity.getAccountPoints() - points);
|
entity.setAccountPoints(entity.getAccountPoints() - points);
|
||||||
@@ -205,12 +201,9 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
|||||||
log.setFloatType("subtract");
|
log.setFloatType("subtract");
|
||||||
log.setFloatPoints(-points);
|
log.setFloatPoints(-points);
|
||||||
// 有关联订单的需要回置订单表的相关积分使用字段
|
// 有关联订单的需要回置订单表的相关积分使用字段
|
||||||
if (orderId != null) {
|
if (orderInfo != null) {
|
||||||
OrderInfo orderInfo = orderInfoService.getById(orderId);
|
log.setOrderNo(orderInfo.getOrderNo());
|
||||||
if (orderInfo != null) {
|
// TODO 是否需要回执“使用的积分数量(points_num)”和“积分抵扣金额(points_discount_amount)”,目前不清楚是创建订单的时候置入还是支付完成后回调时置入需要商议后决定
|
||||||
log.setOrderNo(orderInfo.getOrderNo());
|
|
||||||
// TODO 是否需要回执“使用的积分数量(points_num)”和“积分抵扣金额(points_discount_amount)”,目前不清楚是创建订单的时候置入还是支付完成后回调时置入需要商议后决定
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
super.updateById(entity);
|
super.updateById(entity);
|
||||||
memberPointsLogMapper.insert(log);
|
memberPointsLogMapper.insert(log);
|
||||||
@@ -219,7 +212,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean addPoints(Long userId, int points, String content, Long orderId) {
|
public boolean addPoints(Long userId, int points, String content, OrderInfo orderInfo) {
|
||||||
MemberPoints entity = initMemberPoints(userId);
|
MemberPoints entity = initMemberPoints(userId);
|
||||||
// 增加账户积分
|
// 增加账户积分
|
||||||
entity.setAccountPoints(entity.getAccountPoints() + points);
|
entity.setAccountPoints(entity.getAccountPoints() + points);
|
||||||
@@ -233,11 +226,8 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
|||||||
log.setFloatType("add");
|
log.setFloatType("add");
|
||||||
log.setFloatPoints(points);
|
log.setFloatPoints(points);
|
||||||
// 有关联订单的需要回置订单表的相关积分使用字段
|
// 有关联订单的需要回置订单表的相关积分使用字段
|
||||||
if (orderId != null) {
|
if (orderInfo != null) {
|
||||||
OrderInfo orderInfo = orderInfoService.getById(orderId);
|
log.setOrderNo(orderInfo.getOrderNo());
|
||||||
if (orderInfo != null) {
|
|
||||||
log.setOrderNo(orderInfo.getOrderNo());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
super.updateById(entity);
|
super.updateById(entity);
|
||||||
memberPointsLogMapper.insert(log);
|
memberPointsLogMapper.insert(log);
|
||||||
@@ -246,8 +236,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void consumeAwardPoints(Long userId, Long orderId) {
|
public void consumeAwardPoints(Long userId, OrderInfo orderInfo) {
|
||||||
OrderInfo orderInfo = orderInfoService.getById(orderId);
|
|
||||||
if (orderInfo == null) {
|
if (orderInfo == null) {
|
||||||
throw new CzgException("订单不存在");
|
throw new CzgException("订单不存在");
|
||||||
}
|
}
|
||||||
@@ -282,6 +271,6 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BigDecimal awardPoints = NumberUtil.roundDown(NumberUtil.div(payAmount, consumeAmount), 0);
|
BigDecimal awardPoints = NumberUtil.roundDown(NumberUtil.div(payAmount, consumeAmount), 0);
|
||||||
addPoints(userId, awardPoints.intValue(), StrUtil.format("消费¥{}送{}积分", payAmount, awardPoints.intValue()), orderId);
|
addPoints(userId, awardPoints.intValue(), StrUtil.format("消费¥{}送{}积分", payAmount, awardPoints.intValue()), orderInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user