[ 'name' => 'fc_miniapp', 'title' => '小程序配置', 'active' => false, 'list' => [ self::item('fc_base_appName', '小程序名称', 'string', $pick('base.appName', ''), '显示在小程序首页与分享卡片', 'required'), self::item('fc_base_logo', '小程序LOGO', 'image', $pick('base.logo', ''), '留空时使用默认 LOGO'), self::item('fc_base_servicePhone', '客服电话', 'string', $pick('base.servicePhone', ''), '展示在小程序「联系客服」入口'), self::item('fc_base_shareTitle', '分享标题', 'string', $pick('base.shareTitle', ''), '留空则默认使用小程序名称'), self::item('fc_base_aboutUs', '关于我们', 'text', $pick('base.aboutUs', ''), '展示在小程序「关于我们」页面'), self::item('fc_wx_appid', '小程序 AppID', 'string', $pick('wx.appid', ''), '微信公众平台 → 开发管理 → 开发设置 → AppID(微信登录用)'), self::item('fc_wx_secret', 'AppSecret', 'password', '', '仅服务端保存与调用;已配置时留空表示不修改(微信登录用)'), self::item('fc_wx_tplAudit', '审核结果模板 ID', 'string', $pick('wx.tplAudit', ''), '小程序订阅消息:审核结果通知(公众平台 → 订阅消息)'), self::item('fc_wx_tplTransfer', '提现到账模板 ID', 'string', $pick('wx.tplTransfer', ''), '小程序订阅消息:提现到账通知'), self::item('fc_admin_userIds', '后台接口管理员 ID', 'string', $pick('admin.userIds', ''), '允许调用 /api/v1/admin/** 的用户 ID,多个用逗号分隔(留空 = 全部禁止)'), self::item('fc_admin_mobiles', '后台接口管理员手机号', 'string', $pick('admin.mobiles', ''), '允许调用管理接口的手机号,多个用逗号分隔'), ], ], 'fc_publish' => [ 'name' => 'fc_publish', 'title' => '发布配置', 'active' => false, 'list' => [ self::item('fc_post_mode', '发布模式', 'radio', $pick('post.mode', 'free'), '免费发布不收费;付费发布按价格计费', 'required', [ 'free' => '免费发布', 'paid' => '付费发布', ]), self::item('fc_post_freeQuota', '免费条数', 'number', $pick('post.freeQuota', '0'), '付费模式下免费发布的条数,0 = 不限制', 'required;number'), self::item('fc_post_freeQuotaCycle', '统计周期', 'select', $pick('post.freeQuotaCycle', 'day'), '免费条数的统计周期', 'required', [ 'day' => '每日', 'month' => '每月', 'total' => '累计', ]), self::item('fc_post_singlePrice', '单条价格', 'number', $pick('post.singlePrice', '5'), '未开通套餐时的单条发布价格(元)', 'required;number'), self::item('fc_post_monthPrice', '月卡价格', 'number', $pick('post.monthPrice', '19.9'), '会员月卡价格(元),保存后同步会员套餐', 'required;number'), self::item('fc_post_monthQuota', '月卡条数', 'number', $pick('post.monthQuota', '30'), '月卡包含的发布条数', 'required;number'), self::item('fc_post_yearPrice', '年卡价格', 'number', $pick('post.yearPrice', '168'), '会员年卡价格(元),保存后同步会员套餐', 'required;number'), self::item('fc_post_yearQuota', '年卡条数', 'number', $pick('post.yearQuota', '500'), '年卡包含的发布条数', 'required;number'), ], ], 'fc_dist' => [ 'name' => 'fc_dist', 'title' => '分销配置', 'active' => false, 'list' => [ self::item('fc_dist_enabled', '开启分销', 'switch', $pick('dist.enabled', '1'), '关闭后不再产生新的分销佣金'), self::item('fc_dist_level', '分佣层级', 'select', $pick('dist.level', '2'), '最多计算到第几级上级', 'required', [ '1' => '一级', '2' => '二级', ]), self::item('fc_dist_level1Rate', '一级比例', 'number', $pick('dist.level1Rate', '20'), '一级上级分佣比例(%)', 'required;number'), self::item('fc_dist_level2Rate', '二级比例', 'number', $pick('dist.level2Rate', '10'), '二级上级分佣比例(%)', 'required;number'), self::item('fc_dist_settleCycle', '结算周期', 'string', $pick('dist.settleCycle', 'T+7'), '如 T+7,展示给分销员'), self::item('fc_dist_minWithdraw', '最低提现', 'number', $pick('dist.minWithdraw', '50'), '最低提现金额(元)', 'required;number'), ], ], ]; } /** * 保存业务配置(由系统配置页提交) * * @param array $row 系统配置页提交的 row 数组 * @return void * @throws \Exception */ public static function save(array $row) { $has = function ($prefix) use ($row) { foreach ($row as $key => $value) { if (strpos($key, $prefix) === 0) { return true; } } return false; }; if ($has('fc_base_')) { self::saveBase($row); } if ($has('fc_post_')) { self::savePublish($row); } if ($has('fc_dist_')) { self::saveDistribution($row); } } /** * 小程序基础信息 * * @param array $row * @return void * @throws \Exception */ protected static function saveBase(array $row) { $appName = isset($row['fc_base_appName']) ? trim((string)$row['fc_base_appName']) : ''; if ($appName === '') { throw new \Exception('小程序名称不能为空'); } $values = [ 'base.appName' => $appName, 'base.logo' => isset($row['fc_base_logo']) ? trim((string)$row['fc_base_logo']) : '', 'base.servicePhone' => isset($row['fc_base_servicePhone']) ? trim((string)$row['fc_base_servicePhone']) : '', 'base.shareTitle' => isset($row['fc_base_shareTitle']) ? trim((string)$row['fc_base_shareTitle']) : '', 'base.aboutUs' => isset($row['fc_base_aboutUs']) ? trim((string)$row['fc_base_aboutUs']) : '', ]; foreach ($values as $key => $value) { self::put($key, $value, 'base', '小程序配置'); } // 兼容旧 ui.* 键:名称/LOGO 同步一份,避免旧数据在用户端回落时“复活” self::put('ui.siteName', $appName, 'ui', '站点名称'); self::put('ui.logo', $values['base.logo'], 'ui', '自定义LOGO'); // 微信登录参数(真源同为 fa_fc_config,由 WxMini 读取): // AppSecret 不回显、留空表示不修改,避免表单提交把已保存的密钥冲成空串 $wxAppid = isset($row['fc_wx_appid']) ? trim((string)$row['fc_wx_appid']) : ''; if ($wxAppid !== '') { self::put('wx.appid', $wxAppid, 'wx', '小程序AppID(微信登录用)'); } $wxSecret = isset($row['fc_wx_secret']) ? trim((string)$row['fc_wx_secret']) : ''; if ($wxSecret !== '') { self::put('wx.secret', $wxSecret, 'wx', '小程序AppSecret(仅服务端持有,不下发前端)'); } // 管理接口白名单(/api/v1/admin/**):留空表示不允许任何小程序端账号调用 if (array_key_exists('fc_admin_userIds', $row)) { self::put('admin.userIds', trim((string)$row['fc_admin_userIds']), 'admin', '管理接口允许的用户ID(逗号分隔)'); } if (array_key_exists('fc_admin_mobiles', $row)) { self::put('admin.mobiles', trim((string)$row['fc_admin_mobiles']), 'admin', '管理接口允许的手机号(逗号分隔)'); } // 订阅消息模板 ID if (array_key_exists('fc_wx_tplAudit', $row)) { self::put('wx.tplAudit', trim((string)$row['fc_wx_tplAudit']), 'wx', '审核结果订阅消息模板ID'); } if (array_key_exists('fc_wx_tplTransfer', $row)) { self::put('wx.tplTransfer', trim((string)$row['fc_wx_tplTransfer']), 'wx', '提现到账订阅消息模板ID'); } } /** * 发布模式与价格(同时同步会员套餐 M1/M12) * * @param array $row * @return void * @throws \Exception */ protected static function savePublish(array $row) { $mode = isset($row['fc_post_mode']) ? trim((string)$row['fc_post_mode']) : 'free'; if (!in_array($mode, ['free', 'paid'], true)) { throw new \Exception('发布模式只支持「免费发布」或「付费发布」'); } $cycle = isset($row['fc_post_freeQuotaCycle']) ? trim((string)$row['fc_post_freeQuotaCycle']) : 'day'; if (!in_array($cycle, ['day', 'month', 'total'], true)) { throw new \Exception('免费条数统计周期只支持「每日 / 每月 / 累计」'); } $num = function ($key, $default) use ($row) { if (!isset($row[$key]) || $row[$key] === '') { return $default; } return round((float)$row[$key], 2); }; $int = function ($key, $default) use ($row) { if (!isset($row[$key]) || $row[$key] === '') { return $default; } return (int)$row[$key]; }; $single = $num('fc_post_singlePrice', 5); $monthPrice = $num('fc_post_monthPrice', 19.9); $yearPrice = $num('fc_post_yearPrice', 168); $monthQuota = $int('fc_post_monthQuota', 30); $yearQuota = $int('fc_post_yearQuota', 500); $freeQuota = $int('fc_post_freeQuota', 0); foreach (['单条发布价格' => $single, '月卡价格' => $monthPrice, '年卡价格' => $yearPrice] as $label => $value) { if ($value < 0) { throw new \Exception($label . '不能为负'); } } if ($monthQuota < 0 || $yearQuota < 0) { throw new \Exception('含发布条数不能为负'); } if ($freeQuota < 0) { throw new \Exception('免费发布条数不能为负(0 表示不限制)'); } $values = [ 'post.mode' => $mode, 'post.singlePrice' => $single, 'post.freeQuota' => $freeQuota, 'post.freeQuotaCycle' => $cycle, 'post.monthPrice' => $monthPrice, 'post.monthQuota' => $monthQuota, 'post.yearPrice' => $yearPrice, 'post.yearQuota' => $yearQuota, ]; foreach ($values as $key => $value) { self::put($key, $value, 'post', '发布配置'); } // 与会员套餐保持一致(后台「运营推广 → 会员套餐」仍可单独维护,但价格/条数以本页为准) $now = time(); Db::name('fc_plan')->where('plan_code', 'M1')->update([ 'price' => $monthPrice, 'post_quota' => $monthQuota, 'updatetime' => $now, ]); Db::name('fc_plan')->where('plan_code', 'M12')->update([ 'price' => $yearPrice, 'post_quota' => $yearQuota, 'updatetime' => $now, ]); } /** * 分销参数 * * @param array $row * @return void * @throws \Exception */ protected static function saveDistribution(array $row) { $enabled = isset($row['fc_dist_enabled']) ? (int)$row['fc_dist_enabled'] : 1; $level = isset($row['fc_dist_level']) ? (int)$row['fc_dist_level'] : 2; $rate1 = isset($row['fc_dist_level1Rate']) ? round((float)$row['fc_dist_level1Rate'], 2) : 20; $rate2 = isset($row['fc_dist_level2Rate']) ? round((float)$row['fc_dist_level2Rate'], 2) : 10; $settle = isset($row['fc_dist_settleCycle']) ? trim((string)$row['fc_dist_settleCycle']) : 'T+7'; $minWithdraw = isset($row['fc_dist_minWithdraw']) ? round((float)$row['fc_dist_minWithdraw'], 2) : 50; if (!in_array($level, [1, 2], true)) { throw new \Exception('分佣层级只支持一级或二级'); } if ($rate1 < 0 || $rate1 > 100 || $rate2 < 0 || $rate2 > 100) { throw new \Exception('分佣比例必须在 0-100 之间'); } if ($minWithdraw < 0) { throw new \Exception('最低提现金额不能为负'); } if ($settle === '') { $settle = 'T+7'; } $values = [ 'dist.enabled' => $enabled ? 1 : 0, 'dist.level' => $level, 'dist.level1Rate' => $rate1, 'dist.level2Rate' => $rate2, 'dist.settleCycle' => $settle, 'dist.minWithdraw' => $minWithdraw, ]; foreach ($values as $key => $value) { self::put($key, $value, 'dist', '分销配置'); } } /** * 读取 fc_config 全部配置 * * @return array */ protected static function values() { $result = []; try { foreach (Db::name('fc_config')->select() as $row) { $result[$row['key']] = $row['value']; } } catch (\Exception $e) { // 业务表尚未初始化时,系统配置页仍可正常打开(使用默认值) } return $result; } /** * 写入单项配置 * * @param string $key * @param mixed $value * @param string $group * @param string $remark * @return void */ protected static function put($key, $value, $group, $remark) { $now = time(); $value = is_scalar($value) || $value === null ? (string)$value : json_encode($value, JSON_UNESCAPED_UNICODE); $exist = Db::name('fc_config')->where('key', $key)->find(); if ($exist) { Db::name('fc_config')->where('key', $key)->update([ 'value' => $value, 'group_key' => $group, 'remark' => $remark, 'updatetime' => $now, ]); } else { Db::name('fc_config')->insert([ 'key' => $key, 'value' => $value, 'group_key' => $group, 'remark' => $remark, 'createtime' => $now, 'updatetime' => $now, ]); } } /** * 构造系统配置页的单个配置项 * * @param string $name * @param string $title * @param string $type * @param mixed $value * @param string $tip * @param string $rule * @param array $content * @return array */ protected static function item($name, $title, $type, $value, $tip = '', $rule = '', array $content = []) { return [ 'name' => $name, 'title' => $title, 'type' => $type, 'value' => $value, 'content' => $content, 'tip' => $tip, 'rule' => $rule, 'extend' => '', 'extend_html' => '', 'setting' => [], 'visible' => '', 'id' => 0, ]; } }