From 46d9a52288d5c36985435e775a8433df4e12000b Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 16 Jul 2025 14:27:59 +0800
Subject: [PATCH] feat(mall): 添加自定义打印功能并优化订单相关接口

---
 src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesPatternInfoVo.java      |    2 +
 src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesLocationInfoVo.java     |    2 +
 src/main/resources/templates/febs/views/modules/clothesType/orderList.html     |   68 ++++++++++++++++++++++++++++++++++
 src/main/resources/mapper/modules/ClothesOrderDraftMapper.xml                  |    2 
 src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java |   11 ++++-
 src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiMyDraftVo.java                 |    6 +++
 6 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java
index a6c9631..9f029d3 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiClothesOrderServiceImpl.java
@@ -210,6 +210,8 @@
         ClothesOrderDraft clothesOrderDraft = clothesOrderDraftMapper.selectById(id);
 
         if (ObjectUtil.isNotNull(clothesOrderDraft)){
+            Long draftId = clothesOrderDraft.getId();
+
             Long typeId = clothesOrderDraft.getTypeId();
             ClothesType clothesType = clothesTypeMapper.selectById(typeId);
             record.setTypeId(typeId);
@@ -226,6 +228,7 @@
                         record.setSizeId(sizeId);
                         record.setSizeName(clothesSize.getName());
                         record.setSizePrice(clothesSize.getPrice());
+                        record.setSizeImage(clothesSize.getImage());
                     }
                 }
             }
@@ -240,7 +243,7 @@
             BigDecimal totalPatternPrice = BigDecimal.ZERO;
             List<ClothesPatternRemark> clothesPatternRemarks = clothesPatternRemarkMapper.selectList(
                     Wrappers.lambdaQuery(ClothesPatternRemark.class)
-                            .eq(ClothesPatternRemark::getSourceId, record.getId())
+                            .eq(ClothesPatternRemark::getSourceId, draftId)
                             .eq(ClothesPatternRemark::getType, SocialPatternLocationTypeEnum.DRAFT.getValue())
             );
             if(CollUtil.isNotEmpty(clothesPatternRemarks)){
@@ -253,6 +256,7 @@
                     vo.setPatternName(clothesPattern.getName());
                     vo.setPatternPrice(clothesPattern.getPrice());
                     vo.setPatternRemark(entity.getRemark());
+                    vo.setPatternImage(clothesPattern.getImage());
                     vos.add(vo);
 
                     totalPatternPrice = totalPatternPrice.add(clothesPattern.getPrice());
@@ -263,7 +267,7 @@
             BigDecimal totalLocationPrice = BigDecimal.ZERO;
             List<ClothesLocationRemark> clothesLocationRemarks = clothesLocationRemarkMapper.selectList(
                     Wrappers.lambdaQuery(ClothesLocationRemark.class)
-                            .eq(ClothesLocationRemark::getSourceId, record.getId())
+                            .eq(ClothesLocationRemark::getSourceId, draftId)
                             .eq(ClothesLocationRemark::getType, SocialPatternLocationTypeEnum.DRAFT.getValue())
             );
             if(CollUtil.isNotEmpty(clothesLocationRemarks)){
@@ -276,6 +280,7 @@
                     vo.setLocationName(location.getName());
                     vo.setLocationPrice(location.getPrice());
                     vo.setLocationRemark(entity.getRemark());
+                    vo.setLocationImage(location.getImage());
                     vos.add(vo);
 
                     totalLocationPrice = totalLocationPrice.add(location.getPrice());
@@ -293,6 +298,7 @@
                         record.setArtId(artId);
                         record.setArtName(clothesArt.getName());
                         record.setArtPrice(clothesArt.getPrice());
+                        record.setArtImage(clothesArt.getImage());
                     }
                 }
             }
@@ -307,6 +313,7 @@
                         record.setClothId(clothId);
                         record.setClothName(clothesCloth.getName());
                         record.setClothPrice(clothesCloth.getPrice());
+                        record.setClothImage(clothesCloth.getImage());
                     }
                 }
             }
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesLocationInfoVo.java b/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesLocationInfoVo.java
index cce33bd..bb0b12f 100644
--- a/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesLocationInfoVo.java
+++ b/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesLocationInfoVo.java
@@ -15,6 +15,8 @@
     private Long locationId;
     @ApiModelProperty(value = "反面图案名称")
     private String locationName;
+    @ApiModelProperty(value = "反面图案图片")
+    private String locationImage;
     @ApiModelProperty(value = "反面图案价格")
     private BigDecimal locationPrice = BigDecimal.ZERO;
     @ApiModelProperty(value = "反面自定义内容")
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesPatternInfoVo.java b/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesPatternInfoVo.java
index a1fe32b..4373f80 100644
--- a/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesPatternInfoVo.java
+++ b/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiClothesPatternInfoVo.java
@@ -15,6 +15,8 @@
     private Long patternId;
     @ApiModelProperty(value = "正面图案名称")
     private String patternName;
+    @ApiModelProperty(value = "正面图案图片")
+    private String patternImage;
     @ApiModelProperty(value = "正面图案价格")
     private BigDecimal patternPrice = BigDecimal.ZERO;
     @ApiModelProperty(value = "正面自定义内容")
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiMyDraftVo.java b/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiMyDraftVo.java
index f789d3b..a9115d4 100644
--- a/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiMyDraftVo.java
+++ b/src/main/java/cc/mrbird/febs/mall/vo/clothes/ApiMyDraftVo.java
@@ -30,6 +30,8 @@
     private String artName;
     @ApiModelProperty(value = "工艺价格")
     private BigDecimal artPrice = BigDecimal.ZERO;
+    @ApiModelProperty(value = "工艺图片")
+    private String artImage;
 
     @ApiModelProperty(value = "尺码ID")
     private Long sizeId;
@@ -37,6 +39,8 @@
     private String sizeName;
     @ApiModelProperty(value = "尺码价格")
     private BigDecimal sizePrice = BigDecimal.ZERO;
+    @ApiModelProperty(value = "尺码图片")
+    private String sizeImage;
 
     @ApiModelProperty(value = "正面图案")
     private List<ApiClothesPatternInfoVo> patternList;
@@ -52,6 +56,8 @@
     private String clothName;
     @ApiModelProperty(value = "布料价格")
     private BigDecimal clothPrice = BigDecimal.ZERO;
+    @ApiModelProperty(value = "布料图片")
+    private String clothImage;
 
     @ApiModelProperty(value = "身材数据ID")
     private Long statureId;
diff --git a/src/main/resources/mapper/modules/ClothesOrderDraftMapper.xml b/src/main/resources/mapper/modules/ClothesOrderDraftMapper.xml
index e17e850..d19e901 100644
--- a/src/main/resources/mapper/modules/ClothesOrderDraftMapper.xml
+++ b/src/main/resources/mapper/modules/ClothesOrderDraftMapper.xml
@@ -10,7 +10,7 @@
         where a.member_id = #{record.memberId}
         and a.del_flag = 0
         and b.state = 1
-        order by a.CREATED_TIME asc
+        order by a.CREATED_TIME desc
     </select>
 
 </mapper>
\ No newline at end of file
diff --git a/src/main/resources/templates/febs/views/modules/clothesType/orderList.html b/src/main/resources/templates/febs/views/modules/clothesType/orderList.html
index d5a50f8..a498a93 100644
--- a/src/main/resources/templates/febs/views/modules/clothesType/orderList.html
+++ b/src/main/resources/templates/febs/views/modules/clothesType/orderList.html
@@ -100,6 +100,7 @@
 </script>
 <script type="text/html" id="tableToolBarClothesOrder">
     <div class="layui-btn-container">
+        <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="printSelect">自定义打印</button>
         <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="deliverGoods">发货</button>
         <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="updateDeliver">修改物流信息</button>
         <button class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain" lay-event="refundOrder">仅退款</button>
@@ -150,6 +151,28 @@
             var layEvent = obj.event;
             var id = obj.config.id;
             var checkStatus = table.checkStatus(id);
+            if(layEvent === 'printSelect'){
+                let data = checkStatus.data;
+                if (data.length > 1) {
+                    febs.alert.warn('每次只能操作一个订单');
+                    return;
+                }
+                let ids = "";
+                for(let i = 0;i < data.length;i++){
+                    console.log(data[i].status);
+                    if(data[i].status != 2){
+                        febs.alert.warn('请选择待发货的订单');
+                        return;
+                    }else{
+                        ids = data[i].id;
+                    }
+                }
+                if(ids == null || ids == ""){
+                    febs.alert.warn('请选择订单');
+                    return;
+                }
+                printSelect(data)
+            }
 
             if (layEvent === 'deliverGoods') {
                 let data = checkStatus.data;
@@ -282,6 +305,51 @@
 
         });
 
+
+        /*
+         * [自定义打印选中行数据]
+         * @param  {[type]}  allData [传入选中行]
+         */
+        function printSelect(allData) {
+            //用于包含内容
+            var v = document.createElement("div");
+            //页面头部,导入css  ,media="print"表示打印时使用该样式
+            var f = ["<head>", "<style>", "div{font-size:8px;}", ".main{width:100%;}",
+                ".main div{width:100%;display:inline-block;}", "</style>", "</head>"
+            ].join("");
+            var contentHtml = "";
+            for (let i = 0; i < allData.length; i++) {
+                let data = allData[i]
+                var template =
+                    "<div class='main'>" +
+                    "<table cellspacing=\"0\" width=\"100%\" style=\"border-collapse: separate; border-spacing: 0px;\">" +
+                    "<tr>" +
+                    "<td style='width: 50%;'>" +
+                    "<img src='" + data.img + "' style='width: 100%;'/>" +
+                    "</td>" +
+                    "<td style='width: 50%;'>" +
+                    "<img src='" + data.img + "' style='width: 100%;'/>" +
+                    "</td>" +
+                    "</tr>" +
+                    "</table>" +
+                    "<div style='text-align: center;font-size: 10px;font-weight: bold;margin-bottom: 10px'>订单编号:" + data.orderNo + "</div>" +
+                    "</div>"
+
+                contentHtml += template;
+            }
+
+            //contentHtml为已拼凑好的内容
+            $(v).append(contentHtml)
+            //新建窗口
+            var h = window.open("打印窗口", "_blank");
+            //写入拼凑内容
+            h.document.write(f + $(v).prop("outerHTML"));
+            //调用打印
+            h.print();
+            //关闭页面
+            h.close();
+        }
+
         function refundOrder(id) {
             febs.get(ctx + 'admin/clothesType/refundOrder/' + id, null, function () {
                 febs.alert.success('操作成功');

--
Gitblit v1.9.1