Authored by ping

update

... ... @@ -4,6 +4,11 @@ import com.yoho.queue.dal.model.BaseModel;
public class OrderShareActivityBO extends BaseModel{
/**
*
*/
private static final long serialVersionUID = 1008965277169881429L;
private Integer id;
private String activityName;
... ... @@ -14,14 +19,6 @@ public class OrderShareActivityBO extends BaseModel{
private String h5Title;
private String unregistCouponId;
private String registCouponId;
private Integer couponMaxNum;
private Integer shareMaxNum;
private String activityNormalPic;
private String activityEndPic;
... ... @@ -84,38 +81,6 @@ public class OrderShareActivityBO extends BaseModel{
this.h5Title = h5Title;
}
public String getUnregistCouponId() {
return unregistCouponId;
}
public void setUnregistCouponId(String unregistCouponId) {
this.unregistCouponId = unregistCouponId;
}
public String getRegistCouponId() {
return registCouponId;
}
public void setRegistCouponId(String registCouponId) {
this.registCouponId = registCouponId;
}
public Integer getCouponMaxNum() {
return couponMaxNum;
}
public void setCouponMaxNum(Integer couponMaxNum) {
this.couponMaxNum = couponMaxNum;
}
public Integer getShareMaxNum() {
return shareMaxNum;
}
public void setShareMaxNum(Integer shareMaxNum) {
this.shareMaxNum = shareMaxNum;
}
public String getActivityNormalPic() {
return activityNormalPic;
}
... ...
/**
*
*/
package com.yoho.activity.common.helper;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.yoho.core.common.utils.AES;
import com.yoho.core.common.utils.MD5;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.core.rest.client.hystrix.AsyncFuture;
import com.yoho.error.exception.ServiceException;
/**
* @author ping.huang
* 2016年6月2日
*/
@Component
public class SendSMSHelper {
static Logger log = LoggerFactory.getLogger(SendSMSHelper.class);
@Resource
ServiceCaller serviceCaller;
@Value("${sendSMS.password}")
private String sendSMSPassword;
public void sendNoticeSms(String mobile, String content) throws ServiceException {
log.info("sendNoticeSms with mobile={},, content={}", mobile, content);
String url = "http://www.ztsms.cn/sendSms.do?";
try {
String pwd = AES.decrypt("yoho96461qaz2wsx", sendSMSPassword);
url += "username=youhuo&password=" + MD5.md5(pwd) + "&mobile=" + mobile + "&content="+ content +"&productid=333333";
// 调用接口发送短信请求
AsyncFuture<String> response = serviceCaller.get("sms.sendSMS", url, null, String.class, null);
String result = response.get();
log.info("sendNoticeSms result is {}, mobile is {}", result, mobile);
} catch (Exception e) {
log.error("AES.decrypt error with code={}", sendSMSPassword, e);
}
}
}
... ...
... ... @@ -66,8 +66,6 @@ public class OrderShareController {
return new ApiResponse(data);
}
/**
* 订单分享活动领券
*
... ... @@ -79,11 +77,8 @@ public class OrderShareController {
@RequestMapping(params = "method=wap.order.drawOrderShareCoupon")
@ResponseBody
public ApiResponse drawOrderShareCoupon(String mobile, String ordercode) {
logger.info("drawOrderShareCoupon enter, mobile: {}, orderCode: {}", mobile, ordercode);
DrawOrderShareCouponRespBO respBO = orderShareActivityService.drawOrderShareCoupon(mobile, getOrderCode(ordercode));
return new ApiResponse.ApiResponseBuilder().code(200).data(respBO).message("ok").build();
}
... ... @@ -104,9 +99,10 @@ public class OrderShareController {
DrawOrderShareCouponRespBO respBO = orderShareActivityService.registerAndSendCoupon(mobile, getOrderCode(ordercode), identifycode);
return new ApiResponse.ApiResponseBuilder().code(200).data(respBO).message("ok").build();
}
/**
* 将字符串类型订单号转化为Long类型
*
* @param orderCodeStr
* @return
*/
... ... @@ -116,9 +112,9 @@ public class OrderShareController {
orderCode = Long.valueOf(orderCodeStr);
} catch (Exception e) {
}
if(orderCode < 1) {
logger.warn("order code is invalid");
throw new ServiceException(ServiceError.ORDER_ORDER_CODE_IS_EMPTY);
if (orderCode < 1) {
logger.warn("order code is invalid");
throw new ServiceException(ServiceError.ORDER_ORDER_CODE_IS_EMPTY);
}
return orderCode;
}
... ...
package com.yoho.coupon.dal;
import org.apache.ibatis.annotations.Param;
import com.yoho.coupon.dal.model.OrderShareCoupon;
public interface IOrderShareCouponDAO {
... ... @@ -14,4 +16,6 @@ public interface IOrderShareCouponDAO {
int updateByPrimaryKeySelective(OrderShareCoupon record);
int updateByPrimaryKey(OrderShareCoupon record);
OrderShareCoupon selectCouponByDateAndType(@Param("useDate") String useDate, @Param("couponType") int couponType);
}
\ No newline at end of file
... ...
... ... @@ -18,14 +18,6 @@ public class OrderShareActivity extends BaseModel {
private String h5Title;
private String unregistCouponId;
private String registCouponId;
private Integer couponMaxNum;
private Integer shareMaxNum;
private String activityNormalPic;
private String activityEndPic;
... ... @@ -98,38 +90,6 @@ public class OrderShareActivity extends BaseModel {
this.h5Title = h5Title == null ? null : h5Title.trim();
}
public String getUnregistCouponId() {
return unregistCouponId;
}
public void setUnregistCouponId(String unregistCouponId) {
this.unregistCouponId = unregistCouponId == null ? null : unregistCouponId.trim();
}
public String getRegistCouponId() {
return registCouponId;
}
public void setRegistCouponId(String registCouponId) {
this.registCouponId = registCouponId == null ? null : registCouponId.trim();
}
public Integer getCouponMaxNum() {
return couponMaxNum;
}
public void setCouponMaxNum(Integer couponMaxNum) {
this.couponMaxNum = couponMaxNum;
}
public Integer getShareMaxNum() {
return shareMaxNum;
}
public void setShareMaxNum(Integer shareMaxNum) {
this.shareMaxNum = shareMaxNum;
}
public String getActivityNormalPic() {
return activityNormalPic;
}
... ...
... ... @@ -8,13 +8,6 @@
<result column="show_pic" property="showPic" jdbcType="VARCHAR" />
<result column="is_show_pic" property="isShowPic" jdbcType="TINYINT" />
<result column="h5_title" property="h5Title" jdbcType="VARCHAR" />
<result column="unregist_coupon_id" property="unregistCouponId"
jdbcType="VARCHAR" />
<result column="regist_coupon_id" property="registCouponId"
jdbcType="VARCHAR" />
<result column="coupon_max_num" property="couponMaxNum"
jdbcType="INTEGER" />
<result column="share_max_num" property="shareMaxNum" jdbcType="INTEGER" />
<result column="activity_normal_pic" property="activityNormalPic"
jdbcType="VARCHAR" />
<result column="activity_end_pic" property="activityEndPic"
... ... @@ -33,9 +26,7 @@
<result column="status" property="status" jdbcType="TINYINT" />
</resultMap>
<sql id="Base_Column_List">
id, activity_name, show_pic, is_show_pic, h5_title, unregist_coupon_id,
regist_coupon_id,
coupon_max_num, share_max_num, activity_normal_pic, activity_end_pic, share_img_url,
id, activity_name, show_pic, is_show_pic, h5_title, activity_normal_pic, activity_end_pic, share_img_url,
share_title, share_content, activity_desc, begin_time, end_time,
coupon_pic, button_link,
create_time,status
... ... @@ -61,17 +52,14 @@
</delete>
<insert id="insert" parameterType="com.yoho.coupon.dal.model.OrderShareActivity">
insert into order_share_activity (activity_name, show_pic,
is_show_pic, h5_title, unregist_coupon_id,
regist_coupon_id, coupon_max_num, share_max_num,
is_show_pic, h5_title,
activity_normal_pic, activity_end_pic, share_img_url,
share_title, share_content, activity_desc,
begin_time, end_time, coupon_pic,
button_link, create_time,status)
values (#{activityName,jdbcType=VARCHAR},
#{showPic,jdbcType=VARCHAR},
#{isShowPic,jdbcType=TINYINT}, #{h5Title,jdbcType=VARCHAR}, #{unregistCouponId,jdbcType=VARCHAR},
#{registCouponId,jdbcType=VARCHAR}, #{couponMaxNum,jdbcType=INTEGER},
#{shareMaxNum,jdbcType=INTEGER},
#{isShowPic,jdbcType=TINYINT}, #{h5Title,jdbcType=VARCHAR},
#{activityNormalPic,jdbcType=VARCHAR},
#{activityEndPic,jdbcType=VARCHAR}, #{shareImgUrl,jdbcType=VARCHAR},
#{shareTitle,jdbcType=VARCHAR}, #{shareContent,jdbcType=VARCHAR},
... ... @@ -94,18 +82,7 @@
<if test="h5Title != null">
h5_title = #{h5Title,jdbcType=VARCHAR},
</if>
<if test="unregistCouponId != null">
unregist_coupon_id = #{unregistCouponId,jdbcType=VARCHAR},
</if>
<if test="registCouponId != null">
regist_coupon_id = #{registCouponId,jdbcType=VARCHAR},
</if>
<if test="couponMaxNum != null">
coupon_max_num = #{couponMaxNum,jdbcType=INTEGER},
</if>
<if test="shareMaxNum != null">
share_max_num = #{shareMaxNum,jdbcType=INTEGER},
</if>
<if test="activityNormalPic != null">
activity_normal_pic = #{activityNormalPic,jdbcType=VARCHAR},
</if>
... ... @@ -151,10 +128,6 @@
show_pic = #{showPic,jdbcType=VARCHAR},
is_show_pic = #{isShowPic,jdbcType=TINYINT},
h5_title = #{h5Title,jdbcType=VARCHAR},
unregist_coupon_id = #{unregistCouponId,jdbcType=VARCHAR},
regist_coupon_id = #{registCouponId,jdbcType=VARCHAR},
coupon_max_num = #{couponMaxNum,jdbcType=INTEGER},
share_max_num = #{shareMaxNum,jdbcType=INTEGER},
activity_normal_pic = #{activityNormalPic,jdbcType=VARCHAR},
activity_end_pic = #{activityEndPic,jdbcType=VARCHAR},
share_img_url = #{shareImgUrl,jdbcType=VARCHAR},
... ...
... ... @@ -18,6 +18,16 @@
from order_share_coupon
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectCouponByDateAndType" resultMap="BaseResultMap">
select * from order_share_coupon where 1=1
<if test="useDate != null">
and use_date=#{useDate}
</if>
<if test="coupon_type != null">
and coupon_type=#{couponType}
</if>
limit 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from order_share_coupon
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -4,6 +4,7 @@
package com.yoho.activity.service;
import com.yoho.activity.common.ApiResponse;
import com.yoho.coupon.dal.model.CouponActivity;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.activity.coupon.response.CouponActivityResponseBO;
... ... @@ -16,6 +17,15 @@ import com.yoho.service.model.activity.coupon.response.CouponActivityResponseBO;
public interface ICouponActivityService {
/**
* 发送短信
* @param mobile
* @param password
* @param activity
* @throws ServiceException
*/
public void sendNoticeSms(String mobile, String password, CouponActivity activity) throws ServiceException;
/**
* 根据id活动优惠券活动信息
* @param activityCode
* @return
... ...
... ... @@ -13,30 +13,32 @@ 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.helper.SendSMSHelper;
import com.yoho.activity.common.utils.DateUtils;
import com.yoho.activity.common.utils.RandomUtil;
import com.yoho.activity.service.ICouponActivityService;
import com.yoho.activity.service.IOrderShareActivityService;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.core.rest.exception.ServiceNotAvaibleException;
import com.yoho.core.rest.exception.ServiceNotFoundException;
import com.yoho.coupon.dal.IOrderShareActivityDAO;
import com.yoho.coupon.dal.IOrderShareCouponDAO;
import com.yoho.coupon.dal.IUserCouponHistoryDAO;
import com.yoho.coupon.dal.IUserShareHistoryDAO;
import com.yoho.coupon.dal.model.OrderShareActivity;
import com.yoho.coupon.dal.model.OrderShareCoupon;
import com.yoho.coupon.dal.model.UserCouponHistory;
import com.yoho.coupon.dal.model.UserShareHistory;
import com.yoho.coupon.dal.model.UserShareHistoryRequest;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.activity.drawline.response.DrawOrderShareCouponRespBO;
import com.yoho.service.model.promotion.CouponForm;
import com.yoho.service.model.request.ProfileRequestBO;
import com.yoho.service.model.request.RegisterReqBO;
import com.yoho.service.model.response.ProfileInfoRsp;
import com.yoho.service.model.response.RegisterRspBO;
@Service
public class OrderShareActivityServiceImpl implements IOrderShareActivityService {
... ... @@ -44,13 +46,13 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
static Logger log = LoggerFactory.getLogger(OrderShareActivityServiceImpl.class);
@Resource
private IOrderShareActivityDAO orderShareActivityDAO;
@Resource
private IUserShareHistoryDAO userShareHistoryDAO;
@Resource
private IUserCouponHistoryDAO userCouponHistoryDAO;
@Resource
ICouponActivityService couponActivityService;
... ... @@ -63,10 +65,16 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
// 老用户领券限制
@Value("${orderShare.recevied.maxNum}")
private int orderShareOldUserLimit;
@Value("${orderShare.shareUrl}")
private String shareUrl;
@Resource
IOrderShareCouponDAO orderShareCouponDAO;
@Resource
SendSMSHelper sendSMSHelper;
@Override
public OrderShareActivityBO getActivityInfoById() {
OrderShareActivity db = orderShareActivityDAO.selectOne();
... ... @@ -79,13 +87,13 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
@Override
public OrderShareBO getShareInfo(String ordercode, int uid) {
log.info("getShareInfo params is ordercode={},uid={}",ordercode,uid);
log.info("getShareInfo params is ordercode={},uid={}", ordercode, uid);
// 1、查询此活动
OrderShareBO bo = new OrderShareBO();
OrderShareActivity activitydb = orderShareActivityDAO.selectOne();
if (activitydb == null) {
// 活动不存在
log.warn("there is not activity,params is ordercode={},uid={},flag=2",ordercode,uid);
log.warn("there is not activity,params is ordercode={},uid={},flag=2", ordercode, uid);
bo.setFlag(2);
return bo;
}
... ... @@ -94,13 +102,13 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
int nowtime = DateUtils.getCurrentTimeSecond();
if (activitydb.getEndTime() < nowtime) {
// 活动已结束
log.warn("activity is over ,params is ordercode={},uid={},flag=3",ordercode,uid);
log.warn("activity is over ,params is ordercode={},uid={},flag=3", ordercode, uid);
bo.setFlag(3);
return bo;
}
if (activitydb.getBeginTime() > nowtime) {
// 活动未开始
log.warn("activity could not started ,params is ordercode={},uid={},flag=4",ordercode,uid);
log.warn("activity could not started ,params is ordercode={},uid={},flag=4", ordercode, uid);
bo.setFlag(4);
return bo;
}
... ... @@ -147,32 +155,32 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
newrecord.setNewUserNum(0);
newrecord.setOldUserNum(0);
userShareHistoryDAO.insert(newrecord);
log.info("getShareInfo,insert userShareHistory,params is {}",newrecord);
log.info("getShareInfo,insert userShareHistory,params is {}", newrecord);
} else {
// 已达到分享最大数
log.warn("share has been finished ,params is ordercode={},uid={},flag=5",ordercode,uid);
log.warn("share has been finished ,params is ordercode={},uid={},flag=5", ordercode, uid);
bo.setFlag(5);
return bo;
}
}
bo = OrderShareActivityConvert.db2boResponse(activitydb);
bo.setFlag(1);
bo.setShareUrl(shareUrl+"?ordercode="+ordercode+"&uid="+uid);
log.info("getShareInfo result is {}",bo);
bo.setShareUrl(shareUrl + "?ordercode=" + ordercode + "&uid=" + uid);
log.info("getShareInfo result is {}", bo);
return bo;
}
/**
* 记录领券接口
*
* @param activityId
* @param uid
* @param orderCode
* @param couponId
* @param userType
*/
private void addCouponHistory(int activityId, int uid, String orderCode,String couponId, int userType){
log.info("start addCouponHistory with activityId is {}, uid is {}, orderCode is {}, couponId is {}, userType is {}",activityId,uid,orderCode,couponId, userType);
* @param userType
*/
private void addCouponHistory(int activityId, int uid, String orderCode, String couponId, int userType) {
log.info("start addCouponHistory with activityId is {}, uid is {}, orderCode is {}, couponId is {}, userType is {}", activityId, uid, orderCode, couponId, userType);
UserCouponHistory couponHistory = new UserCouponHistory();
couponHistory.setActivityId(activityId);
couponHistory.setCouponId(couponId);
... ... @@ -185,28 +193,30 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
/**
* 更新用户领取记录
*
* @param id
* @param userType
*/
private void updateShareHistory(int id, int userType){
log.info("start with updateShareHistory. id is {}, userType is {}",id , userType);
*/
private void updateShareHistory(int id, int userType) {
log.info("start with updateShareHistory. id is {}, userType is {}", id, userType);
userShareHistoryDAO.updateShareHistoryNum(id, userType);
log.info("end with updateShareHistory.");
}
/**
* 发送优惠券
* 发送优惠券
*
* @param couponId
* @param uid
*/
private String sendCoupon(String couponId, String uid){
log.info("start with sendCoupon. couponId is {}, uid is {}",couponId , uid);
*/
private String sendCoupon(String couponId, String uid) {
log.info("start with sendCoupon. couponId is {}, uid is {}", couponId, uid);
CouponForm form = new CouponForm();
form.setCouponId(couponId);
form.setUid(uid);
String couponCode = "";
try {
couponCode = serviceCaller.call("promotion.sendCoupon",form,String.class);
couponCode = serviceCaller.call("promotion.sendCoupon", form, String.class);
} catch (Exception e) {
log.error("sendCoupon failed, ex: {}", e.getMessage());
}
... ... @@ -214,78 +224,77 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
return couponCode;
}
@Override
public DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile, long orderCode) {
DrawOrderShareCouponRespBO respBO = new DrawOrderShareCouponRespBO(mobile, orderCode);
//1、简单验证手机号
if(!validMobile(mobile)) {
// 1、简单验证手机号
if (!validMobile(mobile)) {
respBO.setReturnCode(Constant.ORDER_SHARE_MOBILE_ERROR);
respBO.setReturnMsg("手机号错误,请重新输入");
log.warn("mobile is invalid: {}", mobile);
return respBO;
}
//2、检查活动是否结束
// 2、检查活动是否结束
OrderShareActivityBO activityInfo = getActivityInfoById();
if(activityInfo == null || isAcitvityExpire(activityInfo)) {
if (activityInfo == null || isAcitvityExpire(activityInfo)) {
respBO.setReturnCode(Constant.ORDER_SHARE_ACTIVITY_EXPIRE);
respBO.setReturnMsg("活动已经过期");
log.warn("the acitivity is out of date, mobile: {}, activity: {}", mobile, activityInfo.getId());
return respBO;
}
//3、检查手机号是否注册过
}
// 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: {}, sendSms for register", mobile);
return respBO;
}
//4、判断老用户是否达到分享限制
if(isUpToOrderShareLimit(orderCode, activityInfo.getId())) {
// 4、判断老用户是否达到分享限制
if (isUpToOrderShareLimit(orderCode, activityInfo.getId())) {
respBO.setReturnCode(Constant.ORDER_SHARE_OLDUSER_UPLIMIT);
respBO.setReturnMsg("优惠券已抢光");
log.warn("orderShare for Register user is over, orderCode: {}, activityId: {}", orderCode, activityInfo.getId());
return respBO;
}
// 发送优惠券
String couponCode = sendCoupon(activityInfo.getRegistCouponId(), String.valueOf(profileInfo.getUid()));
if(StringUtils.isEmpty(couponCode))
{
// 获取老人优惠券
OrderShareCoupon coupon = orderShareCouponDAO.selectCouponByDateAndType(DateUtils.getToday("yyyy-MM-dd"), 1);
String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(profileInfo.getUid()));
if (StringUtils.isEmpty(couponCode)) {
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
respBO.setReturnMsg("优惠券已发光");
log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", activityInfo.getUnregistCouponId(), profileInfo.getUid());
log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", profileInfo.getUid(), coupon.getCouponId());
return respBO;
}
//4、记录用户领券的记录
// 4、记录用户领券的记录
respBO.setCoupon(couponCode);
updateOrderShareRecord(activityInfo.getId(), profileInfo.getUid(), orderCode, activityInfo.getRegistCouponId(), 1);
updateOrderShareRecord(activityInfo.getId(), profileInfo.getUid(), orderCode, coupon.getCouponId(), 1);
return respBO;
}
@Override
public DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile,
long orderCode, String identifyCode) {
public DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile, long orderCode, String identifyCode) {
DrawOrderShareCouponRespBO respBO = new DrawOrderShareCouponRespBO(mobile, orderCode);
//1、检查活动是否结束
// 1、检查活动是否结束
OrderShareActivityBO activityInfo = getActivityInfoById();
if(activityInfo == null) {
if (activityInfo == null || isAcitvityExpire(activityInfo)) {
respBO.setReturnCode(Constant.ORDER_SHARE_ACTIVITY_EXPIRE);
respBO.setReturnMsg("活动已经过期");
log.warn("the acitivity not exists, activity: {}", activityInfo.getId());
return respBO;
}
}
// 1、验证验证码
ApiResponse identityResp = couponActivityService.validRegCode(identifyCode, "86", mobile);
if (Constant.CODE_SUCCESS != identityResp.getCode()) {
... ... @@ -294,97 +303,111 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
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()) {
RegisterReqBO registerReqBO = new RegisterReqBO();
registerReqBO.setArea("86");
registerReqBO.setProfile(mobile);
registerReqBO.setPassword(RandomUtil.getCharAndNumr(6, 2));
registerReqBO.setClient_type("h5");
RegisterRspBO model = null;
try {
model = serviceCaller.call("users.register", registerReqBO, RegisterRspBO.class);
log.info("call register result is {}", model);
} catch (Exception e) {
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、发送优惠券
String couponCode = sendCoupon(activityInfo.getUnregistCouponId(), String.valueOf(uid));
if(StringUtils.isEmpty(couponCode))
{
// 3、发送优惠券
// 获取新人优惠券
OrderShareCoupon coupon = orderShareCouponDAO.selectCouponByDateAndType(null, 0);
String couponCode = sendCoupon(coupon.getCouponId(), String.valueOf(model.getUid()));
if (StringUtils.isEmpty(couponCode)) {
respBO.setReturnCode(Constant.ORDER_SHARE_SENDCOUPON_ERROR);
respBO.setReturnMsg("优惠券已发光");
log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", activityInfo.getUnregistCouponId(), uid);
log.error("orderShare sendCoupon failed, uid: {}, couponId: {}", coupon.getCouponId(), model.getUid());
return respBO;
}
//4、记录用户领券的记录
// 4、记录用户领券的记录
respBO.setCoupon(couponCode);
updateOrderShareRecord(activityInfo.getId(), uid, orderCode, activityInfo.getUnregistCouponId(), 0);
updateOrderShareRecord(activityInfo.getId(), model.getUid(), orderCode, coupon.getCouponId(), 0);
//发送短信
sendSMSHelper.sendNoticeSms(mobile, "【Yoho!Buy有货】恭喜您获得一张"+ coupon.getCouponName() +",您的登录账户是"+ mobile +",密码是"+ registerReqBO.getPassword() +";下载Yoho!Buy有货手机端http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho,更多惊喜等着您!");
return respBO;
}
/**
* 简单验证是否是11位手机号
*
* @param mobile
* @return
*/
private boolean validMobile(String mobile) {
if(mobile == null)
if (mobile == null)
return false;
if(mobile.length() != 11)
if (mobile.length() != 11)
return false;
return StringUtils.isNumeric(mobile);
}
/**
* 根据手机号查注册用户
*
* @param mobile
* @return
*/
private ProfileInfoRsp getRegisterUser(String mobile) {
log.info("query register user by mobile: {}", mobile);
ProfileRequestBO reqBO = new ProfileRequestBO();
reqBO.setMobile(mobile);
reqBO.setArea("86");
reqBO.setCheckSSO(true);
ProfileInfoRsp respBO = serviceCaller.call("users.getUserprofileByEmailOrMobile", reqBO, ProfileInfoRsp.class);
log.info("user with mobile {} is: {}", mobile, respBO);
return respBO;
}
/**
* 查询活动信息
*
* @param activityId
* @return
*/
private OrderShareActivity getActvivity(int activityId) {
log.info("query order share acitvity, activityId: {}", activityId);
//....补充缓存操作
//......
// ....补充缓存操作
// ......
OrderShareActivity activityInfo = orderShareActivityDAO.selectByPrimaryKey(activityId);
return activityInfo;
}
}
/**
* 判断活动是否过期
*
* @param activityInfo
* @return
*/
private boolean isAcitvityExpire(OrderShareActivityBO activityInfo) {
if(activityInfo == null) {
if (activityInfo == null) {
return true;
}
return activityInfo.getEndTime() * 1000L < (new Date().getTime());
}
/**
* 根据订单号和活动ID获取分享历史
*
* @param orderCode
* @param activityId
* @return
... ... @@ -393,35 +416,36 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
UserShareHistory shareHistoryInfo = userShareHistoryDAO.selectByOrderAndActivity(String.valueOf(orderCode), activityId);
return shareHistoryInfo;
}
/**
* 检查老用户是否超出分享次数限制(默认限制5次)
* 检查老用户是否超出领取优惠券限制(默认限制5次)
*
* @param shareHistoryInfo
* @param userType
* @return
*/
private boolean isUpToOrderShareLimit(long orderCode, int activityId) {
UserShareHistory shareHistoryInfo = getShareHistoryByOrderAndActivity(orderCode, activityId);
if(shareHistoryInfo == null) {
if (shareHistoryInfo == null) {
log.error("None order share, orderCode: {}, activityId: {}", orderCode, activityId);
return true;
}
if(shareHistoryInfo.getOldUserNum() >= orderShareOldUserLimit) {
if (shareHistoryInfo.getOldUserNum() >= orderShareOldUserLimit) {
log.warn("Up to limit of orderShare for Register user");
return true;
}
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) {
if (shareHistoryInfo == null) {
log.error("None order share, orderCode: {}, activityId: {}", orderCode, activityId);
return;
}
}
updateShareHistory(shareHistoryInfo.getId(), userType);
}
}
... ...