Selaa lähdekoodia

添加购买优惠券的功能

lighter 1 vuosi sitten
vanhempi
commit
e14fadcc88

+ 20 - 0
src/main/java/thyyxxk/webserver/controller/outpatient/coupon/CouponManageController.java

@@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.*;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.login.UserInfo;
+import thyyxxk.webserver.entity.outpatient.coupon.CouponGainWay;
 import thyyxxk.webserver.entity.outpatient.coupon.ZdCoupon;
 import thyyxxk.webserver.service.outpatient.coupon.CouponManageService;
 import thyyxxk.webserver.utils.ResultVoUtil;
@@ -39,6 +40,12 @@ public class CouponManageController {
                         "总量不能小于余量!");
             }
         }
+        if (coupon.getGainWay() == CouponGainWay.PURCHASE) {
+            if (coupon.getPrice() <= 0) {
+                return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "优惠券单价必须大于0");
+            }
+            coupon.setEffectiveDays(365 * 100);
+        }
         String response = service.updateCouponState(coupon);
         return ResultVoUtil.success(response);
     }
@@ -62,6 +69,18 @@ public class CouponManageController {
                 StringUtil.isBlank(coupon.getDescription())) {
             return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "优惠券描述不能为空。");
         }
+        if (null == coupon.getGainWay()) {
+            return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "优惠券获取方式不能为空。");
+        }
+        if (null == coupon.getPrice()) {
+            coupon.setPrice(0);
+        }
+        if (coupon.getGainWay() == CouponGainWay.PURCHASE) {
+            if (coupon.getPrice() <= 0) {
+                return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "优惠券单价必须大于0");
+            }
+            coupon.setEffectiveDays(365 * 100);
+        }
         if (null == coupon.getValue()) {
             return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "优惠券金额不能为空。");
         }
@@ -74,6 +93,7 @@ public class CouponManageController {
         if (null == coupon.getType()) {
             return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "优惠券下发方式不能为空。");
         }
+
         String response = service.insertNewCoupon(coupon);
         if (response.equals("SUCCESS")) {
             return ResultVoUtil.success("新增优惠券成功。");

+ 6 - 0
src/main/java/thyyxxk/webserver/entity/outpatient/coupon/CouponGainWay.java

@@ -0,0 +1,6 @@
+package thyyxxk.webserver.entity.outpatient.coupon;
+
+public enum CouponGainWay {
+    FREE,
+    PURCHASE,
+}

+ 2 - 0
src/main/java/thyyxxk/webserver/entity/outpatient/coupon/ZdCoupon.java

@@ -22,6 +22,8 @@ public class ZdCoupon {
     private String createStaff;
     private CouponState state;
     private CouponType type;
+    private CouponGainWay gainWay;
+    private Integer price;
     private String description;
     private String availableCharge;
     private String availableChargeName;