...
|
...
|
@@ -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);
|
|
|
}
|
|
|
} |
...
|
...
|
|