UserLevelActiveBiz.java
8.15 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
package com.cjs.cms.biz.user.point;
import java.util.ArrayList;
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 org.springframework.transaction.annotation.Transactional;
import com.cjs.cms.biz.ServiceException;
import com.cjs.cms.biz.user.WeiXinBiz;
import com.cjs.cms.dao.pub.MySqlSysDateDao;
import com.cjs.cms.dao.user.AgentInfoDao;
import com.cjs.cms.dao.user.WeixinDao;
import com.cjs.cms.dao.user.account.ClientInfoDao;
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.dao.user.point.UserLevelRecordDao;
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.PointActiveInfo;
import com.cjs.cms.model.user.point.PointRecordInfo;
import com.cjs.cms.model.user.point.PointRuleInfo;
import com.cjs.cms.model.user.point.PointUserInfo;
import com.cjs.cms.model.user.point.UserLevelRecordInfo;
import com.cjs.cms.util.lang.DateEnum;
import com.cjs.cms.util.lang.DateUtil;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.web.ActionUtil;
/**
* 等级会员配售额度发放
* @author tongxiaochuan
*
*/
@Service
public class UserLevelActiveBiz {
Logger log = LogManager.getLogger();
@Autowired
private UserLevelRecordDao userLevelRecordDao;
@Autowired
private PointActiveDao pointActiveDao;
@Autowired
private ClientInfoDao clientInfoDao;
@Autowired
private AgentInfoDao agentInfoDao;
@Autowired
private PointRecordDao pointRecordDao;
@Autowired
private PointUserDao pointUserDao;
@Autowired
private PointCommonBiz pointCommonBiz;
@Autowired
private MySqlSysDateDao mySqlSysDateDao;
@Autowired
private WeixinDao weixinDao;
@Autowired
private WeiXinBiz weiXinBiz;
@Transactional
public String levelActive(int id) {
UserInfo userInfo = ActionUtil.getUser();
PointActiveInfo pointActiveInfo = pointActiveDao.queryActiveById(id);
if (pointActiveInfo.getStartDate().after(mySqlSysDateDao.getSysDate())
|| pointActiveInfo.getEndDate().before(mySqlSysDateDao.getSysDate())) {
return JsonUtil.toFormJson("非活动时间", false);
}
//积分有效期
Date expiredDate = pointCommonBiz.getExpiredDate(pointActiveInfo.getExpiredDate());
List<UserLevelRecordInfo> list = userLevelRecordDao.queryForActive("2");
List<Map<String, Object>> queryList = new ArrayList<Map<String, Object>>();
Map<String, Object> params = new HashMap<String, Object>();
for (UserLevelRecordInfo userLevelRecordInfo : list) {
if (userLevelRecordInfo.getLevelAt().after(pointActiveInfo.getStartDate())) {
params.put("startDate",
DateUtil.parseDate(userLevelRecordInfo.getLevelAt(), DateEnum.UNSIGNED_DATE));
} else {
params.put("startDate",
DateUtil.parseDate(pointActiveInfo.getStartDate(), DateEnum.UNSIGNED_DATE));
}
params.put("endDate",
DateUtil.parseDate(pointActiveInfo.getEndDate(), DateEnum.UNSIGNED_DATE));
AgentInfo agentInfo = agentInfoDao.queryByFundAccount(userLevelRecordInfo.getUserId());
if (agentInfo == null) {
params.put("developer", userLevelRecordInfo.getUserId());
} else {
params.put("developer", agentInfo.getAgentNo());
}
Map<String, Object> queryMap = clientInfoDao.queryGroupByDeveloper(params);
if (queryMap == null) {
queryMap = new HashMap<String, Object>();
queryMap.put("NUM", "0");
}
queryMap.put("DEVELOPER", userLevelRecordInfo.getUserId());
queryList.add(queryMap);
}
double basePoint = 0.00;
for (Map<String, Object> map : queryList) {
UserLevelRecordInfo record = userLevelRecordDao
.queryForActiveByUserId(map.get("DEVELOPER").toString());
for (PointRuleInfo rule : pointActiveInfo.getRules()) {
if (Integer.parseInt(record.getLevel()) >= rule.getStartRule()
&& Integer.parseInt(record.getLevel()) <= rule.getEndRule()) {
basePoint = rule.getGiftAmount().doubleValue();
}
}
map.put("userId", map.get("DEVELOPER"));
map.put("activeId", pointActiveInfo.getId());
map.put("businessType", "0");
PointRecordInfo pointRecordInfo = pointRecordDao.queryRecordByCondition(map);
if (pointRecordInfo != null) {
continue;
}
if (pointActiveInfo.getGiftAmount() != 0 && pointActiveInfo
.getGiftRemain() < Double.parseDouble(map.get("NUM").toString()) + basePoint) {
throw new ServiceException("剩余数量不足");
}
if (pointActiveInfo.getGiftAmount() != 0) {
pointActiveInfo
.setGiftRemain(pointActiveInfo.getGiftRemain()
- Double.parseDouble(map.get("NUM").toString()) - basePoint);
pointActiveDao.update(pointActiveInfo);
}
PointRecordInfo recordInfo = new PointRecordInfo();
recordInfo.setActiveId(pointActiveInfo.getId());
recordInfo.setUserId(map.get("DEVELOPER").toString());
recordInfo.setOccurCount(Double.parseDouble(map.get("NUM").toString()) + basePoint);
recordInfo.setRemainCount(Double.parseDouble(map.get("NUM").toString()) + basePoint);
PointUserInfo pointUserInfo = pointUserDao
.queryByUserId(map.get("DEVELOPER").toString());
double postAmount;
if (pointUserInfo != null) {
postAmount = pointUserInfo.getPointAmount()
+ Double.parseDouble(map.get("NUM").toString()) + basePoint;
pointUserInfo.setPointAmount(postAmount);
pointUserDao.update(pointUserInfo);
} else {
postAmount = Double.parseDouble(map.get("NUM").toString()) + basePoint;
pointUserInfo = new PointUserInfo();
pointUserInfo.setPointAmount(postAmount);
pointUserInfo.setUserId(map.get("DEVELOPER").toString());
pointUserDao.insert(pointUserInfo);
}
recordInfo.setPostCount(postAmount);
recordInfo.setExpiredDate(expiredDate);
recordInfo.setBusinessType("0");
recordInfo.setRemark("完成" + pointActiveInfo.getName() + "活动");
recordInfo.setGiftBy("推荐人数:" + map.get("NUM") + ",会员等级:" + record.getLevel());
recordInfo.setCreateBy(userInfo.getTruename());
pointRecordDao.insert(recordInfo);
log.info("用户:" + map.get("DEVELOPER").toString() + ",银牌及以上会员配售额度已发放");
//发送微信提示
WxUserInfo wxUserInfo = weixinDao.queryByUserId(map.get("DEVELOPER").toString());
if (wxUserInfo != null) {
Map<String, String> rationPointInfo = new HashMap<String, String>();
rationPointInfo.put("openId", wxUserInfo.getOpenId());
rationPointInfo.put("active", pointActiveInfo.getName());
rationPointInfo.put("occurCount", recordInfo.getOccurCount().toString());
rationPointInfo.put("postCount", recordInfo.getPostCount().toString());
weiXinBiz.postTemplate(rationPointInfo,
"/template/rationPointInfo?openId={openId}&active={active}&occurCount={occurCount}&postCount={postCount}");
}
}
return JsonUtil.toFormJson("银牌及以上会员配售额度发放活动发放完毕", true);
}
}