超级会员相关
This commit is contained in:
@@ -29,7 +29,7 @@ public class Main {
|
||||
// String packageName = "product";
|
||||
String packageName = "market";
|
||||
|
||||
String tableName = "tb_member_exp_flow";
|
||||
String tableName = "mk_shop_recharge_detail";
|
||||
String author = "zs";
|
||||
//是否生成DTO实体 默认生成
|
||||
boolean isGenerateDto = true;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkConsumeDiscount;
|
||||
|
||||
/**
|
||||
* 新客立减 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
public interface MkConsumeDiscountMapper extends BaseMapper<MkConsumeDiscount> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkShopRechargeDetail;
|
||||
|
||||
/**
|
||||
* 充值面额详情 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
public interface MkShopRechargeDetailMapper extends BaseMapper<MkShopRechargeDetail> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkShopRecharge;
|
||||
|
||||
/**
|
||||
* 充值配置表 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
public interface MkShopRechargeMapper extends BaseMapper<MkShopRecharge> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.czg.constant.TableValueConstant;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.czg.market.dto.MkConsumeDiscountDTO;
|
||||
import com.czg.market.entity.MkConsumeDiscountRandom;
|
||||
import com.czg.market.vo.MkConsumeDiscountVO;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MkConsumeDiscount;
|
||||
import com.czg.market.service.MkConsumeDiscountService;
|
||||
import com.czg.service.market.mapper.MkConsumeDiscountMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 新客立减 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Service
|
||||
public class MkConsumeDiscountServiceImpl extends ServiceImpl<MkConsumeDiscountMapper, MkConsumeDiscount> implements MkConsumeDiscountService{
|
||||
@Override
|
||||
public MkConsumeDiscountVO detail(Long shopId) {
|
||||
MkConsumeDiscount consumeDiscount = getOne(new QueryWrapper().eq(MkConsumeDiscount::getShopId, shopId));
|
||||
if (consumeDiscount == null) {
|
||||
consumeDiscount = new MkConsumeDiscount();
|
||||
consumeDiscount.setShopId(shopId);
|
||||
save(consumeDiscount);
|
||||
consumeDiscount = getOne(new QueryWrapper().eq(MkConsumeDiscount::getShopId, shopId));
|
||||
|
||||
}
|
||||
MkConsumeDiscountVO consumeDiscountVO = BeanUtil.copyProperties(consumeDiscount, MkConsumeDiscountVO.class, "randomDiscountList", "useTypeList");
|
||||
if (StrUtil.isNotBlank(consumeDiscount.getRandomDiscountList())) {
|
||||
consumeDiscountVO.setRandomDiscountList(JSONArray.parseArray(consumeDiscount.getRandomDiscountList()).toList(MkConsumeDiscountRandom.class));
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(consumeDiscount.getUseTypeList())) {
|
||||
consumeDiscountVO.setUseTypeList(JSONArray.parseArray(consumeDiscount.getUseTypeList()).toList(String.class));
|
||||
}
|
||||
return consumeDiscountVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(Long shopId, MkConsumeDiscountDTO consumeDiscountDTO) {
|
||||
if (consumeDiscountDTO.getRandomDiscountList() == null && consumeDiscountDTO.getDiscountAmount() == null) {
|
||||
throw new ApiNotPrintException("优惠金额和随机优惠金额不能同时为空");
|
||||
}
|
||||
if (TableValueConstant.ConsumeDiscount.DiscountType.RANDOM.getCode().equals(consumeDiscountDTO.getDiscountType())) {
|
||||
if (consumeDiscountDTO.getRandomDiscountList() == null || consumeDiscountDTO.getRandomDiscountList().isEmpty()) {
|
||||
throw new ApiNotPrintException("随机优惠金额不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
MkConsumeDiscount consumeDiscount = getOne(new QueryWrapper().eq(MkConsumeDiscount::getShopId, shopId));
|
||||
BeanUtil.copyProperties(consumeDiscountDTO, consumeDiscount);
|
||||
if (consumeDiscountDTO.getRandomDiscountList() != null) {
|
||||
if (consumeDiscountDTO.getRandomDiscountList().stream().map(MkConsumeDiscountRandom::getProbability).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal("100")) != 0) {
|
||||
throw new ApiNotPrintException("随机概率综合必须为100%");
|
||||
}
|
||||
consumeDiscount.setRandomDiscountList(JSONArray.toJSONString(consumeDiscountDTO.getRandomDiscountList()));
|
||||
}
|
||||
|
||||
if (consumeDiscountDTO.getUseTypeList() != null) {
|
||||
consumeDiscount.setUseTypeList(JSONArray.toJSONString(consumeDiscountDTO.getUseTypeList()));
|
||||
}
|
||||
|
||||
return updateById(consumeDiscount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MkShopRechargeDetail;
|
||||
import com.czg.market.service.MkShopRechargeDetailService;
|
||||
import com.czg.service.market.mapper.MkShopRechargeDetailMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 充值面额详情 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Service
|
||||
public class MkShopRechargeDetailServiceImpl extends ServiceImpl<MkShopRechargeDetailMapper, MkShopRechargeDetail> implements MkShopRechargeDetailService{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.czg.market.dto.CouponInfoDTO;
|
||||
import com.czg.market.dto.MkShopRechargeDTO;
|
||||
import com.czg.market.entity.MkShopRechargeDetail;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.MkShopRechargeDetailService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.market.vo.CouponInfoVO;
|
||||
import com.czg.market.vo.MkShopRechargeDetailVO;
|
||||
import com.czg.market.vo.MkShopRechargeVO;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MkShopRecharge;
|
||||
import com.czg.market.service.MkShopRechargeService;
|
||||
import com.czg.service.market.mapper.MkShopRechargeMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 充值配置表 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Service
|
||||
public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper, MkShopRecharge> implements MkShopRechargeService{
|
||||
@Resource
|
||||
private MkShopRechargeDetailService shopRechargeDetailService;
|
||||
@Resource
|
||||
private ShopCouponService shopCouponService;
|
||||
|
||||
@Override
|
||||
public MkShopRechargeVO detail(Long shopId) {
|
||||
MkShopRecharge shopRecharge = getOne(new QueryWrapper().eq(MkShopRecharge::getMasterShopId, shopId));
|
||||
if (shopRecharge == null) {
|
||||
shopRecharge = new MkShopRecharge();
|
||||
shopRecharge.setMasterShopId(shopId);
|
||||
save(shopRecharge);
|
||||
shopRecharge = getOne(new QueryWrapper().eq(MkShopRecharge::getMasterShopId, shopId));
|
||||
}
|
||||
|
||||
MkShopRechargeVO shopRechargeVO = BeanUtil.copyProperties(shopRecharge, MkShopRechargeVO.class, "shopIdList");
|
||||
if (StrUtil.isNotBlank(shopRecharge.getShopIdList())) {
|
||||
shopRechargeVO.setShopIdList(JSONArray.parseArray(shopRecharge.getShopIdList()).toList(Long.class));
|
||||
}
|
||||
|
||||
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());
|
||||
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 -> {
|
||||
couponInfoVOS.add(new CouponInfoVO().setCoupon(couponMap.get(item.getId())).setNum(item.getNum()));
|
||||
});
|
||||
}
|
||||
detailVO.setCouponInfoList(couponInfoVOS);
|
||||
}
|
||||
return detailVO;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
shopRechargeVO.setRechargeDetailList(detailList);
|
||||
|
||||
return shopRechargeVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(Long shopId, MkShopRechargeDTO shopRechargeDTO) {
|
||||
MkShopRecharge shopRecharge = getOne(new QueryWrapper().eq(MkShopRecharge::getMasterShopId, shopId));
|
||||
BeanUtil.copyProperties(shopRechargeDTO, shopRecharge);
|
||||
if (shopRechargeDTO.getShopIdList() != null && !shopRechargeDTO.getShopIdList().isEmpty()) {
|
||||
shopRecharge.setShopIdList(JSONArray.toJSONString(shopRechargeDTO.getShopIdList()));
|
||||
}
|
||||
|
||||
if (shopRechargeDTO.getShopRechargeDetailList() != null && !shopRechargeDTO.getShopRechargeDetailList().isEmpty()) {
|
||||
shopRechargeDetailService.remove(new QueryWrapper().eq(MkShopRechargeDetail::getShopRechargeId, shopRecharge.getId()));
|
||||
shopRechargeDTO.getShopRechargeDetailList().forEach(item -> {
|
||||
MkShopRechargeDetail mkShopRechargeDetail = BeanUtil.copyProperties(item, MkShopRechargeDetail.class,"couponInfoList");
|
||||
mkShopRechargeDetail.setCouponInfoList(JSONArray.toJSONString(item.getCouponInfoList()));
|
||||
mkShopRechargeDetail.setShopRechargeId(shopRecharge.getId());
|
||||
shopRechargeDetailService.save(mkShopRechargeDetail);
|
||||
});
|
||||
}
|
||||
return updateById(shopRecharge);
|
||||
}
|
||||
}
|
||||
@@ -221,8 +221,8 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
}
|
||||
|
||||
|
||||
MemberLevelConfig levelConfig = levelConfigService.getById(shopUser.getMemberLevelId());
|
||||
if (levelConfig == null) {
|
||||
MemberLevelVO levelVO = levelConfigService.detail(shopUser.getMemberLevelId());
|
||||
if (levelVO == null) {
|
||||
log.warn("会员等级配置不存在, 店铺id: {}, 等级id: {}", shopId, shopUser.getMemberLevelId());
|
||||
return false;
|
||||
}
|
||||
@@ -235,8 +235,8 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
exp = money.longValue() * memberConfig.getCostReward();
|
||||
}
|
||||
// 消费送积分
|
||||
if (levelConfig.getIsCostRewardPoints() == 1 && levelConfig.getCostRewardPoints() != null) {
|
||||
int points = (int) (money.floatValue() / levelConfig.getCostRewardPoints());
|
||||
if (levelVO.getIsCostRewardPoints() == 1 && levelVO.getCostRewardPoints() != null) {
|
||||
int points = (int) (money.floatValue() / levelVO.getCostRewardPoints());
|
||||
memberPointsService.addPoints(shopUser.getId(), points, "会员消费送积分", null);
|
||||
}
|
||||
}
|
||||
@@ -246,6 +246,31 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
}
|
||||
}
|
||||
case PAY -> exp = expVal;
|
||||
case MEMBER_TASK -> {
|
||||
if (levelVO.getIsCycleReward() == 1) {
|
||||
if (levelVO.getCycleRewardPoints() != null) {
|
||||
int points = levelVO.getCycleRewardPoints();
|
||||
memberPointsService.addPoints(shopUser.getId(), points, "会员任务奖励", null);
|
||||
}
|
||||
|
||||
if (levelVO.getCycleRewardCouponList() != null && !levelVO.getCycleRewardCouponList().isEmpty()) {
|
||||
|
||||
// TODO 待办
|
||||
ArrayList<MkCouponGiftDTO> giftDTOS = new ArrayList<>();
|
||||
// levelVO.getCycleRewardCouponList().forEach(item -> {
|
||||
// giftDTOS.add(new MkCouponGiftDTO().setCouponId(item.getCoupon().getId())
|
||||
// .setCouponId(item.getCoupon().getId())
|
||||
// .setCouponName(item.getCoupon().getTitle())
|
||||
// .setSourceName("会员开通赠券")
|
||||
// .setSourceId(shopUser)
|
||||
// .setType(1)
|
||||
// .setNum(item.getNum()));
|
||||
// });
|
||||
// couponGiftService.addCouponGift(memberOrderId, "会员开通赠券", 1, giftDTOS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -263,7 +288,7 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
shopUser.setExperience(shopUser.getExperience() + exp);
|
||||
// 修改会员等级
|
||||
MemberLevelConfig nextConfig = levelConfigService.getOne(new QueryWrapper().eq(MemberLevelConfig::getShopId, shopId)
|
||||
.gt(MemberLevelConfig::getExperienceValue, levelConfig.getExperienceValue()).orderBy(MemberLevelConfig::getExperienceValue, true).limit(1));
|
||||
.gt(MemberLevelConfig::getExperienceValue, levelVO.getExperienceValue()).orderBy(MemberLevelConfig::getExperienceValue, true).limit(1));
|
||||
|
||||
if (shopUser.getExperience() >= nextConfig.getExperienceValue()) {
|
||||
shopUser.setMemberLevelId(nextConfig.getId());
|
||||
@@ -327,17 +352,18 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(memberOrder.getCouponList())) {
|
||||
ArrayList<MkCouponGiftDTO> giftDTOS = new ArrayList<>();
|
||||
JSONArray.parseArray(memberOrder.getCouponList()).toJavaList(MemberConfigDTO.ConfigCoupon.class).forEach(item -> {
|
||||
giftDTOS.add(new MkCouponGiftDTO().setCouponId(item.getCoupon().getId())
|
||||
.setCouponId(item.getCoupon().getId())
|
||||
.setCouponName(item.getCoupon().getTitle())
|
||||
.setSourceName("会员开通赠券")
|
||||
.setSourceId(memberOrderId)
|
||||
.setType(1)
|
||||
.setNum(item.getNum()));
|
||||
});
|
||||
couponGiftService.addCouponGift(memberOrderId, "会员开通赠券", 1, giftDTOS);
|
||||
// TODO 发券流程
|
||||
// ArrayList<MkCouponGiftDTO> giftDTOS = new ArrayList<>();
|
||||
// JSONArray.parseArray(memberOrder.getCouponList()).toJavaList(MemberConfigDTO.ConfigCoupon.class).forEach(item -> {
|
||||
// giftDTOS.add(new MkCouponGiftDTO().setCouponId(item.getCoupon().getId())
|
||||
// .setCouponId(item.getCoupon().getId())
|
||||
// .setCouponName(item.getCoupon().getTitle())
|
||||
// .setSourceName("会员开通赠券")
|
||||
// .setSourceId(memberOrderId)
|
||||
// .setType(1)
|
||||
// .setNum(item.getNum()));
|
||||
// });
|
||||
// couponGiftService.addCouponGift(memberOrderId, "会员开通赠券", 1, giftDTOS);
|
||||
}
|
||||
|
||||
MemberLevelConfig levelConfig = levelConfigService.getOne(new QueryWrapper().eq(MemberLevelConfig::getShopId, shopId).orderBy(MemberLevelConfig::getExperienceValue, true).limit(1));
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.czg.market.dto.MemberLevelDTO;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.market.vo.MemberLevelVO;
|
||||
import com.czg.service.market.mapper.TbMemberLevelConfigMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MemberLevelConfig;
|
||||
import com.czg.market.service.MemberLevelConfigService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员等级配置 服务层实现。
|
||||
*
|
||||
@@ -14,5 +24,22 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class TbMemberLevelConfigServiceImpl extends ServiceImpl<TbMemberLevelConfigMapper, MemberLevelConfig> implements MemberLevelConfigService{
|
||||
|
||||
@Resource
|
||||
private ShopCouponService shopCouponService;
|
||||
@Override
|
||||
public MemberLevelVO detail(Long memberLevelId) {
|
||||
MemberLevelConfig memberLevelConfig = getById(memberLevelId);
|
||||
if (memberLevelConfig == null) {
|
||||
return null;
|
||||
}
|
||||
MemberLevelVO levelVO = BeanUtil.copyProperties(memberLevelConfig, MemberLevelVO.class, "cycleRewardCouponList");
|
||||
if (StrUtil.isNotBlank(memberLevelConfig.getCycleRewardCouponList())) {
|
||||
List<MemberLevelDTO.ConfigCoupon> coupons = JSONArray.parseArray(memberLevelConfig.getCycleRewardCouponList()).toList(MemberLevelDTO.ConfigCoupon.class);
|
||||
coupons.forEach(item -> {
|
||||
item.setCoupon(shopCouponService.getById(item.getCoupon().getId()));
|
||||
});
|
||||
levelVO.setCycleRewardCouponList(coupons);
|
||||
}
|
||||
return levelVO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkConsumeDiscountMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkShopRechargeDetailMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkShopRechargeMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user