parent
3be9ca1710
commit
7dc3183289
|
|
@ -66,8 +66,8 @@ public class ShopCouponController {
|
|||
* 权限标识: coupon:delete
|
||||
*/
|
||||
@SaAdminCheckPermission("coupon:queryReceive")
|
||||
@PostMapping("/queryReceive")
|
||||
public CzgResult<Page<CouponReceiveVo>> queryReceive(@Validated @RequestBody QueryReceiveDto param) {
|
||||
@GetMapping("/queryReceive")
|
||||
public CzgResult<Page<CouponReceiveVo>> queryReceive(@Validated QueryReceiveDto param) {
|
||||
return CzgResult.success(couponService.queryReceive(param));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package com.czg.controller.user;
|
|||
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -27,8 +29,21 @@ public class UserShopCouponController {
|
|||
* @param status 0 未使用 1已使用 2已过期
|
||||
*/
|
||||
@GetMapping("/findByUserId")
|
||||
public CzgResult<List<ShopActivateCouponRecord>> findByUserId(
|
||||
@RequestParam Long shopUserId, @RequestParam(required = false) Integer status) {
|
||||
return CzgResult.success(couponService.find(shopUserId, status));
|
||||
public CzgResult<Page<ShopActivateCouponRecord>> findByUserId(
|
||||
@RequestParam Long userId,
|
||||
@RequestParam(required = false) Integer status,
|
||||
@RequestParam(required = false) Long orderId) {
|
||||
return CzgResult.success(couponService.find(userId, orderId, status));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单后使用
|
||||
* 通过用户Id 查找优惠券
|
||||
*
|
||||
* @param shopUserId 店铺用户Id
|
||||
*/
|
||||
@GetMapping("/findCoupon")
|
||||
public CzgResult<List<UserCouponVo>> findCoupon(@RequestHeader String shopId, @RequestParam Long shopUserId) {
|
||||
return CzgResult.success(couponService.findCoupon(Long.parseLong(shopId), shopUserId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public class AdminOrderController {
|
|||
/**
|
||||
* 订单列表
|
||||
*/
|
||||
@PostMapping
|
||||
public CzgResult<Page<OrderInfoVo>> getOrderPage(@RequestBody OrderInfoQueryDTO queryDTO) {
|
||||
@GetMapping
|
||||
public CzgResult<Page<OrderInfoVo>> getOrderPage(OrderInfoQueryDTO queryDTO) {
|
||||
queryDTO.setShopId(StpKit.USER.getShopId());
|
||||
return CzgResult.success(orderInfoService.getOrderByPage(queryDTO));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ public class UserOrderController {
|
|||
/**
|
||||
* 订单列表
|
||||
*/
|
||||
@PostMapping
|
||||
public CzgResult<Page<OrderInfoVo>> getOrderPage(@RequestBody OrderInfoQueryDTO queryDTO) {
|
||||
@GetMapping
|
||||
public CzgResult<Page<OrderInfoVo>> getOrderPage(OrderInfoQueryDTO queryDTO) {
|
||||
queryDTO.setIsDel(0);
|
||||
queryDTO.setUserId(StpKit.USER.getLoginIdAsLong());
|
||||
return CzgResult.success(orderInfoService.getOrderByPage(queryDTO));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.czg.account.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ public class ShopActivateCouponRecord implements Serializable {
|
|||
* 店铺id
|
||||
*/
|
||||
private Long shopId;
|
||||
@Column(ignore = true)
|
||||
private String shopName;
|
||||
|
||||
/**
|
||||
* 来源活动id
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ import com.mybatisflex.annotation.KeyType;
|
|||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Time;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
|
@ -108,12 +108,12 @@ public class ShopCoupon implements Serializable {
|
|||
/**
|
||||
* 可用开始时间
|
||||
*/
|
||||
private Time useStartTime;
|
||||
private LocalTime useStartTime;
|
||||
|
||||
/**
|
||||
* 可用结束时间
|
||||
*/
|
||||
private Time useEndTime;
|
||||
private LocalTime useEndTime;
|
||||
|
||||
/**
|
||||
* 满多少金额
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ package com.czg.account.service;
|
|||
|
||||
import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 活动商品赠送记录表 服务层。
|
||||
*
|
||||
|
|
@ -15,5 +18,9 @@ import com.czg.account.entity.ShopActivateCouponRecord;
|
|||
public interface ShopActivateCouponRecordService extends IService<ShopActivateCouponRecord> {
|
||||
|
||||
|
||||
Page<CouponReceiveVo> queryReceive(Page<CouponReceiveVo> page, QueryReceiveDto param);
|
||||
Page<CouponReceiveVo> queryReceive(Page<CouponReceiveVo> page, QueryReceiveDto param);
|
||||
|
||||
Page<ShopActivateCouponRecord> findByUser(Page<ShopActivateCouponRecord> page, List<Long> shopUserIds, Integer status);
|
||||
|
||||
List<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.czg.account.dto.ShopCouponDTO;
|
|||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
|
|
@ -34,7 +35,9 @@ public interface ShopCouponService extends IService<ShopCoupon> {
|
|||
Page<CouponReceiveVo> queryReceive(QueryReceiveDto param);
|
||||
|
||||
|
||||
List<ShopActivateCouponRecord> find(Long shopUserId, Integer status);
|
||||
Page<ShopActivateCouponRecord> find(Long userId, Long orderId, Integer status);
|
||||
|
||||
List<UserCouponVo> findCoupon(Long shopId, Long shopUserId);
|
||||
|
||||
Boolean use(List<Long> ids, Long shopUserId, Long orderId);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,14 @@ import lombok.Data;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
*/
|
||||
@Data
|
||||
public class UserCouponVo {
|
||||
private Long id;
|
||||
private Long shopId;
|
||||
private String shopName;
|
||||
private BigDecimal fullAmount;
|
||||
private BigDecimal discountAmount;
|
||||
private Long couponId;
|
||||
|
|
@ -24,20 +29,8 @@ public class UserCouponVo {
|
|||
private Integer num;
|
||||
//到期时间
|
||||
private Date endTime;
|
||||
private Long expireTime;
|
||||
private String useRestrictions;
|
||||
private boolean isUse = false;
|
||||
//当前使用数量
|
||||
private BigDecimal currentUseNum;
|
||||
private Integer finalUseNum;
|
||||
private BigDecimal finalDiscountAmount = new BigDecimal(0);
|
||||
|
||||
|
||||
public void setEndTime(Date endTime) {
|
||||
this.endTime = endTime;
|
||||
if(endTime!=null){
|
||||
expireTime=endTime.getTime();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ package com.czg.service.account.mapper;
|
|||
|
||||
import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 活动商品赠送记录表 映射层。
|
||||
*
|
||||
|
|
@ -15,4 +18,7 @@ import com.mybatisflex.core.paginate.Page;
|
|||
public interface ShopActivateCouponRecordMapper extends BaseMapper<ShopActivateCouponRecord> {
|
||||
|
||||
Page<CouponReceiveVo> queryReceive(Page<CouponReceiveVo> page, QueryReceiveDto param);
|
||||
|
||||
Page<ShopActivateCouponRecord> findByUser(Page<ShopActivateCouponRecord> page, List<Long> shopUserIds, Integer status);
|
||||
List<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,14 @@ import com.czg.account.dto.QueryReceiveDto;
|
|||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.service.ShopActivateCouponRecordService;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.service.account.mapper.ShopActivateCouponRecordMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 活动商品赠送记录表 服务层实现。
|
||||
*
|
||||
|
|
@ -16,10 +19,20 @@ import org.apache.dubbo.config.annotation.DubboService;
|
|||
* @since 2025-02-20
|
||||
*/
|
||||
@DubboService
|
||||
public class ShopActivateCouponRecordServiceImpl extends ServiceImpl<ShopActivateCouponRecordMapper, ShopActivateCouponRecord> implements ShopActivateCouponRecordService{
|
||||
public class ShopActivateCouponRecordServiceImpl extends ServiceImpl<ShopActivateCouponRecordMapper, ShopActivateCouponRecord> implements ShopActivateCouponRecordService {
|
||||
|
||||
@Override
|
||||
public Page<CouponReceiveVo> queryReceive(Page<CouponReceiveVo> page, QueryReceiveDto param) {
|
||||
return getMapper().queryReceive(page, param);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ShopActivateCouponRecord> findByUser(Page<ShopActivateCouponRecord> page, List<Long> shopUserIds, Integer status) {
|
||||
return getMapper().findByUser(page, shopUserIds, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCouponVo> queryByVipIdAndShopId(Long shopId, Long shopUserId) {
|
||||
return getMapper().queryByVipIdAndShopId(shopId, shopUserId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,35 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.QueryReceiveDto;
|
||||
import com.czg.account.dto.ShopCouponDTO;
|
||||
import com.czg.account.entity.ShopActivateCouponRecord;
|
||||
import com.czg.account.entity.ShopCoupon;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopActivateCouponRecordService;
|
||||
import com.czg.account.service.ShopCouponService;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.vo.CouponReceiveVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopCouponMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 优惠券 服务层实现。
|
||||
|
|
@ -32,6 +42,10 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
|
||||
@Resource
|
||||
private ShopActivateCouponRecordService couponRecordService;
|
||||
@Resource
|
||||
private ShopUserService shopUserService;
|
||||
@Resource
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private ProductService productService;
|
||||
|
||||
|
|
@ -71,15 +85,37 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
|
||||
|
||||
@Override
|
||||
public List<ShopActivateCouponRecord> find(Long shopUserId, Integer status) {
|
||||
List<ShopActivateCouponRecord> list = couponRecordService.queryChain()
|
||||
.eq(ShopActivateCouponRecord::getShopId, StpKit.USER.getShopId())
|
||||
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
|
||||
.eq(ShopActivateCouponRecord::getStatus, status)
|
||||
.orderBy(ShopActivateCouponRecord::getStatus).asc()
|
||||
.orderBy(ShopActivateCouponRecord::getCreateTime).desc()
|
||||
.select().list();
|
||||
return list;
|
||||
public Page<ShopActivateCouponRecord> find(Long userId, Long orderId, Integer status) {
|
||||
List<Long> shopUserIds = shopUserService.queryChain().eq(ShopUser::getUserId, userId).select(ShopUser::getId).listAs(Long.class);
|
||||
if (CollectionUtil.isNotEmpty(shopUserIds)) {
|
||||
return couponRecordService.findByUser(PageUtil.buildPage(), shopUserIds, status);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCouponVo> findCoupon(Long shopId, Long shopUserId) {
|
||||
List<UserCouponVo> tbUserCouponVos = couponRecordService.queryByVipIdAndShopId(shopId, shopUserId);
|
||||
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
|
||||
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
|
||||
LocalTime now = LocalTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
|
||||
//券id 券使用描述
|
||||
Map<Long, JsonObject> coupons = new HashMap<>();
|
||||
for (UserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||
setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter);
|
||||
}
|
||||
JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||
tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());
|
||||
tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean());
|
||||
|
||||
}
|
||||
tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
|
||||
return tbUserCouponVos;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -102,4 +138,40 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
.eq(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
.update();
|
||||
}
|
||||
|
||||
private void setCouponInfo(Map<Long, JsonObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, LocalTime now, DateTimeFormatter formatter) {
|
||||
JsonObject json = new JsonObject();
|
||||
boolean isUse = true;
|
||||
ShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
|
||||
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
||||
if (amount != null && tbShopCoupon.getType().equals(1)) {
|
||||
if (amount.compareTo(tbShopCoupon.getFullAmount()) < 0) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(tbShopCoupon.getUserDays())) {
|
||||
String[] split = tbShopCoupon.getUserDays().split(",");
|
||||
if (split.length != 7) {
|
||||
useRestrictions = new StringBuilder(STR."\{tbShopCoupon.getUserDays()} ");
|
||||
}
|
||||
if (!tbShopCoupon.getUserDays().contains(week)) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if ("custom".equals(tbShopCoupon.getUseTimeType())) {
|
||||
if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
|
||||
isUse = false;
|
||||
}
|
||||
useRestrictions.append(
|
||||
STR."\{tbShopCoupon.getUseStartTime().format(formatter)}-\{tbShopCoupon.getUseEndTime().format(formatter)}");
|
||||
} else {
|
||||
useRestrictions.append("全时段");
|
||||
}
|
||||
useRestrictions.append(" 可用");
|
||||
json.addProperty("isUse", isUse);
|
||||
json.addProperty("useRestrictions", useRestrictions.toString());
|
||||
|
||||
coupons.put(tbUserCouponVo.getCouponId(), json);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,49 @@
|
|||
</if>
|
||||
order by record.create_time desc
|
||||
</select>
|
||||
<select id="findByUser" resultType="com.czg.account.entity.ShopActivateCouponRecord">
|
||||
select tb_shop_activate_coupon_record.*,tb_shop_info.shop_name
|
||||
from tb_shop_activate_coupon_record
|
||||
left join tb_shop_info on tb_shop_activate_coupon_record.shop_id = tb_shop_info.id
|
||||
where tb_shop_activate_coupon_record.shop_user_id in
|
||||
<foreach collection="shopUserIds" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
<if test="status != null">
|
||||
and tb_shop_activate_coupon_record.status = #{status}
|
||||
</if>
|
||||
order by tb_shop_activate_coupon_record.status , tb_shop_activate_coupon_record.create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
<select id="queryByVipIdAndShopId" resultType="com.czg.account.vo.UserCouponVo">
|
||||
SELECT
|
||||
inRecord.id as id,
|
||||
inRecord.shop_id as shopId,
|
||||
shop.shop_name as shopName,
|
||||
inRecord.full_amount as fullAmount,
|
||||
inRecord.discount_amount as discountAmount,
|
||||
inRecord.coupon_id as couponId,
|
||||
pro.id as proId,
|
||||
inRecord.name as name,
|
||||
inRecord.type,
|
||||
inRecord.over_num as num,
|
||||
inRecord.use_end_time as endTime
|
||||
FROM
|
||||
tb_activate_in_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}
|
||||
WHERE
|
||||
inRecord.shop_user_id in
|
||||
<foreach item="item" index="index" collection="vipUserIds" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
<if test="shopId != null and shopId != ''">
|
||||
and inRecord.shop_id = #{shopId}
|
||||
</if>
|
||||
and inRecord.over_num != 0
|
||||
and inRecord.use_start_time < now()
|
||||
and inRecord.use_end_time > now()
|
||||
order by inRecord.use_end_time
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue