8 Commity 605ad0f3a9 ... b33204204f

Autor SHA1 Wiadomość Data
  wangming b33204204f add 3 tygodni temu
  wangming bafbfb88b9 Merge remote-tracking branch 'origin/dev' into dev 3 tygodni temu
  wangming f7ff508b1b add 3 tygodni temu
  wangming 5852b08208 add 3 tygodni temu
  wangming 4e442e748e add 3 tygodni temu
  wangming ff1bb03ecb fix 3 tygodni temu
  wangming d210d6f18f fix 3 tygodni temu
  wangming 0919e6fa31 fix 3 tygodni temu
19 zmienionych plików z 1037 dodań i 10 usunięć
  1. 2 2
      yami-shop-api/src/main/resources/application.yml
  2. 42 0
      yami-shop-bean/src/main/java/com/yami/shop/bean/po/FreightStatisticsPo.java
  3. 33 0
      yami-shop-bean/src/main/java/com/yami/shop/bean/po/SkuStatisticsPo.java
  4. 62 0
      yami-shop-bean/src/main/java/com/yami/shop/bean/vo/FreightStatisticsVo.java
  5. 17 0
      yami-shop-bean/src/main/java/com/yami/shop/bean/vo/IdNameVo.java
  6. 31 0
      yami-shop-bean/src/main/java/com/yami/shop/bean/vo/SkuStatistics.java
  7. 55 0
      yami-shop-bean/src/main/java/com/yami/shop/bean/vo/SkuStatisticsExcel.java
  8. 55 0
      yami-shop-bean/src/main/java/com/yami/shop/bean/vo/SkuStatisticsVo.java
  9. 68 4
      yami-shop-platform/src/main/java/com/yami/shop/platform/controller/SkuController.java
  10. 2 2
      yami-shop-platform/src/main/resources/application.yml
  11. 1 0
      yami-shop-security/yami-shop-security-platform/src/main/java/com/yami/shop/security/platform/config/ResourceServerConfiguration.java
  12. 3 1
      yami-shop-service/src/main/java/com/yami/shop/dao/ChannelMapper.java
  13. 15 0
      yami-shop-service/src/main/java/com/yami/shop/dao/SkuMapper.java
  14. 5 1
      yami-shop-service/src/main/java/com/yami/shop/service/ChannelService.java
  15. 13 0
      yami-shop-service/src/main/java/com/yami/shop/service/SkuService.java
  16. 8 0
      yami-shop-service/src/main/java/com/yami/shop/service/impl/ChannelServiceImpl.java
  17. 159 0
      yami-shop-service/src/main/java/com/yami/shop/service/impl/SkuServiceImpl.java
  18. 7 0
      yami-shop-service/src/main/resources/mapper/ChannelMapper.xml
  19. 459 0
      yami-shop-service/src/main/resources/mapper/SkuMapper.xml

+ 2 - 2
yami-shop-api/src/main/resources/application.yml

@@ -2,8 +2,8 @@
 spring:
   # 环境 dev|prod|docker
   profiles:
-    active: dev
-#    active: prod
+#    active: dev
+    active: prod
   #文件上传设置
   servlet:
     multipart:

+ 42 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/po/FreightStatisticsPo.java

@@ -0,0 +1,42 @@
+
+package com.yami.shop.bean.po;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class FreightStatisticsPo {
+
+    @ApiModelProperty("企业ids")
+    private List<Long> channelIds;
+
+    @ApiModelProperty("收货人")
+    private String receiver;
+
+    @ApiModelProperty("收货人手机号")
+    private String mobile;
+
+    @ApiModelProperty("运输公司")
+    private String delivery;
+
+    @ApiModelProperty("运单号")
+    private String deliveryNo;
+
+    @ApiModelProperty("到件地址")
+    private String toAddress;
+
+    @ApiModelProperty("订/退单号")
+    private String orderNo;
+
+    @ApiModelProperty("开始时间")
+    private String startTime;
+
+    @ApiModelProperty("结束时间")
+    private String endTime;
+}

+ 33 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/po/SkuStatisticsPo.java

@@ -0,0 +1,33 @@
+
+package com.yami.shop.bean.po;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SkuStatisticsPo {
+
+    @ApiModelProperty("企业ids")
+    private List<Long> channelIds;
+
+    @ApiModelProperty("skuId")
+    private Long skuId;
+
+    @ApiModelProperty("skuName")
+    private String skuName;
+
+    @ApiModelProperty("规格")
+    private String spec;
+
+    @ApiModelProperty("开始时间")
+    private String startTime;
+
+    @ApiModelProperty("结束时间")
+    private String endTime;
+}

+ 62 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/FreightStatisticsVo.java

@@ -0,0 +1,62 @@
+
+package com.yami.shop.bean.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class FreightStatisticsVo {
+
+    @ApiModelProperty("排序")
+    @ExcelProperty("序号")
+    private Integer sort;
+
+    @ApiModelProperty("日期")
+    @ExcelProperty("日期")
+    @JsonFormat(pattern = "yyyy/MM/dd")
+    private String payTime;
+
+    @ApiModelProperty("寄方")
+    @ExcelProperty("寄方")
+    private String sendSize = "中数未来(贵州)商业服务有限公司";
+
+    @ApiModelProperty("收方")
+    @ExcelProperty("收方")
+    private String receiver;
+
+    @ApiModelProperty("运输公司")
+    @ExcelProperty("运输公司")
+    private String delivery = "邮政";
+
+    @ApiModelProperty("运单号")
+    @ExcelProperty("运单号")
+    private String deliveryNo;
+
+    @ApiModelProperty("寄件地区")
+    @ExcelProperty("寄件地区")
+    private String sendArea = "铜仁市";
+
+    @ApiModelProperty("到件地址")
+    @ExcelProperty("到件地址")
+    private String toAddress;
+
+    @ApiModelProperty("经手人")
+    @ExcelProperty("经手人")
+    private String handler = "谭靖";
+
+    @ApiModelProperty("费用")
+    @ExcelProperty("费用(元)")
+    private String money;
+
+    @ApiModelProperty("订/退单号")
+    @ExcelProperty("订/退单号")
+    private String orderNo;
+
+
+}

+ 17 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/IdNameVo.java

@@ -0,0 +1,17 @@
+
+package com.yami.shop.bean.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class IdNameVo {
+
+    private Long id;
+
+    private String name;
+
+}

+ 31 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/SkuStatistics.java

@@ -0,0 +1,31 @@
+
+package com.yami.shop.bean.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SkuStatistics {
+
+    @ApiModelProperty("商品总额")
+    private Double goodsTotalPrice;
+
+    @ApiModelProperty("积分抵扣")
+    private Double totalPoints;
+
+    @ApiModelProperty("现金抵扣")
+    private Double totalCash;
+
+    @ApiModelProperty("运费")
+    private Double totalFreight;
+
+    @ApiModelProperty("sku")
+    private List<SkuStatisticsVo> skuStatisticsList;
+
+}

+ 55 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/SkuStatisticsExcel.java

@@ -0,0 +1,55 @@
+
+package com.yami.shop.bean.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SkuStatisticsExcel {
+
+    @ExcelProperty("商品ID")
+    @ApiModelProperty("skuId")
+    private Long skuId;
+
+    @ApiModelProperty("skuName")
+    @ExcelProperty("商品名称")
+    private String skuName;
+
+    @ApiModelProperty("规格")
+    @ExcelProperty("规格")
+    private String spec;
+
+    @ApiModelProperty("单价")
+    @ExcelProperty("单价(元)")
+    private Double price;
+
+    @ApiModelProperty("商品总数量")
+    @ExcelProperty("商品总数量")
+    private Integer prodCount;
+
+    @ApiModelProperty("小计")
+    @ExcelProperty("小计(元)")
+    private Double total;
+
+    @ApiModelProperty("商品总额")
+    @ExcelProperty("商品总额(元)")
+    private Double goodsTotalPrice;
+
+    @ApiModelProperty("积分抵扣")
+    @ExcelProperty("总积分抵扣(元)")
+    private Double totalPoints;
+
+    @ApiModelProperty("现金抵扣")
+    @ExcelProperty("总现金抵扣(元)")
+    private Double totalCash;
+
+    @ApiModelProperty("运费")
+    @ExcelProperty("总运费(元)")
+    private Double totalFreight;
+
+}

+ 55 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/SkuStatisticsVo.java

@@ -0,0 +1,55 @@
+
+package com.yami.shop.bean.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SkuStatisticsVo {
+
+    @ExcelProperty("商品ID")
+    @ApiModelProperty("skuId")
+    private Long skuId;
+
+    @ApiModelProperty("skuName")
+    @ExcelProperty("商品名称")
+    private String skuName;
+
+    @ApiModelProperty("规格")
+    @ExcelProperty("规格")
+    private String spec;
+
+    @ApiModelProperty("单价")
+    @ExcelProperty("单价(元)")
+    private Double price;
+
+    @ApiModelProperty("商品总数量")
+    @ExcelProperty("商品总数量")
+    private Integer prodCount;
+
+    @ApiModelProperty("小计")
+    @ExcelProperty("小计(元)")
+    private Double total;
+
+    @ApiModelProperty(value = "商品总额",hidden = true)
+    @ExcelProperty("商品总额(元)")
+    private Double goodsTotalPrice;
+
+    @ApiModelProperty(value = "积分抵扣",hidden = true)
+    @ExcelProperty("总积分抵扣(元)")
+    private Double totalPoints;
+
+    @ApiModelProperty(value = "现金抵扣",hidden = true)
+    @ExcelProperty("总现金抵扣(元)")
+    private Double totalCash;
+
+    @ApiModelProperty(value = "运费",hidden = true)
+    @ExcelProperty("总运费(元)")
+    private Double totalFreight;
+
+}

+ 68 - 4
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/SkuController.java

@@ -10,20 +10,30 @@
 
 package com.yami.shop.platform.controller;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yami.shop.bean.model.Sku;
+import com.yami.shop.bean.po.FreightStatisticsPo;
+import com.yami.shop.bean.po.SkuStatisticsPo;
+import com.yami.shop.bean.vo.FreightStatisticsVo;
+import com.yami.shop.bean.vo.IdNameVo;
+import com.yami.shop.bean.vo.SkuStatisticsVo;
+import com.yami.shop.common.util.PageParam;
+import com.yami.shop.common.util.R;
+import com.yami.shop.security.platform.util.SecurityUtils;
+import com.yami.shop.service.ChannelService;
 import com.yami.shop.service.SkuService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.MediaType;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
-import com.yami.shop.common.util.R;
+import java.util.stream.Collectors;
+
 /**
  * 商品SKU管理实现
  *
@@ -37,6 +47,7 @@ import com.yami.shop.common.util.R;
 public class SkuController {
 
     private final SkuService skuService;
+    private final ChannelService channelService;
 
     @GetMapping("/getAllSkuList")
     @PreAuthorize("@pms.hasPermission('plateform:sku:list')")
@@ -44,4 +55,57 @@ public class SkuController {
         List<Sku> skus = skuService.listByProdId(prodId);
         return R.SUCCESS(skus);
     }
+
+    @GetMapping("/skuStatisticsList")
+    @ApiOperation(value = "对账单汇总表(商品)-列表")
+    public R<IPage<SkuStatisticsVo>> skuStatisticsList(PageParam<SkuStatisticsPo> page, SkuStatisticsPo po) {
+        if (po.getChannelIds().contains(0L)){
+            List<IdNameVo> idNameVos = channelService.queryMyChannel(SecurityUtils.getSysUser().getUserId());
+            if (!idNameVos.isEmpty()){
+                List<Long> ids = idNameVos.stream().map(IdNameVo::getId).collect(Collectors.toList());
+                po.setChannelIds(ids);
+            }
+        }
+        return R.SUCCESS(skuService.skuStatisticsList(page,po));
+    }
+
+    @GetMapping(value = "/skuStatisticsExcel",produces =  MediaType.APPLICATION_OCTET_STREAM_VALUE)
+    @ApiOperation("对账单汇总表(商品)-导出")
+    public void skuStatisticsExcel(HttpServletResponse response, SkuStatisticsPo po) {
+        if (po.getChannelIds().contains(0L)){
+            List<IdNameVo> idNameVos = channelService.queryMyChannel(SecurityUtils.getSysUser().getUserId());
+            if (!idNameVos.isEmpty()){
+                List<Long> ids = idNameVos.stream().map(IdNameVo::getId).collect(Collectors.toList());
+                po.setChannelIds(ids);
+            }
+        }
+        skuService.skuStatisticsExcel(response,po);
+    }
+
+    @GetMapping("/freightStatisticsList")
+    @ApiOperation(value = "运费明细表-列表")
+    public R<IPage<FreightStatisticsVo>> freightStatisticsList(PageParam<FreightStatisticsPo> page, FreightStatisticsPo po) {
+        if (po.getChannelIds().contains(0L)){
+            List<IdNameVo> idNameVos = channelService.queryMyChannel(SecurityUtils.getSysUser().getUserId());
+            if (!idNameVos.isEmpty()){
+                List<Long> ids = idNameVos.stream().map(IdNameVo::getId).collect(Collectors.toList());
+                po.setChannelIds(ids);
+            }
+        }
+        return R.SUCCESS(skuService.freightStatisticsList(page,po));
+    }
+
+    @GetMapping("/freightStatisticsExcel")
+    @ApiOperation("运费明细表-导出")
+    public R<Void> freightStatisticsExcel(HttpServletResponse response, FreightStatisticsPo po) {
+        if (po.getChannelIds().contains(0L)){
+            List<IdNameVo> idNameVos = channelService.queryMyChannel(SecurityUtils.getSysUser().getUserId());
+            if (!idNameVos.isEmpty()){
+                List<Long> ids = idNameVos.stream().map(IdNameVo::getId).collect(Collectors.toList());
+                po.setChannelIds(ids);
+            }
+        }
+        skuService.freightStatisticsExcel(response,po);
+        return R.SUCCESS();
+    }
 }

+ 2 - 2
yami-shop-platform/src/main/resources/application.yml

@@ -1,8 +1,8 @@
 spring:
   # 环境 dev|prod|docker quartz定时任务
   profiles:
-    active: dev
-#    active: prod
+#    active: dev
+    active: prod
   #文件上传设置
   servlet:
 

+ 1 - 0
yami-shop-security/yami-shop-security-platform/src/main/java/com/yami/shop/security/platform/config/ResourceServerConfiguration.java

@@ -65,6 +65,7 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter
                     "/admin/enterprise/downloadExcel",
                     "/admin/enterprise/downloadErrorExcel",
                     "/admin/enterprise/export",
+                    "/platform/sku/**",
                     "/captcha.jpg").permitAll()
             .and()
             .authorizeRequests()

+ 3 - 1
yami-shop-service/src/main/java/com/yami/shop/dao/ChannelMapper.java

@@ -13,8 +13,8 @@ package com.yami.shop.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yami.shop.bean.model.Channel;
-import com.yami.shop.bean.model.ChannelProd;
 import com.yami.shop.bean.vo.ChannelVO;
+import com.yami.shop.bean.vo.IdNameVo;
 import com.yami.shop.common.util.PageParam;
 import org.apache.ibatis.annotations.Param;
 
@@ -33,4 +33,6 @@ public interface ChannelMapper extends BaseMapper<Channel> {
     Channel selectByName(@Param("channelName") String channelName);
 
     IPage<ChannelVO> statisticsPage(@Param("pageParam")PageParam pageParam, @Param("channel")Channel channel);
+
+    List<IdNameVo> queryMyChannel(Long userId);
 }

+ 15 - 0
yami-shop-service/src/main/java/com/yami/shop/dao/SkuMapper.java

@@ -13,7 +13,11 @@ package com.yami.shop.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yami.shop.bean.model.Sku;
+import com.yami.shop.bean.po.FreightStatisticsPo;
+import com.yami.shop.bean.po.SkuStatisticsPo;
+import com.yami.shop.bean.vo.FreightStatisticsVo;
 import com.yami.shop.bean.vo.SkuBuyTogetherOftenVo;
+import com.yami.shop.bean.vo.SkuStatisticsVo;
 import com.yami.shop.common.util.PageParam;
 import org.apache.ibatis.annotations.Param;
 
@@ -57,4 +61,15 @@ public interface SkuMapper extends BaseMapper<Sku> {
                                                   @Param("channelId") Long channelId,
                                                   @Param("userId") String userId
     );
+
+    Double goodsTotalPrice(@Param("po")SkuStatisticsPo po);
+    Double totalPoints(@Param("po")SkuStatisticsPo po);
+    Double totalCash(@Param("po")SkuStatisticsPo po);
+    Double totalFreight(@Param("po")SkuStatisticsPo po);
+
+    IPage<SkuStatisticsVo> skuStatisticsList(@Param("page") PageParam<SkuStatisticsPo> page, @Param("po") SkuStatisticsPo po);
+    List<SkuStatisticsVo> skuStatisticsList2(@Param("po") SkuStatisticsPo po);
+
+    IPage<FreightStatisticsVo> freightStatisticsList(@Param("page") PageParam<FreightStatisticsPo> page, @Param("po") FreightStatisticsPo po);
+    List<FreightStatisticsVo> freightStatisticsList2(@Param("po") FreightStatisticsPo po);
 }

+ 5 - 1
yami-shop-service/src/main/java/com/yami/shop/service/ChannelService.java

@@ -3,10 +3,12 @@ package com.yami.shop.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.yami.shop.bean.model.Channel;
-import com.yami.shop.bean.model.ChannelProd;
 import com.yami.shop.bean.vo.ChannelVO;
+import com.yami.shop.bean.vo.IdNameVo;
 import com.yami.shop.common.util.PageParam;
 
+import java.util.List;
+
 /**
  * 渠道管理服务接口
  * @author fbj 2024/01/01.
@@ -20,5 +22,7 @@ public interface ChannelService extends IService<Channel> {
      * @return 渠道统计分页数据
      */
     IPage<ChannelVO> statisticsPage(PageParam pageParam, Channel channel);
+
+    List<IdNameVo> queryMyChannel(Long userId);
 }
 

+ 13 - 0
yami-shop-service/src/main/java/com/yami/shop/service/SkuService.java

@@ -13,9 +13,14 @@ package com.yami.shop.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.yami.shop.bean.model.Sku;
+import com.yami.shop.bean.po.FreightStatisticsPo;
+import com.yami.shop.bean.po.SkuStatisticsPo;
+import com.yami.shop.bean.vo.FreightStatisticsVo;
 import com.yami.shop.bean.vo.SkuBuyTogetherOftenVo;
+import com.yami.shop.bean.vo.SkuStatisticsVo;
 import com.yami.shop.common.util.PageParam;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 /**
@@ -66,4 +71,12 @@ public interface SkuService extends IService<Sku> {
     void removeSkuCacheBySkuId(Long skuId, Long prodId);
 
     IPage<SkuBuyTogetherOftenVo> buyTogetherOften(PageParam<SkuBuyTogetherOftenVo> page, Long prodId,Long shopId,Long channelId,String userId);
+
+    IPage<SkuStatisticsVo> skuStatisticsList(PageParam<SkuStatisticsPo> page, SkuStatisticsPo po);
+
+    void skuStatisticsExcel(HttpServletResponse response, SkuStatisticsPo po);
+
+    void freightStatisticsExcel(HttpServletResponse response, FreightStatisticsPo po);
+
+    IPage<FreightStatisticsVo> freightStatisticsList(PageParam<FreightStatisticsPo> page, FreightStatisticsPo po);
 }

+ 8 - 0
yami-shop-service/src/main/java/com/yami/shop/service/impl/ChannelServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yami.shop.bean.model.Channel;
 import com.yami.shop.bean.vo.ChannelVO;
+import com.yami.shop.bean.vo.IdNameVo;
 import com.yami.shop.common.util.PageParam;
 import com.yami.shop.dao.ChannelMapper;
 import com.yami.shop.service.ChannelService;
@@ -11,6 +12,8 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 渠道管理服务实现类
  *
@@ -25,4 +28,9 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
     public IPage<ChannelVO> statisticsPage(PageParam pageParam, Channel channel) {
          return baseMapper.statisticsPage(pageParam, channel);
     }
+
+    @Override
+    public List<IdNameVo> queryMyChannel(Long userId) {
+        return baseMapper.queryMyChannel(userId);
+    }
 }

+ 159 - 0
yami-shop-service/src/main/java/com/yami/shop/service/impl/SkuServiceImpl.java

@@ -10,19 +10,43 @@
 
 package com.yami.shop.service.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
+import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
+import com.alibaba.excel.write.metadata.style.WriteCellStyle;
+import com.alibaba.excel.write.metadata.style.WriteFont;
+import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yami.shop.bean.model.Sku;
+import com.yami.shop.bean.po.FreightStatisticsPo;
+import com.yami.shop.bean.po.SkuStatisticsPo;
+import com.yami.shop.bean.vo.FreightStatisticsVo;
 import com.yami.shop.bean.vo.SkuBuyTogetherOftenVo;
+import com.yami.shop.bean.vo.SkuStatisticsVo;
+import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.PageParam;
 import com.yami.shop.dao.SkuMapper;
 import com.yami.shop.service.SkuService;
+import lombok.SneakyThrows;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author lgh on 2018/09/29.
@@ -71,4 +95,139 @@ public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuSe
     public IPage<SkuBuyTogetherOftenVo> buyTogetherOften(PageParam<SkuBuyTogetherOftenVo> page, Long prodId,Long shopId,Long channelId,String userId) {
         return skuMapper.buyTogetherOften(page, prodId,shopId,channelId,userId);
     }
+
+    @Override
+    public IPage<SkuStatisticsVo> skuStatisticsList(PageParam<SkuStatisticsPo> page, SkuStatisticsPo po) {
+        return skuMapper.skuStatisticsList(page, po);
+    }
+
+
+    @Override
+    @SneakyThrows
+    public void skuStatisticsExcel(HttpServletResponse response, SkuStatisticsPo po) {
+        List<SkuStatisticsVo> skuStatisticsVoList = skuMapper.skuStatisticsList2(po);
+        Double goodsTotalPrice = skuMapper.goodsTotalPrice(po);
+        Double totalPoints = skuMapper.totalPoints(po);
+        Double totalCash = skuMapper.totalCash(po);
+        Double totalFreight = skuMapper.totalFreight(po);
+
+        String head = "对账汇总表";
+        List<String> heads = Arrays.asList(
+                "商品ID", "商品名称", "规格", "单价(元)", "商品总数量", "小计(元)",
+                "商品总额(元)", "总积分抵扣(元)", "总现金抵扣(元)", "总运费(元)"
+        );
+        List<List<String>> hs = heads.stream()
+                .map(h -> Arrays.asList(head, h))
+                .collect(Collectors.toList());
+
+        List<List<Object>> data = new ArrayList<>();
+        for (int i = 0; i < skuStatisticsVoList.size(); i++) {
+            SkuStatisticsVo sku = skuStatisticsVoList.get(i);
+            List<Object> row = new ArrayList<>();
+            row.add(sku.getSkuId());
+            row.add(sku.getSkuName());
+            row.add(sku.getSpec());
+            row.add(sku.getPrice());
+            row.add(sku.getProdCount());
+            row.add(sku.getTotal());
+
+            if (i == 0) {   // 第一行放值
+                row.add(goodsTotalPrice);
+                row.add(totalPoints);
+                row.add(totalCash);
+                row.add(totalFreight);
+            } else {        // 其余行留空
+                row.add(null);
+                row.add(null);
+                row.add(null);
+                row.add(null);
+            }
+            data.add(row);
+        }
+
+        /* 4. 样式 */
+        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
+        headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+        WriteFont headWriteFont = new WriteFont();
+        headWriteFont.setFontHeightInPoints((short) 15);
+        headWriteFont.setBold(true);
+        headWriteCellStyle.setWriteFont(headWriteFont);
+        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+
+        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
+        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
+
+        /* 5. 合并策略:数据区域第 1 行到最后一行,列 6~9 纵向合并 */
+        OnceAbsoluteMergeStrategy mergeStrategy = null;
+        if (data.size() > 1) {          // 至少两行才需要合并
+            mergeStrategy = new OnceAbsoluteMergeStrategy(2, data.size()+1, 6, 6);
+        }
+
+        OnceAbsoluteMergeStrategy mergeStrategy2 = null;
+        if (data.size() > 1) {          // 至少两行才需要合并
+            mergeStrategy2 = new OnceAbsoluteMergeStrategy(2, data.size()+1, 7, 7);
+        }
+
+        OnceAbsoluteMergeStrategy mergeStrategy3 = null;
+        if (data.size() > 1) {          // 至少两行才需要合并
+            mergeStrategy3 = new OnceAbsoluteMergeStrategy(2, data.size()+1, 8, 8);
+        }
+
+        OnceAbsoluteMergeStrategy mergeStrategy4 = null;
+        if (data.size() > 1) {          // 至少两行才需要合并
+            mergeStrategy4 = new OnceAbsoluteMergeStrategy(2, data.size()+1, 9, 9);
+        }
+
+        /* 6. 写出 */
+        String fileName = URLEncoder.encode("对账汇总表", "UTF-8").replaceAll("\\+", "%20");
+        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+
+        ExcelWriterSheetBuilder writerBuilder = EasyExcel.write(response.getOutputStream())
+                .head(hs)
+                .sheet(head)
+                .registerWriteHandler(horizontalCellStyleStrategy);
+        if (mergeStrategy != null) {
+            writerBuilder.registerWriteHandler(mergeStrategy);
+        }
+        if (mergeStrategy2 != null) {
+            writerBuilder.registerWriteHandler(mergeStrategy2);
+        }
+        if (mergeStrategy3 != null) {
+            writerBuilder.registerWriteHandler(mergeStrategy3);
+        }
+        if (mergeStrategy4 != null) {
+            writerBuilder.registerWriteHandler(mergeStrategy4);
+        }
+        writerBuilder.doWrite(data);
+    }
+
+    @Override
+    public void freightStatisticsExcel(HttpServletResponse response,FreightStatisticsPo po) {
+        try {
+            List<FreightStatisticsVo> list = skuMapper.freightStatisticsList2(po);
+            if (!list.isEmpty()){
+                list.forEach(c->{
+                    LocalDateTime dateTime = LocalDateTime.parse(c.getPayTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                    String result = dateTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
+                    c.setPayTime(result);
+                });
+            }
+            response.setCharacterEncoding("utf-8");
+            String fileName = URLEncoder.encode("运费汇总表", "UTF-8").replaceAll("\\+", "%20");
+            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+            EasyExcel.write(response.getOutputStream(), FreightStatisticsVo.class)
+                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+                    .sheet("列表").doWrite(list);
+        } catch (IOException e) {
+            throw new GlobalException("文件下载异常");
+        }
+    }
+
+    @Override
+    public IPage<FreightStatisticsVo> freightStatisticsList(PageParam<FreightStatisticsPo> page, FreightStatisticsPo po) {
+        return skuMapper.freightStatisticsList(page,po);
+    }
+
 }

+ 7 - 0
yami-shop-service/src/main/resources/mapper/ChannelMapper.xml

@@ -31,4 +31,11 @@
         group by c.id
 
     </select>
+
+    <select id="queryMyChannel" resultType="com.yami.shop.bean.vo.IdNameVo">
+        SELECT b.id,b.channel_name name FROM tz_sys_user_channel a
+        LEFT JOIN tz_channel b on a.channel_id=b.id
+        WHERE a.user_id=#{userId}
+    </select>
+
 </mapper>

+ 459 - 0
yami-shop-service/src/main/resources/mapper/SkuMapper.xml

@@ -200,4 +200,463 @@
         ORDER BY a.rec_time desc, a.order_item_id desc
     </select>
 
+    <select id="goodsTotalPrice" resultType="Double">
+        SELECT (SELECT SUM(IFNULL(total,0)) goods_total_price FROM tz_order
+        WHERE is_payed=1
+        <if test="po.startTime != null and po.startTime != ''">
+            and create_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and create_time&lt;= #{po.endTime}
+        </if>
+        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+        and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
+                                                <where>
+                                                    <if test="po.skuId != null">
+                                                        AND a.sku_id like concat('%',#{po.skuId} ,'%')
+                                                    </if>
+
+                                                    <if test="po.skuName != null and po.skuName != ''">
+                                                        AND a.sku_name like concat('%',#{po.skuName} ,'%')
+                                                    </if>
+
+                                                    <if test="po.spec != null and po.spec != ''">
+                                                        AND b.spec like concat('%',#{po.spec} ,'%')
+                                                    </if>
+                                                </where>
+            )
+        </if>
+
+          and channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        )
+        -
+        (SELECT IFNULL(SUM(a.sku_price * product_count),0)
+        FROM `tz_order_refund_sku` a
+        LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
+        LEFT JOIN tz_order c on b.order_number=c.order_number
+        LEFT JOIN tz_sku d on a.sku_id=d.sku_id
+        WHERE b.return_money_sts=70
+        <if test="po.startTime != null and po.startTime != ''">
+            and b.apply_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and b.apply_time&lt;= #{po.endTime}
+        </if>
+        and c.channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+
+        <if test="po.skuId != null">
+            AND a.sku_id like concat('%',#{po.skuId} ,'%')
+        </if>
+
+        <if test="po.skuName != null and po.skuName != ''">
+            AND d.sku_name like concat('%',#{po.skuName} ,'%')
+        </if>
+
+        <if test="po.spec != null and po.spec != ''">
+            AND d.spec like concat('%',#{po.spec} ,'%')
+        </if>
+
+        ) goods_total_price
+    </select>
+
+    <select id="totalPoints" resultType="Double">
+        SELECT TRUNCATE(((SELECT SUM(IFNULL(offset_points,0)) FROM tz_order
+        WHERE is_payed=1
+        <if test="po.startTime != null and po.startTime != ''">
+            and create_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and create_time&lt;= #{po.endTime}
+        </if>
+        and channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+            and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
+            <where>
+                <if test="po.skuId != null">
+                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
+                </if>
+
+                <if test="po.skuName != null and po.skuName != ''">
+                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
+                </if>
+
+                <if test="po.spec != null and po.spec != ''">
+                    AND b.spec like concat('%',#{po.spec} ,'%')
+                </if>
+            </where>
+            )
+        </if>
+        )
+        -
+        (SELECT  IFNULL(SUM( total_offset_points ),0)  FROM (SELECT
+        CASE
+        WHEN refund_type=1 THEN total_offset_points
+        ELSE total_offset_points+ (freight_amount * 100)
+        END AS total_offset_points
+        FROM tz_order_refund a
+        LEFT JOIN (SELECT SUM(tor.offset_points) total_offset_points ,tor.order_number
+        FROM tz_order_refund tor
+        WHERE tor.return_money_sts=70
+        <if test="po.startTime != null and po.startTime != ''">
+            and tor.apply_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and tor.apply_time&lt;= #{po.endTime}
+        </if>
+            and tor.order_number in(SELECT ao.order_number FROM tz_order_item ao
+                LEFT JOIN tz_sku b on ao.sku_id=b.sku_id
+                LEFT JOIN tz_order c on ao.order_number=c.order_number
+            <where>
+                 c.channel_id in
+                <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+                    #{id}
+                </foreach>
+                <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+                <if test="po.skuId != null">
+                    AND ao.sku_id like concat('%',#{po.skuId} ,'%')
+                </if>
+                <if test="po.skuName != null and po.skuName != ''">
+                    AND ao.sku_name like concat('%',#{po.skuName} ,'%')
+                </if>
+                <if test="po.spec != null and po.spec != ''">
+                    AND b.spec like concat('%',#{po.spec} ,'%')
+                </if>
+                </if>
+            </where>
+            )
+        GROUP BY tor.order_number) b on a.order_number=b.order_number
+        WHERE return_money_sts=70
+        <if test="po.startTime != null and po.startTime != ''">
+            and apply_time &gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and apply_time &lt;= #{po.endTime}
+        </if>
+            and a.order_number in(SELECT ao2.order_number FROM tz_order_item ao2
+        LEFT JOIN tz_sku b on ao2.sku_id=b.sku_id
+        LEFT JOIN tz_order c on ao2.order_number=c.order_number
+        <where>
+            c.channel_id in
+            <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
+            <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+                <if test="po.skuId != null">
+                    AND ao2.sku_id like concat('%',#{po.skuId} ,'%')
+                </if>
+                <if test="po.skuName != null and po.skuName != ''">
+                    AND ao2.sku_name like concat('%',#{po.skuName} ,'%')
+                </if>
+                <if test="po.spec != null and po.spec != ''">
+                    AND b.spec like concat('%',#{po.spec} ,'%')
+                </if>
+            </if>
+        </where>
+        )
+        GROUP BY a.order_number) a)) /100,2) total_offset_points
+    </select>
+
+    <select id="totalCash" resultType="Double">
+        SELECT (SELECT SUM(IFNULL(actual_total,0)) FROM tz_order WHERE is_payed=1
+        <if test="po.startTime != null and po.startTime != ''">
+            and create_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and create_time&lt;= #{po.endTime}
+        </if>
+        and channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+            and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
+            <where>
+                <if test="po.skuId != null">
+                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
+                </if>
+                <if test="po.skuName != null and po.skuName != ''">
+                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
+                </if>
+                <if test="po.spec != null and po.spec != ''">
+                    AND b.spec like concat('%',#{po.spec} ,'%')
+                </if>
+            </where>
+            )
+        </if>
+                                                                 )
+        -
+        (SELECT IFNULL(SUM( refund_amount ),0) FROM tz_order_refund WHERE return_money_sts=70
+        <if test="po.startTime != null and po.startTime != ''">
+            and apply_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and apply_time&lt;= #{po.endTime}
+        </if>
+        and order_number in(SELECT a.order_number FROM tz_order_item a
+        LEFT JOIN tz_sku b on a.sku_id=b.sku_id
+        LEFT JOIN tz_order c on a.order_number=c.order_number
+        <where>
+            c.channel_id in
+            <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
+            <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+                <if test="po.skuId != null">
+                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
+                </if>
+                <if test="po.skuName != null and po.skuName != ''">
+                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
+                </if>
+                <if test="po.spec != null and po.spec != ''">
+                    AND b.spec like concat('%',#{po.spec} ,'%')
+                </if>
+            </if>
+        </where>
+        )) cash
+    </select>
+
+    <select id="totalFreight" resultType="Double">
+        SELECT (SELECT IFNULL(SUM(freight_amount),0) total_freight FROM tz_order
+        WHERE is_payed=1
+        <if test="po.startTime != null and po.startTime != ''">
+            and create_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and create_time&lt;= #{po.endTime}
+        </if>
+        and channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+            and order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
+            <where>
+                <if test="po.skuId != null">
+                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
+                </if>
+
+                <if test="po.skuName != null and po.skuName != ''">
+                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
+                </if>
+
+                <if test="po.spec != null and po.spec != ''">
+                    AND b.spec like concat('%',#{po.spec} ,'%')
+                </if>
+            </where>
+            )
+        </if>
+        )
+        -
+        (SELECT IFNULL(SUM(freight_amount),0)
+        FROM `tz_order_refund`
+        WHERE return_money_sts=70
+        <if test="po.startTime != null and po.startTime != ''">
+            and apply_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and apply_time&lt;= #{po.endTime}
+        </if>
+          and refund_type=1
+        and order_number in(SELECT a.order_number FROM tz_order_item a
+        LEFT JOIN tz_sku b on a.sku_id=b.sku_id
+        LEFT JOIN tz_order c on a.order_number=c.order_number
+        <where>
+            c.channel_id in
+            <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
+            <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
+                <if test="po.skuId != null">
+                    AND a.sku_id like concat('%',#{po.skuId} ,'%')
+                </if>
+                <if test="po.skuName != null and po.skuName != ''">
+                    AND a.sku_name like concat('%',#{po.skuName} ,'%')
+                </if>
+                <if test="po.spec != null and po.spec != ''">
+                    AND b.spec like concat('%',#{po.spec} ,'%')
+                </if>
+            </if>
+        </where>
+        ))
+    </select>
+
+    <select id="skuStatisticsList" resultType="com.yami.shop.bean.vo.SkuStatisticsVo">
+        SELECT a.prod_id,a.sku_id,a.sku_name,c.spec,TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) price,IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0) as prod_count,
+        TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) * (IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0)) total
+        FROM tz_order_item a
+        LEFT JOIN tz_order b on a.order_number=b.order_number
+        LEFT JOIN tz_sku c on a.sku_id=c.sku_id
+        LEFT JOIN (SELECT a.sku_id,SUM(a.product_count) product_count
+        FROM `tz_order_refund_sku` a
+        LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
+        WHERE return_money_sts=70
+
+        <if test="po.startTime != null and po.startTime != ''">
+            and b.apply_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and b.apply_time&lt;= #{po.endTime}
+        </if>
+        GROUP BY a.sku_id) d on a.sku_id = d.sku_id
+
+        WHERE b.is_payed=1
+        <if test="po.startTime != null and po.startTime != ''">
+            and a.rec_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and a.rec_time&lt;= #{po.endTime}
+        </if>
+        and b.channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        <if test="po.skuId != null">
+            AND a.sku_id like concat('%',#{po.skuId} ,'%')
+        </if>
+
+        <if test="po.skuName != null and po.skuName != ''">
+            AND a.sku_name like concat('%',#{po.skuName} ,'%')
+        </if>
+
+        <if test="po.spec != null and po.spec != ''">
+            AND c.spec like concat('%',#{po.spec} ,'%')
+        </if>
+        GROUP BY a.sku_id HAVING prod_count>0
+    </select>
+
+    <select id="skuStatisticsList2" resultType="com.yami.shop.bean.vo.SkuStatisticsVo">
+        SELECT a.prod_id,a.sku_id,a.sku_name,c.spec,TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) price,IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0) as prod_count,
+        TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) * (IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0)) total
+        FROM tz_order_item a
+        LEFT JOIN tz_order b on a.order_number=b.order_number
+        LEFT JOIN tz_sku c on a.sku_id=c.sku_id
+        LEFT JOIN (SELECT a.sku_id,SUM(a.product_count) product_count
+        FROM `tz_order_refund_sku` a
+        LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
+        WHERE return_money_sts=70
+
+        <if test="po.startTime != null and po.startTime != ''">
+            and b.apply_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and b.apply_time&lt;= #{po.endTime}
+        </if>
+        GROUP BY a.sku_id) d on a.sku_id = d.sku_id
+
+        WHERE b.is_payed=1
+        <if test="po.startTime != null and po.startTime != ''">
+            and a.rec_time&gt;= #{po.startTime}
+        </if>
+
+        <if test="po.endTime != null and po.endTime != ''">
+            and a.rec_time&lt;= #{po.endTime}
+        </if>
+        and b.channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        <if test="po.skuId != null">
+            AND a.sku_id like concat('%',#{po.skuId} ,'%')
+        </if>
+
+        <if test="po.skuName != null and po.skuName != ''">
+            AND a.sku_name like concat('%',#{po.skuName} ,'%')
+        </if>
+
+        <if test="po.spec != null and po.spec != ''">
+            AND c.spec like concat('%',#{po.spec} ,'%')
+        </if>
+        GROUP BY a.sku_id HAVING prod_count>0
+    </select>
+
+    <select id="freightStatisticsList" resultType="com.yami.shop.bean.vo.FreightStatisticsVo">
+        SELECT @row_number := @row_number + 1 AS sort,a.pay_time,CONCAT(b.receiver,'  ',b.mobile) receiver,a.dvy_flow_id delivery_no,b.address to_address,a.freight_amount money,a.order_number order_no
+        FROM (SELECT @row_number := 0) sort,
+        tz_order a
+        LEFT JOIN tz_user_addr_order b on a.addr_order_id =b.addr_order_id
+        WHERE a.is_payed=1 and a.dvy_type=1 and a.hb_order_status not in(0,60)
+        and a.channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+
+        <if test="po.receiver != null and po.receiver != ''">
+            AND b.receiver like concat('%',#{po.receiver} ,'%')
+        </if>
+        <if test="po.mobile != null and po.mobile != ''">
+            AND b.mobile like concat('%',#{po.mobile} ,'%')
+        </if>
+        <if test="po.deliveryNo != null and po.deliveryNo != ''">
+            AND a.dvy_flow_id like concat('%',#{po.deliveryNo} ,'%')
+        </if>
+        <if test="po.toAddress != null and po.toAddress != ''">
+            AND b.address like concat('%',#{po.toAddress} ,'%')
+        </if>
+        <if test="po.orderNo != null and po.orderNo != ''">
+            AND a.order_number like concat('%',#{po.orderNo} ,'%')
+        </if>
+        <if test="po.startTime != null and po.startTime != ''">
+            and a.pay_time&gt;= #{po.startTime}
+        </if>
+        <if test="po.endTime != null and po.endTime != ''">
+            and a.pay_time&lt;= #{po.endTime}
+        </if>
+    </select>
+
+    <select id="freightStatisticsList2" resultType="com.yami.shop.bean.vo.FreightStatisticsVo">
+        SELECT @row_number := @row_number + 1 AS sort,a.pay_time,CONCAT(b.receiver,'  ',b.mobile) receiver,a.dvy_flow_id delivery_no,b.address to_address,a.freight_amount money,a.order_number order_no
+        FROM (SELECT @row_number := 0) sort,
+        tz_order a
+        LEFT JOIN tz_user_addr_order b on a.addr_order_id =b.addr_order_id
+        WHERE a.is_payed=1 and a.dvy_type=1 and a.hb_order_status not in(0,60)
+        and a.channel_id in
+        <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+
+        <if test="po.receiver != null and po.receiver != ''">
+            AND b.receiver like concat('%',#{po.receiver} ,'%')
+        </if>
+        <if test="po.mobile != null and po.mobile != ''">
+            AND b.mobile like concat('%',#{po.mobile} ,'%')
+        </if>
+        <if test="po.deliveryNo != null and po.deliveryNo != ''">
+            AND a.dvy_flow_id like concat('%',#{po.deliveryNo} ,'%')
+        </if>
+        <if test="po.toAddress != null and po.toAddress != ''">
+            AND b.address like concat('%',#{po.toAddress} ,'%')
+        </if>
+        <if test="po.orderNo != null and po.orderNo != ''">
+            AND a.order_number like concat('%',#{po.orderNo} ,'%')
+        </if>
+        <if test="po.startTime != null and po.startTime != ''">
+            and a.pay_time&gt;= #{po.startTime}
+        </if>
+        <if test="po.endTime != null and po.endTime != ''">
+            and a.pay_time&lt;= #{po.endTime}
+        </if>
+    </select>
+
+
 </mapper>