ActiveBiz.java
29.5 KB
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
package com.cjs.cms.biz.user.point;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cjs.cms.biz.trade.TradeBiz;
import com.cjs.cms.biz.user.WeiXinBiz;
import com.cjs.cms.dao.pub.SysParamValueDao;
import com.cjs.cms.dao.user.AgentInfoDao;
import com.cjs.cms.dao.user.WeixinDao;
import com.cjs.cms.dao.user.account.ClientDao;
import com.cjs.cms.dao.user.account.ClientInfoDao;
import com.cjs.cms.dao.user.point.ActiveConfigDao;
import com.cjs.cms.dao.user.point.ActiveGiftDao;
import com.cjs.cms.dao.user.point.ActiveGiftRecordDao;
import com.cjs.cms.dao.user.point.ActiveRuleDao;
import com.cjs.cms.dao.user.point.PointActiveDao;
import com.cjs.cms.dao.user.point.PointRecordDao;
import com.cjs.cms.dao.user.point.PointUserDao;
import com.cjs.cms.model.user.AgentInfo;
import com.cjs.cms.model.user.UserInfo;
import com.cjs.cms.model.user.WxUserInfo;
import com.cjs.cms.model.user.point.ActiveConfigInfo;
import com.cjs.cms.model.user.point.ActiveGiftInfo;
import com.cjs.cms.model.user.point.ActiveGiftRecordInfo;
import com.cjs.cms.model.user.point.ActiveRuleInfo;
import com.cjs.cms.model.user.point.PointActiveInfo;
import com.cjs.cms.model.user.point.PointRecordInfo;
import com.cjs.cms.model.user.point.PointUserInfo;
import com.cjs.cms.util.lang.DateEnum;
import com.cjs.cms.util.lang.DateUtil;
import com.cjs.cms.util.lang.StringUtil;
import com.cjs.cms.util.t2.T2Result;
import com.cjs.cms.util.t2.T2Util;
import com.cjs.cms.util.web.ActionUtil;
@Service
public class ActiveBiz {
Logger log = LogManager.getLogger();
@Autowired
private ActiveConfigDao activeConfigDao;
@Autowired
private ActiveRuleDao activeRuleDao;
@Autowired
private ActiveGiftRecordDao activeGiftRecordDao;
@Autowired
private TradeBiz userTradeBiz;
@Autowired
private ClientDao clientDao;
@Autowired
private ActiveGiftDao activeGiftDao;
@Autowired
private AgentInfoDao agentInfoDao;
@Autowired
private PointActiveDao pointActiveDao;
@Autowired
private PointRecordDao pointRecordDao;
@Autowired
private PointUserDao pointUserDao;
@Autowired
private WeiXinBiz templateBiz;
@Autowired
private WeixinDao weixinDao;
@Autowired
private ClientInfoDao clientInfoDao;
@Autowired
private SysParamValueDao sysParamValueDao;
/**开户送奖品*/
public Map<String, Object> openAccountActive(Map<String, Object> params) {
Map<String, Object> outmap = new HashMap<String, Object>();
//活动信息
Map<String, Object> inmap = new HashMap<String, Object>();
inmap.put("type", "0");
inmap.put("status", "2");
inmap.put("nowDate", DateUtil.parseDate(new Date(), DateEnum.DATETIME));
List<ActiveConfigInfo> list = activeConfigDao.queryActive(inmap);
ActiveConfigInfo config = list.get(0);
int ruleCount = activeRuleDao.queryRuleCountByConfigId(config.getId());
int giftId = 0;
log.info(config);
Date nowdate = new Date();
if (nowdate.before(config.getStartDate()) || nowdate.after(config.getEndDate())) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "活动未开始");
return outmap;
}
Map<String, Object> result = new HashMap<String, Object>();
for (int i = 0; i < ruleCount; i++) {
result = this.transferGift(params, config.getId());
if ("1".equals(result.get("resultCode"))) {
//记录用户中奖纪录
giftId = Integer.parseInt(result.get("giftId").toString());
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(params.get("clientId").toString());
record.setGiftId(giftId);
record.setGiftAmount(Integer.parseInt(result.get("giftAmount").toString()));
record.setGiftBy("开户中奖");
record.setIssueStatus("1");
record.setIssueBy(config.getActiveAccount());
record.setCreateBy(params.get("clientId").toString());
activeGiftRecordDao.insert(record);
//减活动奖品存量
Map<String, Object> updatemap = new HashMap<String, Object>();
updatemap.put("id", giftId);
updatemap.put("amount", result.get("giftAmount"));
activeGiftDao.updateRemainAmount(updatemap);
break;
} else if ("-1".equals(result.get("resultCode"))) {
giftId = Integer.parseInt(result.get("giftId").toString());
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(params.get("clientId").toString());
record.setGiftId(giftId);
record.setGiftAmount(Integer.parseInt(result.get("giftAmount").toString()));
record.setGiftBy("开户中奖");
record.setIssueStatus("2");
record.setIssueBy(config.getActiveAccount());
record.setCreateBy(params.get("clientId").toString());
activeGiftRecordDao.insert(record);
outmap.put("resultCode", "-1");
return outmap;
}
}
//未发送奖品
if (giftId == 0) {
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(params.get("clientId").toString());
record.setGiftId(Integer.parseInt(result.get("giftId").toString()));
record.setGiftAmount(Integer.parseInt(result.get("giftAmount").toString()));
record.setGiftBy("开户中奖");
record.setIssueStatus("0");
record.setIssueBy(config.getActiveAccount());
record.setCreateBy(params.get("clientId").toString());
activeGiftRecordDao.insert(record);
}
outmap.put("resultCode", "1");
return outmap;
}
/**发放奖品*/
public Map<String, Object> transferGift(Map<String, Object> params, int activeId) {
Map<String, Object> outmap = new HashMap<String, Object>();
ActiveConfigInfo config = activeConfigDao.queryById(activeId);
outmap.put("issueBy", config.getActiveAccount());
//确定奖品
List<ActiveRuleInfo> list = activeRuleDao.queryByConfigId(activeId);
ActiveRuleInfo rule = this.chooseRule(list);
if (rule == null) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "奖品不足,已发放完毕");
outmap.put("giftId", 0);
outmap.put("giftAmount", 0);
return outmap;
}
ActiveGiftInfo gift = rule.getActiveGiftInfo();
try {
T2Result result = userTradeBiz.transfer(gift.getGiftCode(), config.getActiveAccount(),
params.get("clientId").toString(), rule.getGiftAmount(), "");
log.info(result);
if (result.getCode() == 0) {
outmap.put("resultCode", "1");
} else {
outmap.put("resultCode", result.getCode());
}
outmap.put("giftId", gift.getId());
outmap.put("giftAmount", rule.getGiftAmount());
return outmap;
} catch (Exception e) {
log.info(e);
outmap.put("giftId", 0);
outmap.put("giftAmount", rule.getGiftAmount());
outmap.put("resultCode", "-1");
return outmap;
}
}
/**选择奖品*/
public ActiveRuleInfo chooseRule(List<ActiveRuleInfo> list) {
log.info(list);
ActiveRuleInfo rule = null;
ActiveGiftInfo gift = null;
int randomNum = (int) (Math.random() * 10);
for (ActiveRuleInfo activeRuleInfo : list) {
if (activeRuleInfo.getStartRule() <= randomNum
&& randomNum <= activeRuleInfo.getEndRule()) {
rule = activeRuleInfo;
gift = rule.getActiveGiftInfo();
}
}
if (gift.getGiftRemainAmount() < rule.getGiftAmount()) {
list.remove(rule);
for (ActiveRuleInfo activeRuleInfo : list) {
if (activeRuleInfo.getGiftAmount() <= activeRuleInfo.getActiveGiftInfo()
.getGiftRemainAmount()) {
rule = activeRuleInfo;
return rule;
}
}
}
return rule;
}
/**为指定用户发送指定奖品*/
public Map<String, Object> sendGift(Map<String, Object> params) {
Map<String, Object> outmap = new HashMap<String, Object>();
//查询需要发放奖品的用户
params.put("startDate", "20150910");
params.put("endDate", "20160525");
params.put("clientStatus", "0");
List<String> list = clientDao.queryClientId(params);
Map<String, Object> inmap = new HashMap<String, Object>();
for (String str : list) {
inmap.put("clientId", str);
this.openAccountActive(inmap);
}
outmap.put("resultCode", "1");
outmap.put("resultMsg", "操作完毕");
return outmap;
}
/**发放预览查询*/
public List<Map<String, Object>> search(Map<String, Object> params) {
return activeGiftRecordDao.search(params);
}
public int searchTotal(Map<String, Object> params) {
return activeGiftRecordDao.searchTotal(params);
}
/**活动规则查询*/
public List<ActiveConfigInfo> configSearch(Map<String, Object> params) {
return activeConfigDao.search(params);
}
public int configSearchTotal(Map<String, Object> params) {
return activeConfigDao.searchTotal(params);
}
/**奖品补送*/
public Map<String, Object> sendRecord(Map<String, Object> params) {
Map<String, Object> outmap = new HashMap<String, Object>();
//活动信息
ActiveConfigInfo config = activeConfigDao
.queryById(Integer.parseInt(params.get("id").toString()));
Date nowdate = new Date();
if (nowdate.before(config.getStartDate()) || nowdate.after(config.getEndDate())) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "活动未开始");
return outmap;
}
List<Map<String, Object>> list = this.search(params);
return null;
}
/**重新送奖品*/
public Map<String, Object> reSendGift(Map<String, Object> params, ActiveConfigInfo config) {
Map<String, Object> outmap = new HashMap<String, Object>();
int ruleCount = activeRuleDao.queryRuleCountByConfigId(config.getId());
Map<String, Object> result = new HashMap<String, Object>();
for (int i = 0; i < ruleCount; i++) {
result = this.transferGift(params, config.getId());
if ("1".equals(result.get("resultCode"))) {
//记录用户中奖纪录
int giftId = Integer.parseInt(result.get("giftId").toString());
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(params.get("clientId").toString());
record.setGiftId(giftId);
record.setGiftAmount(Integer.parseInt(result.get("giftAmount").toString()));
record.setGiftBy("开户中奖");
record.setIssueStatus("1");
record.setIssueBy(config.getActiveAccount());
record.setCreateBy(params.get("clientId").toString());
activeGiftRecordDao.insert(record);
//减活动奖品存量
Map<String, Object> updatemap = new HashMap<String, Object>();
updatemap.put("id", giftId);
updatemap.put("amount", result.get("giftAmount"));
activeGiftDao.updateRemainAmount(updatemap);
break;
}
}
outmap.put("resultCode", "1");
return outmap;
}
/**补送(开户成功未执行送奖品操作的)*/
public Map<String, Object> sendGiftFor() {
Map<String, Object> inmap = new HashMap<String, Object>();
inmap.put("type", "0");
inmap.put("status", "2");
inmap.put("nowDate", DateUtil.getNow());
List<ActiveConfigInfo> actList = activeConfigDao.queryActive(inmap);
ActiveConfigInfo config = actList.get(0);
int ruleCount = activeRuleDao.queryRuleCountByConfigId(config.getId());
Map<String, Object> dateMap = new HashMap<String, Object>();
dateMap.put("nowDate", DateUtil.getNow(DateEnum.UNSIGNED_DATE));
List<Map<String, Object>> list = clientDao.queryForSendGift(dateMap);
Map<String, Object> params = new HashMap<String, Object>();
for (Map<String, Object> map : list) {
//开户成功的才送
params.put("client_name", map.get("CLIENT_NAME"));
params.put("id_no", map.get("ID_NO"));
params.put("id_kind", map.get("ID_KIND"));
T2Result result = T2Util.request(params, "619852");
if (!"0".equals(result.getData().get(0).get("result_code"))) {
continue;
}
//已送过的不送
params.put("clientId", map.get("CLIENT_ID"));
params.put("activeId", config.getId());
int recordCount = activeGiftRecordDao.queryCountByConditions(params);
if (recordCount > 0) {
continue;
}
int giftId = 0;
map.put("clientId", map.get("CLIENT_ID"));
Map<String, Object> outmap = new HashMap<String, Object>();
for (int i = 0; i < ruleCount; i++) {
outmap = this.transferGift(map, config.getId());
if ("1".equals(outmap.get("resultCode"))) {
//记录用户中奖纪录
giftId = Integer.parseInt(outmap.get("giftId").toString());
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(map.get("clientId").toString());
record.setGiftId(giftId);
record.setGiftAmount(Integer.parseInt(outmap.get("giftAmount").toString()));
record.setGiftBy("开户中奖");
record.setIssueStatus("1");
record.setIssueBy(config.getActiveAccount());
record.setCreateBy(map.get("clientId").toString());
activeGiftRecordDao.insert(record);
//减活动奖品存量
Map<String, Object> updatemap = new HashMap<String, Object>();
updatemap.put("id", giftId);
updatemap.put("amount", outmap.get("giftAmount"));
activeGiftDao.updateRemainAmount(updatemap);
break;
} else if ("-1".equals(outmap.get("resultCode"))) {
giftId = Integer.parseInt(outmap.get("giftId").toString());
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(map.get("clientId").toString());
record.setGiftId(giftId);
record.setGiftAmount(Integer.parseInt(outmap.get("giftAmount").toString()));
record.setGiftBy("开户中奖");
record.setIssueStatus("2");
record.setIssueBy(config.getActiveAccount());
record.setCreateBy(map.get("clientId").toString());
activeGiftRecordDao.insert(record);
outmap.put("resultCode", "-1");
return outmap;
}
}
//未发送奖品
if (giftId == 0) {
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(map.get("clientId").toString());
record.setGiftId(Integer.parseInt(outmap.get("giftId").toString()));
record.setGiftAmount(Integer.parseInt(outmap.get("giftAmount").toString()));
record.setGiftBy("开户中奖");
record.setIssueStatus("0");
record.setIssueBy(config.getActiveAccount());
record.setCreateBy(map.get("clientId").toString());
activeGiftRecordDao.insert(record);
}
}
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("resultCode", "1");
resultMap.put("resultMsg", "操作完毕");
return resultMap;
}
/**推荐赠送活动用户补发*/
public Map<String, Object> sendGiftForReferee() {
UserInfo userInfo = ActionUtil.getUser();
Map<String, Object> inmap = new HashMap<String, Object>();
inmap.put("type", "1");
inmap.put("status", "2");
inmap.put("nowDate", DateUtil.getNow());
List<ActiveConfigInfo> actList = activeConfigDao.queryActive(inmap);
ActiveConfigInfo config = actList.get(0);
int recordCount, developerCount, mixCount;
String developer;
Map<String, Object> params = new HashMap<String, Object>();
Map<String, Object> paramMap = new HashMap<String, Object>();
params.put("activeId", config.getId());
List<Map<String, Object>> list = clientDao.queryDeveloperList();
log.info("推荐用户数大于等于15的推荐人列表:" + list);
for (Map<String, Object> map : list) {
developer = map.get("DEVELOPER").toString();
//如果推荐人号码为代理商编号,获取推荐人的会员号
if (developer.length() < 8) {
Map<String, Object> devmap = new HashMap<String, Object>();
devmap.put("agentNo", developer);
AgentInfo agentInfo = agentInfoDao.search(devmap);
developer = agentInfo.getFundAccount();
}
params.put("clientId", developer);
recordCount = activeGiftRecordDao.queryCountByConditions(params);
developerCount = Integer.parseInt(map.get("NUM").toString());
if ((developerCount - 10) / 5 > recordCount) {
paramMap.put("clientId", developer);
mixCount = (developerCount - 10) / 5 - recordCount;
for (int i = 0; i < mixCount; i++) {
Map<String, Object> result = this.transferGift(paramMap, config.getId());
ActiveGiftRecordInfo record = new ActiveGiftRecordInfo();
record.setActiveId(config.getId());
record.setUserId(developer);
record.setGiftId(Integer.parseInt(result.get("giftId").toString()));
record.setGiftBy("推荐达标中奖");
record.setIssueBy(result.get("issueBy").toString());
record.setGiftAmount(Integer.parseInt(result.get("giftAmount").toString()));
record.setCreateBy(userInfo.getTruename());
if ("1".equals(result.get("resultCode"))) {
record.setIssueStatus("1");
Map<String, Object> updatemap = new HashMap<String, Object>();
updatemap.put("id", result.get("giftId"));
updatemap.put("amount", result.get("giftAmount"));
activeGiftDao.updateRemainAmount(updatemap);
} else if ("-1".equals(result.get("resultCode"))) {
record.setIssueStatus("2");
} else {
record.setIssueStatus("0");
}
activeGiftRecordDao.insert(record);
}
}
}
Map<String, Object> outmap = new HashMap<String, Object>();
outmap.put("resultCode", "1");
outmap.put("resultMsg", "操作完毕");
return outmap;
}
/**指定活动补送*/
public Map<String, Object> send(int activeId) {
UserInfo userInfo = ActionUtil.getUser();
Map<String, Object> params = new HashMap<String, Object>();
params.put("activeId", activeId);
List<ActiveGiftRecordInfo> list = activeGiftRecordDao.queryRecord(params);
for (ActiveGiftRecordInfo record : list) {
params.put("clientId", record.getUserId());
Map<String, Object> result = this.transferGift(params, activeId);
record.setGiftId(Integer.parseInt(result.get("giftId").toString()));
record.setIssueBy(result.get("issueBy").toString());
record.setGiftAmount(Integer.parseInt(result.get("giftAmount").toString()));
record.setCreateBy(userInfo.getTruename());
if ("1".equals(result.get("resultCode"))) {
record.setIssueStatus("1");
Map<String, Object> updatemap = new HashMap<String, Object>();
updatemap.put("id", result.get("giftId"));
updatemap.put("amount", result.get("giftAmount"));
activeGiftDao.updateRemainAmount(updatemap);
} else if ("-1".equals(result.get("resultCode"))) {
record.setIssueStatus("2");
} else {
record.setIssueStatus("0");
}
activeGiftRecordDao.updateRecord(record);
}
Map<String, Object> outmap = new HashMap<String, Object>();
outmap.put("resultCode", "1");
outmap.put("resultMsg", "操作完毕");
return outmap;
}
/**会员推荐奖励配额活动_计算配额
* @throws Exception */
public Map<String, Object> setPoint(Map<String, Object> params) {
Map<String, Object> outmap = new HashMap<String, Object>();
String baseUser = params.get("clientId").toString();
Map<String, Object> query = new HashMap<String, Object>();
query.put("type", "3");
query.put("status", "1");
query.put("nowDate", DateUtil.getNow());
List<PointActiveInfo> activeList = pointActiveDao.queryActive(query);
if (activeList.size() == 0) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "当前非活动时间");
return outmap;
}
String remark = "直推开户的配售额度奖励活动";
String giftBy = "开户会员为:" + params.get("clientId");
Date expiredDate = this.getExpiredDate(activeList.get(0).getExpiredDate());
outmap = this.sendPoint(params.get("clientId").toString(), 20, activeList.get(0),
expiredDate, giftBy, remark);
Map<String, Object> inmap = new HashMap<String, Object>();
Map<String, Object> retmap = new HashMap<String, Object>();
for (int i = 0; i <= 4; i++) {
int devPoint;
if (retmap.size() == 0) {
inmap.put("clientId", baseUser);
inmap.put("userLevel", 0);
inmap.put("baseUser", 1);
} else {
inmap.put("clientId", retmap.get("developer"));
inmap.put("userLevel", retmap.get("developerLevel"));
inmap.put("baseUser", 0);
}
retmap = this.checkDeveloper(inmap);
if ("0".equals(retmap.get("resultCode"))) {
break;
}
if (inmap.get("clientId").equals(baseUser)) {
devPoint = 5;
} else {
devPoint = 1;
}
giftBy = "直推用户为:" + inmap.get("clientId") + ",推荐人为:" + retmap.get("developer");
this.sendPoint(retmap.get("developer").toString(), devPoint, activeList.get(0),
expiredDate, giftBy, remark);
}
return outmap;
}
/**
* 根据有效期天数查询有效期截止时间
* @param expiredDate 有效期天数
* @return
*/
public Date getExpiredDate(int expiredDate) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(sysParamValueDao.getSysDate());
calendar.add(Calendar.DAY_OF_YEAR, expiredDate);
return calendar.getTime();
}
/**发放配额奖励
* @throws Exception */
public Map<String, Object> sendPoint(String userId, double point, PointActiveInfo active,
Date expiredDate, String giftBy, String remark) {
Map<String, Object> outmap = new HashMap<String, Object>();
if (point > active.getGiftRemain() && active.getGiftAmount() > 0) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "剩余配额不足");
log.info("剩余配额不足");
return outmap;
}
Map<String, Object> inmap = new HashMap<String, Object>();
inmap.put("userId", userId);
inmap.put("activeId", active.getId());
inmap.put("businessType", "0");
List<PointRecordInfo> list = pointRecordDao.queryRecordByConditions(inmap);
if (list.size() > 0 && point == 20) {
outmap.put("resultCode", "0");
outmap.put("resultMsg", "已发放过配额奖励");
log.info("已发放过配额奖励");
return outmap;
}
PointRecordInfo record = new PointRecordInfo();
record.setActiveId(active.getId());
record.setUserId(userId);
record.setBusinessType("0");
record.setOccurCount(point);
record.setRemainCount(point);
PointUserInfo pointUserInfo = pointUserDao.queryByUserId(userId);
double postAmount;
if (pointUserInfo != null) {
postAmount = pointUserInfo.getPointAmount() + point;
pointUserInfo.setPointAmount(postAmount);
pointUserDao.update(pointUserInfo);
} else {
postAmount = point;
pointUserInfo = new PointUserInfo();
pointUserInfo.setPointAmount(postAmount);
pointUserInfo.setUserId(userId);
pointUserDao.insert(pointUserInfo);
}
record.setPostCount(postAmount);
record.setExpiredDate(expiredDate);
record.setBusinessType("0");
record.setRemark(remark);
record.setGiftBy(giftBy);
record.setCreateBy("管理员");
pointRecordDao.insert(record);
if (active.getGiftAmount() != 0) {
active.setGiftRemain(active.getGiftRemain() - point);
pointActiveDao.updateGiftRemain(active);
}
outmap.put("resultCode", "1");
outmap.put("resultMsg", "您已获得20配售额度!");
//发送微信提示
WxUserInfo wxUserInfo = weixinDao.queryByUserId(userId);
if (wxUserInfo != null) {
Map<String, String> rationPointInfo = new HashMap<String, String>();
rationPointInfo.put("openId", wxUserInfo.getOpenId());
rationPointInfo.put("active", active.getName());
rationPointInfo.put("occurCount", record.getOccurCount().toString());
rationPointInfo.put("postCount", record.getPostCount().toString());
templateBiz.postTemplate(rationPointInfo,
"/template/rationPointInfo?openId={openId}&active={active}&occurCount={occurCount}&postCount={postCount}");
}
return outmap;
}
/**推荐开户活动_验证直推用户。
* 若直推用户等级高于该用户等级,则返回直推用户会员号、直推用户等级,否则而返回失败
* @param params {clientId : 当前会员号, userLevel : 当前会员会员等级}
* @return {developer : 直推用户 , developerLevel : 直推用户会员等级}
*/
public Map<String, Object> checkDeveloper(Map<String, Object> params) {
Map<String, Object> outmap = new HashMap<String, Object>();
String developer = clientInfoDao
.queryDeveloperByClientId(params.get("clientId").toString());
if ("".equals(developer) || "5001".equals(developer) || StringUtil.isBlank(developer)) {
outmap.put("resultCode", "0");
log.info("用户:" + params.get("clientId") + "没有推荐人");
return outmap;
}
String develoeprLevel = clientDao.queryUserLevel(developer);
//若推荐人等级不高于该会员等级,则返回失败
if (Integer.parseInt(develoeprLevel) <= Integer.parseInt(params.get("userLevel").toString())
&& "0".equals(params.get("baseUser").toString())) {
outmap.put("resultCode", "0");
log.info("等级为:" + params.get("userLevel") + "的会员:" + params.get("clientId") + "的推荐人等级为:"
+ develoeprLevel);
} else {
outmap.put("resultCode", "1");
outmap.put("developer", developer);
outmap.put("developerLevel", develoeprLevel);
}
return outmap;
}
/**开户送积分活动_补发积分*/
public void reissue(String userId, int activeId) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("userId", userId);
params.put("activeId", activeId);
params.put("businessType", "0");
List<PointRecordInfo> list = pointRecordDao.queryRecordByConditions(params);
if (list.size() == 0) {
params.clear();
params.put("clientId", userId);
this.setPoint(params);
}
}
}