Authored by wangshusheng

砍价逻辑校验

... ... @@ -146,7 +146,20 @@ public final class DateUtils {
today.set(Calendar.MILLISECOND, 0);
return (int)(today.getTime().getTime() / 1000);
}
/**
* 获取当天零点时间
* @return
*/
public static int getTodayEnd() {
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, 23);
today.set(Calendar.MINUTE, 59);
today.set(Calendar.SECOND, 59);
today.set(Calendar.MILLISECOND, 999);
return (int)(today.getTime().getTime() / 1000);
}
public static void main(String[] args) {
System.out.println(getTodayZero());
}
... ...
... ... @@ -13,7 +13,10 @@ public interface CutDownPriceUserHelpMapper {
List<CutDownPriceProductHelpUser> selectHelpInfoByUidAndCode(@Param("list") List<Integer> uidList, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
Integer selectExistHelpInfo(@Param("userId") Integer userId, @Param("helpUserId") Integer helpUserId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
Integer selectExistHelpInfo(@Param("helpUserId") Integer helpUserId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
List<CutDownPriceProductHelpUser> selectHelpInfoList(@Param("list") List<CutPriceHelpUserRequestBO> requestList);
List<CutDownPriceProductHelpUser> selectHelpInfoListCurrentDay(@Param("helpUserId") Integer helpUserId, @Param("startTime") Integer startTime, @Param("endTime") Integer endTime);
}
... ...
... ... @@ -16,6 +16,8 @@ public interface CutDownPriceUserRecordMapper {
CutDownPriceUserRecord selectCutDownPriceUserRecord(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
List<CutDownPriceUserRecord> selectCutDownPriceUserRecordList(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
int updateCutDownHelpCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
int updateDecreaseUseCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
... ...
... ... @@ -32,8 +32,7 @@
<select id="selectExistHelpInfo" resultType="java.lang.Integer">
select count(1) FROM cutdown_price_help_user
where user_id = #{userId,jdbcType=INTEGER}
AND help_user_id = #{helpUserId,jdbcType=INTEGER}
where help_user_id = #{helpUserId,jdbcType=INTEGER}
AND activity_id = #{activityId,jdbcType=INTEGER}
AND product_skn = #{productSkn,jdbcType=INTEGER}
</select>
... ... @@ -48,4 +47,14 @@
</foreach>
</select>
<select id="selectHelpInfoListCurrentDay" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from cutdown_price_help_user
where
help_user_id = #{helpUserId,jdbcType=INTEGER}
and create_time &gt;= #{startTime,jdbcType=INTEGER}
and create_time &lt;= #{endTime,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -45,6 +45,18 @@
where activity_id = #{activityId,jdbcType=INTEGER}
and user_id = #{userId,jdbcType=INTEGER}
and product_skn = #{productSkn,jdbcType=INTEGER}
order by create_time DESC
limit 1
</select>
<select id="selectCutDownPriceUserRecordList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from cutdown_price_user_record
where activity_id = #{activityId,jdbcType=INTEGER}
and user_id = #{userId,jdbcType=INTEGER}
and product_skn = #{productSkn,jdbcType=INTEGER}
order by create_time DESC
</select>
<update id="updateCutDownHelpCount" >
... ...
... ... @@ -51,7 +51,7 @@ public class CutDownProductPriceRest {
}
/**
* 用户发起砍价,系统自动砍价
* 用户发起砍价,系统自动砍价(首次发起或者之前失败后发起)
*/
@RequestMapping("/addCutPriceRecord")
@ResponseBody
... ...
... ... @@ -16,7 +16,6 @@ import com.yoho.activity.queue.service.ICutDownPriceService;
import com.yoho.activity.queue.service.IDrawlineList2MapService;
import com.yoho.activity.queue.wrapper.CutDownPriceProductHelpUserWrapper;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.core.rest.client.hystrix.AsyncFuture;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.product.model.ProductBo;
... ... @@ -24,7 +23,6 @@ import com.yoho.product.request.BatchBaseRequest;
import com.yoho.product.response.PageResponseBo;
import com.yoho.service.model.activity.*;
import com.yoho.service.model.activity.drawline.request.CutPriceHelpUserRequestBO;
import com.yoho.service.model.activity.drawline.response.UserBaseRspBO;
import com.yoho.service.model.social.request.UicUserReqBO;
import com.yoho.service.model.social.response.UserInfoRspBO;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -46,6 +44,7 @@ import java.util.stream.Collectors;
public class CutDownPriceServiceImpl implements ICutDownPriceService {
private static Logger logger = LoggerFactory.getLogger(CutDownPriceServiceImpl.class);
private static final Integer SYSTEM_HELP_ID = 0;
private static final Integer MAX_HELP_COUNT = 3;
private static final String SYSTEM_HELP_NAME = "有货";
private static final String SYSTEM_HELP_IMAGE = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKic2dZ7ib6p1PJJXFpYl95ibRyvSKCib3icUiaStlRN6PWmcRZjzPn4w4moEk2xhUxpYbibuPtBNPJBMeqQ/132";
@Autowired
... ... @@ -267,8 +266,19 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
Integer userId = cutPriceHelpUserRequestBO.getUserId();
Integer helpUserId = cutPriceHelpUserRequestBO.getHelpUserId();
//判断用户是否已经帮助砍价
Integer count = cutPriceUserHelpMapper.selectExistHelpInfo(userId, helpUserId, activityId, productSkn);
// 每位用户每天最多可以帮好友砍3次价
if(!SYSTEM_HELP_ID.equals(helpUserId)){
int startTime = DateUtils.getTodayZero();
int endTime = DateUtils.getTodayEnd();
List<CutDownPriceProductHelpUser> existHelpUsers = cutPriceUserHelpMapper.selectHelpInfoListCurrentDay(helpUserId, startTime, endTime);
if(CollectionUtils.isNotEmpty(existHelpUsers) && existHelpUsers.size() >= MAX_HELP_COUNT){
logger.warn(" you have help exceed max times, activityId is {}, productSkn is {}, helpUserId is {}, max help time is {}", activityId, productSkn, helpUserId, MAX_HELP_COUNT);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAVE_EXCEED_MAX_CUTDOWNNUM_ERROR);
}
}
//判断用户是否已经针对该skn帮助砍价
Integer count = cutPriceUserHelpMapper.selectExistHelpInfo(helpUserId, activityId, productSkn);
if (count>0){
logger.warn(" you have help only one time, activityId is {}, productSkn is {}, helpUserId is {}", activityId, productSkn, helpUserId);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_HELPED_ERROR);
... ... @@ -323,9 +333,9 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
logger.warn(" the cutdown product not exist, activityId is {}, productSkn is {}", activityId, productSkn);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PRODUCT_NOTEXIST_ERROR);
}
// 查询该用户是否已经发起过
// 查询该用户是否已经发起过(之前发起过,没砍价成功,发起时间超过24小时)
CutDownPriceUserRecord recordDb = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
if(recordDb!=null){
if(recordDb!=null && (recordDb.getHelpCount()>=cutDownPriceProductBo.getJoinNum() || (DateUtils.getCurrentTimeSecond() - recordDb.getCreateTime() < 24*3600))){
logger.warn(" the cutdown record has exist, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_CREATE_CUTDOWN_ERROR);
}
... ...