Authored by ping

update

... ... @@ -77,7 +77,7 @@ public class OrderShareController {
@ResponseBody
public ApiResponse drawOrderShareCoupon(String mobile, String ordercode) {
logger.info("drawOrderShareCoupon enter, mobile: {}, orderCode: {}", mobile, ordercode);
DrawOrderShareCouponRespBO respBO = orderShareActivityService.drawOrderShareCoupon(mobile, getOrderCode(ordercode));
DrawOrderShareCouponRespBO respBO = orderShareActivityService.drawOrderShareCoupon(mobile, ordercode);
return new ApiResponse.ApiResponseBuilder().code(200).data(respBO).message("ok").build();
}
... ... @@ -95,26 +95,7 @@ public class OrderShareController {
public ApiResponse registerAndSendCoupon(String mobile, String ordercode, String identifycode) {
logger.info("registerAndSendCoupon enter, mobile: {}, orderCode: {}, identifyCode : {}", mobile, ordercode, identifycode);
DrawOrderShareCouponRespBO respBO = orderShareActivityService.registerAndSendCoupon(mobile, getOrderCode(ordercode), identifycode);
DrawOrderShareCouponRespBO respBO = orderShareActivityService.registerAndSendCoupon(mobile, ordercode, identifycode);
return new ApiResponse.ApiResponseBuilder().code(200).data(respBO).message("ok").build();
}
/**
* 将字符串类型订单号转化为Long类型
*
* @param orderCodeStr
* @return
*/
private long getOrderCode(String orderCodeStr) {
long orderCode = 0;
try {
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);
}
return orderCode;
}
}
... ...
... ... @@ -32,4 +32,13 @@ public interface IUserCouponHistoryDAO {
* @return
*/
int selectCountAfter(@Param("uid") int uid, @Param("activityId") int activityId, @Param("createTime") int createTime);
/**
* 查询该活动的,这个订单下的老用户领券次数
* @param activityId
* @param uid
* @param orderCode
* @return
*/
int selectOldUserCouponNum(@Param("activityId") int activityId, @Param("uid") int uid, @Param("orderCode") String orderCode);
}
\ No newline at end of file
... ...
... ... @@ -25,8 +25,12 @@
from user_coupon_history
where uid = #{uid,jdbcType=INTEGER}
and activity_id = #{activityId,jdbcType=INTEGER}
and create_time > #{createTime,jdbcType=INTEGER} and user_type=1
and create_time &gt; #{createTime,jdbcType=INTEGER} and user_type=1
</select>
<select id="selectOldUserCouponNum" resultType="java.lang.Integer">
select count(1) from user_coupon_history where activity_id=#{activityId} and uid=#{uid} and order_code=#{orderCode} and user_type=1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from user_coupon_history
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -28,8 +28,8 @@ public interface IOrderShareActivityService {
* @param orderCode
* @return
*/
DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile, long orderCode);
DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile, String orderCode);
DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile, long orderCode, String identifyCode);
DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile, String orderCode, String identifyCode);
}
... ...
... ... @@ -232,18 +232,6 @@ 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);
userShareHistoryDAO.updateShareHistoryNum(id, userType);
log.info("end with updateShareHistory.");
}
/**
* 发送优惠券
*
* @param couponId
... ... @@ -265,7 +253,7 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
}
@Override
public DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile, long orderCode) {
public DrawOrderShareCouponRespBO drawOrderShareCoupon(String mobile, String orderCode) {
log.info("drawOrderShareCoupon with mobile={}, orderCode={}", mobile, orderCode);
DrawOrderShareCouponRespBO respBO = new DrawOrderShareCouponRespBO(mobile, orderCode);
// 1、简单验证手机号
... ... @@ -305,7 +293,7 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
}
// 4、判断老用户是否达到分享限制
if (isUpToOrderShareLimit(orderCode, activityInfo.getId())) {
if (isUpToOrderShareLimit(orderCode, activityInfo.getId(), profileInfo.getUid())) {
respBO.setReturnCode(Constant.ORDER_SHARE_OLDUSER_UPLIMIT);
respBO.setReturnMsg("优惠券已抢光");
log.warn("orderShare for Register user is over, orderCode: {}, activityId: {}", orderCode, activityInfo.getId());
... ... @@ -331,7 +319,7 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
}
@Override
public DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile, long orderCode, String identifyCode) {
public DrawOrderShareCouponRespBO registerAndSendCoupon(String mobile, String orderCode, String identifyCode) {
DrawOrderShareCouponRespBO respBO = new DrawOrderShareCouponRespBO(mobile, orderCode);
// 1、检查活动是否结束
... ... @@ -446,10 +434,10 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
* @param activityId
* @return
*/
private UserShareHistory getShareHistoryByOrderAndActivity(long orderCode, int activityId) {
UserShareHistory shareHistoryInfo = userShareHistoryDAO.selectByOrderAndActivity(String.valueOf(orderCode), activityId);
return shareHistoryInfo;
}
// private UserShareHistory getShareHistoryByOrderAndActivity(long orderCode, int activityId) {
// UserShareHistory shareHistoryInfo = userShareHistoryDAO.selectByOrderAndActivity(String.valueOf(orderCode), activityId);
// return shareHistoryInfo;
// }
/**
* 检查老用户当天是否已经领取过用户券
... ... @@ -475,14 +463,11 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
* @param userType
* @return
*/
private boolean isUpToOrderShareLimit(long orderCode, int activityId) {
UserShareHistory shareHistoryInfo = getShareHistoryByOrderAndActivity(orderCode, activityId);
if (shareHistoryInfo == null) {
log.error("None order share, orderCode: {}, activityId: {}", orderCode, activityId);
return true;
}
private boolean isUpToOrderShareLimit(String orderCode, int activityId, int uid) {
log.info("isUpToOrderShareLimit with orderCode={}, activityId={}", orderCode, activityId);
int oldNum = userCouponHistoryDAO.selectOldUserCouponNum(activityId, uid, orderCode);
if (shareHistoryInfo.getOldUserNum() >= orderShareOldUserLimit) {
if (oldNum >= orderShareOldUserLimit) {
log.warn("Up to limit of orderShare for Register user");
return true;
}
... ... @@ -498,17 +483,17 @@ public class OrderShareActivityServiceImpl implements IOrderShareActivityService
* @param couponId
* @param userType
*/
private void updateOrderShareRecord(int activityId, int uid, long orderCode, String couponId, int userType) {
private void updateOrderShareRecord(int activityId, int uid, String orderCode, String couponId, int userType) {
log.info("updateOrderShareRecord with activityId={}, uid={}, orderCode={}, couponId={}, userType={}", activityId, uid, orderCode, couponId, userType);
addCouponHistory(activityId, uid, String.valueOf(orderCode), couponId, userType);
log.info("updateOrderShareRecord addCouponHistory success with activityId={}, uid={}, orderCode={}, couponId={}, userType={}", activityId, uid, orderCode, couponId, userType);
UserShareHistory shareHistoryInfo = getShareHistoryByOrderAndActivity(orderCode, activityId);
log.info("updateOrderShareRecord getShareHistoryByOrderAndActivity success with activityId={}, uid={}, orderCode={}, couponId={}, userType={}, shareHistoryInfo={}", activityId, uid, orderCode, couponId, userType, shareHistoryInfo);
if (shareHistoryInfo == null) {
log.error("None order share, orderCode: {}, activityId: {}", orderCode, activityId);
return;
}
updateShareHistory(shareHistoryInfo.getId(), userType);
// UserShareHistory shareHistoryInfo = getShareHistoryByOrderAndActivity(orderCode, activityId);
// log.info("updateOrderShareRecord getShareHistoryByOrderAndActivity success with activityId={}, uid={}, orderCode={}, couponId={}, userType={}, shareHistoryInfo={}", activityId, uid, orderCode, couponId, userType, shareHistoryInfo);
// if (shareHistoryInfo == null) {
// log.error("None order share, orderCode: {}, activityId: {}", orderCode, activityId);
// return;
// }
// updateShareHistory(shareHistoryInfo.getId(), userType);
}
/**
... ...