Helius
2021-06-30 02b38bb7c08d68fffc6af25e4ba00a456d96e94e
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<?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.xzx.gc.order.mapper.OrderManageMapper">
 
    <select id="queryStaticDataToday" resultType="map">
        SELECT
        IFNULL(e.weight, 0) AS weight,
        IFNULL(e.money, 0) AS money,
        a.title as config_value_name
        FROM xzx_sys_environmental_info a
        LEFT JOIN (
        SELECT
        SUM(b.money) as money,
        SUM(b.weight) as weight,
        b.item_type,
        b.flag
        FROM xzx_order_storage_info c
        LEFT JOIN xzx_order_storage_detail b ON c.storage_id = b.storage_id
        WHERE b.flag = #{flag}
 
        <if test="startTime != null and startTime != ''">
            and c.storage_time BETWEEN #{startTime} AND #{endTime}
        </if>
 
        <if test="receiverphone != null and receiverphone != ''">
            and c.receiver_phone=#{receiverphone}
        </if>
        GROUP BY b.item_type
        ) e ON e.item_type = a.item_type
        WHERE a.del_flag = 0 and a.parent_id is NOT NULL;
    </select>
    <select id="queryOrderIdsByStorageId" resultType="java.lang.String">
        SELECT order_id
        FROM xzx_order_storage_info
        where storage_id = #{storageId}
    </select>
    <select id="queryCuserOrderByUserIdCount1" resultType="java.util.Map">
        SELECT
            count(a.order_id)                                           as count,
            (select count(b.order_id)
             from xzx_order_info b
             where b.order_status = 3 and b.create_user_id = #{userId}) as count1
        FROM xzx_order_info a
        WHERE a.create_user_id = #{userId} and a.order_status in (4, 5, 7)
    </select>
    <select id="queryOrderByOrderId" resultType="java.lang.String">
        select receiver
        from xzx_order_info
        WHERE order_id = #{orderId}
    </select>
    <select id="queryUserIdByOrderId" resultType="java.lang.String">
        select create_user_id
        from xzx_order_info
        WHERE order_id = #{orderId}
    </select>
    <select id="queryOrderPageByOrderno" resultType="map">
        SELECT a.address, a.address_area, a.order_type, a.order_status,a.create_time,
           a.rela_name as relaName,b.*,e.item_type, e.cweight AS cweight, e.camount as camount,
           e.cmoney as cmoney, e.title as title,a.reserve_time as reserveTime,b.address_id as addressId
    FROM xzx_order_info a
    LEFT JOIN xzx_order_detail_info b ON a.order_id=b.order_id
    LEFT JOIN(
         select c.item_type, c.weight AS cweight, c.amount as camount,c.order_id,
           c.money as cmoney,d.title FROM xzx_order_item_info c
          LEFT JOIN xzx_sys_environmental_info d ON c.item_type = d.item_type
          WHERE c.money>0
      )e on a.order_id = e.order_id
        WHERE a.order_id = #{orderNo}
        group by e.item_type
 
    </select>
    <select id="queryOrderList" resultType="map">
        SELECT
        a.order_id,
        a.create_time,
        a.reserve_time,
        a.order_type,
        a.order_status,
        c.nick_name,
        c.name,
        a.rela_name,
        b.money,
        SUM(f.weight) AS weight
        FROM xzx_order_info a
        LEFT JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        LEFT JOIN xzx_user_other_info c ON a.receiver = c.user_id
        LEFT JOIN xzx_order_item_info f ON a.order_id = f.order_id
        WHERE 1 = 1
 
        <if test="orderStatus != null and orderStatus != ''">
            AND a.order_status=#{orderStatus}
        </if>
 
        <if test="startTime != null and startTime != ''">
            AND a.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
 
        <if test="orderType != null and orderType != ''">
            AND a.order_type = #{orderType}
        </if>
 
        <if test="name != null and name != ''">
            AND c.name = #{name}
        </if>
 
        <if test="mobilePhone != null and mobilePhone != ''">
            AND c.mobile_phone = #{mobilePhone}
        </if>
        GROUP BY a.create_time desc
    </select>
    <select id="queryOrderApiList" resultType="com.xzx.gc.model.admin.OrderModel">
        SELECT a.order_id as orderId,a.create_time as createTime,a.reserve_time as reserveTime,a.order_type as
        orderType,a.rela_phone as relaPhone,b.receive_time as receiveTime,b.complete_time as
        completeTime,b.cancel_reason_name as cancelReasonName,
        a.order_status as orderStatus,IFNULL(d.nick_name,c.nick_name) as nickName,c.name as name,d.mobile_phone as
        mobilePhone,a.rela_name as relaName,SUM(f.money) as orderMoney,SUM(f.weight) AS orderWeight,IFNULL(b.mark_read,0) as markRead,
        b.order_fast_flag as orderFastFlag,b.mark_code as markCode,d.partner_id as partnerId,IFNULL(c.del_flag,0) as delFlag
        FROM xzx_order_info a
        LEFT JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        LEFT JOIN xzx_user_info d ON a.create_user_id = d.user_id
        LEFT JOIN xzx_user_other_info c ON a.receiver = c.user_id
        LEFT JOIN xzx_order_item_info f ON a.order_id = f.order_id
        LEFT JOIN xzx_user_address_info k ON b.address_id=k.address_id
        WHERE 1 = 1
        <if test="orderStatus != null and orderStatus != ''">
            AND a.order_status=#{orderStatus}
        </if>
 
        <if test="startTime != null and startTime != ''">
            AND a.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
 
        <if test="orderType != null and orderType != ''">
            AND a.order_type = #{orderType}
        </if>
 
        <if test="name != null and name != ''">
            AND c.name like concat('%',#{name} ,'%')
        </if>
 
        <if test="mobilePhone != null and mobilePhone != ''">
            AND (d.mobile_phone like concat('%',#{mobilePhone} ,'%') or d.nick_name = #{nickName} or a.rela_phone like concat('%',#{mobilePhone} ,'%'))
        </if>
 
        <if test="orderId != null and orderId != ''">
            AND a.order_id like concat('%',#{orderId} ,'%')
        </if>
 
        <if test="createType != null and createType != ''">
            AND a.create_type = #{createType}
        </if>
 
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND c.partner_id in
            <foreach collection="partnerIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
        <if test="townIds != null">
            AND k.township_id in
            <foreach collection="townIds" index="index" item="tid" separator="," open="(" close=")">
                #{tid}
            </foreach>
        </if>
        GROUP BY a.order_id
        order by a.create_time desc
    </select>
    <select id="queryOrderByTownIdApiList" resultType="com.xzx.gc.model.admin.OrderModel">
        SELECT a.order_id as orderId,a.create_time as createTime,a.reserve_time as reserveTime,a.order_type as
        orderType,
        a.rela_phone as relaPhone,m.receive_time as receiveTime,
        m.complete_time as completeTime,
        m.cancel_reason_name as cancelReasonName,
        a.order_status as orderStatus,
        IFNULL(d.nick_name,c.nick_name) as nickName,
        c.name as name,d.mobile_phone as mobilePhone,a.rela_name as relaName,
        m.orderMoney as orderMoney,m.orderWeight AS orderWeight,
        m.order_fast_flag as orderFastFlag,
        m.mark_code as markCode,
        IFNULL(m.mark_read,0) as markRead,
        d.partner_id as partnerId,
        IFNULL(c.del_flag,0) as delFlag
        FROM xzx_order_info a
        LEFT JOIN ( select SUM(f.money) as orderMoney,SUM(f.weight) AS orderWeight,b.order_id,
        b.complete_time,b.cancel_reason_name,b.receive_time,b.order_fast_flag,b.mark_code,b.mark_read
        from
        xzx_order_detail_info b
        LEFT JOIN xzx_order_item_info f ON f.order_id = b.order_id
        where 1=1 group by b.order_id
        )m ON m.order_id=a.order_id
        LEFT JOIN xzx_user_info d ON a.create_user_id = d.user_id
        LEFT JOIN xzx_user_other_info c ON a.receiver = c.user_id
        WHERE 1=1
 
        <if test="orderStatus != null and orderStatus != ''">
            AND a.order_status=#{orderStatus}
        </if>
 
        <if test="startTime != null and startTime != ''">
            AND a.create_time BETWEEN #{startTime} AND #{endTime}
        </if>
 
        <if test="orderType != null and orderType != ''">
            AND a.order_type = #{orderType}
        </if>
 
        <if test="name != null and name != ''">
            AND c.name like concat('%',#{name} ,'%')
        </if>
 
        <if test="mobilePhone != null and mobilePhone != ''">
            AND (d.mobile_phone like concat('%',#{mobilePhone} ,'%') or d.nick_name = #{nickName} or a.rela_phone like concat('%',#{mobilePhone} ,'%'))
        </if>
 
        <if test="orderId != null and orderId != ''">
            AND a.order_id like concat('%',#{orderId},'%')
        </if>
 
        <if test="createType != null and createType != ''">
            AND a.create_type = #{createType}
        </if>
 
        <if test="townIds != null and townIds.size()>0">
            AND a.town_id in
            <foreach collection="townIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
        GROUP BY a.order_id
        order by a.create_time desc
    </select>
    <select id="queryTownIdsByPartnerIds" parameterType="java.util.List" resultType="java.lang.String">
        select distinct fence_id from xzx_partner_fence where 1=1
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND partner_id in
            <foreach collection="partnerIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="queryStatusByCuserId" resultType="map">
        SELECT
            COUNT(*)       as count,
            a.order_status as orderStatus
        FROM xzx_order_info a
        WHERE a.receiver = #{userId}
        GROUP BY a.order_status
    </select>
    <select id="queryOrderByPartnerId" resultType="java.lang.String">
        select a.town_id
        from xzx_order_info a
        where a.order_id = #{orderId}
    </select>
    <update id="updateOrderStatus">
        update xzx_order_info
        <set>
            <if test="orderStatus != null and orderStatus != ''">
                order_status=#{orderStatus},
            </if>
 
            <if test="receiveId != null and receiveId != ''">
                receiver=#{receiveId},
            </if>
        </set>
        where order_id=#{orderId}
    </update>
    <update id="updateApirecByOrderId">
        update xzx_order_info
        set receiver = #{receiveId}, order_status = 2, trace_id = #{trid}
        where order_id = #{orderId}
    </update>
    <update id="updateApirecDetailByOrderId">
        update xzx_order_detail_info
        set receive_time = SYSDATE(), receiver_phone = #{mobilePhone}, receiver_name = #{name}
        where order_id = #{orderId}
    </update>
    <update id="updateOrderStatus1">
        update xzx_order_info
        set order_status = #{orderStatus}
        where order_id = #{orderId}
    </update>
    <update id="updateOrderDetailReData">
        update xzx_order_detail_info
        set cancel_reason_name = #{cancelReasonName}
        where order_id = #{orderId}
    </update>
    <select id="queryOrderReNum" resultType="java.lang.String">
        select count(order_id)
        from xzx_order_info
        where del_flag = 0 and receiver = #{userId} and order_status = 2
    </select>
    <select id="queryStorageApiList" resultType="map">
        select
        a.storage_id as storageId,
        IFNULL(x.name,a.storage_user_name) as storageName,
        a.storage_user_phone as storageUserPhone,
        (select user_type
        from xzx_user_other_info
        where user_id = receiver) as userType,
        receiver_name as receiverName,
        receiver as receiver,
        receiver_phone as receiverPhone,
        storage_time as storageTime,
        IFNULL(a.recycle_weight,'0') as recycleWeight,
        IFNULL(a.storage_weight,'0') as storageWeight,
        IFNULL(a.storage_money,'0') as storageMoney,
        IFNULL(a.recycle_money,'0') as recycleMoney,
        x.del_flag as delFlag,
        IFNULL(y.create_time,'-') as batchTime,
        y.vehicle_id as vehicleId,
        y.batch_no as batchNo,
        y.emptyWeight as emptyWeight,
        y.batchWeight as batchWeight,
        IFNULL((select z.storage_name
        from xzx_sys_storage z
        where a.sys_storage_id = z.id and a.sys_storage_type=1),(select m.partner_name from xzx_city_partner m where m.id=x.partner_id and a.sys_storage_type=2)) as sysStorageName,
        (select m.partner_name from xzx_city_partner m where m.id=x.partner_id) as partnerName
        from xzx_order_storage_info a
        LEFT JOIN (
        select f.create_time,b.order_id,b.vehicle_id,b.batch_no,b.weight as batchWeight,f.weight as emptyWeight from xzx_user_vehicle_info f
        LEFT JOIN  xzx_order_batch_info b ON f.id=b.vehicle_id
        WHERE  f.id=b.vehicle_id GROUP BY b.order_id
        )y ON y.order_id = a.order_id
        left join xzx_user_other_info x on x.user_id = a.storage_user_id
        where 1 = 1
        <if test="orderStatus != null and orderStatus != ''">
            AND a.storage_status = #{storageStatus}
        </if>
        <if test="storageStatus != null and storageStatus != ''">
          AND a.storage_status = #{storageStatus}
        </if>
        <if test="startTime != null and startTime != ''">
            AND a.storage_time >= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND a.storage_time &lt;= #{endTime}
        </if>
        <if test="name != null and name != ''">
            AND (a.receiver_name like concat('%',#{name} ,'%') or a.receiver_phone like concat('%',#{name} ,'%') or
            a.storage_id like concat('%',#{name} ,'%') )
        </if>
 
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND x.partner_id in
            <foreach collection="partnerIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
        group by a.storage_id
        order by a.storage_time desc
    </select>
    <select id="queryStorageDetailApiList" resultType="map">
        SELECT a.order_id as orderid,a.create_time as createtime,
        c.name as name,c.mobile_phone as mobilephone,SUM(f.money) as ordermoney,SUM(f.weight) AS orderweight
        FROM xzx_order_info a
        LEFT JOIN xzx_order_detail_info b ON a.order_id = b.order_id
        LEFT JOIN xzx_user_other_info c ON a.receiver = c.user_id
        LEFT JOIN xzx_order_item_info f ON a.order_id = f.order_id
        WHERE 1=1
        <if test="orderIds != null and orderIds.size() != 0">
            AND a.order_id in
            <foreach collection="orderIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
 
        GROUP BY a.order_id desc
    </select>
    <select id="queryStroageDetailPageByOrderno" resultType="map">
        select
        IFNULL(sum(a.money),0) as recyclemoney,
        IFNULL(sum(a.weight),0) as recycleweight,
        d.title,
        IFNULL((SELECT c.money
        from xzx_order_storage_detail c
        where a.item_type = c.item_type and c.flag=1
        <if test="storageId != null and storageId != ''">
            AND c.storage_id =#{storageId}
        </if>
        group by item_type),0) as storagemoney,
        IFNULL((SELECT c.weight
        from xzx_order_storage_detail c
        where a.item_type = c.item_type and c.flag=1
        <if test="storageId != null and storageId != ''">
            AND c.storage_id =#{storageId}
        </if>
        group by item_type),0) as storageweight
        from xzx_order_item_info a
        LEFT JOIN  (select f.township_id,e.order_id from  xzx_order_detail_info e
        LEFT JOIN xzx_user_address_info f on f.address_id=e.address_id
        )m  ON a.order_id=m.order_id
        LEFT JOIN xzx_sys_environmental_info d ON d.item_type = a.item_type and m.township_id=d.city_id
        where 1 = 1 AND a.money<![CDATA[> ]]>0 and a.weight<![CDATA[> ]]>0
        <if test="orderIds != null and orderIds.size() != 0">
            AND a.order_id in
            <foreach collection="orderIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
        GROUP BY a.item_type
    </select>
    <select id="queryProvince" resultType="com.xzx.gc.model.admin.SysAddressLevelModel">
        select
            level_1_id   as level1Id,
            level_1_name as level1Name
        from xzx_sys_address_level_info
        where 1 = 1
        group by level_1_id
    </select>
    <select id="queryCityByProvinceId" resultType="com.xzx.gc.model.admin.SysAddressLevelModel">
        select
            level_2_id   as level2Id,
            level_2_name as level2Name
        from xzx_sys_address_level_info
        where 1 = 1 and level_1_id = #{provinceId}
        group by level_2_id
    </select>
    <select id="queryTownShipByCityId" resultType="com.xzx.gc.model.admin.SysAddressLevelModel">
        select
            level_3_id   as level3Id,
            level_3_name as level3Name
        from xzx_sys_address_level_info
        where 1 = 1 and level_2_id = #{cityId}
        group by level_3_id
    </select>
    <update id="updateOrderReserveTime">
        update xzx_order_detail_info
        set reserve_time = #{reserveDate},receive_time=null,receiver_name=null
        where order_id = #{orderId}
    </update>
    <update id="updateOrderInfoReserveTime">
        update xzx_order_info
        set reserve_time = #{reserveDate},order_status=1,receiver=null
        where order_id = #{orderId}
    </update>
    <delete id="updateOrderDetailByNo">
        update xzx_order_detail_info set mark_read='1' where  order_id=#{orderId}
    </delete>
 
 
</mapper>