From dfb7c31b6591f9bb53182b3023f0be1d496a7d1a Mon Sep 17 00:00:00 2001
From: lisy <linlangsur163@163.com>
Date: 星期一, 14 八月 2023 13:54:32 +0800
Subject: [PATCH] 管理后台:添加优惠券和积分商品的优化

---
 cloud-server-management/src/main/java/com/dsh/guns/modular/system/model/CouponDataVo.java |    6 +-
 cloud-server-management/src/main/webapp/WEB-INF/view/system/tCoupon/TCouponAdd.html       |    6 +-
 cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java        |   19 ------
 cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js      |  130 +++++++++++++++++++++++++++++++++---------
 cloud-server-management/src/main/webapp/static/modular/system/tGoods/tGoods_info.js       |    2 
 5 files changed, 108 insertions(+), 55 deletions(-)

diff --git a/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java b/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java
index 0dc7c54..eb205d6 100644
--- a/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java
+++ b/cloud-server-course/src/main/java/com/dsh/config/Sharding_jdbc/ShardingConfig.java
@@ -104,14 +104,6 @@
 
         linkedList.add(result1);
 
-        //分片规则配置
-        result1.getTables().add(getCoursePackageSchedulingTableRuleConfiguration());
-        Properties props5 = new Properties();
-        props5.setProperty("algorithm-expression", "t_course_package_scheduling$->{coursePackageId % 5 + 1}");
-        result1.getShardingAlgorithms().put("t_course_package_scheduling-inline", new AlgorithmConfiguration("INLINE", props5));
-        result1.getKeyGenerators().put("t_course_package_scheduling-snowflake", new AlgorithmConfiguration("SNOWFLAKE", new Properties()));
-        linkedList.add(result1);
-
         return linkedList;
     }
 
@@ -139,17 +131,6 @@
         return result;
     }
 
-
-    /**
-     * 分片算法配置
-     * @return
-     */
-    private ShardingTableRuleConfiguration getCoursePackageSchedulingTableRuleConfiguration() {
-        ShardingTableRuleConfiguration result = new ShardingTableRuleConfiguration("t_course_package_scheduling", "m_$->{0}.t_course_package_scheduling$->{1..5}");//30
-        result.setTableShardingStrategy(new StandardShardingStrategyConfiguration("coursePackageId", "t_course_package_scheduling-inline"));
-        result.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "t_course_package_scheduling-snowflake"));
-        return result;
-    }
 
 
 
diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/model/CouponDataVo.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/model/CouponDataVo.java
index f84643c..c0fc2f8 100644
--- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/model/CouponDataVo.java
+++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/model/CouponDataVo.java
@@ -83,7 +83,7 @@
     /**
      * 图片列表
      */
-    List<String> goodImgs;
+    String goodImgs;
     /**
      * 适用范围
      */
@@ -91,9 +91,9 @@
     /**
      * 城市code
      */
-    List<Integer> cityIds;
+    String cityIds;
     /**
      * 门店列表
      */
-    List<Integer> storeIds;
+    String storeIds;
 }
diff --git a/cloud-server-management/src/main/webapp/WEB-INF/view/system/tCoupon/TCouponAdd.html b/cloud-server-management/src/main/webapp/WEB-INF/view/system/tCoupon/TCouponAdd.html
index 5cd9c43..f1172fc 100644
--- a/cloud-server-management/src/main/webapp/WEB-INF/view/system/tCoupon/TCouponAdd.html
+++ b/cloud-server-management/src/main/webapp/WEB-INF/view/system/tCoupon/TCouponAdd.html
@@ -270,17 +270,17 @@
                             <label class="col-sm-3">*适用范围: </label>
                             <div class="col-sm-3" id="belongsNationwide" hidden="hidden">
                                 <input class="col-sm-1" onclick="scopeOfApplication1()" name="company" type="radio"
-                                       value="0" checked style="margin-top: 10px"/>
+                                       value="1" checked style="margin-top: 10px"/>
                                 <label class="col-sm-2" style="width: 68%;margin-top: 7px">全国通用</label>
                             </div>
                             <div class="col-sm-3" id="belongsCity"  hidden="hidden">
                                 <input class="col-sm-1" name="company" onclick="scopeOfApplication2()" type="radio"
-                                       value="1"  style="margin-top: 10px"/>
+                                       value="2"  style="margin-top: 10px"/>
                                 <label class="col-sm-2" style="width: 64%;margin-top: 7px">指定城市</label>
                             </div>
                             <div class="col-sm-3" id="belongsStore"  hidden="hidden">
                                 <input class="col-sm-1" name="company" onclick="scopeOfApplication3()" type="radio"
-                                       value="1" style="margin-left: 4%;margin-top: 10px;width: 13px;height: 13px"/>
+                                       value="3" style="margin-left: 4%;margin-top: 10px;width: 13px;height: 13px"/>
                                 <label class="col-sm-2" style="width: 64%;margin-top: 6px;">指定门店</label>
                             </div>
                         </div>
diff --git a/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js b/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js
index ee79454..01e5dd4 100644
--- a/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js
+++ b/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js
@@ -80,6 +80,9 @@
 function scopeOfApplication1() {
     $("#storeSelect").hide();
     $("#citySelect").hide();
+
+    num = 0;
+
 }
 /**
  * 指定城市
@@ -213,9 +216,9 @@
 }
 
 
-var num = 0;
+let num = 0;
 couponInfoDlg.addBranch = function () {
-    num=num+1;
+    num = num+1;
     var a= "";
     a = "<div style=\'margin-left: 25%\' class=\"col-sm-9 control-label\">\n" +
         "                            <select class=\"col-sm-1\"  id=\'provinceData"+num+"\' style=\"margin-top: 1%;width: 25%\" onchange=\'changeCity("+num+")\'>\n" +
@@ -253,22 +256,17 @@
                 '<td><input type="hidden" id="id" name="id" value="'+arrays[i].id+'"><input type="hidden" id="provinceCity" name="provinceCity" value="'+arrays[i].provinceCity+'">' + arrays[i].provinceCity + '</td>' +
                 '<td><input type="hidden" id="accountName" name="accountName" value="'+arrays[i].accountName+'">' + arrays[i].accountName + '</td>' +
                 '<td><input type="hidden" id="name" name="name" value="'+arrays[i].name+'">' + arrays[i].name + '</td><td><button onclick="deleteSub(this)">移除</button></td></tr>';
+            this.storeIds.push(arrays[i].id);
         }
     }
     $("#coun").append(str);
-    console.log('storeIds',this.storeIds)
 }
 
 function deleteSub(e) {
-    console.log(e);
     var row = $(e).closest('tr');
-    var idValue = row.find('#id').val();
-    var index = this.storeIds.indexOf(idValue.toString());
-    if (index !== -1) {
-        this.storeIds.splice(index, 1);
-    }
+    var value = row.find('#id').val();
+    couponInfoDlg.storeIds.splice(couponInfoDlg.storeIds.indexOf(parseInt(value)), 1)
     $(e).parent().parent().remove();
-    console.log('storeIds',this.storeIds)
 }
 
 
@@ -284,29 +282,97 @@
     var cityIds = [];
     // 优惠券名称
     var couponName = $('#name').val();
+    if (couponName === undefined || couponName === '' || couponName === null){
+        return Feng.error('优惠券名称不能为空');
+    }
     // 优惠券类型
-    var prescription = $('#prescription').val();
+    let prescription = $(":radio[name='prescription']:checked").val();
+    // 满xx金额
+    let conditionalAmount = $('#conditionalAmount').val();
+    // 减xx金额
+    let deductionAmount = $('#deductionAmount').val();
+    // 可抵扣xx金额
+    let voucherAmount = $('#voucherAmount').val();
+    // 体验券名称
+    let experienceName = $('#experienceName').val();
+    if (prescription === '1'){
+        if (conditionalAmount === undefined || conditionalAmount === '' || conditionalAmount === null){
+            return Feng.error('条件金额不能为空');
+        }
+        if (deductionAmount === undefined || deductionAmount === '' || deductionAmount === null){
+            return Feng.error('减扣金额不能为空');
+        }
+    }
+    if (prescription === '2'){
+        if (voucherAmount === undefined || voucherAmount === '' || voucherAmount === null){
+            return Feng.error('抵扣金额不能为空');
+        }
+    }
+    if (prescription === '3'){
+        if (experienceName === undefined || experienceName === '' || experienceName === null){
+            return Feng.error('体验券名称不能为空');
+        }
+    }
+
+
     // 说明
     var illustrate = $('#illustrate').val();
+    if (illustrate === undefined || illustrate === '' || illustrate === null){
+        return Feng.error('优惠券说明不能为空');
+    }
     // 发放方式
-    var distributionMethod = $('#distributionMethod').val();
+    let distributionMethod = $(":radio[name='distributionMethod']:checked").val();
+    if (distributionMethod === undefined || distributionMethod === '' || distributionMethod === null){
+        return Feng.error('发放方式不能为空');
+    }
     // 所需积分
     var requiredPoints = $('#requiredPoints').val();
+    // 所需现金
+    var requiredCash = $('#requiredCash').val();
     // 用户人群
     let userGroup = $(':radio[name="userGroup"]:checked').val();
 
     // 发放数量
     var quantityIssued = $('#quantityIssued').val();
+    if (quantityIssued === undefined || quantityIssued === '' || quantityIssued === null){
+        return Feng.error('发放数量不能为空');
+    }
     // 限领数量
     var pickUpQuantity = $('#pickUpQuantity').val();
+    if (pickUpQuantity === undefined || pickUpQuantity === '' || pickUpQuantity === null){
+        return Feng.error('限领数量不能为空');
+    }
     // 有效期
     var periodOfValidity = $('#periodOfValidity').val();
-
+    if (periodOfValidity === undefined || periodOfValidity === '' || periodOfValidity === null){
+        return Feng.error('有效期不能为空');
+    }
+    // 兑换方式
     let exchangeMethod = $(':radio[name="exchangeMethod"]:checked').val();
+    if (distributionMethod === '' || distributionMethod === undefined || distributionMethod === null){
+        return Feng.error('兑换方式不能为空');
+    }
+    if (distributionMethod === '1'){
+        if (requiredPoints === undefined || requiredPoints === '' || requiredPoints === null){
+            return Feng.error('所需积分不能为空');
+        }
+    }
+    if (distributionMethod === '2'){
+        if (requiredPoints === undefined || requiredPoints === '' || requiredPoints === null){
+            return Feng.error('所需积分不能为空');
+        }
+        if (requiredCash === undefined || requiredCash === '' || requiredCash === null){
+            return Feng.error('所需现金不能为空');
+        }
+    }
+    if (distributionMethod === '3'){
+        if (requiredCash === undefined || requiredCash === '' || requiredCash === null){
+            return Feng.error('所需现金不能为空');
+        }
+    }
 
-    var requiredCash = $('#requiredCash').val();
-
-    var company = $('#company').val();
+    let company = $(':radio[name="company"]:checked').val();
+    var cts = "";
     if (company === '2'){
         var myselect=document.getElementById('cityData');
         var seCity = myselect.options[myselect.selectedIndex].value;
@@ -314,7 +380,7 @@
             return Feng.error('请选中一个省市');
         }
         cityIds.push(seCity);
-        if (this.num > 0){
+        if (num > 0){
             for (let i = 1; i <= num; i++) {
                 var insSelect=document.getElementById('cityData'+i);
                 var inData = insSelect.options[insSelect.selectedIndex].value;
@@ -322,15 +388,21 @@
                     cityIds.push(inData);
                 }
             }
+            cts = cityIds.join(',');
         }
     }
 
+    const commaSeparatedString = this.goodsPicArray.join(',');
+
+    var stores = "";
     if (company === '3'){
-
+        console.log('3---this.storeIds',this.storeIds);
+        if (couponInfoDlg.storeIds.length === 0 ){
+            return Feng.error('请至少选择一个门店');
+        }
+        stores = this.storeIds.join(',');
+        console.log('stores--===--',stores)
     }
-
-    console.log('11111111')
-
     //提交信息
     var ajax = new $ax(Feng.ctxPath + "/tCouponManage/commitData", function (data) {
         Feng.success("添加成功!");
@@ -343,10 +415,10 @@
     ajax.set("cityManagerId",1);
     ajax.set("couponName",couponName);
     ajax.set("prescription",prescription);
-    ajax.set("condition",$('#conditionalAmount').val());
-    ajax.set("subtraction",$('#deductionAmount').val());
-    ajax.set("discount",$('#voucherAmount').val());
-    ajax.set("experience",$('#experienceName').val());
+    ajax.set("condition",conditionalAmount);
+    ajax.set("subtraction",deductionAmount);
+    ajax.set("discount",voucherAmount);
+    ajax.set("experience",experienceName);
     ajax.set("illustrate",illustrate);
     ajax.set("distributionMethod",distributionMethod);
     ajax.set("requiredPoints",requiredPoints);
@@ -357,10 +429,10 @@
     ajax.set("periodOfValidity",periodOfValidity);
     ajax.set("exchangeMethod",exchangeMethod);
     ajax.set("goodImg",this.goodsCover);
-    ajax.set("goodImgs",this.goodsPicArray);
-    ajax.set("company",$('#company').val());
-    ajax.set("cityIds",cityIds);
-    ajax.set("storeIds",this.storeIds);
+    ajax.set("goodImgs",commaSeparatedString);
+    ajax.set("company",company);
+    ajax.set("cityIds",cts);
+    ajax.set("storeIds",stores);
     ajax.start();
 
 }
diff --git a/cloud-server-management/src/main/webapp/static/modular/system/tGoods/tGoods_info.js b/cloud-server-management/src/main/webapp/static/modular/system/tGoods/tGoods_info.js
index c314067..d66b8e2 100644
--- a/cloud-server-management/src/main/webapp/static/modular/system/tGoods/tGoods_info.js
+++ b/cloud-server-management/src/main/webapp/static/modular/system/tGoods/tGoods_info.js
@@ -144,7 +144,7 @@
     console.log(e);
     var row = $(e).closest('tr');
     var value = row.find('#id').val();
-    TCarInfoDlg.storeIds.splice(TCarInfoDlg.storeIds.indexOf(value), 1)
+    TCarInfoDlg.storeIds.splice(TCarInfoDlg.storeIds.indexOf(parseInt(value)), 1)
     $(e).parent().parent().remove();
     console.log('storeIds',TCarInfoDlg.storeIds)
 }

--
Gitblit v1.7.1