xuhy
2024-08-24 146cffe8e1a2223677dadf2b51e6fd4fd08e5810
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?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.ruoyi.order.mapper.TShoppingOrderMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.order.api.model.TShoppingOrder">
        <id column="id" property="id" />
        <result column="code" property="code" />
        <result column="app_user_id" property="appUserId" />
        <result column="order_type" property="orderType" />
        <result column="goods_id" property="goodsId" />
        <result column="coupon_id" property="couponId" />
        <result column="purchase_quantity" property="purchaseQuantity" />
        <result column="app_user_address_id" property="appUserAddressId" />
        <result column="order_amount" property="orderAmount" />
        <result column="app_coupon_id" property="appCouponId" />
        <result column="coupon_discount_amount" property="couponDiscountAmount" />
        <result column="vip_discount" property="vipDiscount" />
        <result column="vip_discount_amount" property="vipDiscountAmount" />
        <result column="payment_amount" property="paymentAmount" />
        <result column="payment_status" property="paymentStatus" />
        <result column="payment_type" property="paymentType" />
        <result column="serial_number" property="serialNumber" />
        <result column="remark" property="remark" />
        <result column="status" property="status" />
        <result column="express_company" property="expressCompany" />
        <result column="express_number" property="expressNumber" />
        <result column="consigner_id" property="consignerId" />
        <result column="consigner_time" property="consignerTime" />
        <result column="receiving_time" property="receivingTime" />
        <result column="cancellation_time" property="cancellationTime" />
        <result column="cancellation_id" property="cancellationId" />
        <result column="refund_code" property="refundCode" />
        <result column="refund_amount" property="refundAmount" />
        <result column="refund_status" property="refundStatus" />
        <result column="refund_serial_number" property="refundSerialNumber" />
        <result column="refund_time" property="refundTime" />
        <result column="create_time" property="createTime" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code, app_user_id, order_type, goods_id, coupon_id, purchase_quantity, app_user_address_id, order_amount, app_coupon_id, coupon_discount_amount, vip_discount, vip_discount_amount, payment_amount, payment_status, payment_type, serial_number, remark, status, express_company, express_number, consigner_id, consigner_time, receiving_time, cancellation_time, cancellation_id, refund_code, refund_amount, refund_status, refund_serial_number, refund_time, create_time, del_flag
    </sql>
    <select id="activityStatistics" resultType="com.ruoyi.order.api.vo.TActivityStatisticslVO">
        <if test="req.orderType == null or req.orderType == 1">
        <if test="req.type == null or req.type == 1 or req.type == 2">
        select t1.code ,t1.order_amount as orderAmount,
               t1.coupon_discount_amount as couponDiscountAmount,
               t1.vip_discount_amount as vipDiscountAmount,
               t1.payment_amount as paymentAmount,
               t1.create_time as createTime,
               1 as orderType
            from t_charging_order t1
            where 1 = 1
            <if test="null != req.code and req.code!=''">
                and t1.code  LIKE CONCAT('%',#{req.code},'%')
            </if>
            <if test="req.type != null and req.type != '' and req.type == 1">
                and t1.coupon_discount_amount  IS NOT NULL and t1.coupon_discount_amount  != 0
            </if>
            <if test="req.type != null and req.type != '' and req.type == 2">
                and t1.vip_discount_amount  IS NOT NULL and t1.vip_discount_amount  != 0
            </if>
            <if test="null != req.userIds and req.userIds.size()>0" >
                and t1.app_user_id in
                <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="null != req.chargingPileIds and req.chargingPileIds.size()>0" >
                and t1.charging_pile_id in
                <foreach collection="req.chargingPileIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                AND (t1.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
            </if>
        and t1.recharge_payment_status =2
        and t1.refund_status !=2
            AND t1.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </if>
        </if>
        <if test="req.orderType == null or req.orderType == 2">
        <if test="req.type == null or req.type == 1 or req.type == 2">
            union all
            select t2.code ,t2.order_amount as orderAmount,
            t2.coupon_discount_amount as couponDiscountAmount,
            t2.vip_discount_amount as vipDiscountAmount,
            t2.payment_amount as paymentAmount,
            t2.create_time as createTime,
            2 as orderType
            from t_shopping_order t2
            where 1 = 1
            <if test="null != req.code and req.code!=''">
                and t2.code  LIKE CONCAT('%',#{req.code},'%')
            </if>
            <if test="req.type != null and req.type != '' and req.type == 1">
                and t2.coupon_discount_amount  IS NOT NULL and t2.coupon_discount_amount  != 0
            </if>
            <if test="req.type != null and req.type != '' and req.type == 2">
                and t2.vip_discount_amount  IS NOT NULL and t2.vip_discount_amount  != 0
            </if>
            <if test="req.type == null ">
                and t2.vip_discount_amount  IS NOT NULL and t2.vip_discount_amount  != 0 and t2.coupon_discount_amount  IS NOT NULL and t2.coupon_discount_amount  != 0
            </if>
            <if test="null != req.userIds and req.userIds.size()>0" >
                and t2.app_user_id in
                <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                AND (t2.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
            </if>
            and t2.refund_status !=2
            and t2.payment_status =2
            AND t2.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </if>
        </if>
        <if test="req.orderType == null or req.orderType == 3">
            <if test="req.type == null or req.type == 3">
                union all
                select t3.code ,t3.order_amount as orderAmount,
                0 as couponDiscountAmount,
                t3.discount_amount as vipDiscountAmount,
                t3.payment_amount as paymentAmount,
                t3.create_time as createTime,
                3 as orderType
                from t_vip_order t3
                where 1 = 1
                and t3.type =1
                <if test="null != req.code and req.code!=''">
                    and t3.code  LIKE CONCAT('%',#{req.code},'%')
                </if>
                <if test="req.type == null ">
                    and t3.discount_amount  IS NOT NULL and t3.discount_amount  != 0
                </if>
                <if test="null != req.userIds and req.userIds.size()>0" >
                    and t3.app_user_id in
                    <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                    AND (t3.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                </if>
                and t3.payment_status =2
                AND t3.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            </if>
        </if>
        <if test="req.orderType == null or req.orderType == 4">
            <if test="req.type == null or req.type == 4">
                union all
                select t4.code ,t4.order_amount as orderAmount,
                0 as couponDiscountAmount,
                t4.discount_amount as vipDiscountAmount,
                t4.payment_amount as paymentAmount,
                t4.create_time as createTime,
                4 as orderType
                from t_vip_order t4
                where 1 = 1
                and t4.type =2
                <if test="null != req.code and req.code!=''">
                    and t4.code  LIKE CONCAT('%',#{req.code},'%')
                </if>
                <if test="req.type == null ">
                    and t4.discount_amount  IS NOT NULL and t4.discount_amount  != 0
                </if>
                <if test="null != req.userIds and req.userIds.size()>0" >
                    and t4.app_user_id in
                    <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                    AND (t4.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                </if>
                and t4.payment_status =2
                AND t4.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            </if>
        </if>
        <if test="req.orderType == null or req.orderType == 4">
            <if test="req.type == null or req.type == 4">
                union all
                select t5.code ,t5.order_amount as orderAmount,
                0 as couponDiscountAmount,
                0 as vipDiscountAmount,
                0 as paymentAmount,
                t5.create_time as createTime,
                4 as orderType
                from t_grant_vip t5
                where 1 = 1
                <if test="null != req.code and req.code!=''">
                    and t5.code  LIKE CONCAT('%',#{req.code},'%')
                </if>
                <if test="null != req.userIds and req.userIds.size()>0" >
                    and t5.app_user_id in
                    <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                    AND (t5.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                </if>
                AND t5.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
 
            </if>
        </if>
    </select>
    
    
    
    <select id="getNoInvoicedOrder" resultMap="BaseResultMap">
        select * from t_shopping_order where del_flag = 0 and app_user_id = #{appUserId}
        <if test="null != month and '' != month">
            and DATE_FORMAT(create_time, '%Y-%m') = #{month}
        </if>
        and id not in (select order_id from t_order_invoice_detail where order_type = 2)
        order by create_time desc
        <if test="null != pageCurr and null != pageSize">
            limit #{pageCurr}, #{pageSize}
        </if>
    </select>
    <select id="pageList" resultType="com.ruoyi.order.api.model.TShoppingOrder">
        select t1.*
        from t_shopping_order t1
        where 1=1
        <if test="null != req.code and req.code!=''">
            and t1.code  LIKE CONCAT('%',#{req.code},'%')
        </if>
        <if test="null != req.userIds and req.userIds.size()>0" >
            and t1.app_user_id in
            <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
 
        <if test="null != req.couponIds and req.couponIds.size()>0 or null != req.couponIds and req.couponIds.size()>0" >
            and (t1.goods_id in
            <foreach collection="req.goodsIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
                     or
            and t1.coupon_id in
            <foreach collection="req.couponIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
            )
        </if>
        <if test="startTime1 != null and startTime1!=''">
            and (t1.create_time between #{startTime1} and #{startTime2}
        </if>
        and t1.payment_status = 2
        AND t1.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
    </select>
</mapper>