Helius
2022-02-21 f54f8a92c09a2cd76b3bbb796df680215b63ab8a
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
<?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.user.mapper.AccountMapper">
    <resultMap id="AccountMap" type="com.xzx.gc.model.user.AccountVo">
        <result column="account_id" jdbcType="VARCHAR" property="accountId"/>
        <result column="account_name" jdbcType="VARCHAR" property="accountName"/>
        <result column="user_id" jdbcType="VARCHAR" property="userId"/>
        <result column="pay_password" jdbcType="VARCHAR" property="payPassword"/>
        <result column="freeze_money" jdbcType="VARCHAR" property="freezeMoney"/>
        <result column="withdraw_money" jdbcType="VARCHAR" property="withdrawMoney"/>
        <result column="overdraft_limit" jdbcType="VARCHAR" property="overdraftLimit"/>
        <result column="lock_time" jdbcType="VARCHAR" property="lockTime"/>
    </resultMap>
 
    <resultMap id="UserInfoMap" type="com.xzx.gc.model.user.UserInfoVo">
        <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
        <result column="user_type" jdbcType="VARCHAR" property="userType"/>
        <result column="user_id" jdbcType="VARCHAR" property="userId"/>
        <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone"/>
    </resultMap>
 
 
    <update id="updateAccountWarehousingPrice">
        update xzx_account_info set
        <if test="oldOverdrawPrice != null and oldOverdrawPrice != ''">
            overdraft_limit=#{oldOverdrawPrice},
        </if>
        fixed_limit=#{newOverdrawPrice}
        where del_flag=0
        and user_id in
        <foreach collection="orderIds" index="index" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>
 
    <update id="updateAccountOverdrawPrice">
        update xzx_account_info set
        overdraft_limit=#{newOverdrawPrice},
        fixed_limit=#{newOverdrawPrice}
        where del_flag=0 and overdraft_limit=#{oldOverdrawPrice}
        and user_id in
        <foreach collection="orderIds" index="index" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </update>
 
    <update id="updateCuserAccount">
        update xzx_account_info set del_flag=0 where del_flag=1
        <if test="userId != null and userId != ''">
            and user_id=#{userId}
        </if>
        <if test="phone != null and phone != ''">
            and account_name=#{phone}
        </if>
        order by account_id desc limit 1
    </update>
 
    <insert id="addCuserAccountRole">
        INSERT INTO xzx_account_info(`account_id`,`account_name`, `user_id`, `pay_password`, `money`, `freeze_money`,
                                     `withdraw_money`, `overdraft_limit`, `lock_time`,`fixed_limit`)
        VALUES (#{id}, #{phone}, #{userId}, NULL, '0', '0', '0', #{money}, NULL,#{money})
    </insert>
 
    <update id="updateAccountLimit">
        update  xzx_account_info set fixed_limit=#{fixedLimit},overdraft_limit=#{overdraftLimit} where account_id=#{accountId}
    </update>
 
    <select id="queryAccountByUserIds" resultType="com.xzx.gc.model.admin.AccountMoneyModel">
        select * from xzx_account_info
        <if test="userFlag==1">
            inner join xzx_user_info  on xzx_account_info.user_id=xzx_user_info.user_id
        </if>
 
        where xzx_account_info.del_flag=0
        <if test=" userIds != null and userIds.size() != 0 and userFlag!=1">
            AND user_id in
            <foreach collection="userIds" index="index" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
 
 
        <if test="isProhibit != null and isProhibit != ''">
            AND is_prohibit = #{isProhibit}
        </if>
        order by CAST(money AS DECIMAL) desc
    </select>
 
    <update id="updateAccountType">
        update xzx_account_info
        set is_prohibit = #{isProhibit}
        where account_id = #{accountId}
    </update>
 
    <update id="updateAccountPartner">
        update xzx_account_info
        set money = #{money}
        where user_id = #{userId}
    </update>
 
    <select id="getAccountByUserId" resultType="com.xzx.gc.model.admin.UserAccountModel">
        select *
        from xzx_account_info
        where user_id = #{userId} and del_flag = 0
    </select>
 
    <update id="updateUserAccount">
        update xzx_account_info
        set money = #{money}, overdraft_limit = #{overdraftLimit}
        where user_id = #{userId} and del_flag = 0
    </update>
 
    <delete id="deleteAccount">
        update xzx_account_info
        set del_flag = 1
        where account_id = #{accountId}
    </delete>
 
    <select id="queryAccountByAccountId" resultType="com.xzx.gc.model.admin.AccountMoneyModel">
        select * from  xzx_account_info where account_id=#{accountId}
    </select>
 
    <select id="findArea" resultType="com.xzx.gc.entity.OrderInfo">
        SELECT a.user_id "userId",a.money,c.township_id  "townId",d.level_3_name "townShipName"
            ,c.longitude,c.latitude
        from xzx_account_info a
            inner JOIN xzx_user_info b
                on a.user_id=b.user_id
            left JOIN xzx_user_address_info c on b.user_id=c.user_id and c.del_flag=0   AND c.flag=1
            left join  xzx_sys_address_level_info d on c.township_id=d.level_3_id
        where a.del_flag=0 and b.del_flag=0
              and cast(a.money as DECIMAL(9,2))>0
 
    </select>
 
 
    <insert id="insertScoreDetailsRet">
        insert into xzx_score_details (CREATED_TIME, user_id, type, original_score, change_score, current_score)
        values (
                   #{createdTime}, #{userId}, #{type}, #{originalScore}, #{changeScore}, #{currentScore}
               )
    </insert>
 
 
 
    <select id="selectOneByUserId" resultType="com.xzx.gc.entity.AccountInfo">
        select * from  xzx_account_info where user_id = #{userId}
    </select>
 
    <select id="selectDsitribListByQueryCol" resultType="com.xzx.gc.user.vo.DistribListVo">
        SELECT
        a.account_id id,
        a.is_head isHead,
        b.nick_name nickname,
        b.regist_time registTime,
        b.mobile_phone phone
        FROM
        xzx_account_info a
        LEFT JOIN xzx_user_info b on a.user_id = b.user_id
        <where>
            1=1
            <if test="record.queryCol != null and record.queryCol != ''">
                and (b.nick_name like concat('%',#{record.name},'%')
                or b.mobile_phone like concat('%',#{record.phone},'%') )
            </if>
        </where>
        order by id desc
    </select>
 
    <select id="selectDsitribInfoListByQueryCol" resultType="com.xzx.gc.user.vo.DistribInfoListVo">
        SELECT
        a.account_id id,
        b.nick_name nickname,
        b.mobile_phone phone,
        b.regist_time registTime,
        a.is_head isHead,
        (select IFNULL(count(1), 0) from xzx_user_head_relate where head_user_id = a.user_id ) cnt,
        (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id ) orderCnt,
        (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id ) amount,
        (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id ) score,
        a.is_prohibit isProhibit
        FROM
        xzx_account_info a
        LEFT JOIN xzx_user_info b on a.user_id = b.user_id
        <where>
            1=1
            and a.is_head = 1
            <if test="record.name != null and record.name != ''">
                and b.nick_name like concat('%',#{record.name},'%')
            </if>
            <if test="record.phone != null and record.phone != ''">
                and b.mobile_phone like concat('%',#{record.phone},'%')
            </if>
            <if test="record.isProhibit != null and record.isProhibit != ''">
                and  a.is_prohibit = #{record.isProhibit}
            </if>
            <if test="record.reserveTimeStart != null">
                and b.regist_time >= #{record.reserveTimeStart}
            </if>
 
            <if test="record.reserveTimeEnd != null">
                and b.regist_time &lt;= #{record.reserveTimeEnd}
            </if>
        </where>
         order by id desc
    </select>
 
    <select id="selectDistribByAccountId" resultType="com.xzx.gc.user.vo.ViewDistribInfoVo">
        SELECT
        a.account_id id,
        b.nick_name nickname,
        b.mobile_phone phone,
        b.regist_time registTime,
        (select IFNULL(count(1), 0) from xzx_user_head_relate where head_user_id = a.user_id ) cnt,
        (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id ) orderCnt,
        (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id ) amount,
        (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id ) score
        FROM
        xzx_account_info a
        LEFT JOIN xzx_user_info b on a.user_id = b.user_id
        where a.account_id = #{id}
    </select>
 
    <select id="selectUserHeadInfoByAccountId" resultType="com.xzx.gc.user.vo.UserHeadInfoVo">
        SELECT
            b.nick_name nickname,
            b.mobile_phone phone,
            a.CREATED_TIME createTime,
            (select IFNULL(count(1), 0) from xzx_user_head_details where user_id = a.user_id and head_user_id = #{id}) orderCnt,
            (select IFNULL(sum(amount), 0) from xzx_user_head_details where user_id = a.user_id and head_user_id = #{id}) amount,
            (select IFNULL(sum(score), 0) from xzx_user_head_details where user_id = a.user_id and head_user_id = #{id}) score,
            (SELECT
                IFNULL(SUM(score),0) as kg
            FROM
                xzx_jhy_order_items WHERE order_id in ( SELECT
                        id
                    FROM
                        xzx_jhy_order WHERE order_no in ( SELECT
                                order_no
                            FROM
                                xzx_user_head_details WHERE
                                user_id = a.user_id and head_user_id = #{id} ) )) orderScore
        FROM
            xzx_user_head_relate a
                LEFT JOIN xzx_user_info b on a.user_id = b.user_id
        where a.head_user_id = #{id}
    </select>
 
    <select id="selectOrderItemsByUserId" resultType="com.xzx.gc.user.vo.OrderItemsVo">
        SELECT
            b.id orderId,
            a.order_no orderNo,
            a.score scoreReward,
            a.amount amountReward,
            c.nick_name nickname,
            c.mobile_phone phone,
            (select sum(score) from xzx_jhy_order_items where b.id = order_id) score,
            (select sum(score/ 40) from xzx_jhy_order_items where b.id = order_id) amount
        FROM
            xzx_user_head_details a
                LEFT JOIN xzx_jhy_order b ON a.order_no = b.order_no
                LEFT JOIN xzx_user_info c on a.user_id = c.user_id
        WHERE
            a.head_user_id = #{userId}
        order by b.CREATED_TIME desc
    </select>
 
 
 
    <select id="selectOrderById" resultType="com.xzx.gc.entity.JhyOrderItems">
        SELECT
               *
        FROM
            xzx_jhy_order_items a
        where a.order_id = #{orderId}
    </select>
 
    <select id="distribDataList" resultType="com.xzx.gc.user.vo.DistribDataListVo">
        SELECT
        a.account_id id,
        b.nick_name nickname,
        b.mobile_phone phone,
        b.regist_time registTime,
        a.is_head isHead,
        (select IFNULL(count(1), 0) from xzx_user_head_relate where head_user_id = a.user_id) cnt,
        (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id
            <if test="record.reserveTimeStart != null">
                and CREATED_TIME >= #{record.reserveTimeStart}
            </if>
 
            <if test="record.reserveTimeEnd != null">
                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
            </if>
        ) orderCnt,
        (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id
        <if test="record.reserveTimeStart != null">
            and CREATED_TIME >= #{record.reserveTimeStart}
        </if>
 
        <if test="record.reserveTimeEnd != null">
            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
        </if>
        ) amount,
        (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id
        <if test="record.reserveTimeStart != null">
            and CREATED_TIME >= #{record.reserveTimeStart}
        </if>
 
        <if test="record.reserveTimeEnd != null">
            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
        </if>
        ) score,
        a.is_prohibit isProhibit
        FROM
        xzx_account_info a
        LEFT JOIN xzx_user_info b on a.user_id = b.user_id
        <where>
            1=1
            and a.is_head = 1
            <if test="record.queryCol != null and record.queryCol != ''">
                and (b.nick_name like concat('%',#{record.name},'%') or b.mobile_phone like concat('%',#{record.phone},'%'))
            </if>
        </where>
        order by id desc
    </select>
 
    <select id="selectOrderByHeadUserId" resultType="java.lang.String">
        SELECT
            IFNULL(SUM(a.weight),0) as kg
        FROM
            xzx_jhy_order_items a
                 left join xzx_sys_environmental_info b on a.item_type = b.id
        WHERE
            b.item_unit = 'kg'
        and a.order_id in (
                SELECT
                    id
                FROM
                    xzx_jhy_order
                WHERE
                        order_no in (
                        SELECT
                            order_no
                        FROM
                            xzx_user_head_details
                        WHERE
                                head_user_id = (
                                SELECT
                                    user_id
                                FROM
                                    xzx_account_info
                                WHERE
                                    account_id =  #{accountId}
                            )
                    )
        <if test="record!= null">
            <if test="record.reserveTimeStart != null">
                and CREATED_TIME >= #{record.reserveTimeStart}
            </if>
 
            <if test="record.reserveTimeEnd != null">
                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
            </if>
        </if>
            )
    </select>
 
    <select id="selectJDSLByHeadUserId" resultType="java.lang.String">
        SELECT
            IFNULL(SUM(a.weight),0) as jdsl
        FROM
            xzx_jhy_order_items a
                left join xzx_sys_environmental_info b on a.item_type = b.id
        WHERE
            b.item_unit = '台' and
                a.order_id in (
                SELECT
                    id
                FROM
                    xzx_jhy_order
                WHERE order_no in (
                        SELECT
                            order_no
                        FROM
                            xzx_user_head_details
                        WHERE
                                head_user_id = (
                                SELECT
                                    user_id
                                FROM
                                    xzx_account_info
                                WHERE
                                    account_id = #{accountId}
                            )
                    )
 
        <if test="record!= null">
            <if test="record.reserveTimeStart != null">
                and CREATED_TIME >= #{record.reserveTimeStart}
            </if>
 
            <if test="record.reserveTimeEnd != null">
                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
            </if>
        </if>
            )
    </select>
 
    <select id="selectDistribDataInfoVo" resultType="com.xzx.gc.user.vo.DistribDataInfoVo">
        SELECT
        IFNULL(count(1), 0) cnt,
        SUM((select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id) ) orderCnt,
        SUM((select IFNULL(sum(amount), 0) from xzx_user_head_details where head_user_id = a.user_id) ) amount,
        SUM((select IFNULL(sum(score), 0) from xzx_user_head_details where head_user_id = a.user_id) ) score
        FROM
        xzx_account_info a
        where
            1=1
            and a.is_head = 1
    </select>
 
    <select id="distribDataExport" resultType="com.xzx.gc.user.vo.DistribDataListVo">
    SELECT
    a.account_id id,
    b.nick_name nickname,
    b.mobile_phone phone,
    b.regist_time registTime,
    a.is_head isHead,
    (select IFNULL(count(1), 0) from xzx_user_head_relate where head_user_id = a.user_id) cnt,
    (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id
        <if test="record.reserveTimeStart != null">
            and CREATED_TIME >= #{record.reserveTimeStart}
        </if>
 
        <if test="record.reserveTimeEnd != null">
            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
        </if>) orderCnt,
    (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id
        <if test="record.reserveTimeStart != null">
            and CREATED_TIME >= #{record.reserveTimeStart}
        </if>
 
        <if test="record.reserveTimeEnd != null">
            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
        </if>) amount,
    (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id
        <if test="record.reserveTimeStart != null">
            and CREATED_TIME >= #{record.reserveTimeStart}
        </if>
 
        <if test="record.reserveTimeEnd != null">
            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
        </if>) score,
    a.is_prohibit isProhibit
    FROM
    xzx_account_info a
    LEFT JOIN xzx_user_info b on a.user_id = b.user_id
    <where>
        1=1
        and a.is_head = 1
        <if test="record.queryCol != null and record.queryCol != ''">
            and (b.nick_name like concat('%',#{record.name},'%') or b.mobile_phone like concat('%',#{record.phone},'%'))
        </if>
    </where>
    order by id desc
</select>
 
    <select id="selectOrderExportByHeadUserId" resultType="java.lang.String">
    SELECT
    IFNULL(SUM(a.weight),0) as kg
    FROM
    xzx_jhy_order_items a
    left join xzx_sys_environmental_info b on a.item_type = b.id
    WHERE
    b.item_unit = 'kg'
    and a.order_id in (
    SELECT
    id
    FROM
    xzx_jhy_order
    WHERE
    order_no in (
    SELECT
    order_no
    FROM
    xzx_user_head_details
    WHERE
    head_user_id = (
    SELECT
    user_id
    FROM
    xzx_account_info
    WHERE
    account_id =  #{accountId}
    )
    )
    <if test="record!= null">
        <if test="record.reserveTimeStart != null">
            and CREATED_TIME >= #{record.reserveTimeStart}
        </if>
 
        <if test="record.reserveTimeEnd != null">
            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
        </if>
    </if>
    )
</select>
 
    <select id="selectJDSLExportByHeadUserId" resultType="java.lang.String">
        SELECT
        IFNULL(SUM(a.weight),0) as jdsl
        FROM
        xzx_jhy_order_items a
        left join xzx_sys_environmental_info b on a.item_type = b.id
        WHERE
        b.item_unit = '台' and
        a.order_id in (
        SELECT
        id
        FROM
        xzx_jhy_order
        WHERE order_no in (
        SELECT
        order_no
        FROM
        xzx_user_head_details
        WHERE
        head_user_id = (
        SELECT
        user_id
        FROM
        xzx_account_info
        WHERE
        account_id = #{accountId}
        )
        )
 
        <if test="record!= null">
            <if test="record.reserveTimeStart != null">
                and CREATED_TIME >= #{record.reserveTimeStart}
            </if>
 
            <if test="record.reserveTimeEnd != null">
                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
            </if>
        </if>
        )
    </select>
 
    <select id="selectAccountInfoByIds" resultType="com.xzx.gc.entity.AccountInfo">
        select * from xzx_account_info
        where account_id in
        <foreach collection="list" index="index" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="selectAccountInfoByPhone" resultType="com.xzx.gc.entity.AccountInfo">
        select a.* from xzx_account_info a, xzx_user_info b
        where a.user_id=b.user_id and b.mobile_phone=#{phone}
    </select>
</mapper>