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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?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.WalletReduceMapper">
 
 
    <select id="getPage" resultType="com.mzl.flower.dto.response.wallet.WalletReduceVO">
        select *
        from (
                 SELECT si.id as id
                      ,si.fee_supplier as fee
                      ,si.audit_time as audit_time
                      ,o.payment_time as payment_time
                      ,'sale' as type,'售后扣款' as type_name
                      ,o.order_no as order_no
                      ,oi.supplier_id as supplier_id
                 FROM t_order_item_sales si
                 join t_order_item oi on oi.id = si.order_item_id
                 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 si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
                and o.payment_time &gt;= #{dto.walletOnlineTime}
                <if test="dto.supplierId != null">
                    and oi.supplier_id = #{dto.supplierId}
                </if>
<!--                <if test="dto.startDate != null">-->
<!--                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}-->
<!--                </if>-->
<!--                <if test="dto.endDate != null">-->
<!--                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}-->
<!--                </if>-->
                <if test="dto.startDate != null">
                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &gt;= #{dto.startDate}
                </if>
                <if test="dto.endDate != null">
                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &lt;= #{dto.endDate}
                </if>
                 union
 
                 select  oic.id as id ,
                         oic.num*oi.supplier_price AS fee,
                         oic.audit_time AS audit_time,
                         o.payment_time as payment_time,
                         oic.type as type,
                         check_type.label as type_name,
                         o.order_no as order_no,
                         oi.supplier_id as supplier_id
                 from t_order_item_check oic
                 left join t_order_item oi
                 on oic.order_item_id=oi.id
                 left join t_order o
                 on oi.order_id=o.id
                 left join t_code_value check_type
                 on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
                 where o.deleted=0
                    and oic.type in ('lack','replace')
                    and o.status_backend not in ('PENDING','CANCEL','REFUND')
                    and  oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
                    and o.payment_time &gt;= #{dto.walletOnlineTime}
                <if test="dto.supplierId != null">
                    and oi.supplier_id = #{dto.supplierId}
                </if>
<!--                <if test="dto.startDate != null">-->
<!--                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}-->
<!--                </if>-->
<!--                <if test="dto.endDate != null">-->
<!--                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}-->
<!--                </if>-->
                <if test="dto.startDate != null">
                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &gt;= #{dto.startDate}
                </if>
                <if test="dto.endDate != null">
                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &lt;= #{dto.endDate}
                </if>
                union
                    select  oic.id as id ,
                    oic.deduct_amount AS fee,
                    oic.audit_time AS audit_time,
                    o.payment_time as payment_time,
                    oic.type as type,
                    check_type.label as type_name,
                    o.order_no as order_no,
                    oi.supplier_id as supplier_id
                    from t_order_item_check oic
                    left join t_order_item oi
                    on oic.order_item_id=oi.id
                    left join t_order o
                    on oi.order_id=o.id
                    left join t_code_value check_type
                    on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
                    where o.deleted=0
                    and oic.type in ('reduce')
                    and o.status_backend not in ('PENDING','CANCEL','REFUND')
                    and  oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
                    and o.payment_time &gt;= #{dto.walletOnlineTime}
                    <if test="dto.supplierId != null">
                        and oi.supplier_id = #{dto.supplierId}
                    </if>
                    <!--                <if test="dto.startDate != null">-->
                    <!--                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}-->
                    <!--                </if>-->
                    <!--                <if test="dto.endDate != null">-->
                    <!--                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}-->
                    <!--                </if>-->
                    <if test="dto.startDate != null">
                        and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &gt;= #{dto.startDate}
                    </if>
                    <if test="dto.endDate != null">
                        and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &lt;= #{dto.endDate}
                    </if>
 
             ) t
 
        order by audit_time desc
    </select>
    <select id="getCheckLackReplaceAmount" resultType="java.math.BigDecimal">
        select  sum(oic.num*oi.supplier_price)
        from t_order_item_check oic
        left join t_order_item oi
        on oic.order_item_id=oi.id
        left join t_order o
        on oi.order_id=o.id
        left join t_code_value check_type
        on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
        where o.deleted=0
          and oic.type in ('lack','replace')
          and o.status_backend not in ('PENDING','CANCEL','REFUND')
          and oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
          and oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt;= #{dto.startTime}
    </select>
    <select id="getSaleReduceAmount" resultType="java.math.BigDecimal">
 
        SELECT sum(si.fee_supplier)
        FROM t_order_item_sales si
        join t_order_item oi on oi.id = si.order_item_id
        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  si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
          and oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt;= #{dto.startTime}
    </select>
 
    <select id="getStationFeeAmount" resultType="java.math.BigDecimal">
        SELECT sum(ois.station_fee)
        FROM t_order_item_settlement ois
                 join t_order_item oi on oi.id = ois.order_item_id
                 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  ois.deleted=0 and oi.deleted=0
          and oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt;= #{dto.startTime}
    </select>
    <select id="getCheckReduceAmount" resultType="java.math.BigDecimal">
        select  sum(oic.deduct_amount)
        from t_order_item_check oic
         left join t_order_item oi
         on oic.order_item_id=oi.id
         left join t_order o
         on oi.order_id=o.id
         left join t_code_value check_type
        on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
        where o.deleted=0
          and oic.type in ('reduce')
          and o.status_backend not in ('PENDING','CANCEL','REFUND')
          and oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
          and oi.supplier_id = #{dto.supplierId}
          and o.payment_time &gt;= #{dto.startTime}
 
    </select>
</mapper>