yujian
2020-01-03 c9cbdfa41d645d42eeaa7e06d550d4ef8ac328e7
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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
package com.yeshi.fanli.controller.client.v2;
 
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.JsonUtil;
 
import com.yeshi.fanli.dto.wx.WXAccountInfoDTO;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.msg.UserSystemMsg;
import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.ThreeSaleExtraInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
import com.yeshi.fanli.entity.bus.user.UserInviteSeparate;
import com.yeshi.fanli.entity.bus.user.WeiXinUser;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.exception.user.UserAccountException;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SpreadImgService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.msg.UserSystemMsgService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserInviteSeparateService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleExtraInfoSerivce;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
import com.yeshi.fanli.util.wx.WXLoginUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("api/v2/invite")
public class InviteControllerV2 {
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private PushService pushService;
 
    @Resource
    private UserSystemMsgService userSystemMsgService;
 
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private UserInfoExtraService userInfoExtraService;
 
    @Resource
    private ThreeSaleExtraInfoSerivce threeSaleExtraInfoSerivce;
 
    @Resource
    private UserVIPInfoService userVIPInfoService;
    
    @Resource
    private UserInviteSeparateService userInviteSeparateService;
 
    @Resource
    private SpreadImgService spreadImgService;
    
    @Resource
    private SpreadUserImgService spreadUserImgService;
    
    @Resource
    private SystemClientParamsService systemClientParamsService;
    
    
    
    /**
     * 邀请码验证
     * 
     * @param out
     */
    @RequestMapping(value = "verifyCode")
    public void verifyCode(AcceptData acceptData, Long uid, String inviteCode, PrintWriter out) {
        try {
            UserInfo userInfo = userInfoExtraService.getUserByInviteCode(inviteCode);
            JSONObject data = new JSONObject();
            data.put("nickName", userInfo.getNickName());
            data.put("portrait", userInfo.getPortrait());
            data.put("tips", "确认要成为TA的直接粉丝吗?邀请关系一旦建立不可更改。");
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserInfoExtraException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
        }
    }
 
    /**
     * 邀请码微信验证
     * 
     * @param out
     */
    @RequestMapping(value = "verifyWX")
    public void verifyWX(AcceptData acceptData, Long uid, String code, PrintWriter out) {
        try {
            WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
            // 获取微信信息
            WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
            if (weiXinUser == null)
                throw new UserInfoExtraException(1, "微信授权失败");
 
            String wxUnionId = weiXinUser.getUnionid();
            if (wxUnionId == null || wxUnionId.trim().length() == 0)
                throw new UserInfoExtraException(1, "微信授权失败");
 
            String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5("activeWX:" + weiXinUser.getUnionid()));
            redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(weiXinUser), 60 * 20);
 
            // 邀请关系用户信息
            UserInfo userInfo = userInfoExtraService.getInviterInfo(uid, wxUnionId);
 
            JSONObject data = new JSONObject();
            data.put("nickName", userInfo.getNickName());
            data.put("portrait", userInfo.getPortrait());
            data.put("tips", "确认要成为TA的直接粉丝吗?邀请关系一旦建立不可更改。");
            data.put("key", key);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserInfoExtraException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
        }
    }
 
    /**
     * 微信激活
     * 
     * @param acceptData
     * @param uid
     * @param key
     *            验证返回的key
     * @param out
     */
    @RequestSerializableByKey(key = "'activeInviteWX-'+#uid")
    @RequestMapping(value = "activeInviteWX")
    public void activeInviteWX(AcceptData acceptData, Long uid, String key, PrintWriter out) {
        try {
            String value = redisManager.getCommonString(key);
            if (StringUtil.isNullOrEmpty(value))
                throw new UserAccountException(1, "微信授权失效");
 
            WeiXinUser weiXinUser = JsonUtil.getSimpleGson().fromJson(value, WeiXinUser.class);
            if (weiXinUser == null)
                throw new UserAccountException(1, "微信授权失效");
 
            userInfoExtraService.activeInviteWX(uid, weiXinUser);
            // 删除缓存
            redisManager.removeCommonString(key);
 
            out.print(JsonUtil.loadTrueResult("邀请码激活成功"));
        } catch (UserInfoExtraException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("邀请码激活失败"));
            e.printStackTrace();
        }
    }
 
    /**
     * 用户队员列表查询 1.5.3查询有效队员
     * 
     * @param acceptData
     * @param id
     * @param out
     */
    @RequestMapping(value = "getMyTeam", method = RequestMethod.POST)
    public void getMyTeam(AcceptData acceptData, long page, long uid, int type, PrintWriter out) {
        if (type != 1 && type != 2) {
            out.print(JsonUtil.loadFalseResult("粉丝类型不正确"));
            return;
        }
 
        long count = 0;
        List<ThreeSale> listTeam = null;
        if (type == 1) {
            listTeam = threeSaleSerivce.listFirstTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid, 1);
            count = threeSaleSerivce.countFirstTeam(uid, 1);
        } else if (type == 2) {
            listTeam = threeSaleSerivce.listSecondTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid, 1);
            count = threeSaleSerivce.countSecondTeam(uid, 1);
        }
 
        boolean needVIPInfo = false;
        if (VersionUtil.greaterThan_2_0_5(acceptData.getPlatform(), acceptData.getVersion()))
            needVIPInfo = true;
 
        // 组织数据
        JSONObject resultData = organizeTeam(count, listTeam, uid, type,needVIPInfo);
 
        // 第一页判断是否激活 是否有队员
        if (type == 1 && page == 1) {
            boolean hasCode = false;
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
            if (userInfoExtra != null) {
                if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
                    hasCode = true;
            }
            resultData.put("hasCode", hasCode);
            resultData.put("hasTeam", count > 0 ? true : false);
        }
        out.print(JsonUtil.loadTrueResult(resultData));
    }
 
    /**
     * 组织数据
     * 
     * @param count
     * @param list
     * @param uid
     * @param type
     * @return
     */
    private JSONObject organizeTeam(long count, List<ThreeSale> list, Long uid, int type, boolean needVipInfo) {
        JSONObject result = new JSONObject();
        JSONArray resultArray = new JSONArray();
 
        Date todayTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("MM.dd HH:mm");
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        SimpleDateFormat formatYears = new SimpleDateFormat("yyyy");
 
        List<Long> workerIdList = new ArrayList<>();
        Map<Long, Boolean> vipMap = null;
        if (needVipInfo) {
            for (ThreeSale threeSale : list)
                workerIdList.add(threeSale.getWorker().getId());
            if (workerIdList.size() > 0)
                vipMap = userVIPInfoService.listByUids(workerIdList);
        }
        for (ThreeSale threeSale : list) {
            UserInfo worker = threeSale.getWorker();
            if (worker == null) {
                continue;
            }
            Long workerId = worker.getId();
 
            JSONObject object = new JSONObject();
            object.put("workerId", worker.getId());
            object.put("nickName", worker.getNickName());
            object.put("portrait", worker.getPortrait());
            object.put("inviteId", threeSale.getId());
 
            Date inviteTime = new Date(threeSale.getCreateTime());
            object.put("inviteTime", format.format(inviteTime) + " 加入");
            // 添加是否为VIP
            if (vipMap != null && vipMap.get(worker.getId()) != null) {
                object.put("vip", vipMap.get(worker.getId()));
                if (vipMap.get(worker.getId())) {
                    UserInviteSeparate separate = userInviteSeparateService.selectByWorkerIdAndBossId(worker.getId(), uid);
                    if (separate != null && separate.getEndTime() != null) {
                        try {
                            
                        
                            JSONObject contentJson1 = new JSONObject();
                            contentJson1.put("color", "#888888");
                            contentJson1.put("content", "将于");
 
                            JSONObject contentJson2 = new JSONObject();
                            contentJson2.put("color", "#F14242");
                            contentJson2.put("content", DateUtil.dateDiff4(new Date(), separate.getEndTime()));
 
                            JSONObject contentJson3 = new JSONObject();
                            contentJson3.put("color", "#888888");
                            contentJson3.put("content", "后脱离邀请关系");
                            
                            JSONArray array = new JSONArray();
                            array.add(contentJson1);
                            array.add(contentJson2);
                            array.add(contentJson3);
                            object.put("vipBreakTime",array);
                        
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            String fontColor1 = "#888888";
            JSONArray array = new JSONArray();
            if (threeSale.getState()) {
                Long lastLoginTime = worker.getLastLoginTime();
                if (lastLoginTime == null) {
                    lastLoginTime = threeSale.getCreateTime();
                }
 
                JSONObject contentJson = new JSONObject();
                contentJson.put("color", fontColor1);
                if (formatYears.format(todayTime).equals(formatYears.format(lastLoginTime))) {
                    // 本年
                    contentJson.put("content", "最近登录 " + sdf.format(lastLoginTime));
                } else {
                    // 往年
                    contentJson.put("content", "最近登录 " + format.format(lastLoginTime));
                }
                array.add(contentJson);
 
                // 一级队员 查询
                if (type == 1) {
                    String memoName = null;
                    ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo();
                    if (threeSaleExtraInfo != null) {
                        if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) {
                            memoName = threeSaleExtraInfo.getNickname();
                        }
                    }
                    object.put("memoName", memoName);
 
                    UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(workerId);
                    if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin())) {
                        object.put("weiXin", userInfoExtra.getWeiXin());
                        object.put("weiXinState", 3);
                        object.put("weiXinTip", "添加TA的微信,你可教授TA如何通过板栗快省赚钱技巧。");
                    } else {
                        if (!threeSaleExtraInfoSerivce.isRemindWorker(uid, workerId)) {
                            object.put("weiXinState", 1);
                            object.put("weiXinTip", "点击提醒TA,系统会发送一封站内信,提醒其添加微信号。");
                        } else {
                            object.put("weiXinState", 2);
                            object.put("weiXinTip", "系统已发送提醒,邀请人添加微信后你可复制,如对方迟迟不添加,你可联系人工客服寻求帮助");
                        }
                    }
                }
            }
            object.put("state", 1);
            object.put("recentMsg", array);
            resultArray.add(object);
        }
 
        result.put("count", count);
        result.put("list", resultArray);
        return result;
    }
 
    /**
     * 用户队员统计- IOS
     * 
     * @param acceptData
     * @param id
     * @param out
     */
    @RequestMapping(value = "countMyTeam", method = RequestMethod.POST)
    public void countMyTeam(AcceptData acceptData, long uid, PrintWriter out) {
        JSONObject bossData = getBossInfo(uid, threeSaleSerivce.getMyBoss(uid));
        JSONObject resultData = new JSONObject();
 
        long firstTeam = threeSaleSerivce.countFirstTeam(uid, 1);
        resultData.put("boss", bossData);
        resultData.put("helpLink", configService.get("team_help_url"));
        resultData.put("firstTeam", firstTeam);
        resultData.put("firstTeamTotal", threeSaleSerivce.countFirstTeam(uid, null));
        resultData.put("secondTeam", threeSaleSerivce.countSecondTeam(uid, 1));
        resultData.put("secondTeamTotal", threeSaleSerivce.countSecondTeam(uid, null));
 
        boolean hasTeam = true;
        if (firstTeam <= 0) {
            hasTeam = false;
            resultData.put("invitelink", configService.get("invite_activation_url"));
        }
        resultData.put("hasTeam", hasTeam);
 
        boolean hasCode = false;
        boolean bdWeiXin = false;
        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
        if (userInfoExtra != null) {
            if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
                hasCode = true;
 
            if (!StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin()))
                bdWeiXin = true;
        }
 
        // 未激活邀请码
        resultData.put("hasCode", hasCode);
        if (!hasCode) {
            List<String> tipCode = new ArrayList<String>();
            resultData.put("helpLinkActivate", configService.get("team_help_url"));
            tipCode.add("激活邀请功能后才可以邀请粉丝,直接粉丝是由你直接邀请,间接粉丝是由你的直接粉丝邀请。");
            tipCode.add("邀请激活功能,必须要有邀请码,邀请码可以通过金币兑换,也可以全网搜索。");
            resultData.put("tipCode", tipCode);
        }
 
        // 未添加微信号
        List<String> tipWeiXin = new ArrayList<String>();
        if (!bdWeiXin) {
            tipWeiXin.add("添加微信号后,你的邀请人和直接粉丝可通过微信号与你建立联系;");
            tipWeiXin.add("你也可以向邀请人学习或向直接粉丝教授赚钱技巧。");
        }
        resultData.put("tipWeiXin", tipWeiXin);
        resultData.put("tipWeiXinAdd", "添加微信号后,你的邀请人和直接粉丝可以通过微信与你建立联系。");
        resultData.put("bdWeiXin", bdWeiXin);
 
        out.print(JsonUtil.loadTrueResult(resultData));
    }
 
    /**
     * 获取用户信息
     * @param acceptData
     * @param uid
     * @param out
     */
    @RequestMapping(value = "getBossInfo", method = RequestMethod.POST)
    public void getBossInfo(AcceptData acceptData, Long uid, PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult("用户未登录"));
            return;
        }
        JSONObject bossData = getBossInfo(uid, threeSaleSerivce.getMyBoss(uid));
        out.print(JsonUtil.loadTrueResult(bossData));
    }
    
    
    /**
     * 上级信息组织
     * 
     * @param acceptData
     * @param uid
     * @param threeSale
     * @return
     */
    private JSONObject getBossInfo(long uid, ThreeSale threeSale) {
        JSONObject bossData = new JSONObject();
        if (threeSale != null && threeSale.getBoss() != null) {
            UserInfo boss = threeSale.getBoss();
            bossData.put("hasBoss", true);
            bossData.put("inviteId", threeSale.getId());
            bossData.put("nickName", boss.getNickName());
            bossData.put("portrait", boss.getPortrait());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
            Long createTime = threeSale.getCreateTime();
            Date inviteTime = new Date(createTime);
 
            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(boss.getId());
            if (userInfoExtra != null && !StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin())) {
                bossData.put("weiXin", userInfoExtra.getWeiXin());
                bossData.put("weiXinState", 3);
                bossData.put("weiXinTip", "添加TA的微信,你可向TA学习如何通过板栗快省赚钱。");
            } else {
                if (!threeSaleExtraInfoSerivce.isRemindBoss(boss.getId(), uid)) {
                    bossData.put("weiXinState", 1);
                    bossData.put("weiXinTip", "点击提醒TA,系统会发送一封站内信,提醒其添加微信号。");
                } else {
                    bossData.put("weiXinState", 2);
                    bossData.put("weiXinTip", "系统已发送提醒,邀请人添加微信后你可复制,如对方迟迟不添加,你可联系人工客服寻求帮助");
                }
            }
            bossData.put("inviteTime", "你于 " + sdf.format(inviteTime) + "接受了TA的邀请");
        } else {
            bossData.put("hasBoss", false);
            bossData.put("helpLink", configService.get("invite_code_hlep_link"));
            bossData.put("weiXinTip", "恭喜你,我们的优质用户;\r\n你并没有邀请人,但你的邀请激活功能是被默认开启的;\r\n你拥有独特的无邀请人激活码。");
        }
        return bossData;
    }
 
    /**
     * 站内信提醒队员添加微信号
     * 
     * @param acceptData
     * @param uid
     * @param inviteId
     * @param out
     */
    @RequestMapping(value = "remindTeam")
    public void remindTeam(AcceptData acceptData, Long uid, Long inviteId, PrintWriter out) {
        if (uid == null || inviteId == null) {
            out.print(JsonUtil.loadFalseResult("传递参数缺失"));
            return;
        }
 
        UserInfo userInfo = userInfoService.selectByPKey(uid);
        if (userInfo == null) {
            out.print(JsonUtil.loadFalseResult("用户信息不存在"));
            return;
        }
 
        ThreeSale threeSale = threeSaleSerivce.selectByPrimaryKey(inviteId);
        if (threeSale == null) {
            out.print(JsonUtil.loadFalseResult("关系id不存在"));
            return;
        }
 
        Long remindId = null;
        boolean remindBoss = true;
        if (uid.longValue() == threeSale.getWorker().getId().longValue()) {
            remindId = threeSale.getBoss().getId(); // 提醒上级
        } else if (uid.longValue() == threeSale.getBoss().getId().longValue()) {
            remindBoss = false;
            remindId = threeSale.getWorker().getId(); // 提醒下级
        }
 
        if (remindId == null) {
            out.print(JsonUtil.loadFalseResult("信息验证未通过"));
            return;
        }
 
        Long bossId = null;
        Long workerId = null;
        String title = "粉丝提醒消息";
        String content = "";
        if (remindBoss) {
            // 提示队长
            bossId = remindId;
            workerId = uid;
            content = "你的直接粉丝" + userInfo.getNickName()
                    + ",提醒你添加微信号,以便于和你取得联系和学习省钱技巧,赶快去添加吧;注:请升级到本软件最新版本在“我的-我的信息”中添加。";
        } else {
            // 提示队员
            bossId = uid;
            workerId = remindId;
            content = "你的邀请人" + userInfo.getNickName()
                    + ",提醒你添加微信号,以便于和你取得联系帮助你更好的省钱,赶快去添加吧;注:请升级到本软件最新版本在“我的-我的信息”中添加。";
        }
 
        try {
            List<String> listIOS = new ArrayList<String>();
            List<String> listAndroid = new ArrayList<String>();
            pushService.pushZNX(remindId, title, content, listIOS, listAndroid);
 
            userSystemMsgService.addUserSystemMsg(remindId, UserSystemMsgTypeEnum.common, title, content,
                    UserSystemMsg.TIME_TAG_COMMON, null);
 
            ThreeSaleExtraInfo newInfo = new ThreeSaleExtraInfo();
            if (remindBoss) {
                newInfo.setRemindBoss(1);
            } else {
                newInfo.setRemindWorker(1);
            }
 
            ThreeSaleExtraInfo threeExtra = threeSaleExtraInfoSerivce.getbyBossIdAndWorkerId(bossId, workerId);
            if (threeExtra != null) {
                newInfo.setId(threeExtra.getId());
                newInfo.setUpdateTime(new Date());
                threeSaleExtraInfoSerivce.updateByPrimaryKeySelective(newInfo);
            } else {
                newInfo.setBoss(new UserInfo(bossId));
                newInfo.setWorker(new UserInfo(workerId));
                newInfo.setCreateTime(new Date());
                newInfo.setUpdateTime(new Date());
                threeSaleExtraInfoSerivce.insertSelective(newInfo);
            }
 
            JSONObject data = new JSONObject();
            data.put("weiXinState", 2);
            data.put("weiXinTip", "系统已发送提醒,邀请人添加微信后你可复制,如对方迟迟不添加,你可联系人工客服寻求帮助");
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            e.printStackTrace();
            out.print(JsonUtil.loadFalseResult("提醒失败"));
        }
    }
    
    
    @RequestSerializableByKey(key = "'getInviteImgs-'+#uid")
    @RequestMapping(value = "/getInviteImgs", method = RequestMethod.POST)
    public void getInviteImgs(AcceptData acceptData, Long uid, Integer page, PrintWriter out, HttpServletRequest request) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult("用户未登录"));
            return;
        }
 
        if (page == null || page < 1)
            page = 1;
        
        try {
            String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
            if (StringUtil.isNullOrEmpty(inviteCode)) {
                out.print(JsonUtil.loadFalseResult("邀请码未激活"));
                return;
            }
            
            int count = 3;
            if (page > 1) 
                count = Integer.MAX_VALUE;
            
            // 邀请图
            List<String> imgList = spreadUserImgService.getUserSpreadImgToPage(uid, page, count, request);
        
            // 邀请规则
            BusinessSystem system = new BusinessSystem();
            system.setId(4L);
            system.setPlatform(1);
            system.setCreatetime(java.lang.System.currentTimeMillis());
            SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, "inviteRules");
            
            JSONObject data = new JSONObject();
            data.put("count", spreadImgService.countAll());
            data.put("inviteCode", inviteCode);
            data.put("helpLink", configService.get("invite_help_link"));
            data.put("inviteRules",  values.getValue().replace("\n", "<br><br>"));
            data.put("imgUrlList", JsonUtil.getSimpleGsonWithDate().toJson(imgList));
            data.put("inviteLink", "http://a.app.qq.com/o/simple.jsp?pkgname=com.yeshi.ec.rebate");
            out.print(JsonUtil.loadTrue(0, JsonUtil.getSimpleGson().toJson(data), "成功"));
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
            out.print(JsonUtil.loadFalseResult("邀请信息获取失败"));
        }
    }
    
    /**
     * 站内信提醒队员添加微信号
     * 
     * @param acceptData
     * @param uid
     * @param inviteId
     * @param out
     */
    @RequestMapping(value = "tailorCode")
    public void tailorCode(AcceptData acceptData, String callback, Long uid, PrintWriter out) {
        if (uid == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户id缺失"));
            return;
        }
 
        JSONObject data = new JSONObject();
        data.put("num", threeSaleSerivce.countFirstTeam(uid, 1));
        data.put("limit", Constant.INVITE_CODRE_TAILOR_LIMIT);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
    }
    
    
    
}