邀请记录

This commit is contained in:
wangw 2024-11-08 10:15:54 +08:00
parent f567bd821b
commit 02a2785878
9 changed files with 315 additions and 134 deletions

View File

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

View File

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

View File

@ -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<TbActivateInRecord> {
@ -42,140 +44,17 @@ public class TbActivateInRecord extends Model<TbActivateInRecord> {
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;
}

View File

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

View File

@ -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<TbCouponProduct> {
@Select(" select " +
" *" +
" from tb_coupon_product " +
" where " +
" coupon_id = #{couponId}")
List<TbCouponProduct> queryAllByCouponId(@Param("couponId") Integer couponId);
}

View File

@ -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<TbShopShareRecord> {
@Select("<script> " +
"SELECT" +
" record.*," +
" user1.nick_name AS invitedName," +
" user2.nick_name AS beInvitedName," +
" user1.head_img AS invitedHeadImg," +
" user2.head_img AS beInvitedHeadImg " +
"FROM" +
" tb_shop_share_record record" +
" LEFT JOIN tb_user_info user1 ON record.invited_id = user1.id " +
" <if test=\"param.search != null and param.search != '' \"> " +
" AND (user1.nick_name like concat('%', #{param.search}, '%') or user1.telephone like concat('%', #{param.search}, '%')) " +
" </if> " +
" LEFT JOIN tb_user_info user2 ON record.be_invited_id = user2.id " +
" <if test=\"param.search != null and param.search != '' \"> " +
" AND (user2.nick_name like concat('%', #{param.search}, '%') or user2.telephone like concat('%', #{param.search}, '%')) " +
" </if> " +
"WHERE" +
" share_id = #{param.shareId}" +
" <if test=\" param.status != null \"> " +
" and record.status = #{param.status} "+
" </if> " +
"</script>")
Page<TbShopShareRecord> selectAllByShare(@Param("param") TbShopShareRecordQueryCriteria param, Page page);
}

View File

@ -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<TbShopShareRecord> {
Map<String, Object> selectAllByShare(TbShopShareRecordQueryCriteria criteria);
void give(TbShopShareRecord shareRecord, Integer userId);
}

View File

@ -72,6 +72,8 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
private TbActivateInRecordMapper inRecordMapper;
@Autowired
private TbActivateOutRecordMapper outRecordMapper;
@Autowired
private TbShopShareRecordService shareRecordService;
private final TbMShopUserMapper shopUserMapper;
private final MpShopUserService shopUserService;
private final MpOrderInfoService mpOrderInfoService;
@ -317,6 +319,15 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
public boolean use(Integer shopId, Integer orderId, Integer vipUserId, List<TbActivateOutRecord> 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());

View File

@ -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<TbShopShareRecordMapper, TbShopShareRecord> 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<String, Object> selectAllByShare(TbShopShareRecordQueryCriteria criteria) {
Page<TbShopShareRecord> 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<TbShopShare.ShareCoupons> 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<TbActivateInRecord> 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<TbCouponProduct> 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);
}
}
}
}