feat: 添加顾客权限控制和订单时间限制
This commit is contained in:
@@ -28,8 +28,9 @@ public interface OrderService {
|
||||
|
||||
/**
|
||||
* 获取订单详情(含明细)
|
||||
* 顾客只能查看自己的订单
|
||||
*/
|
||||
Map<String, Object> getOrderDetail(String orderId);
|
||||
Map<String, Object> getOrderDetail(String orderId, String userId, String role);
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.example.building.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.example.building.entity.SystemConfig;
|
||||
import com.example.building.mapper.SystemConfigMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Service
|
||||
public class SystemConfigService {
|
||||
|
||||
@Autowired
|
||||
private SystemConfigMapper systemConfigMapper;
|
||||
|
||||
/**
|
||||
* 获取顾客订单可见天数配置
|
||||
* 默认180天(半年)
|
||||
*/
|
||||
public int getCustomerOrderVisibleDays() {
|
||||
LambdaQueryWrapper<SystemConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemConfig::getConfigKey, "customer_order_visible_days");
|
||||
SystemConfig config = systemConfigMapper.selectOne(wrapper);
|
||||
|
||||
if (config != null && config.getConfigValue() != null) {
|
||||
try {
|
||||
return Integer.parseInt(config.getConfigValue());
|
||||
} catch (NumberFormatException e) {
|
||||
return 180;
|
||||
}
|
||||
}
|
||||
return 180; // 默认半年
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取顾客可见订单开始日期
|
||||
*/
|
||||
public LocalDate getCustomerOrderStartDate() {
|
||||
int days = getCustomerOrderVisibleDays();
|
||||
return LocalDate.now().minusDays(days);
|
||||
}
|
||||
}
|
||||
@@ -171,14 +171,20 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
/**
|
||||
* 获取订单详情(含明细)
|
||||
* 顾客只能查看自己的订单
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> getOrderDetail(String orderId) {
|
||||
public Map<String, Object> getOrderDetail(String orderId, String userId, String role) {
|
||||
Order order = orderMapper.selectById(orderId);
|
||||
if (order == null) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
|
||||
// 顾客只能查看自己的订单
|
||||
if ("customer".equals(role) && !userId.equals(order.getCustomerId())) {
|
||||
throw new RuntimeException("无权查看该订单");
|
||||
}
|
||||
|
||||
List<OrderItem> items = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>()
|
||||
.eq(OrderItem::getOrderId, orderId));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user