优惠券店铺列表
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.czg.controller.user;
|
package com.czg.controller.user;
|
||||||
|
|
||||||
|
import com.czg.account.vo.ShopInfoCouponVO;
|
||||||
import com.czg.account.vo.UserCouponVo;
|
import com.czg.account.vo.UserCouponVo;
|
||||||
import com.czg.market.service.ShopCouponService;
|
import com.czg.market.service.ShopCouponService;
|
||||||
import com.czg.market.vo.UserCouponVO;
|
import com.czg.market.vo.UserCouponVO;
|
||||||
@@ -22,6 +23,19 @@ public class UShopCouponController {
|
|||||||
@Resource
|
@Resource
|
||||||
private ShopCouponService couponService;
|
private ShopCouponService couponService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前店铺会员信息
|
||||||
|
* 请求头必须携带shopId, 不携带则会失败
|
||||||
|
*
|
||||||
|
* @return 店铺会员信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/shops")
|
||||||
|
public CzgResult<List<ShopInfoCouponVO>> shops() {
|
||||||
|
return CzgResult.success(couponService.getShopByCouponRecord(StpKit.USER.getShopId(), StpKit.USER.getLoginIdAsLong()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户Id 查找优惠券
|
* 通过用户Id 查找优惠券
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.czg.market.service;
|
package com.czg.market.service;
|
||||||
|
|
||||||
|
import com.czg.account.vo.ShopInfoCouponVO;
|
||||||
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;
|
||||||
@@ -34,4 +35,6 @@ public interface ShopCouponService extends IService<ShopCoupon> {
|
|||||||
Boolean use(List<Long> ids, Long shopUserId, Long orderId);
|
Boolean use(List<Long> ids, Long shopUserId, Long orderId);
|
||||||
|
|
||||||
Boolean refund(Long orderId, Long shopUserId);
|
Boolean refund(Long orderId, Long shopUserId);
|
||||||
|
|
||||||
|
List<ShopInfoCouponVO> getShopByCouponRecord(Long shopId, Long shopUserId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.czg.service.market.mapper;
|
|||||||
|
|
||||||
import com.czg.account.dto.QueryReceiveDto;
|
import com.czg.account.dto.QueryReceiveDto;
|
||||||
import com.czg.account.vo.CouponReceiveVo;
|
import com.czg.account.vo.CouponReceiveVo;
|
||||||
|
import com.czg.account.vo.ShopInfoCouponVO;
|
||||||
import com.czg.account.vo.UserCouponVo;
|
import com.czg.account.vo.UserCouponVo;
|
||||||
import com.czg.market.vo.UserCouponVO;
|
import com.czg.market.vo.UserCouponVO;
|
||||||
import com.mybatisflex.core.BaseMapper;
|
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<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId, Integer type);
|
||||||
|
|
||||||
|
List<ShopInfoCouponVO> getShopByCouponRecord(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import com.czg.account.entity.ShopInfo;
|
|||||||
import com.czg.account.entity.ShopUser;
|
import com.czg.account.entity.ShopUser;
|
||||||
import com.czg.account.service.ShopInfoService;
|
import com.czg.account.service.ShopInfoService;
|
||||||
import com.czg.account.service.ShopUserService;
|
import com.czg.account.service.ShopUserService;
|
||||||
|
import com.czg.account.vo.ShopInfoCouponVO;
|
||||||
import com.czg.account.vo.UserCouponFoodVo;
|
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;
|
||||||
@@ -24,6 +25,7 @@ import com.czg.market.service.ShopCouponService;
|
|||||||
import com.czg.market.vo.UserCouponVO;
|
import com.czg.market.vo.UserCouponVO;
|
||||||
import com.czg.product.entity.Product;
|
import com.czg.product.entity.Product;
|
||||||
import com.czg.product.service.ProductService;
|
import com.czg.product.service.ProductService;
|
||||||
|
import com.czg.service.market.mapper.MkShopCouponRecordMapper;
|
||||||
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;
|
||||||
@@ -56,6 +58,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||||||
private MkCouponGiftService couponGiftService;
|
private MkCouponGiftService couponGiftService;
|
||||||
@Resource
|
@Resource
|
||||||
private MkShopCouponRecordService recordService;
|
private MkShopCouponRecordService recordService;
|
||||||
|
@Resource
|
||||||
|
private MkShopCouponRecordMapper recordMapper;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopInfoService shopInfoService;
|
private ShopInfoService shopInfoService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
@@ -149,15 +153,15 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||||||
}
|
}
|
||||||
coupon.setFoods(result.toString());
|
coupon.setFoods(result.toString());
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
coupon.setFoods("全部商品");
|
coupon.setFoods("全部商品");
|
||||||
}
|
}
|
||||||
if ("only".equals(coupon.getUseShopType())) {
|
if ("only".equals(coupon.getUseShopType())) {
|
||||||
coupon.setUseShops("仅本店");
|
coupon.setUseShops("仅本店");
|
||||||
}else if ("all".equals(coupon.getUseShopType())) {
|
} else if ("all".equals(coupon.getUseShopType())) {
|
||||||
coupon.setUseShops("所有门店");
|
coupon.setUseShops("所有门店");
|
||||||
}else if ("custom".equals(coupon.getUseShopType())) {
|
} else if ("custom".equals(coupon.getUseShopType())) {
|
||||||
if(StrUtil.isNotBlank(coupon.getUseShops())){
|
if (StrUtil.isNotBlank(coupon.getUseShops())) {
|
||||||
List<String> shopNames = shopInfoService.listAs(new QueryWrapper().select(ShopInfo::getShopName)
|
List<String> shopNames = shopInfoService.listAs(new QueryWrapper().select(ShopInfo::getShopName)
|
||||||
.in(ShopInfo::getId, Arrays.stream(coupon.getUseShops().split(",")).map(Long::parseLong).toList())
|
.in(ShopInfo::getId, Arrays.stream(coupon.getUseShops().split(",")).map(Long::parseLong).toList())
|
||||||
.eq(ShopInfo::getStatus, 1), String.class);
|
.eq(ShopInfo::getStatus, 1), String.class);
|
||||||
@@ -265,6 +269,42 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||||||
.update();
|
.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) {
|
private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, DateTimeFormatter formatter) {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
boolean isUse = true;
|
boolean isUse = true;
|
||||||
|
|||||||
@@ -106,4 +106,16 @@
|
|||||||
and inRecord.is_del = 0
|
and inRecord.is_del = 0
|
||||||
order by inRecord.use_end_time
|
order by inRecord.use_end_time
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user