wzy
2021-04-01 d388e2788b7ef088d7cd40f901b0acdcec460bc3
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
<?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.hive.dao.MoneyCardUseDao">
    <!-- 定义MoneyCardUse 的复杂关联map -->
    <resultMap type="MoneyCardUse" id="MoneyCardUseMap">
        <id property="id" column="id"/>
        <result property="orderItemId" column="order_item_id"/>
        <result property="useTotal" column="use_total"/>
        <result property="lastCount" column="last_count"/>
        <result property="realMoney" column="real_money"/>
        <result property="giftMoney" column="gift_money"/>
        <result property="status" column="status"/>
        <result property="source" column="source"/>
        <result property="failTime" column="fail_time"/>
        <result property="goodsId" column="goods_id"/>
        <result property="vipId" column="vip_id"/>
        <result property="isOver" column="is_over"/>
        <result property="isVipCar" column="is_vip_car"/>
        <result property="remark" column="remark"/>
        <result property="cardName" column="card_name"/>
        <result property="orderId" column="orderId"/>
 
        <!-- 对应会员信息 -->
        <association property="vipInfo" javaType="SysVipInfo"
                     column="{id=vip_id}" select="com.matrix.system.hive.dao.SysVipInfoDao.selectById"/>
    </resultMap>
 
 
    <!-- 定义MoneyCardUse 的简单map  ,本map不添加其他的关联属性 -->
    <resultMap type="MoneyCardUse" id="MoneyCardUseSimpleMap">
        <id property="id" column="id"/>
        <result property="orderItemId" column="order_item_id"/>
        <result property="useTotal" column="use_total"/>
        <result property="lastCount" column="last_count"/>
        <result property="realMoney" column="real_money"/>
        <result property="giftMoney" column="gift_money"/>
        <result property="status" column="status"/>
        <result property="source" column="source"/>
        <result property="failTime" column="fail_time"/>
        <result property="goodsId" column="goods_id"/>
        <result property="vipId" column="vip_id"/>
        <result property="isOver" column="is_over"/>
        <result property="isVipCar" column="is_vip_car"/>
        <result property="remark" column="remark"/>
        <result property="cardName" column="card_name"/>
    </resultMap>
 
    <delete id="deleteByOrderItemId">
        delete from money_card_use where order_item_id=#{orderId}
    </delete>
 
    <!--  插入方法   -->
    <insert id="insert" parameterType="MoneyCardUse"
            useGeneratedKeys="true" keyProperty="id">
        INSERT INTO money_card_use (
            id,
            order_item_id,
            use_total,
            last_count,
            real_money,
            gift_money,
            status,
            source,
            fail_time,
            goods_id,
            vip_id,
            is_vip_car,
            is_over,
            remark,
            card_name
        )
    VALUES (
            #{id},
            #{orderItemId},
            #{useTotal},
            #{lastCount},
            #{realMoney},
            #{giftMoney},
            #{status},
            #{source},
            #{failTime},
            #{goodsId},
            #{vipId},
            #{isVipCar},
            #{isOver},
            #{remark},
            #{cardName}
    )
    </insert>
 
 
    <!--  根据id更新 部分更新   -->
    <update id="update">
        UPDATE money_card_use
        <set>
            <if test="orderItemId != null and orderItemId !='' ">
                order_item_id = #{orderItemId},
            </if>
            <if test="useTotal != null ">
                use_total = #{useTotal},
            </if>
            <if test="lastCount != null ">
                last_count = #{lastCount},
            </if>
 
            <if test="realMoney != null ">
                real_money = #{realMoney},
            </if>
            <if test="giftMoney != null ">
                gift_money = #{giftMoney},
            </if>
            <if test="status != null and status !='' ">
                status = #{status},
            </if>
            <if test="source != null and source !='' ">
                source = #{source},
            </if>
            <if test="failTime != null  ">
                fail_time = #{failTime},
            </if>
            <if test="goodsId != null and goodsId !='' ">
                goods_id = #{goodsId},
            </if>
            <if test="vipId != null and vipId !='' ">
                vip_id = #{vipId},
            </if>
            <if test="isOver != null and isOver !='' ">
                is_over = #{isOver},
            </if>
            <if test="isVipCar != null and isVipCar !='' ">
                is_vip_car = #{isVipCar},
            </if>
            <if test="remark != null and remark !='' ">
                remark = #{remark},
            </if>
            <if test="cardName != null and cardName !='' ">
                card_name = #{cardName},
            </if>
        </set>
        WHERE id=#{id}
    </update>
 
 
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from money_card_use where id in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </delete>
 
    <!-- 根据id删除-->
    <delete id="deleteById">
        DELETE FROM money_card_use
        where  id=#{id} 
    </delete>
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="MoneyCardUseMap">
        select
        id,
        order_item_id,
        use_total,
        last_count,
        real_money,
        gift_money,
        status,
        source,
        fail_time,
        goods_id,
        vip_id,
        is_over,
        is_vip_car,
        remark,
        card_name
        from money_card_use
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and order_item_id = #{record.orderItemId}
            </if>
            <if test="record.useTotal != null and record.useTotal !='' ">
                and use_total = #{record.useTotal}
            </if>
            <if test="record.lastCount != null and record.lastCount !='' ">
                and last_count = #{record.lastCount}
            </if>
            <if test="record.realMoney != null and record.realMoney !='' ">
                and real_money = #{record.realMoney}
            </if>
            <if test="record.giftMoney != null and record.giftMoney !='' ">
                and gift_money = #{record.giftMoney}
            </if>
            <if test="record.status != null and record.status !='' ">
                and status = #{record.status}
            </if>
            <if test="record.source != null and record.source !='' ">
                and source = #{record.source}
            </if>
            <if test="record.failTime != null  ">
                and fail_time = #{record.failTime}
            </if>
            <if test="record.goodsId != null and record.goodsId !='' ">
                and goods_id = #{record.goodsId}
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and vip_id = #{record.vipId}
            </if>
            <if test="record.isOver != null and record.isOver !='' ">
                and is_over = #{record.isOver}
            </if>
            <if test="record.isVipCar != null and record.isVipCar !='' ">
                and is_vip_car = #{record.isVipCar}
            </if>
            <if test="record.remark != null and record.remark !='' ">
                and remark = #{record.remark}
            </if>
            <if test="record.cardName != null and record.cardName !='' ">
                and card_name = #{record.cardName}
            </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>
 
    <!-- 查询总条数 -->
    <select id="selectTotalRecord" resultType="java.lang.Integer">
        select count(*)
        from money_card_use
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id}
            </if>
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and order_item_id = #{record.orderItemId}
            </if>
            <if test="record.useTotal != null and record.useTotal !='' ">
                and use_total = #{record.useTotal}
            </if>
            <if test="record.lastCount != null and record.lastCount !='' ">
                and last_count = #{record.lastCount}
            </if>
            <if test="record.realMoney != null and record.realMoney !='' ">
                and real_money = #{record.realMoney}
            </if>
            <if test="record.giftMoney != null and record.giftMoney !='' ">
                and gift_money = #{record.giftMoney}
            </if>
            <if test="record.status != null and record.status !='' ">
                and status = #{record.status}
            </if>
            <if test="record.source != null and record.source !='' ">
                and source = #{record.source}
            </if>
            <if test="record.failTime != null  ">
                and fail_time = #{record.failTime}
            </if>
            <if test="record.goodsId != null and record.goodsId !='' ">
                and goods_id = #{record.goodsId}
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and vip_id = #{record.vipId}
            </if>
            <if test="record.isOver != null and record.isOver !='' ">
                and is_over = #{record.isOver}
            </if>
            <if test="record.isVipCar != null and record.isVipCar !='' ">
                and is_vip_car = #{record.isVipCar}
            </if>
            <if test="record.remark != null and record.remark !='' ">
                and remark = #{record.remark}
            </if>
            <if test="record.cardName != null and record.cardName !='' ">
                and card_name = #{record.cardName}
            </if>
        </if>
    </select>
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="MoneyCardUseMap">
        select *
        from money_card_use
        where  id=#{id} 
    </select>
 
    <!--获取会员的会籍卡-->
    <select id="selectVipCard" resultMap="MoneyCardUseMap">
        select *
        from money_card_use
        where  vip_id=#{vipId} and card_name='储值卡'
    </select>
 
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="MoneyCardUseMap">
        select *
        from money_card_use
        where 1=1
        <if test="record!=null">
            <if test="record.id != null and record.id !='' ">
                and id = #{record.id} ,
            </if>
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and order_item_id = #{record.orderItemId}
            </if>
            <if test="record.useTotal != null and record.useTotal !='' ">
                and use_total = #{record.useTotal}
            </if>
            <if test="record.lastCount != null and record.lastCount !='' ">
                and last_count = #{record.lastCount}
            </if>
            <if test="record.realMoney != null and record.realMoney !='' ">
                and real_money = #{record.realMoney}
            </if>
            <if test="record.giftMoney != null and record.giftMoney !='' ">
                and gift_money = #{record.giftMoney}
            </if>
            <if test="record.status != null and record.status !='' ">
                and status = #{record.status}
            </if>
            <if test="record.source != null and record.source !='' ">
                and source = #{record.source}
            </if>
            <if test="record.failTime != null  ">
                and fail_time = #{record.failTime}
            </if>
            <if test="record.goodsId != null and record.goodsId !='' ">
                and goods_id = #{record.goodsId}
            </if>
            <if test="record.vipId != null and record.vipId !='' ">
                and vip_id = #{record.vipId}
            </if>
            <if test="record.isOver != null and record.isOver !='' ">
                and is_over = #{record.isOver}
            </if>
            <if test="record.isVipCar != null and record.isVipCar !='' ">
                and is_vip_car = #{record.isVipCar}
            </if>
            <if test="record.remark != null and record.remark !='' ">
                and remark = #{record.remark}
            </if>
            <if test="record.cardName != null and record.cardName !='' ">
                and card_name = #{record.cardName}
            </if>
        </if>
        order by is_over ,fail_time
    </select>
 
 
    <!-- 分页查询vip的充值卡 -->
    <select id="selectVipCardUseInPage" resultMap="MoneyCardUseMap">
        select
        a.id,
        a.order_item_id,
        d.id AS orderId,
        a.use_total,
        a.last_count,
        a.real_money,
        a.gift_money,
        a.status,
        a.source,
        a.fail_time,
        a.goods_id,
        a.vip_id,
        a.is_over,
        a.is_vip_car,
        a.remark,
        a.card_name
        from money_card_use a
        left join shopping_goods b on a.goods_id=b.id
        left join sys_order_item c on a.ORDER_ITEM_ID=c.id
        left join sys_order d on c.ORDER_ID=d.id
        where a.vip_id = #{record.vipId}
        <if test="record!=null">
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and a.order_item_id = #{record.orderItemId}
            </if>
            <if test="record.status != null and record.status !='' ">
                and a.status = #{record.status}
            </if>
            <if test="record.source != null and record.source !='' ">
                and a.source = #{record.source}
            </if>
 
            <if test="record.isOver != null and record.isOver !='' ">
                and a.is_over = #{record.isOver}
            </if>
            <if test="record.isVipCar != null and record.isVipCar !='' ">
                and a.is_vip_car = #{record.isVipCar}
            </if>
 
            <if test="record.remark != null and record.remark !='' ">
                and a.remark = #{record.remark}
            </if>
            <if test="record.cardName != null and record.cardName !='' ">
                and card_name = #{record.cardName}
            </if>
        </if>
        order by a.is_over ,a.fail_time
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <!-- 查询总条数 -->
    <select id="selectVipCardUseTotal" resultType="java.lang.Integer">
        select count(*)
        from money_card_use a
        left join shopping_goods b on a.goods_id=b.id
        left join sys_order_item c on a.ORDER_ITEM_ID=c.id
        left join sys_order d on c.ORDER_ID=d.id
        where a.vip_id = #{record.vipId}
        <if test="record!=null">
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and a.order_item_id = #{record.orderItemId}
            </if>
            <if test="record.status != null and record.status !='' ">
                and a.status = #{record.status}
            </if>
            <if test="record.source != null and record.source !='' ">
                and a.source = #{record.source}
            </if>
            <if test="record.isOver != null and record.isOver !='' ">
                and a.is_over = #{record.isOver}
            </if>
            <if test="record.isVipCar != null and record.isVipCar !='' ">
                and a.is_vip_car = #{record.isVipCar}
            </if>
            <if test="record.remark != null and record.remark !='' ">
                and a.remark = #{record.remark}
            </if>
 
            <if test="record.cardName != null and record.cardName !='' ">
                and card_name = #{record.cardName}
            </if>
        </if>
    </select>
 
    <!--查询vip的充值卡 -->
    <select id="selectVipCardUse" resultMap="MoneyCardUseMap">
        select
        a.id,
        a.order_item_id,
        a.use_total,
        a.last_count,
        a.real_money,
        a.gift_money,
        a.status,
        a.source,
        a.fail_time,
        a.goods_id,
        a.vip_id,
        a.is_over,
        a.is_vip_car,
        a.remark,
        a.card_name
        from money_card_use a
        left join shopping_goods b on a.goods_id=b.id
        where vip_id = #{record.vipId}
        <if test="record!=null">
            <if test="record.orderItemId != null and record.orderItemId !='' ">
                and a.order_item_id = #{record.orderItemId}
            </if>
            <if test="record.status != null and record.status !='' ">
                and a.status = #{record.status}
            </if>
            <if test="record.source != null and record.source !='' ">
                and a.source = #{record.source}
            </if>
 
            <if test="record.isOver != null and record.isOver !='' ">
                and a.is_over = #{record.isOver}
            </if>
            <if test="record.isVipCar != null and record.isVipCar !='' ">
                and a.is_vip_car = #{record.isVipCar}
            </if>
 
            <if test="record.remark != null and record.remark !='' ">
                and a.remark = #{record.remark}
            </if>
            <if test="record.cardName != null and record.cardName !='' ">
                and card_name = #{record.cardName}
            </if>
        </if>
        order by a.is_over ,a.fail_time
    </select>
 
    <select id="selectItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        select c.VIP_NAME,
        a.card_name,
        a.real_money,
        a.gift_money,
        a.IS_OVER,
        a.FAIL_TIME,
        a.is_vip_car,
        a.SOURCE,
        e.ORDER_NO,
        a.remark,
        a.card_name
        from money_card_use a
        left join sys_vip_info c on c.ID = a.VIP_ID
        left join sys_order_item d on d.id = a.ORDER_ITEM_ID
        left join sys_order e on e.id = d.ORDER_ID
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="vipQueryKey != null and vipQueryKey != ''  ">
                and c.VIP_NAME like concat('%',#{vipQueryKey},'%')
                or (c.VIP_NO like concat('%',#{vipQueryKey},'%')
                or c.PHONE like concat('%',#{vipQueryKey},'%')
                )
            </if>
            <if test="goodsName != null and goodsName != ''  ">
                b.name like concat('%',#{goodsName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                b.cate_id=#{cateId}
            </if>
        </where>
 
        <if test="sort !=null and sort!=''"> order by ${sort} ${order}</if>
        <if test="(offset !=null and offset!='') or offset==0 ">
            limit ${offset},${limit}
        </if>
    </select>
 
    <select id="selectItemDetailTotal" resultType="java.lang.Integer">
        select count(a.id)
        from money_card_use a
        left join shopping_goods b on a.goods_id = b.id
        left join sys_vip_info c on c.ID = a.VIP_ID
        left join sys_order_item d on d.id = a.ORDER_ITEM_ID
        left join sys_order e on e.id = d.ORDER_ID
        left join shopping_goods_category f on f.id = b.cate_id
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="vipQueryKey != null and vipQueryKey != ''  ">
                and e.VIP_NAME like concat('%',#{vipQueryKey},'%')
                or (e.VIP_NO like concat('%',#{vipQueryKey},'%')
                or e.PHONE like concat('%',#{vipQueryKey},'%')
                )
            </if>
            <if test="goodsName != null and goodsName != ''  ">
                b.name like concat('%',#{goodsName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                b.cate_id=#{cateId}
            </if>
        </where>
    </select>
 
    <select id="summaryItemDetail" resultType="java.util.HashMap" parameterType="java.util.HashMap">
        select
        a.card_name,
        b.id,
        ROUND( SUM(a.real_money),2)as real_money,
        ROUND(SUM(a.gift_money),2) as gift_money
        from money_card_use a
        left join shopping_goods b on a.goods_id = b.id
        left join sys_vip_info c on c.ID = a.VIP_ID
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="goodsName != null and goodsName != ''  ">
                b.name like concat('%',#{goodsName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                b.cate_id=#{cateId}
            </if>
        </where>
        group by b.id
 
        <if test="sort !=null and sort!=''"> order by ${sort} ${order}</if>
        <if test="(offset !=null and offset!='') or offset==0 ">
            limit ${offset},${limit}
        </if>
    </select>
 
    <select id="summaryItemDetailTotal" resultType="java.lang.Integer">
        select count(1) from (
        select count(1)
        from money_card_use a
        left join shopping_goods b on a.goods_id = b.id
        left join sys_vip_info c on c.ID = a.VIP_ID
        <where>
            <if test="shopId != null and  shopId != ''">
                and c.shop_id =#{shopId}
            </if>
            <if test="goodsName != null and goodsName != ''  ">
                b.name like concat('%',#{goodsName},'%')
            </if>
            <if test="cateId != null and cateId != ''  ">
                b.cate_id=#{cateId}
            </if>
        </where>
        group by b.id) t
    </select>
 
    <select id="selectVipCardTotalMoney" resultType="java.lang.Double">
            SELECT TRUNCATE( SUM(gift_money)+SUM(real_money) ,2 ) from money_card_use where vip_id=#{vipId}  and `status` ='有效'
    </select>
 
 
    <select id="selectHasValidMoneyCardUse" resultMap="MoneyCardUseSimpleMap">
        select * from money_card_use
        where date_format(now(), '%Y-%m-%d') > date_format(FAIL_TIME, '%Y-%m-%d') and STATUS='有效'
    </select>
</mapper>