diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java index e467b652..40ffba36 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/controller/TbShopShareController.java @@ -1,7 +1,10 @@ package cn.ysk.cashier.controller; +import cn.ysk.cashier.annotation.rest.AnonymousPostMapping; +import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria; import cn.ysk.cashier.mybatis.entity.TbShopShare; +import cn.ysk.cashier.mybatis.service.TbShopShareRecordService; import cn.ysk.cashier.mybatis.service.TbShopShareService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -26,11 +29,22 @@ public class TbShopShareController { @Resource private TbShopShareService tbShopShareService; + /** + * 服务对象 + */ + @Resource + private TbShopShareRecordService tbShopShareRecordService; + + @PostMapping("byShare") + @AnonymousPostMapping + @ApiOperation("分页查询") + public ResponseEntity selectAllByShare(@RequestBody TbShopShareRecordQueryCriteria criteria) { + return new ResponseEntity<>(tbShopShareRecordService.selectAllByShare(criteria), HttpStatus.OK); + } + @GetMapping("byShopId") @ApiOperation("通过shopId查询详情") - public ResponseEntity getByShopId( - @RequestParam Integer shopId - ) { + public ResponseEntity getByShopId(@RequestParam Integer shopId) { return ResponseEntity.ok(tbShopShareService.getByShopId(shopId)); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/TbShopShareRecordQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/TbShopShareRecordQueryCriteria.java new file mode 100644 index 00000000..df31aa05 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/TbShopShareRecordQueryCriteria.java @@ -0,0 +1,26 @@ +package cn.ysk.cashier.dto; + +import lombok.Data; + +/** + * (TbShopShareRecord)表查询类 + * + * @author ww + * @since 2024-11-08 09:17:38 + */ +@Data +public class TbShopShareRecordQueryCriteria { + + private Integer shareId; + //店铺Id + private Integer shopId; + //邀请人名称/被邀请人/昵称/手机号 模糊查询 + private String search; + + //0 非新用户 1 未领取 2 已领取 3 已使用 + private Integer status; + + private long page = 1; + private long size = 10; +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivateInRecord.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivateInRecord.java index d688ef29..e1d9f790 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivateInRecord.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivateInRecord.java @@ -5,6 +5,7 @@ import java.util.Date; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.Data; import java.io.Serializable; @@ -12,8 +13,9 @@ import java.io.Serializable; * 活动商品赠送记录表(TbActivateInRecord)表实体类 * * @author ww - * @since 2024-10-23 09:49:59 + * @since 2024-11-08 09:53:21 */ +@Data @SuppressWarnings("serial") public class TbActivateInRecord extends Model { @@ -42,140 +44,17 @@ public class TbActivateInRecord extends Model { private Integer sourceActId; private Integer sourceFlowId; - + //可用开始时间 + private Date useStartTime; + //可用结束时间 + private Date useEndTime; + @TableField(fill = FieldFill.INSERT) private Date createTime; @TableField(fill = FieldFill.UPDATE) private Date updateTime; private String couponJson; - - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getVipUserId() { - return vipUserId; - } - - public void setVipUserId(Integer vipUserId) { - this.vipUserId = vipUserId; - } - - public Integer getCouponId() { - return couponId; - } - - public void setCouponId(Integer couponId) { - this.couponId = couponId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getType() { - return type; - } - - public void setType(Integer type) { - this.type = type; - } - - public Integer getProId() { - return proId; - } - - public void setProId(Integer proId) { - this.proId = proId; - } - - public Integer getFullAmount() { - return fullAmount; - } - - public void setFullAmount(Integer fullAmount) { - this.fullAmount = fullAmount; - } - - public Integer getDiscountAmount() { - return discountAmount; - } - - public void setDiscountAmount(Integer discountAmount) { - this.discountAmount = discountAmount; - } - - public Integer getNum() { - return num; - } - - public void setNum(Integer num) { - this.num = num; - } - - public Integer getOverNum() { - return overNum; - } - - public void setOverNum(Integer overNum) { - this.overNum = overNum; - } - - public Integer getShopId() { - return shopId; - } - - public void setShopId(Integer shopId) { - this.shopId = shopId; - } - - public Integer getSourceActId() { - return sourceActId; - } - - public void setSourceActId(Integer sourceActId) { - this.sourceActId = sourceActId; - } - - public Integer getSourceFlowId() { - return sourceFlowId; - } - - public void setSourceFlowId(Integer sourceFlowId) { - this.sourceFlowId = sourceFlowId; - } - - 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; - } - - public String getCouponJson() { - return couponJson; - } - - public void setCouponJson(String couponJson) { - this.couponJson = couponJson; - } + //invited/activate + private String source; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java new file mode 100644 index 00000000..775908c8 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbShopShareRecord.java @@ -0,0 +1,50 @@ +package cn.ysk.cashier.mybatis.entity; + +import java.util.Date; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.Data; + +import java.io.Serializable; + +/** + * (TbShopShareRecord)表实体类 + * + * @author ww + * @since 2024-11-08 09:17:37 + */ +@Data +@SuppressWarnings("serial") +public class TbShopShareRecord extends Model { + + private Integer id; + //tb_shop_share 主键Id + private Integer shareId; + //店铺Id + private Integer shopId; + + private String invitedHeadImg; + //邀请人id + private Integer invitedId; + //邀请人名称 + private String invitedName; + + private String beInvitedHeadImg; + //被邀请人Id + private Integer beInvitedId; + + private String beInvitedName; + //奖励券获得方式 get/use 领取获得/使用获得 + private String method; + //0 非新用户 1 未领取 2 已领取 3 已使用 + private Integer status; + //生效时间/获得奖励的时间 + private Date rewardTime; + + private Date createTime; + + private Date updateTime; + + +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCouponProductMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCouponProductMapper.java index 7e900b4b..8fe3939b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCouponProductMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbCouponProductMapper.java @@ -2,6 +2,10 @@ package cn.ysk.cashier.mybatis.mapper; import cn.ysk.cashier.mybatis.entity.TbCouponProduct; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * 活动赠送商品表(TbActivateProduct)表数据库访问层 @@ -11,5 +15,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; */ public interface TbCouponProductMapper extends BaseMapper { + + @Select(" select " + + " *" + + " from tb_coupon_product " + + " where " + + " coupon_id = #{couponId}") + List queryAllByCouponId(@Param("couponId") Integer couponId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopShareRecordMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopShareRecordMapper.java new file mode 100644 index 00000000..a2a9db41 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbShopShareRecordMapper.java @@ -0,0 +1,46 @@ +package cn.ysk.cashier.mybatis.mapper; + +import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria; +import cn.ysk.cashier.vo.TbUserCouponVo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import cn.ysk.cashier.mybatis.entity.TbShopShareRecord; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * (TbShopShareRecord)表数据库访问层 + * + * @author ww + * @since 2024-11-08 09:17:37 + */ +public interface TbShopShareRecordMapper extends BaseMapper { + + @Select("") + Page selectAllByShare(@Param("param") TbShopShareRecordQueryCriteria param, Page page); +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopShareRecordService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopShareRecordService.java new file mode 100644 index 00000000..aa79a529 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbShopShareRecordService.java @@ -0,0 +1,22 @@ +package cn.ysk.cashier.mybatis.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import cn.ysk.cashier.mybatis.entity.TbShopShareRecord; +import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria; + +import java.util.Map; + +/** + * (TbShopShareRecord)表服务接口 + * + * @author ww + * @since 2024-11-08 09:17:37 + */ +public interface TbShopShareRecordService extends IService { + + Map selectAllByShare(TbShopShareRecordQueryCriteria criteria); + + void give(TbShopShareRecord shareRecord, Integer userId); + +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java index 3dfd63b4..b2e6a849 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java @@ -72,6 +72,8 @@ public class TbShopCouponServiceImpl extends ServiceImpl param) { for (TbActivateOutRecord outRecord : param) { TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId()); + if (inRecord.getSource().equals("invited")) { + TbShopShareRecord shareRecord = shareRecordService.getById(inRecord.getSourceActId()); + if (shareRecord.getMethod().equals("use")) { + shareRecord.setStatus(3); + shareRecordService.give(shareRecord,shareRecord.getInvitedId()); + shareRecordService.updateById(shareRecord); + } + } + inRecord.setOverNum(inRecord.getOverNum() - outRecord.getUseNum()); inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum()); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java new file mode 100644 index 00000000..c536e378 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java @@ -0,0 +1,122 @@ +package cn.ysk.cashier.mybatis.service.impl; + +import cn.hutool.core.date.DateUtil; +import cn.ysk.cashier.mybatis.entity.*; +import cn.ysk.cashier.mybatis.mapper.*; +import cn.ysk.cashier.mybatis.service.TbCouponProductService; +import cn.ysk.cashier.pojo.shop.TbShopUser; +import cn.ysk.cashier.repository.shop.TbShopUserRepository; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import cn.ysk.cashier.mybatis.service.TbShopShareRecordService; +import org.springframework.stereotype.Service; +import org.apache.commons.lang3.StringUtils; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria; +import org.springframework.beans.factory.annotation.Autowired; +import cn.ysk.cashier.utils.PageUtil; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * (TbShopShareRecord)表服务实现类 + * + * @author ww + * @since 2024-11-08 09:17:37 + */ +@Service("tbShopShareRecordService") +public class TbShopShareRecordServiceImpl extends ServiceImpl implements TbShopShareRecordService { + + @Autowired + private TbShopShareRecordMapper tbShopShareRecordmapper; + @Autowired + private TbShopShareMapper tbShopShareMapper; + @Autowired + private TbShopUserRepository shopUserRepository; + @Autowired + private TbShopCouponMapper couponMapper; + @Autowired + private TbCouponProductMapper couProductMapper; + @Autowired + private TbActivateInRecordMapper inRecordMapper; + + @Override + public Map selectAllByShare(TbShopShareRecordQueryCriteria criteria) { + Page ipage = tbShopShareRecordmapper.selectAllByShare(criteria,new Page<>(criteria.getPage(), criteria.getSize())); + return PageUtil.toPage(ipage.getRecords(), ipage.getTotal()); + } + + @Override + public void give(TbShopShareRecord shareRecord, Integer userId) { + TbShopShare shopShare = tbShopShareMapper.selectById(shareRecord.getShareId()); + TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(userId.toString(), shopShare.getShopId().toString()); + if (userId.equals(shareRecord.getInvitedId())) { + giveCoupon(shopShare, tbShopUser, shopShare.getRewardCoupons()); + } else if (userId.equals(shareRecord.getBeInvitedId())) { + giveCoupon(shopShare, tbShopUser, shopShare.getNewCoupons()); + } + } + + + public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List coupons) { + for (TbShopShare.ShareCoupons newCoupon : coupons) { + TbShopCoupon tbShopCoupon = couponMapper.selectById(newCoupon.getCouponId()); + Date start = new Date(); + Date end = new Date(); + if ("fixed".equals(tbShopCoupon.getValidityType())) { + //固定时间 + end = DateUtil.offsetDay(new Date(), tbShopCoupon.getValidDays()); + } else if ("custom".equals(tbShopCoupon.getValidityType())) { + //自定义时间 + start = tbShopCoupon.getValidStartTime(); + end = tbShopCoupon.getValidEndTime(); + } + if (tbShopCoupon != null) { + List actGiveRecords = new ArrayList<>(); + if (tbShopCoupon.getType() == 1) { + //满减 + TbActivateInRecord record = new TbActivateInRecord(); + record.setVipUserId(Integer.valueOf(tbShopUser.getId())); + record.setCouponId(tbShopCoupon.getId()); + record.setName("满" + tbShopCoupon.getFullAmount() + "减" + tbShopCoupon.getDiscountAmount()); + record.setFullAmount(tbShopCoupon.getFullAmount()); + record.setDiscountAmount(tbShopCoupon.getDiscountAmount()); + record.setType(1); + record.setNum(newCoupon.getCouponNum()); + record.setOverNum(newCoupon.getCouponNum()); + record.setShopId(Integer.valueOf(tbShopUser.getShopId())); + record.setSourceActId(shopShare.getId()); + record.setUseStartTime(start); + record.setUseEndTime(end); + record.setSource("invited"); + actGiveRecords.add(record); + } else if (tbShopCoupon.getType() == 2) { + //商品卷 + List tbCouponProducts = couProductMapper.queryAllByCouponId(tbShopCoupon.getId()); + for (TbCouponProduct actPro : tbCouponProducts) { + TbActivateInRecord record = new TbActivateInRecord(); + record.setVipUserId(Integer.valueOf(tbShopUser.getId())); + record.setCouponId(tbShopCoupon.getId()); + record.setName("商品卷"); + record.setType(2); + record.setProId(actPro.getProductId()); + record.setNum(actPro.getNum() * tbShopCoupon.getNumber()); + record.setOverNum(actPro.getNum() * tbShopCoupon.getNumber()); + record.setShopId(Integer.valueOf(tbShopUser.getShopId())); + record.setSourceActId(shopShare.getId()); + record.setUseStartTime(start); + record.setUseEndTime(end); + record.setSource("invited"); + actGiveRecords.add(record); + } + } + inRecordMapper.insert(actGiveRecords); + } + } + + } +} +