luodangjia
2025-01-15 257d66798aa538f8737980f13d94c547bf0b51ea
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.account.mapper.AppUserMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.account.api.model.AppUser">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="phone" property="phone" />
        <result column="avatar" property="avatar" />
        <result column="vip_id" property="vipId" />
        <result column="wx_openid" property="wxOpenid" />
        <result column="ali_openid" property="aliOpenid" />
        <result column="status" property="status" />
        <result column="create_time" property="createTime" />
        <result column="del_flag" property="delFlag" />
        <result column="first_add" property="firstAdd" />
        <result column="last_login_time" property="lastLoginTime" />
        <result column="invite_user_id" property="inviteUserId" />
        <result column="shop_id" property="shopId" />
        <result column="part_point" property="partPoint" />
        <result column="part_grow_point" property="partGrowPoint" />
        <result column="shop_point" property="shopPoint" />
        <result column="share_point" property="sharePoint" />
        <result column="shop_amount" property="shopAmount" />
        <result column="last_shop_time" property="lastShopTime" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, phone, avatar, vip_id, wx_openid, ali_openid, status, create_time, del_flag, first_add, last_login_time, invite_user_id, shop_id, part_point, part_grow_point, shop_point, share_point, shop_amount, last_shop_time
    </sql>
 
    
    
    
    <select id="getNearbyReferrer" resultType="com.ruoyi.account.vo.NearbyReferrerVo">
        select
        id,
        avatar,
        `name`,
        vip_id as vip,
        longitude,
        latitude,
        phone
        from t_app_user where ((city_code = #{cityCode} and vip_id >= 4) or id = 1) and del_flag = 0 and status = 1
        <if test="null != nearbyReferrer.name and '' != nearbyReferrer.name">
            and `name` like CONCAT('%', #{nearbyReferrer.name}, '%')
        </if>
    </select>
 
    <select id="getAppuserPage" resultType="com.ruoyi.account.api.model.AppUser">
        SELECT *
        FROM t_app_user ta
        <where>
            ta.del_flag = 0 and ta.status != 3
            <if test="null != appUser.name and '' != appUser.name">
                and ta.`name` like CONCAT('%',#{appUser.name},'%')
            </if>
            <if test="null != appUser.phone and '' != appUser.phone">
                and ta.phone like CONCAT('%',#{appUser.phone},'%')
            </if>
            <if test="null != appUser.status">
                and ta.status = #{appUser.status}
            </if>
            <if test="null != appUser.vipId">
                and ta.vip_id = #{appUser.vipId}
            </if>
            <if test="null != appUser.shopIds and appUser.shopIds.size() > 0">
                and ta.shop_id in
                <foreach collection="appUser.shopIds" item="shopId" open="(" separator="," close=")">
                    #{shopId}
                </foreach>
            </if>
            <if test="null != shopId">
                and ta.shop_id = #{shopId} or ta.id in
                <foreach collection="userId" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by ta.is_danger desc
 
    </select>
    <select id="getAppuserPage1" resultType="com.ruoyi.account.api.model.AppUser">
        SELECT ta.id, ta.phone, ta.`name`, ta.vip_id, ta.shop_id, ta.status
        FROM t_app_user ta
        <where>
            ta.del_flag = 0 and ta.status != 3
            <if test="null != appUser.name and '' != appUser.name">
                and ta.`name` like CONCAT('%',#{appUser.name},'%')
            </if>
            <if test="null != appUser.phone and '' != appUser.phone">
                and ta.phone like CONCAT('%',#{appUser.phone},'%')
            </if>
            <if test="null != appUser.status">
                and ta.status = #{appUser.status}
            </if>
            <if test="null != appUser.vipId">
                and ta.vip_id = #{appUser.vipId}
            </if>
            <if test="null != appUser.shopIds and appUser.shopIds.size() > 0">
                and ta.shop_id in
                <foreach collection="appUser.shopIds" item="shopId" open="(" separator="," close=")">
                    #{shopId}
                </foreach>
            </if>
            and ( ta.id
             in
            <foreach collection="userIds" item="userId" open="(" separator="," close=")">
                #{userId}
            </foreach>
            or ta.shop_id = #{objectId} )
        </where>
    </select>
    <select id="getUserStatistics" resultType="com.ruoyi.account.vo.UserStatistics">
        SELECT
        COUNT(*) AS totalUser,
        SUM(CASE WHEN tau.user_type = 2 THEN 1 ELSE 0 END) AS shopUser,
        SUM(CASE WHEN tau.vip_id <![CDATA[<]]> 4 THEN 1 ELSE 0 END) AS consumerUser,
        SUM(CASE WHEN tau.vip_id = 1 THEN 1 ELSE 0 END) AS commonUser,
        SUM(CASE WHEN tau.vip_id = 2 THEN 1 ELSE 0 END) AS goldUser,
        SUM(CASE WHEN tau.vip_id = 3 THEN 1 ELSE 0 END) AS diamondUser,
        SUM(CASE WHEN tau.vip_id <![CDATA[>]]> 3 THEN 1 ELSE 0 END) AS entrepreneurUser,
        SUM(CASE WHEN tau.vip_id = 4 THEN 1 ELSE 0 END) AS proxyUser,
        SUM(CASE WHEN tau.vip_id = 5 THEN 1 ELSE 0 END) AS agentUser,
        SUM(CASE WHEN tau.vip_id = 6 THEN 1 ELSE 0 END) AS totalAgentUser,
        SUM(CASE WHEN tau.vip_id = 7 THEN 1 ELSE 0 END) AS partnerUser
        FROM
        t_app_user tau
        <where>
            <if test="null != shopId">
                tau.shop_id = #{shopId}
                <if test="null != userId">
                    or tau.id in
                    <foreach collection="userId" item="item" index="index" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
            </if>
        and  tau.del_flag = 0
        and tau.`status` !=3
        </where>
    </select>
    <select id="getUserStatisticsDetail" resultType="com.ruoyi.account.vo.UserStatisticsDetail">
        SELECT
            SUM(tau.total_point) totalScore,
            SUM(tau.shop_point) consumeScore,
            SUM(tau.share_point) rebateScore,
            SUM(tau.total_invite_point) inviteScore,
            SUM(tau.total_register_point) registerScore,
            SUM(tau.total_share_point+tau.total_sign_point+tau.total_hour_point) workScore,
            SUM(tau.total_performance_point) achievementScore,
            SUM(tau.total_distribution_amount) totalRebate,
            SUM(tau.total_recharge_amount) totalRecharge,
            SUM(tau.withdrawn_amount) totalWithdraw
        FROM
            t_app_user tau
        <where>
            <if test="null != shopId">
                tau.shop_id = #{shopId} or
            </if>
            <if test="null != userId and userId.size() > 0">
                tau.id in
                <foreach collection="userId" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        and tau.del_flag = 0
        </where>
    </select>
</mapper>