h 1 settimana fa
parent
commit
4580be3811

+ 6 - 0
src/main/java/com/zhentao/common/constant/BestConstants.java

@@ -12,6 +12,9 @@ public class BestConstants {
     public static final int MAX_QUERY_SIZE = 10;
     public static final int MIN_QUERY_CURRENT = 1;
     public static final String OVER_QUERY_SIZE = "超出最大查询长度";
+    public static final String ADDITION_WAS_SUCCESSFUL = "添加成功";
+    public static final String HIDE_WAS_SUCCESSFUL = "隐藏成功";
+    public static final Integer HIDE_FLAG = 0;
     //销售规格
     public static final Integer ITEM_TYPE_SPECIFICATIONS = 1;
     //基础属性
@@ -23,6 +26,7 @@ public class BestConstants {
     public static final String BTB_TEAMBUY = "btb_teambuy";
     public static final String BTB_CONFIG_FOOTER = "btb_config_footer";
     public static final String BTB_MINI_CONFIG = "btb_mini_config";
+    public static final String HIDE_FAILED_MSG = "隐藏失败的消息";
 
     public static final String GOODS_NOT_FOUND = "商品已下架!";
     public static final String TB_GOODS_NOT_FOUND = "团购商品不存在!";
@@ -199,6 +203,8 @@ public class BestConstants {
     public static final Long SAN_XIANG_BANK_ID = 443611075020201984L;
     public static final Integer USER_NOT_PHONE_CODE = 110;
     public static final String USER_NOT_PHONE_MSG = "请先绑定手机号!";
+    public static final String DELETE_SUCCESS_MSG = "删除成功";
+    public static final String DELETE_FAILED_MSG = "删除失败";
 
     //企业价
     public static final Integer priceTypeEnterAdd=1;

+ 38 - 0
src/main/java/com/zhentao/controller/CouponController.java

@@ -6,6 +6,7 @@ import com.zhentao.service.CouponService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
@@ -13,8 +14,45 @@ import org.springframework.web.bind.annotation.RestController;
 public class CouponController {
     @Autowired
     CouponService couponService;
+
+    /**
+     * 优惠券添加
+     * @param couponDto
+     * @return
+     */
     @RequestMapping("add")
     public R add(@RequestBody CouponDto couponDto){
         return couponService.add(couponDto);
     }
+
+    /**
+     * 隐藏优惠券
+     * @param couponId
+     * @return
+     */
+
+    @RequestMapping("hide")
+    public R hide(@RequestParam("couponId") Long couponId){
+        return couponService.hide(couponId);
+    }
+
+    /**
+     * 删除优惠券
+     * @param couponId
+     * @return
+     */
+    @RequestMapping("del")
+    public R del(Long couponId){
+        return couponService.delCoupon(couponId);
+    }
+
+    /**
+     * 查询全部优惠券
+     * @param couponId
+     * @return
+     */
+    @RequestMapping("sel")
+    public R sel(Long couponId){
+        return couponService.delCoupon(couponId);
+    }
 }

+ 14 - 0
src/main/java/com/zhentao/controller/CouponUserController.java

@@ -0,0 +1,14 @@
+package com.zhentao.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("couponUser")
+public class CouponUserController {
+    @RequestMapping("add")
+    public String add() {
+
+        return "couponUser";
+    }
+}

+ 11 - 2
src/main/java/com/zhentao/dto/CouponDto.java

@@ -8,9 +8,14 @@ import java.util.Date;
 @Data
 public class CouponDto {
 
+    /**
+     *
+     */
+    @TableId
+    private Long id;
 
     /**
-     * 优惠券类型1满减券2满折券,
+     * 优惠券类型1满减券2满折券
      */
     private Integer tacticsType;
 
@@ -99,10 +104,14 @@ public class CouponDto {
      */
     private Integer totalNum;
 
-
     /**
      * 排序
      */
     private Integer sort;
 
+    /**
+     * 店铺id
+     */
+    private Long shopId;
+
 }

+ 1 - 1
src/main/java/com/zhentao/mapper/CouponMapper.java

@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 /**
 * @author H
 * @description 针对表【coupon(营销优惠券)】的数据库操作Mapper
-* @createDate 2025-05-08 16:51:42
+* @createDate 2025-05-12 09:47:05
 * @Entity com.zhentao.pojo.Coupon
 */
 public interface CouponMapper extends BaseMapper<Coupon> {

+ 11 - 5
src/main/java/com/zhentao/pojo/Coupon.java

@@ -1,7 +1,9 @@
 package com.zhentao.pojo;
 
-import com.baomidou.mybatisplus.annotation.*;
-
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
@@ -15,7 +17,7 @@ import lombok.Data;
 @Data
 public class Coupon implements Serializable {
     /**
-     *
+     * 
      */
     @TableId
     private Long id;
@@ -123,7 +125,6 @@ public class Coupon implements Serializable {
     /**
      * 版本
      */
-    @Version
     private Integer reversion;
 
     /**
@@ -141,6 +142,11 @@ public class Coupon implements Serializable {
      */
     private Integer delFlag;
 
+    /**
+     * 店铺id
+     */
+    private Long shopId;
+
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
-}
+}

+ 4 - 0
src/main/java/com/zhentao/service/CouponService.java

@@ -13,4 +13,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface CouponService extends IService<Coupon> {
 
     R add(CouponDto couponDto);
+
+    R hide(Long couponId);
+
+    R delCoupon(Long couponId);
 }

+ 40 - 3
src/main/java/com/zhentao/service/impl/CouponServiceImpl.java

@@ -1,6 +1,7 @@
 package com.zhentao.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.api.IErrorCode;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -30,18 +31,54 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon>
         if (couponDto==null || StringUtils.checkValNull(couponDto.getTacticsType())
                 || StringUtils.checkValNull(couponDto.getName())
                 || StringUtils.checkValNull(couponDto.getGetWay())
+                || StringUtils.checkValNull(couponDto.getFaceValue())
                 || StringUtils.checkValNull(couponDto.getProductType())
                 || StringUtils.checkValNull(couponDto.getLimitMinFlag())
+                || StringUtils.checkValNull(couponDto.getImgUrl())
                 || StringUtils.checkValNull(couponDto.getValidFlag())
                 || StringUtils.checkValNull(couponDto.getGetTimeLimit())
+                || StringUtils.checkValNull(couponDto.getShopId())
                 || StringUtils.checkValNull(couponDto.getTotalLimit())) {
             throw new RRException(BestConstants.PARAMS_ERROR_MSG);
         }else {
             Coupon coupon=new Coupon();
             BeanUtil.copyProperties(couponDto,coupon);
-            coupon.setCreateddTime(new Date());
-            boolean save = this.save(coupon);
-            return null;
+            if (coupon.getId()==null){
+                coupon.setCreateddTime(new Date());
+                this.save(coupon);
+            }else {
+                coupon.setUpdatedTime(new Date());
+                this.updateById(coupon);
+            }
+            return R.ok(BestConstants.ADDITION_WAS_SUCCESSFUL);
+        }
+    }
+
+    @Override
+    public R hide(Long couponId) {
+        if (couponId==null) {
+            throw new RRException(BestConstants.PARAMS_ERROR_MSG);
+        }else {
+            Coupon coupon=this.getById(couponId);
+            if (coupon==null) {
+                throw new RRException(BestConstants.COUPON_NOT_FOUND_MSG);
+            }else {
+                coupon.setStatus(BestConstants.HIDE_FLAG);
+                this.updateById(coupon);
+                return R.ok(BestConstants.HIDE_WAS_SUCCESSFUL);
+            }
+        }
+    }
+
+    @Override
+    public R delCoupon(Long couponId) {
+        if (couponId==null){
+            throw new RRException(BestConstants.PARAMS_ERROR_MSG);
+        }
+        if (this.removeById(couponId)){
+            return R.ok(BestConstants.DELETE_SUCCESS_MSG);
+        }else {
+            throw new RRException(BestConstants.DELETE_FAILED_MSG);
         }
     }
 }

+ 2 - 2
src/main/resources/application.yml

@@ -2,8 +2,8 @@ server:
   port: 8780
 spring:
   datasource:
-    driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://47.95.39.95:3306/xm3?useSSL=false&serverTimezone=UTC
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://47.95.39.95:3306/xm3?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
     username: root
     password: 123456
   redis:

+ 2 - 1
src/main/resources/mapper/CouponMapper.xml

@@ -30,6 +30,7 @@
             <result property="createddTime" column="createdd_time" jdbcType="TIMESTAMP"/>
             <result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
             <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
+            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
     </resultMap>
 
     <sql id="Base_Column_List">
@@ -41,6 +42,6 @@
         get_start_time,get_end_time,total_limit,
         total_num,status,sort,
         reversion,createdd_time,updated_time,
-        del_flag
+        del_flag,shop_id
     </sql>
 </mapper>