下单总入口,打烊店铺限制下单

This commit is contained in:
Jack 2025-10-27 17:23:52 +08:00
parent ff66979876
commit f87242a929
6 changed files with 25 additions and 15 deletions

View File

@ -22,6 +22,7 @@ import java.io.Serializable;
*/
public class StoreBizTimeInfoDTO implements Serializable {
private Integer store_id;
private String store_name;
private Integer store_biz_state;
private String store_opening_hours;
private String store_close_hours;

View File

@ -6318,8 +6318,9 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
}
// 判断店铺是否打烊打烊不能下单
if (CheckUtil.isEmpty(currStoreId) || CommonConstant.Disable2.equals(shopStoreBaseService.getStoreBizState(currStoreId))) {
throw new ApiException(I18nUtil._("店铺打烊中,不可以下单!"));
Pair<Integer, String> storeBizState = shopStoreBaseService.getStoreBizState(currStoreId);
if (storeBizState != null && CommonConstant.Disable2.equals(storeBizState.getFirst())) {
throw new ApiException(I18nUtil._(storeBizState.getSecond() + ",无法提交订单。"));
}
// 每个订单记录的商品列表

View File

@ -47,8 +47,8 @@ public interface ShopStoreBaseMapper extends BaseMapper<ShopStoreBase> {
* @param storeId
* @return
*/
@Select("SELECT ssb.store_id, ssb.store_biz_state, ssi.store_opening_hours, ssi.store_close_hours " +
" LEFT FROM shop_store_base ssb JOIN shop_store_info ssi ON ssb.store_id = ssi.store_id " +
@Select("SELECT ssb.store_id, ssb.store_name, ssb.store_biz_state, ssi.store_opening_hours, ssi.store_close_hours " +
" FROM shop_store_base ssb LEFT JOIN shop_store_info ssi ON ssb.store_id = ssi.store_id " +
" WHERE ssb.store_id = #{storeId} LIMIT 1")
StoreBizTimeInfoDTO getStoreBizTimeInfo(@Param("storeId") Integer storeId);

View File

@ -243,7 +243,7 @@ public interface ShopStoreBaseService extends IBaseService<ShopStoreBase> {
* @param storeId
* @return
*/
Integer getStoreBizState(Integer storeId);
Pair<Integer, String> getStoreBizState(Integer storeId);
// Page<ShopStoreBase> getMobileStoreList(Integer page, Integer rows);

View File

@ -4239,18 +4239,19 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
* @param storeId 店铺ID
* @return 营业状态1-营业中2-已打烊
*/
public Integer getStoreBizState(Integer storeId) {
@Override
public Pair<Integer, String> getStoreBizState(Integer storeId) {
// 参数校验
if (CheckUtil.isEmpty(storeId)) {
log.warn("店铺ID为空无法确定营业状态");
return CommonConstant.Disable2;
return Pair.of(CommonConstant.Disable2, "店铺营业状态有误");
}
try {
StoreBizTimeInfoDTO storeBizTimeInfo = baseMapper.getStoreBizTimeInfo(storeId);
if (storeBizTimeInfo == null) {
log.warn("未找到店铺营业时间信息storeId: {}", storeId);
return CommonConstant.Disable2;
return Pair.of(CommonConstant.Disable2, "店铺营业状态有误");
}
Integer storeBizState = storeBizTimeInfo.getStore_biz_state();
@ -4266,20 +4267,25 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
// 不在营业时间内返回已打烊状态
log.debug("店铺当前不在营业时间内storeId: {}, openingHours: {}, closingHours: {}",
storeId, openingHours, closingHours);
return CommonConstant.Disable2;
return Pair.of(CommonConstant.Disable2, String.format("%s营业时间段%s-%s", storeBizTimeInfo.getStore_name(),
openingHours, closingHours));
}
return CommonConstant.Enable;
return Pair.of(CommonConstant.Enable, "");
}
// 返回原始营业状态处理null情况
Integer resultState = storeBizState != null ? storeBizState : CommonConstant.Disable2;
log.debug("返回店铺营业状态storeId: {}, state: {}", storeId, resultState);
return resultState;
if (resultState == CommonConstant.Disable2) {
return Pair.of(resultState, String.format("%s打烊中", storeBizTimeInfo.getStore_name()));
}
return Pair.of(resultState, "");
} catch (Exception e) {
// 处理异常避免影响主流程
log.error("检查店铺营业状态发生异常storeId: {}", storeId, e);
return CommonConstant.Disable2;
log.error("检查店铺营业状态发生异常storeId: {}", storeId, e);
return Pair.of(CommonConstant.Disable2, "无法获取店铺营业状态");
}
}

View File

@ -58,6 +58,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -1052,8 +1053,9 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
// 店铺Id
Integer storeId = Convert.toInt(product_row.get("store_id"));
// 判断店铺是否打烊打烊不能放入购物车
if (CheckUtil.isEmpty(storeId) || CommonConstant.Disable2.equals(shopStoreBaseService.getStoreBizState(storeId))) {
throw new ApiException(I18nUtil._("店铺打烊中,商品无法加入购物车!"));
Pair<Integer, String> storeBizState = shopStoreBaseService.getStoreBizState(storeId);
if (storeBizState != null && CommonConstant.Disable2.equals(storeBizState.getFirst())) {
throw new ApiException(I18nUtil._(storeBizState.getSecond() + ",无法加购商品。"));
}
Integer cart_type = Convert.toInt(data.get("cart_type"));