Browse Source

优惠设置限制

LuoDLeo 2 months ago
parent
commit
7add0d8a69

+ 5 - 3
src/main/java/org/springblade/modules/api/controller/ApiFacilityCargoWayController.java

@@ -2,7 +2,6 @@ package org.springblade.modules.api.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.lang.Assert;
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
@@ -12,7 +11,6 @@ import lombok.AllArgsConstructor;
 import org.springblade.common.base.BaseEntity;
 import org.springblade.common.constant.CommonConstant;
 import org.springblade.core.mp.support.Condition;
-import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.modules.business.entity.FacilityCargoWay;
 import org.springblade.modules.business.service.IFacilityCargoWayService;
@@ -23,6 +21,7 @@ import org.springblade.modules.mall.service.IGoodsInfoService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -75,12 +74,15 @@ public class ApiFacilityCargoWayController {
     }
 
     @PostMapping("/discount/setting")
-    @ApiOperationSupport(order =3 )
+    @ApiOperationSupport(order = 3)
     @ApiOperation(value = "批量设置折扣", notes = "传入facilityCargoWay")
     public R<Void> discountSetting(@RequestBody FacilityCargoWayVO facilityCargoWay) {
         List<FacilityCargoWay> list = iFacilityCargoWayService.list(Wrappers.lambdaQuery(FacilityCargoWay.class)
                 .in(BaseEntity::getId, facilityCargoWay.getCargoWayIds()));
         for (FacilityCargoWay cargoWay : list) {
+            if (cargoWay.getSalePrice().compareTo(BigDecimal.valueOf(facilityCargoWay.getDiscount())) < 0) {
+                return R.fail("商品优惠不能高于商品售价");
+            }
             cargoWay.setDiscount(facilityCargoWay.getDiscount());
         }
         return R.status(iFacilityCargoWayService.updateBatchById(list));