优惠券相关管理功能实现
This commit is contained in:
+111
@@ -0,0 +1,111 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.CouponDTO;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
import com.xiaowang.yuminailcore.vo.CouponVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserCouponVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/coupon")
|
||||
@RequiredArgsConstructor
|
||||
public class CouponController {
|
||||
|
||||
private final CouponService couponService;
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("coupon:create")
|
||||
public Result<Long> createCoupon(@RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
Long couponId = couponService.createCoupon(couponDTO, shopId);
|
||||
return Result.success(couponId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("coupon:edit")
|
||||
public Result<Boolean> updateCoupon(@PathVariable Long id, @RequestBody CouponDTO couponDTO, @RequestParam(required = false) Long shopId) {
|
||||
boolean success = couponService.updateCoupon(id, couponDTO, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("coupon:delete")
|
||||
public Result<Boolean> deleteCoupon(@PathVariable Long id, @RequestParam(required = false) Long shopId) {
|
||||
boolean success = couponService.deleteCoupon(id, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券详情
|
||||
*/
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequirePermission("coupon:view")
|
||||
public Result<CouponVO> getCouponById(@PathVariable Long id) {
|
||||
CouponVO couponVO = couponService.getCouponById(id);
|
||||
return Result.success(couponVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@RequirePermission("coupon:view")
|
||||
public Result<PageResultVO<CouponVO>> listCoupons(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) Long shopId) {
|
||||
PageResultVO<CouponVO> pageResult = couponService.listCoupons(page, size, shopId);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为用户分配优惠券
|
||||
*/
|
||||
@PostMapping("/assign")
|
||||
@RequirePermission("coupon:assign")
|
||||
public Result<Boolean> assignCouponToUser(@RequestParam Long userId, @RequestParam Long couponId, @RequestParam(required = false) Long shopId) {
|
||||
boolean success = couponService.assignCouponToUser(userId, couponId, shopId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户优惠券列表
|
||||
*/
|
||||
@GetMapping("/user/list")
|
||||
public Result<List<UserCouponVO>> listUserCoupons(@RequestParam(required = false) Integer status, @RequestAttribute("userId") Long userId) {
|
||||
List<UserCouponVO> userCoupons = couponService.listUserCoupons(userId, status);
|
||||
return Result.success(userCoupons);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用优惠券
|
||||
*/
|
||||
@PostMapping("/use")
|
||||
public Result<Boolean> useCoupon(@RequestParam Long userCouponId, @RequestAttribute("userId") Long userId) {
|
||||
boolean success = couponService.useCoupon(userCouponId, userId);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品可用的优惠券
|
||||
*/
|
||||
@GetMapping("/available")
|
||||
public Result<List<UserCouponVO>> getAvailableCoupons(@RequestParam String productTags, @RequestParam Double productPrice, @RequestAttribute("userId") Long userId) {
|
||||
List<UserCouponVO> availableCoupons = couponService.getAvailableCoupons(userId, productTags, productPrice);
|
||||
return Result.success(availableCoupons);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/tag")
|
||||
@RequestMapping("/tag")
|
||||
@RequiredArgsConstructor
|
||||
public class TagController {
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券DTO
|
||||
*/
|
||||
@Data
|
||||
public class CouponDTO {
|
||||
|
||||
/**
|
||||
* 优惠券编码
|
||||
*/
|
||||
private String couponCode;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 优惠券类型:1-折扣券,2-满减券
|
||||
*/
|
||||
private Integer couponType;
|
||||
|
||||
/**
|
||||
* 折扣值(如9.5表示95折)
|
||||
*/
|
||||
private BigDecimal discountValue;
|
||||
|
||||
/**
|
||||
* 满减券最低消费金额
|
||||
*/
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/**
|
||||
* 满减券减免金额
|
||||
*/
|
||||
private BigDecimal reduceAmount;
|
||||
|
||||
/**
|
||||
* 优惠券总数量
|
||||
*/
|
||||
private Integer totalCount;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 可用标签ID列表
|
||||
*/
|
||||
private List<Long> availableTagIds;
|
||||
|
||||
/**
|
||||
* 不可用标签ID列表
|
||||
*/
|
||||
private List<Long> unavailableTagIds;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 优惠券信息表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_coupon")
|
||||
public class CouponDO extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 优惠券编码
|
||||
*/
|
||||
private String couponCode;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 优惠券类型:1-折扣券,2-满减券
|
||||
*/
|
||||
private Integer couponType;
|
||||
|
||||
/**
|
||||
* 折扣值(如9.5表示95折)
|
||||
*/
|
||||
private BigDecimal discountValue;
|
||||
|
||||
/**
|
||||
* 满减券最低消费金额
|
||||
*/
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/**
|
||||
* 满减券减免金额
|
||||
*/
|
||||
private BigDecimal reduceAmount;
|
||||
|
||||
/**
|
||||
* 优惠券总数量
|
||||
*/
|
||||
private Integer totalCount;
|
||||
|
||||
/**
|
||||
* 已使用数量
|
||||
*/
|
||||
private Integer usedCount;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 状态:1-可用,2-已过期,3-已用完
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 优惠券标签关联表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_coupon_tag")
|
||||
public class CouponTagDO extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 关联优惠券表主键
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 关联标签表主键
|
||||
*/
|
||||
private Long tagId;
|
||||
|
||||
/**
|
||||
* 是否可用:1-可用,0-不可用
|
||||
*/
|
||||
private Integer isAvailable;
|
||||
|
||||
/**
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户优惠券关联表
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_user_coupon")
|
||||
public class UserCouponDO extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 关联用户表主键
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 关联优惠券表主键
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 状态:1-未使用,2-已使用,3-已过期
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 获取时间
|
||||
*/
|
||||
private LocalDateTime obtainTime;
|
||||
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private LocalDateTime useTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.CouponDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 优惠券Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponMapper extends BaseMapper<CouponDO> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.CouponTagDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 优惠券标签关联Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponTagMapper extends BaseMapper<CouponTagDO> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.xiaowang.yuminailcore.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.yuminailcore.entity.UserCouponDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户优惠券Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserCouponMapper extends BaseMapper<UserCouponDO> {
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.xiaowang.yuminailcore.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xiaowang.yuminailcore.dto.CouponDTO;
|
||||
import com.xiaowang.yuminailcore.entity.CouponDO;
|
||||
import com.xiaowang.yuminailcore.vo.CouponVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserCouponVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券服务
|
||||
*/
|
||||
public interface CouponService extends IService<CouponDO> {
|
||||
|
||||
/**
|
||||
* 创建优惠券
|
||||
* @param couponDTO 优惠券DTO
|
||||
* @param shopId 店铺ID
|
||||
* @return 优惠券ID
|
||||
*/
|
||||
Long createCoupon(CouponDTO couponDTO, Long shopId);
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
* @param id 优惠券ID
|
||||
* @param couponDTO 优惠券DTO
|
||||
* @param shopId 店铺ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateCoupon(Long id, CouponDTO couponDTO, Long shopId);
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
* @param id 优惠券ID
|
||||
* @param shopId 店铺ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteCoupon(Long id, Long shopId);
|
||||
|
||||
/**
|
||||
* 获取优惠券详情
|
||||
* @param id 优惠券ID
|
||||
* @return 优惠券VO
|
||||
*/
|
||||
CouponVO getCouponById(Long id);
|
||||
|
||||
/**
|
||||
* 获取优惠券列表
|
||||
* @param page 页码
|
||||
* @param size 每页大小
|
||||
* @param shopId 店铺ID
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<CouponVO> listCoupons(Integer page, Integer size, Long shopId);
|
||||
|
||||
/**
|
||||
* 为用户分配优惠券
|
||||
* @param userId 用户ID
|
||||
* @param couponId 优惠券ID
|
||||
* @param shopId 店铺ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean assignCouponToUser(Long userId, Long couponId, Long shopId);
|
||||
|
||||
/**
|
||||
* 获取用户优惠券列表
|
||||
* @param userId 用户ID
|
||||
* @param status 状态
|
||||
* @return 用户优惠券列表
|
||||
*/
|
||||
List<UserCouponVO> listUserCoupons(Long userId, Integer status);
|
||||
|
||||
/**
|
||||
* 使用优惠券
|
||||
* @param userCouponId 用户优惠券ID
|
||||
* @param userId 用户ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean useCoupon(Long userCouponId, Long userId);
|
||||
|
||||
/**
|
||||
* 获取商品可用的优惠券
|
||||
* @param userId 用户ID
|
||||
* @param productTags 商品标签
|
||||
* @param productPrice 商品价格
|
||||
* @return 可用优惠券列表
|
||||
*/
|
||||
List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice);
|
||||
}
|
||||
+452
@@ -0,0 +1,452 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.dto.CouponDTO;
|
||||
import com.xiaowang.yuminailcore.entity.CouponDO;
|
||||
import com.xiaowang.yuminailcore.entity.CouponTagDO;
|
||||
import com.xiaowang.yuminailcore.entity.TagDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserCouponDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CouponMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.CouponTagMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.TagMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserCouponMapper;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
import com.xiaowang.yuminailcore.vo.CouponVO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserCouponVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 优惠券服务实现
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> implements CouponService {
|
||||
|
||||
private final CouponTagMapper couponTagMapper;
|
||||
private final UserCouponMapper userCouponMapper;
|
||||
private final TagMapper tagMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Long createCoupon(CouponDTO couponDTO, Long shopId) {
|
||||
// 创建优惠券
|
||||
CouponDO couponDO = new CouponDO();
|
||||
couponDO.setCouponCode(couponDTO.getCouponCode());
|
||||
couponDO.setCouponName(couponDTO.getCouponName());
|
||||
couponDO.setCouponType(couponDTO.getCouponType());
|
||||
couponDO.setDiscountValue(couponDTO.getDiscountValue());
|
||||
couponDO.setMinAmount(couponDTO.getMinAmount());
|
||||
couponDO.setReduceAmount(couponDTO.getReduceAmount());
|
||||
couponDO.setTotalCount(couponDTO.getTotalCount());
|
||||
couponDO.setUsedCount(0);
|
||||
couponDO.setStartTime(couponDTO.getStartTime());
|
||||
couponDO.setEndTime(couponDTO.getEndTime());
|
||||
couponDO.setStatus(1);
|
||||
save(couponDO);
|
||||
|
||||
// 处理标签关联
|
||||
handleCouponTags(couponDO.getId(), couponDTO.getAvailableTagIds(), couponDTO.getUnavailableTagIds());
|
||||
|
||||
return couponDO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateCoupon(Long id, CouponDTO couponDTO, Long shopId) {
|
||||
// 更新优惠券
|
||||
CouponDO couponDO = getById(id);
|
||||
if (couponDO == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
couponDO.setCouponCode(couponDTO.getCouponCode());
|
||||
couponDO.setCouponName(couponDTO.getCouponName());
|
||||
couponDO.setCouponType(couponDTO.getCouponType());
|
||||
couponDO.setDiscountValue(couponDTO.getDiscountValue());
|
||||
couponDO.setMinAmount(couponDTO.getMinAmount());
|
||||
couponDO.setReduceAmount(couponDTO.getReduceAmount());
|
||||
couponDO.setTotalCount(couponDTO.getTotalCount());
|
||||
couponDO.setStartTime(couponDTO.getStartTime());
|
||||
couponDO.setEndTime(couponDTO.getEndTime());
|
||||
updateById(couponDO);
|
||||
|
||||
// 处理标签关联
|
||||
handleCouponTags(id, couponDTO.getAvailableTagIds(), couponDTO.getUnavailableTagIds());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteCoupon(Long id, Long shopId) {
|
||||
// 删除优惠券
|
||||
CouponDO couponDO = getById(id);
|
||||
if (couponDO == null) {
|
||||
return false;
|
||||
}
|
||||
couponDO.setIsDelete(1);
|
||||
return updateById(couponDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouponVO getCouponById(Long id) {
|
||||
CouponDO couponDO = getById(id);
|
||||
if (couponDO == null || couponDO.getIsDelete() == 1) {
|
||||
return null;
|
||||
}
|
||||
return convertToCouponVO(couponDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<CouponVO> listCoupons(Integer page, Integer size, Long shopId) {
|
||||
Page<CouponDO> pageInfo = new Page<>(page, size);
|
||||
IPage<CouponDO> couponPage = page(pageInfo, new LambdaQueryWrapper<CouponDO>()
|
||||
.eq(CouponDO::getIsDelete, 0)
|
||||
.orderByDesc(CouponDO::getCreateTime)
|
||||
);
|
||||
|
||||
List<CouponVO> couponVOs = couponPage.getRecords().stream()
|
||||
.map(this::convertToCouponVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
PageResultVO<CouponVO> pageResult = new PageResultVO<>();
|
||||
pageResult.setList(couponVOs);
|
||||
pageResult.setTotal(couponPage.getTotal());
|
||||
pageResult.setPage(page);
|
||||
pageResult.setSize(size);
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean assignCouponToUser(Long userId, Long couponId, Long shopId) {
|
||||
// 检查优惠券是否存在
|
||||
CouponDO couponDO = getById(couponId);
|
||||
if (couponDO == null || couponDO.getIsDelete() == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查优惠券是否可用
|
||||
if (couponDO.getStatus() != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否已经分配
|
||||
UserCouponDO existing = userCouponMapper.selectOne(new LambdaQueryWrapper<UserCouponDO>()
|
||||
.eq(UserCouponDO::getUserId, userId)
|
||||
.eq(UserCouponDO::getCouponId, couponId)
|
||||
.eq(UserCouponDO::getIsDelete, 0)
|
||||
);
|
||||
if (existing != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 分配优惠券
|
||||
UserCouponDO userCouponDO = new UserCouponDO();
|
||||
userCouponDO.setUserId(userId);
|
||||
userCouponDO.setCouponId(couponId);
|
||||
userCouponDO.setStatus(1);
|
||||
userCouponDO.setObtainTime(LocalDateTime.now());
|
||||
userCouponMapper.insert(userCouponDO);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCouponVO> listUserCoupons(Long userId, Integer status) {
|
||||
LambdaQueryWrapper<UserCouponDO> queryWrapper = new LambdaQueryWrapper<UserCouponDO>()
|
||||
.eq(UserCouponDO::getUserId, userId)
|
||||
.eq(UserCouponDO::getIsDelete, 0);
|
||||
|
||||
if (status != null) {
|
||||
queryWrapper.eq(UserCouponDO::getStatus, status);
|
||||
}
|
||||
|
||||
List<UserCouponDO> userCouponDOs = userCouponMapper.selectList(queryWrapper);
|
||||
return userCouponDOs.stream()
|
||||
.map(this::convertToUserCouponVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean useCoupon(Long userCouponId, Long userId) {
|
||||
// 检查用户优惠券是否存在
|
||||
UserCouponDO userCouponDO = userCouponMapper.selectById(userCouponId);
|
||||
if (userCouponDO == null || userCouponDO.getIsDelete() == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否属于当前用户
|
||||
if (!userCouponDO.getUserId().equals(userId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查是否未使用
|
||||
if (userCouponDO.getStatus() != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查优惠券是否过期
|
||||
CouponDO couponDO = getById(userCouponDO.getCouponId());
|
||||
if (couponDO == null || couponDO.getEndTime().isBefore(LocalDateTime.now())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 使用优惠券
|
||||
userCouponDO.setStatus(2);
|
||||
userCouponDO.setUseTime(LocalDateTime.now());
|
||||
userCouponMapper.updateById(userCouponDO);
|
||||
|
||||
// 更新优惠券使用数量
|
||||
couponDO.setUsedCount(couponDO.getUsedCount() + 1);
|
||||
if (couponDO.getUsedCount() >= couponDO.getTotalCount()) {
|
||||
couponDO.setStatus(3);
|
||||
}
|
||||
updateById(couponDO);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCouponVO> getAvailableCoupons(Long userId, String productTags, Double productPrice) {
|
||||
// 获取用户未使用的优惠券
|
||||
List<UserCouponDO> userCouponDOs = userCouponMapper.selectList(new LambdaQueryWrapper<UserCouponDO>()
|
||||
.eq(UserCouponDO::getUserId, userId)
|
||||
.eq(UserCouponDO::getStatus, 1)
|
||||
.eq(UserCouponDO::getIsDelete, 0)
|
||||
);
|
||||
|
||||
List<UserCouponVO> availableCoupons = new ArrayList<>();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
for (UserCouponDO userCouponDO : userCouponDOs) {
|
||||
CouponDO couponDO = getById(userCouponDO.getCouponId());
|
||||
if (couponDO == null || couponDO.getIsDelete() == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查优惠券是否在有效期内
|
||||
if (now.isBefore(couponDO.getStartTime()) || now.isAfter(couponDO.getEndTime())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查优惠券是否可用
|
||||
if (couponDO.getStatus() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查满减券的最低消费金额
|
||||
if (couponDO.getCouponType() == 2) {
|
||||
if (couponDO.getMinAmount().doubleValue() > productPrice) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查标签是否匹配
|
||||
if (!checkTagMatch(couponDO.getId(), productTags)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
availableCoupons.add(convertToUserCouponVO(userCouponDO));
|
||||
}
|
||||
|
||||
return availableCoupons;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理优惠券标签关联
|
||||
*/
|
||||
private void handleCouponTags(Long couponId, List<Long> availableTagIds, List<Long> unavailableTagIds) {
|
||||
// 删除原有标签关联
|
||||
couponTagMapper.delete(new LambdaQueryWrapper<CouponTagDO>()
|
||||
.eq(CouponTagDO::getCouponId, couponId)
|
||||
);
|
||||
|
||||
// 添加可用标签
|
||||
if (availableTagIds != null) {
|
||||
for (Long tagId : availableTagIds) {
|
||||
CouponTagDO couponTagDO = new CouponTagDO();
|
||||
couponTagDO.setCouponId(couponId);
|
||||
couponTagDO.setTagId(tagId);
|
||||
couponTagDO.setIsAvailable(1);
|
||||
couponTagMapper.insert(couponTagDO);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加不可用标签
|
||||
if (unavailableTagIds != null) {
|
||||
for (Long tagId : unavailableTagIds) {
|
||||
CouponTagDO couponTagDO = new CouponTagDO();
|
||||
couponTagDO.setCouponId(couponId);
|
||||
couponTagDO.setTagId(tagId);
|
||||
couponTagDO.setIsAvailable(0);
|
||||
couponTagMapper.insert(couponTagDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查标签是否匹配
|
||||
*/
|
||||
private boolean checkTagMatch(Long couponId, String productTags) {
|
||||
if (productTags == null || productTags.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 解析商品标签
|
||||
String[] tagNames = productTags.split(",");
|
||||
|
||||
// 查询所有标签
|
||||
List<TagDO> allTags = tagMapper.selectList(new LambdaQueryWrapper<>());
|
||||
|
||||
// 找到匹配的标签ID
|
||||
List<Long> productTagIds = allTags.stream()
|
||||
.filter(tag -> {
|
||||
for (String tagName : tagNames) {
|
||||
if (tag.getTagName() != null && tag.getTagName().equals(tagName.trim())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.map(tag -> tag.getId())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (productTagIds.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<CouponTagDO> couponTagDOs = couponTagMapper.selectList(new LambdaQueryWrapper<CouponTagDO>()
|
||||
.eq(CouponTagDO::getCouponId, couponId)
|
||||
.in(CouponTagDO::getTagId, productTagIds)
|
||||
);
|
||||
|
||||
// 如果有不可用标签,则返回false
|
||||
for (CouponTagDO couponTagDO : couponTagDOs) {
|
||||
if (couponTagDO.getIsAvailable() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为CouponVO
|
||||
*/
|
||||
private CouponVO convertToCouponVO(CouponDO couponDO) {
|
||||
CouponVO couponVO = new CouponVO();
|
||||
couponVO.setId(couponDO.getId());
|
||||
couponVO.setCouponCode(couponDO.getCouponCode());
|
||||
couponVO.setCouponName(couponDO.getCouponName());
|
||||
couponVO.setCouponType(couponDO.getCouponType());
|
||||
couponVO.setCouponTypeName(couponDO.getCouponType() == 1 ? "折扣券" : "满减券");
|
||||
couponVO.setDiscountValue(couponDO.getDiscountValue());
|
||||
couponVO.setMinAmount(couponDO.getMinAmount());
|
||||
couponVO.setReduceAmount(couponDO.getReduceAmount());
|
||||
couponVO.setTotalCount(couponDO.getTotalCount());
|
||||
couponVO.setUsedCount(couponDO.getUsedCount());
|
||||
couponVO.setRemainingCount(couponDO.getTotalCount() - couponDO.getUsedCount());
|
||||
couponVO.setStartTime(couponDO.getStartTime());
|
||||
couponVO.setEndTime(couponDO.getEndTime());
|
||||
couponVO.setStatus(couponDO.getStatus());
|
||||
|
||||
switch (couponDO.getStatus()) {
|
||||
case 1:
|
||||
couponVO.setStatusName("可用");
|
||||
break;
|
||||
case 2:
|
||||
couponVO.setStatusName("已过期");
|
||||
break;
|
||||
case 3:
|
||||
couponVO.setStatusName("已用完");
|
||||
break;
|
||||
default:
|
||||
couponVO.setStatusName("未知");
|
||||
}
|
||||
|
||||
// 获取可用标签
|
||||
List<TagVO> availableTags = couponTagMapper.selectList(new LambdaQueryWrapper<CouponTagDO>()
|
||||
.eq(CouponTagDO::getCouponId, couponDO.getId())
|
||||
.eq(CouponTagDO::getIsAvailable, 1)
|
||||
).stream()
|
||||
.map(couponTag -> {
|
||||
TagVO tagVO = new TagVO();
|
||||
tagVO.setId(couponTag.getTagId());
|
||||
return tagVO;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
couponVO.setAvailableTags(availableTags);
|
||||
|
||||
// 获取不可用标签
|
||||
List<TagVO> unavailableTags = couponTagMapper.selectList(new LambdaQueryWrapper<CouponTagDO>()
|
||||
.eq(CouponTagDO::getCouponId, couponDO.getId())
|
||||
.eq(CouponTagDO::getIsAvailable, 0)
|
||||
).stream()
|
||||
.map(couponTag -> {
|
||||
TagVO tagVO = new TagVO();
|
||||
tagVO.setId(couponTag.getTagId());
|
||||
return tagVO;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
couponVO.setUnavailableTags(unavailableTags);
|
||||
|
||||
return couponVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为UserCouponVO
|
||||
*/
|
||||
private UserCouponVO convertToUserCouponVO(UserCouponDO userCouponDO) {
|
||||
UserCouponVO userCouponVO = new UserCouponVO();
|
||||
userCouponVO.setId(userCouponDO.getId());
|
||||
userCouponVO.setCouponId(userCouponDO.getCouponId());
|
||||
|
||||
CouponDO couponDO = getById(userCouponDO.getCouponId());
|
||||
if (couponDO != null) {
|
||||
userCouponVO.setCouponName(couponDO.getCouponName());
|
||||
userCouponVO.setCouponType(couponDO.getCouponType());
|
||||
userCouponVO.setCouponTypeName(couponDO.getCouponType() == 1 ? "折扣券" : "满减券");
|
||||
userCouponVO.setDiscountValue(couponDO.getDiscountValue() != null ? couponDO.getDiscountValue().toString() : "");
|
||||
userCouponVO.setMinAmount(couponDO.getMinAmount() != null ? couponDO.getMinAmount().toString() : "");
|
||||
userCouponVO.setReduceAmount(couponDO.getReduceAmount() != null ? couponDO.getReduceAmount().toString() : "");
|
||||
userCouponVO.setStartTime(couponDO.getStartTime());
|
||||
userCouponVO.setEndTime(couponDO.getEndTime());
|
||||
}
|
||||
|
||||
userCouponVO.setStatus(userCouponDO.getStatus());
|
||||
switch (userCouponDO.getStatus()) {
|
||||
case 1:
|
||||
userCouponVO.setStatusName("未使用");
|
||||
break;
|
||||
case 2:
|
||||
userCouponVO.setStatusName("已使用");
|
||||
break;
|
||||
case 3:
|
||||
userCouponVO.setStatusName("已过期");
|
||||
break;
|
||||
default:
|
||||
userCouponVO.setStatusName("未知");
|
||||
}
|
||||
|
||||
userCouponVO.setObtainTime(userCouponDO.getObtainTime());
|
||||
userCouponVO.setUseTime(userCouponDO.getUseTime());
|
||||
|
||||
return userCouponVO;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 优惠券VO
|
||||
*/
|
||||
@Data
|
||||
public class CouponVO {
|
||||
|
||||
/**
|
||||
* 优惠券ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 优惠券编码
|
||||
*/
|
||||
private String couponCode;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 优惠券类型:1-折扣券,2-满减券
|
||||
*/
|
||||
private Integer couponType;
|
||||
|
||||
/**
|
||||
* 优惠券类型名称
|
||||
*/
|
||||
private String couponTypeName;
|
||||
|
||||
/**
|
||||
* 折扣值(如9.5表示95折)
|
||||
*/
|
||||
private BigDecimal discountValue;
|
||||
|
||||
/**
|
||||
* 满减券最低消费金额
|
||||
*/
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/**
|
||||
* 满减券减免金额
|
||||
*/
|
||||
private BigDecimal reduceAmount;
|
||||
|
||||
/**
|
||||
* 优惠券总数量
|
||||
*/
|
||||
private Integer totalCount;
|
||||
|
||||
/**
|
||||
* 已使用数量
|
||||
*/
|
||||
private Integer usedCount;
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer remainingCount;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 状态:1-可用,2-已过期,3-已用完
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 状态名称
|
||||
*/
|
||||
private String statusName;
|
||||
|
||||
/**
|
||||
* 可用标签列表
|
||||
*/
|
||||
private List<TagVO> availableTags;
|
||||
|
||||
/**
|
||||
* 不可用标签列表
|
||||
*/
|
||||
private List<TagVO> unavailableTags;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.xiaowang.yuminailcore.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户优惠券VO
|
||||
*/
|
||||
@Data
|
||||
public class UserCouponVO {
|
||||
|
||||
/**
|
||||
* 关联ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 优惠券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 优惠券类型:1-折扣券,2-满减券
|
||||
*/
|
||||
private Integer couponType;
|
||||
|
||||
/**
|
||||
* 优惠券类型名称
|
||||
*/
|
||||
private String couponTypeName;
|
||||
|
||||
/**
|
||||
* 折扣值(如9.5表示95折)
|
||||
*/
|
||||
private String discountValue;
|
||||
|
||||
/**
|
||||
* 满减券最低消费金额
|
||||
*/
|
||||
private String minAmount;
|
||||
|
||||
/**
|
||||
* 满减券减免金额
|
||||
*/
|
||||
private String reduceAmount;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 状态:1-未使用,2-已使用,3-已过期
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 状态名称
|
||||
*/
|
||||
private String statusName;
|
||||
|
||||
/**
|
||||
* 获取时间
|
||||
*/
|
||||
private LocalDateTime obtainTime;
|
||||
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private LocalDateTime useTime;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
-- 优惠券信息表
|
||||
create table t_coupon
|
||||
(
|
||||
id bigint unsigned auto_increment comment '优惠券唯一主键ID'
|
||||
primary key comment '优惠券主键索引',
|
||||
coupon_code varchar(50) not null comment '优惠券编码',
|
||||
coupon_name varchar(100) not null comment '优惠券名称',
|
||||
coupon_type tinyint not null comment '优惠券类型:1-折扣券,2-满减券',
|
||||
discount_value decimal(10, 2) default 0.00 null comment '折扣值(如9.5表示95折)',
|
||||
min_amount decimal(10, 2) default 0.00 null comment '满减券最低消费金额',
|
||||
reduce_amount decimal(10, 2) default 0.00 null comment '满减券减免金额',
|
||||
total_count int unsigned default 100 not null comment '优惠券总数量',
|
||||
used_count int unsigned default 0 not null comment '已使用数量',
|
||||
start_time datetime not null comment '开始时间',
|
||||
end_time datetime not null comment '结束时间',
|
||||
status tinyint unsigned default 1 not null comment '状态:1-可用,2-已过期,3-已用完',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_coupon_code
|
||||
unique (coupon_code) comment '优惠券编码唯一索引'
|
||||
) comment '优惠券信息表';
|
||||
|
||||
create index idx_status
|
||||
on t_coupon (status) comment '按状态查询优惠券的索引';
|
||||
|
||||
-- 用户优惠券关联表
|
||||
create table t_user_coupon
|
||||
(
|
||||
id bigint unsigned auto_increment comment '用户优惠券关联唯一主键ID'
|
||||
primary key comment '用户优惠券关联主键索引',
|
||||
user_id bigint unsigned not null comment '关联用户表主键',
|
||||
coupon_id bigint unsigned not null comment '关联优惠券表主键',
|
||||
status tinyint unsigned default 1 not null comment '状态:1-未使用,2-已使用,3-已过期',
|
||||
obtain_time datetime default CURRENT_TIMESTAMP not null comment '获取时间',
|
||||
use_time datetime null comment '使用时间',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_user_coupon
|
||||
unique (user_id, coupon_id) comment '用户-优惠券唯一索引'
|
||||
) comment '用户优惠券关联表';
|
||||
|
||||
create index idx_status
|
||||
on t_user_coupon (status) comment '按状态查询用户优惠券的索引';
|
||||
|
||||
create index idx_user_id
|
||||
on t_user_coupon (user_id) comment '按用户查询优惠券的索引';
|
||||
|
||||
-- 优惠券标签关联表
|
||||
create table t_coupon_tag
|
||||
(
|
||||
id bigint unsigned auto_increment comment '优惠券标签关联唯一主键ID'
|
||||
primary key comment '优惠券标签关联主键索引',
|
||||
coupon_id bigint unsigned not null comment '关联优惠券表主键',
|
||||
tag_id bigint unsigned not null comment '关联标签表主键',
|
||||
is_available tinyint unsigned default 1 not null comment '是否可用:1-可用,0-不可用',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
constraint uk_coupon_tag
|
||||
unique (coupon_id, tag_id) comment '优惠券-标签唯一索引'
|
||||
) comment '优惠券标签关联表';
|
||||
|
||||
create index idx_coupon_id
|
||||
on t_coupon_tag (coupon_id) comment '按优惠券查询标签的索引';
|
||||
|
||||
create index idx_tag_id
|
||||
on t_coupon_tag (tag_id) comment '按标签查询优惠券的索引';
|
||||
|
||||
-- 插入优惠券管理相关权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
|
||||
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
|
||||
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
|
||||
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
|
||||
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员(type=4)分配优惠券管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 4
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign'
|
||||
);
|
||||
|
||||
-- 为店长(type=2)分配优惠券管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 2
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign'
|
||||
);
|
||||
Reference in New Issue
Block a user