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:
@@ -119,6 +119,37 @@ class ArticleServices extends BaseServices
|
||||
return $this->dao->update($id, ['product_id' => $product_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按分类标题获取一条随机文章(用于签到前置阅读门槛)
|
||||
* @param string $categoryTitle 分类标题(如"签到广告")
|
||||
* @return array|null id/title/image_input/visit;分类或文章不存在时返回 null
|
||||
*/
|
||||
public function getRandomByCategoryTitle(string $categoryTitle)
|
||||
{
|
||||
/** @var ArticleCategoryServices $categoryServices */
|
||||
$categoryServices = app()->make(ArticleCategoryServices::class);
|
||||
$cat = $categoryServices->getOne([
|
||||
'title' => $categoryTitle,
|
||||
'status' => 1,
|
||||
'is_del' => 0,
|
||||
'hidden' => 0,
|
||||
], 'id');
|
||||
if (!$cat) {
|
||||
return null;
|
||||
}
|
||||
$where = ['cid' => (int)$cat['id'], 'status' => 1, 'hide' => 0];
|
||||
$ids = $this->dao->getColumn($where, 'id');
|
||||
if (!$ids) {
|
||||
return null;
|
||||
}
|
||||
$pickId = (int)$ids[array_rand($ids)];
|
||||
$article = $this->dao->getOne(['id' => $pickId], 'id,title,image_input,visit,add_time');
|
||||
if (!$article) {
|
||||
return null;
|
||||
}
|
||||
return is_array($article) ? $article : $article->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数量
|
||||
* @param array $where
|
||||
|
||||
Reference in New Issue
Block a user