Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user