|
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; |
|
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; |
16
|
import com.yoho.activity.common.ApiResponse;
|
16
|
import com.yoho.activity.common.ApiResponse;
|
17
|
import com.yoho.activity.common.bo.OrderShareActivityBO;
|
17
|
import com.yoho.activity.common.bo.OrderShareActivityBO;
|
18
|
import com.yoho.activity.common.bo.OrderShareBO;
|
18
|
import com.yoho.activity.common.bo.OrderShareBO;
|
|
|
19
|
+import com.yoho.activity.common.bo.OrderShareCouponVO;
|
19
|
import com.yoho.activity.common.constatns.Constant;
|
20
|
import com.yoho.activity.common.constatns.Constant;
|
20
|
import com.yoho.activity.common.convert.OrderShareActivityConvert;
|
21
|
import com.yoho.activity.common.convert.OrderShareActivityConvert;
|
21
|
import com.yoho.activity.common.helper.SendSMSHelper;
|
22
|
import com.yoho.activity.common.helper.SendSMSHelper;
|
|
@@ -265,6 +266,14 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
@@ -265,6 +266,14 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
265
|
return respBO;
|
266
|
return respBO;
|
266
|
}
|
267
|
}
|
267
|
|
268
|
|
|
|
269
|
+ //判断老用户今天是否已经领券过
|
|
|
270
|
+ if(isDrawCouponToday(profileInfo.getUid(), activityInfo.getId())) {
|
|
|
271
|
+ respBO.setReturnCode(Constant.ORDER_SHARE_ALREADYDRAW_ERROR);
|
|
|
272
|
+ respBO.setReturnMsg("您今天已经领过咯,速度去有货购潮流!");
|
|
|
273
|
+ log.warn("unable to draw more today, uid: {}, activityId: {}", profileInfo.getUid(), activityInfo.getId());
|
|
|
274
|
+ return respBO;
|
|
|
275
|
+ }
|
|
|
276
|
+
|
268
|
// 4、判断老用户是否达到分享限制
|
277
|
// 4、判断老用户是否达到分享限制
|
269
|
if (isUpToOrderShareLimit(orderCode, activityInfo.getId())) {
|
278
|
if (isUpToOrderShareLimit(orderCode, activityInfo.getId())) {
|
270
|
respBO.setReturnCode(Constant.ORDER_SHARE_OLDUSER_UPLIMIT);
|
279
|
respBO.setReturnCode(Constant.ORDER_SHARE_OLDUSER_UPLIMIT);
|
|
@@ -275,18 +284,18 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
@@ -275,18 +284,18 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
275
|
|
284
|
|
276
|
// 发送优惠券
|
285
|
// 发送优惠券
|
277
|
// 获取老人优惠券
|
286
|
// 获取老人优惠券
|
278
|
- OrderShareCoupon coupon = orderShareCouponDAO.selectCouponByDateAndType(DateUtils.getToday("yyyy-MM-dd"), 1);
|
|
|
279
|
- String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(profileInfo.getUid()));
|
|
|
280
|
- if (StringUtils.isEmpty(couponCode)) {
|
287
|
+ OrderShareCouponVO couponVO = drawCoupon(profileInfo.getUid(), Constant.ORDER_SHARE_USERTYPE_OLD);
|
|
|
288
|
+ if (!couponVO.isDrawCouponSuccess()) {
|
281
|
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
|
289
|
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
|
282
|
respBO.setReturnMsg("优惠券已发光");
|
290
|
respBO.setReturnMsg("优惠券已发光");
|
283
|
- log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", profileInfo.getUid(), coupon.getCouponId());
|
291
|
+ log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", profileInfo.getUid(), couponVO.getCouponId());
|
284
|
return respBO;
|
292
|
return respBO;
|
285
|
}
|
293
|
}
|
|
|
294
|
+ log.info("orderShare drawCoupon success, uid: {}, couponCode: {}", profileInfo.getUid(), couponVO.getCouponCode());
|
286
|
|
295
|
|
287
|
// 4、记录用户领券的记录
|
296
|
// 4、记录用户领券的记录
|
288
|
- respBO.setCoupon(couponCode);
|
|
|
289
|
- updateOrderShareRecord(activityInfo.getId(), profileInfo.getUid(), orderCode, coupon.getCouponId(), 1);
|
297
|
+ respBO.setCoupon(couponVO.getCouponCode());
|
|
|
298
|
+ updateOrderShareRecord(activityInfo.getId(), profileInfo.getUid(), orderCode, couponVO.getCouponCode(), Constant.ORDER_SHARE_USERTYPE_OLD);
|
290
|
|
299
|
|
291
|
return respBO;
|
300
|
return respBO;
|
292
|
}
|
301
|
}
|
|
@@ -333,20 +342,20 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
@@ -333,20 +342,20 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
333
|
|
342
|
|
334
|
// 3、发送优惠券
|
343
|
// 3、发送优惠券
|
335
|
// 获取新人优惠券
|
344
|
// 获取新人优惠券
|
336
|
- OrderShareCoupon coupon = orderShareCouponDAO.selectCouponByDateAndType(null, 0);
|
|
|
337
|
- String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(model.getUid()));
|
|
|
338
|
- if (StringUtils.isEmpty(couponCode)) {
|
345
|
+ OrderShareCouponVO couponVO = drawCoupon(model.getUid(), Constant.ORDER_SHARE_USERTYPE_NEW);
|
|
|
346
|
+ if (!couponVO.isDrawCouponSuccess()) {
|
339
|
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
|
347
|
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
|
340
|
respBO.setReturnMsg("优惠券已发光");
|
348
|
respBO.setReturnMsg("优惠券已发光");
|
341
|
- log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", coupon.getCouponId(), model.getUid());
|
349
|
+ log.error("orderShare drawCoupon failed, uid: {}", model.getUid());
|
342
|
return respBO;
|
350
|
return respBO;
|
343
|
}
|
351
|
}
|
|
|
352
|
+ log.info("orderShare drawCoupon success, uid: {}, couponCode: {}", model.getUid(), couponVO.getCouponCode());
|
344
|
// 4、记录用户领券的记录
|
353
|
// 4、记录用户领券的记录
|
345
|
- respBO.setCoupon(couponCode);
|
|
|
346
|
- updateOrderShareRecord(activityInfo.getId(), model.getUid(), orderCode, coupon.getCouponId(), 0);
|
354
|
+ respBO.setCoupon(couponVO.getCouponCode());
|
|
|
355
|
+ updateOrderShareRecord(activityInfo.getId(), model.getUid(), orderCode, couponVO.getCouponCode(), Constant.ORDER_SHARE_USERTYPE_NEW);
|
347
|
|
356
|
|
348
|
//发送短信
|
357
|
//发送短信
|
349
|
- sendSMSHelper.sendNoticeSms(mobile, "【Yoho!Buy有货】恭喜您获得一张"+ coupon.getCouponName() +",您的登录账户是"+ mobile +",密码是"+ registerReqBO.getPassword() +";下载Yoho!Buy有货手机端http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho,更多惊喜等着您!");
|
358
|
+ sendSMSHelper.sendNoticeSms(mobile, "【Yoho!Buy有货】恭喜您获得一张"+ couponVO.getCouponName() +",您的登录账户是"+ mobile +",密码是"+ registerReqBO.getPassword() +";下载Yoho!Buy有货手机端http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho,更多惊喜等着您!");
|
350
|
|
359
|
|
351
|
return respBO;
|
360
|
return respBO;
|
352
|
}
|
361
|
}
|
|
@@ -427,6 +436,23 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
@@ -427,6 +436,23 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
427
|
}
|
436
|
}
|
428
|
|
437
|
|
429
|
/**
|
438
|
/**
|
|
|
439
|
+ * 检查老用户当天是否已经领取过用户券
|
|
|
440
|
+ * @param uid
|
|
|
441
|
+ * @param activityId
|
|
|
442
|
+ * @return
|
|
|
443
|
+ */
|
|
|
444
|
+ private boolean isDrawCouponToday(int uid, int activityId) {
|
|
|
445
|
+ int todayZero = DateUtils.getTodayZero();
|
|
|
446
|
+ int count = userCouponHistoryDAO.selectCountAfter(uid, activityId, todayZero);
|
|
|
447
|
+ if(count > 0) {
|
|
|
448
|
+ log.warn("the user have draw coupon today, uid: {}, count: {}", uid, count);
|
|
|
449
|
+ return false;
|
|
|
450
|
+ }
|
|
|
451
|
+ log.info("the user haven't draw coupon today, uid: {}, fromTime: {}", uid, todayZero);
|
|
|
452
|
+ return true;
|
|
|
453
|
+ }
|
|
|
454
|
+
|
|
|
455
|
+ /**
|
430
|
* 检查老用户是否超出领取优惠券限制(默认限制5次)
|
456
|
* 检查老用户是否超出领取优惠券限制(默认限制5次)
|
431
|
*
|
457
|
*
|
432
|
* @param shareHistoryInfo
|
458
|
* @param shareHistoryInfo
|
|
@@ -448,6 +474,14 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
@@ -448,6 +474,14 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
448
|
return false;
|
474
|
return false;
|
449
|
}
|
475
|
}
|
450
|
|
476
|
|
|
|
477
|
+ /**
|
|
|
478
|
+ * 修改领券记录
|
|
|
479
|
+ * @param activityId
|
|
|
480
|
+ * @param uid
|
|
|
481
|
+ * @param orderCode
|
|
|
482
|
+ * @param couponId
|
|
|
483
|
+ * @param userType
|
|
|
484
|
+ */
|
451
|
private void updateOrderShareRecord(int activityId, int uid, long orderCode, String couponId, int userType) {
|
485
|
private void updateOrderShareRecord(int activityId, int uid, long orderCode, String couponId, int userType) {
|
452
|
addCouponHistory(activityId, uid, String.valueOf(orderCode), couponId, userType);
|
486
|
addCouponHistory(activityId, uid, String.valueOf(orderCode), couponId, userType);
|
453
|
UserShareHistory shareHistoryInfo = getShareHistoryByOrderAndActivity(orderCode, activityId);
|
487
|
UserShareHistory shareHistoryInfo = getShareHistoryByOrderAndActivity(orderCode, activityId);
|
|
@@ -457,4 +491,44 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
@@ -457,4 +491,44 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
457
|
}
|
491
|
}
|
458
|
updateShareHistory(shareHistoryInfo.getId(), userType);
|
492
|
updateShareHistory(shareHistoryInfo.getId(), userType);
|
459
|
}
|
493
|
}
|
|
|
494
|
+
|
|
|
495
|
+ /**
|
|
|
496
|
+ * 领取券
|
|
|
497
|
+ * @param uid
|
|
|
498
|
+ * @param userType
|
|
|
499
|
+ * @return
|
|
|
500
|
+ */
|
|
|
501
|
+ private OrderShareCouponVO drawCoupon(int uid, int userType) {
|
|
|
502
|
+ log.info("draw orderShare coupon: uid: {}, userType: {}", uid, userType);
|
|
|
503
|
+ OrderShareCouponVO couponVO = new OrderShareCouponVO();
|
|
|
504
|
+
|
|
|
505
|
+ //新人券、老人全不一样
|
|
|
506
|
+ OrderShareCoupon coupon = null;
|
|
|
507
|
+ if(userType == Constant.ORDER_SHARE_USERTYPE_OLD) {
|
|
|
508
|
+ coupon = orderShareCouponDAO.selectCouponByDateAndType(DateUtils.getToday("yyyy-MM-dd"), Constant.ORDER_SHARE_USERTYPE_OLD);
|
|
|
509
|
+ }
|
|
|
510
|
+ else if(userType == Constant.ORDER_SHARE_USERTYPE_NEW) {
|
|
|
511
|
+ coupon = orderShareCouponDAO.selectCouponByDateAndType(null, Constant.ORDER_SHARE_USERTYPE_NEW);
|
|
|
512
|
+ }
|
|
|
513
|
+
|
|
|
514
|
+ if(coupon == null) {
|
|
|
515
|
+ log.error("no orderShare coupon for user, uid: {}, userType: {}", uid, userType);
|
|
|
516
|
+ return couponVO;
|
|
|
517
|
+ }
|
|
|
518
|
+ couponVO.setCouponId(coupon.getCouponId());
|
|
|
519
|
+ couponVO.setCouponName(coupon.getCouponName());
|
|
|
520
|
+
|
|
|
521
|
+ //发送优惠券
|
|
|
522
|
+ log.info("orderShare sendCoupon, uid: {}, couponId: {}", uid, coupon.getCouponId());
|
|
|
523
|
+ String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(uid));
|
|
|
524
|
+ if(StringUtils.isEmpty(couponCode)) {
|
|
|
525
|
+ log.error("sendCoupon failed, uid: {}, couponId: {}", uid, coupon.getCouponId());
|
|
|
526
|
+ return couponVO;
|
|
|
527
|
+ }
|
|
|
528
|
+ couponVO.setCouponCode(couponCode);
|
|
|
529
|
+ couponVO.setDrawCouponSuccess(true); //领券成功
|
|
|
530
|
+ log.info("draw orderShare coupon result: uid: {}, coupon code: {}", uid, couponCode);
|
|
|
531
|
+ return couponVO;
|
|
|
532
|
+ }
|
|
|
533
|
+
|
460
|
} |
534
|
} |