cloudroam
2024-10-12 ef4f769a35eda2e8631b0376f35899e69a13d87f
src/main/resources/mapper/report/OrderReportMapper.xml
@@ -439,4 +439,151 @@
    </sql>
    <sql id="baseSupplierSql">
        SELECT
        t2.*,
        IFNULL( t3.sales_fee_supplier, 0 ) AS sales_fee_supplier
        FROM
        (
        SELECT
        t1.order_item_id,
        t1.supplier_id,
        t1.dateinfo,
        t1.order_id,
        sum( t1.supplier_price_amount ) AS order_supplier_price_amount,
        sum( t1.check_fee ) AS order_check_fee,
        sum( t1.replace_fee ) AS order_replace_fee,
        sum( t1.lack_fee_supplier ) AS order_lack_fee_supplier,
        sum( t1.num ) AS order_num,
        sum( t1.lack_num ) AS order_lack_num
        FROM
        (
        SELECT
        oi.id AS order_item_id,
        o.id order_id,
        oi.supplier_id supplier_id,
        CASE
        WHEN HOUR ( o.payment_time ) >= 17 THEN
        DATE_FORMAT( DATE_ADD( o.payment_time, INTERVAL 1 DAY ), '%Y-%m-%d' ) ELSE DATE_FORMAT( o.payment_time, '%Y-%m-%d' )
        END AS dateinfo,
        IFNULL( oi.num, 0 ) AS num,
        IFNULL( oi.total, 0 ) AS total,
        IFNULL( oi.supplier_price, 0 ) * IFNULL( oi.num, 0 ) AS supplier_price_amount,
        IFNULL( ois.check_fee, 0 ) AS check_fee,
        IFNULL( ois.replace_fee, 0 ) AS replace_fee,
        IFNULL( ois.lack_fee_supplier, 0 ) AS lack_fee_supplier,
        IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack'),0) as lack_num
        FROM
        t_order o
        LEFT JOIN t_order_item oi ON oi.order_id = o.id
        LEFT JOIN t_station s ON s.id = oi.station_id
        LEFT JOIN t_supplier_info si ON si.id = oi.supplier_id
        LEFT JOIN t_order_item_settlement ois ON ois.order_item_id = oi.id
        WHERE
        oi.deleted = 0
        and  o.payment_time is not null
        <if test="dto.startDate != null">
            and o.payment_time >= #{dto.startDate}
        </if>
        <if test="dto.endDate != null">
            and o.payment_time &lt;= #{dto.endDate}
        </if>
        <if test="dto.supplierId != null">
            and oi.supplierId = #{dto.supplierId}
        </if>
        ) t1
        GROUP BY
        t1.order_item_id
        ) t2
        LEFT JOIN ( SELECT ois.order_item_id, IFNULL( sum( ois.sales_fee_supplier ), 0 ) AS sales_fee_supplier FROM t_order_item_settlement ois GROUP BY order_item_id ) t3 ON t2.order_item_id = t3.order_item_id
    </sql>
    <select id="getOrderSupplierPageReport" resultType="com.mzl.flower.dto.response.report.OrderSupplierReportResultVO">
        select
        dateinfo,
        supplier_id,
        supplierName,
        sum(order_supplier_price_amount) order_supplier_price_amount,
        sum(order_check_fee) order_check_fee,
        sum(order_replace_fee) + sum(order_lack_fee_supplier) order_lack_fee_supplier,
        sum(order_num)-sum(order_lack_num) as real_sale_num,
        sum(sales_fee_supplier) sales_fee_supplier,
        sum(order_supplier_price_amount) -   sum(order_check_fee) - sum(order_replace_fee) -  sum(order_lack_fee_supplier) -  sum(sales_fee_supplier) profitFeeAmount,
        case when  COUNT(CASE WHEN status_backend IS NULL THEN 1 ELSE NULL END)  = 0 Then '已完成' Else '进行中' end as settleStatus
        from(
        SELECT
        oi.id,vor.*,p.name as supplierName,o.status_backend
        FROM
        (<include refid="baseSupplierSql"></include>) vor
        left join t_order_item oi
        on vor.order_item_id = oi.id
        left join t_supplier_info p
        on vor.supplier_id=p.id
        left join t_order o
        on vor.order_id= o.id
        and o.status_backend not in ('PENDING','CANCEL','REFUND')
        )  s group by dateinfo,supplier_id
    </select>
    <select id="getOrderSupplierReport" resultType="com.mzl.flower.dto.response.report.OrderSupplierReportResultVO">
        select
        dateinfo,
        supplier_id,
        supplierName,
        sum(order_supplier_price_amount) order_supplier_price_amount,
        sum(order_check_fee) order_check_fee,
        sum(order_replace_fee) + sum(order_lack_fee_supplier) order_lack_fee_supplier,
        sum(order_num)-sum(order_lack_num) as real_sale_num,
        sum(sales_fee_supplier) sales_fee_supplier,
        sum(order_supplier_price_amount) -   sum(order_check_fee) - sum(order_replace_fee) -  sum(order_lack_fee_supplier) -  sum(sales_fee_supplier) profitFeeAmount,
        case when  COUNT(CASE WHEN status_backend IS NULL THEN 1 ELSE NULL END)  = 0 Then '已完成' Else '进行中' end as settleStatus
        from(
        SELECT
        oi.id,vor.*,p.name as supplierName,o.status_backend
        FROM
        (<include refid="baseSupplierSql"></include>) vor
        left join t_order_item oi
        on vor.order_item_id = oi.id
        left join t_supplier_info p
        on vor.supplier_id=p.id
        left join t_order o
        on vor.order_id= o.id
        and o.status_backend not in ('PENDING','CANCEL','REFUND')
        )  s group by dateinfo,supplier_id
    </select>
    <select id="getOrderSupplierCountReport" resultType="com.mzl.flower.dto.response.report.OrderSupplierReportResultVO">
        Select
        sum(order_supplier_price_amount) order_supplier_price_amount,
        sum(order_check_fee) order_check_fee,
        sum(order_lack_fee_supplier) order_lack_fee_supplier,
        sum(real_sale_num) real_sale_num,
        sum(sales_fee_supplier) sales_fee_supplier,
        sum(profitFeeAmount) profitFeeAmount
        from(
        select
        dateinfo,
        supplier_id,
        supplierName,
        sum(order_supplier_price_amount) order_supplier_price_amount,
        sum(order_check_fee) order_check_fee,
        sum(order_replace_fee) + sum(order_lack_fee_supplier) order_lack_fee_supplier,
        sum(order_num)-sum(order_lack_num) as real_sale_num,
        sum(sales_fee_supplier) sales_fee_supplier,
        sum(order_supplier_price_amount) -   sum(order_check_fee) - sum(order_replace_fee) -  sum(order_lack_fee_supplier) -  sum(sales_fee_supplier) profitFeeAmount
        from(
        SELECT
        oi.id,vor.*,p.name as supplierName
        FROM
        (<include refid="baseSupplierSql"></include>) vor
        left join t_order_item oi
        on vor.order_item_id = oi.id
        left join t_supplier_info p
        on vor.supplier_id=p.id
        left join t_order o
        on vor.order_id= o.id
        and o.status_backend not in ('PENDING','CANCEL','REFUND')
        )  s group by dateinfo,supplier_id
        ) s2
    </select>
</mapper>