...
|
...
|
@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; |
|
|
import com.yoho.activity.common.ApiResponse;
|
|
|
import com.yoho.activity.common.bo.OrderShareActivityBO;
|
|
|
import com.yoho.activity.common.bo.OrderShareBO;
|
|
|
import com.yoho.activity.common.bo.OrderShareCouponVO;
|
|
|
import com.yoho.activity.common.constatns.Constant;
|
|
|
import com.yoho.activity.common.convert.OrderShareActivityConvert;
|
|
|
import com.yoho.activity.common.helper.SendSMSHelper;
|
...
|
...
|
@@ -265,6 +266,14 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
//判断老用户今天是否已经领券过
|
|
|
if(isDrawCouponToday(profileInfo.getUid(), activityInfo.getId())) {
|
|
|
respBO.setReturnCode(Constant.ORDER_SHARE_ALREADYDRAW_ERROR);
|
|
|
respBO.setReturnMsg("您今天已经领过咯,速度去有货购潮流!");
|
|
|
log.warn("unable to draw more today, uid: {}, activityId: {}", profileInfo.getUid(), activityInfo.getId());
|
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
// 4、判断老用户是否达到分享限制
|
|
|
if (isUpToOrderShareLimit(orderCode, activityInfo.getId())) {
|
|
|
respBO.setReturnCode(Constant.ORDER_SHARE_OLDUSER_UPLIMIT);
|
...
|
...
|
@@ -275,18 +284,18 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
|
|
|
|
// 发送优惠券
|
|
|
// 获取老人优惠券
|
|
|
OrderShareCoupon coupon = orderShareCouponDAO.selectCouponByDateAndType(DateUtils.getToday("yyyy-MM-dd"), 1);
|
|
|
String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(profileInfo.getUid()));
|
|
|
if (StringUtils.isEmpty(couponCode)) {
|
|
|
OrderShareCouponVO couponVO = drawCoupon(profileInfo.getUid(), Constant.ORDER_SHARE_USERTYPE_OLD);
|
|
|
if (!couponVO.isDrawCouponSuccess()) {
|
|
|
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
|
|
|
respBO.setReturnMsg("优惠券已发光");
|
|
|
log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", profileInfo.getUid(), coupon.getCouponId());
|
|
|
log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", profileInfo.getUid(), couponVO.getCouponId());
|
|
|
return respBO;
|
|
|
}
|
|
|
log.info("orderShare drawCoupon success, uid: {}, couponCode: {}", profileInfo.getUid(), couponVO.getCouponCode());
|
|
|
|
|
|
// 4、记录用户领券的记录
|
|
|
respBO.setCoupon(couponCode);
|
|
|
updateOrderShareRecord(activityInfo.getId(), profileInfo.getUid(), orderCode, coupon.getCouponId(), 1);
|
|
|
respBO.setCoupon(couponVO.getCouponCode());
|
|
|
updateOrderShareRecord(activityInfo.getId(), profileInfo.getUid(), orderCode, couponVO.getCouponCode(), Constant.ORDER_SHARE_USERTYPE_OLD);
|
|
|
|
|
|
return respBO;
|
|
|
}
|
...
|
...
|
@@ -333,20 +342,20 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
|
|
|
|
// 3、发送优惠券
|
|
|
// 获取新人优惠券
|
|
|
OrderShareCoupon coupon = orderShareCouponDAO.selectCouponByDateAndType(null, 0);
|
|
|
String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(model.getUid()));
|
|
|
if (StringUtils.isEmpty(couponCode)) {
|
|
|
OrderShareCouponVO couponVO = drawCoupon(model.getUid(), Constant.ORDER_SHARE_USERTYPE_NEW);
|
|
|
if (!couponVO.isDrawCouponSuccess()) {
|
|
|
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
|
|
|
respBO.setReturnMsg("优惠券已发光");
|
|
|
log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", coupon.getCouponId(), model.getUid());
|
|
|
log.error("orderShare drawCoupon failed, uid: {}", model.getUid());
|
|
|
return respBO;
|
|
|
}
|
|
|
log.info("orderShare drawCoupon success, uid: {}, couponCode: {}", model.getUid(), couponVO.getCouponCode());
|
|
|
// 4、记录用户领券的记录
|
|
|
respBO.setCoupon(couponCode);
|
|
|
updateOrderShareRecord(activityInfo.getId(), model.getUid(), orderCode, coupon.getCouponId(), 0);
|
|
|
respBO.setCoupon(couponVO.getCouponCode());
|
|
|
updateOrderShareRecord(activityInfo.getId(), model.getUid(), orderCode, couponVO.getCouponCode(), Constant.ORDER_SHARE_USERTYPE_NEW);
|
|
|
|
|
|
//发送短信
|
|
|
sendSMSHelper.sendNoticeSms(mobile, "【Yoho!Buy有货】恭喜您获得一张"+ coupon.getCouponName() +",您的登录账户是"+ mobile +",密码是"+ registerReqBO.getPassword() +";下载Yoho!Buy有货手机端http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho,更多惊喜等着您!");
|
|
|
sendSMSHelper.sendNoticeSms(mobile, "【Yoho!Buy有货】恭喜您获得一张"+ couponVO.getCouponName() +",您的登录账户是"+ mobile +",密码是"+ registerReqBO.getPassword() +";下载Yoho!Buy有货手机端http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho,更多惊喜等着您!");
|
|
|
|
|
|
return respBO;
|
|
|
}
|
...
|
...
|
@@ -427,6 +436,23 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 检查老用户当天是否已经领取过用户券
|
|
|
* @param uid
|
|
|
* @param activityId
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean isDrawCouponToday(int uid, int activityId) {
|
|
|
int todayZero = DateUtils.getTodayZero();
|
|
|
int count = userCouponHistoryDAO.selectCountAfter(uid, activityId, todayZero);
|
|
|
if(count > 0) {
|
|
|
log.warn("the user have draw coupon today, uid: {}, count: {}", uid, count);
|
|
|
return false;
|
|
|
}
|
|
|
log.info("the user haven't draw coupon today, uid: {}, fromTime: {}", uid, todayZero);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 检查老用户是否超出领取优惠券限制(默认限制5次)
|
|
|
*
|
|
|
* @param shareHistoryInfo
|
...
|
...
|
@@ -448,6 +474,14 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改领券记录
|
|
|
* @param activityId
|
|
|
* @param uid
|
|
|
* @param orderCode
|
|
|
* @param couponId
|
|
|
* @param userType
|
|
|
*/
|
|
|
private void updateOrderShareRecord(int activityId, int uid, long orderCode, String couponId, int userType) {
|
|
|
addCouponHistory(activityId, uid, String.valueOf(orderCode), couponId, userType);
|
|
|
UserShareHistory shareHistoryInfo = getShareHistoryByOrderAndActivity(orderCode, activityId);
|
...
|
...
|
@@ -457,4 +491,44 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService |
|
|
}
|
|
|
updateShareHistory(shareHistoryInfo.getId(), userType);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 领取券
|
|
|
* @param uid
|
|
|
* @param userType
|
|
|
* @return
|
|
|
*/
|
|
|
private OrderShareCouponVO drawCoupon(int uid, int userType) {
|
|
|
log.info("draw orderShare coupon: uid: {}, userType: {}", uid, userType);
|
|
|
OrderShareCouponVO couponVO = new OrderShareCouponVO();
|
|
|
|
|
|
//新人券、老人全不一样
|
|
|
OrderShareCoupon coupon = null;
|
|
|
if(userType == Constant.ORDER_SHARE_USERTYPE_OLD) {
|
|
|
coupon = orderShareCouponDAO.selectCouponByDateAndType(DateUtils.getToday("yyyy-MM-dd"), Constant.ORDER_SHARE_USERTYPE_OLD);
|
|
|
}
|
|
|
else if(userType == Constant.ORDER_SHARE_USERTYPE_NEW) {
|
|
|
coupon = orderShareCouponDAO.selectCouponByDateAndType(null, Constant.ORDER_SHARE_USERTYPE_NEW);
|
|
|
}
|
|
|
|
|
|
if(coupon == null) {
|
|
|
log.error("no orderShare coupon for user, uid: {}, userType: {}", uid, userType);
|
|
|
return couponVO;
|
|
|
}
|
|
|
couponVO.setCouponId(coupon.getCouponId());
|
|
|
couponVO.setCouponName(coupon.getCouponName());
|
|
|
|
|
|
//发送优惠券
|
|
|
log.info("orderShare sendCoupon, uid: {}, couponId: {}", uid, coupon.getCouponId());
|
|
|
String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(uid));
|
|
|
if(StringUtils.isEmpty(couponCode)) {
|
|
|
log.error("sendCoupon failed, uid: {}, couponId: {}", uid, coupon.getCouponId());
|
|
|
return couponVO;
|
|
|
}
|
|
|
couponVO.setCouponCode(couponCode);
|
|
|
couponVO.setDrawCouponSuccess(true); //领券成功
|
|
|
log.info("draw orderShare coupon result: uid: {}, coupon code: {}", uid, couponCode);
|
|
|
return couponVO;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|