Commit 0fc95c77399336e3acf8fafffeb12c4e17b752df

Authored by shaofan
1 parent 146da27e

Refactor: 新增资金对账功能,扩展商户与骑手账单查询接口

src/main/java/com/diligrp/rider/controller/AdminMerchantFundController.java 0 → 100644
  1 +package com.diligrp.rider.controller;
  2 +
  3 +import com.diligrp.rider.common.exception.BizException;
  4 +import com.diligrp.rider.common.result.Result;
  5 +import com.diligrp.rider.service.MerchantFundService;
  6 +import com.diligrp.rider.vo.*;
  7 +import jakarta.servlet.http.HttpServletRequest;
  8 +import lombok.RequiredArgsConstructor;
  9 +import org.springframework.web.bind.annotation.GetMapping;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RequestParam;
  12 +import org.springframework.web.bind.annotation.RestController;
  13 +
  14 +@RestController
  15 +@RequestMapping("/api/admin/merchant/fund")
  16 +@RequiredArgsConstructor
  17 +public class AdminMerchantFundController {
  18 +
  19 + private final MerchantFundService merchantFundService;
  20 +
  21 + @GetMapping("/merchant-bills")
  22 + public Result<PageResultVO<MerchantBillItemVO>> merchantBills(@RequestParam(required = false) Long cityId,
  23 + @RequestParam(required = false) String keyword,
  24 + @RequestParam String startDate,
  25 + @RequestParam String endDate,
  26 + @RequestParam(defaultValue = "1") int page,
  27 + HttpServletRequest request) {
  28 + return Result.success(merchantFundService.merchantBillList(resolveQueryCityId(request, cityId), keyword, startDate, endDate, page));
  29 + }
  30 +
  31 + @GetMapping("/merchant-bill-detail")
  32 + public Result<PageResultVO<MerchantBillDetailItemVO>> merchantBillDetail(@RequestParam(required = false) Long cityId,
  33 + @RequestParam String outStoreId,
  34 + @RequestParam String startDate,
  35 + @RequestParam String endDate,
  36 + @RequestParam(defaultValue = "1") int page,
  37 + HttpServletRequest request) {
  38 + return Result.success(merchantFundService.merchantBillDetail(resolveQueryCityId(request, cityId), outStoreId, startDate, endDate, page));
  39 + }
  40 +
  41 + @GetMapping("/rider-bills")
  42 + public Result<PageResultVO<RiderBillItemVO>> riderBills(@RequestParam(required = false) Long cityId,
  43 + @RequestParam(required = false) String keyword,
  44 + @RequestParam String startDate,
  45 + @RequestParam String endDate,
  46 + @RequestParam(defaultValue = "1") int page,
  47 + HttpServletRequest request) {
  48 + return Result.success(merchantFundService.riderBillList(resolveQueryCityId(request, cityId), keyword, startDate, endDate, page));
  49 + }
  50 +
  51 + @GetMapping("/rider-bill-detail")
  52 + public Result<PageResultVO<RiderBillDetailItemVO>> riderBillDetail(@RequestParam(required = false) Long cityId,
  53 + @RequestParam Long riderId,
  54 + @RequestParam String startDate,
  55 + @RequestParam String endDate,
  56 + @RequestParam(defaultValue = "1") int page,
  57 + HttpServletRequest request) {
  58 + return Result.success(merchantFundService.riderBillDetail(resolveQueryCityId(request, cityId), riderId, startDate, endDate, page));
  59 + }
  60 +
  61 + private Long resolveScopedCityId(HttpServletRequest request) {
  62 + if (!"substation".equals(request.getAttribute("role"))) {
  63 + return null;
  64 + }
  65 + Long cityId = (Long) request.getAttribute("cityId");
  66 + if (cityId == null || cityId < 1) {
  67 + throw new BizException("当前账号未绑定有效城市");
  68 + }
  69 + return cityId;
  70 + }
  71 +
  72 + private Long resolveQueryCityId(HttpServletRequest request, Long queryCityId) {
  73 + Long scopedCityId = resolveScopedCityId(request);
  74 + return scopedCityId != null ? scopedCityId : queryCityId;
  75 + }
  76 +}
... ...
src/main/java/com/diligrp/rider/mapper/MerchantFundMapper.java 0 → 100644
  1 +package com.diligrp.rider.mapper;
  2 +
  3 +import com.diligrp.rider.vo.MerchantBillDetailItemVO;
  4 +import com.diligrp.rider.vo.MerchantBillItemVO;
  5 +import com.diligrp.rider.vo.RiderBillDetailItemVO;
  6 +import com.diligrp.rider.vo.RiderBillItemVO;
  7 +import org.apache.ibatis.annotations.Mapper;
  8 +import org.apache.ibatis.annotations.Param;
  9 +
  10 +import java.util.List;
  11 +
  12 +@Mapper
  13 +public interface MerchantFundMapper {
  14 + long countMerchantBills(@Param("cityId") Long cityId,
  15 + @Param("keyword") String keyword,
  16 + @Param("startTime") Long startTime,
  17 + @Param("endTime") Long endTime);
  18 +
  19 + List<MerchantBillItemVO> selectMerchantBills(@Param("cityId") Long cityId,
  20 + @Param("keyword") String keyword,
  21 + @Param("startTime") Long startTime,
  22 + @Param("endTime") Long endTime,
  23 + @Param("offset") int offset,
  24 + @Param("pageSize") int pageSize);
  25 +
  26 + long countMerchantBillDetails(@Param("cityId") Long cityId,
  27 + @Param("outStoreId") String outStoreId,
  28 + @Param("startTime") Long startTime,
  29 + @Param("endTime") Long endTime);
  30 +
  31 + List<MerchantBillDetailItemVO> selectMerchantBillDetails(@Param("cityId") Long cityId,
  32 + @Param("outStoreId") String outStoreId,
  33 + @Param("startTime") Long startTime,
  34 + @Param("endTime") Long endTime,
  35 + @Param("offset") int offset,
  36 + @Param("pageSize") int pageSize);
  37 +
  38 + long countRiderBills(@Param("cityId") Long cityId,
  39 + @Param("keyword") String keyword,
  40 + @Param("startTime") Long startTime,
  41 + @Param("endTime") Long endTime);
  42 +
  43 + List<RiderBillItemVO> selectRiderBills(@Param("cityId") Long cityId,
  44 + @Param("keyword") String keyword,
  45 + @Param("startTime") Long startTime,
  46 + @Param("endTime") Long endTime,
  47 + @Param("offset") int offset,
  48 + @Param("pageSize") int pageSize);
  49 +
  50 + long countRiderBillDetails(@Param("cityId") Long cityId,
  51 + @Param("riderId") Long riderId,
  52 + @Param("startTime") Long startTime,
  53 + @Param("endTime") Long endTime);
  54 +
  55 + List<RiderBillDetailItemVO> selectRiderBillDetails(@Param("cityId") Long cityId,
  56 + @Param("riderId") Long riderId,
  57 + @Param("startTime") Long startTime,
  58 + @Param("endTime") Long endTime,
  59 + @Param("offset") int offset,
  60 + @Param("pageSize") int pageSize);
  61 +}
... ...
src/main/java/com/diligrp/rider/service/MerchantFundService.java 0 → 100644
  1 +package com.diligrp.rider.service;
  2 +
  3 +import com.diligrp.rider.vo.*;
  4 +
  5 +public interface MerchantFundService {
  6 + PageResultVO<MerchantBillItemVO> merchantBillList(Long cityId, String keyword, String startDate, String endDate, int page);
  7 + PageResultVO<MerchantBillDetailItemVO> merchantBillDetail(Long cityId, String outStoreId, String startDate, String endDate, int page);
  8 + PageResultVO<RiderBillItemVO> riderBillList(Long cityId, String keyword, String startDate, String endDate, int page);
  9 + PageResultVO<RiderBillDetailItemVO> riderBillDetail(Long cityId, Long riderId, String startDate, String endDate, int page);
  10 +}
... ...
src/main/java/com/diligrp/rider/service/impl/MenuBootstrapServiceImpl.java
... ... @@ -64,6 +64,7 @@ public class MenuBootstrapServiceImpl implements MenuBootstrapService {
64 64 defaults.add(menu("merchant.root", "商家管理", "DIR", "", "ShopOutlined", 0L, MenuScopeEnum.BOTH, 40));
65 65 defaults.add(menu("merchant.enter", "入驻申请", "MENU", "/merchant/enter", "", 0L, MenuScopeEnum.BOTH, 41));
66 66 defaults.add(menu("merchant.store", "店铺管理", "MENU", "/merchant/store", "", 0L, MenuScopeEnum.BOTH, 42));
  67 + defaults.add(menu("merchant.fund", "资金对账", "MENU", "/merchant/fund", "", 0L, MenuScopeEnum.BOTH, 43));
67 68 defaults.add(menu("rider.list", "骑手管理", "MENU", "/rider", "UserOutlined", 0L, MenuScopeEnum.BOTH, 50));
68 69 defaults.add(menu("rider.level", "骑手等级", "MENU", "/rider/level", "TrophyOutlined", 0L, MenuScopeEnum.BOTH, 55));
69 70 defaults.add(menu("rider.evaluate", "骑手评价", "MENU", "/rider/evaluate", "StarOutlined", 0L, MenuScopeEnum.BOTH, 60));
... ... @@ -104,6 +105,7 @@ public class MenuBootstrapServiceImpl implements MenuBootstrapService {
104 105  
105 106 persisted.get("merchant.enter").setParentId(persisted.get("merchant.root").getId());
106 107 persisted.get("merchant.store").setParentId(persisted.get("merchant.root").getId());
  108 + persisted.get("merchant.fund").setParentId(persisted.get("merchant.root").getId());
107 109 persisted.get("order.list").setParentId(persisted.get("order.root").getId());
108 110 persisted.get("order.refund").setParentId(persisted.get("order.root").getId());
109 111 persisted.get("order.delivery").setParentId(persisted.get("order.root").getId());
... ...
src/main/java/com/diligrp/rider/service/impl/MerchantFundServiceImpl.java 0 → 100644
  1 +package com.diligrp.rider.service.impl;
  2 +
  3 +import com.diligrp.rider.common.exception.BizException;
  4 +import com.diligrp.rider.mapper.MerchantFundMapper;
  5 +import com.diligrp.rider.service.MerchantFundService;
  6 +import com.diligrp.rider.vo.*;
  7 +import lombok.RequiredArgsConstructor;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +import java.time.LocalDate;
  11 +import java.time.ZoneId;
  12 +
  13 +@Service
  14 +@RequiredArgsConstructor
  15 +public class MerchantFundServiceImpl implements MerchantFundService {
  16 +
  17 + private static final int PAGE_SIZE = 20;
  18 + private static final ZoneId ZONE_ID = ZoneId.of("Asia/Shanghai");
  19 +
  20 + private final MerchantFundMapper merchantFundMapper;
  21 +
  22 + @Override
  23 + public PageResultVO<MerchantBillItemVO> merchantBillList(Long cityId, String keyword, String startDate, String endDate, int page) {
  24 + long startTime = parseStartTime(startDate);
  25 + long endTime = parseEndTime(endDate);
  26 + int currentPage = normalizePage(page);
  27 + int offset = (currentPage - 1) * PAGE_SIZE;
  28 + PageResultVO<MerchantBillItemVO> result = new PageResultVO<>();
  29 + result.setList(merchantFundMapper.selectMerchantBills(cityId, normalizeKeyword(keyword), startTime, endTime, offset, PAGE_SIZE));
  30 + result.setPage(currentPage);
  31 + result.setPageSize(PAGE_SIZE);
  32 + result.setTotal(merchantFundMapper.countMerchantBills(cityId, normalizeKeyword(keyword), startTime, endTime));
  33 + return result;
  34 + }
  35 +
  36 + @Override
  37 + public PageResultVO<MerchantBillDetailItemVO> merchantBillDetail(Long cityId, String outStoreId, String startDate, String endDate, int page) {
  38 + if (outStoreId == null || outStoreId.isBlank()) {
  39 + throw new BizException("店铺编号不能为空");
  40 + }
  41 + long startTime = parseStartTime(startDate);
  42 + long endTime = parseEndTime(endDate);
  43 + int currentPage = normalizePage(page);
  44 + int offset = (currentPage - 1) * PAGE_SIZE;
  45 + PageResultVO<MerchantBillDetailItemVO> result = new PageResultVO<>();
  46 + result.setList(merchantFundMapper.selectMerchantBillDetails(cityId, outStoreId, startTime, endTime, offset, PAGE_SIZE));
  47 + result.setPage(currentPage);
  48 + result.setPageSize(PAGE_SIZE);
  49 + result.setTotal(merchantFundMapper.countMerchantBillDetails(cityId, outStoreId, startTime, endTime));
  50 + return result;
  51 + }
  52 +
  53 + @Override
  54 + public PageResultVO<RiderBillItemVO> riderBillList(Long cityId, String keyword, String startDate, String endDate, int page) {
  55 + long startTime = parseStartTime(startDate);
  56 + long endTime = parseEndTime(endDate);
  57 + int currentPage = normalizePage(page);
  58 + int offset = (currentPage - 1) * PAGE_SIZE;
  59 + PageResultVO<RiderBillItemVO> result = new PageResultVO<>();
  60 + result.setList(merchantFundMapper.selectRiderBills(cityId, normalizeKeyword(keyword), startTime, endTime, offset, PAGE_SIZE));
  61 + result.setPage(currentPage);
  62 + result.setPageSize(PAGE_SIZE);
  63 + result.setTotal(merchantFundMapper.countRiderBills(cityId, normalizeKeyword(keyword), startTime, endTime));
  64 + return result;
  65 + }
  66 +
  67 + @Override
  68 + public PageResultVO<RiderBillDetailItemVO> riderBillDetail(Long cityId, Long riderId, String startDate, String endDate, int page) {
  69 + if (riderId == null || riderId < 1) {
  70 + throw new BizException("骑手ID不能为空");
  71 + }
  72 + long startTime = parseStartTime(startDate);
  73 + long endTime = parseEndTime(endDate);
  74 + int currentPage = normalizePage(page);
  75 + int offset = (currentPage - 1) * PAGE_SIZE;
  76 + PageResultVO<RiderBillDetailItemVO> result = new PageResultVO<>();
  77 + result.setList(merchantFundMapper.selectRiderBillDetails(cityId, riderId, startTime, endTime, offset, PAGE_SIZE));
  78 + result.setPage(currentPage);
  79 + result.setPageSize(PAGE_SIZE);
  80 + result.setTotal(merchantFundMapper.countRiderBillDetails(cityId, riderId, startTime, endTime));
  81 + return result;
  82 + }
  83 +
  84 + private int normalizePage(int page) {
  85 + return Math.max(page, 1);
  86 + }
  87 +
  88 + private String normalizeKeyword(String keyword) {
  89 + return keyword == null || keyword.isBlank() ? null : keyword.trim();
  90 + }
  91 +
  92 + private long parseStartTime(String startDate) {
  93 + LocalDate date = parseDate(startDate, "开始日期不能为空");
  94 + return date.atStartOfDay(ZONE_ID).toEpochSecond();
  95 + }
  96 +
  97 + private long parseEndTime(String endDate) {
  98 + LocalDate date = parseDate(endDate, "结束日期不能为空");
  99 + return date.plusDays(1).atStartOfDay(ZONE_ID).toEpochSecond();
  100 + }
  101 +
  102 + private LocalDate parseDate(String value, String errorMessage) {
  103 + if (value == null || value.isBlank()) {
  104 + throw new BizException(errorMessage);
  105 + }
  106 + try {
  107 + return LocalDate.parse(value);
  108 + } catch (Exception ex) {
  109 + throw new BizException(errorMessage);
  110 + }
  111 + }
  112 +}
... ...
src/main/java/com/diligrp/rider/vo/MerchantBillDetailItemVO.java 0 → 100644
  1 +package com.diligrp.rider.vo;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.math.BigDecimal;
  6 +
  7 +@Data
  8 +public class MerchantBillDetailItemVO {
  9 + private Long orderId;
  10 + private String orderNo;
  11 + private Long payTime;
  12 + private Long completeTime;
  13 + private Integer status;
  14 + private BigDecimal orderAmount;
  15 + private BigDecimal deliveryAmount;
  16 + private BigDecimal refundAmount;
  17 +}
... ...
src/main/java/com/diligrp/rider/vo/MerchantBillItemVO.java 0 → 100644
  1 +package com.diligrp.rider.vo;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.math.BigDecimal;
  6 +
  7 +@Data
  8 +public class MerchantBillItemVO {
  9 + private Long storeId;
  10 + private String outStoreId;
  11 + private String storeName;
  12 + private Long cityId;
  13 + private Long orderCount;
  14 + private BigDecimal orderAmount;
  15 + private BigDecimal deliveryAmount;
  16 + private BigDecimal refundAmount;
  17 + private BigDecimal merchantReceivableAmount;
  18 +}
... ...
src/main/java/com/diligrp/rider/vo/PageResultVO.java 0 → 100644
  1 +package com.diligrp.rider.vo;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.util.List;
  6 +
  7 +@Data
  8 +public class PageResultVO<T> {
  9 + private List<T> list;
  10 + private Integer page;
  11 + private Integer pageSize;
  12 + private Long total;
  13 +}
... ...
src/main/java/com/diligrp/rider/vo/RiderBillDetailItemVO.java 0 → 100644
  1 +package com.diligrp.rider.vo;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.math.BigDecimal;
  6 +
  7 +@Data
  8 +public class RiderBillDetailItemVO {
  9 + private Long orderId;
  10 + private String orderNo;
  11 + private Long completeTime;
  12 + private Integer status;
  13 + private BigDecimal deliveryAmount;
  14 + private BigDecimal riderIncomeAmount;
  15 + private BigDecimal refundAmount;
  16 + private BigDecimal settleableAmount;
  17 +}
... ...
src/main/java/com/diligrp/rider/vo/RiderBillItemVO.java 0 → 100644
  1 +package com.diligrp.rider.vo;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.math.BigDecimal;
  6 +
  7 +@Data
  8 +public class RiderBillItemVO {
  9 + private Long riderId;
  10 + private String riderName;
  11 + private String mobile;
  12 + private Long orderCount;
  13 + private BigDecimal deliveryAmount;
  14 + private BigDecimal riderIncomeAmount;
  15 + private BigDecimal refundAdjustAmount;
  16 + private BigDecimal settleableAmount;
  17 +}
... ...
src/main/resources/mapper/MerchantFundMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.diligrp.rider.mapper.MerchantFundMapper">
  4 +
  5 + <sql id="merchantBillFilter">
  6 + WHERE o.is_del = 0
  7 + AND o.status IN (2, 3, 4, 6, 7, 8, 9)
  8 + AND o.pay_time &gt;= #{startTime}
  9 + AND o.pay_time &lt; #{endTime}
  10 + <if test="cityId != null">
  11 + AND o.city_id = #{cityId}
  12 + </if>
  13 + <if test="keyword != null and keyword != ''">
  14 + AND ms.name LIKE CONCAT('%', #{keyword}, '%')
  15 + </if>
  16 + </sql>
  17 +
  18 + <sql id="merchantBillDetailFilter">
  19 + WHERE o.is_del = 0
  20 + AND o.status IN (2, 3, 4, 6, 7, 8, 9)
  21 + AND o.pay_time &gt;= #{startTime}
  22 + AND o.pay_time &lt; #{endTime}
  23 + AND CAST(o.store_oid AS CHAR) = #{outStoreId}
  24 + <if test="cityId != null">
  25 + AND o.city_id = #{cityId}
  26 + </if>
  27 + </sql>
  28 +
  29 + <sql id="riderBillFilter">
  30 + WHERE o.is_del = 0
  31 + AND o.rider_id &gt; 0
  32 + AND o.status IN (6, 7, 8, 9)
  33 + AND o.complete_time &gt;= #{startTime}
  34 + AND o.complete_time &lt; #{endTime}
  35 + <if test="cityId != null">
  36 + AND o.city_id = #{cityId}
  37 + </if>
  38 + <if test="keyword != null and keyword != ''">
  39 + AND (r.user_nickname LIKE CONCAT('%', #{keyword}, '%') OR r.mobile LIKE CONCAT('%', #{keyword}, '%'))
  40 + </if>
  41 + </sql>
  42 +
  43 + <sql id="riderBillDetailFilter">
  44 + WHERE o.is_del = 0
  45 + AND o.rider_id = #{riderId}
  46 + AND o.status IN (6, 7, 8, 9)
  47 + AND o.complete_time &gt;= #{startTime}
  48 + AND o.complete_time &lt; #{endTime}
  49 + <if test="cityId != null">
  50 + AND o.city_id = #{cityId}
  51 + </if>
  52 + </sql>
  53 +
  54 + <select id="countMerchantBills" resultType="long">
  55 + SELECT COUNT(1)
  56 + FROM (
  57 + SELECT ms.out_store_id
  58 + FROM orders o
  59 + INNER JOIN merchant_store ms ON ms.out_store_id = CAST(o.store_oid AS CHAR)
  60 + AND ms.city_id = o.city_id
  61 + AND ms.is_del = 0
  62 + <include refid="merchantBillFilter"/>
  63 + GROUP BY ms.out_store_id
  64 + ) t
  65 + </select>
  66 +
  67 + <select id="selectMerchantBills" resultType="com.diligrp.rider.vo.MerchantBillItemVO">
  68 + SELECT
  69 + MAX(ms.id) AS storeId,
  70 + ms.out_store_id AS outStoreId,
  71 + MAX(ms.name) AS storeName,
  72 + MAX(ms.city_id) AS cityId,
  73 + COUNT(o.id) AS orderCount,
  74 + COALESCE(SUM(o.money), 0) AS orderAmount,
  75 + COALESCE(SUM(o.money_delivery), 0) AS deliveryAmount,
  76 + COALESCE(SUM(rr.refund_amount), 0) AS refundAmount,
  77 + COALESCE(SUM(o.money), 0) - COALESCE(SUM(rr.refund_amount), 0) AS merchantReceivableAmount
  78 + FROM orders o
  79 + INNER JOIN merchant_store ms ON ms.out_store_id = CAST(o.store_oid AS CHAR)
  80 + AND ms.city_id = o.city_id
  81 + AND ms.is_del = 0
  82 + LEFT JOIN (
  83 + SELECT oid, SUM(money) AS refund_amount
  84 + FROM orders_refund_record
  85 + WHERE status = 1
  86 + GROUP BY oid
  87 + ) rr ON rr.oid = o.id
  88 + <include refid="merchantBillFilter"/>
  89 + GROUP BY ms.out_store_id
  90 + ORDER BY MAX(o.pay_time) DESC
  91 + LIMIT #{offset}, #{pageSize}
  92 + </select>
  93 +
  94 + <select id="countMerchantBillDetails" resultType="long">
  95 + SELECT COUNT(1)
  96 + FROM orders o
  97 + <include refid="merchantBillDetailFilter"/>
  98 + </select>
  99 +
  100 + <select id="selectMerchantBillDetails" resultType="com.diligrp.rider.vo.MerchantBillDetailItemVO">
  101 + SELECT
  102 + o.id AS orderId,
  103 + o.order_no AS orderNo,
  104 + o.pay_time AS payTime,
  105 + o.complete_time AS completeTime,
  106 + o.status AS status,
  107 + o.money AS orderAmount,
  108 + o.money_delivery AS deliveryAmount,
  109 + COALESCE(rr.refund_amount, 0) AS refundAmount
  110 + FROM orders o
  111 + LEFT JOIN (
  112 + SELECT oid, SUM(money) AS refund_amount
  113 + FROM orders_refund_record
  114 + WHERE status = 1
  115 + GROUP BY oid
  116 + ) rr ON rr.oid = o.id
  117 + <include refid="merchantBillDetailFilter"/>
  118 + ORDER BY o.pay_time DESC, o.id DESC
  119 + LIMIT #{offset}, #{pageSize}
  120 + </select>
  121 +
  122 + <select id="countRiderBills" resultType="long">
  123 + SELECT COUNT(1)
  124 + FROM (
  125 + SELECT o.rider_id
  126 + FROM orders o
  127 + INNER JOIN rider r ON r.id = o.rider_id AND r.is_del = 0
  128 + <include refid="riderBillFilter"/>
  129 + GROUP BY o.rider_id
  130 + ) t
  131 + </select>
  132 +
  133 + <select id="selectRiderBills" resultType="com.diligrp.rider.vo.RiderBillItemVO">
  134 + SELECT
  135 + o.rider_id AS riderId,
  136 + MAX(r.user_nickname) AS riderName,
  137 + MAX(r.mobile) AS mobile,
  138 + COUNT(o.id) AS orderCount,
  139 + COALESCE(SUM(o.money_delivery), 0) AS deliveryAmount,
  140 + COALESCE(SUM(o.rider_income), 0) AS riderIncomeAmount,
  141 + COALESCE(SUM(rr.refund_amount), 0) AS refundAdjustAmount,
  142 + COALESCE(SUM(o.rider_income), 0) AS settleableAmount
  143 + FROM orders o
  144 + INNER JOIN rider r ON r.id = o.rider_id AND r.is_del = 0
  145 + LEFT JOIN (
  146 + SELECT oid, SUM(money) AS refund_amount
  147 + FROM orders_refund_record
  148 + WHERE status = 1
  149 + GROUP BY oid
  150 + ) rr ON rr.oid = o.id
  151 + <include refid="riderBillFilter"/>
  152 + GROUP BY o.rider_id
  153 + ORDER BY MAX(o.complete_time) DESC
  154 + LIMIT #{offset}, #{pageSize}
  155 + </select>
  156 +
  157 + <select id="countRiderBillDetails" resultType="long">
  158 + SELECT COUNT(1)
  159 + FROM orders o
  160 + <include refid="riderBillDetailFilter"/>
  161 + </select>
  162 +
  163 + <select id="selectRiderBillDetails" resultType="com.diligrp.rider.vo.RiderBillDetailItemVO">
  164 + SELECT
  165 + o.id AS orderId,
  166 + o.order_no AS orderNo,
  167 + o.complete_time AS completeTime,
  168 + o.status AS status,
  169 + o.money_delivery AS deliveryAmount,
  170 + o.rider_income AS riderIncomeAmount,
  171 + COALESCE(rr.refund_amount, 0) AS refundAmount,
  172 + o.rider_income AS settleableAmount
  173 + FROM orders o
  174 + LEFT JOIN (
  175 + SELECT oid, SUM(money) AS refund_amount
  176 + FROM orders_refund_record
  177 + WHERE status = 1
  178 + GROUP BY oid
  179 + ) rr ON rr.oid = o.id
  180 + <include refid="riderBillDetailFilter"/>
  181 + ORDER BY o.complete_time DESC, o.id DESC
  182 + LIMIT #{offset}, #{pageSize}
  183 + </select>
  184 +
  185 +</mapper>
... ...