优惠券店铺列表

This commit is contained in:
wangw 2025-09-25 14:37:40 +08:00
parent b5e6077321
commit 1e39877bb0
6 changed files with 132 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.czg.controller.user;
import com.czg.account.vo.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.service.ShopCouponService;
import com.czg.market.vo.UserCouponVO;
@ -22,6 +23,19 @@ public class UShopCouponController {
@Resource
private ShopCouponService couponService;
/**
* 获取当前店铺会员信息
* 请求头必须携带shopId, 不携带则会失败
*
* @return 店铺会员信息
*/
@GetMapping("/shops")
public CzgResult<List<ShopInfoCouponVO>> shops() {
return CzgResult.success(couponService.getShopByCouponRecord(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong()));
}
/**
* 通过用户Id 查找优惠券
*

View File

@ -0,0 +1,57 @@
package com.czg.account.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
/**
* 店铺信息 优惠券选择VO
*
* @author Administrator
* @since 2025-02-10
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ShopInfoCouponVO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* shopId
*/
private Long shopId;
/**
* 店铺名称
*/
private String shopName;
/**
* 连锁店扩展店名
*/
private String chainName;
/**
* 店铺logo
*/
private String logo;
/**
* 详细地址
*/
private String shopAddress;
/**
* 优惠券数量
*/
private Integer couponCount;
}

View File

@ -1,5 +1,6 @@
package com.czg.market.service;
import com.czg.account.vo.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.dto.ShopCouponDTO;
import com.czg.market.entity.MkShopCouponRecord;
@ -34,4 +35,6 @@ public interface ShopCouponService extends IService<ShopCoupon> {
Boolean use(List<Long> ids, Long shopUserId, Long orderId);
Boolean refund(Long orderId, Long shopUserId);
List<ShopInfoCouponVO> getShopByCouponRecord(Long shopId, Long shopUserId);
}

View File

@ -2,6 +2,7 @@ package com.czg.service.market.mapper;
import com.czg.account.dto.QueryReceiveDto;
import com.czg.account.vo.CouponReceiveVo;
import com.czg.account.vo.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.vo.UserCouponVO;
import com.mybatisflex.core.BaseMapper;
@ -24,4 +25,5 @@ public interface MkShopCouponRecordMapper extends BaseMapper<MkShopCouponRecord>
List<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId, Integer type);
List<ShopInfoCouponVO> getShopByCouponRecord(Long userId);
}

View File

@ -13,6 +13,7 @@ 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.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponFoodVo;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.dto.ShopCouponDTO;
@ -24,6 +25,7 @@ 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.MkShopCouponRecordMapper;
import com.czg.service.market.mapper.ShopCouponMapper;
import com.czg.utils.AssertUtil;
import com.czg.utils.PageUtil;
@ -56,6 +58,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
private MkCouponGiftService couponGiftService;
@Resource
private MkShopCouponRecordService recordService;
@Resource
private MkShopCouponRecordMapper recordMapper;
@DubboReference
private ShopInfoService shopInfoService;
@DubboReference
@ -149,15 +153,15 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
}
coupon.setFoods(result.toString());
}
}else {
} else {
coupon.setFoods("全部商品");
}
if ("only".equals(coupon.getUseShopType())) {
coupon.setUseShops("仅本店");
}else if ("all".equals(coupon.getUseShopType())) {
} else if ("all".equals(coupon.getUseShopType())) {
coupon.setUseShops("所有门店");
}else if ("custom".equals(coupon.getUseShopType())) {
if(StrUtil.isNotBlank(coupon.getUseShops())){
} 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);
@ -265,6 +269,42 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
.update();
}
@Override
public List<ShopInfoCouponVO> getShopByCouponRecord(Long shopId, Long shopUserId) {
List<ShopInfoCouponVO> originalList = recordMapper.getShopByCouponRecord(shopUserId);
// 2. 若shopId为空直接返回原集合
if (shopId == null) {
return originalList;
}
// 3. 若shopId不为空筛选目标元素并重组列表
List<ShopInfoCouponVO> resultList = new ArrayList<>();
ShopInfoCouponVO targetShop = null;
// 遍历原始集合找到目标元素
for (ShopInfoCouponVO shopVO : originalList) {
if (Objects.equals(shopVO.getShopId(), shopId)) {
targetShop = shopVO;
break;
}
}
if (targetShop != null) {
resultList.add(targetShop);
// 再添加其余非目标元素
for (ShopInfoCouponVO shopVO : originalList) {
if (!Objects.equals(shopVO.getShopId(), shopId)) {
resultList.add(shopVO);
}
}
} else {
resultList = originalList;
}
return resultList;
}
private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, DateTimeFormatter formatter) {
JSONObject json = new JSONObject();
boolean isUse = true;

View File

@ -106,4 +106,16 @@
and inRecord.is_del = 0
order by inRecord.use_end_time
</select>
<select id="getShopByCouponRecord" resultType="com.czg.account.vo.ShopInfoCouponVO">
SELECT inRecord.shop_id AS shopId,
shop.shop_name AS shopName,
shop.address AS shopAddress,
shop.chain_name AS chainName,
COUNT(inRecord.coupon_id) AS couponCount
FROM mk_shop_coupon_record inRecord
LEFT JOIN tb_shop_info shop ON inRecord.shop_id = shop.id
WHERE inRecord.user_id = #{userId}
AND inRecord.is_del = 0
GROUP BY inRecord.shop_id
</select>
</mapper>