|
@@ -109,7 +109,7 @@ public class CouponServiceImpl implements ICouponService { |
|
@@ -109,7 +109,7 @@ public class CouponServiceImpl implements ICouponService { |
109
|
validityRange = Range.open(now, end);
|
109
|
validityRange = Range.open(now, end);
|
110
|
}
|
110
|
}
|
111
|
|
111
|
|
112
|
- return sendCoupons(uid, couponTokens.stream().collect(Collectors.joining(",")), repeatable, validityRange);
|
112
|
+ return sendCoupons(uid, couponTokens.stream().collect(Collectors.joining(",")), repeatable, validityRange, true);
|
113
|
}
|
113
|
}
|
114
|
|
114
|
|
115
|
|
115
|
|
|
@@ -118,6 +118,8 @@ public class CouponServiceImpl implements ICouponService { |
|
@@ -118,6 +118,8 @@ public class CouponServiceImpl implements ICouponService { |
118
|
|
118
|
|
119
|
// 允许重复发放
|
119
|
// 允许重复发放
|
120
|
boolean repeatable;
|
120
|
boolean repeatable;
|
|
|
121
|
+ //是否需要校验可领取时间
|
|
|
122
|
+ boolean receiveStartTimeChkNecessary = false;
|
121
|
// 有效期
|
123
|
// 有效期
|
122
|
Range<Integer> validityRange;
|
124
|
Range<Integer> validityRange;
|
123
|
|
125
|
|
|
@@ -129,15 +131,20 @@ public class CouponServiceImpl implements ICouponService { |
|
@@ -129,15 +131,20 @@ public class CouponServiceImpl implements ICouponService { |
129
|
}else if(CouponSendType.PLATFORM_SEND_COUPON.equals(sendType)){
|
131
|
}else if(CouponSendType.PLATFORM_SEND_COUPON.equals(sendType)){
|
130
|
repeatable = true;
|
132
|
repeatable = true;
|
131
|
validityRange = null;
|
133
|
validityRange = null;
|
132
|
- } else {
|
134
|
+ } else {//用户领取
|
133
|
repeatable = false;
|
135
|
repeatable = false;
|
134
|
validityRange = null;
|
136
|
validityRange = null;
|
|
|
137
|
+ receiveStartTimeChkNecessary = true;
|
135
|
}
|
138
|
}
|
136
|
|
139
|
|
137
|
- return sendCoupons(uid, couponTokens, repeatable, validityRange);
|
140
|
+ return sendCoupons(uid, couponTokens, repeatable, validityRange, receiveStartTimeChkNecessary);
|
138
|
}
|
141
|
}
|
139
|
|
142
|
|
140
|
- private List<CouponSendBo> sendCoupons(Integer uid, String couponTokens, boolean repeatable, Range<Integer> validityRange) {
|
143
|
+ private List<CouponSendBo> sendCoupons(Integer uid,
|
|
|
144
|
+ String couponTokens,
|
|
|
145
|
+ boolean repeatable,
|
|
|
146
|
+ Range<Integer> validityRange,
|
|
|
147
|
+ boolean receiveStartTimeChkNecessary) {
|
141
|
|
148
|
|
142
|
if (uid == null || uid.intValue() <=0
|
149
|
if (uid == null || uid.intValue() <=0
|
143
|
|| StringUtils.isEmpty(couponTokens)){
|
150
|
|| StringUtils.isEmpty(couponTokens)){
|
|
@@ -154,7 +161,7 @@ public class CouponServiceImpl implements ICouponService { |
|
@@ -154,7 +161,7 @@ public class CouponServiceImpl implements ICouponService { |
154
|
CouponSendBo couponSendBo = new CouponSendBo();
|
161
|
CouponSendBo couponSendBo = new CouponSendBo();
|
155
|
couponSendBo.setCouponToken(couponToken);
|
162
|
couponSendBo.setCouponToken(couponToken);
|
156
|
try {
|
163
|
try {
|
157
|
- couponSendBo.setCouponCode(sendPerCoupon(uid, couponToken, repeatable,validityRange));
|
164
|
+ couponSendBo.setCouponCode(sendPerCoupon(uid, couponToken, repeatable,validityRange, receiveStartTimeChkNecessary));
|
158
|
couponSendBo.setSuccess(true);
|
165
|
couponSendBo.setSuccess(true);
|
159
|
} catch (ServiceException ex) {
|
166
|
} catch (ServiceException ex) {
|
160
|
logger.info("happened serviceException,uid:{},couponTokens:{}", uid, couponTokens, ex);
|
167
|
logger.info("happened serviceException,uid:{},couponTokens:{}", uid, couponTokens, ex);
|
|
@@ -171,23 +178,43 @@ public class CouponServiceImpl implements ICouponService { |
|
@@ -171,23 +178,43 @@ public class CouponServiceImpl implements ICouponService { |
171
|
return couponSendBoList;
|
178
|
return couponSendBoList;
|
172
|
}
|
179
|
}
|
173
|
|
180
|
|
174
|
- private String sendPerCoupon(Integer uid, String couponToken, boolean repeatable, Range<Integer> validityRange) {
|
181
|
+ private void checkReceiveStartTime(int uid, Coupon coupon){
|
|
|
182
|
+ Integer receiveStartTime;
|
|
|
183
|
+ Integer currentDT = DateUtil.getCurrentTimeSecond();
|
|
|
184
|
+ if (Objects.nonNull(receiveStartTime = coupon.getReceiveStartTime())
|
|
|
185
|
+ && currentDT < receiveStartTime){
|
|
|
186
|
+ logger.warn("sendCoupon find current time not reach receiveStartTime,uid {} couponToken {} [{} {}]", uid, coupon.getCouponToken(), currentDT, receiveStartTime);
|
|
|
187
|
+ throw new ServiceException(ServiceError.PROMOTION_COUPON_NOT_ARRIVE_GET_START_TIME);
|
|
|
188
|
+ }
|
|
|
189
|
+ }
|
175
|
|
190
|
|
176
|
- logger.info("senCoupon enter,{},{},{}", uid, couponToken, repeatable);
|
191
|
+ private String sendPerCoupon(Integer uid,
|
|
|
192
|
+ String couponToken,
|
|
|
193
|
+ boolean repeatable,
|
|
|
194
|
+ Range<Integer> validityRange,
|
|
|
195
|
+ boolean receiveStartTimeChkNecessary) {
|
|
|
196
|
+
|
|
|
197
|
+ logger.info("sendCoupon enter,{},{},{},{},{}", uid, couponToken, repeatable, validityRange, receiveStartTimeChkNecessary);
|
177
|
|
198
|
|
178
|
// 根据 couponToken 获取coupon&couponType信息
|
199
|
// 根据 couponToken 获取coupon&couponType信息
|
179
|
CouponAndType couponAndType = couponCacheService.getCouponAndType(couponToken);
|
200
|
CouponAndType couponAndType = couponCacheService.getCouponAndType(couponToken);
|
180
|
if (couponAndType == null){
|
201
|
if (couponAndType == null){
|
181
|
- logger.warn("query coupon info,coupontype is null:{}", couponToken);
|
202
|
+ logger.warn("sendCoupon query coupon info,coupontype is null:{}", couponToken);
|
182
|
throw new ServiceException(ServiceError.PROMOTION_COUPON_HAS_NOT_EXISTS);
|
203
|
throw new ServiceException(ServiceError.PROMOTION_COUPON_HAS_NOT_EXISTS);
|
183
|
}
|
204
|
}
|
|
|
205
|
+ Coupon coupon = couponAndType.getCoupon();
|
|
|
206
|
+ //check receive start time
|
|
|
207
|
+ if(receiveStartTimeChkNecessary){
|
|
|
208
|
+ //
|
|
|
209
|
+ checkReceiveStartTime(uid, coupon);
|
|
|
210
|
+ }
|
184
|
|
211
|
|
185
|
if(!repeatable){
|
212
|
if(!repeatable){
|
186
|
// 校验是否可以领取(重复领取,时间是否合法,状态)
|
213
|
// 校验是否可以领取(重复领取,时间是否合法,状态)
|
187
|
checkCanAcquire(uid, couponToken, couponAndType);
|
214
|
checkCanAcquire(uid, couponToken, couponAndType);
|
188
|
}
|
215
|
}
|
189
|
|
216
|
|
190
|
- if (couponAndType.getCoupon().getStatus() != CouponsStatusEnum.VALID.getCode()){
|
217
|
+ if (coupon.getStatus() != CouponsStatusEnum.VALID.getCode()){
|
191
|
logger.info("couponrulebo status is not valid:{},{}",uid, couponToken);
|
218
|
logger.info("couponrulebo status is not valid:{},{}",uid, couponToken);
|
192
|
throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
|
219
|
throw new ServiceException(ServiceError.PROMOTION_COUPON_IS_NOT_VAILD);
|
193
|
}
|
220
|
}
|