积分 发放
This commit is contained in:
@@ -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;
|
||||
}
|
||||
MkPointsConfig pointsConfig = getOne(query().eq(MkPointsConfig::getShopId, orderInfo.getShopId()));
|
||||
if (pointsConfig == null) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
Integer enableRewards = pointsConfig.getEnableRewards();
|
||||
if (enableRewards == 0) {
|
||||
return;
|
||||
}
|
||||
BigDecimal consumeAmount = pointsConfig.getConsumeAmount();
|
||||
if (consumeAmount == null) {
|
||||
return;
|
||||
}
|
||||
if (NumberUtil.isLessOrEqual(consumeAmount, BigDecimal.ZERO)) {
|
||||
return;
|
||||
MkPointsConfig pointsConfig = getOne(query().eq(MkPointsConfig::getShopId, orderInfo.getShopId()));
|
||||
if (pointsConfig == null) {
|
||||
return;
|
||||
}
|
||||
if (pointsConfig.getEnableRewards() == null || pointsConfig.getEnableRewards() == 0) {
|
||||
return;
|
||||
}
|
||||
if (pointsConfig.getConsumeAmount() != null && pointsConfig.getConsumeAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
consumeAmount = pointsConfig.getConsumeAmount();
|
||||
}
|
||||
}
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, "充值赠送");
|
||||
}
|
||||
|
||||
// 发放优惠券
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user