Browse Source

超级会员优惠券状态新增重复月份处理

chao 3 years ago
parent
commit
00766cc5af

+ 5 - 4
src/main/java/com/caimei/modules/coupon/dao/CmCouponVipDao.java

@@ -24,10 +24,11 @@ public interface CmCouponVipDao extends CrudDao<CmVipCoupon> {
     void deleteByMonthId(String montId);
     List<CmCoupon> getCouponListByIds(@Param("bindCoupons") List<String> bindCoupons,@Param("couponType") String couponType,@Param("status") String status);
     /**
-     * 查供应商名称
-     *
-     * @param shopId
-     * @return
+     * 查供应商
      */
     NewCmShop getShopInfoByShopId(Integer shopId);
+    /**
+     * 获取所有优惠月份
+     */
+    List<String> getAllUseDateList();
 }

+ 6 - 0
src/main/java/com/caimei/modules/coupon/service/CmVipCouponService.java

@@ -238,6 +238,7 @@ public class CmVipCouponService extends CrudService<CmCouponVipDao, CmVipCoupon>
             coupon4.setId(svipcouponForm.getCouponId4());
             cmCouponVipDao.updateVipCouponMonth(cmVipCoupon);
         } else {
+            // 新增
             flag = true;
             cmCouponVipDao.insertVipCouponMonth(cmVipCoupon);
         }
@@ -417,4 +418,9 @@ public class CmVipCouponService extends CrudService<CmCouponVipDao, CmVipCoupon>
         }
         cmCouponVipDao.updateVipCouponMonth(cmVipCoupon);
     }
+
+
+    public List<String> getAllUseDateList(){
+        return cmCouponVipDao.getAllUseDateList();
+    };
 }

+ 12 - 2
src/main/java/com/caimei/modules/coupon/web/CmVipCouponController.java

@@ -18,6 +18,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.text.ParseException;
+import java.util.List;
 
 /**
  * @author zzj
@@ -54,6 +55,8 @@ public class CmVipCouponController extends BaseController {
         model.addAttribute("cmVipCoupon", cmVipCoupon);
         // 设置4张券的表单
         SvipCouponForm svipcouponForm = cmVipCouponService.setSvipcouponForms(cmVipCoupon);
+        List<String> useDateList = cmVipCouponService.getAllUseDateList();
+        model.addAttribute("useDateList", useDateList);
         model.addAttribute("svipcouponForm", svipcouponForm);
         return "modules/svip/cmSvipCouponForm";
     }
@@ -65,13 +68,20 @@ public class CmVipCouponController extends BaseController {
      */
     @RequestMapping(value = "save")
     public String save(SvipCouponForm svipcouponForm, Model model, RedirectAttributes redirectAttributes) throws ParseException {
-        cmVipCouponService.saveVipCoupon(svipcouponForm);
         if (StringUtils.isNotBlank(svipcouponForm.getId())) {
             // 修改
+            cmVipCouponService.saveVipCoupon(svipcouponForm);
             addMessage(redirectAttributes, "修改超级会员专属优惠券成功");
         } else {
             // 新增
-            addMessage(redirectAttributes, "新增超级会员专属优惠券成功");
+            List<String> useDateList = cmVipCouponService.getAllUseDateList();
+            if (useDateList.contains(svipcouponForm.getMonth())) {
+                //不能新增,这个月已经有了
+                addMessage(redirectAttributes, "已存在该月优惠券,请修改月份或重新添加!");
+            } else {
+                cmVipCouponService.saveVipCoupon(svipcouponForm);
+                addMessage(redirectAttributes, "新增超级会员专属优惠券成功");
+            }
         }
         return "redirect:" + Global.getAdminPath() + "/vip/cmCoupon/?repage";
     }

+ 3 - 0
src/main/resources/mappings/modules/super/CmCouponVipMapper.xml

@@ -113,4 +113,7 @@
         WHERE s.shopID = #{shopId}
         LIMIT 1
     </select>
+    <select id="getAllUseDateList" resultType="java.lang.String">
+        SELECT DISTINCT useTime FROM cm_svip_coupon_month WHERE delFlag='0'
+    </select>
 </mapper>

+ 125 - 112
src/main/webapp/WEB-INF/views/modules/svip/cmSvipCouponForm.jsp

@@ -5,16 +5,132 @@
 <head>
     <title>优惠券管理</title>
     <meta name="decorator" content="default"/>
-    <style>
-        .coupon-wrap {
-            border: 1px solid #aaa;
-            padding: 20px 20px 0;
-            margin-bottom: 20px;
-        }
-        .couponType {
-            margin-right: 15px;
+<style>
+    .coupon-wrap {
+        border: 1px solid #aaa;
+        padding: 20px 20px 0;
+        margin-bottom: 20px;
+    }
+    .couponType {
+        margin-right: 15px;
+    }
+</style>
+<script type="text/javascript">
+    $(document).ready(function () {
+        var dateList = [];
+        if (${not empty useDateList}) {
+            <c:forEach items="${useDateList}" var="date" varStatus="index">
+            dateList.push("${date}");
+            </c:forEach>
         }
-    </style>
+        $("#inputForm").validate({
+            submitHandler: function (form) {
+                if (imageList1.length > 0) {
+                    var productInfo1 = JSON.stringify(imageList1);
+                    $('#productInfo1').val(productInfo1);
+                }
+                if (imageList2.length > 0) {
+                    var productInfo2 = JSON.stringify(imageList2);
+                    $('#productInfo2').val(productInfo2);
+                }
+                if (imageList3.length > 0) {
+                    var productInfo3 = JSON.stringify(imageList3);
+                    $('#productInfo3').val(productInfo3);
+                }
+                if (imageList4.length > 0) {
+                    var productInfo4 = JSON.stringify(imageList4);
+                    $('#productInfo4').val(productInfo4);
+                }
+                var couponType1 = $("#couponType1").val();
+                var shopId1 = $("#shopId1").val();
+                if (couponType1 == 3) {
+                    if (shopId1 == "" || shopId1 == null) {
+                        alert("店铺券供应商不能为空 !");
+                        return false;
+                    }
+                }
+                var month = $("#month").val();
+                // 判断月份 ...
+                if (month == null || month == "") {
+                    alert("请选择生效时间! ");
+                    return false;
+                }
+                var vipId = $("#id").val();
+                if (!vipId && dateList.indexOf(month)>=0){
+                    alert("已存在该月优惠券,请修改月份!");
+                    return false;
+                }
+                var couponAmount1 = $("#couponAmount1").val() * 1;
+                var touchPrice1 = $("#touchPrice1").val() * 1;
+                if (couponAmount1 == "") {
+                    alertx("【优惠券1】优惠券金额不能为空");
+                    return false;
+                }
+                if (touchPrice1 == "") {
+                    alertx("【优惠券1】优惠条件不能为空");
+                    return false;
+                }
+                if (couponAmount1 >= touchPrice1) {
+                    alertx("【优惠券1】优惠券金额必须小于优惠条件金额");
+                    return false;
+                }
+                var couponAmount2 = $("#couponAmount2").val() * 1;
+                var touchPrice2 = $("#touchPrice2").val() * 1;
+                if (couponAmount2 == "") {
+                    alertx("【优惠券2】优惠券金额不能为空");
+                    return false;
+                }
+                if (touchPrice2 == "") {
+                    alertx("【优惠券2】优惠条件不能为空");
+                    return false;
+                }
+                if (couponAmount2 >= touchPrice2) {
+                    alertx("【优惠券2】优惠券金额必须小于优惠条件金额");
+                    return false;
+                }
+                var couponAmount3 = $("#couponAmount3").val() * 1;
+                var touchPrice3 = $("#touchPrice3").val() * 1;
+                if (couponAmount3 == "") {
+                    alertx("【优惠券3】优惠券金额不能为空");
+                    return false;
+                }
+                if (touchPrice3 == "") {
+                    alertx("【优惠券3】优惠条件不能为空");
+                    return false;
+                }
+                if (couponAmount3 >= touchPrice3) {
+                    alertx("【优惠券3】优惠券金额必须小于优惠条件金额");
+                    return false;
+                }
+                var couponAmount4 = $("#couponAmount4").val() * 1;
+                var touchPrice4 = $("#touchPrice4").val() * 1;
+                if (couponAmount4 == "") {
+                    alertx("【优惠券4】优惠券金额不能为空");
+                    return false;
+                }
+                if (touchPrice4 == "") {
+                    alertx("【优惠券4】优惠条件不能为空");
+                    return false;
+                }
+                if (couponAmount4 >= touchPrice4) {
+                    alertx("【优惠券4】优惠券金额必须小于优惠条件金额");
+                    return false;
+                }
+                loading('正在提交,请稍等...');
+                form.submit();
+            },
+            errorContainer: "#messageBox",
+            errorPlacement: function (error, element) {
+                $("#messageBox").text("输入有误,请先更正。");
+                if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
+                    error.appendTo(element.parent().parent());
+                } else {
+                    error.insertAfter(element);
+                }
+            }
+        });
+    });
+</script>
 </head>
 <body>
 <ul class="nav nav-tabs">
@@ -865,109 +981,6 @@
         obj.value = obj.value.replace(/[^\d]/g, ""); //清除"数字"以外的字符
     }
 
-    $(document).ready(function () {
-        $("#inputForm").validate({
-            submitHandler: function (form) {
-                if (imageList1.length > 0) {
-                    var productInfo1 = JSON.stringify(imageList1);
-                    $('#productInfo1').val(productInfo1);
-                }
-                if (imageList2.length > 0) {
-                    var productInfo2 = JSON.stringify(imageList2);
-                    $('#productInfo2').val(productInfo2);
-                }
-                if (imageList3.length > 0) {
-                    var productInfo3 = JSON.stringify(imageList3);
-                    $('#productInfo3').val(productInfo3);
-                }
-                if (imageList4.length > 0) {
-                    var productInfo4 = JSON.stringify(imageList4);
-                    $('#productInfo4').val(productInfo4);
-                }
-                var couponType1 = $("#couponType1").val();
-                var shopId1 = $("#shopId1").val();
-                if (couponType1 == 3) {
-                    if (shopId1 == "" || shopId1 == null) {
-                        alert("店铺券供应商不能为空 !");
-                        return false;
-                    }
-                }
-                var month = $("#month").val();
-                // 判断月份 ...
-                if (month == null || month == "") {
-                    alert("请选择生效时间! ");
-                    return false;
-                }
-                var couponAmount1 = $("#couponAmount1").val() * 1;
-                var touchPrice1 = $("#touchPrice1").val() * 1;
-                if (couponAmount1 == "") {
-                    alertx("【优惠券1】优惠券金额不能为空");
-                    return false;
-                }
-                if (touchPrice1 == "") {
-                    alertx("【优惠券1】优惠条件不能为空");
-                    return false;
-                }
-                if (couponAmount1 >= touchPrice1) {
-                    alertx("【优惠券1】优惠券金额必须小于优惠条件金额");
-                    return false;
-                }
-                var couponAmount2 = $("#couponAmount2").val() * 1;
-                var touchPrice2 = $("#touchPrice2").val() * 1;
-                if (couponAmount2 == "") {
-                    alertx("【优惠券2】优惠券金额不能为空");
-                    return false;
-                }
-                if (touchPrice2 == "") {
-                    alertx("【优惠券2】优惠条件不能为空");
-                    return false;
-                }
-                if (couponAmount2 >= touchPrice2) {
-                    alertx("【优惠券2】优惠券金额必须小于优惠条件金额");
-                    return false;
-                }
-                var couponAmount3 = $("#couponAmount3").val() * 1;
-                var touchPrice3 = $("#touchPrice3").val() * 1;
-                if (couponAmount3 == "") {
-                    alertx("【优惠券3】优惠券金额不能为空");
-                    return false;
-                }
-                if (touchPrice3 == "") {
-                    alertx("【优惠券3】优惠条件不能为空");
-                    return false;
-                }
-                if (couponAmount3 >= touchPrice3) {
-                    alertx("【优惠券3】优惠券金额必须小于优惠条件金额");
-                    return false;
-                }
-                var couponAmount4 = $("#couponAmount4").val() * 1;
-                var touchPrice4 = $("#touchPrice4").val() * 1;
-                if (couponAmount4 == "") {
-                    alertx("【优惠券4】优惠券金额不能为空");
-                    return false;
-                }
-                if (touchPrice4 == "") {
-                    alertx("【优惠券4】优惠条件不能为空");
-                    return false;
-                }
-                if (couponAmount4 >= touchPrice4) {
-                    alertx("【优惠券4】优惠券金额必须小于优惠条件金额");
-                    return false;
-                }
-                loading('正在提交,请稍等...');
-                form.submit();
-            },
-            errorContainer: "#messageBox",
-            errorPlacement: function (error, element) {
-                $("#messageBox").text("输入有误,请先更正。");
-                if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
-                    error.appendTo(element.parent().parent());
-                } else {
-                    error.insertAfter(element);
-                }
-            }
-        });
-    });
 </script>
 </body>
 </html>