From 7c2b6cb25f09df99f057963b7674e7253a54d512 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 8 Nov 2024 13:36:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/TbCouponProductMapper.java | 1 + .../entity/TbCouponProduct.java | 54 ++----------------- .../cashierservice/entity/TbShopShare.java | 2 +- .../entity/TbShopShareRecord.java | 2 + .../impl/TbShopShareRecordServiceImpl.java | 45 +++++++++++++++- .../service/impl/TbShopShareServiceImpl.java | 4 +- .../mapper/TbCouponProductMapper.xml | 8 +++ 7 files changed, 63 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponProductMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponProductMapper.java index 6ca6628..538dfa4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponProductMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCouponProductMapper.java @@ -34,6 +34,7 @@ public interface TbCouponProductMapper { List queryAllByCouponId(Integer couponId); List queryProsByActivateId(@Param("couponId")Integer couponId,@Param("num")Integer num); + List queryProInfoByActivateId(@Param("couponId")Integer couponId,@Param("num")Integer num); /** diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponProduct.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponProduct.java index 2572106..66d2e2d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponProduct.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCouponProduct.java @@ -1,5 +1,7 @@ package com.chaozhanggui.system.cashierservice.entity; +import lombok.Data; + import java.util.Date; import java.io.Serializable; @@ -9,6 +11,7 @@ import java.io.Serializable; * @author ww * @since 2024-10-23 14:35:49 */ +@Data public class TbCouponProduct implements Serializable { private static final long serialVersionUID = 619724621133545616L; @@ -21,6 +24,8 @@ public class TbCouponProduct implements Serializable { * 商品id */ private Integer productId; + private String proName; + private String proImg; /** * 数量 */ @@ -30,54 +35,5 @@ public class TbCouponProduct implements Serializable { private Date updateTime; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getCouponId() { - return couponId; - } - - public void setCouponId(Integer couponId) { - this.couponId = couponId; - } - - public Integer getProductId() { - return productId; - } - - public void setProductId(Integer productId) { - this.productId = productId; - } - - public Integer getNum() { - return num; - } - - public void setNum(Integer num) { - this.num = num; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getUpdateTime() { - return updateTime; - } - - public void setUpdateTime(Date updateTime) { - this.updateTime = updateTime; - } - } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShare.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShare.java index 9c3021f..8f014af 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShare.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShare.java @@ -125,7 +125,7 @@ public class TbShopShare implements Serializable { //使用描述 private String useDetail; //商品描述 - private List gives; + private List gives; } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShareRecord.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShareRecord.java index 11238c4..b2051e3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShareRecord.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShareRecord.java @@ -5,6 +5,7 @@ import lombok.Data; import java.util.Date; import java.io.Serializable; +import java.util.List; /** * (TbShopShareRecord)实体类 @@ -45,6 +46,7 @@ public class TbShopShareRecord extends BasePageDto implements Serializable { * 奖励券获得方式 get/use 领取获得/使用获得 */ private String method; + private List newCoupons; /** * 1 未领取 2 已领取 3 已使用 */ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java index 50e5801..22f1c85 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java @@ -11,6 +11,7 @@ import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Service; @@ -20,6 +21,7 @@ import org.springframework.data.domain.PageRequest; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.format.DateTimeFormatter; import java.util.*; /** @@ -113,11 +115,11 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { @Override public Result insert(TbShopShareRecord tbShopShareRecord) { TbShopUser shopUserInfo = getShopUserInfo(tbShopShareRecord.getBeInvitedId(), tbShopShareRecord.getShopId()); + TbShopShare tbShopShare = tbShopShareMapper.queryById(tbShopShareRecord.getShareId()); TbShopShareRecord query = tbShopShareRecordMapper.queryByData( tbShopShareRecord.getShareId(), tbShopShareRecord.getShopId(), tbShopShareRecord.getInvitedId(), tbShopShareRecord.getBeInvitedId()); if (query == null) { - TbShopShare tbShopShare = tbShopShareMapper.queryById(tbShopShareRecord.getShareId()); tbShopShareRecord.setMethod(tbShopShare.getGetMethod()); tbShopShareRecord.setShopId(tbShopShareRecord.getShopId()); tbShopShareRecord.setCreateTime(new Date()); @@ -146,6 +148,24 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { if (query == null) { query = tbShopShareRecord; } + for (TbShopShare.ShareCoupons newCoupon : tbShopShare.getNewCoupons()) { + TbShopCoupon coupon = couponMapper.queryById(newCoupon.getCouponId()); + if (coupon != null) { + if (coupon.getType() == 1) { + //满减 + newCoupon.setType(1); + newCoupon.setFullAmount(coupon.getFullAmount()); + newCoupon.setDiscountAmount(coupon.getDiscountAmount()); + newCoupon.setUseDetail(setCouponInfo(coupon)); + } else if (coupon.getType() == 2) { + //商品 + newCoupon.setType(2); + newCoupon.setUseDetail(setCouponInfo(coupon)); + newCoupon.setGives(couProductMapper.queryProInfoByActivateId(coupon.getId(), newCoupon.getCouponNum())); + } + } + } + query.setNewCoupons(tbShopShare.getNewCoupons()); return Result.successWithData(query); } @@ -269,4 +289,27 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { } } + + private String setCouponInfo(TbShopCoupon tbShopCoupon) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + StringBuilder useRestrictions = new StringBuilder("每天 "); + if (StringUtils.isNotBlank(tbShopCoupon.getUserDays())) { + String[] split = tbShopCoupon.getUserDays().split(","); + if (split.length != 7) { + useRestrictions = new StringBuilder(tbShopCoupon.getUserDays() + " "); + } + + } + if (StringUtils.isNotBlank(tbShopCoupon.getUseTimeType()) && tbShopCoupon.getUseTimeType().equals("custom")) { + useRestrictions.append( + tbShopCoupon.getUseStartTime().format(formatter) + + "-" + + tbShopCoupon.getUseEndTime().format(formatter)); + } else { + useRestrictions.append("全时段"); + } + useRestrictions.append(" 可用"); + + return useRestrictions.toString(); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java index 156b121..bf6bde3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java @@ -50,7 +50,7 @@ public class TbShopShareServiceImpl implements TbShopShareService { //商品 newCoupon.setType(2); newCoupon.setUseDetail(setCouponInfo(coupon)); - newCoupon.setGives(couProductMapper.queryProsByActivateId(coupon.getId(), newCoupon.getCouponNum())); + newCoupon.setGives(couProductMapper.queryProInfoByActivateId(coupon.getId(), newCoupon.getCouponNum())); } } } @@ -69,7 +69,7 @@ public class TbShopShareServiceImpl implements TbShopShareService { //商品 rewardCoupon.setType(2); rewardCoupon.setUseDetail(setCouponInfo(coupon)); - rewardCoupon.setGives(couProductMapper.queryProsByActivateId(coupon.getId(), rewardCoupon.getCouponNum())); + rewardCoupon.setGives(couProductMapper.queryProInfoByActivateId(coupon.getId(), rewardCoupon.getCouponNum())); } } } diff --git a/src/main/resources/mapper/TbCouponProductMapper.xml b/src/main/resources/mapper/TbCouponProductMapper.xml index 251e1b6..8042d8e 100644 --- a/src/main/resources/mapper/TbCouponProductMapper.xml +++ b/src/main/resources/mapper/TbCouponProductMapper.xml @@ -68,6 +68,14 @@ group by tb_coupon_product.product_id + + insert into tb_coupon_product(coupon_id, product_id, num, create_time, update_time)