砍价下单验证是否达标,不达标不允许下单购买
This commit is contained in:
parent
abfefb6f57
commit
2af8bc966a
@ -322,7 +322,7 @@ public class UserOrderController extends BaseControllerImpl {
|
|||||||
return CommonResult.success(data);
|
return CommonResult.success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "可预约订单的时间槽", notes = "可预约订单的时间槽")
|
@ApiOperation(value = "可预约订单的时间槽", notes = "结算中心页面,可预约订单的时间槽")
|
||||||
@RequestMapping(value = "/booking_time_args", method = RequestMethod.GET)
|
@RequestMapping(value = "/booking_time_args", method = RequestMethod.GET)
|
||||||
public CommonResult listInvoice(@RequestParam(name = "store_ids", defaultValue = "") String store_ids) {
|
public CommonResult listInvoice(@RequestParam(name = "store_ids", defaultValue = "") String store_ids) {
|
||||||
List<BookingArgDTO> list = shopOrderInfoService.genBookingOrderArgList(store_ids);
|
List<BookingArgDTO> list = shopOrderInfoService.genBookingOrderArgList(store_ids);
|
||||||
|
|||||||
@ -1395,8 +1395,8 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
|||||||
|
|
||||||
Integer quantity = getParameter("quantity", 1);
|
Integer quantity = getParameter("quantity", 1);
|
||||||
Integer channelType = getParameter("channel_type", 0);
|
Integer channelType = getParameter("channel_type", 0);
|
||||||
Map activityRows = new HashMap();
|
|
||||||
|
|
||||||
|
Map activityRows = new HashMap();
|
||||||
if (!activityId.equals(0)) {
|
if (!activityId.equals(0)) {
|
||||||
activityRows = shopStoreActivityBaseService.getActivityFormatOne(activityId, quantity);
|
activityRows = shopStoreActivityBaseService.getActivityFormatOne(activityId, quantity);
|
||||||
}
|
}
|
||||||
@ -1580,8 +1580,17 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
|
|||||||
|
|
||||||
// 判断是否砍价购买
|
// 判断是否砍价购买
|
||||||
Integer acId = getParameter("ac_id", Integer.class);
|
Integer acId = getParameter("ac_id", Integer.class);
|
||||||
if (acId != null) {
|
// 判断是否为砍价活动
|
||||||
cartData.put("ac_id", acId); // 拼团ID, 为0,在创建拼团
|
Boolean isCutPriceActivity = shopStoreActivityBaseService.isCutPriceActivity(activityId);
|
||||||
|
if (CheckUtil.isNotEmpty(acId) && isCutPriceActivity) {
|
||||||
|
cartData.put("ac_id", acId);
|
||||||
|
|
||||||
|
// 校验砍价活动,用户是否可以立即购买了?
|
||||||
|
Pair<Boolean, String> canDoOrderCutPriceActivity = shopActivityCutpriceService.canDoOrderCutPriceActivity(acId, userId);
|
||||||
|
if (!canDoOrderCutPriceActivity.getFirst()) {
|
||||||
|
logger.error(canDoOrderCutPriceActivity.getSecond());
|
||||||
|
throw new ApiException(I18nUtil._("砍价活动未达标,请继续努力,再提交订单。"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注:(重要)邮费检测和计算
|
// 注:(重要)邮费检测和计算
|
||||||
|
|||||||
@ -865,55 +865,55 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
|||||||
public Pair<Boolean, String> checkBookingOrderArgs(Integer storeId, Integer bookingState, String bookingBeginTimeStr, String bookingEndTimeStr) {
|
public Pair<Boolean, String> checkBookingOrderArgs(Integer storeId, Integer bookingState, String bookingBeginTimeStr, String bookingEndTimeStr) {
|
||||||
// 1. 必填参数检查
|
// 1. 必填参数检查
|
||||||
if (CheckUtil.isEmpty(storeId) || CheckUtil.isEmpty(bookingState)) {
|
if (CheckUtil.isEmpty(storeId) || CheckUtil.isEmpty(bookingState)) {
|
||||||
return Pair.of(false, "[预约订单校验] 缺少必要参数");
|
return Pair.of(false, "[预约单校验] 缺少必要参数");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 预约状态检查
|
// 2. 预约状态检查
|
||||||
if (!CommonConstant.Order_Booking_State_YY.equals(bookingState)) {
|
if (!CommonConstant.Order_Booking_State_YY.equals(bookingState)) {
|
||||||
return Pair.of(true, "[预约订单校验] 非预订单,跳过验证");
|
return Pair.of(true, "[预约单校验] 非预订单,跳过验证");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 时间格式检查
|
// 3. 时间格式检查
|
||||||
if (StrUtil.isBlank(bookingBeginTimeStr)) {
|
if (StrUtil.isBlank(bookingBeginTimeStr)) {
|
||||||
return Pair.of(false, "[预约订单校验] 预约时间不能为空");
|
return Pair.of(false, "[预约单校验] 预约时间不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
Date bookingBeginTime = DateTimeUtils.tryParseDateTimeToDate(bookingBeginTimeStr);
|
Date bookingBeginTime = DateTimeUtils.tryParseDateTimeToDate(bookingBeginTimeStr);
|
||||||
Date bookingEndTime = DateTimeUtils.tryParseDateTimeToDate(bookingEndTimeStr);
|
Date bookingEndTime = DateTimeUtils.tryParseDateTimeToDate(bookingEndTimeStr);
|
||||||
if (bookingBeginTime == null) {
|
if (bookingBeginTime == null) {
|
||||||
return Pair.of(false, "[预约订单校验] 预约时间格式有误");
|
return Pair.of(false, "[预约单校验] 预约时间格式有误");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 时间逻辑检查 - 开始时间不能晚于结束时间
|
// 4. 时间逻辑检查 - 开始时间不能晚于结束时间
|
||||||
if (bookingEndTime != null && bookingBeginTime.after(bookingEndTime)) {
|
if (bookingEndTime != null && bookingBeginTime.after(bookingEndTime)) {
|
||||||
return Pair.of(false, "[预约订单校验] 开始时间不能晚于截止时间");
|
return Pair.of(false, "[预约单校验] 开始时间不能晚于截止时间");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 店铺信息检查
|
// 5. 店铺信息检查
|
||||||
ShopStoreInfo shopStoreInfo = shopStoreInfoService.getShopStoreInfoByStoreId(storeId);
|
ShopStoreInfo shopStoreInfo = shopStoreInfoService.getShopStoreInfoByStoreId(storeId);
|
||||||
if (shopStoreInfo == null) {
|
if (shopStoreInfo == null) {
|
||||||
return Pair.of(false, "[预约订单校验] 店铺信息有误");
|
return Pair.of(false, "[预约单校验] 店铺信息有误");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.isBlank(shopStoreInfo.getStore_opening_hours()) || StrUtil.isBlank(shopStoreInfo.getStore_close_hours())) {
|
if (StrUtil.isBlank(shopStoreInfo.getStore_opening_hours()) || StrUtil.isBlank(shopStoreInfo.getStore_close_hours())) {
|
||||||
shopStoreInfo.setStore_opening_hours("09:00");
|
shopStoreInfo.setStore_opening_hours("09:00");
|
||||||
shopStoreInfo.setStore_close_hours("06:00");
|
shopStoreInfo.setStore_close_hours("06:00");
|
||||||
logger.warn("[预约订单校验] 店铺营业时间未设置,请联系商家,默认指定 {}-{}", shopStoreInfo.getStore_opening_hours(), shopStoreInfo.getStore_close_hours());
|
logger.warn("[预约单校验] 店铺营业时间未设置,请联系商家,默认指定 {}-{}", shopStoreInfo.getStore_opening_hours(), shopStoreInfo.getStore_close_hours());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. 店铺营业时间检查
|
// 6. 店铺营业时间检查
|
||||||
if (!DateTimeUtils.isTimeInRange(shopStoreInfo.getStore_opening_hours(), shopStoreInfo.getStore_close_hours(), bookingBeginTime)) {
|
if (!DateTimeUtils.isTimeInRange(shopStoreInfo.getStore_opening_hours(), shopStoreInfo.getStore_close_hours(), bookingBeginTime)) {
|
||||||
String message = StrUtil.format("[预约订单校验] 请在 {}-{} 店铺营业时间内预约下单", shopStoreInfo.getStore_opening_hours(), shopStoreInfo.getStore_close_hours());
|
String message = StrUtil.format("[预约单校验] 请在 {}-{} 店铺营业时间内预约下单", shopStoreInfo.getStore_opening_hours(), shopStoreInfo.getStore_close_hours());
|
||||||
return Pair.of(false, message);
|
return Pair.of(false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. 预约时间范围检查 - 仅能预约50分钟后的订单(防止用户在下单页面停留太长,45分钟也是可以通过的)
|
// 7. 预约时间范围检查 - 仅能预约50分钟后的订单(防止用户在下单页面停留太长,45分钟也是可以通过的)
|
||||||
Date fortyFiveMinutesLater = DateUtil.offsetMinute(new Date(), CommonConstant.MIN_DELAY_MINUTES_FOR_BOOKING_ORDER - 5);
|
Date fortyFiveMinutesLater = DateUtil.offsetMinute(new Date(), CommonConstant.MIN_DELAY_MINUTES_FOR_BOOKING_ORDER - 5);
|
||||||
if (bookingBeginTime.before(fortyFiveMinutesLater)) {
|
if (bookingBeginTime.before(fortyFiveMinutesLater)) {
|
||||||
return Pair.of(false, String.format("[预约订单校验] 请预约%d分后的订单", CommonConstant.MIN_DELAY_MINUTES_FOR_BOOKING_ORDER));
|
return Pair.of(false, String.format("[预约单校验] 请预约%d分后的订单", CommonConstant.MIN_DELAY_MINUTES_FOR_BOOKING_ORDER));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair.of(true, "[预约订单校验] 成功");
|
return Pair.of(true, "[预约单校验] 成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -59,7 +59,7 @@ public interface ShopStoreActivityBaseService extends IBaseService<ShopStoreActi
|
|||||||
List<Long> getActivityAllItemIds(Map activity_row);
|
List<Long> getActivityAllItemIds(Map activity_row);
|
||||||
|
|
||||||
boolean isActivityTimeValid(Map activity_row);
|
boolean isActivityTimeValid(Map activity_row);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证活动时间是否有效
|
* 验证活动时间是否有效
|
||||||
*
|
*
|
||||||
@ -180,5 +180,13 @@ public interface ShopStoreActivityBaseService extends IBaseService<ShopStoreActi
|
|||||||
*/
|
*/
|
||||||
Map getGiftbag(Integer activity_id);
|
Map getGiftbag(Integer activity_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是砍价活动
|
||||||
|
*
|
||||||
|
* @param activity_id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean isCutPriceActivity(Integer activity_id);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4376,6 +4376,33 @@ public class ShopStoreActivityBaseServiceImpl extends BaseServiceImpl<ShopStoreA
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是砍价活动
|
||||||
|
*
|
||||||
|
* @param activity_id 活动ID
|
||||||
|
* @return 是否为砍价活动
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean isCutPriceActivity(Integer activity_id) {
|
||||||
|
// 参数校验
|
||||||
|
if (activity_id == null || activity_id <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 使用exists查询优化性能,只判断是否存在而不加载数据
|
||||||
|
QueryWrapper<ShopStoreActivityBase> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("activity_id", activity_id);
|
||||||
|
queryWrapper.eq("activity_type_id", StateCode.ACTIVITY_TYPE_CUTPRICE);
|
||||||
|
return shopStoreActivityBaseMapper.selectCount(queryWrapper) > 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 异常处理,防止影响主流程
|
||||||
|
logger.error("判断是否为砍价活动时发生异常,activity_id={}", activity_id, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean removeActivityBase(Integer activity_id, ShopStoreActivityBase activity_row) {
|
public boolean removeActivityBase(Integer activity_id, ShopStoreActivityBase activity_row) {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user