优惠券 填充 券

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

View File

@@ -1,13 +1,17 @@
package com.czg.service.market.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService;
import com.czg.account.vo.UserCouponFoodVo;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.dto.ShopCouponDTO;
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.MkShopCouponRecordService;
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.utils.AssertUtil;
import com.czg.utils.PageUtil;
@@ -49,6 +55,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
private MkShopCouponRecordService recordService;
@DubboReference
private ShopUserService shopUserService;
@DubboReference
private ProductService productService;
@Override
public Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param) {
@@ -136,7 +144,26 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
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());
return tbUserCouponVos;

View File

@@ -59,15 +59,14 @@
inRecord.full_amount as fullAmount,
inRecord.discount_amount as discountAmount,
inRecord.coupon_id as couponId,
pro.id as proId,
pro.name as productName,
inRecord.name as name,
inRecord.type,
coupon.foods as foods,
inRecord.use_end_time as endTime
FROM
mk_shop_coupon_record inRecord
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
inRecord.shop_user_id = #{shopUserId}
<if test="shopId != null and shopId != ''">