帮助文档
{{userInfo.nickname}}
用户设置 退出登录

{{wikiTitle}}

配置说明

CRMEB多店系统配置说明

概述

CRMEB多店系统的配置文件位于 config/ 目录下,基于ThinkPHP 6.0的配置机制,支持环境变量覆盖。


配置文件列表

文件名 说明
app.php 应用配置
database.php 数据库配置
cache.php 缓存配置
queue.php 队列配置
route.php 路由配置
session.php Session配置
cookie.php Cookie配置
log.php 日志配置
view.php 视图配置
pay.php 支付配置
wechat.php 微信配置
sms.php 短信配置
upload.php 上传配置
admin.php 后台配置
swoole.php Swoole配置
template.php 模板消息配置
delivery.php 配送配置
printer.php 打印机配置

核心配置详解

1. 应用配置 (app.php)

<?php
return [
    // 应用地址
    'app_host'         => env('app.host', ''),
    // 应用命名空间
    'app_namespace'    => '',
    // 是否启用路由
    'with_route'       => true,
    // 是否启用事件
    'with_event'       => true,
    // 应用映射
    'app_map'          => [],
    // 域名绑定
    'domain_bind'      => [],
    // 禁止URL访问的应用列表
    'deny_app_list'    => [],
    // 默认应用
    'default_app'      => '',
    // 默认时区
    'default_timezone' => 'Asia/Shanghai',
    // 异常页面模板
    'exception_tmpl'   => app()->getRootPath() . 'public/statics/exception.tpl',
    // 错误显示信息
    'error_message'    => '页面错误!请稍后再试~',
    // 显示错误信息
    'show_error_msg'   => false,
];

2. 数据库配置 (database.php)

<?php
return [
    // 默认数据库连接
    'default'         => env('database.driver', 'mysql'),
    // 数据库连接配置
    'connections'     => [
        'mysql' => [
            'type'            => env('database.type', 'mysql'),
            'hostname'        => env('database.hostname', '127.0.0.1'),
            'database'        => env('database.database', 'crmeb'),
            'username'        => env('database.username', 'root'),
            'password'        => env('database.password', 'root'),
            'hostport'        => env('database.hostport', '3306'),
            'charset'         => env('database.charset', 'utf8mb4'),
            'prefix'          => env('database.prefix', 'eb_'),
            'debug'           => env('database.debug', true),
            'deploy'          => 0,           // 0:集中式 1:分布式
            'rw_separate'     => false,       // 读写分离
            'master_num'      => 1,           // 主服务器数量
            'fields_strict'   => true,        // 字段严格检查
            'break_reconnect' => true,        // 断线重连
        ],
    ],
    // 自动写入时间戳
    'auto_timestamp'  => 'timestamp',
    // 时间格式
    'datetime_format' => 'Y-m-d H:i:s',
    // 分页配置
    'page' => [
        'pageKey'      => 'page',
        'limitKey'     => 'limit',
        'limitMax'     => 100,
        'defaultLimit' => 10,
    ]
];

3. 缓存配置 (cache.php)

<?php
return [
    // 默认缓存驱动
    'default' => env('cache.driver', 'redis'),
    // 缓存连接配置
    'stores'  => [
        'file' => [
            'type'       => 'File',
            'path'       => app()->getRuntimePath() . 'cache/',
            'prefix'     => '',
            'expire'     => 0,
            'serialize'  => [],
        ],
        'redis' => [
            'type'       => 'redis',
            'host'       => env('redis.redis_hostname', '127.0.0.1'),
            'port'       => env('redis.port', '6379'),
            'password'   => env('redis.redis_password', ''),
            'select'     => env('redis.select', 0),
            'timeout'    => 0,
            'expire'     => 0,
            'persistent' => false,
            'prefix'     => env('redis.prefix', 'crmeb:'),
        ],
    ],
];

4. 队列配置 (queue.php)

<?php
return [
    // 默认队列连接
    'default'     => 'redis',
    // 队列连接配置
    'connections' => [
        'sync'     => [
            'type' => 'sync',
        ],
        'database' => [
            'type'  => 'database',
            'queue' => 'default',
            'table' => 'jobs',
        ],
        'redis'    => [
            'type'       => 'redis',
            'queue'      => 'default',
            'host'       => env('redis.redis_hostname', '127.0.0.1'),
            'port'       => env('redis.port', 6379),
            'password'   => env('redis.redis_password', ''),
            'select'     => env('redis.select', 0),
            'timeout'    => 0,
            'persistent' => false,
        ],
    ],
    'failed'      => [
        'type'  => 'none',
        'table' => 'failed_jobs',
    ],
];

5. 路由配置 (route.php)

<?php
return [
    // pathinfo分隔符
    'pathinfo_depr'         => '/',
    // URL伪静态后缀
    'url_html_suffix'       => 'html',
    // 是否强制使用路由
    'url_route_must'        => true,
    // 路由完全匹配
    'route_complete_match'  => true,
    // 是否开启路由缓存
    'route_check_cache'     => false,
    // 访问控制器层名称
    'controller_layer'      => 'controller',
    // 空控制器名
    'empty_controller'      => 'Error',
    // 默认控制器名
    'default_controller'    => 'Index',
    // 默认操作名
    'default_action'        => 'index',
];

6. Session配置 (session.php)

<?php
return [
    // session名称
    'name'       => 'PHPSESSID',
    // session类型
    'type'       => 'file',
    // session存储路径
    'path'       => '',
    // session过期时间
    'expire'     => 1440,
    // session前缀
    'prefix'     => '',
    // 是否使用锁
    'use_lock'   => true,
];
<?php
return [
    // cookie保存时间
    'expire'    => 0,
    // cookie保存路径
    'path'      => '/',
    // cookie有效域名
    'domain'    => '',
    // cookie启用安全传输
    'secure'    => false,
    // httponly设置
    'httponly'  => false,
    // samesite设置
    'samesite'  => '',
    // CORS跨域头配置
    'header'    => [
        'Access-Control-Allow-Origin'      => '*',
        'Access-Control-Allow-Headers'     => 'Authori-zation,Authorization,Content-Type,If-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,X-Requested-With,Form-type',
        'Access-Control-Allow-Methods'     => 'GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE',
        'Access-Control-Max-Age'           => '1728000',
        'Access-Control-Allow-Credentials' => 'true'
    ]
];

8. 日志配置 (log.php)

<?php
return [
    // 默认日志通道
    'default'      => env('log.channel', 'file'),
    // 日志通道配置
    'channels'     => [
        'file' => [
            'type'           => 'File',
            'path'           => app()->getRuntimePath() . 'log/',
            'single'         => false,
            'apart_level'    => ['error', 'sql'],
            'max_files'      => 0,
            'json'           => false,
            'format'         => '[%s][%s] %s',
            'realtime_write' => true,
        ],
    ],
];

9. 支付配置 (pay.php)

<?php
return [
    // 默认支付方式
    'default'     => 'wechat',
    // 支付方式列表
    'payType'     => [
        'weixin'  => '微信支付', 
        'yue'     => '余额支付', 
        'offline' => '线下支付'
    ],
    // 提现方式
    'extractType' => ['alipay', 'bank', 'weixin', 'balance'],
    // 配送方式
    'deliveryType' => [
        'send'    => '商家配送', 
        'express' => '快递配送'
    ],
    // 支付驱动配置
    'stores'      => [
        'wechat'   => [],  // 微信支付
        'routine'  => [],  // 小程序支付
        'wechath5' => [],  // 微信H5支付
        'alipay'   => [],  // 支付宝支付
        'yue'      => [],  // 余额支付
    ]
];

10. 微信配置 (wechat.php)

<?php
return [
    // 公众号配置
    'official' => [
        'app_id'  => '',
        'secret'  => '',
        'token'   => '',
        'aes_key' => '',
    ],
    // 小程序配置
    'mini' => [
        'app_id'  => '',
        'secret'  => '',
    ],
    // 开放平台配置
    'open' => [
        'app_id'     => '',
        'secret'     => '',
        'token'      => '',
        'aes_key'    => '',
    ],
    // 企业微信配置
    'work' => [
        'corp_id'  => '',
        'agent_id' => '',
        'secret'   => '',
        'token'    => '',
        'aes_key'  => '',
    ],
];

11. 短信配置 (sms.php)

<?php
return [
    // 默认短信平台
    'default' => 'yunxin',
    // 短信平台配置
    'stores'  => [
        'yunxin' => [
            'account'  => '',
            'password' => '',
        ],
        'aliyun' => [
            'access_key_id'     => '',
            'access_key_secret' => '',
            'sign_name'         => '',
        ],
        'tencent' => [
            'sdk_app_id' => '',
            'secret_id'  => '',
            'secret_key' => '',
            'sign_name'  => '',
        ],
    ],
    // 短信模板配置
    'template' => [
        'register'       => '',  // 注册验证码
        'login'          => '',  // 登录验证码
        'pay_success'    => '',  // 支付成功
        'deliver_goods'  => '',  // 发货通知
        // ...
    ],
];

12. 上传配置 (upload.php)

<?php
return [
    // 默认上传方式
    'default' => 'local',
    // 上传驱动配置
    'stores'  => [
        'local' => [
            'type' => 'local',
        ],
        'oss' => [
            'type'            => 'oss',
            'accessKey'       => '',
            'secretKey'       => '',
            'bucket'          => '',
            'endpoint'        => '',
            'cdn'             => '',
        ],
        'cos' => [
            'type'      => 'cos',
            'appId'     => '',
            'secretId'  => '',
            'secretKey' => '',
            'bucket'    => '',
            'region'    => '',
            'cdn'       => '',
        ],
        'qiniu' => [
            'type'      => 'qiniu',
            'accessKey' => '',
            'secretKey' => '',
            'bucket'    => '',
            'cdn'       => '',
        ],
    ],
    // 上传限制
    'filesize'     => 2097152,    // 文件大小限制(2MB)
    'fileExt'      => ['jpg', 'jpeg', 'png', 'gif', 'pem', 'mp3', 'wma', 'wav', 'amr', 'mp4', 'key', 'xlsx', 'xls', 'txt'],
    'fileMime'     => ['image/jpeg', 'image/gif', 'image/png', 'text/plain', 'audio/mpeg'],
];

13. Swoole配置 (swoole.php)

<?php
return [
    // HTTP服务配置
    'server' => [
        'host'      => env('swoole.host', '0.0.0.0'),
        'port'      => env('swoole.port', 20230),
        'mode'      => SWOOLE_PROCESS,
        'sock_type' => SWOOLE_SOCK_TCP,
    ],
    // Swoole运行参数
    'options' => [
        'worker_num'               => swoole_cpu_num(),
        'task_worker_num'          => swoole_cpu_num(),
        'daemonize'                => false,
        'pid_file'                 => runtime_path() . 'swoole.pid',
        'log_file'                 => runtime_path() . 'swoole.log',
        'max_request'              => 10000,
        'task_max_request'         => 10000,
        'dispatch_mode'            => 2,
        'enable_static_handler'    => true,
        'document_root'            => root_path('public'),
        'package_max_length'       => 5 * 1024 * 1024,
    ],
    // WebSocket配置
    'websocket' => [
        'enable'        => true,
        'handler'       => \app\webscoket\Manager::class,
        'ping_interval' => 25000,
        'ping_timeout'  => 60000,
        'room' => [
            'type'  => 'table',
            'table' => [
                'room_rows'   => 8192,
                'room_size'   => 2048,
                'client_rows' => 8192,
                'client_size' => 2048,
            ],
        ],
    ],
];

环境变量配置

.env文件配置

APP_DEBUG = true
APP_TRACE = false

[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
APP_KEY = your_app_key_here

[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = crmeb
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
CHARSET = utf8mb4
PREFIX = eb_
DEBUG = true

[REDIS]
REDIS_HOSTNAME = 127.0.0.1
PORT = 6379
REDIS_PASSWORD = 
SELECT = 0
PREFIX = crmeb:

[CACHE]
DRIVER = redis

[LOG]
CHANNEL = file

[SWOOLE]
HOST = 0.0.0.0
PORT = 20230

获取配置值

1. 使用Config门面

use think\facade\Config;

// 获取配置值
$value = Config::get('database.connections.mysql.hostname');

// 获取配置值,带默认值
$value = Config::get('custom.key', 'default_value');

// 判断配置是否存在
if (Config::has('database.connections.mysql')) {
    // ...
}

2. 使用config()助手函数

// 获取配置值
$hostname = config('database.connections.mysql.hostname');

// 获取整个配置文件
$database = config('database');

// 带默认值
$value = config('custom.key', 'default');

3. 使用env()助手函数

// 获取环境变量
$debug = env('APP_DEBUG', false);
$hostname = env('database.hostname', '127.0.0.1');

系统配置(数据库)

系统还支持从数据库读取配置:

// 使用sys_config()助手函数
$siteName = sys_config('site_name');
$siteUrl = sys_config('site_url');

// 获取多个配置
$configs = sys_config(['site_name', 'site_url', 'site_logo']);

自定义配置

1. 创建配置文件

config/ 目录下创建新的配置文件:

<?php
// config/custom.php
return [
    'key1' => 'value1',
    'key2' => [
        'sub_key1' => 'sub_value1',
        'sub_key2' => 'sub_value2',
    ],
];

2. 读取自定义配置

$value = config('custom.key1');
$subValue = config('custom.key2.sub_key1');

注意事项

  1. 敏感信息:数据库密码、API密钥等敏感信息应放在 .env 文件中
  2. .env文件.env 文件不应提交到版本控制系统
  3. 配置优先级:环境变量 > 配置文件
  4. 缓存配置:生产环境建议开启配置缓存:php think config:cache
  5. 清除缓存:修改配置后清除缓存:php think config:clear

常见问题

Q: 配置文件修改后不生效?

A: 可能是开启了配置缓存,执行 php think config:clear 清除缓存

Q: 如何在不同环境使用不同配置?

A: 使用 .env 文件配置环境变量,不同环境使用不同的 .env 文件

Q: 数据库配置如何读写分离?

A: 设置 deploy => 1rw_separate => true,配置多个数据库地址

{{cateWiki.like_num}}人点赞
0人点赞
评论({{cateWiki.comment_num}}) {{commentWhere.order ? '评论从旧到新':'评论从新到旧'}} {{cateWiki.page_view_num}}人看过该文档
评论(0) {{commentWhere.order ? '评论从旧到新':'评论从新到旧'}} 14人看过该文档
评论
{{item.user ? item.user.nickname : ''}} (自评)
{{item.content}}
{{item.create_time}} 删除
{{item.like ? item.like.like_num : 0}} {{replyIndex == index ? '取消回复' : '回复'}}
评论
{{items.user ? items.user.nickname : '暂无昵称'}} (自评)
{{items.content}}
{{items.create_time}} 删除
{{items.like ? items.like.like_num : 0}} {{replyIndexJ == (index+'|'+indexJ) ? '取消回复' : '回复'}}
评论
目录
  • {{item}}