From 5c656bf6da9673b88d8dfefb5b3b459d29946472 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 11 Oct 2023 15:40:19 +0800
Subject: [PATCH] redbagprod

---
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java    |   61 +++++++++++++++
 src/main/resources/templates/febs/views/modules/goods/goodsCouponUpdate.html |   52 ++++++++++++
 src/main/java/cc/mrbird/febs/mall/vo/AdminMallGoodsCouponVo.java             |    3 
 src/main/java/cc/mrbird/febs/mall/service/IAdminMallGoodsService.java        |    2 
 src/main/java/cc/mrbird/febs/mall/controller/AdminMallGoodsController.java   |    5 +
 src/main/resources/templates/febs/views/modules/goods/goodsCouponAdd.html    |   50 ++++++++++++
 src/main/java/cc/mrbird/febs/mall/dto/CouponRuleAddDto.java                  |    5 +
 src/main/java/cc/mrbird/febs/mall/mapper/CouponGoodsMapper.java              |    2 
 src/main/resources/mapper/modules/CouponGoodsMapper.xml                      |    6 +
 9 files changed, 184 insertions(+), 2 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/controller/AdminMallGoodsController.java b/src/main/java/cc/mrbird/febs/mall/controller/AdminMallGoodsController.java
index fa61156..8cc2543 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/AdminMallGoodsController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/AdminMallGoodsController.java
@@ -404,5 +404,10 @@
         return new FebsResponse().success().data(adminMallGoodsService.findAdminMallGoodsCouponVoTreeList());
     }
 
+    @GetMapping(value = "/goodsTreeSet")
+    public FebsResponse goodsTreeSet() {
+        return new FebsResponse().success().data(adminMallGoodsService.findAdminMallGoodsVoTreeList());
+    }
+
 
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/dto/CouponRuleAddDto.java b/src/main/java/cc/mrbird/febs/mall/dto/CouponRuleAddDto.java
index 7a2c95b..1e08024 100644
--- a/src/main/java/cc/mrbird/febs/mall/dto/CouponRuleAddDto.java
+++ b/src/main/java/cc/mrbird/febs/mall/dto/CouponRuleAddDto.java
@@ -5,6 +5,8 @@
 
 import javax.validation.constraints.*;
 import java.math.BigDecimal;
+import java.util.List;
+
 @Data
 @ApiModel(value = "CouponRuleAddDto", description = "参数类")
 public class CouponRuleAddDto {
@@ -27,4 +29,7 @@
     @DecimalMax(value = "10000", inclusive = false, message = "字段不能大于10000")
     private BigDecimal realAmount;
 
+    //优惠卷IDs
+    private List<Long> goodsIds;
+
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/mapper/CouponGoodsMapper.java b/src/main/java/cc/mrbird/febs/mall/mapper/CouponGoodsMapper.java
index d4469a6..358ed36 100644
--- a/src/main/java/cc/mrbird/febs/mall/mapper/CouponGoodsMapper.java
+++ b/src/main/java/cc/mrbird/febs/mall/mapper/CouponGoodsMapper.java
@@ -10,5 +10,7 @@
 
     List<Long> selectByGoodId(Long id);
 
+    List<Long> selectByCouponId(Long id);
+
     List<CouponGoods> selectByGoodIdAndCouponId(@Param("goodsId")Long goodsId, @Param("couponId")Long couponId);
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IAdminMallGoodsService.java b/src/main/java/cc/mrbird/febs/mall/service/IAdminMallGoodsService.java
index 6164200..daad038 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/IAdminMallGoodsService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/IAdminMallGoodsService.java
@@ -72,4 +72,6 @@
     List<AdminMallGoodsCouponTreeVo> findAdminMallGoodsCouponVoTree();
 
     List<AdminMallGoodsCouponTreeListVo> findAdminMallGoodsCouponVoTreeList();
+
+    List<AdminMallGoodsCouponTreeListVo> findAdminMallGoodsVoTreeList();
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
index 6764092..28e95b3 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -865,6 +865,25 @@
         mallGoodsCoupon.setCostAmount(couponRuleAddDto.getCostAmount());
         mallGoodsCoupon.setRealAmount(couponRuleAddDto.getRealAmount());
         mallGoodsCouponMapper.insert(mallGoodsCoupon);
+
+        Long couponId = mallGoodsCoupon.getId();
+        QueryWrapper<CouponGoods> objectQueryWrapperCoupon = new QueryWrapper<>();
+        objectQueryWrapperCoupon.eq("coupon_id",couponId);
+        List<CouponGoods> couponGoodsList = couponGoodsMapper.selectList(objectQueryWrapperCoupon);
+        if(CollUtil.isNotEmpty(couponGoodsList)){
+            for(CouponGoods couponGoods : couponGoodsList){
+                couponGoodsMapper.deleteById(couponGoods);
+            }
+        }
+        if(CollUtil.isNotEmpty(couponRuleAddDto.getGoodsIds())){
+            List<Long> goodsIds = couponRuleAddDto.getGoodsIds();
+            for(Long goodsId : goodsIds){
+                CouponGoods couponGoods = new CouponGoods();
+                couponGoods.setGoodsId(goodsId);
+                couponGoods.setCouponId(couponId);
+                couponGoodsMapper.insert(couponGoods);
+            }
+        }
         return new FebsResponse().success().message("操作成功");
     }
 
@@ -906,7 +925,10 @@
 
     @Override
     public AdminMallGoodsCouponVo selectGoodsCouponById(long id) {
-        return mallGoodsCouponMapper.selectGoodsCouponById(id);
+        List<Long> goodsIds = couponGoodsMapper.selectByCouponId(id);
+        AdminMallGoodsCouponVo adminMallGoodsCouponVo = mallGoodsCouponMapper.selectGoodsCouponById(id);
+        adminMallGoodsCouponVo.setGoodsIds(goodsIds);
+        return adminMallGoodsCouponVo;
     }
 
     @Override
@@ -925,6 +947,25 @@
         mallGoodsCoupon.setCostAmount(adminMallGoodsCouponVo.getCostAmount());
         mallGoodsCoupon.setRealAmount(adminMallGoodsCouponVo.getRealAmount());
         mallGoodsCouponMapper.updateById(mallGoodsCoupon);
+
+        Long couponId = mallGoodsCoupon.getId();
+        QueryWrapper<CouponGoods> objectQueryWrapperCoupon = new QueryWrapper<>();
+        objectQueryWrapperCoupon.eq("coupon_id",couponId);
+        List<CouponGoods> couponGoodsList = couponGoodsMapper.selectList(objectQueryWrapperCoupon);
+        if(CollUtil.isNotEmpty(couponGoodsList)){
+            for(CouponGoods couponGoods : couponGoodsList){
+                couponGoodsMapper.deleteById(couponGoods);
+            }
+        }
+        if(CollUtil.isNotEmpty(adminMallGoodsCouponVo.getGoodsIds())){
+            List<Long> goodsIds = adminMallGoodsCouponVo.getGoodsIds();
+            for(Long goodsId : goodsIds){
+                CouponGoods couponGoods = new CouponGoods();
+                couponGoods.setGoodsId(goodsId);
+                couponGoods.setCouponId(couponId);
+                couponGoodsMapper.insert(couponGoods);
+            }
+        }
         return new FebsResponse().success().message("操作成功");
     }
 
@@ -963,4 +1004,22 @@
         }
         return objects;
     }
+
+    @Override
+    public List<AdminMallGoodsCouponTreeListVo> findAdminMallGoodsVoTreeList() {
+        QueryWrapper<MallGoods> objectQueryWrapper = new QueryWrapper<>();
+        objectQueryWrapper.eq("is_sale",1);
+        List<MallGoods> mallGoodsList = mallGoodsMapper.selectList(objectQueryWrapper);
+
+        List<AdminMallGoodsCouponTreeListVo> objects = new ArrayList<>();
+        if(CollUtil.isNotEmpty(mallGoodsList)){
+            for(MallGoods mallGoods : mallGoodsList){
+                AdminMallGoodsCouponTreeListVo adminMallGoodsCouponTreeListVo = new AdminMallGoodsCouponTreeListVo();
+                adminMallGoodsCouponTreeListVo.setId(mallGoods.getId());
+                adminMallGoodsCouponTreeListVo.setName(mallGoods.getGoodsName());
+                objects.add(adminMallGoodsCouponTreeListVo);
+            }
+        }
+        return objects;
+    }
 }
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/AdminMallGoodsCouponVo.java b/src/main/java/cc/mrbird/febs/mall/vo/AdminMallGoodsCouponVo.java
index 09628ee..9b68a3b 100644
--- a/src/main/java/cc/mrbird/febs/mall/vo/AdminMallGoodsCouponVo.java
+++ b/src/main/java/cc/mrbird/febs/mall/vo/AdminMallGoodsCouponVo.java
@@ -5,6 +5,7 @@
 
 import javax.validation.constraints.*;
 import java.math.BigDecimal;
+import java.util.List;
 
 @Data
 @ApiModel(value = "AdminMallGoodsCouponVo", description = "信息返回类")
@@ -28,4 +29,6 @@
     @DecimalMin(value = "0", inclusive = false, message = "字段不能小于0")
     @DecimalMax(value = "10000", inclusive = false, message = "字段不能大于10000")
     private BigDecimal realAmount;
+
+    private List<Long> goodsIds;
 }
diff --git a/src/main/resources/mapper/modules/CouponGoodsMapper.xml b/src/main/resources/mapper/modules/CouponGoodsMapper.xml
index b8eb6a1..c5f1acf 100644
--- a/src/main/resources/mapper/modules/CouponGoodsMapper.xml
+++ b/src/main/resources/mapper/modules/CouponGoodsMapper.xml
@@ -8,6 +8,12 @@
         where goods_id = #{id}
     </select>
 
+    <select id="selectByCouponId" resultType="java.lang.Long">
+        select a.goods_id
+        from coupon_goods a
+        where coupon_id = #{id}
+    </select>
+
     <select id="selectByGoodIdAndCouponId" resultType="cc.mrbird.febs.mall.entity.CouponGoods">
         select a.*
         from coupon_goods a
diff --git a/src/main/resources/templates/febs/views/modules/goods/goodsCouponAdd.html b/src/main/resources/templates/febs/views/modules/goods/goodsCouponAdd.html
index feb0fde..c8ce3c3 100644
--- a/src/main/resources/templates/febs/views/modules/goods/goodsCouponAdd.html
+++ b/src/main/resources/templates/febs/views/modules/goods/goodsCouponAdd.html
@@ -46,6 +46,17 @@
                                     <div class="layui-form-mid">(元)金额。</div>
                                     <div class="layui-form-mid layui-word-aux">满足0元减免100元,则代表100元无门槛优惠卷。</div>
                                 </div>
+
+                                <blockquote class="layui-elem-quote blue-border">商品设置</blockquote>
+                                <div class="layui-form-item coupon-rule">
+                                    <div class="layui-col-lg6">
+                                        <label class="layui-form-label febs-form-item-require">商品:</label>
+                                        <div class="layui-input-block">
+                                            <div id="coupon-rule"></div>
+                                        </div>
+                                    </div>
+                                </div>
+
                             </div>
                         </div>
                     </div>
@@ -86,9 +97,48 @@
             validate = layui.validate,
             element = layui.element;
 
+        var couponRule = xmSelect.render({
+            el: '#coupon-rule',
+            language: 'zn',
+            prop : {
+                value : 'id',
+                children : 'child'
+            },
+            iconfont: {
+                parent: 'hidden',
+            },
+            toolbar: {
+                show: true,
+            },
+            // radio: true,
+            clickClose: true,
+            tree: {
+                show: true,
+                //非严格模式
+                strict: false,
+            },
+            data: []
+        })
+
+        febs.get(ctx + 'admin/goods/goodsTreeSet', null, function(res) {
+            couponRule.update({
+                data : res.data,
+                autoRow: true,
+            });
+        })
+
         form.render();
 
+
         form.on('submit(coupon-rule-add-form-submit)', function (data) {
+            let couponRuleList = couponRule.getValue();
+            if (couponRuleList.length > 0) {
+                var couponIds = [];
+                layui.each(couponRuleList, function (key, item) {
+                    couponIds.push(item.id)
+                });
+                data.field.goodsIds=couponIds;
+            }
             $.ajax({
                 'url':ctx + 'admin/goods/couponRuleAdd',
                 'type':'post',
diff --git a/src/main/resources/templates/febs/views/modules/goods/goodsCouponUpdate.html b/src/main/resources/templates/febs/views/modules/goods/goodsCouponUpdate.html
index fbf9a2c..5f29717 100644
--- a/src/main/resources/templates/febs/views/modules/goods/goodsCouponUpdate.html
+++ b/src/main/resources/templates/febs/views/modules/goods/goodsCouponUpdate.html
@@ -45,6 +45,17 @@
                                     <div class="layui-form-mid">(元)金额。</div>
                                     <div class="layui-form-mid layui-word-aux">满足0元减免100元,则代表100元无门槛优惠卷。</div>
                                 </div>
+
+                                <blockquote class="layui-elem-quote blue-border">商品设置</blockquote>
+                                <div class="layui-form-item coupon-rule">
+                                    <div class="layui-col-lg6">
+                                        <label class="layui-form-label febs-form-item-require">商品:</label>
+                                        <div class="layui-input-block">
+                                            <div id="coupon-rule"></div>
+                                        </div>
+                                    </div>
+                                </div>
+
                             </div>
                         </div>
                     </div>
@@ -88,7 +99,37 @@
 
         form.render();
 
-        initValue();
+        var couponRuleGoodsIds = xmSelect.render({
+            el: '#coupon-rule',
+            language: 'zn',
+            prop : {
+                value : 'id',
+                children : 'child'
+            },
+            iconfont: {
+                parent: 'hidden',
+            },
+            toolbar: {
+                show: true,
+            },
+            // radio: true,
+            clickClose: true,
+            tree: {
+                show: true,
+                //非严格模式
+                strict: false,
+            },
+            data: []
+        })
+
+        febs.get(ctx + 'admin/goods/goodsTreeSet', null, function(res) {
+            couponRuleGoodsIds.update({
+                data : res.data,
+                autoRow: true,
+            });
+            initValue();
+        })
+
 
         function initValue() {
             form.val("coupon-rule-update-form", {
@@ -98,9 +139,18 @@
                 "costAmount": couponRule.costAmount,
                 "realAmount": couponRule.realAmount
             });
+            couponRuleGoodsIds.setValue(couponRule.goodsIds);
         }
 
         form.on('submit(coupon-rule-update-form-submit)', function (data) {
+            let couponRuleList = couponRuleGoodsIds.getValue();
+            if (couponRuleList.length > 0) {
+                var couponIds = [];
+                layui.each(couponRuleList, function (key, item) {
+                    couponIds.push(item.id)
+                });
+                data.field.goodsIds=couponIds;
+            }
             $.ajax({
                 'url':ctx + 'admin/goods/couponUpdate',
                 'type':'post',

--
Gitblit v1.9.1