|
@@ -3,6 +3,7 @@ |
|
@@ -3,6 +3,7 @@ |
3
|
*/
|
3
|
*/
|
4
|
package com.yoho.activity.service.impl;
|
4
|
package com.yoho.activity.service.impl;
|
5
|
|
5
|
|
|
|
6
|
+import java.math.BigDecimal;
|
6
|
import java.util.HashMap;
|
7
|
import java.util.HashMap;
|
7
|
import java.util.Iterator;
|
8
|
import java.util.Iterator;
|
8
|
import java.util.List;
|
9
|
import java.util.List;
|
|
@@ -20,6 +21,7 @@ import org.slf4j.LoggerFactory; |
|
@@ -20,6 +21,7 @@ import org.slf4j.LoggerFactory; |
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
21
|
import org.springframework.stereotype.Service;
|
22
|
import org.springframework.stereotype.Service;
|
22
|
|
23
|
|
|
|
24
|
+import com.yoho.activity.common.cache.Cacheable;
|
23
|
import com.yoho.activity.common.helper.SendCouponHelper;
|
25
|
import com.yoho.activity.common.helper.SendCouponHelper;
|
24
|
import com.yoho.activity.common.vo.LotteryRespData;
|
26
|
import com.yoho.activity.common.vo.LotteryRespData;
|
25
|
import com.yoho.activity.service.ILotteryService;
|
27
|
import com.yoho.activity.service.ILotteryService;
|
|
@@ -67,6 +69,7 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -67,6 +69,7 @@ public class LotteryServiceImpl implements ILotteryService { |
67
|
private SendCouponHelper sendCouponHelper;
|
69
|
private SendCouponHelper sendCouponHelper;
|
68
|
|
70
|
|
69
|
@Override
|
71
|
@Override
|
|
|
72
|
+ @Cacheable(expireTime = 300)
|
70
|
public LotteryRespData getLotteryInfo(Integer lotteryId) {
|
73
|
public LotteryRespData getLotteryInfo(Integer lotteryId) {
|
71
|
|
74
|
|
72
|
LotteryRespData data = new LotteryRespData();
|
75
|
LotteryRespData data = new LotteryRespData();
|
|
@@ -107,7 +110,7 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -107,7 +110,7 @@ public class LotteryServiceImpl implements ILotteryService { |
107
|
LotteryRecord rec = records.get(0);
|
110
|
LotteryRecord rec = records.get(0);
|
108
|
boolean havePrize;
|
111
|
boolean havePrize;
|
109
|
Prize prize = null;
|
112
|
Prize prize = null;
|
110
|
- if(rec.getPrizeId() == null || rec.getPrizeId() <= 0) {
|
113
|
+ if (rec.getPrizeId() == null || rec.getPrizeId() <= 0) {
|
111
|
havePrize = false;
|
114
|
havePrize = false;
|
112
|
} else {
|
115
|
} else {
|
113
|
prize = prizeMapper.selectByPrimaryKey(rec.getPrizeId());
|
116
|
prize = prizeMapper.selectByPrimaryKey(rec.getPrizeId());
|
|
@@ -129,10 +132,11 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -129,10 +132,11 @@ public class LotteryServiceImpl implements ILotteryService { |
129
|
|
132
|
|
130
|
@Override
|
133
|
@Override
|
131
|
public synchronized LotteryRespData lucky(Integer lotteryId, Integer userId, String orderCode) {
|
134
|
public synchronized LotteryRespData lucky(Integer lotteryId, Integer userId, String orderCode) {
|
132
|
-
|
135
|
+ logger.info("用户{}的订单{}进行抽奖!", userId, orderCode);
|
133
|
// 已抽奖检查
|
136
|
// 已抽奖检查
|
134
|
LotteryRespData orderLotteryState = getOrderLotteryState(lotteryId, userId, orderCode);
|
137
|
LotteryRespData orderLotteryState = getOrderLotteryState(lotteryId, userId, orderCode);
|
135
|
if (orderLotteryState.getOrderLotteryCode() != STATE_NOT_USE) {
|
138
|
if (orderLotteryState.getOrderLotteryCode() != STATE_NOT_USE) {
|
|
|
139
|
+ logger.info("用户{}的订单{}不符合抽奖条件!", userId, orderCode);
|
136
|
return orderLotteryState;
|
140
|
return orderLotteryState;
|
137
|
}
|
141
|
}
|
138
|
|
142
|
|
|
@@ -140,6 +144,7 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -140,6 +144,7 @@ public class LotteryServiceImpl implements ILotteryService { |
140
|
int lotteryCount = lotteryRecordMapper.selectUserLotteryPrizeCount(lotteryId, userId, lotteryId % 10);
|
144
|
int lotteryCount = lotteryRecordMapper.selectUserLotteryPrizeCount(lotteryId, userId, lotteryId % 10);
|
141
|
// 只能中一次
|
145
|
// 只能中一次
|
142
|
if (lotteryCount > 0) {
|
146
|
if (lotteryCount > 0) {
|
|
|
147
|
+ logger.info("用户{}的订单{}已经中过奖!", userId, orderCode);
|
143
|
return savePrizeAndGetResp(lotteryId, userId, orderCode, null);
|
148
|
return savePrizeAndGetResp(lotteryId, userId, orderCode, null);
|
144
|
}
|
149
|
}
|
145
|
|
150
|
|
|
@@ -170,10 +175,11 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -170,10 +175,11 @@ public class LotteryServiceImpl implements ILotteryService { |
170
|
|
175
|
|
171
|
// 随机抽取一个
|
176
|
// 随机抽取一个
|
172
|
Integer prizeId = selectOne(allMap);
|
177
|
Integer prizeId = selectOne(allMap);
|
173
|
-
|
178
|
+ logger.info("用户{}的订单{}抽到奖项{}!", userId, orderCode, prizeId);
|
174
|
// 奖品已经抽完
|
179
|
// 奖品已经抽完
|
175
|
Integer remain = remainMap.get(prizeId);
|
180
|
Integer remain = remainMap.get(prizeId);
|
176
|
if (remain <= 0) {
|
181
|
if (remain <= 0) {
|
|
|
182
|
+ logger.info("用户{}的订单{}抽到奖项{},该奖项剩余量为0!", userId, orderCode, prizeId);
|
177
|
prizeId = null;
|
183
|
prizeId = null;
|
178
|
}
|
184
|
}
|
179
|
|
185
|
|
|
@@ -185,6 +191,7 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -185,6 +191,7 @@ public class LotteryServiceImpl implements ILotteryService { |
185
|
LotteryRespData data = savePrizeAndGetResp(lotteryId, userId, orderCode, prizeId);
|
191
|
LotteryRespData data = savePrizeAndGetResp(lotteryId, userId, orderCode, prizeId);
|
186
|
Prize prize = prizeMapper.selectByPrimaryKey(prizeId);
|
192
|
Prize prize = prizeMapper.selectByPrimaryKey(prizeId);
|
187
|
if (!hasRealPrize(prize)) {
|
193
|
if (!hasRealPrize(prize)) {
|
|
|
194
|
+ logger.info("用户{}的订单{}抽到奖项{},该奖项为nothing!", userId, orderCode, prizeId);
|
188
|
data.setOrderLotteryCode(STATE_USE_NO_PRIZE);
|
195
|
data.setOrderLotteryCode(STATE_USE_NO_PRIZE);
|
189
|
data.setOrderLotteryMessage(MSG_NO_PRIZE);
|
196
|
data.setOrderLotteryMessage(MSG_NO_PRIZE);
|
190
|
return data;
|
197
|
return data;
|
|
@@ -199,6 +206,7 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -199,6 +206,7 @@ public class LotteryServiceImpl implements ILotteryService { |
199
|
}
|
206
|
}
|
200
|
|
207
|
|
201
|
private void givePrize(Integer userId, String orderCode, Prize prize) {
|
208
|
private void givePrize(Integer userId, String orderCode, Prize prize) {
|
|
|
209
|
+ logger.info("用户{}的订单{}抽到奖项{},进行发奖!", userId, orderCode, prize);
|
202
|
executor.execute(() -> {
|
210
|
executor.execute(() -> {
|
203
|
if ("coupons".equals(prize.getPrizeType())) {
|
211
|
if ("coupons".equals(prize.getPrizeType())) {
|
204
|
sendCouponHelper.sendCoupon(prize.getPrizeValue(), userId);
|
212
|
sendCouponHelper.sendCoupon(prize.getPrizeValue(), userId);
|
|
@@ -207,7 +215,11 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -207,7 +215,11 @@ public class LotteryServiceImpl implements ILotteryService { |
207
|
sendCouponHelper.sendYOHOBi(userId, Integer.parseInt(prize.getPrizeValue()), orderCode);
|
215
|
sendCouponHelper.sendYOHOBi(userId, Integer.parseInt(prize.getPrizeValue()), orderCode);
|
208
|
}
|
216
|
}
|
209
|
if ("orderyohocoin".equals(prize.getPrizeType())) {
|
217
|
if ("orderyohocoin".equals(prize.getPrizeType())) {
|
210
|
-
|
218
|
+ // 订单金额
|
|
|
219
|
+ BigDecimal orderMoney = BigDecimal.ONE;
|
|
|
220
|
+ int yohobi = new BigDecimal(prize.getPrizeValue()).divide(new BigDecimal("100")).multiply(orderMoney)
|
|
|
221
|
+ .intValue();
|
|
|
222
|
+ sendCouponHelper.sendYOHOBi(userId, yohobi, orderCode);
|
211
|
}
|
223
|
}
|
212
|
});
|
224
|
});
|
213
|
}
|
225
|
}
|
|
@@ -260,14 +272,14 @@ public class LotteryServiceImpl implements ILotteryService { |
|
@@ -260,14 +272,14 @@ public class LotteryServiceImpl implements ILotteryService { |
260
|
|
272
|
|
261
|
for (Iterator<Prize> iterator = prize.iterator(); iterator.hasNext();) {
|
273
|
for (Iterator<Prize> iterator = prize.iterator(); iterator.hasNext();) {
|
262
|
Prize p = iterator.next();
|
274
|
Prize p = iterator.next();
|
263
|
- if(!hasRealPrize(p)) {
|
275
|
+ if (!hasRealPrize(p)) {
|
264
|
iterator.remove();
|
276
|
iterator.remove();
|
265
|
} else {
|
277
|
} else {
|
266
|
clearPrize(p);
|
278
|
clearPrize(p);
|
267
|
}
|
279
|
}
|
268
|
}
|
280
|
}
|
269
|
}
|
281
|
}
|
270
|
-
|
282
|
+
|
271
|
private boolean hasRealPrize(Prize prize) {
|
283
|
private boolean hasRealPrize(Prize prize) {
|
272
|
return !StringUtils.equals("nothing", prize.getPrizeType());
|
284
|
return !StringUtils.equals("nothing", prize.getPrizeType());
|
273
|
}
|
285
|
}
|