商品券

This commit is contained in:
2024-11-08 13:36:12 +08:00
parent 19202f5881
commit 7c2b6cb25f
7 changed files with 63 additions and 53 deletions

View File

@@ -34,6 +34,7 @@ public interface TbCouponProductMapper {
List<TbCouponProduct> queryAllByCouponId(Integer couponId);
List<String> queryProsByActivateId(@Param("couponId")Integer couponId,@Param("num")Integer num);
List<TbCouponProduct> queryProInfoByActivateId(@Param("couponId")Integer couponId,@Param("num")Integer num);
/**

View File

@@ -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;
}
}

View File

@@ -125,7 +125,7 @@ public class TbShopShare implements Serializable {
//使用描述
private String useDetail;
//商品描述
private List<String> gives;
private List<TbCouponProduct> gives;
}
}

View File

@@ -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<TbShopShare.ShareCoupons> newCoupons;
/**
* 1 未领取 2 已领取 3 已使用
*/

View File

@@ -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();
}
}

View File

@@ -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()));
}
}
}

View File

@@ -68,6 +68,14 @@
group by tb_coupon_product.product_id
</select>
<select id="queryProInfoByActivateId" resultType="com.chaozhanggui.system.cashierservice.entity.TbCouponProduct" >
select tb_coupon_product.*,tb_product name as proName,tb_product.cover_img as proImg SUM(tb_coupon_product.num)*#{num} as num
from tb_coupon_product
LEFT JOIN tb_product ON tb_coupon_product.product_id = tb_product.id
where coupon_id = #{couponId}
group by tb_coupon_product.product_id
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into tb_coupon_product(coupon_id, product_id, num, create_time, update_time)