Browse Source

更新每日账单功能

Yangzw 8 months ago
parent
commit
9d1f8cc9ca
19 changed files with 624 additions and 53 deletions
  1. 1 0
      feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/enums/ErrorCodeConstants.java
  2. 2 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/dailybill/vo/DailyBillPageReqVO.java
  3. 4 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/dailybill/vo/DailyBillRespVO.java
  4. 4 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/dailybill/vo/DailyBillSaveReqVO.java
  5. 94 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/PtDailyBillController.java
  6. 51 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/vo/PtDailyBillPageReqVO.java
  7. 63 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/vo/PtDailyBillRespVO.java
  8. 52 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/vo/PtDailyBillSaveReqVO.java
  9. 4 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/dailybill/DailyBillDO.java
  10. 66 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/ptdailybill/PtDailyBillDO.java
  11. 6 1
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/dailybill/DailyBillMapper.java
  12. 34 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/ptdailybill/PtDailyBillMapper.java
  13. 80 49
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/dailybill/DailyBillServiceImpl.java
  14. 4 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/dailybill/dto/OrderDTO.java
  15. 53 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ptdailybill/PtDailyBillService.java
  16. 70 0
      feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ptdailybill/PtDailyBillServiceImpl.java
  17. 3 3
      feifan-module-distri/feifan-module-distri-biz/src/main/resources/mapper/dailybill/DailyBillMapper.xml
  18. 12 0
      feifan-module-distri/feifan-module-distri-biz/src/main/resources/mapper/ptdailybill/PtDailyBillMapper.xml
  19. 21 0
      sql/mysql/建空库SQL/16_20240704.sql

+ 1 - 0
feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/enums/ErrorCodeConstants.java

@@ -35,5 +35,6 @@ public interface ErrorCodeConstants {
     ErrorCode ORDER_SETTLEMENT_NOT_EXISTS = new ErrorCode(1_002_030_028, "该结算订单二级表记录不存在");
     ErrorCode ORDER_ITEM_SETTLEMENT_NOT_EXISTS = new ErrorCode(1_002_030_029, "该结算订单项二级表记录不存在");
     ErrorCode PT_SETTLEMENT_NOT_EXISTS = new ErrorCode(1_002_030_030, "平台结算记录不存在");
+    ErrorCode PT_DAILY_BILL_NOT_EXISTS = new ErrorCode(1_002_030_031, "平台每日账单不存在");
 
 }

+ 2 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/dailybill/vo/DailyBillPageReqVO.java

@@ -53,5 +53,7 @@ public class DailyBillPageReqVO extends PageParam {
     @Schema(description = "订单所属日期")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDate[] orderCalcTime;
+    @Schema(description = "平台每日账单表id", example = "6905")
+    private Long ptDailyBillId;
 
 }

+ 4 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/dailybill/vo/DailyBillRespVO.java

@@ -72,6 +72,10 @@ public class DailyBillRespVO {
     @ExcelProperty("订单所属日期")
     private LocalDate orderCalcTime;
 
+    @Schema(description = "平台每日账单表id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6905")
+    @ExcelProperty("平台每日账单表id")
+    private Long ptDailyBillId;
+
     public String getOrderCalcTime() {
         return orderCalcTime.toString();
     }

+ 4 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/dailybill/vo/DailyBillSaveReqVO.java

@@ -55,4 +55,8 @@ public class DailyBillSaveReqVO {
     @NotNull(message = "订单所属日期不能为空")
     private LocalDate orderCalcTime;
 
+    @Schema(description = "平台每日账单表id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6905")
+    @NotNull(message = "平台每日账单表id不能为空")
+    private Long ptDailyBillId;
+
 }

+ 94 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/PtDailyBillController.java

@@ -0,0 +1,94 @@
+package cn.newfeifan.mall.module.distri.controller.admin.ptdailybill;
+
+import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.security.access.prepost.PreAuthorize;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Operation;
+
+import javax.validation.*;
+import javax.servlet.http.*;
+import java.util.*;
+import java.io.IOException;
+
+import cn.newfeifan.mall.framework.common.pojo.PageParam;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.common.pojo.CommonResult;
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
+
+import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;
+
+import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
+import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.*;
+
+import cn.newfeifan.mall.module.distri.controller.admin.ptdailybill.vo.*;
+import cn.newfeifan.mall.module.distri.dal.dataobject.ptdailybill.PtDailyBillDO;
+import cn.newfeifan.mall.module.distri.service.ptdailybill.PtDailyBillService;
+
+@Tag(name = "管理后台 - 平台每日账单统计")
+@RestController
+@RequestMapping("/distri/pt-daily-bill")
+@Validated
+public class PtDailyBillController {
+
+    @Resource
+    private PtDailyBillService ptDailyBillService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建平台每日账单统计")
+    @PreAuthorize("@ss.hasPermission('distri:pt-daily-bill:create')")
+    public CommonResult<Long> createPtDailyBill(@Valid @RequestBody PtDailyBillSaveReqVO createReqVO) {
+        return success(ptDailyBillService.createPtDailyBill(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新平台每日账单统计")
+    @PreAuthorize("@ss.hasPermission('distri:pt-daily-bill:update')")
+    public CommonResult<Boolean> updatePtDailyBill(@Valid @RequestBody PtDailyBillSaveReqVO updateReqVO) {
+        ptDailyBillService.updatePtDailyBill(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除平台每日账单统计")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('distri:pt-daily-bill:delete')")
+    public CommonResult<Boolean> deletePtDailyBill(@RequestParam("id") Long id) {
+        ptDailyBillService.deletePtDailyBill(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得平台每日账单统计")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('distri:pt-daily-bill:query')")
+    public CommonResult<PtDailyBillRespVO> getPtDailyBill(@RequestParam("id") Long id) {
+        PtDailyBillDO ptDailyBill = ptDailyBillService.getPtDailyBill(id);
+        return success(BeanUtils.toBean(ptDailyBill, PtDailyBillRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得平台每日账单统计分页")
+    @PreAuthorize("@ss.hasPermission('distri:pt-daily-bill:query')")
+    public CommonResult<PageResult<PtDailyBillRespVO>> getPtDailyBillPage(@Valid PtDailyBillPageReqVO pageReqVO) {
+        PageResult<PtDailyBillDO> pageResult = ptDailyBillService.getPtDailyBillPage(pageReqVO);
+        return success(BeanUtils.toBean(pageResult, PtDailyBillRespVO.class));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出平台每日账单统计 Excel")
+    @PreAuthorize("@ss.hasPermission('distri:pt-daily-bill:export')")
+    @OperateLog(type = EXPORT)
+    public void exportPtDailyBillExcel(@Valid PtDailyBillPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<PtDailyBillDO> list = ptDailyBillService.getPtDailyBillPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "平台每日账单统计.xls", "数据", PtDailyBillRespVO.class,
+                        BeanUtils.toBean(list, PtDailyBillRespVO.class));
+    }
+
+}

+ 51 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/vo/PtDailyBillPageReqVO.java

@@ -0,0 +1,51 @@
+package cn.newfeifan.mall.module.distri.controller.admin.ptdailybill.vo;
+
+import lombok.*;
+
+import java.time.LocalDate;
+import io.swagger.v3.oas.annotations.media.Schema;
+import cn.newfeifan.mall.framework.common.pojo.PageParam;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.time.LocalDateTime;
+
+import static cn.newfeifan.mall.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 平台每日账单统计分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class PtDailyBillPageReqVO extends PageParam {
+
+    @Schema(description = "金额,单位:分", example = "24178")
+    private Long price;
+
+    @Schema(description = "确收金额,单位:分", example = "4933")
+    private Long receivedPrice;
+
+    @Schema(description = "订单数,默认为0", example = "24153")
+    private Long orderCount;
+
+    @Schema(description = "退款金额, 单位: 分", example = "25468")
+    private Long refundPrice;
+
+    @Schema(description = "积分")
+    private Long integral;
+
+    @Schema(description = "确收积分")
+    private Long receivedIntegral;
+
+    @Schema(description = "退款积分")
+    private Long refundIntegral;
+
+    @Schema(description = "订单所属日期")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDate[] orderCalcTime;
+
+    @Schema(description = "订单ID列表,文本类型")
+    private String orderIds;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 63 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/vo/PtDailyBillRespVO.java

@@ -0,0 +1,63 @@
+package cn.newfeifan.mall.module.distri.controller.admin.ptdailybill.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import com.alibaba.excel.annotation.*;
+
+@Schema(description = "管理后台 - 平台每日账单统计 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class PtDailyBillRespVO {
+
+    @Schema(description = "账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4121")
+    @ExcelProperty("账单编号")
+    private Long id;
+
+    @Schema(description = "金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "24178")
+    @ExcelProperty("金额,单位:分")
+    private Long price;
+
+    @Schema(description = "确收金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "4933")
+    @ExcelProperty("确收金额,单位:分")
+    private Long receivedPrice;
+
+    @Schema(description = "订单数,默认为0", requiredMode = Schema.RequiredMode.REQUIRED, example = "24153")
+    @ExcelProperty("订单数,默认为0")
+    private Long orderCount;
+
+    @Schema(description = "退款金额, 单位: 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "25468")
+    @ExcelProperty("退款金额, 单位: 分")
+    private Long refundPrice;
+
+    @Schema(description = "积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("积分")
+    private Long integral;
+
+    @Schema(description = "确收积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("确收积分")
+    private Long receivedIntegral;
+
+    @Schema(description = "退款积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("退款积分")
+    private Long refundIntegral;
+
+    @Schema(description = "订单所属日期", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("订单所属日期")
+    private LocalDate orderCalcTime;
+
+    @Schema(description = "订单ID列表,文本类型", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("订单ID列表,文本类型")
+    private String orderIds;
+
+    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+    public String getOrderCalcTime() {
+        return orderCalcTime.toString();
+    }
+
+}

+ 52 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/ptdailybill/vo/PtDailyBillSaveReqVO.java

@@ -0,0 +1,52 @@
+package cn.newfeifan.mall.module.distri.controller.admin.ptdailybill.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+
+import java.time.LocalDate;
+import javax.validation.constraints.*;
+
+@Schema(description = "管理后台 - 平台每日账单统计新增/修改 Request VO")
+@Data
+public class PtDailyBillSaveReqVO {
+
+    @Schema(description = "账单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4121")
+    private Long id;
+
+    @Schema(description = "金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "24178")
+    @NotNull(message = "金额,单位:分不能为空")
+    private Long price;
+
+    @Schema(description = "确收金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "4933")
+    @NotNull(message = "确收金额,单位:分不能为空")
+    private Long receivedPrice;
+
+    @Schema(description = "订单数,默认为0", requiredMode = Schema.RequiredMode.REQUIRED, example = "24153")
+    @NotNull(message = "订单数,默认为0不能为空")
+    private Long orderCount;
+
+    @Schema(description = "退款金额, 单位: 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "25468")
+    @NotNull(message = "退款金额, 单位: 分不能为空")
+    private Long refundPrice;
+
+    @Schema(description = "积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotNull(message = "积分不能为空")
+    private Long integral;
+
+    @Schema(description = "确收积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotNull(message = "确收积分不能为空")
+    private Long receivedIntegral;
+
+    @Schema(description = "退款积分", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotNull(message = "退款积分不能为空")
+    private Long refundIntegral;
+
+    @Schema(description = "订单所属日期", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotNull(message = "订单所属日期不能为空")
+    private LocalDate orderCalcTime;
+
+    @Schema(description = "订单ID列表,文本类型", requiredMode = Schema.RequiredMode.REQUIRED)
+    @NotEmpty(message = "订单ID列表,文本类型不能为空")
+    private String orderIds;
+
+}

+ 4 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/dailybill/DailyBillDO.java

@@ -70,5 +70,9 @@ public class DailyBillDO extends BaseDO {
      * 订单所属日期
      */
     private LocalDate orderCalcTime;
+    /**
+     * 平台每日账单表id
+     */
+    private Long ptDailyBillId;
 
 }

+ 66 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/dataobject/ptdailybill/PtDailyBillDO.java

@@ -0,0 +1,66 @@
+package cn.newfeifan.mall.module.distri.dal.dataobject.ptdailybill;
+
+import lombok.*;
+
+import java.time.LocalDate;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.newfeifan.mall.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 平台每日账单统计 DO
+ *
+ * @author 非繁人
+ */
+@TableName("distri_pt_daily_bill")
+@KeySequence("distri_pt_daily_bill_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class PtDailyBillDO extends BaseDO {
+
+    /**
+     * 账单编号
+     */
+    @TableId
+    private Long id;
+    /**
+     * 金额,单位:分
+     */
+    private Long price;
+    /**
+     * 确收金额,单位:分
+     */
+    private Long receivedPrice;
+    /**
+     * 订单数,默认为0
+     */
+    private Long orderCount;
+    /**
+     * 退款金额, 单位: 分
+     */
+    private Long refundPrice;
+    /**
+     * 积分
+     */
+    private Long integral;
+    /**
+     * 确收积分
+     */
+    private Long receivedIntegral;
+    /**
+     * 退款积分
+     */
+    private Long refundIntegral;
+    /**
+     * 订单所属日期
+     */
+    private LocalDate orderCalcTime;
+    /**
+     * 订单ID列表,文本类型
+     */
+    private String orderIds;
+
+}

+ 6 - 1
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/dailybill/DailyBillMapper.java

@@ -29,13 +29,18 @@ public interface DailyBillMapper extends BaseMapperX<DailyBillDO> {
                 .eqIfPresent(DailyBillDO::getMerchantId, reqVO.getMerchantId())
                 .eqIfPresent(DailyBillDO::getOrderIds, reqVO.getOrderIds())
                 .betweenIfPresent(DailyBillDO::getCreateTime, reqVO.getCreateTime())
+                .eqIfPresent(DailyBillDO::getRefundPrice, reqVO.getRefundPrice())
+                .eqIfPresent(DailyBillDO::getIntegral, reqVO.getIntegral())
+                .eqIfPresent(DailyBillDO::getReceivedIntegral, reqVO.getReceivedIntegral())
+                .eqIfPresent(DailyBillDO::getRefundIntegral, reqVO.getRefundIntegral())
                 .betweenIfPresent(DailyBillDO::getOrderCalcTime, reqVO.getOrderCalcTime())
+                .eqIfPresent(DailyBillDO::getPtDailyBillId, reqVO.getPtDailyBillId())
                 .orderByDesc(DailyBillDO::getId));
     }
 
     List<MerchantDTO> getMerchantDTO();
 
-    List<OrderDTO> getOrderDetailsByMerchantIdWithsShopId(@Param("merchantId") Long merchantId, @Param("shopId") Long shopId);
+    List<OrderDTO> getOrderDetails();
 
     void updateOrderItemByOrderId(@Param("orderIds") List<Long> orderIds);
 

+ 34 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/ptdailybill/PtDailyBillMapper.java

@@ -0,0 +1,34 @@
+package cn.newfeifan.mall.module.distri.dal.mysql.ptdailybill;
+
+
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
+import cn.newfeifan.mall.module.distri.dal.dataobject.ptdailybill.PtDailyBillDO;
+import org.apache.ibatis.annotations.Mapper;
+import cn.newfeifan.mall.module.distri.controller.admin.ptdailybill.vo.*;
+
+/**
+ * 平台每日账单统计 Mapper
+ *
+ * @author 非繁人
+ */
+@Mapper
+public interface PtDailyBillMapper extends BaseMapperX<PtDailyBillDO> {
+
+    default PageResult<PtDailyBillDO> selectPage(PtDailyBillPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<PtDailyBillDO>()
+                .eqIfPresent(PtDailyBillDO::getPrice, reqVO.getPrice())
+                .eqIfPresent(PtDailyBillDO::getReceivedPrice, reqVO.getReceivedPrice())
+                .eqIfPresent(PtDailyBillDO::getOrderCount, reqVO.getOrderCount())
+                .eqIfPresent(PtDailyBillDO::getRefundPrice, reqVO.getRefundPrice())
+                .eqIfPresent(PtDailyBillDO::getIntegral, reqVO.getIntegral())
+                .eqIfPresent(PtDailyBillDO::getReceivedIntegral, reqVO.getReceivedIntegral())
+                .eqIfPresent(PtDailyBillDO::getRefundIntegral, reqVO.getRefundIntegral())
+                .betweenIfPresent(PtDailyBillDO::getOrderCalcTime, reqVO.getOrderCalcTime())
+                .eqIfPresent(PtDailyBillDO::getOrderIds, reqVO.getOrderIds())
+                .betweenIfPresent(PtDailyBillDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(PtDailyBillDO::getId));
+    }
+
+}

+ 80 - 49
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/dailybill/DailyBillServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.newfeifan.mall.module.distri.service.dailybill;
 
-import cn.newfeifan.mall.module.distri.service.dailybill.dto.MerchantDTO;
+import cn.newfeifan.mall.module.distri.dal.dataobject.ptdailybill.PtDailyBillDO;
+import cn.newfeifan.mall.module.distri.dal.mysql.ptdailybill.PtDailyBillMapper;
 import cn.newfeifan.mall.module.distri.service.dailybill.dto.OrderDTO;
 import org.springframework.stereotype.Service;
 
@@ -36,6 +37,8 @@ public class DailyBillServiceImpl implements DailyBillService {
 
     @Resource
     private DailyBillMapper dailyBillMapper;
+    @Resource
+    private PtDailyBillMapper ptDailyBillMapper;
 
     @Override
     public Long createDailyBill(DailyBillSaveReqVO createReqVO) {
@@ -88,55 +91,83 @@ public class DailyBillServiceImpl implements DailyBillService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void caleDailyBill() {
-        // 获取所有商户及旗下的店铺
-        List<MerchantDTO> merchantDTOS = dailyBillMapper.getMerchantDTO();
-
-        merchantDTOS.forEach(merchantDTO -> {
-            merchantDTO.getShopIds().forEach(shopId -> {
-                // 获取每个店铺的订单列表
-                List<OrderDTO> orderDetails = dailyBillMapper.getOrderDetailsByMerchantIdWithsShopId(merchantDTO.getMerchantId(), shopId);
-
-                // 使用Stream API和Collectors.groupingBy按照日期分组,并按时间倒序排序每个日期的Order列表
-                Map<LocalDate, List<OrderDTO>> ordersByDate = orderDetails.stream()
-                        .collect(Collectors.groupingBy(order -> order.getCreateTime().toLocalDate(),
-                                LinkedHashMap::new, // 保持插入顺序
-                                Collectors.toList()));
-
-                // 计算分组结果,并按订单创建时间倒序输出每个日期的订单
-                ordersByDate.forEach((date, orderList) -> {
-
-                    Long price = orderList.stream()
-                            .mapToLong(OrderDTO::getPayPrice)
-                            .sum();
-                    Long refundPrice = orderList.stream()
-                            .mapToLong(OrderDTO::getRefundPrice)
-                            .sum();
-                    Long integral = orderList.stream()
-                            .mapToLong(OrderDTO::getPayIntegral)
-                            .sum();
-                    Long refundIntegral = orderList.stream()
-                            .filter(order -> order.getRefundIntegral() != null)  // 过滤掉 getRefundIntegral 为空的订单
-                            .mapToLong(OrderDTO::getRefundIntegral)
-                            .sum();
-
-                    DailyBillDO dailyBillDO = DailyBillDO.builder()
-                            .price(price)
-                            .refundPrice(refundPrice)
-                            .receivedPrice(price - refundPrice)
-                            .integral(integral)
-                            .refundIntegral(refundIntegral)
-                            .receivedIntegral(integral - refundIntegral)
-                            .orderCount((long) orderList.size())
-                            .shopId(shopId)
-                            .merchantId(merchantDTO.getMerchantId())
-                            .orderIds(orderList.stream().map(OrderDTO::getId).collect(Collectors.toList()).toString())
-                            .orderCalcTime(date)
-                            .build();
-
-                    dailyBillMapper.insert(dailyBillDO);
-                    dailyBillMapper.updateOrderItemByOrderId(orderList.stream().map(OrderDTO::getId).collect(Collectors.toList()));
-                });
+        // 获取每天的订单列表
+        List<OrderDTO> orderDetails = dailyBillMapper.getOrderDetails();
+        // 使用Stream API和Collectors.groupingBy按照日期分组,并按时间倒序排序每个日期的Order列表
+        Map<LocalDate, List<OrderDTO>> ordersByDate = orderDetails.stream()
+                .collect(Collectors.groupingBy(order -> order.getCreateTime().toLocalDate(),
+                        LinkedHashMap::new, // 保持插入顺序
+                        Collectors.toList()));
+
+        ordersByDate.forEach((date, orderList) -> {
+            // 计算分组结果,并按订单创建时间倒序输出每个日期的订单
+
+            Long ptPrice = orderList.stream()
+                    .mapToLong(OrderDTO::getPayPrice)
+                    .sum();
+            Long ptRefundPrice = orderList.stream()
+                    .mapToLong(OrderDTO::getRefundPrice)
+                    .sum();
+            Long ptIntegral = orderList.stream()
+                    .mapToLong(OrderDTO::getPayIntegral)
+                    .sum();
+            Long ptRefundIntegral = orderList.stream()
+                    .filter(order -> order.getRefundIntegral() != null)  // 过滤掉 getRefundIntegral 为空的订单
+                    .mapToLong(OrderDTO::getRefundIntegral)
+                    .sum();
+
+            PtDailyBillDO ptDailyBillDO = PtDailyBillDO.builder()
+                    .price(ptPrice)
+                    .refundPrice(ptRefundPrice)
+                    .receivedPrice(ptPrice - ptRefundPrice)
+                    .integral(ptIntegral)
+                    .refundIntegral(ptRefundIntegral)
+                    .receivedIntegral(ptIntegral - ptRefundIntegral)
+                    .orderCount((long) orderList.size())
+                    .orderIds(orderList.stream().map(OrderDTO::getId).collect(Collectors.toList()).toString())
+                    .orderCalcTime(date)
+                    .build();
+
+            ptDailyBillMapper.insert(ptDailyBillDO);
+
+            Map<Long, List<OrderDTO>> dailyBillByShop = orderList.stream()
+                    .collect(Collectors.groupingBy(OrderDTO::getShopId,
+                            Collectors.toList()));
+
+            dailyBillByShop.forEach((shopId, shopOrderList) -> {
+                Long price = shopOrderList.stream()
+                        .mapToLong(OrderDTO::getPayPrice)
+                        .sum();
+                Long refundPrice = shopOrderList.stream()
+                        .mapToLong(OrderDTO::getRefundPrice)
+                        .sum();
+                Long integral = shopOrderList.stream()
+                        .mapToLong(OrderDTO::getPayIntegral)
+                        .sum();
+                Long refundIntegral = shopOrderList.stream()
+                        .filter(order -> order.getRefundIntegral() != null)  // 过滤掉 getRefundIntegral 为空的订单
+                        .mapToLong(OrderDTO::getRefundIntegral)
+                        .sum();
+
+                DailyBillDO dailyBillDO = DailyBillDO.builder()
+                        .price(price)
+                        .refundPrice(refundPrice)
+                        .receivedPrice(price - refundPrice)
+                        .integral(integral)
+                        .refundIntegral(refundIntegral)
+                        .receivedIntegral(integral - refundIntegral)
+                        .orderCount((long) shopOrderList.size())
+                        .orderIds(shopOrderList.stream().map(OrderDTO::getId).collect(Collectors.toList()).toString())
+                        .orderCalcTime(date)
+                        .shopId(shopId)
+                        .merchantId(shopOrderList.get(0).getMerchantId())
+                        .ptDailyBillId(ptDailyBillDO.getId())
+                        .build();
+
+                dailyBillMapper.insert(dailyBillDO);
             });
+            //修改订单状态为已经计算每日账单
+            dailyBillMapper.updateOrderItemByOrderId(orderList.stream().map(OrderDTO::getId).collect(Collectors.toList()));
         });
     }
 

+ 4 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/dailybill/dto/OrderDTO.java

@@ -59,5 +59,9 @@ public class OrderDTO extends BaseDO {
      */
     private Integer payRmb;
 
+    private Long shopId;
+
+    private Long merchantId;
+
     private List<OrderItemDTO> items;
 }

+ 53 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ptdailybill/PtDailyBillService.java

@@ -0,0 +1,53 @@
+package cn.newfeifan.mall.module.distri.service.ptdailybill;
+
+import javax.validation.*;
+import cn.newfeifan.mall.module.distri.controller.admin.ptdailybill.vo.*;
+import cn.newfeifan.mall.module.distri.dal.dataobject.ptdailybill.PtDailyBillDO;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+
+/**
+ * 平台每日账单统计 Service 接口
+ *
+ * @author 非繁人
+ */
+public interface PtDailyBillService {
+
+    /**
+     * 创建平台每日账单统计
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createPtDailyBill(@Valid PtDailyBillSaveReqVO createReqVO);
+
+    /**
+     * 更新平台每日账单统计
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updatePtDailyBill(@Valid PtDailyBillSaveReqVO updateReqVO);
+
+    /**
+     * 删除平台每日账单统计
+     *
+     * @param id 编号
+     */
+    void deletePtDailyBill(Long id);
+
+    /**
+     * 获得平台每日账单统计
+     *
+     * @param id 编号
+     * @return 平台每日账单统计
+     */
+    PtDailyBillDO getPtDailyBill(Long id);
+
+    /**
+     * 获得平台每日账单统计分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 平台每日账单统计分页
+     */
+    PageResult<PtDailyBillDO> getPtDailyBillPage(PtDailyBillPageReqVO pageReqVO);
+
+}

+ 70 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/ptdailybill/PtDailyBillServiceImpl.java

@@ -0,0 +1,70 @@
+package cn.newfeifan.mall.module.distri.service.ptdailybill;
+
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import cn.newfeifan.mall.module.distri.controller.admin.ptdailybill.vo.*;
+import cn.newfeifan.mall.module.distri.dal.dataobject.ptdailybill.PtDailyBillDO;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+
+import cn.newfeifan.mall.module.distri.dal.mysql.ptdailybill.PtDailyBillMapper;
+
+import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.*;
+
+/**
+ * 平台每日账单统计 Service 实现类
+ *
+ * @author 非繁人
+ */
+@Service
+@Validated
+public class PtDailyBillServiceImpl implements PtDailyBillService {
+
+    @Resource
+    private PtDailyBillMapper ptDailyBillMapper;
+
+    @Override
+    public Long createPtDailyBill(PtDailyBillSaveReqVO createReqVO) {
+        // 插入
+        PtDailyBillDO ptDailyBill = BeanUtils.toBean(createReqVO, PtDailyBillDO.class);
+        ptDailyBillMapper.insert(ptDailyBill);
+        // 返回
+        return ptDailyBill.getId();
+    }
+
+    @Override
+    public void updatePtDailyBill(PtDailyBillSaveReqVO updateReqVO) {
+        // 校验存在
+        validatePtDailyBillExists(updateReqVO.getId());
+        // 更新
+        PtDailyBillDO updateObj = BeanUtils.toBean(updateReqVO, PtDailyBillDO.class);
+        ptDailyBillMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deletePtDailyBill(Long id) {
+        // 校验存在
+        validatePtDailyBillExists(id);
+        // 删除
+        ptDailyBillMapper.deleteById(id);
+    }
+
+    private void validatePtDailyBillExists(Long id) {
+        if (ptDailyBillMapper.selectById(id) == null) {
+            throw exception(PT_DAILY_BILL_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public PtDailyBillDO getPtDailyBill(Long id) {
+        return ptDailyBillMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<PtDailyBillDO> getPtDailyBillPage(PtDailyBillPageReqVO pageReqVO) {
+        return ptDailyBillMapper.selectPage(pageReqVO);
+    }
+
+}

+ 3 - 3
feifan-module-distri/feifan-module-distri-biz/src/main/resources/mapper/dailybill/DailyBillMapper.xml

@@ -26,12 +26,12 @@
     <select id="selectShopIdsByMerchantId" resultType="long">
         SELECT id FROM sale_shop WHERE merchant_id = #{merchantId}
     </select>
-    <select id="getOrderDetailsByMerchantIdWithsShopId"
+    <select id="getOrderDetails"
             resultType="cn.newfeifan.mall.module.distri.service.dailybill.dto.OrderDTO">
-        select o.id,o.no,o.product_count,o.delivery_price,o.pay_price,o.refund_status,o.refund_price,o.pay_integral,o.refund_integral,
+        select o.id,o.no,o.product_count,o.delivery_price,o.pay_price,o.refund_status,o.refund_price,o.pay_integral,o.refund_integral,o.shop_id,o.merchant_id,
                o.pay_rmb,o.create_time from trade_order o
                join trade_order_item item on item.order_id = o.id
-        where shop_id = #{shopId} and merchant_id = #{merchantId} and pay_status = 1 and date(o.create_time) &lt; date(now()) and item.computation_bill = 0
+        where pay_status = 1 and date(o.create_time) &lt; date(now()) and item.computation_bill = 0
     </select>
     <select id="getMerchantName" resultType="java.lang.String">
         select name from sale_merchant where id = #{merchantId}

+ 12 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/resources/mapper/ptdailybill/PtDailyBillMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.newfeifan.mall.module.distri.dal.mysql.ptdailybill.PtDailyBillMapper">
+
+    <!--
+        一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
+        无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
+        代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
+        文档可见:https://www.zhongxing.cn/MyBatis/x-plugins/
+     -->
+
+</mapper>

+ 21 - 0
sql/mysql/建空库SQL/16_20240704.sql

@@ -0,0 +1,21 @@
+CREATE TABLE `distri_pt_daily_bill` (
+                                        `id` bigint NOT NULL AUTO_INCREMENT COMMENT '账单编号',
+                                        `price` bigint NOT NULL DEFAULT '0' COMMENT '金额,单位:分',
+                                        `received_price` bigint NOT NULL DEFAULT '0' COMMENT '确收金额,单位:分',
+                                        `order_count` bigint NOT NULL DEFAULT '0' COMMENT '订单数,默认为0',
+                                        `refund_price` bigint NOT NULL DEFAULT '0' COMMENT '退款金额, 单位: 分',
+                                        `integral` bigint NOT NULL DEFAULT '0' COMMENT '积分',
+                                        `received_integral` bigint NOT NULL DEFAULT '0' COMMENT '确收积分',
+                                        `refund_integral` bigint NOT NULL DEFAULT '0' COMMENT '退款积分',
+                                        `order_calc_time` date NOT NULL COMMENT '订单所属日期',
+                                        `order_ids` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT '订单ID列表,文本类型',
+                                        `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '' COMMENT '创建者',
+                                        `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+                                        `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '' COMMENT '更新者',
+                                        `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+                                        `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
+                                        PRIMARY KEY (`id`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='平台每日账单统计表';
+
+ALTER TABLE distri_daily_bill
+    ADD COLUMN `pt_daily_bill_id` bigint NOT NULL default b'0' COMMENT '平台每日账单表id';