KKSU
2024-11-18 e143e08a77c00047048a5596bed1d674f967649d
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
<?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="cc.mrbird.febs.mall.mapper.MallSalesmanMapper">
 
    <select id="selectMallSalesmanListInPage" resultType="cc.mrbird.febs.mall.entity.MallSalesman">
        SELECT
            a.*
        FROM mall_salesman a
        GROUP BY a.id order by a.CREATED_TIME desc
    </select>
 
    <select id="selectTreeByState" resultType="cc.mrbird.febs.mall.vo.AdminMallSalesmansTreeVo">
        SELECT
            a.id,
               a.name
        FROM mall_salesman a
        where a.state = #{state}
        GROUP BY a.id order by a.CREATED_TIME desc
    </select>
 
    <select id="agentSelect" resultType="cc.mrbird.febs.mall.vo.AdminAgentSelectVo">
        SELECT
            a.id,
               a.salesmans_id salesmansId
        FROM mall_member a
        where a.id = #{memberId}
    </select>
 
    <select id="selectAddressAmountListInPage" resultType="cc.mrbird.febs.mall.vo.AdminMallAddressInfoVo">
        SELECT
            a.province,
            a.city
        FROM mall_address_info a
        <where>
            <if test="record != null" >
                <if test="record.province != null and record.province != ''">
                    and a.province = #{record.province}
                </if>
                <if test="record.city != null and record.city != ''">
                    and a.city = #{record.city}
                </if>
            </if>
        </where>
        group by a.city,a.province
    </select>
 
    <select id="selectSumOrderAmountByProvinceAndCity" resultType="java.math.BigDecimal">
        select
               IFNULL(sum(IFNULL(amount,0)),0)
        from
             mall_order_info
        where
              status in (2, 3, 4)
          and order_type = 1
          and address_id in (
              select
                     a.id
              from mall_address_info a
                <where>
                    <if test="province != null and province != ''">
                        and a.province = #{province}
                    </if>
                    <if test="city != null and city != ''">
                        and a.city = #{city}
                    </if>
                </where>
         )
    </select>
 
    <select id="selectSumOrderCntByProvinceAndCity" resultType="java.lang.Integer">
        select
               count(id)
        from
             mall_order_info
        where
              status in (2, 3, 4)
          and order_type = 1
          and address_id in (
              select
                     a.id
              from mall_address_info a
                <where>
                    <if test="province != null and province != ''">
                        and a.province = #{province}
                    </if>
                    <if test="city != null and city != ''">
                        and a.city = #{city}
                    </if>
                </where>
         )
    </select>
 
    <select id="selectProvince" resultType="cc.mrbird.febs.mall.vo.AdminMallAddressInfoVo">
        SELECT
        a.province
        FROM mall_address_info a
        group by a.province
    </select>
 
    <select id="selectSalesmanAchieveListInPage" resultType="cc.mrbird.febs.mall.vo.AdminSalesmanAchieveVo">
        SELECT
        a.province,
        a.city,
        a.name salesmanName,
        a.id salesmanId,
        (select count(b.id) from mall_member b where b.salesmans_id = a.id) memberCnt
        FROM mall_salesman a
        <where>
            <if test="record != null" >
                <if test="record.province != null and record.province != ''">
                    and a.province = #{record.province}
                </if>
                <if test="record.city != null and record.city != ''">
                    and a.city = #{record.city}
                </if>
                <if test="record.name != null and record.name != ''">
                    and a.name like concat('%',  #{record.name},'%')
                </if>
            </if>
        </where>
        ORDER BY
        memberCnt DESC, a.province ASC
    </select>
 
    <select id="selectSalesmanAchieveProvince" resultType="cc.mrbird.febs.mall.vo.AdminSalesmanAchieveVo">
        SELECT
            a.province
        FROM mall_salesman a
        group by a.province
    </select>
 
    <select id="selectAdminMemberOrderVoBySalesmanId" resultType="cc.mrbird.febs.mall.vo.AdminMemberOrderVo">
        select
            c.name memberName,
            c.phone memberPhone,
            a.address memberAddress,
            a.id orderId,
            a.order_no orderNo,
            a.CREATED_TIME createdTime,
            a.amount orderAmount
        from
            mall_order_info a
        left join mall_member c on a.member_id = c.id
        where
            a.status in (2, 3, 4)
            and  a.order_type = 1
            and  a.member_id in (
                select
                    b.id
                from mall_member b
                where
                    b.salesmans_id = #{salesmanId}
            )
    </select>
 
    <select id="selectAgentAchieveListInPage" resultType="cc.mrbird.febs.mall.vo.AdminMallAgentRecordVo">
        SELECT
        a.province,
        a.city,
        a.name,
        a.phone,
        d.name nickname,
        (
            select ifnull(sum(e.amount),0)
            from mall_money_flow e
            where e.flow_type = 1
            and e.type = 20
            and e.member_id = a.member_id
        ) rechargeSendAmount,
        (
            select count(b.id)
            from mall_order_info b
            <where>
                b.member_id = a.member_id
                    and (b.status = 4)
                <if test="record != null" >
                    <if test="record.startTime != null and record.startTime != ''">
                        and b.order_time &gt;= #{record.startTime}
                    </if>
                    <if test="record.endTime != null and record.endTime != ''">
                        and b.order_time &lt;= #{record.endTime}
                    </if>
                </if>
            </where>
        ) orderCnt,
        (
            select ifnull(sum(c.amount),0)
            from mall_order_info c
 
            <where>
                c.member_id = a.member_id
                and (c.status = 4)
                <if test="record != null" >
                    <if test="record.startTime != null and record.startTime != ''">
                        and c.order_time &gt;= #{record.startTime}
                    </if>
                    <if test="record.endTime != null and record.endTime != ''">
                        and c.order_time &lt;= #{record.endTime}
                    </if>
                </if>
            </where>
        ) orderAmount
        FROM mall_agent_record a
        inner join mall_member d on a.member_id = d.id
        <where>
            <if test="record != null" >
                <if test="record.province != null and record.province != ''">
                    and a.province = #{record.province}
                </if>
                <if test="record.city != null and record.city != ''">
                    and a.city = #{record.city}
                </if>
                <if test="record.name != null and record.name != ''">
                    and a.name like concat('%',  #{record.name},'%')
                </if>
                <if test="record.nickname != null and record.nickname != ''">
                    and d.name like concat('%',  #{record.nickname},'%')
                </if>
            </if>
        </where>
        ORDER BY orderAmount desc
    </select>
 
    <select id="selectAgentAddressProvince" resultType="cc.mrbird.febs.mall.vo.AdminMallAgentRecordVo">
        SELECT
            a.province
        FROM mall_agent_record a
        group by a.province
    </select>
 
    <select id="selectAgentAddressCity" resultType="java.lang.String">
        SELECT
            a.city
        FROM mall_agent_record a
        where a.province = #{province}
        group by a.city
    </select>
 
</mapper>