ソースを参照

运费模板增加校验以及下单优惠加入全场

zhang 6 年 前
コミット
69b71572f7

+ 45 - 5
kmall-admin/src/main/java/com/kmall/admin/controller/FreightController.java

@@ -3,14 +3,13 @@ package com.kmall.admin.controller;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.collect.ImmutableBiMap;
 import com.kmall.admin.entity.FreightEntity;
+import com.kmall.admin.entity.FreightItemEntity;
 import com.kmall.admin.service.FreightService;
 import com.kmall.admin.utils.ParamUtils;
 import com.kmall.common.entity.SysUserEntity;
-import com.kmall.common.utils.PageUtils;
-import com.kmall.common.utils.Query;
-import com.kmall.common.utils.R;
-import com.kmall.common.utils.ShiroUtils;
+import com.kmall.common.utils.*;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -63,6 +62,27 @@ public class FreightController {
     @RequestMapping("/save")
     @RequiresPermissions("freight:save")
     public R save(@RequestBody FreightEntity freight) {
+
+        if (freight.getFreightItemEntityList() == null || freight.getFreightItemEntityList().size() == 0) {
+            throw new RRException("配送区域及运费不能为空");
+        }
+
+        for (FreightItemEntity freightItemEntity : freight.getFreightItemEntityList()) {
+            if (freightItemEntity != null) {
+                Map<String, Object> valideDate = MapBeanUtil.fromObject(freightItemEntity);
+                ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
+                builder.put("firstPiece", "首件");
+                builder.put("freight", "运费");
+                builder.put("continuePiece", "续件");
+                builder.put("renew", "续费");
+                R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
+                if (Integer.valueOf(r.get("code").toString()) != 0) {
+                    throw new RRException(r.get("msg").toString());
+                }
+            }
+        }
+
+
         freightService.save(freight);
 
         return R.ok();
@@ -74,6 +94,26 @@ public class FreightController {
     @RequestMapping("/update")
     @RequiresPermissions("freight:update")
     public R update(@RequestBody FreightEntity freight) {
+
+        if (freight.getFreightItemEntityList() == null || freight.getFreightItemEntityList().size() == 0) {
+            throw new RRException("配送区域及运费不能为空");
+        }
+
+        for (FreightItemEntity freightItemEntity : freight.getFreightItemEntityList()) {
+            if (freightItemEntity != null) {
+                Map<String, Object> valideDate = MapBeanUtil.fromObject(freightItemEntity);
+                ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
+                builder.put("firstPiece", "首件");
+                builder.put("freight", "运费");
+                builder.put("continuePiece", "续件");
+                builder.put("renew", "续费");
+                R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
+                if (Integer.valueOf(r.get("code").toString()) != 0) {
+                    throw new RRException(r.get("msg").toString());
+                }
+            }
+        }
+
         freightService.update(freight);
 
         return R.ok();
@@ -84,7 +124,7 @@ public class FreightController {
      */
     @RequestMapping("/delete")
     @RequiresPermissions("freight:delete")
-    public R delete(@RequestBody Integer[]ids) {
+    public R delete(@RequestBody Integer[] ids) {
         freightService.deleteBatch(ids);
 
         return R.ok();

+ 18 - 17
kmall-admin/src/main/java/com/kmall/admin/service/impl/FreightServiceImpl.java

@@ -28,7 +28,8 @@ import java.util.Map;
  * @date 2018-10-22 15:18:16
  */
 @Service("freightService")
-public class FreightServiceImpl implements FreightService {
+public class FreightServiceImpl
+        implements FreightService {
     @Autowired
     private FreightDao freightDao;
     @Autowired
@@ -82,9 +83,6 @@ public class FreightServiceImpl implements FreightService {
             throw new RRException(r.get("msg").toString());
         }
 
-        Integer id = freightDao.queryMaxId() + 1;
-        freight.setId(id);
-
         if (Boolean.valueOf(freight.getIsDefault())) {
             freight.setIsDefault("1");
         } else {
@@ -93,20 +91,23 @@ public class FreightServiceImpl implements FreightService {
 
         // 运费详情
         List<FreightItemEntity> freightItemEntityList = freight.getFreightItemEntityList();
-        if (null != freightItemEntityList && freightItemEntityList.size() > 0) {
-            freight.setDefaultFreight(freightItemEntityList.get(0).getFreight());
-            for (FreightItemEntity item : freightItemEntityList) {
-                if (Boolean.valueOf(item.getDeliveryArea())) {
-                    item.setDeliveryArea("ALL");
-                }
-                if (item.getFreId() == null) {
-                    item.setFreId(id);
-                    freightItemDao.save(item);
-                }
-            }
+        if (freight.getFreightItemEntityList() == null || freight.getFreightItemEntityList().size() == 0) {
+            throw new RRException("配送区域及运费不能为空");
         }
 
-        return freightDao.save(freight);
+        freight.setDefaultFreight(freightItemEntityList.get(0).getFreight());
+        int res = freightDao.save(freight);
+
+        for (FreightItemEntity item : freightItemEntityList) {
+            if (Boolean.valueOf(item.getDeliveryArea())) {
+                item.setDeliveryArea("ALL");
+            }
+            if (item.getFreId() == null) {
+                item.setFreId(freight.getId());
+                freightItemDao.save(item);
+            }
+        }
+        return res;
     }
 
     @Override
@@ -173,7 +174,7 @@ public class FreightServiceImpl implements FreightService {
     }
 
     @Override
-    public int deleteBatch(Integer[]ids) {
+    public int deleteBatch(Integer[] ids) {
         for (int id : ids) {
             Map<String, Object> map = new HashMap<>();
             map.put("freightId", id);

+ 2 - 2
kmall-admin/src/main/resources/mybatis/mapper/CouponDao.xml

@@ -27,10 +27,10 @@
                 AND a.name LIKE concat('%',#{name},'%')
             </if>
             <if test="storeId != null and storeId != ''">
-                AND store_id = #{storeId}
+                AND (a.store_id = #{storeId} OR a.is_all = 1)
             </if>
             <if test="merchSn != null and merchSn.trim() != ''">
-                AND merch_sn = #{merchSn}
+                AND (a.merch_sn = #{merchSn} OR a.is_all = 1)
             </if>
         </where>
     </sql>