Authored by wangshusheng

砍价状态

... ... @@ -50,6 +50,7 @@ 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 Integer TIME_24_HOUR = 24*3600;
private static final String SYSTEM_HELP_NAME = "有货";
private static final String SYSTEM_HELP_IMAGE = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKic2dZ7ib6p1PJJXFpYl95ibRyvSKCib3icUiaStlRN6PWmcRZjzPn4w4moEk2xhUxpYbibuPtBNPJBMeqQ/132";
... ... @@ -195,7 +196,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HASNOT_CUTDOWN_SUCCESS_ERROR);
}
// 用户发起砍价成功后,24小时未付款,则取消
if(record.getCutTime()+24*3600 < DateUtils.getCurrentTimeSecond()){
if(record.getCutTime()+TIME_24_HOUR < DateUtils.getCurrentTimeSecond()){
logger.warn(" you create cutprice has expired, activityId is {}, productSkn is {}", activityId, productSkn);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_CREATE_HAS_EXPIRED_ERROR);
}
... ... @@ -226,8 +227,8 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
PageResponseBo<CutDownPriceActivityProductBo> cacheResult = getFromRedis(CacheKeyEnum.CUTDOWN_PRICE_MYPRODUCTLIST_INFO, uid,
PageResponseBo.class, String.valueOf(request.getPage()), String.valueOf(request.getSize()));
if (cacheResult != null) {
// 赋值当前时间
buildCurrentTime(cacheResult);
// 处理砍价状态,赋值当前时间
buildCutStatusAndCurrentTime(cacheResult);
return cacheResult;
}
// 查询我的砍价列表
... ... @@ -378,7 +379,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
}
// 查询该用户是否已经发起过(之前发起过,没砍价成功,发起时间超过24小时)
CutDownPriceUserRecord recordDb = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
if(recordDb!=null && (recordDb.getHelpCount()>=cutDownPriceProductBo.getJoinNum()+1 || (DateUtils.getCurrentTimeSecond() - recordDb.getCreateTime() < 24*3600))){
if(recordDb!=null && (recordDb.getHelpCount()>=cutDownPriceProductBo.getJoinNum()+1 || (DateUtils.getCurrentTimeSecond() - recordDb.getCreateTime() < TIME_24_HOUR))){
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);
}
... ... @@ -577,22 +578,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
cutDownPriceActivityProductBo.setCreateTime(record.getCreateTime());
cutDownPriceActivityProductBo.setCutTime(record.getCutTime());
if(DateUtils.getCurrentTimeSecond()>activityBo.getEndTime()){
// 活动已结束
cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_END);
}else{
// 活动进行中
if(helpUserBos.size()>cutDownPriceProductBo.getJoinNum()){
// 砍价已成功
cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_SUCCESS);
}else if(DateUtils.getCurrentTimeSecond()-record.getCreateTime()>24*3600){
// 未成功,发起已超过24小时,已失效
cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_EXPIRE);
}else{
// 未成功,发起24小时内,砍价中
cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_ONGOING);
}
}
buildCutStatus(cutDownPriceActivityProductBo);
list.add(cutDownPriceActivityProductBo);
}
return list;
... ... @@ -622,11 +608,34 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
return cutDownPriceProductBo;
}
private void buildCurrentTime(PageResponseBo<CutDownPriceActivityProductBo> cacheResult) {
private void buildCutStatusAndCurrentTime(PageResponseBo<CutDownPriceActivityProductBo> cacheResult) {
List<CutDownPriceActivityProductBo> productList = cacheResult.getList();
if (CollectionUtils.isNotEmpty(productList)) {
for (CutDownPriceActivityProductBo bo : productList) {
bo.setCurrentTime(DateUtils.getCurrentTimeSecond());
if (CollectionUtils.isEmpty(productList)) {
return;
}
for (CutDownPriceActivityProductBo bo : productList) {
buildCutStatus(bo);
}
}
// 设置砍价当前状态
private void buildCutStatus(CutDownPriceActivityProductBo bo) {
int currentTime = DateUtils.getCurrentTimeSecond();
bo.setCurrentTime(currentTime);
if(currentTime>bo.getEndTime()){
// 活动已结束
bo.setCutStatus(CutPriceConstant.CUT_STATUS_END);
}else{
// 活动进行中
if(bo.getHasJoinNum() > bo.getJoinNum()){
// 砍价已成功
bo.setCutStatus(CutPriceConstant.CUT_STATUS_SUCCESS);
}else if(currentTime - bo.getCreateTime()>TIME_24_HOUR){
// 未成功,发起已超过24小时,已失效
bo.setCutStatus(CutPriceConstant.CUT_STATUS_EXPIRE);
}else{
// 未成功,发起24小时内,砍价中
bo.setCutStatus(CutPriceConstant.CUT_STATUS_ONGOING);
}
}
}
... ...