feat(admin): 信息置顶 + 发布与费用配置(免费/付费开关、单条与月年卡价格含条数)

需求落地:
- 置顶:fc/post 新增 top 动作(批量置顶/取消置顶 + 站内消息通知),列表加「置顶/取消置顶」工具栏按钮、
  行内按钮与置顶状态徽章;置顶信息在用户端首页与「我的发布」中优先展示(Home::feed 按 is_top desc)
- 发布与费用配置(新增页面:同城业务 → 基础数据 → 发布与费用配置,fc/publish):
  发布模式(免费发布 / 付费发布)、会员单条发布价格、按月(价格 + 含条数)、按年(价格 + 含条数);
  真源为 fc_config 的 post.*,保存时同步 fc_plan 的月卡(M1)/年卡(M12) 价格与 post_quota
- FcInstall:新增 post.* 六项配置(默认免费发布,避免上线即撞付费墙);fc_user_ext 加 post_quota_left /
  post_quota_expire(套餐额度与有效期)、fc_plan 加 post_quota;新增 upgradePublish() 幂等升级老库并同步月/年卡
- tools/verify-api.mjs:新增 P9 发布配置 / P8 我的发布 契约校验,P1 发布改为「免费模式/额度内发布」并按付费模式容错
- 语言包与视图同步中文,均通过 php -l 与 node --check
这个提交包含在:
linda
2026-10-15 23:24:03 +08:00
父节点 f806dc269b
当前提交 043227dee7
共有 13 个文件被更改,包括 844 次插入 和 34 次删除

查看文件

@@ -77,6 +77,9 @@ class FcInstall extends Command
$output->writeln('==> 轮播底色与春绿主题对齐');
$this->upgradeBanners($output);
$output->writeln('==> 发布模式与发布套餐升级');
$this->upgradePublish($output);
$output->writeln('==> 初始化后台菜单');
$this->menu($output);
@@ -133,6 +136,121 @@ class FcInstall extends Command
: ' - 轮播底色已是春绿渐变或非内置轮播,无需处理');
}
/**
* 发布模式与发布套餐升级(幂等,可重复执行)
*
* 背景:v1.0.7 新增「免费发布 / 付费发布」开关与付费发布的三档定价
* · 单条价格 post.singlePrice
* · 按月(价格 + 含条数)post.monthPrice / post.monthQuota
* · 按年(价格 + 含条数)post.yearPrice / post.yearQuota
* 老库缺列/缺配置时补齐,**不覆盖运营已改过的值**:
* ① fc_user_ext 补 post_quota_left / post_quota_expire(剩余发布条数 + 有效期)
* ② fc_plan 补 post_quota(套餐含发布条数,月/年卡赠送额度)
* ③ fc_config 补 post.* 六项(已存在则跳过)
* ④ 月卡/年卡的价格与条数以配置为准做一次同步(配置缺失时反向用套餐值填配置)
*/
private function upgradePublish(Output $output)
{
$prefix = \think\Config::get('database.prefix');
$changed = 0;
// ① 用户扩展表:发布额度
$extTable = $prefix . 'fc_user_ext';
if (!$this->hasColumn($extTable, 'post_quota_left')) {
Db::execute("ALTER TABLE `{$extTable}` ADD COLUMN `post_quota_left` int(10) NOT NULL DEFAULT 0"
. " COMMENT '剩余发布条数(月/年套餐赠送)' AFTER `free_view_used`");
$output->writeln(' - ' . $extTable . ' 新增列 post_quota_left');
$changed++;
}
if (!$this->hasColumn($extTable, 'post_quota_expire')) {
Db::execute("ALTER TABLE `{$extTable}` ADD COLUMN `post_quota_expire` int(10) NULL"
. " COMMENT '发布额度有效期(=会员到期时间)' AFTER `post_quota_left`");
$output->writeln(' - ' . $extTable . ' 新增列 post_quota_expire');
$changed++;
}
// ② 会员套餐:含发布条数
$planTable = $prefix . 'fc_plan';
if (!$this->hasColumn($planTable, 'post_quota')) {
Db::execute("ALTER TABLE `{$planTable}` ADD COLUMN `post_quota` int(10) NOT NULL DEFAULT 0"
. " COMMENT '含发布条数(月/年套餐赠送额度)' AFTER `days`");
$output->writeln(' - ' . $planTable . ' 新增列 post_quota');
$changed++;
}
// ③ 配置项(只补缺失的,不覆盖运营已改的值)
$defaults = [
['post.mode', 'free', 'post', '发布模式:free 免费发布 / paid 付费发布'],
['post.singlePrice', '5', 'post', '单条发布价格(元)'],
['post.monthPrice', '19.9', 'post', '按月发布价格(元)'],
['post.monthQuota', '30', 'post', '按月含发布条数'],
['post.yearPrice', '168', 'post', '按年发布价格(元)'],
['post.yearQuota', '500', 'post', '按年含发布条数'],
];
$now = time();
$added = [];
foreach ($defaults as $d) {
if (Db::name('fc_config')->where('key', $d[0])->find()) {
continue;
}
Db::name('fc_config')->insert([
'key' => $d[0], 'value' => $d[1], 'group_key' => $d[2], 'remark' => $d[3],
'createtime' => $now, 'updatetime' => $now,
]);
$added[] = $d[0];
}
if ($added) {
$output->writeln(' - 新增配置 ' . count($added) . ' 项:' . implode(' / ', $added));
$changed++;
}
// ④ 月/年卡「价格 + 含发布条数」与配置对齐
$map = ['M1' => ['post.monthPrice', 'post.monthQuota'], 'M12' => ['post.yearPrice', 'post.yearQuota']];
$synced = 0;
foreach ($map as $code => $keys) {
$plan = Db::name('fc_plan')->where('plan_code', $code)->find();
if (!$plan) {
continue;
}
$price = round((float)$this->cfgValue($keys[0], $plan['price']), 2);
$quota = (int)$this->cfgValue($keys[1], $plan['post_quota']);
if (round((float)$plan['price'], 2) !== $price || (int)$plan['post_quota'] !== $quota) {
Db::name('fc_plan')->where('id', $plan['id'])->update([
'price' => $price,
'post_quota' => $quota,
'updatetime' => time(),
]);
$synced++;
}
}
if ($synced) {
$output->writeln(' - 会员套餐已与发布配置对齐 ' . $synced . ' 条(月/年卡价格与含条数)');
$changed++;
}
$output->writeln($changed
? ' - 完成(发布模式 ' . $this->cfgValue('post.mode', 'free') . ')'
: ' - 发布模式与套餐配置已是最新,无需处理');
}
/** 表是否存在某列 */
private function hasColumn($table, $column)
{
$cols = Db::query("SHOW COLUMNS FROM `{$table}` LIKE '" . addslashes($column) . "'");
return !empty($cols);
}
/** 读配置默认值(不依赖 api 基类的 cfg 缓存) */
private function cfgValue($key, $default = null)
{
$row = Db::name('fc_config')->where('key', $key)->find();
if (!$row || $row['value'] === '' || $row['value'] === null) {
return $default;
}
return $row['value'];
}
/**
* 初始化 FastAdmin 后台菜单(幂等)
*
@@ -211,6 +329,7 @@ class FcInstall extends Command
'fc/distrelation' => ['fc/dist', '分销关系', 'fa fa-sitemap', 95],
'fc/withdraw' => ['fc/dist', '提现审核', 'fa fa-credit-card', 90],
'fc/area' => ['fc/base', '服务区域', 'fa fa-map-o', 95],
'fc/publish' => ['fc/base', '发布与费用配置', 'fa fa-cny', 85],
'fc/draft' => ['fc/base', '草稿箱', 'fa fa-folder-o', 90],
];
$done = 0;
@@ -422,6 +541,7 @@ class FcInstall extends Command
`price` decimal(10,2) NOT NULL DEFAULT '0.00',
`origin_price` decimal(10,2) NOT NULL DEFAULT '0.00',
`days` int(10) NOT NULL DEFAULT '30',
`post_quota` int(10) NOT NULL DEFAULT '0' COMMENT '含发布条数(月/年套餐赠送额度)',
`tag` varchar(16) NOT NULL DEFAULT '',
`sort` int(10) NOT NULL DEFAULT '0',
`enabled` tinyint(1) NOT NULL DEFAULT '1',
@@ -444,6 +564,8 @@ class FcInstall extends Command
`inviter_id` int(10) unsigned NOT NULL DEFAULT '0',
`free_view_date` varchar(10) NOT NULL DEFAULT '' COMMENT '免费查看额度基准日',
`free_view_used` int(10) NOT NULL DEFAULT '0',
`post_quota_left` int(10) NOT NULL DEFAULT '0' COMMENT '剩余发布条数(月/年套餐赠送)',
`post_quota_expire` int(10) DEFAULT NULL COMMENT '发布额度有效期(=会员到期时间)',
`createtime` int(10) DEFAULT NULL,
`updatetime` int(10) DEFAULT NULL,
PRIMARY KEY (`id`),
@@ -565,6 +687,13 @@ class FcInstall extends Command
['fee.memberMonth', '19.9', 'fee', '月卡价格'],
['fee.memberQuarter', '49.9', 'fee', '季卡价格'],
['fee.memberYear', '168', 'fee', '年卡价格'],
// 发布模式与发布套餐(后台「发布与费用配置」页维护;真源=配置,保存时同步 fc_plan)
['post.mode', 'free', 'post', '发布模式:free 免费发布 / paid 付费发布(默认免费,避免上线即撞付费墙)'],
['post.singlePrice', '5', 'post', '单条发布价格(元)'],
['post.monthPrice', '19.9', 'post', '按月发布价格(元)'],
['post.monthQuota', '30', 'post', '按月含发布条数'],
['post.yearPrice', '168', 'post', '按年发布价格(元)'],
['post.yearQuota', '500', 'post', '按年含发布条数'],
['dist.enabled', '1', 'dist', '是否开启分销'],
['dist.level', '2', 'dist', '分佣层级'],
['dist.level1Rate', '20', 'dist', '一级分佣比例%'],
@@ -629,14 +758,15 @@ class FcInstall extends Command
/* ---------- 会员套餐 ---------- */
$plans = [
['M1', '月卡', 19.9, 29.9, 30, '尝鲜'],
['M3', '季卡', 49.9, 89.7, 90, '最划算'],
['M12', '年卡', 168, 358.8, 365, '省心'],
['M1', '月卡', 19.9, 29.9, 30, '尝鲜', 30],
['M3', '季卡', 49.9, 89.7, 90, '最划算', 90],
['M12', '年卡', 168, 358.8, 365, '省心', 500],
];
foreach ($plans as $i => $p) {
Db::name('fc_plan')->insert([
'plan_code' => $p[0], 'name' => $p[1], 'price' => $p[2], 'origin_price' => $p[3],
'days' => $p[4], 'tag' => $p[5], 'sort' => $i + 1, 'enabled' => 1,
'post_quota' => $p[6],
'createtime' => $now, 'updatetime' => $now,
]);
}