砍价字段修改,补充逻辑
This commit is contained in:
parent
cfb8714410
commit
415bbfd4ba
@ -136,4 +136,11 @@ public class CommonConstant {
|
|||||||
public final static Integer Store_Biz_State_Closed = 2;
|
public final static Integer Store_Biz_State_Closed = 2;
|
||||||
//3-开业(活动)筹备中;
|
//3-开业(活动)筹备中;
|
||||||
public final static Integer Store_Biz_State_PreActivity = 3;
|
public final static Integer Store_Biz_State_PreActivity = 3;
|
||||||
|
|
||||||
|
//用户砍价订单状态:1-砍价已完成下单;2-砍价未下单已取消;3-砍价助力进行中;4-砍价过期失效;6-砍价助力已完成待下单;
|
||||||
|
public static final Integer CutPrice_Order_State_Finished = 1;
|
||||||
|
public static final Integer CutPrice_Order_State_Canceled = 2;
|
||||||
|
public static final Integer CutPrice_Order_State_ING = 3;
|
||||||
|
public static final Integer CutPrice_Order_State_Expired = 4;
|
||||||
|
public static final Integer CutPrice_Order_State_CutFinished = 6;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,6 +59,9 @@ public class ShopActivityCutprice implements Serializable {
|
|||||||
@ApiModelProperty(value = "砍价过期时间戳")
|
@ApiModelProperty(value = "砍价过期时间戳")
|
||||||
private Long expired_at;
|
private Long expired_at;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户砍价订单状态:1-砍价已完成下单;2-砍价未下单已取消;3-砍价助力进行中;4-砍价过期失效;6-砍价助力已完成待下单;")
|
||||||
|
private Integer state;
|
||||||
|
|
||||||
@Version
|
@Version
|
||||||
@ApiModelProperty(value = "乐观锁")
|
@ApiModelProperty(value = "乐观锁")
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|||||||
@ -112,7 +112,7 @@ public class UserActivityController extends BaseControllerImpl {
|
|||||||
return CommonResult.success(shopActivityCutpriceHistoryService.listsUserCutPriceHistory(page, rows, is_sponsor));
|
return CommonResult.success(shopActivityCutpriceHistoryService.listsUserCutPriceHistory(page, rows, is_sponsor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "砍价活动详情", notes = "砍价活动详情")
|
@ApiOperation(value = "砍价活动详情", notes = "砍价活动详情(注:除了获取活动详情信息,还创建砍价订单记录和查询砍价历史历史)")
|
||||||
@RequestMapping(value = "/getCutPriceActivity", method = RequestMethod.GET)
|
@RequestMapping(value = "/getCutPriceActivity", method = RequestMethod.GET)
|
||||||
public CommonResult getCutPriceActivityDetail() {
|
public CommonResult getCutPriceActivityDetail() {
|
||||||
return CommonResult.success(shopActivityCutpriceService.getCutPriceActivity());
|
return CommonResult.success(shopActivityCutpriceService.getCutPriceActivity());
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.suisung.mall.shop.activity.service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.suisung.mall.common.api.CommonResult;
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
import com.suisung.mall.common.modules.activity.ShopActivityCutprice;
|
import com.suisung.mall.common.modules.activity.ShopActivityCutprice;
|
||||||
|
import com.suisung.mall.common.modules.store.ShopStoreActivityBase;
|
||||||
import com.suisung.mall.core.web.service.IBaseService;
|
import com.suisung.mall.core.web.service.IBaseService;
|
||||||
import org.springframework.data.util.Pair;
|
import org.springframework.data.util.Pair;
|
||||||
|
|
||||||
@ -38,4 +39,14 @@ public interface ShopActivityCutpriceService extends IBaseService<ShopActivityCu
|
|||||||
*/
|
*/
|
||||||
Pair<Boolean, String> canDoOrderCutPriceActivity(Integer ac_id, Integer order_user_id);
|
Pair<Boolean, String> canDoOrderCutPriceActivity(Integer ac_id, Integer order_user_id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查砍价活动是否过期和库存是否足够
|
||||||
|
*
|
||||||
|
* @param shopStoreActivityBase 砍价活动基础信息
|
||||||
|
* @return Pair<Boolean, String> 检查结果,Boolean表示是否通过检查,String表示错误信息
|
||||||
|
*/
|
||||||
|
Pair<Boolean, String> checkCutPriceExpiredAndStock(ShopStoreActivityBase shopStoreActivityBase);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -260,7 +260,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 砍价活动详情(注:用户一进来,就参与砍价创建了)
|
* 砍价活动详情(注:除了获取活动详情信息,还创建砍价订单记录和查询砍价历史历史)
|
||||||
*
|
*
|
||||||
* @return 砍价活动详情信息
|
* @return 砍价活动详情信息
|
||||||
*/
|
*/
|
||||||
@ -289,7 +289,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
|
|
||||||
// 获取当前用户信息
|
// 获取当前用户信息
|
||||||
UserDto user = getCurrentUser();
|
UserDto user = getCurrentUser();
|
||||||
if (CheckUtil.isEmpty(participant_id) && user != null) {
|
if (CheckUtil.isEmpty(participant_id) && user != null && user.getId() > 0) {
|
||||||
participant_id = user.getId();
|
participant_id = user.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,8 +298,12 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
queryWrapper.eq("activity_id", activity_id).eq("user_id", user_id);
|
queryWrapper.eq("activity_id", activity_id).eq("user_id", user_id);
|
||||||
ShopActivityCutprice cutprice_row = findOne(queryWrapper);
|
ShopActivityCutprice cutprice_row = findOne(queryWrapper);
|
||||||
|
|
||||||
|
boolean is_join_activity = false;
|
||||||
|
|
||||||
// 如果用户未参与该砍价活动,则创建新的砍价记录
|
// 如果用户未参与该砍价活动,则创建新的砍价记录
|
||||||
if (cutprice_row == null) {
|
// 需要检查活动有效期和活动商品库存是否足够
|
||||||
|
if (cutprice_row == null && shopStoreActivityBaseService.isActivityTimeValid(activityBase, new Date())) {
|
||||||
|
|
||||||
cutprice_row = new ShopActivityCutprice();
|
cutprice_row = new ShopActivityCutprice();
|
||||||
|
|
||||||
// 从活动规则中获取商品原价和砍价底价
|
// 从活动规则中获取商品原价和砍价底价
|
||||||
@ -316,19 +320,30 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
cutprice_row.setUser_id(user_id);
|
cutprice_row.setUser_id(user_id);
|
||||||
cutprice_row.setAc_sale_price(item_unit_price);
|
cutprice_row.setAc_sale_price(item_unit_price);
|
||||||
cutprice_row.setAc_mix_limit_price(cut_down_min_limit_price);
|
cutprice_row.setAc_mix_limit_price(cut_down_min_limit_price);
|
||||||
cutprice_row.setAc_datetime(new Date());
|
Date now = new Date();
|
||||||
|
|
||||||
|
// 该砍价记录过期时间戳
|
||||||
|
Integer cut_hour = activityBase.getCut_hour();
|
||||||
|
if (CheckUtil.isEmpty(cut_hour)) {
|
||||||
|
cut_hour = 48;
|
||||||
|
}
|
||||||
|
cutprice_row.setExpired_at(now.getTime() + cut_hour * 60000L);
|
||||||
|
|
||||||
|
cutprice_row.setAc_datetime(now);
|
||||||
cutprice_row.setOrder_id("");
|
cutprice_row.setOrder_id("");
|
||||||
|
|
||||||
// 保存砍价记录
|
// 保存砍价记录
|
||||||
if (!saveOrUpdate(cutprice_row)) {
|
if (!saveOrUpdate(cutprice_row)) {
|
||||||
throw new ApiException(I18nUtil._("创建砍价失败!"));
|
throw new ApiException(I18nUtil._("创建砍价失败!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_join_activity = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将砍价记录信息合并到活动信息中
|
// 将砍价记录信息合并到活动信息中
|
||||||
activity_row.putAll(Convert.toMap(String.class, Object.class, cutprice_row));
|
activity_row.putAll(Convert.toMap(String.class, Object.class, cutprice_row));
|
||||||
|
|
||||||
// 查询当前用户是否已参与砍价
|
// 查询当前用户是否已参与砍价,查询砍价历史记录
|
||||||
Integer ac_id = cutprice_row.getAc_id();
|
Integer ac_id = cutprice_row.getAc_id();
|
||||||
QueryWrapper<ShopActivityCutpriceHistory> historyQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopActivityCutpriceHistory> historyQueryWrapper = new QueryWrapper<>();
|
||||||
historyQueryWrapper.eq("ac_id", ac_id).eq("user_id", participant_id);
|
historyQueryWrapper.eq("ac_id", ac_id).eq("user_id", participant_id);
|
||||||
@ -336,7 +351,10 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
|
|
||||||
// 设置用户砍价历史信息
|
// 设置用户砍价历史信息
|
||||||
activity_row.put("cut_row", cutpriceHistory);
|
activity_row.put("cut_row", cutpriceHistory);
|
||||||
|
// 是否自己砍价了?
|
||||||
activity_row.put("is_cut", cutpriceHistory != null);
|
activity_row.put("is_cut", cutpriceHistory != null);
|
||||||
|
// 是否参加了砍价活动
|
||||||
|
activity_row.put("is_join_activity", is_join_activity);
|
||||||
|
|
||||||
// 设置活动规则信息
|
// 设置活动规则信息
|
||||||
activity_row.put("activity_rule", JSONUtil.parseObj(activity_row.get("activity_rule")));
|
activity_row.put("activity_rule", JSONUtil.parseObj(activity_row.get("activity_rule")));
|
||||||
@ -507,7 +525,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 检查活动是否在有效期内
|
// 2. 检查活动是否在有效期内
|
||||||
if (!shopStoreActivityBaseService.isActivityTimeValid(storeActivityBase.getActivity_starttime(), storeActivityBase.getActivity_endtime())) {
|
if (!shopStoreActivityBaseService.isActivityTimeValid(storeActivityBase.getActivity_starttime(), storeActivityBase.getActivity_endtime(), new Date())) {
|
||||||
return Pair.of(false, I18nUtil._("该活动已过期,请检查。"));
|
return Pair.of(false, I18nUtil._("该活动已过期,请检查。"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,5 +569,23 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查砍价活动是否过期和库存是否足够
|
||||||
|
*
|
||||||
|
* @param shopStoreActivityBase 砍价活动基础信息
|
||||||
|
* @return Pair<Boolean, String> 检查结果,Boolean表示是否通过检查,String表示错误信息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Pair<Boolean, String> checkCutPriceExpiredAndStock(ShopStoreActivityBase shopStoreActivityBase) {
|
||||||
|
|
||||||
|
boolean isActivityTimeValid = shopStoreActivityBaseService.isActivityTimeValid(shopStoreActivityBase.getActivity_starttime(), shopStoreActivityBase.getActivity_endtime(), new Date());
|
||||||
|
if (!isActivityTimeValid) {
|
||||||
|
return Pair.of(false, I18nUtil._("该活动已过期,下次早点来。"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,14 +60,24 @@ public interface ShopStoreActivityBaseService extends IBaseService<ShopStoreActi
|
|||||||
|
|
||||||
boolean isActivityTimeValid(Map activity_row);
|
boolean isActivityTimeValid(Map activity_row);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证活动时间是否有效
|
||||||
|
*
|
||||||
|
* @param shopStoreActivityBase
|
||||||
|
* @param checkTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean isActivityTimeValid(ShopStoreActivityBase shopStoreActivityBase, Date checkTime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证活动时间是否有效
|
* 验证活动时间是否有效
|
||||||
*
|
*
|
||||||
* @param starTime 活动开始时间
|
* @param starTime 活动开始时间
|
||||||
* @param endTime 活动结束时间
|
* @param endTime 活动结束时间
|
||||||
|
* @param checkTime 待验证时间
|
||||||
* @return 时间是否有效
|
* @return 时间是否有效
|
||||||
*/
|
*/
|
||||||
boolean isActivityTimeValid(Date starTime, Date endTime);
|
boolean isActivityTimeValid(Date starTime, Date endTime, Date checkTime);
|
||||||
|
|
||||||
Map listsMarketing();
|
Map listsMarketing();
|
||||||
|
|
||||||
|
|||||||
@ -2074,21 +2074,45 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
return !now.before(startTime) && !now.after(endTime);
|
return !now.before(startTime) && !now.after(endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证活动时间是否有效
|
||||||
|
*
|
||||||
|
* @param shopStoreActivityBase
|
||||||
|
* @param checkTime
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isActivityTimeValid(ShopStoreActivityBase shopStoreActivityBase, Date checkTime) {
|
||||||
|
if (shopStoreActivityBase == null || checkTime == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date starTime = shopStoreActivityBase.getActivity_starttime();
|
||||||
|
Date endTime = shopStoreActivityBase.getActivity_endtime();
|
||||||
|
|
||||||
|
|
||||||
|
return isActivityTimeValid(starTime, endTime, checkTime);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证活动时间是否有效
|
* 验证活动时间是否有效
|
||||||
*
|
*
|
||||||
* @param starTime 活动开始时间
|
* @param starTime 活动开始时间
|
||||||
* @param endTime 活动结束时间
|
* @param endTime 活动结束时间
|
||||||
|
* @param checkTime 待验证时间
|
||||||
* @return 时间是否有效
|
* @return 时间是否有效
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isActivityTimeValid(Date starTime, Date endTime) {
|
public boolean isActivityTimeValid(Date starTime, Date endTime, Date checkTime) {
|
||||||
if (starTime == null || endTime == null) {
|
if (starTime == null || endTime == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Date now = new Date();
|
if (checkTime == null) {
|
||||||
return !now.before(starTime) && !now.after(endTime);
|
checkTime = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
return !checkTime.before(starTime) && !checkTime.after(endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user