优惠券 填充 券

This commit is contained in:
wangw 2025-09-18 18:11:23 +08:00
parent 39b37ea8bc
commit 2673440426
4 changed files with 61 additions and 9 deletions

View File

@ -0,0 +1,20 @@
package com.czg.account.vo;
import lombok.Data;
/**
* @author ww
* @description
*/
@Data
public class UserCouponFoodVo {
private Long id;
/**
* 商品名称
*/
private String name;
/**
* 商品图片第一张为缩略图其他为详情
*/
private String images;
}

View File

@ -3,7 +3,9 @@ package com.czg.account.vo;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author ww * @author ww
@ -16,19 +18,23 @@ public class UserCouponVo {
private BigDecimal fullAmount; private BigDecimal fullAmount;
private BigDecimal discountAmount; private BigDecimal discountAmount;
private Long couponId; private Long couponId;
private Long proId; private String foods;
// 商品名称
private String productName;
private String productCover;
//优惠券名称 //优惠券名称
private String name; private String name;
//优惠券类型 1 满减 2 商品 //优惠券类型 优惠券类型1-满减券2-商品兑换券3-折扣券4-第二件半价券 6-买一送一券7-固定价格券8-免配送费
private Integer type; private Integer type;
//到期时间 //到期时间
private Date endTime; private Date endTime;
private String useRestrictions; private String useRestrictions;
private boolean isUse = false; private boolean isUse = false;
/**
* 优惠券门槛商品列表
*/
List<UserCouponFoodVo> thresholdFoods = new ArrayList<>();
/**
* 优惠券可用商品列表
*/
List<UserCouponFoodVo> useFoods = new ArrayList<>();
} }

View File

@ -1,13 +1,17 @@
package com.czg.service.market.service.impl; package com.czg.service.market.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ValidateException; import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.czg.account.entity.ShopUser; import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService; import com.czg.account.service.ShopUserService;
import com.czg.account.vo.UserCouponFoodVo;
import com.czg.account.vo.UserCouponVo; import com.czg.account.vo.UserCouponVo;
import com.czg.market.dto.ShopCouponDTO; import com.czg.market.dto.ShopCouponDTO;
import com.czg.market.entity.MkShopCouponRecord; import com.czg.market.entity.MkShopCouponRecord;
@ -15,6 +19,8 @@ import com.czg.market.entity.ShopCoupon;
import com.czg.market.service.MkCouponGiftService; import com.czg.market.service.MkCouponGiftService;
import com.czg.market.service.MkShopCouponRecordService; import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.ShopCouponService; import com.czg.market.service.ShopCouponService;
import com.czg.product.entity.Product;
import com.czg.product.service.ProductService;
import com.czg.service.market.mapper.ShopCouponMapper; import com.czg.service.market.mapper.ShopCouponMapper;
import com.czg.utils.AssertUtil; import com.czg.utils.AssertUtil;
import com.czg.utils.PageUtil; import com.czg.utils.PageUtil;
@ -49,6 +55,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
private MkShopCouponRecordService recordService; private MkShopCouponRecordService recordService;
@DubboReference @DubboReference
private ShopUserService shopUserService; private ShopUserService shopUserService;
@DubboReference
private ProductService productService;
@Override @Override
public Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param) { public Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param) {
@ -136,7 +144,26 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId()); JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions")); tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
tbUserCouponVo.setUse(couponJson.getBoolean("isUse")); tbUserCouponVo.setUse(couponJson.getBoolean("isUse"));
if (tbUserCouponVo.getType() == 2 || tbUserCouponVo.getType() == 4 || tbUserCouponVo.getType() == 6) {
if (StrUtil.isNotBlank(tbUserCouponVo.getFoods()) && !",".equals(tbUserCouponVo.getFoods())) {
List<Long> couponFoodIds = Arrays.stream(tbUserCouponVo.getFoods().split(",")).map(Long::parseLong).toList();
if (CollUtil.isNotEmpty(couponFoodIds)) {
List<Product> list = productService.list(new QueryWrapper()
.in(Product::getId, couponFoodIds).eq(Product::getIsDel, 0));
if (CollUtil.isEmpty(list)) {
continue;
}
if (tbUserCouponVo.getType() == 2) {
tbUserCouponVo.setUseFoods(JSON.parseObject(JSON.toJSONString(list), new TypeReference<>() {
}));
} else {
tbUserCouponVo.setThresholdFoods(JSON.parseObject(JSON.toJSONString(list), new TypeReference<>() {
}));
}
}
}
}
} }
tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed()); tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
return tbUserCouponVos; return tbUserCouponVos;

View File

@ -59,15 +59,14 @@
inRecord.full_amount as fullAmount, inRecord.full_amount as fullAmount,
inRecord.discount_amount as discountAmount, inRecord.discount_amount as discountAmount,
inRecord.coupon_id as couponId, inRecord.coupon_id as couponId,
pro.id as proId,
pro.name as productName,
inRecord.name as name, inRecord.name as name,
inRecord.type, inRecord.type,
coupon.foods as foods,
inRecord.use_end_time as endTime inRecord.use_end_time as endTime
FROM FROM
mk_shop_coupon_record inRecord mk_shop_coupon_record inRecord
LEFT JOIN tb_shop_info shop ON inRecord.shop_id = shop.id LEFT JOIN tb_shop_info shop ON inRecord.shop_id = shop.id
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId} LEFT JOIN mk_shop_coupon coupon ON inRecord.coupon_id = coupon.id
WHERE WHERE
inRecord.shop_user_id = #{shopUserId} inRecord.shop_user_id = #{shopUserId}
<if test="shopId != null and shopId != ''"> <if test="shopId != null and shopId != ''">