积分 发放

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

@@ -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,10 +1165,9 @@ 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())){
} 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);
}