用户优惠券列表3
This commit is contained in:
parent
55f488db7f
commit
5cd753cc1c
|
|
@ -1,8 +1,8 @@
|
|||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.utils.AssertUtil;
|
||||
|
|
@ -28,10 +28,11 @@ public class UShopCouponController {
|
|||
* @param status 0 未使用 1已使用 2已过期
|
||||
*/
|
||||
@GetMapping("/findByUserId")
|
||||
public CzgResult<Page<MkShopCouponRecord>> findByUserId(
|
||||
public CzgResult<Page<UserCouponVO>> findByUserId(
|
||||
@RequestParam(required = false) Integer status,
|
||||
@RequestParam(required = false) String name,
|
||||
@RequestParam(required = false) Long shopId) {
|
||||
return CzgResult.success(couponService.find(StpKit.USER.getLoginIdAsLong(), shopId, status));
|
||||
return CzgResult.success(couponService.find(StpKit.USER.getLoginIdAsLong(),name, shopId, status));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public class UserCouponVo {
|
|||
private String shopName;
|
||||
private BigDecimal fullAmount;
|
||||
private BigDecimal discountAmount;
|
||||
private BigDecimal discountRate;
|
||||
private Long couponId;
|
||||
private String foods;
|
||||
//优惠券名称
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.czg.account.vo.UserCouponVo;
|
|||
import com.czg.market.dto.MkRewardCouponDTO;
|
||||
import com.czg.market.dto.MkShopCouponGiftDTO;
|
||||
import com.czg.market.dto.MkShopCouponRecordDTO;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
|
|
@ -23,7 +24,7 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
|
|||
|
||||
List<CouponReceiveVo> queryReceive(QueryReceiveDto param);
|
||||
|
||||
List<MkShopCouponRecord> findByUser(List<Long> shopUserIds, Integer status);
|
||||
List<UserCouponVO> findByUser(String name, List<Long> shopUserIds, Integer status);
|
||||
|
||||
List<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId, Integer type);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.czg.market.service;
|
|||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.market.dto.ShopCouponDTO;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
|
|
@ -26,7 +27,7 @@ public interface ShopCouponService extends IService<ShopCoupon> {
|
|||
|
||||
void deleteCoupon(Long id);
|
||||
|
||||
Page<MkShopCouponRecord> find(Long userId, Long shopId, Integer status);
|
||||
Page<UserCouponVO> find(Long userId, String name, Long shopId, Integer status);
|
||||
|
||||
List<UserCouponVo> findCoupon(Long shopId, Long shopUserId, Integer type);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,156 @@
|
|||
package com.czg.market.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 优惠券发放记录表 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-13
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class UserCouponVO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 卷名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 优惠券类型:1-满减券,2-商品兑换券,3-折扣券,4-第二件半价券, 6-买一送一券,7-固定价格券,8-免配送费券
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 满多少金额
|
||||
*/
|
||||
private BigDecimal fullAmount;
|
||||
|
||||
/**
|
||||
* 减多少金额
|
||||
*/
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
/**
|
||||
* 折扣率 %
|
||||
*/
|
||||
private Integer discountRate;
|
||||
|
||||
|
||||
/**
|
||||
* 领取时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private LocalDateTime useTime;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private LocalDateTime effectEndTime;
|
||||
/**
|
||||
* 优惠券生效时间
|
||||
*/
|
||||
private LocalDateTime effectStartTime;
|
||||
|
||||
/**
|
||||
* 0未使用
|
||||
* 1已使用
|
||||
* 2已过期
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 可用门店类型:only-仅本店;all-所有门店,custom-指定门店
|
||||
*/
|
||||
private String useShopType;
|
||||
|
||||
/**
|
||||
* 可用门店
|
||||
*/
|
||||
private String useShops;
|
||||
/**
|
||||
* 可用商品
|
||||
*/
|
||||
private String foods;
|
||||
|
||||
/**
|
||||
* 可使用类型:dine堂食/pickup自取/deliv配送/express快递
|
||||
*/
|
||||
private String useType;
|
||||
|
||||
/**
|
||||
* 可用周期,如:周一,周二,周三,周四,周五,周六,周七
|
||||
*/
|
||||
private String useDays;
|
||||
|
||||
/**
|
||||
* 可用时间段类型:all-全时段,custom-指定时段
|
||||
*/
|
||||
private String useTimeType;
|
||||
|
||||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
private LocalDateTime useStartTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
private LocalDateTime useEndTime;
|
||||
|
||||
|
||||
/**
|
||||
* 每人领取限量,-10086为不限量
|
||||
*/
|
||||
private Integer getLimit;
|
||||
|
||||
/**
|
||||
* 每人每日使用限量,-10086为不限量
|
||||
*/
|
||||
private Integer useLimit;
|
||||
|
||||
/**
|
||||
* 与限时折扣同享:0-否,1-是
|
||||
*/
|
||||
private Integer discountShare;
|
||||
|
||||
/**
|
||||
* 与会员价同享:0-否,1-是
|
||||
*/
|
||||
private Integer vipPriceShare;
|
||||
|
||||
/**
|
||||
* 附加规则说明
|
||||
*/
|
||||
private String ruleDetails;
|
||||
|
||||
private String deductNum;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.czg.service.market.mapper;
|
|||
import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
@ -19,7 +20,7 @@ public interface MkShopCouponRecordMapper extends BaseMapper<MkShopCouponRecord>
|
|||
|
||||
List<CouponReceiveVo> queryReceive(@Param("param") QueryReceiveDto param);
|
||||
|
||||
List<MkShopCouponRecord> findByUser(List<Long> shopUserIds, Integer status);
|
||||
List<UserCouponVO> findCouponVOByUser(String name, List<Long> shopUserIds, Integer status);
|
||||
|
||||
List<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId, Integer type);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import com.czg.market.entity.MkShopCouponRecord;
|
|||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.czg.service.market.mapper.MkShopCouponRecordMapper;
|
||||
import com.czg.service.market.mapper.ShopCouponMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
|
|
@ -66,8 +67,8 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<MkShopCouponRecord> findByUser(List<Long> shopUserIds, Integer status) {
|
||||
return getMapper().findByUser(shopUserIds, status);
|
||||
public List<UserCouponVO> findByUser(String name, List<Long> shopUserIds, Integer status) {
|
||||
return getMapper().findCouponVOByUser(name, shopUserIds, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ 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.ShopInfo;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.vo.UserCouponFoodVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
|
|
@ -19,6 +21,7 @@ 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.market.vo.UserCouponVO;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.service.market.mapper.ShopCouponMapper;
|
||||
|
|
@ -54,6 +57,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
@Resource
|
||||
private MkShopCouponRecordService recordService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private ProductService productService;
|
||||
|
|
@ -115,7 +120,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
}
|
||||
|
||||
@Override
|
||||
public Page<MkShopCouponRecord> find(Long userId, Long shopId, Integer status) {
|
||||
public Page<UserCouponVO> find(Long userId, String name, Long shopId, Integer status) {
|
||||
Page<Object> page = PageUtil.buildPage();
|
||||
List<Long> shopUserIds = shopUserService.listAs(new QueryWrapper().eq(ShopUser::getUserId, userId)
|
||||
.eq(ShopUser::getSourceShopId, shopId)
|
||||
|
|
@ -123,7 +128,57 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
|
||||
if (CollectionUtil.isNotEmpty(shopUserIds)) {
|
||||
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
|
||||
return PageUtil.convert(new PageInfo<>(recordService.findByUser(shopUserIds, status)));
|
||||
List<UserCouponVO> coupons = recordService.findByUser(name, shopUserIds, status);
|
||||
for (UserCouponVO coupon : coupons) {
|
||||
int maxShow = 5;
|
||||
if (StrUtil.isNotBlank(coupon.getFoods())) {
|
||||
List<String> productNames = productService.listAs(new QueryWrapper().select(Product::getName)
|
||||
.in(Product::getId, Arrays.stream(coupon.getFoods().split(",")).map(Long::parseLong).toList())
|
||||
.eq(Product::getIsDel, 0), String.class);
|
||||
if (CollUtil.isNotEmpty(productNames)) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < productNames.size(); i++) {
|
||||
if (i > 0) {
|
||||
result.append(",");
|
||||
}
|
||||
result.append(productNames.get(i));
|
||||
if (i == maxShow - 1 && i != productNames.size() - 1) {
|
||||
result.append("...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
coupon.setFoods(result.toString());
|
||||
}
|
||||
}else {
|
||||
coupon.setFoods("全部商品");
|
||||
}
|
||||
if ("only".equals(coupon.getUseShopType())) {
|
||||
coupon.setUseShops("仅本店");
|
||||
}else if ("all".equals(coupon.getUseShopType())) {
|
||||
coupon.setUseShops("所有门店");
|
||||
}else if ("custom".equals(coupon.getUseShopType())) {
|
||||
if(StrUtil.isNotBlank(coupon.getUseShops())){
|
||||
List<String> shopNames = shopInfoService.listAs(new QueryWrapper().select(ShopInfo::getShopName)
|
||||
.in(ShopInfo::getId, Arrays.stream(coupon.getUseShops().split(",")).map(Long::parseLong).toList())
|
||||
.eq(ShopInfo::getStatus, 1), String.class);
|
||||
if (CollUtil.isNotEmpty(shopNames)) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < shopNames.size(); i++) {
|
||||
if (i > 0) {
|
||||
result.append(",");
|
||||
}
|
||||
result.append(shopNames.get(i));
|
||||
if (i == maxShow - 1 && i != shopNames.size() - 1) {
|
||||
result.append("...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
coupon.setUseShops(result.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return PageUtil.convert(new PageInfo<>(coupons));
|
||||
}
|
||||
return new Page<>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,14 +35,33 @@
|
|||
</if>
|
||||
order by record.create_time desc
|
||||
</select>
|
||||
<select id="findByUser" resultType="com.czg.market.entity.MkShopCouponRecord">
|
||||
select mk_shop_coupon_record.*,tb_shop_info.shop_name
|
||||
<select id="findCouponVOByUser" resultType="com.czg.market.vo.UserCouponVO">
|
||||
select mk_shop_coupon_record.*,
|
||||
mk_shop_coupon_record.use_start_time as effectStartTime,
|
||||
mk_shop_coupon_record.use_end_time as effectEndTime,
|
||||
coupon.use_shop_type as useShopType,
|
||||
coupon.foods as foods,
|
||||
coupon.use_shop as useShops,
|
||||
coupon.use_type as useType,
|
||||
coupon.use_days as useDays,
|
||||
coupon.use_time_type as useTimeType,
|
||||
coupon.use_start_time as useStartTime,
|
||||
coupon.use_end_time as useEndTime,
|
||||
coupon.get_limit as getLimit,
|
||||
coupon.use_limit as useLimit,
|
||||
coupon.discount_share as discountShare,
|
||||
coupon.vip_price_share as vipPriceShare,
|
||||
coupon.rule_details as ruleDetails,
|
||||
coupon.deduct_num as deductNum
|
||||
from mk_shop_coupon_record
|
||||
left join tb_shop_info on mk_shop_coupon_record.shop_id = tb_shop_info.id
|
||||
left join mk_shop_coupon coupon on mk_shop_coupon_record.coupon_id = coupon.id
|
||||
where mk_shop_coupon_record.shop_user_id in
|
||||
<foreach collection="shopUserIds" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
<if test="name != null and name != ''">
|
||||
and mk_shop_coupon_record.name like concat('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and mk_shop_coupon_record.status = #{status}
|
||||
</if>
|
||||
|
|
@ -58,6 +77,7 @@
|
|||
shop.shop_name as shopName,
|
||||
inRecord.full_amount as fullAmount,
|
||||
inRecord.discount_amount as discountAmount,
|
||||
inRecord.discount_rate as discountRate,
|
||||
inRecord.coupon_id as couponId,
|
||||
inRecord.name as name,
|
||||
inRecord.type,
|
||||
|
|
|
|||
Loading…
Reference in New Issue