admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
<?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.yeshi.fanli.dao.mybatis.share.ShareMapper">
 
    <resultMap id="BaseResultMap"
        type="com.yeshi.fanli.entity.taobao.ShareTaoPassword">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="auctionId" property="auctionId" jdbcType="BIGINT" />
        <result column="pid" property="pid" jdbcType="VARCHAR" />
        <result column="taoToken" property="taoToken" jdbcType="VARCHAR" />
        <result column="couponLink" property="couponLink" jdbcType="VARCHAR" />
        <result column="clickUrl" property="clickUrl" jdbcType="VARCHAR" />
        <result column="createTime" property="createTime" jdbcType="DATE" />
    </resultMap>
 
    <!-- 图片的返回实体 -->
    <resultMap id="ImgResultMap" type="com.yeshi.fanli.entity.bus.invite.SpreadImg">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="url" property="url" jdbcType="VARCHAR" />
        <result column="createtime" property="createtime" jdbcType="DATE" />
    </resultMap>
 
    <!-- 根据uid查询是否存在pid与其绑定 -->
    <select id="idBind" resultType="String">
        select yepu.pid from
        yeshi_ec_pid_user yepu where yepu.uid = #{uid}
    </select>
 
    <!-- 随机获得一个pid -->
    <select id="getRandomPid" resultType="String">
        SELECT yep.`pid` FROM
        `yeshi_ec_pid` yep WHERE yep.`used` = '0' ORDER BY RAND() LIMIT 1;
    </select>
 
    <!-- 修改该pid的used为1 -->
    <update id="updatePidUsed">
        UPDATE
        `yeshi_ec_pid` yep
        SET
        yep.`used` = '1'
        WHERE
        yep.`pid` = #{pid}
    </update>
 
    <!-- 插入数据到 yeshi_ec_share_tao_password -->
    <insert id="insertShareTaoPassword" parameterType="com.yeshi.fanli.entity.taobao.ShareTaoPassword"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_share_tao_password
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="auctionId != null">auctionId,</if>
            <if test="pid != null">pid,</if>
            <if test="taoToken != null">taoToken,</if>
            <if test="couponLink != null">couponLink,</if>
            <if test="clickUrl != null">clickUrl,</if>
            <if test="createTime != null">createTime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="auctionId != null">#{auctionId,jdbcType=BIGINT},</if>
            <if test="pid != null">#{pid,jdbcType=VARCHAR},</if>
            <if test="taoToken != null">#{taoToken,jdbcType=VARCHAR},</if>
            <if test="couponLink != null">#{couponLink,jdbcType=VARCHAR},</if>
            <if test="clickUrl != null">#{clickUrl,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
 
    <!-- 添加绑定操作 -->
    <insert id="insertPidUser" parameterType="com.yeshi.fanli.entity.taobao.PidUser"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_pid_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="pid != null">pid,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
            <if test="pid != null">#{pid,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
 
    <!-- 根据auctionId和pid查看是否存在数据 -->
    <select id="getAunctionPidCount" resultType="Integer">
        SELECT
        COUNT(1)
        FROM
        `yeshi_ec_share_tao_password` yestp
        WHERE
        yestp.`auctionId` =
        #{auctionId}
        AND
        yestp.`pid` = #{pid};
    </select>
 
    <!-- 获取创建时间 -->
    <select id="getShareTaoPassword" resultMap="BaseResultMap">
        SELECT
        *
        FROM
        `yeshi_ec_share_tao_password` yestp
        WHERE
        yestp.`auctionId` =
        #{auctionId}
        AND
        yestp.`pid` = #{pid};
    </select>
 
    <!-- 时间大于一个月 更新数据 -->
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.taobao.ShareTaoPassword">
        update yeshi_ec_share_tao_password
        <set>
            <if test="auctionId != null">
                auctionId = #{auctionId,jdbcType=BIGINT},
            </if>
            <if test="pid != null">
                pid = #{pid,jdbcType=VARCHAR},
            </if>
            <if test="taoToken != null">
                taoToken = #{taoToken,jdbcType=VARCHAR},
            </if>
            <if test="couponLink != null">
                couponLink = #{couponLink,jdbcType=VARCHAR},
            </if>
            <if test="clickUrl != null">
                clickUrl = #{clickUrl,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                createTime = #{createTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
 
    <!-- 查询我的一级队员 -->
    <select id="myFirstTeamCount" resultType="Integer">
        SELECT
        count(yet.`worker_id`)
        FROM
        `yeshi_ec_threesale` yet
        WHERE
        yet.`boss_id` =
        #{uid}
        AND
        yet.`state` = '1'
    </select>
 
    <!-- 查询我的二级队员 -->
    <select id="mySecondTeamCount" resultType="Integer">
        SELECT
        count(yet.`worker_id`)
        FROM
        `yeshi_ec_threesale` yet
        WHERE
        yet.`boss_id` =
        ANY(
        SELECT
        yet.`worker_id`
        FROM
        `yeshi_ec_threesale` yet
        WHERE
        yet.`boss_id` = #{uid}
        AND
        yet.`state` = '1'
        )
        AND
        yet.`state` = '1';
    </select>
 
    <!-- 查询我的今日收益 -->
    <select id="getMoneyToday" resultType="java.math.BigDecimal">
        SELECT
        SUM(yeh.`hb_money`)
        FROM
        `yeshi_ec_hongbao_v2` yeh
        WHERE
        (yeh.`hb_state` = '1' OR yeh.`hb_state`
        = '2' OR yeh.`hb_state` = '3')
        AND
        (yeh.`hb_type` = '6' OR yeh.`hb_type`
        = '7' OR yeh.`hb_type` = '20' OR yeh.`hb_type` = '21' OR yeh.`hb_type`
        = '22')
        AND
        yeh.`hb_uid` = #{uid}
        AND
        FROM_UNIXTIME(UNIX_TIMESTAMP(yeh.hb_create_time),'%Y-%m-%d') =
        FROM_UNIXTIME(UNIX_TIMESTAMP(),'%Y-%m-%d');
    </select>
 
    <!-- 查询我的本月预估收益 -->
    <select id="getMoneyMonth" resultType="java.math.BigDecimal">
        SELECT
        SUM(yeh.`hb_money`)
        FROM
        `yeshi_ec_hongbao_v2` yeh
        WHERE
        (yeh.`hb_state` = '1' OR
        yeh.`hb_state` = '2' OR yeh.`hb_state` = '3')
        AND
        (yeh.`hb_type` = '6'
        OR yeh.`hb_type` = '7' OR yeh.`hb_type` = '20' OR yeh.`hb_type` = '21'
        OR yeh.`hb_type` = '22')
        AND
        yeh.`hb_uid` = #{uid}
        AND
        FROM_UNIXTIME(UNIX_TIMESTAMP(yeh.hb_create_time),'%Y-%m') =
        FROM_UNIXTIME(UNIX_TIMESTAMP(),'%Y-%m');
    </select>
 
 
    <!-- 查询我的上月预估收益 -->
    <select id="getMoneyLastMonth" resultType="java.math.BigDecimal">
        SELECT
        SUM(h.`hb_money`) FROM yeshi_ec_hongbao_v2 h WHERE h.`hb_uid`=#{0}
        AND (h.`hb_state`=1 OR h.`hb_state`=2 OR h.`hb_state`=3) AND
        (h.`hb_type`=6 OR h.`hb_type`=7 OR h.`hb_type`=20 OR h.`hb_type`=21 OR
        h.`hb_type`=22 ) AND h.`hb_pre_get_time` IS NOT NULL AND
        DATE_FORMAT(h.`hb_pre_get_time`,'%Y-%m')=DATE_FORMAT(NOW(),'%Y-%m');
    </select>
 
 
 
 
 
    <!-- 邀请图片count -->
    <select id="spreadImgCount" resultType="Integer">
        SELECT COUNT(*) FROM
        `yeshi_ec_spread_img` yesi WHERE 1 = 1;
    </select>
 
    <!-- 分页查询邀请图片 -->
    <select id="spreadImgList" resultMap="ImgResultMap">
        SELECT * FROM
        `yeshi_ec_spread_img`;
    </select>
 
    <!-- 添加邀请好友图片 -->
    <insert id="addInviteFriendImg" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadImg"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_share_tao_password
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="url != null">url,</if>
            <if test="createtime != null">createtime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="url != null">#{url,jdbcType=VARCHAR},</if>
            <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
 
    <!-- 根据uid查询用户头像 -->
    <select id="getPortrait" resultType="String">
        SELECT yeu.`portrait` FROM
        yeshi_ec_user yeu WHERE yeu.`id` = #{uid};
    </select>
 
    <!-- 获取分享赚count -->
    <select id="getCount" resultType="Integer">
        SELECT COUNT(1) FROM
        `yeshi_ec_hongbao` yeh WHERE yeh.`type` = '20' AND yeh.`uid` = #{uid};
    </select>
 
    <!-- 获取邀请赚count -->
    <select id="getInviteCount" resultType="Integer">
        SELECT
        COUNT(1)
        FROM
        `yeshi_ec_hongbao` yeh
        WHERE
        (yeh.`type` = '6' OR yeh.`type` = '7')
        AND
        yeh.`uid` = #{uid};
    </select>
 
    <!-- 随机增加榜单igd_money -->
    <update id="updateInviteRank">
        UPDATE
        `yeshi_ec_invite_getmoney_demo` igt
        SET
        igt.`igd_money` = igt.`igd_money` + #{bigDecimalMoney}
    </update>
 
 
    <!-- 查询所有用户分享赚列表总数 -->
    <select id="getShareMoneyCount" resultType="Integer">
        SELECT COUNT(1) FROM
        `yeshi_ec_pid_order`;
    </select>
 
    <!-- 查询系统内所设定的背景图片 -->
    <select id="systemSpreadImgList" resultType="String">
        SELECT si.`si_url`
        FROM `yeshi_ec_spread_img` si;
    </select>
 
    <!-- 查询板块栏目数量 -->
    <select id="getCounts" resultType="Integer">
        SELECT counts FROM
        `yeshi_ec_recommend_section` WHERE id = #{key};
    </select>
 
    <!-- 查询活动规则 -->
    <select id="getActivityRules" resultType="String">
        SELECT yesc.`value`
        FROM `yeshi_ec_system_clientparams` yesc WHERE yesc.`key` = #{key};
    </select>
 
    <!-- 修改活动规则 -->
    <update id="editActivityRules">
        UPDATE `yeshi_ec_system_clientparams` yesc SET
        yesc.`value` = #{value} WHERE yesc.`key` = #{key};
    </update>
 
 
</mapper>