Skip to content

系统配置

MineShop 提供完善的系统配置管理,通过值对象封装配置项,支持基础设置、商品、订单、支付、物流、会员等多个维度。

🎯 配置架构

┌─────────────────────────────────────────────────────────────┐
│                  DomainMallSettingService                    │
│                      商城配置聚合服务                          │
├─────────────────────────────────────────────────────────────┤
│  BasicSetting   │  ProductSetting  │  OrderSetting          │
│  基础设置        │  商品设置         │  订单设置               │
├─────────────────────────────────────────────────────────────┤
│  PaymentSetting │  ShippingSetting │  MemberSetting         │
│  支付设置        │  物流设置         │  会员设置               │
├─────────────────────────────────────────────────────────────┤
│  ContentSetting │  IntegrationSetting                       │
│  内容设置        │  集成设置                                  │
└─────────────────────────────────────────────────────────────┘

✨ 配置分类

1. 基础设置 (BasicSetting)

配置项说明默认值
name商城名称MineMall 商城
logo商城 Logo-
support_email客服邮箱support@minemall.local
hotline客服热线400-888-0000

2. 商品设置 (ProductSetting)

配置项说明默认值
auto_generate_sku自动生成 SKUtrue
max_gallery最大图片数9
stock_warning库存预警阈值20
allow_preorder允许预售false
content_filter内容过滤词[]

3. 订单设置 (OrderSetting)

配置项说明默认值
auto_close_minutes自动关闭时间(分钟)30
auto_confirm_days自动确认收货(天)7
after_sale_days售后期限(天)15
enable_invoice启用发票true
invoice_provider发票服务商system
customer_service客服电话400-888-1000

4. 支付设置 (PaymentSetting)

配置项说明默认值
wechat_enabled微信支付开关false
wechat_config微信支付配置[]
refund_review退款需审核true
settlement_cycle_days结算周期(天)7
balance_enabled余额支付开关true

5. 物流设置 (ShippingSetting)

配置项说明默认值
default_method默认配送方式express
enable_pickup启用自提true
pickup_address自提地址-
free_shipping_threshold包邮门槛0
supported_providers支持的快递[]
remote_area_enabled偏远地区加价false

6. 会员设置 (MemberSetting)

配置项说明默认值
enable_growth启用成长值true
register_points注册赠送积分100
sign_in_reward签到奖励5
invite_reward邀请奖励50
points_expire_months积分过期月数24
vip_levelsVIP 等级定义[]
points_ratio积分兑换比例100

📦 配置服务

php
// DomainMallSettingService.php
final class DomainMallSettingService extends IService
{
    public function basic(): BasicSetting
    {
        return $this->basic ??= new BasicSetting(
            (string) $this->value('mall.basic.name', 'MineMall 商城'),
            (string) $this->value('mall.basic.logo', ''),
            (string) $this->value('mall.basic.support_email', 'support@minemall.local'),
            (string) $this->value('mall.basic.hotline', '400-888-0000'),
        );
    }

    public function product(): ProductSetting
    {
        return $this->product ??= new ProductSetting(
            (bool) $this->value('mall.product.auto_generate_sku', true),
            (int) $this->value('mall.product.max_gallery', 9),
            (int) $this->value('mall.product.stock_warning', 20),
            (bool) $this->value('mall.product.allow_preorder', false),
            $this->normalizeLines($this->value('mall.product.content_filter', [])),
        );
    }

    // ... 其他配置方法
}

🔧 使用示例

php
// 获取库存预警阈值
$threshold = $this->mallSettingService->product()->stockWarning();

// 获取订单自动关闭时间
$minutes = $this->mallSettingService->order()->autoCloseMinutes();

// 检查微信支付是否启用
if ($this->mallSettingService->payment()->wechatEnabled) {
    // 处理微信支付
}

💻 API 接口

接口方法说明
/admin/settingsGET获取所有配置
/admin/settings/{group}GET获取分组配置
/admin/settingsPUT更新配置

⚠️ 注意事项

  1. 缓存: 配置读取后会缓存,修改后需清除缓存
  2. 类型安全: 使用值对象确保类型安全
  3. 默认值: 所有配置都有合理的默认值
  4. 验证: 配置更新时进行数据验证

📚 相关文档

基于 Apache-2.0 许可发布 | 感谢 MineAdmin 提供的优秀基础框架