本功能提供了微信小程序和抖音小程序平台配置的管理界面,包括:
在FastAdmin后台菜单管理中添加以下菜单项:
-- 主菜单
INSERT INTO `fa_auth_rule` (`name`, `title`, `type`, `status`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`) VALUES
('platform', '平台配置', 'file', 'normal', '', '多平台配置管理', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 100);
-- 平台配置列表
INSERT INTO `fa_auth_rule` (`name`, `title`, `type`, `status`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`) VALUES
('platform/index', '平台列表', 'file', 'normal', '', '查看平台配置列表', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 99);
-- 微信小程序配置
INSERT INTO `fa_auth_rule` (`name`, `title`, `type`, `status`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`) VALUES
('platform/wechat_mini_program', '微信小程序', 'file', 'normal', '', '微信小程序配置', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 98);
-- 抖音小程序配置
INSERT INTO `fa_auth_rule` (`name`, `title`, `type`, `status`, `condition`, `remark`, `ismenu`, `createtime`, `updatetime`, `weigh`) VALUES
('platform/douyin_mini_program', '抖音小程序', 'file', 'normal', '', '抖音小程序配置', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 97);
需要将子菜单的pid
字段设置为主菜单的id
值:
-- 获取主菜单ID
SELECT id FROM `fa_auth_rule` WHERE name = 'platform';
-- 假设主菜单ID为123,更新子菜单的pid
UPDATE `fa_auth_rule` SET `pid` = 123 WHERE `name` IN ('platform/index', 'platform/wechat_mini_program', 'platform/douyin_mini_program');
-- 为超级管理员分配权限(假设管理员组ID为1)
INSERT INTO `fa_auth_group_access` (`uid`, `group_id`) VALUES (1, 1);
运行 install_platform_config.sql
文件来初始化配置数据:
mysql -u username -p database_name < install_platform_config.sql
访问后台URL:/admin/platform/init_config
,通过界面初始化配置数据。
登录FastAdmin后台,在左侧菜单找到"平台配置":
use app\common\model\Config;
// 获取微信小程序配置
$wechatConfig = Config::getConfigByGroup('shop.platform.WechatMiniProgram');
// 获取抖音小程序配置
$douyinConfig = Config::getConfigByGroup('shop.platform.DouyinMiniProgram');
use app\common\model\Config;
// 判断微信小程序是否开启
$wechatStatus = Config::getConfigValue('shop.platform.WechatMiniProgram.status');
if ($wechatStatus) {
// 微信小程序已开启
}
// 判断抖音小程序是否开启
$douyinStatus = Config::getConfigValue('shop.platform.DouyinMiniProgram.status');
if ($douyinStatus) {
// 抖音小程序已开启
}
use app\common\model\Config;
// 获取微信小程序登录配置
$autoLogin = Config::getConfigValue('shop.platform.WechatMiniProgram.auto_login');
$bindMobile = Config::getConfigValue('shop.platform.WechatMiniProgram.bind_mobile');
if ($autoLogin) {
// 启用自动登录
}
if ($bindMobile) {
// 需要绑定手机号
}
如需添加更多平台(如支付宝小程序、QQ小程序等),可以:
getPlatformConfigData
方法中添加对应的配置数据例如添加支付宝小程序:
public function alipay_mini_program()
{
$group = 'shop.platform.AlipayMiniProgram';
return $this->platformConfig($group, '支付宝小程序配置');
}