Bladeren bron

开发完成购物卡管理相关的接口

jinshihui 1 week geleden
bovenliggende
commit
c3ec57d143

+ 177 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/controller/GiftCardManageController.java

@@ -0,0 +1,177 @@
+package com.ylx.giftCard.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ylx.common.annotation.Log;
+import com.ylx.common.core.domain.R;
+import com.ylx.common.enums.BusinessType;
+import com.ylx.common.exception.ServiceException;
+import com.ylx.giftCard.domain.GiftCard;
+import com.ylx.giftCard.domain.dto.GiftCardManageQueryDTO;
+import com.ylx.giftCard.domain.dto.GiftCardManageSaveDTO;
+import com.ylx.giftCard.domain.dto.GiftCardManageUpdateDTO;
+import com.ylx.giftCard.domain.dto.GiftCardPublishStatusDTO;
+import com.ylx.giftCard.domain.vo.GiftCardManageDetailVO;
+import com.ylx.giftCard.domain.vo.GiftCardManageExportVO;
+import com.ylx.giftCard.domain.vo.GiftCardManagePageVO;
+import com.ylx.giftCard.service.IGiftCardService;
+import com.ylx.common.utils.poi.ExcelUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+@Slf4j
+@RestController
+@RequestMapping("/gift/card/manage")
+@Api(tags = {"购物卡管理"})
+public class GiftCardManageController {
+
+    @Resource
+    private IGiftCardService giftCardService;
+
+    /**
+     * 分页查询购物卡
+     * @param page
+     * @param dto
+     * @return R<Page<GiftCardManagePageVO>>
+     */
+    @GetMapping("/page")
+    @ApiOperation("分页查询购物卡")
+    public R<Page<GiftCardManagePageVO>> page(Page<GiftCard> page, GiftCardManageQueryDTO dto) {
+        try {
+            return R.ok(giftCardService.getManagePage(page, dto));
+        } catch (ServiceException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("分页查询购物卡异常", e);
+            return R.fail("分页查询购物卡失败");
+        }
+    }
+
+    /**
+     * 导出购物卡
+     * @param response
+     * @param dto
+     */
+    @PostMapping("/export")
+    @ApiOperation("导出购物卡")
+    @Log(title = "导出购物卡", businessType = BusinessType.EXPORT)
+    public void export(HttpServletResponse response, GiftCardManageQueryDTO dto) {
+        try {
+            List<GiftCardManageExportVO> list = giftCardService.getManageExportList(dto);
+            ExcelUtil<GiftCardManageExportVO> util = new ExcelUtil<>(GiftCardManageExportVO.class);
+            util.exportExcel(response, list, "购物卡管理");
+        } catch (ServiceException e) {
+            log.error("导出购物卡参数异常", e);
+            throw e;
+        } catch (Exception e) {
+            log.error("导出购物卡异常", e);
+            throw new RuntimeException("导出购物卡失败", e);
+        }
+    }
+
+    /**
+     * 查询购物卡详情
+     * @param id
+     * @return R<GiftCardManageDetailVO>
+     */
+    @GetMapping("/{id}")
+    @ApiOperation("查询购物卡详情")
+    public R<GiftCardManageDetailVO> detail(@PathVariable("id") Long id) {
+        try {
+            return R.ok(giftCardService.getManageDetail(id));
+        } catch (ServiceException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("查询购物卡详情异常", e);
+            return R.fail("查询购物卡详情失败");
+        }
+    }
+
+    /**
+     * 新增购物卡
+     * @param dto
+     * @return R<?>
+     */
+    @PostMapping
+    @ApiOperation("新增购物卡")
+    @Log(title = "新增购物卡", businessType = BusinessType.INSERT)
+    public R<?> add(@Validated @RequestBody GiftCardManageSaveDTO dto) {
+        try {
+            giftCardService.addGiftCard(dto);
+            return R.ok();
+        } catch (ServiceException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("新增购物卡异常", e);
+            return R.fail("新增购物卡失败");
+        }
+    }
+
+    /**
+     * 编辑购物卡
+     * @param dto
+     * @return R<?>
+     */
+    @PutMapping
+    @ApiOperation("编辑购物卡")
+    @Log(title = "编辑购物卡", businessType = BusinessType.UPDATE)
+    public R<?> edit(@Validated @RequestBody GiftCardManageUpdateDTO dto) {
+        try {
+            giftCardService.updateGiftCard(dto);
+            return R.ok();
+        } catch (ServiceException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("编辑购物卡异常", e);
+            return R.fail("编辑购物卡失败");
+        }
+    }
+
+    @PutMapping("/publish")
+    @ApiOperation("修改购物卡上架状态")
+    @Log(title = "修改购物卡上架状态", businessType = BusinessType.UPDATE)
+    public R<?> updatePublishStatus(@Validated @RequestBody GiftCardPublishStatusDTO dto) {
+        try {
+            giftCardService.updatePublishStatus(dto);
+            return R.ok();
+        } catch (ServiceException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("修改购物卡上架状态异常", e);
+            return R.fail("修改购物卡上架状态失败");
+        }
+    }
+
+    /**
+     * 删除购物卡
+     * @param id
+     * @return R<?>
+     */
+    @DeleteMapping("/{id}")
+    @ApiOperation("删除购物卡")
+    @Log(title = "删除购物卡", businessType = BusinessType.DELETE)
+    public R<?> delete(@PathVariable("id") Long id) {
+        try {
+            giftCardService.deleteGiftCard(id);
+            return R.ok();
+        } catch (ServiceException e) {
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("删除购物卡异常", e);
+            return R.fail("删除购物卡失败");
+        }
+    }
+}

+ 20 - 16
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/GiftCard.java

@@ -2,9 +2,12 @@ package com.ylx.giftCard.domain;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.ylx.common.core.domain.BaseEntity;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -14,6 +17,7 @@ import java.time.LocalDate;
  */
 @EqualsAndHashCode(callSuper = true)
 @Data
+@TableName("gift_card")
 public class GiftCard extends BaseEntity {
     private static final long serialVersionUID = 2378338959829222898L;
 
@@ -33,11 +37,26 @@ public class GiftCard extends BaseEntity {
      */
     private String name;
 
+    /**
+     * 缩略图URL(上传后存储路径)
+     */
+    private String imageUrl;
+
     /**
      * 面值金额,单位:元
      */
     private BigDecimal amount;
 
+    /**
+     * 商户提成比例,如 1.00 表示 1%
+     */
+    private BigDecimal commissionRate;
+
+    /**
+     * 是否上架:1=上架,0=下架
+     */
+    private Integer isPublished;
+
     /**
      * 库存数量,0表示无库存
      */
@@ -58,21 +77,6 @@ public class GiftCard extends BaseEntity {
      */
     private LocalDate validEndDate;
 
-    /**
-     * 商户提成比例,如 1.00 表示 1%
-     */
-    private BigDecimal commissionRate;
-
-    /**
-     * 缩略图URL(上传后存储路径)
-     */
-    private String imageUrl;
-
-    /**
-     * 是否上架:1=上架,0=下架
-     */
-    private Integer isPublished;
-
     /**
      * 详情(富文本,可存HTML或Markdown)
      */
@@ -81,6 +85,6 @@ public class GiftCard extends BaseEntity {
     /**
      * 是否删除:0=否,1=是。
      */
+    @TableLogic
     private Integer isDelete;
-
 }

+ 29 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/dto/GiftCardManageQueryDTO.java

@@ -0,0 +1,29 @@
+package com.ylx.giftCard.domain.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.time.LocalDate;
+
+@Data
+@ApiModel("购物卡管理分页查询DTO")
+public class GiftCardManageQueryDTO implements Serializable {
+    private static final long serialVersionUID = 1184559947927043323L;
+
+    @ApiModelProperty("购物卡名称")
+    private String name;
+
+    @ApiModelProperty("创建开始日期,格式:yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private LocalDate beginCreateDate;
+
+    @ApiModelProperty("创建结束日期,格式:yyyy-MM-dd")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private LocalDate endCreateDate;
+
+    @ApiModelProperty("是否上架:1=上架,0=下架")
+    private Integer isPublished;
+}

+ 93 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/dto/GiftCardManageSaveDTO.java

@@ -0,0 +1,93 @@
+package com.ylx.giftCard.domain.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+
+@Data
+@ApiModel("购物卡管理新增DTO")
+public class GiftCardManageSaveDTO implements Serializable {
+    private static final long serialVersionUID = -3120530382569245494L;
+
+    /**
+     * 商户ID
+     */
+    @ApiModelProperty("商户ID")
+    private String merchantId;
+
+    /**
+     * 购物卡名称
+     */
+    @NotBlank(message = "购物卡名称不能为空")
+    @Size(max = 20, message = "购物卡名称不能超过20个字符")
+    @ApiModelProperty(value = "购物卡名称", required = true)
+    private String name;
+
+    /**
+     * 缩略图URL(上传后存储路径)
+     */
+    @NotBlank(message = "图片不能为空")
+    @ApiModelProperty(value = "图片URL", required = true)
+    private String imageUrl;
+
+    /**
+     * 购物卡金额
+     */
+    @NotNull(message = "购物卡金额不能为空")
+    @DecimalMin(value = "0.01", message = "购物卡金额必须大于0")
+    @ApiModelProperty(value = "购物卡金额", required = true)
+    private BigDecimal amount;
+
+    /**
+     * 商户提成比例
+     */
+    @NotNull(message = "商户提成比例不能为空")
+    @DecimalMin(value = "0", message = "商户提成比例不能小于0")
+    @DecimalMax(value = "100", message = "商户提成比例不能大于100")
+    @ApiModelProperty(value = "商户提成比例", required = true)
+    private BigDecimal commissionRate;
+
+    /**
+     * 库存
+     */
+    @NotNull(message = "库存不能为空")
+    @Min(value = 0, message = "库存不能小于0")
+    @ApiModelProperty(value = "库存", required = true)
+    private Integer stock;
+
+    /**
+     * 有效期开始日期
+     */
+    @NotNull(message = "有效期开始日期不能为空")
+    @ApiModelProperty(value = "有效期开始日期", required = true)
+    private LocalDate validStartDate;
+
+    /**
+     * 有效期结束日期
+     */
+    @NotNull(message = "有效期结束日期不能为空")
+    @ApiModelProperty(value = "有效期结束日期", required = true)
+    private LocalDate validEndDate;
+
+    /**
+     * 是否上架:1=上架,0=下架,不传默认下架
+     */
+    @ApiModelProperty("是否上架:1=上架,0=下架,不传默认下架")
+    private Integer isPublished;
+
+    /**
+     * 详情
+     */
+    @ApiModelProperty("详情")
+    private String description;
+}

+ 19 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/dto/GiftCardManageUpdateDTO.java

@@ -0,0 +1,19 @@
+package com.ylx.giftCard.domain.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ApiModel("购物卡管理编辑DTO")
+public class GiftCardManageUpdateDTO extends GiftCardManageSaveDTO {
+    private static final long serialVersionUID = -5113137396795744112L;
+
+    @NotNull(message = "购物卡ID不能为空")
+    @ApiModelProperty(value = "购物卡ID", required = true)
+    private Long id;
+}

+ 25 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/dto/GiftCardPublishStatusDTO.java

@@ -0,0 +1,25 @@
+package com.ylx.giftCard.domain.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+@Data
+@ApiModel("购物卡上架状态DTO")
+public class GiftCardPublishStatusDTO implements Serializable {
+    private static final long serialVersionUID = 910932605659176876L;
+
+    /**
+     * 购物卡ID
+     */
+    @NotNull(message = "购物卡ID不能为空")
+    @ApiModelProperty(value = "购物卡ID", required = true)
+    private Long id;
+
+    @NotNull(message = "上架状态不能为空")
+    @ApiModelProperty(value = "是否上架:1=上架,0=下架", required = true)
+    private Integer isPublished;
+}

+ 16 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/vo/GiftCardManageDetailVO.java

@@ -0,0 +1,16 @@
+package com.ylx.giftCard.domain.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ApiModel("购物卡管理详情VO")
+public class GiftCardManageDetailVO extends GiftCardManagePageVO {
+    private static final long serialVersionUID = -5068920224630043312L;
+
+    @ApiModelProperty("详情")
+    private String description;
+}

+ 42 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/vo/GiftCardManageExportVO.java

@@ -0,0 +1,42 @@
+package com.ylx.giftCard.domain.vo;
+
+import com.ylx.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+@ApiModel("购物卡管理导出VO")
+public class GiftCardManageExportVO implements Serializable {
+    private static final long serialVersionUID = -1629841029985374035L;
+
+    @Excel(name = "购物卡ID", sort = 1)
+    private Long id;
+
+    @Excel(name = "购物卡名称", sort = 2)
+    private String name;
+
+    @Excel(name = "金额", sort = 3)
+    private BigDecimal amount;
+
+    @Excel(name = "缩略图", sort = 4)
+    private String imageUrl;
+
+    @Excel(name = "库存", sort = 5)
+    private Integer stock;
+
+    @Excel(name = "销量", sort = 6)
+    private Integer sales;
+
+    @Excel(name = "是否上架", sort = 7, readConverterExp = "0=下架,1=上架")
+    private Integer isPublished;
+
+    @Excel(name = "发布时间", sort = 8, width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+
+    @Excel(name = "商户提成比例", sort = 9, suffix = "%")
+    private BigDecimal commissionRate;
+}

+ 54 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/domain/vo/GiftCardManagePageVO.java

@@ -0,0 +1,54 @@
+package com.ylx.giftCard.domain.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.util.Date;
+
+@Data
+@ApiModel("购物卡管理分页VO")
+public class GiftCardManagePageVO implements Serializable {
+    private static final long serialVersionUID = -6990232175036599711L;
+
+    @ApiModelProperty("购物卡ID")
+    private Long id;
+
+    @ApiModelProperty("商户ID")
+    private String merchantId;
+
+    @ApiModelProperty("购物卡名称")
+    private String name;
+
+    @ApiModelProperty("购物卡金额")
+    private BigDecimal amount;
+
+    @ApiModelProperty("缩略图URL")
+    private String imageUrl;
+
+    @ApiModelProperty("商户提成比例")
+    private BigDecimal commissionRate;
+
+    @ApiModelProperty("库存")
+    private Integer stock;
+
+    @ApiModelProperty("销量")
+    private Integer sales;
+
+    @ApiModelProperty("是否上架:1=上架,0=下架")
+    private Integer isPublished;
+
+    @ApiModelProperty("发布时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+
+    @ApiModelProperty("有效期开始日期")
+    private LocalDate validStartDate;
+
+    @ApiModelProperty("有效期结束日期")
+    private LocalDate validEndDate;
+}

+ 8 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/mapper/GiftCardMapper.java

@@ -2,7 +2,15 @@ package com.ylx.giftCard.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ylx.giftCard.domain.GiftCard;
+import com.ylx.giftCard.domain.dto.GiftCardManageQueryDTO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
 
 public interface GiftCardMapper extends BaseMapper<GiftCard> {
 
+    List<GiftCard> selectManageList(@Param("dto") GiftCardManageQueryDTO dto,
+                                    @Param("beginCreateTime") Date beginCreateTime,
+                                    @Param("endCreateTime") Date endCreateTime);
 }

+ 23 - 0
nightFragrance-massage/src/main/java/com/ylx/giftCard/service/IGiftCardService.java

@@ -2,10 +2,19 @@ package com.ylx.giftCard.service;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ylx.giftCard.domain.GiftCard;
+import com.ylx.giftCard.domain.dto.GiftCardManageQueryDTO;
+import com.ylx.giftCard.domain.dto.GiftCardManageSaveDTO;
+import com.ylx.giftCard.domain.dto.GiftCardManageUpdateDTO;
+import com.ylx.giftCard.domain.dto.GiftCardPublishStatusDTO;
 import com.ylx.giftCard.domain.dto.GiftCardPurchaseDTO;
 import com.ylx.giftCard.domain.vo.GiftCardDetailVO;
+import com.ylx.giftCard.domain.vo.GiftCardManageDetailVO;
+import com.ylx.giftCard.domain.vo.GiftCardManageExportVO;
+import com.ylx.giftCard.domain.vo.GiftCardManagePageVO;
 import com.ylx.giftCard.domain.vo.GiftCardVO;
 
+import java.util.List;
+
 public interface IGiftCardService {
 
     Page<GiftCardVO> getGiftCardPage(Page<GiftCard> page);
@@ -13,4 +22,18 @@ public interface IGiftCardService {
     boolean purchaseGiftCard(GiftCardPurchaseDTO dto);
 
     GiftCardDetailVO getGiftCardDetail(Long id);
+
+    Page<GiftCardManagePageVO> getManagePage(Page<GiftCard> page, GiftCardManageQueryDTO dto);
+
+    List<GiftCardManageExportVO> getManageExportList(GiftCardManageQueryDTO dto);
+
+    GiftCardManageDetailVO getManageDetail(Long id);
+
+    void addGiftCard(GiftCardManageSaveDTO dto);
+
+    void updateGiftCard(GiftCardManageUpdateDTO dto);
+
+    void updatePublishStatus(GiftCardPublishStatusDTO dto);
+
+    void deleteGiftCard(Long id);
 }

+ 255 - 1
nightFragrance-massage/src/main/java/com/ylx/giftCard/service/impl/GiftCardServiceImpl.java

@@ -3,17 +3,25 @@ package com.ylx.giftCard.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ylx.common.core.domain.model.WxLoginUser;
 import com.ylx.common.exception.ServiceException;
+import com.ylx.common.utils.DateUtils;
 import com.ylx.common.utils.SecurityUtils;
 import com.ylx.giftCard.domain.GiftCard;
 import com.ylx.giftCard.domain.GiftCardOrder;
+import com.ylx.giftCard.domain.dto.GiftCardManageQueryDTO;
+import com.ylx.giftCard.domain.dto.GiftCardManageSaveDTO;
+import com.ylx.giftCard.domain.dto.GiftCardManageUpdateDTO;
+import com.ylx.giftCard.domain.dto.GiftCardPublishStatusDTO;
 import com.ylx.giftCard.domain.dto.GiftCardPurchaseDTO;
 import com.ylx.giftCard.domain.vo.GiftCardDetailVO;
+import com.ylx.giftCard.domain.vo.GiftCardManageDetailVO;
+import com.ylx.giftCard.domain.vo.GiftCardManageExportVO;
+import com.ylx.giftCard.domain.vo.GiftCardManagePageVO;
 import com.ylx.giftCard.domain.vo.GiftCardVO;
 import com.ylx.giftCard.mapper.GiftCardMapper;
 import com.ylx.giftCard.service.IGiftCardOrderService;
@@ -26,6 +34,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -40,6 +52,8 @@ public class GiftCardServiceImpl extends ServiceImpl<GiftCardMapper, GiftCard> i
 
     private static final int NOT_DELETE = 0;
     private static final int PUBLISHED = 1;
+    private static final int UNPUBLISHED = 0;
+    private static final int DELETE = 1;
 
     @Override
     public Page<GiftCardVO> getGiftCardPage(Page<GiftCard> page) {
@@ -141,6 +155,112 @@ public class GiftCardServiceImpl extends ServiceImpl<GiftCardMapper, GiftCard> i
         return vo;
     }
 
+    @Override
+    public Page<GiftCardManagePageVO> getManagePage(Page<GiftCard> page, GiftCardManageQueryDTO dto) {
+        Page<GiftCard> pageParam = ObjectUtil.isNull(page) ? new Page<>(1, 10) : page;
+        LambdaQueryWrapper<GiftCard> wrapper = buildManageQueryWrapper(dto);
+
+        Page<GiftCard> entityPage = this.baseMapper.selectPage(pageParam, wrapper);
+        Page<GiftCardManagePageVO> pageData = new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
+        pageData.setPages(entityPage.getPages());
+        if (CollectionUtil.isNotEmpty(entityPage.getRecords())) {
+            pageData.setRecords(entityPage.getRecords().stream()
+                    .map(this::toManagePageVO)
+                    .collect(Collectors.toList()));
+        }
+        return pageData;
+    }
+
+    @Override
+    public List<GiftCardManageExportVO> getManageExportList(GiftCardManageQueryDTO dto) {
+        GiftCardManageQueryDTO query = ObjectUtil.isNull(dto) ? new GiftCardManageQueryDTO() : dto;
+        checkCreateDateRange(query.getBeginCreateDate(), query.getEndCreateDate());
+        if (StrUtil.isNotBlank(query.getName())) {
+            query.setName(StrUtil.trim(query.getName()));
+        }
+        List<GiftCard> entityList = this.baseMapper.selectManageList(
+                query,
+                toStartDate(query.getBeginCreateDate()),
+                toEndDate(query.getEndCreateDate())
+        );
+        return entityList.stream().map(this::toManageExportVO).collect(Collectors.toList());
+    }
+
+    @Override
+    public GiftCardManageDetailVO getManageDetail(Long id) {
+        GiftCard card = getActiveGiftCard(id);
+        GiftCardManageDetailVO vo = new GiftCardManageDetailVO();
+        BeanUtil.copyProperties(card, vo);
+        return vo;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void addGiftCard(GiftCardManageSaveDTO dto) {
+        checkSaveParam(dto);
+
+        GiftCard entity = new GiftCard();
+        fillGiftCard(entity, dto, normalizePublishStatus(dto.getIsPublished(), UNPUBLISHED));
+        entity.setId(null);
+        entity.setSales(0);
+        entity.setCreateBy(SecurityUtils.getUsername());
+        entity.setCreateTime(DateUtils.getNowDate());
+        entity.setUpdateBy(SecurityUtils.getUsername());
+        entity.setUpdateTime(DateUtils.getNowDate());
+
+        int insertResult = this.baseMapper.insert(entity);
+        if (insertResult <= 0) {
+            throw new ServiceException("新增购物卡失败");
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateGiftCard(GiftCardManageUpdateDTO dto) {
+        if (ObjectUtil.isNull(dto) || ObjectUtil.isNull(dto.getId())) {
+            throw new ServiceException("购物卡ID不能为空");
+        }
+        checkSaveParam(dto);
+
+        GiftCard entity = getActiveGiftCard(dto.getId());
+        Integer publishStatus = normalizePublishStatus(dto.getIsPublished(), entity.getIsPublished());
+        fillGiftCard(entity, dto, publishStatus);
+        entity.setUpdateBy(SecurityUtils.getUsername());
+        entity.setUpdateTime(DateUtils.getNowDate());
+
+        int updateResult = this.baseMapper.updateById(entity);
+        if (updateResult <= 0) {
+            throw new ServiceException("编辑购物卡失败");
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updatePublishStatus(GiftCardPublishStatusDTO dto) {
+        if (ObjectUtil.isNull(dto) || ObjectUtil.isNull(dto.getId())) {
+            throw new ServiceException("购物卡ID不能为空");
+        }
+        Integer publishStatus = normalizePublishStatus(dto.getIsPublished(), null);
+        GiftCard entity = getActiveGiftCard(dto.getId());
+        entity.setIsPublished(publishStatus);
+        entity.setUpdateBy(SecurityUtils.getUsername());
+        entity.setUpdateTime(DateUtils.getNowDate());
+
+        int updateResult = this.baseMapper.updateById(entity);
+        if (updateResult <= 0) {
+            throw new ServiceException("修改购物卡上架状态失败");
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteGiftCard(Long id) {
+        int deleteResult = this.baseMapper.deleteById(id);
+        if (deleteResult <= 0) {
+            throw new ServiceException("删除购物卡失败");
+        }
+    }
+
     /**
      * 异步创建订单
      */
@@ -183,4 +303,138 @@ public class GiftCardServiceImpl extends ServiceImpl<GiftCardMapper, GiftCard> i
         }
     }
 
+    private GiftCard getActiveGiftCard(Long id) {
+        if (ObjectUtil.isNull(id)) {
+            throw new ServiceException("购物卡ID不能为空");
+        }
+        if (id <= 0) {
+            throw new ServiceException("购物卡ID不正确");
+        }
+
+        LambdaQueryWrapper<GiftCard> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(GiftCard::getId, id).eq(GiftCard::getIsDelete, NOT_DELETE);
+        GiftCard entity = this.baseMapper.selectOne(wrapper);
+        if (ObjectUtil.isNull(entity)) {
+            throw new ServiceException("购物卡不存在或已删除");
+        }
+        return entity;
+    }
+
+    private void checkSaveParam(GiftCardManageSaveDTO dto) {
+        if (ObjectUtil.isNull(dto)) {
+            throw new ServiceException("购物卡参数不能为空");
+        }
+        if (StrUtil.isBlank(dto.getName())) {
+            throw new ServiceException("购物卡名称不能为空");
+        }
+        if (StrUtil.length(StrUtil.trim(dto.getName())) > 20) {
+            throw new ServiceException("购物卡名称不能超过20个字符");
+        }
+        if (StrUtil.isBlank(dto.getImageUrl())) {
+            throw new ServiceException("图片不能为空");
+        }
+        if (ObjectUtil.isNull(dto.getAmount()) || dto.getAmount().signum() <= 0) {
+            throw new ServiceException("购物卡金额必须大于0");
+        }
+        if (ObjectUtil.isNull(dto.getCommissionRate())
+                || dto.getCommissionRate().signum() < 0
+                || dto.getCommissionRate().compareTo(new BigDecimal("100")) > 0) {
+            throw new ServiceException("商户提成比例必须在0到100之间");
+        }
+        if (ObjectUtil.isNull(dto.getStock()) || dto.getStock() < 0) {
+            throw new ServiceException("库存不能小于0");
+        }
+        if (ObjectUtil.isNull(dto.getValidStartDate()) || ObjectUtil.isNull(dto.getValidEndDate())) {
+            throw new ServiceException("有效期不能为空");
+        }
+        if (dto.getValidStartDate().isAfter(dto.getValidEndDate())) {
+            throw new ServiceException("有效期开始日期不能晚于结束日期");
+        }
+    }
+
+    private void checkCreateDateRange(LocalDate beginDate, LocalDate endDate) {
+        if (ObjectUtil.isNotNull(beginDate) && ObjectUtil.isNotNull(endDate) && beginDate.isAfter(endDate)) {
+            throw new ServiceException("创建开始日期不能晚于结束日期");
+        }
+    }
+
+    private LambdaQueryWrapper<GiftCard> buildManageQueryWrapper(GiftCardManageQueryDTO dto) {
+        GiftCardManageQueryDTO query = ObjectUtil.isNull(dto) ? new GiftCardManageQueryDTO() : dto;
+        checkCreateDateRange(query.getBeginCreateDate(), query.getEndCreateDate());
+
+        LambdaQueryWrapper<GiftCard> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(GiftCard::getIsDelete, NOT_DELETE)
+                .like(StrUtil.isNotBlank(query.getName()), GiftCard::getName, StrUtil.trim(query.getName()))
+                .eq(ObjectUtil.isNotNull(query.getIsPublished()), GiftCard::getIsPublished, query.getIsPublished())
+                .ge(ObjectUtil.isNotNull(query.getBeginCreateDate()), GiftCard::getCreateTime, toStartDate(query.getBeginCreateDate()))
+                .le(ObjectUtil.isNotNull(query.getEndCreateDate()), GiftCard::getCreateTime, toEndDate(query.getEndCreateDate()))
+                .orderByDesc(GiftCard::getCreateTime)
+                .orderByDesc(GiftCard::getId);
+        return wrapper;
+    }
+
+    /**
+     * 填充购物卡实体
+     * @param entity
+     * @param dto
+     * @param publishStatus
+     */
+    private void fillGiftCard(GiftCard entity, GiftCardManageSaveDTO dto, Integer publishStatus) {
+        entity.setMerchantId(StrUtil.trim(dto.getMerchantId()));
+        entity.setName(StrUtil.trim(dto.getName()));
+        entity.setImageUrl(StrUtil.trim(dto.getImageUrl()));
+        entity.setAmount(dto.getAmount());
+        entity.setCommissionRate(dto.getCommissionRate());
+        entity.setStock(dto.getStock());
+        entity.setValidStartDate(dto.getValidStartDate());
+        entity.setValidEndDate(dto.getValidEndDate());
+        entity.setDescription(dto.getDescription());
+        entity.setIsPublished(publishStatus);
+    }
+
+    /**
+     * 规范化上架状态值
+     * @param value
+     * @param defaultValue
+     * @return Integer
+     */
+    private Integer normalizePublishStatus(Integer value, Integer defaultValue) {
+        if (ObjectUtil.isNull(value)) {
+            if (ObjectUtil.isNull(defaultValue)) {
+                throw new ServiceException("上架状态不能为空");
+            }
+            return defaultValue;
+        }
+        if (value == UNPUBLISHED || value == PUBLISHED) {
+            return value;
+        }
+        throw new ServiceException("上架状态值不正确");
+    }
+
+    private GiftCardManagePageVO toManagePageVO(GiftCard entity) {
+        GiftCardManagePageVO vo = new GiftCardManagePageVO();
+        BeanUtil.copyProperties(entity, vo);
+        return vo;
+    }
+
+    private GiftCardManageExportVO toManageExportVO(GiftCard entity) {
+        GiftCardManageExportVO vo = new GiftCardManageExportVO();
+        BeanUtil.copyProperties(entity, vo);
+        return vo;
+    }
+
+    private Date toStartDate(LocalDate date) {
+        if (ObjectUtil.isNull(date)) {
+            return null;
+        }
+        return Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
+    }
+
+    private Date toEndDate(LocalDate date) {
+        if (ObjectUtil.isNull(date)) {
+            return null;
+        }
+        return Date.from(date.plusDays(1).atStartOfDay(ZoneId.systemDefault()).minusNanos(1).toInstant());
+    }
+
 }

+ 21 - 1
nightFragrance-massage/src/main/resources/mapper/giftCard/GiftCardMapper.xml

@@ -4,4 +4,24 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ylx.giftCard.mapper.GiftCardMapper">
 
-</mapper>
+    <select id="selectManageList" resultType="com.ylx.giftCard.domain.GiftCard">
+        select *
+        from gift_card
+        <where>
+            is_delete = 0
+            <if test="dto != null and dto.name != null and dto.name != ''">
+                and name like concat('%', #{dto.name}, '%')
+            </if>
+            <if test="dto != null and dto.isPublished != null">
+                and is_published = #{dto.isPublished}
+            </if>
+            <if test="beginCreateTime != null">
+                and create_time &gt;= #{beginCreateTime}
+            </if>
+            <if test="endCreateTime != null">
+                and create_time &lt;= #{endCreateTime}
+            </if>
+        </where>
+        order by create_time desc
+    </select>
+</mapper>