文件
fenleixinxi/application/admin/controller/fc/Post.php
linda 043227dee7 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
2026-10-15 23:24:03 +08:00

155 行
5.3 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\admin\controller\fc;
use app\common\controller\Backend;
use think\Db;
/**
* 同城-信息
*
* @icon fa fa-circle-o
*/
class Post extends Backend
{
/**
* FcPost模型对象
* @var \app\admin\model\FcPost
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\FcPost;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 审核信息
*/
public function audit()
{
$ids = $this->request->post('ids');
$auditStatus = (int)$this->request->post('auditStatus');
$reason = $this->request->post('reason', '');
if (!in_array($auditStatus, [1, 2])) {
$this->error('审核状态仅支持通过(1)/驳回(2)');
}
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
$ids = array_filter($ids);
if (!$ids) {
$this->error('请选择要审核的信息');
}
$posts = Db::name('fc_post')->where('id', 'in', $ids)->select();
if (!$posts) {
$this->error('信息不存在');
}
foreach ($posts as $post) {
Db::name('fc_post')->where('id', $post['id'])->update([
'audit_status' => $auditStatus,
'audit_reason' => $reason,
'updatetime' => time(),
]);
if ($auditStatus === 1 && !empty($post['category_id'])) {
Db::name('fc_category')->where('id', $post['category_id'])->setInc('post_count');
}
Db::name('fc_message')->insert([
'user_id' => $post['user_id'],
'type' => 'system',
'title' => $auditStatus === 1 ? '审核通过' : '审核驳回',
'content' => $auditStatus === 1
? '您发布的信息「' . $post['title'] . '」已审核通过'
: '您发布的信息「' . $post['title'] . '」审核未通过' . ($reason ? ',原因:' . $reason : ''),
'isread' => 0,
'createtime' => time(),
]);
}
$this->success('审核成功');
}
/**
* 置顶 / 取消置顶(支持批量)
* POST fc/post/top {ids:'1,2', isTop:1|0}
* 说明:置顶信息在用户端主页与列表**排在非置顶之前**(Home::feed / Post::mine 均按 is_top desc 排序)
*/
public function top()
{
$ids = $this->request->post('ids');
$isTop = (int)$this->request->post('isTop', 1);
if (!in_array($isTop, [0, 1], true)) {
$this->error('置顶状态仅支持置顶(1)/取消置顶(0)');
}
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
$ids = array_filter($ids);
if (!$ids) {
$this->error('请选择要操作的信息');
}
$posts = Db::name('fc_post')->where('id', 'in', $ids)->select();
if (!$posts) {
$this->error('信息不存在');
}
foreach ($posts as $post) {
Db::name('fc_post')->where('id', $post['id'])->update([
'is_top' => $isTop,
'updatetime' => time(),
]);
Db::name('fc_message')->insert([
'user_id' => $post['user_id'],
'type' => 'system',
'title' => $isTop === 1 ? '信息已置顶' : '已取消置顶',
'content' => $isTop === 1
? '您发布的信息「' . $post['title'] . '」已被置顶,将在首页优先展示'
: '您发布的信息「' . $post['title'] . '」已取消置顶',
'isread' => 0,
'createtime' => time(),
]);
}
$this->success($isTop === 1 ? '置顶成功' : '已取消置顶');
}
/**
* 下架信息
*/
public function offline()
{
$ids = $this->request->post('ids');
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
$ids = array_filter($ids);
if (!$ids) {
$this->error('请选择要下架的信息');
}
$posts = Db::name('fc_post')->where('id', 'in', $ids)->select();
if (!$posts) {
$this->error('信息不存在');
}
foreach ($posts as $post) {
Db::name('fc_post')->where('id', $post['id'])->update([
'status' => 0,
'updatetime' => time(),
]);
Db::name('fc_message')->insert([
'user_id' => $post['user_id'],
'type' => 'system',
'title' => '信息已下架',
'content' => '您发布的信息「' . $post['title'] . '」已被下架',
'isread' => 0,
'createtime' => time(),
]);
}
$this->success('下架成功');
}
}