积分 发放

This commit is contained in:
2025-12-11 15:12:21 +08:00
parent e43cda28b7
commit 27ff6ae2d7
11 changed files with 161 additions and 149 deletions

View File

@@ -36,6 +36,7 @@ public class MemberTask {
// @Scheduled(cron = "0 0 1 * * ? ")
public void task() {
shopUserService.list(new QueryWrapper().eq(ShopUser::getIsVip, 1).lt(ShopUser::getNextDeliverTime, DateUtil.date().toLocalDateTime())).forEach(item -> {
//周任务
memberConfigService.deliver(item, TableValueConstant.MemberExpFlow.Type.MEMBER_TASK, null, null, null);
});
}
@@ -46,9 +47,7 @@ public class MemberTask {
.isNotNull(ShopUser::getEndTime)
.eq(ShopUser::getIsVip, 1)
.lt(ShopUser::getEndTime, LocalDateTime.now()));
shopUsers.forEach(item -> {
item.setIsVip(0);
});
shopUsers.forEach(item -> item.setIsVip(0));
shopUserService.updateBatch(shopUsers);
}

View File

@@ -101,6 +101,9 @@ public class MemberLevelConfig implements Serializable {
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
/**
* 是否启用消费送积分
*/
private Integer isCostRewardPoints;

View File

@@ -1,5 +1,6 @@
package com.czg.market.service;
import com.czg.account.entity.ShopUser;
import com.czg.order.entity.OrderInfo;
import com.mybatisflex.core.service.IService;
import com.czg.market.entity.MkPointsConfig;
@@ -15,5 +16,5 @@ public interface MkPointsConfigService extends IService<MkPointsConfig> {
* 订单支付成功,通过计算 给用户赠送积分
*
*/
void consumeAwardPoints(Long shopUserId, OrderInfo orderInfo);
void consumeAwardPoints(ShopUser shopUser, OrderInfo orderInfo);
}

View File

@@ -2,10 +2,10 @@ package com.czg.market.service;
import com.czg.account.vo.PointsShopListVO;
import com.czg.market.dto.MkPointsUserDTO;
import com.czg.market.entity.MkPointsUser;
import com.czg.market.enums.PointsConstant;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.market.entity.MkPointsUser;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

View File

@@ -22,6 +22,7 @@ import java.util.List;
public interface TbMemberConfigService extends IService<TbMemberConfig> {
MemberConfigVO detail(Long shopId);
UMemberConfigVO detail(Long shopId, Long userId);
Boolean edit(Long shopId, MemberConfigDTO memberDTO);
@@ -34,15 +35,18 @@ public interface TbMemberConfigService extends IService<TbMemberConfig> {
/**
* 根据传入的用户Id校验是否符合条件符合加入会员
*
* @param shopId 店铺id
* @param userId 用户id
* @return 是否加入成功
*/
boolean joinMember(Long shopId, Long userId, Long memberOrderId);
boolean joinMemberByCondition(Long shopId, Long userId);
boolean joinMemberByCondition(Long shopId, Long userId, ShopUser shopUser);
/**
* 发放会员奖励
*
* @param money 实际消费金额
* @param expVal 经验值只有当type为pay的时候才生效
* @return 是否成功

View File

@@ -23,13 +23,14 @@ public interface TableValueConstant {
}
}
}
interface MemberExpFlow {
@Getter
enum Type {
RECHARGE("RECHARGE", "充值增积分"),
PAY("PAY", "购买会员增积分"),
RECHARGE("RECHARGE", "充值成长值 积分发放在扣减余额的地方"),
PAY("PAY", "购买会员"),
MEMBER_TASK("MEMBER_TASK", "会员周奖励"),
COST("COST", "消费增积分");
COST("COST", "消费成长值");
private final String code;
private final String msg;
@@ -115,6 +116,7 @@ public interface TableValueConstant {
}
}
interface EnableConfig {
@Getter
enum Type {

View File

@@ -1,15 +1,17 @@
package com.czg.service.market.service.impl;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.entity.ShopUser;
import com.czg.market.entity.MemberLevelConfig;
import com.czg.market.entity.MkPointsConfig;
import com.czg.market.enums.PointsConstant;
import com.czg.market.service.MemberLevelConfigService;
import com.czg.market.service.MkPointsConfigService;
import com.czg.market.service.MkPointsUserService;
import com.czg.order.entity.OrderInfo;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.market.entity.MkPointsConfig;
import com.czg.market.service.MkPointsConfigService;
import com.czg.service.market.mapper.MkPointsConfigMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@@ -27,29 +29,37 @@ public class MkPointsConfigServiceImpl extends ServiceImpl<MkPointsConfigMapper,
@Resource
private MkPointsUserService mkPointsUserService;
@Resource
private MemberLevelConfigService levelConfigService;
@Override
public void consumeAwardPoints(Long shopUserId, OrderInfo orderInfo) {
public void consumeAwardPoints(ShopUser shopUser, OrderInfo orderInfo) {
BigDecimal payAmount = orderInfo.getPayAmount();
if (NumberUtil.isLessOrEqual(payAmount, BigDecimal.ZERO)) {
return;
}
BigDecimal consumeAmount = null;
if (shopUser.getIsVip() == 1 && shopUser.getMemberLevelId() != null) {
MemberLevelConfig level = levelConfigService.getById(shopUser.getMemberLevelId());
if (level != null && level.getIsCostRewardPoints() == 1 && level.getCostRewardPoints() != null && level.getCostRewardPoints() > 0) {
consumeAmount = BigDecimal.valueOf(level.getCostRewardPoints());
}
}
if (consumeAmount == null) {
MkPointsConfig pointsConfig = getOne(query().eq(MkPointsConfig::getShopId, orderInfo.getShopId()));
if (pointsConfig == null) {
return;
}
Integer enableRewards = pointsConfig.getEnableRewards();
if (enableRewards == 0) {
if (pointsConfig.getEnableRewards() == null || pointsConfig.getEnableRewards() == 0) {
return;
}
BigDecimal consumeAmount = pointsConfig.getConsumeAmount();
if (consumeAmount == null) {
return;
if (pointsConfig.getConsumeAmount() != null && pointsConfig.getConsumeAmount().compareTo(BigDecimal.ZERO) > 0) {
consumeAmount = pointsConfig.getConsumeAmount();
}
if (NumberUtil.isLessOrEqual(consumeAmount, BigDecimal.ZERO)) {
return;
}
BigDecimal awardPoints = NumberUtil.roundDown(NumberUtil.div(payAmount, consumeAmount), 0);
mkPointsUserService.alterPoints(null, shopUserId, orderInfo.getShopId(), PointsConstant.ADD,
mkPointsUserService.alterPoints(null, shopUser.getId(), orderInfo.getShopId(), PointsConstant.ADD,
awardPoints.intValue(), orderInfo.getId(), StrUtil.format("消费¥{}送{}积分", payAmount, awardPoints.intValue()));
}
}

View File

@@ -75,6 +75,7 @@ public class MkPointsUserServiceImpl extends ServiceImpl<MkPointsUserMapper, MkP
PointsShopListVO.class);
}
@Override
public MkPointsUser getPointsUser(Long shopId, Long shopUserId, Long userId) {
MkPointsUser pointsUser;
if (userId == null && shopUserId == null) {
@@ -161,7 +162,6 @@ public class MkPointsUserServiceImpl extends ServiceImpl<MkPointsUserMapper, MkP
points,
points > 0 ? "存储你的账户" : "使用"));
acUserMsgService.addUserMsg(msg);
return record.getId();
}
}

View File

@@ -90,22 +90,22 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
List<MkShopRechargeDetailVO> detailList = shopRechargeDetailService.list(new QueryWrapper().eq(MkShopRechargeDetail::getShopRechargeId, shopRecharge.getId())).stream().map(mkShopRechargeDetail -> {
MkShopRechargeDetailVO detailVO = BeanUtil.copyProperties(mkShopRechargeDetail, MkShopRechargeDetailVO.class, "couponInfoList");
if (StrUtil.isNotBlank(mkShopRechargeDetail.getCouponInfoList())) {
ArrayList<CouponInfoVO> couponInfoVOS = new ArrayList<>();
List<CouponInfoDTO> couponInfoDTOS = JSONArray.parseArray(mkShopRechargeDetail.getCouponInfoList()).toJavaList(CouponInfoDTO.class);
Set<Long> couponIdList = couponInfoDTOS.stream().map(CouponInfoDTO::getId).collect(Collectors.toSet());
ArrayList<CouponInfoVO> couponInfos = new ArrayList<>();
List<CouponInfoDTO> couponInfoDTOList = JSONArray.parseArray(mkShopRechargeDetail.getCouponInfoList()).toJavaList(CouponInfoDTO.class);
Set<Long> couponIdList = couponInfoDTOList.stream().map(CouponInfoDTO::getId).collect(Collectors.toSet());
if (!couponIdList.isEmpty()) {
Map<Long, ShopCoupon> couponMap = shopCouponService.list(new QueryWrapper().in(ShopCoupon::getId, couponIdList)).stream().collect(Collectors.toMap(ShopCoupon::getId, v -> v));
couponInfoDTOS.forEach(item -> {
couponInfoDTOList.forEach(item -> {
ShopCoupon shopCoupon = couponMap.get(item.getId());
if (shopCoupon == null) {
return;
}
shopCoupon.setInfo();
couponInfoVOS.add(new CouponInfoVO().setCoupon(shopCoupon).setNum(item.getNum()));
couponInfos.add(new CouponInfoVO().setCoupon(shopCoupon).setNum(item.getNum()));
});
}
detailVO.setCouponInfoList(couponInfoVOS);
detailVO.setCouponInfoList(couponInfos);
}
return detailVO;
}).collect(Collectors.toList());
@@ -185,7 +185,7 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
// 发放积分
if (rechargeDetail.getRewardPoints() != null) {
pointsUserService.alterPoints(null, shopUserId, shopUser.getMainShopId(), PointsConstant.ADD, rechargeDetail.getRewardPoints(), editId, "会员充值送积分");
pointsUserService.alterPoints(null, shopUserId, shopUser.getMainShopId(), PointsConstant.ADD, rechargeDetail.getRewardPoints(), editId, "充值赠送");
}
// 发放优惠券

View File

@@ -6,12 +6,21 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.ShopInfo;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopConfigService;
import com.czg.account.service.ShopInfoService;
import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
import com.czg.constant.TableValueConstant;
import com.czg.exception.CzgException;
import com.czg.market.dto.*;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.market.entity.*;
import com.czg.market.dto.MemberConfigDTO;
import com.czg.market.dto.MemberLevelDTO;
import com.czg.market.dto.MkRewardCouponDTO;
import com.czg.market.entity.MemberExpFlow;
import com.czg.market.entity.MemberLevelConfig;
import com.czg.market.entity.MemberOrder;
import com.czg.market.entity.TbMemberConfig;
import com.czg.market.enums.PointsConstant;
import com.czg.market.service.*;
import com.czg.market.vo.*;
@@ -267,16 +276,16 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
@Override
public ArrayList<MemberLevelVO> listLevel(Long shopId) {
shopId = shopInfoService.getMainIdByShopId(shopId);
ArrayList<MemberLevelVO> memberLevelVOS = new ArrayList<>();
ArrayList<MemberLevelVO> memberLevels = new ArrayList<>();
levelConfigService.list(new QueryWrapper().eq(MemberLevelConfig::getShopId, shopId)).forEach(item -> {
MemberLevelVO memberLevelVO = BeanUtil.copyProperties(item, MemberLevelVO.class, "cycleRewardCouponList");
if (StrUtil.isNotBlank(item.getCycleRewardCouponList())) {
memberLevelVO.setCycleRewardCouponList(JSONArray.parseArray(item.getCycleRewardCouponList()).toList(MemberLevelDTO.ConfigCoupon.class));
}
memberLevelVOS.add(memberLevelVO);
memberLevels.add(memberLevelVO);
});
return memberLevelVOS;
return memberLevels;
}
@Override
@@ -298,7 +307,6 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
shopUser.setExperience(0L);
}
MemberLevelVO levelVO = levelConfigService.detail(shopUser.getMemberLevelId());
if (levelVO == null) {
log.warn("会员等级配置不存在, 店铺id: {}, 等级id: {}", shopUser.getMainShopId(), shopUser.getMemberLevelId());
@@ -306,22 +314,12 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
}
log.info("会员奖励发放,类型: {} 金额: {}, userId: {}, 经验值: {}", type.getCode(), money, shopUser.getUserId(), expVal);
long exp = 0;
switch (type) {
case COST -> {
if (memberConfig.getCostReward() != null) {
exp = money.longValue() * memberConfig.getCostReward();
}
// 消费送积分
if (levelVO.getIsCostRewardPoints() == 1 && levelVO.getCostRewardPoints() != null) {
int points = (int) (money.floatValue() / levelVO.getCostRewardPoints());
log.info("消费送积分: {}", points);
if (points > 0) {
pointsUserService.alterPoints(null, shopUser.getId(), shopUser.getMainShopId(), PointsConstant.ADD, points, sourceId, "会员消费送积分");
}
}
}
case RECHARGE -> {
if (memberConfig.getRechargeReward() != null) {
@@ -333,7 +331,8 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
if (levelVO.getIsCycleReward() == 1) {
if (levelVO.getCycleRewardPoints() != null) {
int points = levelVO.getCycleRewardPoints();
pointsUserService.alterPoints(null, shopUser.getId(), shopUser.getMainShopId(), PointsConstant.ADD, points, sourceId, "会员周奖励");
//会员周期发放积分
pointsUserService.alterPoints(null, shopUser.getId(), shopUser.getMainShopId(), PointsConstant.ADD, points, sourceId, "会员周期发放");
}
if (levelVO.getCycleRewardCouponList() != null && !levelVO.getCycleRewardCouponList().isEmpty()) {
@@ -344,7 +343,6 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
.setShopId(shopUser.getMainShopId()), "购买会员赠券");
});
// couponGiftService.addCouponGift(memberOrderId, "会员开通赠券", 1, giftDTOS);
}
}
@@ -381,9 +379,8 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
@Override
@Transactional(rollbackFor = Exception.class)
public boolean joinMemberByCondition(Long shopId, Long userId) {
public boolean joinMemberByCondition(Long shopId, Long userId, ShopUser shopUser) {
MemberConfigVO memberConfigVO = detail(shopId);
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getSourceShopId, shopId).eq(ShopUser::getUserId, userId));
if (shopUser == null) {
log.warn("用户不存在, 店铺id: {}, 用户id: {}", shopId, userId);
return false;
@@ -522,6 +519,7 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
shopUser.setIsVip(1);
shopUser.setOpenType("PAY");
if (memberOrder.getReward() != null) {
//购买开通
deliver(shopUser, TableValueConstant.MemberExpFlow.Type.PAY, memberOrder.getAmount(), memberOrder.getReward(), memberOrderId);
}
return shopUserService.updateInfo(shopUser);
@@ -535,11 +533,11 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
}
Set<Long> shopIdList = shopUsers.stream().map(ShopUser::getSourceShopId).collect(Collectors.toSet());
Map<Long, ShopInfo> shopInfoMap = shopInfoService.list(new QueryWrapper().in(ShopInfo::getId, shopIdList)).stream().collect(Collectors.toMap(ShopInfo::getId, item -> item));
ArrayList<MemberListVO> memberListVOS = new ArrayList<>();
ArrayList<MemberListVO> memberLists = new ArrayList<>();
shopUsers.forEach(shopUser -> {
if (shopUser.getStartTime() != null && shopUser.getEndTime() != null && DateUtil.isIn(DateUtil.date(), DateUtil.date(shopUser.getStartTime()), DateUtil.date(shopUser.getEndTime()))) {
ShopInfo shopInfo = shopInfoMap.getOrDefault(shopUser.getSourceShopId(), new ShopInfo());
memberListVOS.add(new MemberListVO().setShopName(shopInfo.getShopName())
memberLists.add(new MemberListVO().setShopName(shopInfo.getShopName())
.setShopId(shopInfo.getId())
.setLogo(shopInfo.getLogo()));
} else {
@@ -548,10 +546,11 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
}
});
return memberListVOS;
return memberLists;
}
@Override
@Transactional
public MemberDetailVO getUserDetail(Long userId, Long shopId) {
Long mainIdByShopId = shopInfoService.getMainIdByShopId(shopId);
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getUserId, userId).eq(ShopUser::getMainShopId, mainIdByShopId));
@@ -561,8 +560,7 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
}
TbMemberConfig memberConfig = getOne(new QueryWrapper().eq(TbMemberConfig::getShopId, shopId));
if ("CONDITION".equals(memberConfig.getOpenType())) {
joinMemberByCondition(shopId, userId);
shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getUserId, userId).eq(ShopUser::getMainShopId, mainIdByShopId));
joinMemberByCondition(shopId, userId, shopUser);
}
ShopInfo shopInfo = shopInfoService.getById(shopUser.getSourceShopId());

View File

@@ -58,6 +58,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
@@ -1051,17 +1052,11 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
}
upOrderInfo(orderInfo, new BigDecimal(czgCallBackDto.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.DOWN),
DateUtil.parseLocalDateTime(czgCallBackDto.getPayTime()), payment.getId(), null);
// 会员加入
memberConfigService.joinMemberByCondition(orderInfo.getShopId(), orderInfo.getUserId());
// 会员消费赠送成长值
ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId());
memberConfigService.deliver(shopUser, TableValueConstant.MemberExpFlow.Type.COST, orderInfo.getPayAmount(), null, orderInfo.getId());
// 分销员升级等级
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
// 分销奖励
distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
}
else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
} else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
boolean isFree = "free".equals(payment.getPayType());
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
OrderInfo orderInfo = null;
@@ -1128,6 +1123,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// 发放成长值
shopUser = shopUserService.getById(shopUser);
//充值
memberConfigService.deliver(shopUser,
TableValueConstant.MemberExpFlow.Type.RECHARGE,
BigDecimal.valueOf(czgCallBackDto.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN), null, orderInfo.getId());
@@ -1161,8 +1157,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// if (orderInfo != null) {
// distributionUserService.distribute(payment.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), payment.getShopId(), "recharge");
// }
}
else if ("memberPay".equals(payment.getPayType())) {
} else if ("memberPay".equals(payment.getPayType())) {
//购买会员
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
memberConfigService.joinMember(payment.getShopId(), shopUser.getUserId(), payment.getRelatedId());
@@ -1170,8 +1165,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// memberConfigService.deliver(shopUser.getMainShopId(), shopUser.getUserId(), TableValueConstant.MemberExpFlow.Type.COST, payment.getAmount(), null, payment.getId());
// 分销员开通
}
else if ("distribution".equals(payment.getPayType())) {
} else if ("distribution".equals(payment.getPayType())) {
distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId());
} else if ("point".equals(payment.getPayType())) {
goodPayService.payCallBack(payment.getSourceId(), payment.getId());
@@ -1250,66 +1244,12 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
orderInfo.setPaidTime(payTime);
}
orderDetailService.updateOrderDetailStatus(orderInfo.getId(), OrderStatusEnums.DONE.getCode());
if (orderInfo.getUserId() != null) {
ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId());
if (shopUser == null) {
if ((orderInfo.getPointsNum() != null && orderInfo.getPointsNum() > 0)
|| (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) && !"null".equals(orderInfo.getCouponInfoList()))) {
log.error("订单积分使用或优惠券扣除失败订单id{}", orderInfo.getId());
}
} else {
//新客立减
if (orderInfo.getNewCustomerDiscountAmount() != null && orderInfo.getNewCustomerDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
newConsumerDiscountRecordService.useDiscount(shopUser.getId(), orderInfo.getId(), orderInfo.getNewCustomerDiscountAmount());
}
//积分使用
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() > 0) {
pointsUserService.alterPoints(null, shopUser.getId(), orderInfo.getShopId(), PointsConstant.SUB,
orderInfo.getPointsNum(), orderInfo.getId(), "积分抵扣账单");
}
//更新优惠券信息
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) && !"null".equals(orderInfo.getCouponInfoList())) {
//券消耗
List<Long> coupons = JSON.parseArray(orderInfo.getCouponInfoList(), Long.class);
if (CollUtil.isNotEmpty(coupons)) {
couponService.use(coupons, shopUser.getId(), orderInfo.getId());
}
}
if (!orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) {
//消费赠券 挂账支付不赠送
try {
consumerCouponService.receiveConsumerCoupon(shopUser.getSourceShopId(), orderInfo.getId(), orderInfo.getPayAmount(), shopUser.getUserId(), shopUser.getId());
} catch (Exception e) {
log.error("订单{}消费赠券失败", orderInfo.getId(), e);
}
}
String[] payTypes = {PayEnums.VIP_PAY.getValue(), PayEnums.CREDIT_PAY.getValue()};
if ((orderInfo.getPayType() != null && !ArrayUtil.contains(payTypes, orderInfo.getPayType()))
|| (payType != null && !ArrayUtil.contains(payTypes, payType))) {
//下单赠送积分
pointsConfigService.consumeAwardPoints(shopUser.getId(), orderInfo);
//消费返现
if (!orderInfo.getPayType().equals(PayEnums.CASH_PAY.getValue())) {
consumeCashbackService.cashback(orderInfo.getShopId(), shopUser.getUserId(), orderInfo.getPayAmount(), orderInfo.getId(), orderInfo.getOrderNo());
}
}
}
exShopUserInfo(orderInfo);
}
if (StrUtil.isNotBlank(orderInfo.getTableCode())) {
ShopTable table = shopTableService.getOneByTableCode(orderInfo.getShopId(), orderInfo.getTableCode());
if (table != null) {
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
if ("auto".equals(shopInfo.getTableClearType())) {
table.setStatus(ShopTableStatusEnum.IDLE.getValue());
} else {
DateTime dateTime = DateUtil.offsetMinute(DateUtil.date(), shopInfo.getTableClearTime());
table.setCreateTime(LocalDateTimeUtil.of(dateTime));
redisService.set(RedisCst.classKeyExpired.EXPIRED_TABLE + table.getId(), "", 60L * shopInfo.getTableClearTime());
}
shopTableService.updateById(table);
}
exTable(orderInfo);
}
// 保存消息参数(避免闭包中引用的变量被修改)
final Long orderId = orderInfo.getId();
@@ -1337,6 +1277,76 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
}
//订单回调后 跟用户相关的部分
@Async
public void exShopUserInfo(OrderInfo orderInfo) {
ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId());
if (shopUser == null) {
if ((orderInfo.getPointsNum() != null && orderInfo.getPointsNum() > 0) || (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) && !"null".equals(orderInfo.getCouponInfoList()))) {
log.error("订单积分使用或优惠券扣除失败订单id{}", orderInfo.getId());
}
return;
}
//使用内容的 执行
shopUserUseInfo(orderInfo, shopUser);
// 后续 赠送等功能 挂账支付不赠送
if (!orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) {
try {
//消费赠券
consumerCouponService.receiveConsumerCoupon(shopUser.getSourceShopId(), orderInfo.getId(), orderInfo.getPayAmount(), shopUser.getUserId(), shopUser.getId());
//下单赠送积分
pointsConfigService.consumeAwardPoints(shopUser, orderInfo);
//消费返现
consumeCashbackService.cashback(orderInfo.getShopId(), shopUser.getUserId(), orderInfo.getPayAmount(), orderInfo.getId(), orderInfo.getOrderNo());
if (shopUser.getIsVip().equals(0)) {
// 消费累计成为会员的情况
memberConfigService.joinMemberByCondition(orderInfo.getShopId(), orderInfo.getUserId(), shopUser);
} else {
// 消费赠送成长值
memberConfigService.deliver(shopUser, TableValueConstant.MemberExpFlow.Type.COST, orderInfo.getPayAmount(), null, orderInfo.getId());
}
} catch (Exception e) {
log.error("订单{}消费赠券失败", orderInfo.getId(), e);
}
}
}
public void shopUserUseInfo(OrderInfo orderInfo, ShopUser shopUser) {
//新客立减
if (orderInfo.getNewCustomerDiscountAmount() != null && orderInfo.getNewCustomerDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
newConsumerDiscountRecordService.useDiscount(shopUser.getId(), orderInfo.getId(), orderInfo.getNewCustomerDiscountAmount());
}
//积分使用
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() > 0) {
pointsUserService.alterPoints(null, shopUser.getId(), orderInfo.getShopId(), PointsConstant.SUB,
orderInfo.getPointsNum(), orderInfo.getId(), "积分抵扣");
}
//更新优惠券信息
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) && !"null".equals(orderInfo.getCouponInfoList())) {
//券消耗
List<Long> coupons = JSON.parseArray(orderInfo.getCouponInfoList(), Long.class);
if (CollUtil.isNotEmpty(coupons)) {
couponService.use(coupons, shopUser.getId(), orderInfo.getId());
}
}
}
@Async
public void exTable(OrderInfo orderInfo) {
ShopTable table = shopTableService.getOneByTableCode(orderInfo.getShopId(), orderInfo.getTableCode());
if (table != null) {
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
if ("auto".equals(shopInfo.getTableClearType())) {
table.setStatus(ShopTableStatusEnum.IDLE.getValue());
} else {
DateTime dateTime = DateUtil.offsetMinute(DateUtil.date(), shopInfo.getTableClearTime());
table.setCreateTime(LocalDateTimeUtil.of(dateTime));
redisService.set(RedisCst.classKeyExpired.EXPIRED_TABLE + table.getId(), "", 60L * shopInfo.getTableClearTime());
}
shopTableService.updateById(table);
}
}
/**
* 订单到期
*/
@@ -1496,25 +1506,10 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
log.error("订单积分使用或优惠券扣除失败订单id{}", orderInfo.getId());
}
} else {
//新客立减
if (param.getNewCustomerDiscountId() != null) {
newConsumerDiscountRecordService.checkDiscount(orderInfo.getShopId(), shopUser.getUserId(), param.getOrderId(), param.getNewCustomerDiscountAmount());
}
//积分使用
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() > 0) {
pointsUserService.alterPoints(null, shopUser.getId(), orderInfo.getShopId(), PointsConstant.ADD,
orderInfo.getPointsNum(), orderInfo.getId(), "积分抵扣账单");
}
//更新优惠券信息
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) && !"null".equals(orderInfo.getCouponInfoList())) {
//券消耗
List<Long> coupons = JSON.parseArray(orderInfo.getCouponInfoList(), Long.class);
if (CollUtil.isNotEmpty(coupons)) {
couponService.use(coupons, shopUser.getId(), orderInfo.getId());
}
}
shopUserUseInfo(orderInfo, shopUser);
}
}
exTable(orderInfo);
}
orderInfoService.saveOrUpdate(orderInfo);
}