diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java index 5c49993..cb6cfc2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/auth/LoginFilter.java @@ -45,7 +45,6 @@ public class LoginFilter implements Filter { "cashierService/home",//首页 "cashierService/order/testMessage",//首页 "cashierService/common/**",//通用接口 - "cashierService/tbShopShare/**",//通用接口 "cashierService/distirict/**",//首页其它接口 // "cashierService/login/**",//登录部分接口不校验 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/dao/TbShopShareRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopShareRecordMapper.java index a48eace..5ee94c6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopShareRecordMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopShareRecordMapper.java @@ -1,10 +1,12 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbShopShareRecord; +import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.Map; /** * (TbShopShareRecord)表数据库访问层 @@ -37,6 +39,10 @@ public interface TbShopShareRecordMapper { * @return 对象列表 */ List query(TbShopShareRecord tbShopShareRecord); + Map statisticsRecord(TbShopShareRecord tbShopShareRecord); + + List queryIsSuccess(TbShopShareRecord tbShopShareRecord); + List queryIsNoSuccess(TbShopShareRecord tbShopShareRecord); /** 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 36b0a63..9dccda5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShareRecord.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopShareRecord.java @@ -1,7 +1,11 @@ package com.chaozhanggui.system.cashierservice.entity; +import com.chaozhanggui.system.cashierservice.entity.dto.BasePageDto; +import lombok.Data; + import java.util.Date; import java.io.Serializable; +import java.util.List; /** * (TbShopShareRecord)实体类 @@ -9,7 +13,8 @@ import java.io.Serializable; * @author ww * @since 2024-11-07 15:50:04 */ -public class TbShopShareRecord implements Serializable { +@Data +public class TbShopShareRecord extends BasePageDto implements Serializable { private static final long serialVersionUID = -41620929736900271L; private Integer id; @@ -41,10 +46,12 @@ public class TbShopShareRecord implements Serializable { * 奖励券获得方式 get/use 领取获得/使用获得 */ private String method; + private List newCoupons; /** * 1 未领取 2 已领取 3 已使用 */ private Integer status; + private boolean success = true; /** * 生效时间/获得奖励的时间 */ @@ -54,103 +61,5 @@ public class TbShopShareRecord implements Serializable { private Date updateTime; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getShareId() { - return shareId; - } - - public void setShareId(Integer shareId) { - this.shareId = shareId; - } - - public Integer getShopId() { - return shopId; - } - - public void setShopId(Integer shopId) { - this.shopId = shopId; - } - - public Integer getInvitedId() { - return invitedId; - } - - public void setInvitedId(Integer invitedId) { - this.invitedId = invitedId; - } - - public String getInvitedName() { - return invitedName; - } - - public void setInvitedName(String invitedName) { - this.invitedName = invitedName; - } - - public Integer getBeInvitedId() { - return beInvitedId; - } - - public void setBeInvitedId(Integer beInvitedId) { - this.beInvitedId = beInvitedId; - } - - - public String getBeInvitedName() { - return beInvitedName; - } - - public void setBeInvitedName(String beInvitedName) { - this.beInvitedName = beInvitedName; - } - - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method; - } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public Date getRewardTime() { - return rewardTime; - } - - public void setRewardTime(Date rewardTime) { - this.rewardTime = rewardTime; - } - - 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/dto/UserCouponDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java deleted file mode 100644 index b53d03f..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity.dto; - -import lombok.Data; - -@Data -public class UserCouponDto extends BasePageDto{ - private Integer userId; - private Integer status; - private Integer shopId; - -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java index f7d97ac..6f3c155 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TbUserCouponVo.java @@ -12,6 +12,7 @@ public class TbUserCouponVo { private BigDecimal fullAmount; private BigDecimal discountAmount; private Integer couponId; + private Integer shopId; private Integer proId; //优惠券名称 private String name; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopShareRecordService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopShareRecordService.java index c71057c..82e681e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopShareRecordService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopShareRecordService.java @@ -6,6 +6,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import java.util.List; +import java.util.Map; /** * (TbShopShareRecord)表服务接口 @@ -29,7 +30,7 @@ public interface TbShopShareRecordService { * @param tbShopShareRecord 筛选条件 * @return 查询结果 */ - List query(TbShopShareRecord tbShopShareRecord); + Map query(TbShopShareRecord tbShopShareRecord); Result receive(TbShopShareRecord tbShopShareRecord); 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 35ff26a..d5d905b 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 @@ -7,7 +7,11 @@ import cn.hutool.core.util.RandomUtil; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.service.TbShopShareRecordService; +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; @@ -17,9 +21,8 @@ import org.springframework.data.domain.PageRequest; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.time.format.DateTimeFormatter; +import java.util.*; /** * (TbShopShareRecord)表服务实现类 @@ -63,12 +66,26 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { * @return 查询结果 */ @Override - public List query(TbShopShareRecord tbShopShareRecord) { - List records = tbShopShareRecordMapper.query(tbShopShareRecord); + public Map query(TbShopShareRecord tbShopShareRecord) { + Map result = tbShopShareRecordMapper.statisticsRecord(tbShopShareRecord); + if(CollectionUtil.isEmpty(result)){ + result=new HashMap<>(); + result.put("isSuccess",0); + result.put("isFail",0); + } + PageHelper.startPage(tbShopShareRecord.getPage(), tbShopShareRecord.getSize()); + + List records; + if(tbShopShareRecord.isSuccess()){ + records = tbShopShareRecordMapper.queryIsSuccess(tbShopShareRecord); + }else { + records = tbShopShareRecordMapper.queryIsNoSuccess(tbShopShareRecord); + } for (TbShopShareRecord shareRecord : records) { shareRecord.setBeInvitedName(userInfoMapper.selectNameByPrimaryKey(shareRecord.getBeInvitedId())); } - return records; + result.put("records",new PageInfo<>()); + return result; } @Override @@ -103,11 +120,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()); @@ -116,19 +133,13 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { query.setUpdateTime(new Date()); } if (shopUserInfo == null) { - if (query != null) { - query.setStatus(1); - tbShopShareRecordMapper.update(query); - } else { + if (query == null) { tbShopShareRecord.setStatus(1); tbShopShareRecordMapper.insert(tbShopShareRecord); } saveShopUser(tbShopShareRecord.getBeInvitedId(), tbShopShareRecord.getShopId()); } else { - if (query != null) { - query.setStatus(0); - tbShopShareRecordMapper.update(query); - } else { + if (query == null){ tbShopShareRecord.setStatus(0); tbShopShareRecordMapper.insert(tbShopShareRecord); } @@ -136,6 +147,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); } @@ -229,6 +258,7 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { record.setNum(newCoupon.getCouponNum()); record.setOverNum(newCoupon.getCouponNum()); record.setShopId(Integer.valueOf(tbShopUser.getShopId())); + record.setCreateTime(new Date()); record.setSourceActId(shopShare.getId()); record.setUseStartTime(start); record.setUseEndTime(end); @@ -250,6 +280,7 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { record.setSourceActId(shopShare.getId()); record.setUseStartTime(start); record.setUseEndTime(end); + record.setCreateTime(new Date()); record.setSource("invited"); actGiveRecords.add(record); } @@ -259,4 +290,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/TbActivateInRecordMapper.xml b/src/main/resources/mapper/TbActivateInRecordMapper.xml index 67fd5c0..e87fbc0 100644 --- a/src/main/resources/mapper/TbActivateInRecordMapper.xml +++ b/src/main/resources/mapper/TbActivateInRecordMapper.xml @@ -43,6 +43,7 @@ id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, nu inRecord.full_amount as fullAmount, inRecord.discount_amount as discountAmount, inRecord.coupon_id as couponId, + inRecord.shop_id as shopId, pro.id as proId, CASE WHEN inRecord.type = 1 THEN inRecord.NAME diff --git a/src/main/resources/mapper/TbActivateMapper.xml b/src/main/resources/mapper/TbActivateMapper.xml index 4e32f51..c68a8a7 100644 --- a/src/main/resources/mapper/TbActivateMapper.xml +++ b/src/main/resources/mapper/TbActivateMapper.xml @@ -41,8 +41,8 @@ from tb_activate where shop_id = #{shopId} - and amount = #{amount} - order by id desc + and amount <= #{amount} + order by amount desc limit 1 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) diff --git a/src/main/resources/mapper/TbShopShareRecordMapper.xml b/src/main/resources/mapper/TbShopShareRecordMapper.xml index 12d0744..2e7fdb8 100644 --- a/src/main/resources/mapper/TbShopShareRecordMapper.xml +++ b/src/main/resources/mapper/TbShopShareRecordMapper.xml @@ -92,6 +92,45 @@ + + + + + +