1
zhujie
5 天以前 ec15861e14c66c38b1a8f5fffc6975d7da6c315c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?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="com.mzl.flower.mapper.wallet.WalletMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.mzl.flower.entity.wallet.WalletDO">
        <id column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="user_id" property="userId" />
        <result column="supplier_id" property="supplierId" />
        <result column="total_amount" property="totalAmount" />
        <result column="withdrawable_amount" property="withdrawableAmount" />
        <result column="withdrawing_amount" property="withdrawingAmount" />
        <result column="withdrawn_amount" property="withdrawnAmount" />
        <result column="settling_amount" property="settlingAmount" />
        <result column="total_deduction" property="totalDeduction" />
        <result column="total_transaction_amount" property="totalTransactionAmount" />
        <result column="settled_amount" property="settledAmount" />
 
    </resultMap>
    <select id="getWaittingSettlementAmount" resultType="java.math.BigDecimal">
        <include refid="supplier_settlement_amount_timing3"></include>
    </select>
 
    <!--    总交易额-->
    <select id="getSupplierTotalTransactionAmount" resultType="java.math.BigDecimal">
        select IFNULL(sum(oi.supplier_price*oi.num),0) as cur_mon_supplier_amount
        from t_order_item oi
        left join t_order o
        on oi.order_id = o.id
        where o.deleted=0
          and o.status_backend not in ('PENDING','CANCEL','REFUND')
          and  oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt; #{dto.startTime}
    </select>
 
 
    <!--    待结算-->
    <sql id="supplier_settlement_amount_timing">
        select
            sum(t2.final_price) as settlement_amount
        from(
                select
                    t.order_item_id,
                    t.supplier_id,
                    t.supplier_price,
                    t.supplier_price*(t.num-t.replace_num-t.lack_num )- t.deduct_amount -t.fee_supplier-t.station_fee as final_price,
                    t.fee_supplier,
                    t.station_fee
                from (
                         SELECT
                             o.order_no,
                             oi.id as order_item_id,
                             oi.supplier_id,
                             o.payment_time,
                             oi.supplier_price,
                             oi.num as num,
                             IFNULL( (select oic.deduct_amount from t_order_item_check oic where oic.deleted=0 and  oic.order_item_id = oi.id and oic.type = 'reduce' and oic.audit_status='AGREED'),0) as deduct_amount,
                             IFNULL( (select oic.num from t_order_item_check oic where oic.deleted=0 and  oic.order_item_id = oi.id and oic.type = 'replace' and oic.audit_status='AGREED'),0) as replace_num,
                             IFNULL( (select oic.num from t_order_item_check oic where oic.deleted=0 and  oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num,
                             IFNULL( (select ois.fee_supplier from ( select ois.order_item_id,sum(ois.fee_supplier) as fee_supplier  from t_order_item_sales ois where ois.deleted=0 and ois.status='AGREED' group by ois.order_item_id ) ois where  ois.order_item_id = oi.id ),0) as fee_supplier,
                             IFNULL( (select ois.station_fee from t_order_item_settlement ois where ois.deleted=0 and ois.order_item_id = oi.id ),0) as station_fee
                         FROM t_order_item oi
                         LEFT JOIN t_order o ON oi.order_id = o.id
                         WHERE o.deleted=0
                           and o.status_backend not in ('PENDING','CANCEL','REFUND','COMPLETED','EVALUATE')
                           and oi.supplier_id = #{dto.supplierId}
                     ) t
            ) t2
 
 
    </sql>
 
    <sql id="supplier_settlement_amount_timing3">
        select
            sum(t2.final_price) as settlement_amount
        from(
                select
                    t.order_item_id,
                    t.supplier_id,
                    t.supplier_price,
                    t.supplier_price*(t.num-t.replace_num-t.lack_num )- t.deduct_amount -t.fee_supplier-t.station_fee as final_price,
                    t.fee_supplier,
                    t.station_fee
                from (
                         SELECT
                             o.order_no,
                             oi.id as order_item_id,
                             oi.supplier_id,
                             o.payment_time,
                             oi.supplier_price,
                             oi.num as num,
                             IFNULL( (select oic.deduct_amount from t_order_item_check oic where oic.deleted=0 and  oic.order_item_id = oi.id and oic.type = 'reduce' and oic.audit_status='AGREED'),0) as deduct_amount,
                             IFNULL( (select oic.num from t_order_item_check oic where oic.deleted=0 and  oic.order_item_id = oi.id and oic.type = 'replace' and oic.audit_status='AGREED'),0) as replace_num,
                             IFNULL( (select oic.num from t_order_item_check oic where oic.deleted=0 and  oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num,
                             IFNULL( (select ois.fee_supplier from ( select ois.order_item_id,sum(ois.fee_supplier) as fee_supplier  from t_order_item_sales ois where ois.deleted=0 and ois.status='AGREED' group by ois.order_item_id ) ois where  ois.order_item_id = oi.id ),0) as fee_supplier,
                             IFNULL( (select ois.station_fee from t_order_item_settlement ois where ois.deleted=0 and ois.order_item_id = oi.id ),0) as station_fee
                         FROM t_order_item oi
                         LEFT JOIN t_order o ON oi.order_id = o.id
                         WHERE o.deleted=0
                           and o.status_backend not in ('PENDING','CANCEL','REFUND','COMPLETED')
                           and oi.supplier_id = #{dto.supplierId}
                     ) t
            ) t2
    </sql>
 
</mapper>