Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
<?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.matrix.system.shopXcx.dao.ShopOrderDao">
    <!-- 定义ShopOrder 的简单map  ,本map不添加其他的关联属性 -->
    <resultMap type="com.matrix.system.shopXcx.bean.ShopOrder" id="ShopOrderMap">
        <id property="id" column="id" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
            <result property="orderNo" column="order_no" />
            <result property="orderMoney" column="order_money" />
            <result property="commodityPrice" column="commodity_price" />
            <result property="userId" column="user_id" />
            <result property="orderTime" column="order_time" />
            <result property="payStatus" column="pay_status" />
            <result property="discountExplain" column="discount_explain" />
            <result property="discountAmount" column="discount_amount" />
            <result property="orderStatus" column="order_status" />
            <result property="refundCharge" column="refund_charge" />
            <result property="userName" column="user_name" />
            <result property="userTel" column="user_tel" />
            <result property="remarks" column="remarks" />
            <result property="shippingMethod" column="shipping_method"/>
            <result property="storeId" column="store_id" />
            <result property="purchaseQuantity" column="purchase_quantity" />
            <result property="delFlag" column="del_flag" />
            <result property="wxOrderNo" column="wx_order_no" />
            <result property="payResult" column="pay_result" />
            <result property="postage" column="postage" />
            <result property="storeName" column="shop_name" />
            <result property="orderType" column="order_type" />
            <result property="applyStatus" column="apply_status" />
            <result property="scorePay" column="score_pay" />
            <result property="payMethod" column="pay_method" />
            <result property="companyId" column="company_id" />
            <!--返回详情列表-->
            <collection property="details" column="{orderId=id}"
                        select="com.matrix.system.shopXcx.dao.ShopOrderDetailsDao.selectByOrderId"/>
    </resultMap>
 
 
    <!-- 定义ShopOrder 的复杂map -->
    <resultMap type="com.matrix.system.shopXcx.bean.ShopOrder" id="ShopOrderComplexMap">
        <id property="id" column="id" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="payMethod" column="pay_method" />
            <result property="orderNo" column="order_no" />
            <result property="orderMoney" column="order_money" />
            <result property="commodityPrice" column="commodity_price" />
            <result property="userId" column="user_id" />
            <result property="orderTime" column="order_time" />
            <result property="payStatus" column="pay_status" />
            <result property="discountExplain" column="discount_explain" />
            <result property="discountAmount" column="discount_amount" />
            <result property="orderStatus" column="order_status" />
            <result property="refundCharge" column="refund_charge" />
            <result property="userName" column="user_name" />
            <result property="userTel" column="user_tel" />
            <result property="remarks" column="remarks" />
            <result property="shippingMethod" column="shipping_method"/>
            <result property="storeId" column="store_id" />
            <result property="purchaseQuantity" column="purchase_quantity" />
            <result property="delFlag" column="del_flag" />
            <result property="wxOrderNo" column="wx_order_no" />
            <result property="payResult" column="pay_result" />
            <result property="postage" column="postage" />
            <result property="orderType" column="order_type" />
            <result property="storeName" column="shop_name" />
        <result property="scorePay" column="score_pay" />
            <result property="companyId" column="company_id" />
        <result property="activityType" column="activity_type" />
        <!--支付时间-->
        <association property="paymentTime" column="{orderId=id}"
                     select="selectPaymentTimeByOrderId"/>
        <!--开票数量-->
        <association property="invoiceCount" column="{orderId=id}"
                     select="selectInvoiceCountByOrderId"/>
        <!--发货信息-->
        <association property="deliveryInfo" column="{orderId=id}"
                     select="com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao.selectByOrderId"/>
 
        <!--返回详情列表-->
        <collection property="details" column="{orderId=id}"
                    select="com.matrix.system.shopXcx.dao.ShopOrderDetailsDao.selectByOrderId"/>
    </resultMap>
 
    <!--根据订单ID查询开发票数量-->
    <select id="selectInvoiceCountByOrderId" resultType="java.lang.Integer">
        select count(*)
        from shop_invoice
        where order_id = #{orderId}
    </select>
 
    <!--根据订单ID查询支付时间-->
    <select id="selectPaymentTimeByOrderId" resultType="java.util.Date">
        select create_time
        from shop_pay_log
        where pay_type = 1 and pay_status = 2
        and join_id = #{orderId}
    </select>
 
    <!-- 字段sql -->
    <sql id="columns">
        create_by,
        create_time,
        update_by,
        update_time,
            id,
            order_no,
            order_money,
            commodity_price,
            user_id,
            order_time,
            pay_status,
            discount_explain,
            discount_amount,
            order_status,
            refund_charge,
            user_name,
            user_tel,
            remarks,
            shipping_method,
            store_id,
            purchase_quantity,
            del_flag,
            wx_order_no,
            pay_result,
            postage,
            order_type,
            activity_type,
score_pay,
 
        pay_method,
            company_id
    </sql>
    
    <!-- 属性sql -->
    <sql id="propertys">
        #{item.createBy},
        now(),
        #{item.updateBy},
        now(),
            #{item.id},
            #{item.orderNo},
            #{item.orderMoney},
            #{item.commodityPrice},
            #{item.userId},
            now(),
            #{item.payStatus},
            #{item.discountExplain},
            #{item.discountAmount},
            #{item.orderStatus},
            #{item.refundCharge},
            #{item.userName},
            #{item.userTel},
            #{item.remarks},
            #{item.shippingMethod},
            #{item.storeId},
            #{item.purchaseQuantity},
            #{item.delFlag},
            #{item.wxOrderNo},
            #{item.payResult},
            #{item.postage},
            #{item.orderType},
            #{item.activityType},
            #{item.scorePay},
            #{item.payMethod},
            #{item.companyId}
    </sql>
    
    <!-- where sql -->
    <sql id="where_sql">
         
         <if test="record!=null">
            <if test="(record.id!=null and record.id!='') or  (record.id!='' and record.id==0)  ">
                and id  = #{record.id} 
            </if>
            <if test="(record.orderNo!=null and record.orderNo!='') or  (record.orderNo!='' and record.orderNo==0)  ">
                and order_no like concat('%', #{record.orderNo}, '%')
            </if>
            <if test="(record.orderMoney!=null and record.orderMoney!='') or  (record.orderMoney!='' and record.orderMoney==0)  ">
                and order_money  = #{record.orderMoney} 
            </if>
             <if test="(record.commodityPrice!=null and record.commodityPrice!='') or  (record.commodityPrice!='' and record.commodityPrice==0)  ">
                 and commodity_price  = #{record.commodityPrice}
             </if>
            <if test="(record.userId!=null and record.userId!='') or  (record.userId!='' and record.userId==0)  ">
                and user_id  = #{record.userId} 
            </if>
            <if test="(record.orderTime!=null and record.orderTime!='') or  (record.orderTime!='' and record.orderTime==0)  ">
                and order_time  = #{record.orderTime} 
            </if>
            <if test="(record.payStatus!=null and record.payStatus!='') or  (record.payStatus!='' and record.payStatus==0)  ">
                and pay_status  = #{record.payStatus} 
            </if>
            <if test="(record.discountExplain!=null and record.discountExplain!='') or  (record.discountExplain!='' and record.discountExplain==0)  ">
                and discount_explain  = #{record.discountExplain} 
            </if>
            <if test="(record.discountAmount!=null and record.discountAmount!='') or  (record.discountAmount!='' and record.discountAmount==0)  ">
                and discount_amount  = #{record.discountAmount} 
            </if>
            <if test="(record.orderStatus!=null and record.orderStatus!='') or  (record.orderStatus!='' and record.orderStatus==0)  ">
                and order_status  = #{record.orderStatus} 
            </if>
            <if test="(record.refundCharge!=null and record.refundCharge!='') or  (record.refundCharge!='' and record.refundCharge==0)  ">
                and refund_charge  = #{record.refundCharge} 
            </if>
            <if test="(record.userName!=null and record.userName!='') or  (record.userName!='' and record.userName==0)  ">
                and user_name  like concat('%', #{record.userName}, '%')
            </if>
            <if test="(record.userTel!=null and record.userTel!='') or  (record.userTel!='' and record.userTel==0)  ">
                and user_tel  like concat('%', #{record.userTel}, '%')
            </if>
            <if test="(record.remarks!=null and record.remarks!='') or  (record.remarks!='' and record.remarks==0)  ">
                and remarks  = #{record.remarks} 
            </if>
            <if test="(record.shippingMethod!=null and record.shippingMethod!='') or  (record.shippingMethod!='' and record.shippingMethod==0)  ">
                 and shipping_method  = #{record.shippingMethod}
            </if>
            <if test="(record.storeId!=null and record.storeId!='') or  (record.storeId!='' and record.storeId==0)  ">
                and store_id  = #{record.storeId} 
            </if>
            <if test="(record.purchaseQuantity!=null and record.purchaseQuantity!='') or  (record.purchaseQuantity!='' and record.purchaseQuantity==0)  ">
                and purchase_quantity  = #{record.purchaseQuantity} 
            </if>
            <if test="(record.delFlag!=null and record.delFlag!='') or  (record.delFlag!='' and record.delFlag==0)  ">
                and del_flag  = #{record.delFlag} 
            </if>
            <if test="(record.wxOrderNo!=null and record.wxOrderNo!='') or  (record.wxOrderNo!='' and record.wxOrderNo==0)  ">
                and wx_order_no  = #{record.wxOrderNo} 
            </if>
            <if test="(record.payResult!=null and record.payResult!='') or  (record.payResult!='' and record.payResult==0)  ">
                and pay_result  = #{record.payResult} 
            </if>
             <if test="(record.postage!=null and record.postage!='') or  (record.postage!='' and record.postage==0)  ">
                 and postage  = #{record.postage}
             </if>
             <if test="(record.orderType!=null and record.orderType!='') or  (record.orderType!='' and record.orderType==0)  ">
                 and order_type  = #{record.orderType}
             </if>
             <if test="(record.companyId!=null and record.companyId!='') or  (record.companyId!='' and record.companyId==0)  ">
                 and company_id  = #{record.companyId}
             </if>
 
        </if>
         
    </sql>
    
    <!--  插入方法   -->
    <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopOrder"
        useGeneratedKeys="true" keyProperty="item.id">
        INSERT INTO shop_order (
             <include refid="columns"></include>
        )
    VALUES (
         <include refid="propertys"></include>
    )
    </insert>
    
    
    
    <!--  批量插入   -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO shop_order (
        <include refid="columns"></include>    
        )
    VALUES 
    <foreach collection="list" item="item" index="index" separator=",">(
        <include refid="propertys"></include>    
    )</foreach>
    </insert>
    
    
    
    
    
    <!--  根据Map更新 部分更新   -->
    <update id="updateByMap" parameterType="java.util.HashMap" >
        UPDATE shop_order
        <set>
            <if test="_parameter.containsKey('orderNo')">
                    order_no = #{orderNo},
                </if>        
            <if test="_parameter.containsKey('orderMoney')">
                    order_money = #{orderMoney},
                </if>
            <if test="_parameter.containsKey('commodityPrice')">
                    commodity_price = #{commodityPrice},
                </if>
            <if test="_parameter.containsKey('userId')">
                    user_id = #{userId},
                </if>        
            <if test="_parameter.containsKey('orderTime')">
                    order_time = #{orderTime},
                </if>        
            <if test="_parameter.containsKey('payStatus')">
                    pay_status = #{payStatus},
                </if>        
            <if test="_parameter.containsKey('discountExplain')">
                    discount_explain = #{discountExplain},
                </if>        
            <if test="_parameter.containsKey('discountAmount')">
                    discount_amount = #{discountAmount},
                </if>        
            <if test="_parameter.containsKey('orderStatus')">
                    order_status = #{orderStatus},
                </if>        
            <if test="_parameter.containsKey('refundCharge')">
                    refund_charge = #{refundCharge},
                </if>        
            <if test="_parameter.containsKey('userName')">
                    user_name = #{userName},
                </if>        
            <if test="_parameter.containsKey('userTel')">
                    user_tel = #{userTel},
                </if>        
            <if test="_parameter.containsKey('remarks')">
                    remarks = #{remarks},
                </if>
            <if test="_parameter.containsKey('shippingMethod')">
                shipping_method = #{shippingMethod},
                </if>
            <if test="_parameter.containsKey('storeId')">
                    store_id = #{storeId},
                </if>        
            <if test="_parameter.containsKey('purchaseQuantity')">
                    purchase_quantity = #{purchaseQuantity},
                </if>        
            <if test="_parameter.containsKey('delFlag')">
                    del_flag = #{delFlag},
                </if>        
            <if test="_parameter.containsKey('wxOrderNo')">
                    wx_order_no = #{wxOrderNo},
                </if>        
            <if test="_parameter.containsKey('payResult')">
                    pay_result = #{payResult},
                </if>
            <if test="_parameter.containsKey('postage')">
                postage = #{postage},
                </if>
            <if test="true">
                update_time  = now(),
            </if>
            <if test="_parameter.containsKey('orderType')">
                order_type  = #{orderType},
            </if>
            <if test="_parameter.containsKey('scorePay')">
                score_pay  = #{scorePay},
            </if>
        </set>
        WHERE id=#{id} 
    </update> 
    
    
    <!--  根据对象更新 部分更新   -->
    <update id="updateByModel" parameterType="Integer">
        UPDATE shop_order
        <set>
            <if test="record.orderNo != null and record.orderNo != '' ">
                order_no  = #{record.orderNo},
            </if>
            <if test="record.orderMoney != null ">
                order_money  = #{record.orderMoney}, 
            </if>
            <if test="record.commodityPrice != null ">
                commodity_price  = #{record.commodityPrice},
            </if>
            <if test="record.userId != null and record.userId != '' ">
                user_id  = #{record.userId}, 
            </if>
            <if test="record.orderTime != null ">
                order_time  = #{record.orderTime}, 
            </if>
            <if test="record.payStatus != null ">
                pay_status  = #{record.payStatus}, 
            </if>
            <if test="record.discountExplain != null and record.discountExplain != '' ">
                discount_explain  = #{record.discountExplain}, 
            </if>
            <if test="record.discountAmount != null ">
                discount_amount  = #{record.discountAmount}, 
            </if>
            <if test="record.orderStatus != null ">
                order_status  = #{record.orderStatus}, 
            </if>
            <if test="record.refundCharge != null ">
                refund_charge  = #{record.refundCharge}, 
            </if>
            <if test="record.userName != null and record.userName != '' ">
                user_name  = #{record.userName}, 
            </if>
            <if test="record.userTel != null and record.userTel != '' ">
                user_tel  = #{record.userTel}, 
            </if>
            <if test="record.remarks != null and record.remarks != '' ">
                remarks  = #{record.remarks}, 
            </if>
            <if test="record.shippingMethod != null ">
                shipping_method  = #{record.shippingMethod},
            </if>
            <if test="record.storeId != null ">
                store_id  = #{record.storeId}, 
            </if>
            <if test="record.purchaseQuantity != null ">
                purchase_quantity  = #{record.purchaseQuantity}, 
            </if>
            <if test="record.delFlag != null ">
                del_flag  = #{record.delFlag}, 
            </if>
            <if test="record.wxOrderNo != null and record.wxOrderNo != '' ">
                wx_order_no  = #{record.wxOrderNo}, 
            </if>
            <if test="record.payResult != null and record.payResult != '' ">
                pay_result  = #{record.payResult}, 
            </if>
            <if test="record.postage != null and record.postage != '' ">
                postage  = #{record.postage},
            </if>
            <if test="record.scorePay != null and record.scorePay != '' ">
                score_pay  = #{record.scorePay},
            </if>
            <if test="true">
                update_time  = now(),
            </if>
 
            <if test="(record.orderType!=null and record.orderType!='') or  (record.orderType!='' and record.orderType==0)  ">
                order_type  =#{record.orderType},
            </if>
 
        </set>
        WHERE id=#{record.id} 
    </update>
    
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from shop_order where  id in
        <foreach collection="list" index="index" item="item" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </delete>
        
    <!-- 根据id删除-->
    <delete id="deleteById" parameterType="Integer">
        DELETE FROM shop_order
        where  id=#{id} 
    </delete>
    
    <!-- 根据对象删除-->
    <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopOrder">
        DELETE FROM shop_order
        <where>
        <include refid="where_sql" ></include>
        </where>
    </delete>
    
    
    
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="ShopOrderMap">
        select 
        <include refid="columns" ></include>
        from shop_order
        <where>
          <include refid="where_sql"></include>
         </where>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
    
    <!-- 查询总条数 -->
    <select id="selectTotalRecord" parameterType="long"   resultType="java.lang.Integer">
    select count(*)
    from shop_order
        <where>
           <include refid="where_sql"></include>
        </where>
    </select>
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="ShopOrderMap">
        select 
        <include refid="columns" ></include>
        from shop_order
        where  id=#{id} 
    </select>    
    
    
    <!-- 根据id 锁表查询-->
    <select id="selectForUpdate" resultMap="ShopOrderMap">
        select 
        <include refid="columns" ></include>
        from shop_order
        where  id=#{id} 
        for update
    </select>    
    
    
    
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="ShopOrderMap">
        select 
        <include refid="columns" ></include>
        from shop_order
        <where>
          <include refid="where_sql"></include>
         </where>
    </select>
 
    <!--根据状态查询订单列表-->
    <select id="selectMyOrderByStatus" resultMap="ShopOrderComplexMap">
        select o.*,
        s.shop_short_name as shop_name
        from shop_order o
        left JOIN sys_shop_info s on o.store_id = s.ID
        where user_id = #{userId}
        and del_flag = 2
        <if test="params.orderStatus != 0">
            and order_status = #{params.orderStatus}
        </if>
        order by ${params.sort} ${params.order}
        limit #{params.offset}, #{params.limit}
    </select>
 
    <!--根据ID状态查询订单信息-->
    <select id="selectOrderInfoById" resultMap="ShopOrderComplexMap">
        select o.*,
        s.shop_name
        from shop_order o
        LEFT JOIN sys_shop_info s on o.store_id = s.ID
        where user_id = #{userId}
        and o.id = #{id}
        and del_flag = 2
    </select>
 
    <!-- 分页查询 -->
    <select id="selectInPageByQuery" resultMap="ShopOrderComplexMap">
        select
        o.*,
        s.shop_name
        from shop_order o
        INNER JOIN sys_shop_info s on o.store_id = s.ID
        where del_flag = 2 and o.company_id  = #{record.companyId}
        <if test="record != null">
            <if test="(record.userTel!=null and record.userTel!='')">
                and  o.user_tel like concat('%', #{record.userTel}, '%')
            </if>
            <if test="(record.userName!=null and record.userName!='')">
                and o.user_name like concat('%', #{record.userName}, '%')
            </if>
            <if test="(record.orderNo!=null and record.orderNo!='')">
                and  o.order_no like concat('%', #{record.orderNo}, '%')
            </if>
            <if test="(record.orderBeginTime!=null and record.orderBeginTime!='')">
                and date_format(order_time, '%Y-%m-%d') >= #{record.orderBeginTime}
            </if>
            <if test="(record.orderEndTime!=null and record.orderEndTime!='')">
                and  #{record.orderEndTime} >= date_format(o.order_time, '%Y-%m-%d')
            </if>
            <if test="(record.orderStatus!=null and record.orderStatus!='')">
                and  o.order_status = #{record.orderStatus}
            </if>
            <if test="(record.storeName!=null and record.storeName!='')">
                and s.shop_name like concat('%', #{record.storeName}, '%')
            </if>
            <if test="(record.shopId!=null and record.shopId!='')">
                and o.store_id=#{record.shopId}
            </if>
 
 
        </if>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <!-- 导出Excel -->
    <select id="selectInPageByQueryOfExcel" resultMap="ShopOrderComplexMap">
        select
        o.create_by,
        o.create_time,
        o.update_by,
        o.update_time,
        o.id,
        o.order_no,
        o.order_money,
        o.commodity_price,
        o.user_id,
        o.order_time,
        o.pay_status,
        o.discount_explain,
        o.discount_amount,
        o.order_status,
        o.refund_charge,
        o.user_name,
        o.user_tel,
        o.remarks,
        o.shipping_method,
        o.store_id,
        o.purchase_quantity,
        o.del_flag,
        o.wx_order_no,
        o.pay_result,
        o.postage,
               o.pay_method,
        s.shop_name,
        o.order_type
        from shop_order o
        LEFT JOIN sys_shop_info s on o.store_id = s.ID
        where del_flag = 2 and o.company_id  = #{record.companyId}
 
        <if test="record != null">
            <if test="(record.userTel!=null and record.userTel!='')">
                and  o.user_tel like concat('%', #{record.userTel}, '%')
            </if>
            <if test="(record.userName!=null and record.userName!='')">
                and o.user_name like concat('%', #{record.userName}, '%')
            </if>
            <if test="(record.orderNo!=null and record.orderNo!='')">
                and  o.order_no like concat('%', #{record.orderNo}, '%')
            </if>
            <if test="(record.orderBeginTime!=null and record.orderBeginTime!='')">
                and date_format(o.order_time, '%Y-%m-%d') >= #{record.orderBeginTime}
            </if>
            <if test="(record.orderEndTime!=null and record.orderEndTime!='')">
                and  #{record.orderEndTime} >= date_format(o.order_time, '%Y-%m-%d')
            </if>
            <if test="(record.orderStatus!=null and record.orderStatus!='')">
                and  o.order_status = #{record.orderStatus}
            </if>
            <if test="(record.storeName!=null and record.storeName!='')">
                and s.shop_name like concat('%', #{record.storeName}, '%')
            </if>
        </if>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
        </if>
    </select>
 
    <!-- 查询总条数 -->
    <select id="selectTotalRecordByQuery" resultType="java.lang.Integer">
        select count(*)
        from shop_order o
        INNER JOIN sys_shop_info s on o.store_id = s.ID
        where del_flag = 2 and o.company_id  = #{record.companyId}
        <if test="record != null">
            <if test="(record.userTel!=null and record.userTel!='')">
                and  o.user_tel like concat('%', #{record.userTel}, '%')
            </if>
            <if test="(record.userName!=null and record.userName!='')">
                and o.user_name like concat('%', #{record.userName}, '%')
            </if>
            <if test="(record.orderNo!=null and record.orderNo!='')">
                and  o.order_no like concat('%', #{record.orderNo}, '%')
            </if>
            <if test="(record.orderBeginTime!=null and record.orderBeginTime!='')">
                and date_format(o.order_time, '%Y-%m-%d') >= #{record.orderBeginTime}
            </if>
            <if test="(record.orderEndTime!=null and record.orderEndTime!='')">
                and  #{record.orderEndTime} >= date_format(o.order_time, '%Y-%m-%d')
            </if>
            <if test="(record.orderStatus!=null and record.orderStatus!='')">
                and  o.order_status = #{record.orderStatus}
            </if>
            <if test="(record.storeName!=null and record.storeName!='')">
                and s.shop_name like concat('%', #{record.storeName}, '%')
            </if>
            <if test="(record.shopId!=null and record.shopId!='')">
                and o.store_id=#{record.shopId}
            </if>
        </if>
    </select>
 
    <!--根据订单ID查询订单信息-->
    <select id="selectMyOrderById" resultMap="ShopOrderComplexMap">
        select
        <include refid="columns" ></include>
        from shop_order
        where id = #{orderId}
    </select>
 
    <select id="selectOrdersByIds" resultMap="ShopOrderMap">
        select * from shop_order a
        inner join sys_shop_info b on a.store_id=b.id
        where a.store_id=#{shopId}
        and a.id in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </select>
 
    <update id="updateOrderApplyStatus">
        <foreach collection="list" index="index" item="item" separator=";">
            update shop_order set apply_status=#{item.applyStatus}
            where id=#{item.id}
        </foreach>
    </update>
 
    <select id="selectShopOrderByApplyId" resultMap="ShopOrderMap">
        select a.* from shop_order a
        inner join wx_apply_order_relate b on find_in_set(',' + a.id, b.order_ids)
        where b.apply_id=#{applyId}
    </select>
 
    <select id="selectShopOrderInPageByApplyId" resultMap="ShopOrderMap">
        select a.* from shop_order a
        inner join wx_apply_order_relate b on find_in_set(',' + a.id, b.order_ids)
        where b.apply_id=#{applyId}
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <select id="selectShopOrderTotalByApplyId" resultType="java.lang.Integer">
        select count(1) from shop_order a
        inner join wx_apply_order_relate b on find_in_set(',' + a.id, b.order_ids)
        where b.apply_id=#{applyId}
    </select>
 
    <select id="selectOrderStatusCount"  resultType="java.util.HashMap"  >
        select  count(order_status) as count , order_status as orderStatus
        from shop_order
        where user_id=#{userId}
        group by order_status
    </select>
 
    <select id="selectShopOrderByOrderNo"  resultType="com.matrix.system.shopXcx.bean.ShopOrder"  >
        select
        a.*
        from shop_order a
        where a.order_no=#{orderNo}
    </select>
 
    <update id="batchUpdateOrderStatus">
        <foreach collection="list" index="index" item="item" separator=";">
            update shop_order set order_status=#{item.orderStatus}
            where id=#{item.id}
        </foreach>
    </update>
</mapper>