管理端分享好友接口

This commit is contained in:
张松 2025-03-05 15:03:23 +08:00
parent 501748b799
commit f029891719
15 changed files with 647 additions and 0 deletions

View File

@ -0,0 +1,54 @@
package com.czg.controller.admin;
import com.czg.account.dto.ShopShareDTO;
import com.czg.account.service.ShopShareService;
import com.czg.account.vo.ShopShareRecordVO;
import com.czg.account.vo.ShopShareVO;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 小程序分享奖励管理
* @author Administrator
*/
@RestController
@RequestMapping("/admin/shopShare")
public class ShopShareController {
@Resource
private ShopShareService shopShareService;
/**
* 获取分享奖励配置
*/
@SaAdminCheckPermission(value = "shopShare:list", name = "分享好友信息")
@GetMapping
public CzgResult<ShopShareVO> get() {
return CzgResult.success(shopShareService.get(StpKit.USER.getShopId()));
}
/**
* 修改分享奖励配置
*/
@SaAdminCheckPermission(value = "shopShare:add", name = "分享好友信息添加")
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated ShopShareDTO shopShareDTO) {
return CzgResult.success(shopShareService.add(StpKit.USER.getShopId(), shopShareDTO));
}
/**
* 分享奖励记录
* @param key 邀请人/被邀请人手机号或昵称
* @param status 0 非新用户 1 未领取 2 已领取 3 已使用 不传递为全部
* @return 分页数据
*/
@SaAdminCheckPermission(value = "shopShare:record", name = "分享邀请记录")
@GetMapping("/record")
public CzgResult<Page<ShopShareRecordVO>> record(String key, Integer status) {
return CzgResult.success(shopShareService.recordPage(StpKit.USER.getShopId(), key, status));
}
}

View File

@ -0,0 +1,93 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import java.util.List;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺分享 实体类
*
* @author zs
* @since 2025-03-05
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShopShareDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 标题
*/
@Size(min = 1, message = "标题不为空")
private String title;
/**
* 分享封面图
*/
@Size(min = 1, message = "分享封面图不为空")
private String shareImg;
/**
* 邀请顶部图
*/
@Size(min = 1, message = "邀请顶部图不为空")
private String invitedImg;
/**
* 被邀顶部图
*/
@Size(min = 1, message = "被邀顶部图不为空")
private String beInvitedImg;
/**
* 活动开始时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
/**
* 活动结束时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
/**
* 新用户获得券
*/
private List<Long> newCouponIdList;
/**
* 邀请人数
*/
private Integer invitedNum;
/**
* 奖励券
*/
private List<Long> rewardCouponIdList;
/**
* 获取方法 get-新用户领取获得 use-新用户使用获得
*/
@Size(min = 1, message = "获取方法不为空")
private String getMethod;
/**
* 0 关闭 1 开启
*/
private Integer status;
}

View File

@ -0,0 +1,77 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺分享记录 实体类
*
* @author zs
* @since 2025-03-05
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ShopShareRecordDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Integer id;
/**
* tb_shop_share 主键Id
*/
private Integer shareId;
/**
* 店铺Id
*/
private Integer shopId;
/**
* 邀请人id
*/
private Integer invitedId;
/**
* 邀请人名称
*/
private String invitedName;
/**
* 被邀请人Id
*/
private Integer beInvitedId;
/**
* 奖励券获得方式 get/use 领取获得/使用获得
*/
private String method;
/**
* 0 非新用户 1 未领取 2 已领取 3 已使用
*/
private Integer status;
/**
* 生效时间/获得奖励的时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime rewardTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,95 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺分享 实体类
*
* @author zs
* @since 2025-03-05
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_share")
public class ShopShare implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 店铺Id
*/
private Long shopId;
/**
* 标题
*/
private String title;
/**
* 分享封面图
*/
private String shareImg;
/**
* 邀请顶部图
*/
private String invitedImg;
/**
* 被邀顶部图
*/
private String beInvitedImg;
/**
* 活动开始时间
*/
private LocalDateTime startTime;
/**
* 活动结束时间
*/
private LocalDateTime endTime;
/**
* 新用户获得券
*/
private String newCoupon;
/**
* 邀请人数
*/
private Integer invitedNum;
/**
* 奖励券
*/
private String rewardCoupon;
/**
* 获取方法 get-新用户领取获得 use-新用户使用获得
*/
private String getMethod;
/**
* 0 关闭 1 开启
*/
private Integer status;
}

View File

@ -0,0 +1,82 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 店铺分享记录 实体类
*
* @author zs
* @since 2025-03-05
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_share_record")
public class ShopShareRecord implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Integer id;
/**
* tb_shop_share 主键Id
*/
private Integer shareId;
/**
* 店铺Id
*/
private Integer shopId;
/**
* 邀请人id
*/
private Integer invitedId;
/**
* 邀请人名称
*/
private String invitedName;
/**
* 被邀请人Id
*/
private Integer beInvitedId;
/**
* 奖励券获得方式 get/use 领取获得/使用获得
*/
private String method;
/**
* 0 非新用户 1 未领取 2 已领取 3 已使用
*/
private Integer status;
/**
* 生效时间/获得奖励的时间
*/
private LocalDateTime rewardTime;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,14 @@
package com.czg.account.service;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopShareRecord;
/**
* 店铺分享记录 服务层
*
* @author zs
* @since 2025-03-05
*/
public interface ShopShareRecordService extends IService<ShopShareRecord> {
}

View File

@ -0,0 +1,23 @@
package com.czg.account.service;
import com.czg.account.dto.ShopShareDTO;
import com.czg.account.vo.ShopShareRecordVO;
import com.czg.account.vo.ShopShareVO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopShare;
/**
* 店铺分享 服务层
*
* @author zs
* @since 2025-03-05
*/
public interface ShopShareService extends IService<ShopShare> {
ShopShareVO get(Long shopId);
Boolean add(Long shopId, ShopShareDTO shopShareDTO);
Page<ShopShareRecordVO> recordPage(Long shopId, String key, Integer status);
}

View File

@ -0,0 +1,17 @@
package com.czg.account.vo;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author Administrator
*/
@Data
public class ShopShareRecordVO {
private String invitedName;
private String beInvitedName;
private Integer status;
private LocalDateTime createTime;
private LocalDateTime rewardTime;
}

View File

@ -0,0 +1,25 @@
package com.czg.account.vo;
import com.czg.account.entity.ShopCoupon;
import com.czg.account.entity.ShopShare;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.ArrayList;
import java.util.List;
/**
* @author Administrator
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ShopShareVO extends ShopShare {
/**
* 新人奖励优惠券信息
*/
private List<ShopCoupon> newCouponList = new ArrayList<>();
/**
* 邀请人奖励优惠券信息
*/
private List<ShopCoupon> rewardCouponList = new ArrayList<>();
}

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopShare;
/**
* 店铺分享 映射层
*
* @author zs
* @since 2025-03-05
*/
public interface ShopShareMapper extends BaseMapper<ShopShare> {
}

View File

@ -0,0 +1,20 @@
package com.czg.service.account.mapper;
import com.czg.account.vo.ShopShareRecordVO;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopShareRecord;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 店铺分享记录 映射层
*
* @author zs
* @since 2025-03-05
*/
public interface ShopShareRecordMapper extends BaseMapper<ShopShareRecord> {
List<ShopShareRecordVO> getRecord(@Param("shopId") Long shopId, @Param("key") String key, @Param("status") Integer status);
}

View File

@ -0,0 +1,18 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopShareRecord;
import com.czg.account.service.ShopShareRecordService;
import com.czg.service.account.mapper.ShopShareRecordMapper;
import org.springframework.stereotype.Service;
/**
* 店铺分享记录 服务层实现
*
* @author zs
* @since 2025-03-05
*/
@Service
public class ShopShareRecordServiceImpl extends ServiceImpl<ShopShareRecordMapper, ShopShareRecord> implements ShopShareRecordService{
}

View File

@ -0,0 +1,87 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONArray;
import com.czg.account.dto.ShopShareDTO;
import com.czg.account.entity.ShopCoupon;
import com.czg.account.service.ShopCouponService;
import com.czg.account.vo.ShopShareRecordVO;
import com.czg.account.vo.ShopShareVO;
import com.czg.exception.ApiNotPrintException;
import com.czg.service.account.mapper.ShopShareRecordMapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopShare;
import com.czg.account.service.ShopShareService;
import com.czg.service.account.mapper.ShopShareMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
/**
* 店铺分享 服务层实现
*
* @author zs
* @since 2025-03-05
*/
@Service
public class ShopShareServiceImpl extends ServiceImpl<ShopShareMapper, ShopShare> implements ShopShareService{
@Resource
private ShopCouponService shopCouponService;
@Resource
private ShopShareRecordMapper shopShareRecordMapper;
@Override
public ShopShareVO get(Long shopId) {
ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
ShopShareVO shopShareVO = new ShopShareVO();
if (shopShare != null) {
BeanUtil.copyProperties(shopShare, shopShareVO);
if (StrUtil.isNotBlank(shopShare.getRewardCoupon())) {
shopShareVO.setRewardCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getRewardCoupon()))));
}
if (StrUtil.isNotBlank(shopShare.getNewCoupon())) {
shopShareVO.setNewCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getNewCoupon()))));
}
}
return shopShareVO;
}
@Override
public Boolean add(Long shopId, ShopShareDTO shopShareDTO) {
if (shopShareDTO.getNewCouponIdList() != null && !shopShareDTO.getRewardCouponIdList().isEmpty()) {
long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getNewCouponIdList()).eq(ShopCoupon::getShopId, shopId));
if (count != shopShareDTO.getNewCouponIdList().size()) {
throw new ApiNotPrintException("优惠券不存在");
}
}
if (shopShareDTO.getRewardCouponIdList() != null && !shopShareDTO.getRewardCouponIdList().isEmpty()) {
long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getRewardCouponIdList()).eq(ShopCoupon::getShopId, shopId));
if (count != shopShareDTO.getRewardCouponIdList().size()) {
throw new ApiNotPrintException("优惠券不存在");
}
}
ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
if (shopShare == null) {
shopShare = new ShopShareVO();
shopShare.setShopId(shopId);
}
shopShare.setRewardCoupon(JSONArray.toJSONString(shopShareDTO.getRewardCouponIdList()));
shopShare.setNewCoupon(JSONArray.toJSONString(shopShareDTO.getNewCouponIdList()));
BeanUtil.copyProperties(shopShareDTO, shopShare);
return saveOrUpdate(shopShare);
}
@Override
public Page<ShopShareRecordVO> recordPage(Long shopId, String key, Integer status) {
Page<Object> page = PageUtil.buildPage();
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
return PageUtil.convert(new PageInfo<>(shopShareRecordMapper.getRecord(shopId, key, status)));
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopShareMapper">
</mapper>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopShareRecordMapper">
<select id="getRecord" resultType="com.czg.account.vo.ShopShareRecordVO">
SELECT *
FROM `tb_shop_share_record` as a
left join tb_shop_user as b on a.shop_id = b.shop_id and b.user_id = a.invited_id
left join tb_shop_user as c on a.shop_id = c.shop_id and c.user_id = a.be_invited_id
where a.shop_id=#{shopId}
<if test="key != null and key != ''">
and (b.nick_name like concat('%', #{key}, '%') or c.nick_name like concat('%', #{key}, '%') or b.phone like concat('%', #{key}, '%') or c.phone like concat('%', #{key}, '%'))
</if>
<if test="status != null and status != ''">
and a.status=#{status}
</if>
</select>
</mapper>