|
|
package com.yoho.activity.service.impl;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import com.yoho.activity.common.constatns.Constant;
|
|
|
import com.yoho.activity.service.IOrderShareActivityService;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.coupon.dal.IOrderShareActivityDAO;
|
|
|
import com.yoho.coupon.dal.IUserShareHistoryDAO;
|
|
|
import com.yoho.coupon.dal.model.OrderShareActivity;
|
|
|
import com.yoho.coupon.dal.model.UserShareHistory;
|
|
|
import com.yoho.service.model.activity.drawline.response.DrawOrderShareCouponRespBO;
|
|
|
import com.yoho.service.model.request.ProfileRequestBO;
|
|
|
import com.yoho.service.model.response.ProfileInfoRsp;
|
|
|
|
|
|
public class OrderShareActivityServiceImpl implements
|
|
|
IOrderShareActivityService {
|
|
|
private static Logger logger = LoggerFactory.getLogger(OrderShareActivityServiceImpl.class);
|
|
|
|
|
|
@Resource
|
|
|
private ServiceCaller service;
|
|
|
|
|
|
@Resource
|
|
|
private IOrderShareActivityDAO orderShareActivityDAO;
|
|
|
|
|
|
@Resource
|
|
|
private IUserShareHistoryDAO userShareHistoryDAO;
|
|
|
|
|
|
@Override
|
|
|
public DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile,
|
|
|
int activityId, long orderCode) {
|
|
|
DrawOrderShareCouponRespBO respBO = new DrawOrderShareCouponRespBO(mobile, activityId, orderCode);
|
|
|
//1、简单验证手机号
|
|
|
if(!validMobile(mobile)) {
|
|
|
respBO.setReturnCode(Constant.ORDER_SHARE_MOBILE_ERROR);
|
|
|
respBO.setReturnMsg("手机号错误,请重新输入");
|
|
|
logger.error("mobile is invalid: {}", mobile);
|
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
//2、检查手机号是否注册过
|
|
|
ProfileInfoRsp profileInfo = getRegisterUser(mobile);
|
|
|
if (profileInfo == null || profileInfo.getUid() == 0) {
|
|
|
respBO.setReturnCode(Constant.ORDER_SHARE_USER_UNREGISTER);
|
|
|
respBO.setReturnMsg("该手机号没有注册用户");
|
|
|
logger.info("unregister mobile: {}", mobile);
|
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
//3、检查活动是否结束
|
|
|
OrderShareActivity activityInfo = getActvivity(activityId);
|
|
|
if(activityInfo == null || isAcitvityExpire(activityInfo)) {
|
|
|
respBO.setReturnCode(Constant.ORDER_SHARE_ACTIVITY_EXPIRE);
|
|
|
respBO.setReturnMsg("活动已经过期");
|
|
|
logger.info("the acitivity is out of date, mobile: {}, activity: {}", mobile, activityId);
|
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 简单验证是否是11位手机号
|
|
|
* @param mobile
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean validMobile(String mobile) {
|
|
|
if(mobile == null)
|
|
|
return false;
|
|
|
|
|
|
if(mobile.length() != 11)
|
|
|
return false;
|
|
|
|
|
|
return StringUtils.isNumeric(mobile);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据手机号查注册用户
|
|
|
* @param mobile
|
|
|
* @return
|
|
|
*/
|
|
|
private ProfileInfoRsp getRegisterUser(String mobile) {
|
|
|
logger.info("query register user by mobile: {}", mobile);
|
|
|
|
|
|
ProfileRequestBO reqBO = new ProfileRequestBO();
|
|
|
reqBO.setMobile(mobile);
|
|
|
reqBO.setArea("86");
|
|
|
reqBO.setCheckSSO(true);
|
|
|
|
|
|
ProfileInfoRsp respBO = service.call("users.getUserprofileByEmailOrMobile", reqBO, ProfileInfoRsp.class);
|
|
|
logger.info("user with mobile {} is: ", respBO);
|
|
|
return respBO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询活动信息
|
|
|
* @param activityId
|
|
|
* @return
|
|
|
*/
|
|
|
private OrderShareActivity getActvivity(int activityId) {
|
|
|
logger.info("query order share acitvity, activityId: {}", activityId);
|
|
|
//....补充缓存操作
|
|
|
//......
|
|
|
OrderShareActivity activityInfo = orderShareActivityDAO.selectByPrimaryKey(activityId);
|
|
|
return activityInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断活动是否过期
|
|
|
* @param activityInfo
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean isAcitvityExpire(OrderShareActivity activityInfo) {
|
|
|
if(activityInfo == null) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return activityInfo.getEndTime() * 1000L < (new Date().getTime());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据订单号和活动ID获取分享历史
|
|
|
* @param orderCode
|
|
|
* @param activityId
|
|
|
* @return
|
|
|
*/
|
|
|
private UserShareHistory getShareHistoryByOrderAndActivity(long orderCode, int activityId) {
|
|
|
UserShareHistory shareHistoryInfo = userShareHistoryDAO.selectByOrderAndActivity(String.valueOf(orderCode), activityId);
|
|
|
return shareHistoryInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 检查新老用户是否超出分享次数限制
|
|
|
* 1、新用户,无限制;2、老用户,默认限制5次
|
|
|
* @param shareHistoryInfo
|
|
|
* @param userType
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean checkOrderShareLimit(UserShareHistory shareHistoryInfo, int userType) {
|
|
|
if(shareHistoryInfo == null) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
} |
...
|
...
|
|