Authored by chenjian

订单分享活动领券

... ... @@ -24,4 +24,14 @@ public class Constant {
public final static String USED_REGISTER_GET_TIME_MEM_KEY = "yh:users:used_register_get_time_";
public final static int ORDER_SHARE_MOBILE_ERROR = 1;
public final static int ORDER_SHARE_USER_UNREGISTER = 2;
public final static int ORDER_SHARE_ACTIVITY_EXPIRE = 3;
public final static int ORDER_SHARE_USERTYPE_OLD = 0;
public final static int ORDER_SHARE_USERTYPE_NEW = 1;
}
... ...
... ... @@ -4,6 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.activity.common.ApiResponse;
... ... @@ -68,5 +69,23 @@ public class OrderShareController {
Object data=null;
return new ApiResponse(data);
}
/**
* 订单分享活动领券
* @param mobile
* @param activityId
* @param orderCode
* @return
*/
@RequestMapping(params = "method=app.order.drawOrderShareCoupon")
@ResponseBody
public ApiResponse drawOrderShareCoupon(@RequestParam(value = "mobile", required = true) String mobile,
@RequestParam(value = "activityId", required = true) int activityId,
@RequestParam(value = "orderCode", required = true) long orderCode) {
logger.info("drawOrderShareCoupon enter, mobile: {}, activityId: {}, orderCode: {}", mobile, activityId, orderCode);
return new ApiResponse.ApiResponseBuilder().code(200).message("ok").build();
}
}
... ...
... ... @@ -14,4 +14,6 @@ public interface IUserShareHistoryDAO {
int updateByPrimaryKeySelective(UserShareHistory record);
int updateByPrimaryKey(UserShareHistory record);
UserShareHistory selectByOrderAndActivity(String orderCode, int activityId);
}
\ No newline at end of file
... ...
... ... @@ -19,6 +19,14 @@
from user_share_history
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByOrderAndActivity" resultMap="BaseResultMap"
select
<include refid="Base_Column_List" />
from user_share_history
where order_code = #{orderCode,jdbcType=VARCHAR}
and activity_id = #{activityId,jdbcType=INTEGER} limit 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from user_share_history
where id = #{id,jdbcType=INTEGER}
... ...
package com.yoho.activity.service;
public interface IOrderShareActivityService {
import com.yoho.service.model.activity.drawline.response.DrawOrderShareCouponRespBO;
public interface IOrderShareActivityService {
DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile, int activityId, long orderCode);
}
... ...
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;
}
}
... ...