Authored by chenjian

订单分享用户领券

... ... @@ -30,7 +30,9 @@ public class Constant {
public final static int ORDER_SHARE_ACTIVITY_EXPIRE = 3;
public final static int ORDER_SHARE_OLDUSER_UPLIMIT = 4;
public final static int ORDER_SHARE_REGISTER_VALID_ERROR = 5;
public final static int ORDER_SHARE_REGISTER_ERROR = 6;
}
... ...
... ... @@ -49,4 +49,24 @@ public interface ICouponActivityService {
*/
public ApiResponse validCodeAndSendCode(String code, String area, String mobile, String client_id, String activityCode) throws ServiceException;
/**
* 验证验证码
* @param regCode
* @param area
* @param mobile
* @return
* @throws ServiceException
*/
public ApiResponse validRegCode(String regCode, String area, String mobile) throws ServiceException;
/**
* 使用手机号注册
* @param area
* @param mobile
* @param client_type
* @return
* @throws ServiceException
*/
public ApiResponse register(String area, String mobile, String client_type) throws ServiceException;
}
... ...
... ... @@ -22,7 +22,15 @@ public interface IOrderShareActivityService {
*/
public OrderShareBO getShareInfo(String ordercode,int uid);
/**
* 发送订单分享优惠码
* @param mobile
* @param activityId
* @param orderCode
* @return
*/
DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile, int activityId, long orderCode);
DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile, int activityId, long orderCode, String identifyCode);
}
... ...
... ... @@ -181,7 +181,8 @@ public class ICouponActivityServiceImpl implements ICouponActivityService {
return response;
}
private ApiResponse validRegCode(String regCode, String area, String mobile) throws ServiceException {
@Override
public ApiResponse validRegCode(String regCode, String area, String mobile) throws ServiceException {
log.debug("validRegCode with regCode={}, area={}, mobile={}", regCode, area, mobile);
// 检查参数 :验证码
... ... @@ -219,7 +220,8 @@ public class ICouponActivityServiceImpl implements ICouponActivityService {
return response.get();
}
private ApiResponse register(String area, String mobile, String client_type) throws ServiceException {
@Override
public ApiResponse register(String area, String mobile, String client_type) throws ServiceException {
log.debug("register with area={}, mobile={},client_type={}", area, mobile, client_type);
... ...
... ... @@ -13,11 +13,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
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.constatns.Constant;
import com.yoho.activity.common.convert.OrderShareActivityConvert;
import com.yoho.activity.common.utils.DateUtils;
import com.yoho.activity.service.ICouponActivityService;
import com.yoho.activity.service.IOrderShareActivityService;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.coupon.dal.IOrderShareActivityDAO;
... ... @@ -44,6 +47,9 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
@Resource
private IUserCouponHistoryDAO userCouponHistoryDAO;
@Resource
ICouponActivityService couponActivityService;
@Resource
ServiceCaller serviceCaller;
... ... @@ -220,22 +226,74 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
//3、检查手机号是否注册过
ProfileInfoRsp profileInfo = getRegisterUser(mobile);
if (profileInfo == null || profileInfo.getUid() == 0) {
couponActivityService.sendSms("86", mobile);
respBO.setReturnCode(Constant.ORDER_SHARE_USER_UNREGISTER);
respBO.setReturnMsg("该手机号没有注册用户");
log.warn("unregister mobile: {}", mobile);
respBO.setReturnMsg("该手机号没有注册,已发送注册验证码");
log.warn("unregister mobile: {}, sendSms for register", mobile);
return respBO;
}
//4、判断老用户是否达到分享限制
if(isUpToOrderShareLimit(orderCode, activityId)) {
respBO.setReturnCode(Constant.ORDER_SHARE_USER_UNREGISTER);
respBO.setReturnMsg("该手机号没有注册用户");
respBO.setReturnCode(Constant.ORDER_SHARE_OLDUSER_UPLIMIT);
respBO.setReturnMsg("券已经抢光啦");
log.warn("orderShare for Register user is over, orderCode: {}, activityId: {}", orderCode, activityId);
return respBO;
}
// 发送优惠券
sendCoupon(activityInfo.getRegistCouponId(), String.valueOf(profileInfo.getUid()));
//4、记录用户领券的记录
updateOrderShareRecord(activityId, profileInfo.getUid(), orderCode, activityInfo.getRegistCouponId(), 1);
return respBO;
}
@Override
public DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile,
int activityId, long orderCode, String identifyCode) {
DrawOrderShareCouponRespBO respBO = new DrawOrderShareCouponRespBO(mobile, activityId, orderCode);
//1、检查活动是否结束
OrderShareActivity activityInfo = getActvivity(activityId);
if(activityInfo == null) {
respBO.setReturnCode(Constant.ORDER_SHARE_ACTIVITY_EXPIRE);
respBO.setReturnMsg("活动已经过期");
log.warn("the acitivity not exists, activity: {}", activityId);
return respBO;
}
// 1、验证验证码
ApiResponse identityResp = couponActivityService.validRegCode(identifyCode, "86", mobile);
if (Constant.CODE_SUCCESS != identityResp.getCode()) {
respBO.setReturnCode(Constant.ORDER_SHARE_REGISTER_VALID_ERROR);
respBO.setReturnMsg("注册验证码验证失败");
log.error("valid register code error, code: {}, mobile: {}", identifyCode, mobile);
return respBO;
}
// 2、用户注册
ApiResponse registerResp = couponActivityService.register("86", mobile, "web");
if (Constant.CODE_SUCCESS != registerResp.getCode()) {
respBO.setReturnCode(Constant.ORDER_SHARE_REGISTER_ERROR);
respBO.setReturnMsg("用户注册失败");
log.error("user register error, mobile: {}", mobile);
return respBO;
}
JSONObject registerJSON = (JSONObject) registerResp.getData();
int uid = registerJSON.getIntValue("uid");
String password = registerJSON.getString("password");
//3、发送优惠券
sendCoupon(activityInfo.getUnregistCouponId(), String.valueOf(uid));
//4、记录用户领券的记录
updateOrderShareRecord(activityId, uid, orderCode, activityInfo.getUnregistCouponId(), 0);
return respBO;
}
/**
... ... @@ -328,4 +386,14 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
return false;
}
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);
if(shareHistoryInfo == null) {
log.error("None order share, orderCode: {}, activityId: {}", orderCode, activityId);
return;
}
updateShareHistory(shareHistoryInfo.getId(), userType);
}
}
... ...