砍价字段修改
This commit is contained in:
parent
db33dd255e
commit
2661277bd2
@ -129,10 +129,10 @@ public class ShopStoreActivityBase implements Serializable {
|
|||||||
@TableField(updateStrategy = NOT_EMPTY)
|
@TableField(updateStrategy = NOT_EMPTY)
|
||||||
private String flow_no;
|
private String flow_no;
|
||||||
|
|
||||||
@ApiModelProperty(value = "在活动时间范围内,用户砍价允许的天数")
|
@ApiModelProperty(value = "在活动时间范围内,用户砍价有效期(小时)")
|
||||||
private Integer cut_days;
|
private Integer cut_hour;
|
||||||
|
|
||||||
@ApiModelProperty(value = "参与活动商品的总数量")
|
@ApiModelProperty(value = "参与活动商品的总数量(个)")
|
||||||
private Integer product_count;
|
private Integer product_count;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,8 +118,8 @@ public class UserActivityController extends BaseControllerImpl {
|
|||||||
return CommonResult.success(shopActivityCutpriceService.getCutPriceActivity());
|
return CommonResult.success(shopActivityCutpriceService.getCutPriceActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "立即砍价", notes = "自己砍价、要求朋友过来也能砍价")
|
@ApiOperation(value = "立即砍价", notes = "自己砍价、邀请朋友过来也能砍价")
|
||||||
@RequestMapping(value = "/doCutPrice", method = RequestMethod.GET)
|
@RequestMapping(value = "/doCutPrice", method = {RequestMethod.GET, RequestMethod.POST})
|
||||||
public CommonResult doCutPrice(@RequestParam(name = "ac_id", defaultValue = "0") Integer ac_id) {
|
public CommonResult doCutPrice(@RequestParam(name = "ac_id", defaultValue = "0") Integer ac_id) {
|
||||||
UserDto user = getCurrentUser();
|
UserDto user = getCurrentUser();
|
||||||
if (user == null || CheckUtil.isEmpty(user.getId())) {
|
if (user == null || CheckUtil.isEmpty(user.getId())) {
|
||||||
|
|||||||
@ -260,37 +260,58 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 砍价活动详情
|
* 砍价活动详情(注:用户一进来,就参与砍价创建了)
|
||||||
*
|
*
|
||||||
* @return
|
* @return 砍价活动详情信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map getCutPriceActivity() {
|
public Map getCutPriceActivity() {
|
||||||
|
// 获取请求参数
|
||||||
Integer activity_id = getParameter("activity_id", 0);
|
Integer activity_id = getParameter("activity_id", 0);
|
||||||
Integer participant_id = getParameter("participant_id", 0);
|
Integer participant_id = getParameter("participant_id", 0);
|
||||||
Integer user_id = getParameter("user_id", 0);
|
Integer user_id = getParameter("user_id", 0);
|
||||||
|
|
||||||
|
// 参数校验
|
||||||
|
if (activity_id == null || activity_id <= 0) {
|
||||||
|
throw new ApiException(I18nUtil._("活动ID无效!"));
|
||||||
|
}
|
||||||
|
if (user_id == null || user_id <= 0) {
|
||||||
|
throw new ApiException(I18nUtil._("用户ID无效!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取活动基础信息
|
||||||
ShopStoreActivityBase activityBase = shopStoreActivityBaseService.get(activity_id);
|
ShopStoreActivityBase activityBase = shopStoreActivityBaseService.get(activity_id);
|
||||||
|
if (activityBase == null) {
|
||||||
|
throw new ApiException(I18nUtil._("未找到活动信息!"));
|
||||||
|
}
|
||||||
|
|
||||||
Map activity_row = Convert.toMap(String.class, Object.class, activityBase);
|
Map activity_row = Convert.toMap(String.class, Object.class, activityBase);
|
||||||
|
|
||||||
// if (!shopStoreActivityBaseService.verifyActivity(activity_row)) {
|
// 获取当前用户信息
|
||||||
// throw new ApiException(I18nUtil._("该活动不存在或已结束!"));
|
|
||||||
// }
|
|
||||||
|
|
||||||
UserDto user = getCurrentUser();
|
UserDto user = getCurrentUser();
|
||||||
if (CheckUtil.isEmpty(participant_id) && user != null) {
|
if (CheckUtil.isEmpty(participant_id) && user != null) {
|
||||||
participant_id = user.getId();
|
participant_id = user.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询用户是否已参与该砍价活动
|
||||||
QueryWrapper<ShopActivityCutprice> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopActivityCutprice> queryWrapper = new QueryWrapper<>();
|
||||||
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);
|
||||||
|
|
||||||
|
// 如果用户未参与该砍价活动,则创建新的砍价记录
|
||||||
if (cutprice_row == null) {
|
if (cutprice_row == null) {
|
||||||
cutprice_row = new ShopActivityCutprice();
|
cutprice_row = new ShopActivityCutprice();
|
||||||
|
|
||||||
|
// 从活动规则中获取商品原价和砍价底价
|
||||||
JSONObject activity_rule = JSONUtil.parseObj(activityBase.getActivity_rule());
|
JSONObject activity_rule = JSONUtil.parseObj(activityBase.getActivity_rule());
|
||||||
|
if (activity_rule == null) {
|
||||||
|
throw new ApiException(I18nUtil._("活动规则数据异常!"));
|
||||||
|
}
|
||||||
|
|
||||||
BigDecimal item_unit_price = Convert.toBigDecimal(activity_rule.get("item_unit_price"));
|
BigDecimal item_unit_price = Convert.toBigDecimal(activity_rule.get("item_unit_price"));
|
||||||
BigDecimal cut_down_min_limit_price = Convert.toBigDecimal(activity_rule.get("cut_down_min_limit_price"));
|
BigDecimal cut_down_min_limit_price = Convert.toBigDecimal(activity_rule.get("cut_down_min_limit_price"));
|
||||||
|
|
||||||
|
// 初始化砍价记录信息
|
||||||
cutprice_row.setActivity_id(activity_id);
|
cutprice_row.setActivity_id(activity_id);
|
||||||
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);
|
||||||
@ -298,32 +319,29 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
cutprice_row.setAc_datetime(new Date());
|
cutprice_row.setAc_datetime(new Date());
|
||||||
cutprice_row.setOrder_id("");
|
cutprice_row.setOrder_id("");
|
||||||
|
|
||||||
|
// 保存砍价记录
|
||||||
if (!saveOrUpdate(cutprice_row)) {
|
if (!saveOrUpdate(cutprice_row)) {
|
||||||
throw new ApiException(I18nUtil._("创建砍价失败!"));
|
throw new ApiException(I18nUtil._("创建砍价失败!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将砍价记录信息合并到活动信息中
|
||||||
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);
|
||||||
ShopActivityCutpriceHistory cutpriceHistory = cutpriceHistoryService.findOne(historyQueryWrapper);
|
ShopActivityCutpriceHistory cutpriceHistory = cutpriceHistoryService.findOne(historyQueryWrapper);
|
||||||
|
|
||||||
|
// 设置用户砍价历史信息
|
||||||
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("activity_rule", JSONUtil.parseObj(activity_row.get("activity_rule")));
|
activity_row.put("activity_rule", JSONUtil.parseObj(activity_row.get("activity_rule")));
|
||||||
|
|
||||||
// // 砍价订单有效期时长
|
// 判断是否可以立即购买
|
||||||
// if (cutprice_row != null && cutprice_row.getAc_datetime() != null) {
|
|
||||||
// Float order_cutprice_time = accountBaseConfigService.getConfig("order_cutprice_time", 3f);
|
|
||||||
// int second = NumberUtil.mul(order_cutprice_time, 24, 60, 60).intValue();
|
|
||||||
// long time = DateUtil.offsetSecond(cutprice_row.getAc_datetime(), +second).getTime();
|
|
||||||
// activity_row.put("activity_endtime", Convert.toDate(time));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 界面做一个简单的底价验证:
|
|
||||||
boolean canBuyNow = cutprice_row != null
|
boolean canBuyNow = cutprice_row != null
|
||||||
&& CheckUtil.isNotEmpty(cutprice_row.getAc_sale_price())
|
&& CheckUtil.isNotEmpty(cutprice_row.getAc_sale_price())
|
||||||
&& CheckUtil.isNotEmpty(cutprice_row.getAc_mix_limit_price())
|
&& CheckUtil.isNotEmpty(cutprice_row.getAc_mix_limit_price())
|
||||||
@ -331,7 +349,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
|
|
||||||
BigDecimal subtractPrice = NumberUtil.sub(cutprice_row.getAc_sale_price(), cutprice_row.getAc_mix_limit_price());
|
BigDecimal subtractPrice = NumberUtil.sub(cutprice_row.getAc_sale_price(), cutprice_row.getAc_mix_limit_price());
|
||||||
|
|
||||||
// 能否立即出手 1-可以;2-不可以
|
// 设置购买状态和提示信息
|
||||||
activity_row.put("can_buy_now", canBuyNow ? CommonConstant.Enable : CommonConstant.Disable2);
|
activity_row.put("can_buy_now", canBuyNow ? CommonConstant.Enable : CommonConstant.Disable2);
|
||||||
activity_row.put("cannot_buy_now_reason",
|
activity_row.put("cannot_buy_now_reason",
|
||||||
canBuyNow ? "恭喜您,商品可以立即出手了。" :
|
canBuyNow ? "恭喜您,商品可以立即出手了。" :
|
||||||
@ -340,6 +358,7 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
return activity_row;
|
return activity_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 砍价
|
* 砍价
|
||||||
*
|
*
|
||||||
@ -350,11 +369,26 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommonResult doCutPrice(Integer ac_id, Integer user_id) {
|
public CommonResult doCutPrice(Integer ac_id, Integer user_id) {
|
||||||
DateTime today = DateUtil.beginOfDay(new Date());
|
// 参数校验
|
||||||
Integer num = accountBaseConfigService.getConfig("user_cutprice_num", 0);
|
if (ac_id == null || ac_id <= 0) {
|
||||||
Integer cut_num = Convert.toInt(redisService.hGet("cutprice-" + today, user_id.toString()), 0);
|
throw new ApiException(I18nUtil._("活动ID无效!"));
|
||||||
|
}
|
||||||
|
if (user_id == null || user_id <= 0) {
|
||||||
|
throw new ApiException(I18nUtil._("用户ID无效!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取砍价记录
|
||||||
ShopActivityCutprice cutprice_row = get(ac_id);
|
ShopActivityCutprice cutprice_row = get(ac_id);
|
||||||
|
if (cutprice_row == null) {
|
||||||
|
throw new ApiException(I18nUtil._("未找到砍价记录!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否是帮别人砍价且次数已用完
|
||||||
if (!cutprice_row.getUser_id().equals(user_id)) {
|
if (!cutprice_row.getUser_id().equals(user_id)) {
|
||||||
|
DateTime today = DateUtil.beginOfDay(new Date());
|
||||||
|
Integer num = accountBaseConfigService.getConfig("user_cutprice_num", 0);
|
||||||
|
Integer cut_num = Convert.toInt(redisService.hGet("cutprice-" + today, user_id.toString()), 0);
|
||||||
|
|
||||||
if (num > 0 && cut_num >= num) {
|
if (num > 0 && cut_num >= num) {
|
||||||
throw new ApiException(I18nUtil._("今日帮砍次数已用完!"));
|
throw new ApiException(I18nUtil._("今日帮砍次数已用完!"));
|
||||||
}
|
}
|
||||||
@ -362,34 +396,54 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
|
|
||||||
BigDecimal ac_sale_price = cutprice_row.getAc_sale_price();
|
BigDecimal ac_sale_price = cutprice_row.getAc_sale_price();
|
||||||
BigDecimal ac_mix_limit_price = cutprice_row.getAc_mix_limit_price();
|
BigDecimal ac_mix_limit_price = cutprice_row.getAc_mix_limit_price();
|
||||||
|
|
||||||
|
// 检查是否已达到最低价
|
||||||
|
if (ac_sale_price == null || ac_mix_limit_price == null) {
|
||||||
|
throw new ApiException(I18nUtil._("价格数据异常!"));
|
||||||
|
}
|
||||||
|
|
||||||
if (ObjectUtil.compare(ac_sale_price, ac_mix_limit_price) <= 0) {
|
if (ObjectUtil.compare(ac_sale_price, ac_mix_limit_price) <= 0) {
|
||||||
throw new ApiException(I18nUtil._("已达到最低价!"));
|
throw new ApiException(I18nUtil._("已达到最低价!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer activity_id = cutprice_row.getActivity_id();
|
Integer activity_id = cutprice_row.getActivity_id();
|
||||||
ShopStoreActivityBase storeActivityBase = shopStoreActivityBaseService.get(activity_id);
|
ShopStoreActivityBase storeActivityBase = shopStoreActivityBaseService.get(activity_id);
|
||||||
Map activity_row = Convert.toMap(String.class, Object.class, storeActivityBase);
|
if (storeActivityBase == null) {
|
||||||
if (!shopStoreActivityBaseService.isActivityTimeValid(activity_row)) {
|
throw new ApiException(I18nUtil._("未找到活动信息!"));
|
||||||
throw new ApiException(I18nUtil._("该活动不存在!"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查活动是否有效
|
||||||
|
if (!shopStoreActivityBaseService.isActivityTimeValid(Convert.toMap(String.class, Object.class, storeActivityBase))) {
|
||||||
|
throw new ApiException(I18nUtil._("该活动不存在或已过期!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否已经帮过好友砍了价?
|
||||||
QueryWrapper<ShopActivityCutpriceHistory> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopActivityCutpriceHistory> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("user_id", user_id).eq("ac_id", ac_id);
|
queryWrapper.eq("user_id", user_id).eq("ac_id", ac_id);
|
||||||
long ach_num = shopActivityCutpriceHistoryService.count(queryWrapper);
|
long ach_num = shopActivityCutpriceHistoryService.count(queryWrapper);
|
||||||
|
if (ach_num > 0) {
|
||||||
if (CheckUtil.isNotEmpty(ach_num)) {
|
throw new ApiException(I18nUtil._("已经帮过好友砍了价!"));
|
||||||
throw new ApiException(I18nUtil._("已经帮助好友进行砍价!"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算砍价金额
|
||||||
BigDecimal cut_price = shopStoreActivityBaseService.getCutDownPrice(storeActivityBase, cutprice_row);
|
BigDecimal cut_price = shopStoreActivityBaseService.getCutDownPrice(storeActivityBase, cutprice_row);
|
||||||
if (CheckUtil.isEmpty(cut_price)) {
|
if (cut_price == null || cut_price.compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
throw new ApiException(I18nUtil._("砍价失败!"));
|
throw new ApiException(I18nUtil._("砍价失败!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取商品ID
|
||||||
String str_activity_rule = storeActivityBase.getActivity_rule();
|
String str_activity_rule = storeActivityBase.getActivity_rule();
|
||||||
com.alibaba.fastjson.JSONObject activity_rule = com.alibaba.fastjson.JSONObject.parseObject(str_activity_rule);
|
if (StrUtil.isBlank(str_activity_rule)) {
|
||||||
Long item_id = activity_rule.getObject("item_id", Long.class);
|
throw new ApiException(I18nUtil._("活动规则数据异常!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject activity_rule = JSONUtil.parseObj(str_activity_rule);
|
||||||
|
Long item_id = activity_rule.get("item_id", Long.class);
|
||||||
|
if (item_id == null) {
|
||||||
|
throw new ApiException(I18nUtil._("未找到商品信息!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建砍价历史记录
|
||||||
ShopActivityCutpriceHistory ach_data = new ShopActivityCutpriceHistory();
|
ShopActivityCutpriceHistory ach_data = new ShopActivityCutpriceHistory();
|
||||||
ach_data.setActivity_id(activity_id);
|
ach_data.setActivity_id(activity_id);
|
||||||
ach_data.setUser_id(user_id);
|
ach_data.setUser_id(user_id);
|
||||||
@ -398,17 +452,22 @@ public class ShopActivityCutpriceServiceImpl extends BaseServiceImpl<ShopActivit
|
|||||||
ach_data.setAch_datetime(new Date());
|
ach_data.setAch_datetime(new Date());
|
||||||
ach_data.setAc_id(ac_id);
|
ach_data.setAc_id(ac_id);
|
||||||
|
|
||||||
|
// 保存砍价历史记录
|
||||||
if (!shopActivityCutpriceHistoryService.saveOrUpdate(ach_data)) {
|
if (!shopActivityCutpriceHistoryService.saveOrUpdate(ach_data)) {
|
||||||
throw new ApiException(I18nUtil._("修改砍价历史失败!"));
|
throw new ApiException(I18nUtil._("保存砍价历史失败!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新砍价信息
|
||||||
cutprice_row.setAc_sale_price(NumberUtil.sub(ac_sale_price, cut_price));
|
cutprice_row.setAc_sale_price(NumberUtil.sub(ac_sale_price, cut_price));
|
||||||
cutprice_row.setAc_num(cutprice_row.getAc_num() + 1);
|
cutprice_row.setAc_num(cutprice_row.getAc_num() + 1);
|
||||||
if (!edit(cutprice_row)) {
|
if (!edit(cutprice_row)) {
|
||||||
throw new ApiException(I18nUtil._("修改金额失败!"));
|
throw new ApiException(I18nUtil._("更新砍价信息失败!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新帮砍次数(如果不是自己砍自己的话)
|
||||||
if (!cutprice_row.getUser_id().equals(user_id)) {
|
if (!cutprice_row.getUser_id().equals(user_id)) {
|
||||||
|
DateTime today = DateUtil.beginOfDay(new Date());
|
||||||
|
Integer cut_num = Convert.toInt(redisService.hGet("cutprice-" + today, user_id.toString()), 0);
|
||||||
redisService.hSet("cutprice-" + today, user_id.toString(), cut_num + 1, 24 * 60 * 60 * 1000);
|
redisService.hSet("cutprice-" + today, user_id.toString(), cut_num + 1, 24 * 60 * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1049,13 +1049,20 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
|||||||
// 今天是否可预约(在营业时间之前或之中)
|
// 今天是否可预约(在营业时间之前或之中)
|
||||||
boolean isTodayAvailable = true;
|
boolean isTodayAvailable = true;
|
||||||
|
|
||||||
// 获取开业(活动)筹备中店铺最晚的日期, 如果存在说明几个店铺中有开业(活动)筹备中的店铺
|
// 获取开业(活动)筹备中店铺最晚的日期 yyyy-MM-dd, 如果存在说明几个店铺中有开业(活动)筹备中的店铺
|
||||||
Date latestBizOpeningDate = shopStoreBaseService.getLatestBizOpeningDate(storeIds);
|
Date latestBizOpeningDate = shopStoreBaseService.getLatestBizOpeningDate(storeIds);
|
||||||
if (latestBizOpeningDate != null) {
|
if (latestBizOpeningDate != null) {
|
||||||
// 有开业筹备中的店铺,预约以这个开业日期为起始日期
|
|
||||||
startDate = latestBizOpeningDate;
|
if (latestBizOpeningDate.after(startDate)) {
|
||||||
inRangeVal = 1;
|
// 如果开业筹备中的日期在今天之后,预约以这个开业日期为起始日期
|
||||||
isTodayAvailable = false;
|
startDate = latestBizOpeningDate;
|
||||||
|
inRangeVal = 1; // 今天不在营业时间段内
|
||||||
|
isTodayAvailable = false; // 今天不能预约
|
||||||
|
} else {
|
||||||
|
// 如果开业日期已过期,把这个日期设置为今天的日期
|
||||||
|
inRangeVal = 0;
|
||||||
|
isTodayAvailable = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 判断今天还能不能立即下单和预约下单?能:就有今天的时间槽;不能:就没有今天的时间槽
|
// 判断今天还能不能立即下单和预约下单?能:就有今天的时间槽;不能:就没有今天的时间槽
|
||||||
//-1-在时间段之前 0-时间段内,1-在时间段之后
|
//-1-在时间段之前 0-时间段内,1-在时间段之后
|
||||||
@ -1066,7 +1073,7 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
|||||||
isTodayAvailable = inRangeVal <= 0; // 今天是否可预约(在营业时间之前或之中)
|
isTodayAvailable = inRangeVal <= 0; // 今天是否可预约(在营业时间之前或之中)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 生成预约日期参数
|
||||||
for (int i = 0; i < daysCnt; i++) {
|
for (int i = 0; i < daysCnt; i++) {
|
||||||
Date currentDate = DateUtil.offsetDay(startDate, i);
|
Date currentDate = DateUtil.offsetDay(startDate, i);
|
||||||
BookingArgDTO bookingArgDTO = new BookingArgDTO();
|
BookingArgDTO bookingArgDTO = new BookingArgDTO();
|
||||||
@ -1105,97 +1112,104 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
|||||||
List<BookingArgDTO.BookingArgItem> items = new ArrayList<>();
|
List<BookingArgDTO.BookingArgItem> items = new ArrayList<>();
|
||||||
|
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (StrUtil.isNotBlank(dateStr) && StrUtil.isNotBlank(startTimeStr) && StrUtil.isNotBlank(endTimeStr)) {
|
if (StrUtil.isBlank(dateStr) || StrUtil.isBlank(startTimeStr) || StrUtil.isBlank(endTimeStr)) {
|
||||||
try {
|
bookingArgDTO.setItems(items);
|
||||||
// 解析营业时间
|
bookingArgList.add(bookingArgDTO);
|
||||||
Date openTime = DateUtil.parse(dateStr + " " + startTimeStr + ":00", "yyyy-MM-dd HH:mm:ss");
|
continue;
|
||||||
Date closeTime = DateUtil.parse(dateStr + " " + endTimeStr + ":00", "yyyy-MM-dd HH:mm:ss");
|
}
|
||||||
|
|
||||||
// 验证营业时间有效性
|
try {
|
||||||
if (!openTime.after(closeTime)) {
|
// 解析营业时间
|
||||||
// 在营业时间段内,且是今天,添加"立即送出"选项
|
Date openTime = DateUtil.parse(dateStr + " " + startTimeStr + ":00", "yyyy-MM-dd HH:mm:ss");
|
||||||
if (i == 0 && isTodayAvailable && inRangeVal == 0) {
|
Date closeTime = DateUtil.parse(dateStr + " " + endTimeStr + ":00", "yyyy-MM-dd HH:mm:ss");
|
||||||
BookingArgDTO.BookingArgItem immediateItem = new BookingArgDTO.BookingArgItem();
|
|
||||||
immediateItem.setTime_title("立即送出");
|
|
||||||
immediateItem.setBooking_at(0L);
|
|
||||||
immediateItem.setBooking_state(1);
|
|
||||||
immediateItem.setBooking_begin_time("");
|
|
||||||
immediateItem.setBooking_end_time("");
|
|
||||||
items.add(immediateItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确定时间槽开始时间
|
// 验证营业时间有效性
|
||||||
Date startTime = openTime;
|
if (openTime.after(closeTime)) {
|
||||||
if (i == 0 && isTodayAvailable && inRangeVal <= 0) {
|
logger.warn("[生成时间槽] 营业时间无效,openTime: {}, closeTime: {}", openTime, closeTime);
|
||||||
// 当前时间+50分钟作为时间槽的开始时间
|
bookingArgDTO.setItems(items);
|
||||||
Date nowPlusFifty = DateUtil.offsetMinute(new Date(), CommonConstant.MIN_DELAY_MINUTES_FOR_BOOKING_ORDER);
|
bookingArgList.add(bookingArgDTO);
|
||||||
|
continue;
|
||||||
// 确保开始时间在营业时间范围内
|
|
||||||
if (nowPlusFifty.after(openTime)) {
|
|
||||||
if (nowPlusFifty.before(closeTime)) {
|
|
||||||
// 如果当前时间+50分钟在营业时间范围内,则从该时间开始
|
|
||||||
startTime = nowPlusFifty;
|
|
||||||
logger.debug("[生成时间槽] 当前时间+50分钟在营业时间范围内,则从该时间开始");
|
|
||||||
} else {
|
|
||||||
// 如果当前时间+50分钟已经超过营业结束时间,则不生成后续时间槽
|
|
||||||
logger.debug("[生成时间槽] 当前时间+50分钟已超过营业结束时间,不生成后续时间槽");
|
|
||||||
startTime = null; // 标记为不生成时间槽
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成时间槽
|
|
||||||
if (startTime != null) {
|
|
||||||
Date currentTimeSlot = startTime;
|
|
||||||
int slotCount = 0;
|
|
||||||
final int MAX_SLOTS = 96; // 最多生成96个时间段,防止异常循环
|
|
||||||
|
|
||||||
while (currentTimeSlot.before(closeTime) && slotCount < MAX_SLOTS) {
|
|
||||||
Date endTimeSlot = DateUtil.offsetMinute(currentTimeSlot, 15);
|
|
||||||
|
|
||||||
// 如果结束时间超过了营业结束时间,则使用营业结束时间
|
|
||||||
if (endTimeSlot.after(closeTime)) {
|
|
||||||
endTimeSlot = closeTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建时间段项
|
|
||||||
BookingArgDTO.BookingArgItem timeItem = new BookingArgDTO.BookingArgItem();
|
|
||||||
String beginTimeStr = DateUtil.format(currentTimeSlot, "HH:mm");
|
|
||||||
String endTimeStrItem = DateUtil.format(endTimeSlot, "HH:mm");
|
|
||||||
|
|
||||||
timeItem.setTime_title(beginTimeStr + "-" + endTimeStrItem);
|
|
||||||
|
|
||||||
// 时间戳计算(秒)
|
|
||||||
long bookingAt = currentTimeSlot.getTime() / 1000;
|
|
||||||
timeItem.setBooking_at(bookingAt);
|
|
||||||
|
|
||||||
timeItem.setBooking_state(2);
|
|
||||||
timeItem.setBooking_begin_time(DateUtil.format(currentTimeSlot, "yyyy-MM-dd HH:mm:ss"));
|
|
||||||
timeItem.setBooking_end_time(DateUtil.format(endTimeSlot, "yyyy-MM-dd HH:mm:ss"));
|
|
||||||
|
|
||||||
items.add(timeItem);
|
|
||||||
|
|
||||||
// 移动到下一个时间段
|
|
||||||
currentTimeSlot = endTimeSlot;
|
|
||||||
slotCount++;
|
|
||||||
|
|
||||||
// 防止时间相同导致的死循环
|
|
||||||
if (currentTimeSlot.equals(startTime)) {
|
|
||||||
logger.warn("[生成时间槽] 检测到时间循环,跳出循环");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slotCount >= MAX_SLOTS) {
|
|
||||||
logger.warn("[生成时间槽] 时间段数量超过最大限制,date: {}", dateStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.warn("[生成时间槽] 营业时间无效,openTime: {}, closeTime: {}", openTime, closeTime);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("[生成时间槽] 生成时间槽异常,date: {}, openingHours: {}, closeHours: {}", dateStr, startTimeStr, endTimeStr, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在营业时间段内,且是今天,添加"立即送出"选项
|
||||||
|
if (i == 0 && isTodayAvailable && inRangeVal == 0) {
|
||||||
|
BookingArgDTO.BookingArgItem immediateItem = new BookingArgDTO.BookingArgItem();
|
||||||
|
immediateItem.setTime_title("立即送出");
|
||||||
|
immediateItem.setBooking_at(0L);
|
||||||
|
immediateItem.setBooking_state(1);
|
||||||
|
immediateItem.setBooking_begin_time("");
|
||||||
|
immediateItem.setBooking_end_time("");
|
||||||
|
items.add(immediateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确定时间槽开始时间
|
||||||
|
Date startTime = openTime;
|
||||||
|
if (i == 0 && isTodayAvailable && inRangeVal <= 0) {
|
||||||
|
// 当前时间+50分钟作为时间槽的开始时间
|
||||||
|
Date nowPlusFifty = DateUtil.offsetMinute(new Date(), CommonConstant.MIN_DELAY_MINUTES_FOR_BOOKING_ORDER);
|
||||||
|
|
||||||
|
// 确保开始时间在营业时间范围内
|
||||||
|
if (nowPlusFifty.after(openTime)) {
|
||||||
|
if (nowPlusFifty.before(closeTime)) {
|
||||||
|
// 如果当前时间+50分钟在营业时间范围内,则从该时间开始
|
||||||
|
startTime = nowPlusFifty;
|
||||||
|
logger.debug("[生成时间槽] 当前时间+50分钟在营业时间范围内,则从该时间开始");
|
||||||
|
} else {
|
||||||
|
// 如果当前时间+50分钟已经超过营业结束时间,则不生成后续时间槽
|
||||||
|
logger.debug("[生成时间槽] 当前时间+50分钟已超过营业结束时间,不生成后续时间槽");
|
||||||
|
startTime = null; // 标记为不生成时间槽
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成时间槽
|
||||||
|
if (startTime != null) {
|
||||||
|
Date currentTimeSlot = startTime;
|
||||||
|
int slotCount = 0;
|
||||||
|
final int MAX_SLOTS = 96; // 最多生成96个时间段,防止异常循环
|
||||||
|
|
||||||
|
while (currentTimeSlot.before(closeTime) && slotCount < MAX_SLOTS) {
|
||||||
|
Date endTimeSlot = DateUtil.offsetMinute(currentTimeSlot, 15);
|
||||||
|
|
||||||
|
// 如果结束时间超过了营业结束时间,则使用营业结束时间
|
||||||
|
if (endTimeSlot.after(closeTime)) {
|
||||||
|
endTimeSlot = closeTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建时间段项
|
||||||
|
BookingArgDTO.BookingArgItem timeItem = new BookingArgDTO.BookingArgItem();
|
||||||
|
String beginTimeStr = DateUtil.format(currentTimeSlot, "HH:mm");
|
||||||
|
String endTimeStrItem = DateUtil.format(endTimeSlot, "HH:mm");
|
||||||
|
|
||||||
|
timeItem.setTime_title(beginTimeStr + "-" + endTimeStrItem);
|
||||||
|
|
||||||
|
// 时间戳计算(秒)
|
||||||
|
long bookingAt = currentTimeSlot.getTime() / 1000;
|
||||||
|
timeItem.setBooking_at(bookingAt);
|
||||||
|
|
||||||
|
timeItem.setBooking_state(CommonConstant.Order_Booking_State_YY);
|
||||||
|
timeItem.setBooking_begin_time(DateUtil.format(currentTimeSlot, "yyyy-MM-dd HH:mm:ss"));
|
||||||
|
timeItem.setBooking_end_time(DateUtil.format(endTimeSlot, "yyyy-MM-dd HH:mm:ss"));
|
||||||
|
|
||||||
|
items.add(timeItem);
|
||||||
|
|
||||||
|
// 移动到下一个时间段
|
||||||
|
currentTimeSlot = endTimeSlot;
|
||||||
|
slotCount++;
|
||||||
|
|
||||||
|
// 防止时间相同导致的死循环
|
||||||
|
if (currentTimeSlot.equals(startTime)) {
|
||||||
|
logger.warn("[生成时间槽] 检测到时间循环,跳出循环");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slotCount >= MAX_SLOTS) {
|
||||||
|
logger.warn("[生成时间槽] 时间段数量超过最大限制,date: {}", dateStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("[生成时间槽] 生成时间槽异常,date: {}, openingHours: {}, closeHours: {}", dateStr, startTimeStr, endTimeStr, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
bookingArgDTO.setItems(items);
|
bookingArgDTO.setItems(items);
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public class ShopStoreActivityBaseController {
|
|||||||
return CommonResult.success(shopStoreActivityBaseService.listBarginItem());
|
return CommonResult.success(shopStoreActivityBaseService.listBarginItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "活动表-编辑", notes = "活动表-编辑")
|
@ApiOperation(value = "活动表-新增", notes = "活动表-新增")
|
||||||
@RequestMapping(value = "/edit", method = RequestMethod.POST)
|
@RequestMapping(value = "/edit", method = RequestMethod.POST)
|
||||||
public CommonResult edit() {
|
public CommonResult edit() {
|
||||||
return shopStoreActivityBaseService.saveActivityBase();
|
return shopStoreActivityBaseService.saveActivityBase();
|
||||||
|
|||||||
@ -3653,7 +3653,7 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
shopStoreActivityBase.setActivity_rule(Convert.toStr(activity_rule));
|
shopStoreActivityBase.setActivity_rule(Convert.toStr(activity_rule));
|
||||||
|
|
||||||
} else if (base.getActivity_type_id().equals(StateCode.ACTIVITY_TYPE_CUTPRICE)) {
|
} else if (base.getActivity_type_id().equals(StateCode.ACTIVITY_TYPE_CUTPRICE)) {
|
||||||
|
// 砍价活动
|
||||||
activity_rule.put("cut_down_fixed_price", Convert.toBigDecimal(getParameter("cut_down_fixed_price")));// 固定砍价价格
|
activity_rule.put("cut_down_fixed_price", Convert.toBigDecimal(getParameter("cut_down_fixed_price")));// 固定砍价价格
|
||||||
activity_rule.put("cut_down_max_price", Convert.toBigDecimal(getParameter("cut_down_max_price")));// 砍价最高范围
|
activity_rule.put("cut_down_max_price", Convert.toBigDecimal(getParameter("cut_down_max_price")));// 砍价最高范围
|
||||||
activity_rule.put("cut_down_min_price", Convert.toBigDecimal(getParameter("cut_down_min_price"))); // 砍价最低范围
|
activity_rule.put("cut_down_min_price", Convert.toBigDecimal(getParameter("cut_down_min_price"))); // 砍价最低范围
|
||||||
@ -3663,10 +3663,23 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
activity_rule.put("product_item_name", getParameter("product_item_name"));// 产品名称
|
activity_rule.put("product_item_name", getParameter("product_item_name"));// 产品名称
|
||||||
activity_rule.put("item_id", getParameter("item_id"));// 产品ID
|
activity_rule.put("item_id", getParameter("item_id"));// 产品ID
|
||||||
activity_rule.put("activity_intro", getParameter("activity_intro"));
|
activity_rule.put("activity_intro", getParameter("activity_intro"));
|
||||||
|
|
||||||
ShopProductItem item_row = shopProductItemService.get(Convert.toInt(activity_rule.get("item_id")));
|
ShopProductItem item_row = shopProductItemService.get(Convert.toInt(activity_rule.get("item_id")));
|
||||||
ShopProductBase product_row = shopProductBaseService.get(item_row.getProduct_id());
|
ShopProductBase product_row = shopProductBaseService.get(item_row.getProduct_id());
|
||||||
activity_rule.put("product_image", product_row.getProduct_image());
|
activity_rule.put("product_image", product_row.getProduct_image());
|
||||||
activity_rule.put("item_unit_price", item_row.getItem_unit_price());
|
activity_rule.put("item_unit_price", item_row.getItem_unit_price());
|
||||||
|
|
||||||
|
// cut_hour - 砍价有效期(小时)
|
||||||
|
Integer cut_hour = getParameter("cut_hour", 0);
|
||||||
|
if (cut_hour > 0) {
|
||||||
|
activity_rule.put("cut_hour", cut_hour);
|
||||||
|
}
|
||||||
|
// product_count - 参与活动商品总数(个)
|
||||||
|
Integer product_count = getParameter("product_count", 0);
|
||||||
|
if (product_count > 0) {
|
||||||
|
activity_rule.put("product_count", product_count);
|
||||||
|
}
|
||||||
|
|
||||||
shopStoreActivityBase.setActivity_rule(Convert.toStr(activity_rule));
|
shopStoreActivityBase.setActivity_rule(Convert.toStr(activity_rule));
|
||||||
} else if (base.getActivity_type_id().equals(StateCode.ACTIVITY_TYPE_GIFTBAG)) {
|
} else if (base.getActivity_type_id().equals(StateCode.ACTIVITY_TYPE_GIFTBAG)) {
|
||||||
//a+b组合套餐
|
//a+b组合套餐
|
||||||
@ -5315,6 +5328,7 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
data.put("activity_rule", activity_rule);
|
data.put("activity_rule", activity_rule);
|
||||||
|
|
||||||
if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_VOUCHER)) {
|
if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_VOUCHER)) {
|
||||||
|
//店铺优惠券
|
||||||
String voucher_image = getParameter("voucher_image", "");
|
String voucher_image = getParameter("voucher_image", "");
|
||||||
BigDecimal needed = getParameter("voucher_points_needed", BigDecimal.ZERO);
|
BigDecimal needed = getParameter("voucher_points_needed", BigDecimal.ZERO);
|
||||||
BigDecimal subtotal = getParameter("subtotal", BigDecimal.ZERO);
|
BigDecimal subtotal = getParameter("subtotal", BigDecimal.ZERO);
|
||||||
@ -5326,25 +5340,26 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
String voucher_startdate = getParameter("voucher_startdate");
|
String voucher_startdate = getParameter("voucher_startdate");
|
||||||
|
|
||||||
if (!CheckUtil.isDate(voucher_startdate)) {
|
if (!CheckUtil.isDate(voucher_startdate)) {
|
||||||
throw new ApiException(I18nUtil._("请输入有效的生效日期"));
|
throw new ApiException(I18nUtil._("请输入有效的开始日期"));
|
||||||
}
|
}
|
||||||
String voucher_enddate = getParameter("voucher_enddate");
|
String voucher_enddate = getParameter("voucher_enddate");
|
||||||
|
|
||||||
if (!CheckUtil.isDate(voucher_enddate)) {
|
if (!CheckUtil.isDate(voucher_enddate)) {
|
||||||
throw new ApiException(I18nUtil._("请输入有效的失效日期"));
|
throw new ApiException(I18nUtil._("请输入有效的截止日期"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Map requirement = new HashMap();
|
Map requirement = new HashMap();
|
||||||
Map points = new HashMap();
|
Map points = new HashMap();
|
||||||
Map buy = new HashMap();
|
Map buy = new HashMap();
|
||||||
|
|
||||||
points.put("needed", needed);
|
|
||||||
buy.put("subtotal", subtotal);
|
|
||||||
|
|
||||||
requirement.put("points", points);
|
requirement.put("points", points);
|
||||||
requirement.put("buy", buy);
|
requirement.put("buy", buy);
|
||||||
activity_rule.put("requirement", requirement);
|
|
||||||
|
|
||||||
|
points.put("needed", needed);
|
||||||
|
|
||||||
|
buy.put("subtotal", subtotal);
|
||||||
|
|
||||||
|
activity_rule.put("requirement", requirement);
|
||||||
activity_rule.put("voucher_image", voucher_image);
|
activity_rule.put("voucher_image", voucher_image);
|
||||||
activity_rule.put("voucher_price", voucher_price);
|
activity_rule.put("voucher_price", voucher_price);
|
||||||
activity_rule.put("voucher_start_date", voucher_startdate);
|
activity_rule.put("voucher_start_date", voucher_startdate);
|
||||||
@ -5363,6 +5378,7 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
buy.put("buy", buy);
|
buy.put("buy", buy);
|
||||||
data.put("requirement", requirement);
|
data.put("requirement", requirement);
|
||||||
} else if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_MARKETING)) {
|
} else if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_MARKETING)) {
|
||||||
|
//市场活动
|
||||||
String start_join_time = getParameter("start_join_time");
|
String start_join_time = getParameter("start_join_time");
|
||||||
String end_join_time = getParameter("end_join_time");
|
String end_join_time = getParameter("end_join_time");
|
||||||
String activity_address = getParameter("activity_address");
|
String activity_address = getParameter("activity_address");
|
||||||
@ -5389,6 +5405,7 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
activity_rule.put("activity_detail_intro", activity_detail_intro); // 活动详细规则
|
activity_rule.put("activity_detail_intro", activity_detail_intro); // 活动详细规则
|
||||||
activity_rule.put("activity_intro", activity_intro); // 活动介绍
|
activity_rule.put("activity_intro", activity_intro); // 活动介绍
|
||||||
} else if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_LOTTERY)) {
|
} else if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_LOTTERY)) {
|
||||||
|
//幸运大抽奖
|
||||||
String lottery_subtitle = getParameter("lottery_subtitle");
|
String lottery_subtitle = getParameter("lottery_subtitle");
|
||||||
Integer lottery_type = getParameter("lottery_type", Integer.class);
|
Integer lottery_type = getParameter("lottery_type", Integer.class);
|
||||||
String lottery_image = getParameter("lottery_image");
|
String lottery_image = getParameter("lottery_image");
|
||||||
@ -5512,6 +5529,14 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
|
|
||||||
activity_rule.put("product_image", product_row.getProduct_image());
|
activity_rule.put("product_image", product_row.getProduct_image());
|
||||||
activity_rule.put("item_unit_price", item_row.getItem_unit_price());
|
activity_rule.put("item_unit_price", item_row.getItem_unit_price());
|
||||||
|
|
||||||
|
// cut_hour - 砍价有效期(小时)
|
||||||
|
Integer cut_hour = getParameter("cut_hour", 72);
|
||||||
|
// product_count - 参与活动商品总数(个)
|
||||||
|
Integer product_count = getParameter("product_count", 3);
|
||||||
|
activity_rule.put("product_count", product_count); // 参与活动的商品总数(个)
|
||||||
|
activity_rule.put("cut_hour", cut_hour); // 砍价的有效期(小时)
|
||||||
|
|
||||||
} else if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_GIFTBAG)) {
|
} else if (ObjectUtil.equal(activity_type_id, StateCode.ACTIVITY_TYPE_GIFTBAG)) {
|
||||||
//a+b组合套餐
|
//a+b组合套餐
|
||||||
String activity_bag_category = getParameter("activity_bag_category");//礼包分类
|
String activity_bag_category = getParameter("activity_bag_category");//礼包分类
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user