feat(api): add sign required-article endpoint
GET /api/sign/required_article returns one random article from the "签到广告" article category (status=1, is_del=0, hidden=0). Empty category or no articles returns null so clients can fall through to direct sign-in. Powers the pre-sign-in reading gate per docs/project-shaoyaoju/prd-require.md §6. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
namespace app\controller\api\v1\user;
|
||||
|
||||
use app\Request;
|
||||
use app\services\article\ArticleServices;
|
||||
use app\services\user\member\MemberCardServices;
|
||||
use app\services\user\UserServices;
|
||||
use app\services\user\UserSignServices;
|
||||
@@ -147,4 +148,26 @@ class UserSign
|
||||
$this->services->setSignRemind($uid, $status);
|
||||
return app('json')->success('设置成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到前置阅读:从"签到广告"分类下随机返回一篇文章
|
||||
* 分类不存在 / 无文章 时返回 null,前端跳过门槛直接签到
|
||||
*/
|
||||
public function required_article(ArticleServices $articleServices)
|
||||
{
|
||||
$article = $articleServices->getRandomByCategoryTitle('签到广告');
|
||||
if (!$article) {
|
||||
return app('json')->successful(null);
|
||||
}
|
||||
$img = $article['image_input'] ?? '';
|
||||
if (is_array($img)) {
|
||||
$img = $img[0] ?? '';
|
||||
}
|
||||
return app('json')->successful([
|
||||
'id' => (int)($article['id'] ?? 0),
|
||||
'title' => (string)($article['title'] ?? ''),
|
||||
'image' => (string)$img,
|
||||
'view_required_seconds' => 10,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user