安全(P0) - 发布包签名:新增 scripts/package_keygen.php、scripts/package_verify.php、 ywxapp\service\PackageVerifier;FrameworkService::apply() 解压前强制验签 (ywxapp.framework_package_verify,默认开启) - JWT 收紧:config/jwt.php 移除公开默认密钥,JwtService::assertStrongSecret() 校验非空 / 长度≥32 / 已知弱值;.env.production.example 键名由 JWT_SECRET_KEY 修正为 JWT_SECRET - /api/v1/Article:免登录白名单收窄为只读接口,写操作字段白名单 + assertOwner() 越权校验 - 开发者令牌:查找接口不再回显明文、统一失败文案 + 限流 - TemplateInstaller:文件名白名单 + realpath 归一化 + 目录内断言,修复 Zip Slip;补 use ZipArchive - 后台登录:接入验证码、失败锁定与登录限流(config/ratelimit.php) - 缓存 / Session 驱动可由 .env 覆盖(CACHE_DRIVER / SESSION_TYPE),集群部署改 redis - paycenter 支付日志开关改为 PAY_LOG,不再跟随 APP_DEBUG 工程化 / 交付 - 新增 CHANGELOG.md 与 .env.production.example;composer.lock 入库锁定依赖版本 - 插件离线安装 CLI 增加 --uid,后台上传安装透传 uid,付费插件授权校验可通过 - 授权拒绝文案区分「未携带 uid」与「未找到有效授权」,便于排障 - .gitignore 放行 .env.production.example / .env.addon.example / .gitattributes / public/.htaccess 结构 - appmall 由 addon/appmall 迁移为独立应用 app/appmall(市场 / 开发者中心 / 审核 / 分润)
152 lines
5.6 KiB
PHP
152 lines
5.6 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Author: ywxapp<admin@ywxapp.cn>
|
||
// +----------------------------------------------------------------------
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace addon\haonav\controller\backend;
|
||
|
||
use think\facade\Db;
|
||
use addon\haonav\model\Apply as ApplyModel;
|
||
use addon\haonav\model\Links as LinksModel;
|
||
use addon\haonav\model\Category as CategoryModel;
|
||
|
||
/**
|
||
* 友链/广告 申请审核
|
||
* 通过友链申请时可指定分类并一键写入 Links(默认待审核状态可直接上架)。
|
||
*/
|
||
class Apply extends HaonavBackend
|
||
{
|
||
|
||
protected $noNeedVerify = [];
|
||
|
||
protected function initialize()
|
||
{
|
||
$this->model = new ApplyModel();
|
||
}
|
||
|
||
public function index()
|
||
{
|
||
if ($this->request->isAjax()) {
|
||
$type = $this->request->param('type', '');
|
||
$status = $this->request->param('status', '');
|
||
$page = $this->request->param('page/d', 1);
|
||
$limit = $this->request->param('limit/d', 20);
|
||
$data = $this->model
|
||
->when($type !== '', fn($q, $v) => $q->where('type', $type))
|
||
->when($status !== '', fn($q, $v) => $q->where('status', $status))
|
||
->order('status', 'asc')->order('id', 'desc')
|
||
->paginate(['page' => $page, 'list_rows' => $limit]);
|
||
$this->result->setCount($data->total());
|
||
$this->result->success($data->items());
|
||
}
|
||
return $this->view->fetch('apply/index');
|
||
}
|
||
|
||
/**
|
||
* 表单辅助数据:分类列表(通过友链时选分类)
|
||
*/
|
||
public function create()
|
||
{
|
||
if ($this->request->isAjax()) {
|
||
$cates = CategoryModel::where('status', 1)
|
||
->order('sort', 'desc')
|
||
->field('id,title')
|
||
->select()
|
||
->toArray();
|
||
$this->result->success($cates);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 通过申请
|
||
* 友链(type=1):可带 cid(分类)与 online(1=直接上架 0=进待审核),自动写入 Links 并回填 link_id
|
||
* 广告(type=2):仅标记通过,商务细节线下沟通后在「广告管理」建广告
|
||
*/
|
||
public function approve()
|
||
{
|
||
if (! ($this->request->isAjax() && $this->request->isPost())) {
|
||
return $this->result->error('请求方式错误');
|
||
}
|
||
$id = (int)$this->request->param('id');
|
||
$reply = (string)$this->request->param('reply', '');
|
||
$model = $this->model->find($id);
|
||
if (! $model) {
|
||
return $this->result->error('数据不存在');
|
||
}
|
||
if ((int)$model->status === ApplyModel::STATUS_APPROVED) {
|
||
return $this->result->error('该申请已通过,请勿重复操作');
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
$linkId = 0;
|
||
if ((int)$model->type === ApplyModel::TYPE_LINK) {
|
||
$cid = (int)$this->request->param('cid/d', 0);
|
||
$online = (int)$this->request->param('online/d', 1);
|
||
if ($cid <= 0) {
|
||
throw new \think\exception\ValidateException('请选择收录分类');
|
||
}
|
||
// 已有同 URL 链接则复用,避免重复收录
|
||
$exists = LinksModel::where('url', $model->url)->find();
|
||
if ($exists) {
|
||
$linkId = (int)$exists->id;
|
||
} else {
|
||
$link = new LinksModel();
|
||
$link->cid = $cid;
|
||
$link->title = $model->title;
|
||
$link->url = $model->url;
|
||
$link->description = (string)$model->description;
|
||
$link->status = $online ? 1 : 2; // 1上架 2待审核
|
||
$link->save();
|
||
$linkId = (int)$link->id;
|
||
}
|
||
}
|
||
$model->status = ApplyModel::STATUS_APPROVED;
|
||
$model->reply = mb_substr($reply, 0, 255);
|
||
$model->link_id = $linkId;
|
||
$model->save();
|
||
Db::commit();
|
||
$this->result->success([], '已通过' . ($linkId ? ',并已收录(links#' . $linkId . ')' : ''));
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
$this->result->error('操作失败: ' . $e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 拒绝申请(可填审核备注)
|
||
*/
|
||
public function reject()
|
||
{
|
||
if (! ($this->request->isAjax() && $this->request->isPost())) {
|
||
return $this->result->error('请求方式错误');
|
||
}
|
||
$id = (int)$this->request->param('id');
|
||
$reply = (string)$this->request->param('reply', '');
|
||
$model = $this->model->find($id);
|
||
if (! $model) {
|
||
return $this->result->error('数据不存在');
|
||
}
|
||
$model->status = ApplyModel::STATUS_REJECTED;
|
||
$model->reply = mb_substr($reply, 0, 255);
|
||
$model->save();
|
||
$this->result->success([], '已拒绝');
|
||
}
|
||
|
||
public function delete()
|
||
{
|
||
$ids = (string)$this->request->param('ids', '');
|
||
$arr = array_values(array_filter(array_map('intval', explode(',', $ids))));
|
||
if (empty($arr)) {
|
||
return $this->result->error('请选择数据');
|
||
}
|
||
$this->model->whereIn('id', $arr)->delete();
|
||
$this->result->success([], '已删除');
|
||
}
|
||
}
|