111 lines
4.2 KiB
PHP
111 lines
4.2 KiB
PHP
<?php
|
||
|
||
/**
|
||
* @author Any
|
||
* @description KISS
|
||
* @date 2021年7月29日
|
||
* @version 1.0.0
|
||
*
|
||
* _____LOG_____
|
||
*
|
||
*/
|
||
namespace app\modules\api\controllers;
|
||
|
||
use app\modules\api\behaviors\LoginBehavior;
|
||
use app\components\SiteHelper;
|
||
use app\components\SysConst;
|
||
use app\models\common\cms\CommonPostActionForm;
|
||
use app\models\common\cms\CommonPostListForm;
|
||
use app\models\cms\Post;
|
||
use app\components\SysErrCode;
|
||
use yii\web\NotFoundHttpException;
|
||
|
||
class PostController extends Controller
|
||
{
|
||
public function behaviors() {
|
||
return array_merge(parent::behaviors(),[
|
||
'login' => [
|
||
'class' => LoginBehavior::className(),
|
||
'ignore' => [
|
||
'api/post/index',
|
||
'api/post/detail',
|
||
]
|
||
]
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* hidedoc
|
||
* @catalog 文章
|
||
* @title 文章列表
|
||
* @description 本接口提供文章列表
|
||
* @method get
|
||
* @url /api/post/index
|
||
* @param keywords 非必选 string 关键词
|
||
* @param page 必选 int 页码
|
||
* @param limit 非必选 int 每页记录数
|
||
* @param is_top 非必选 int 是否置顶:1=是,0=否
|
||
* @return {"code":0,"msg":"ok","data":[{"author":"","title":"文章文章文章文章1","summary":"","content":"<p>文章文章文章文章文章文章文章文章文章文章文章文章文章额</p>","cover_url":"","id":"1","rich_text_id":"1","sort":"103","is_top":"0","is_index":"1","status":"1","created_at":"1625216065","published_at":"1625216065","viewed_num":"0","created_at_cn":"2021-07-02 16:54:25","published_at_cn":"2021-07-02 16:54:25","status_cn":"已发布"}],"count":"1","page_size":20,"page_count":1,"page_no":1,"end_flag":false}
|
||
* @return_param count int 记录条数
|
||
* @return_param page_size int 每页记录数
|
||
* @return_param page_count int 总页数
|
||
* @return_param page_no int 当前页码
|
||
* @return_param end_flag bool 是否加载结束
|
||
* @remark
|
||
*/
|
||
public function actionIndex()
|
||
{
|
||
$form = new CommonPostListForm();
|
||
$form->attributes = \Yii::$app->request->get();
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$form->status = Post::STATUS_PUBLISHED;
|
||
$form->scene = Post::SCENE_DEFAULT;
|
||
$data = $form->search();
|
||
return $this->responseHandler($data);
|
||
}
|
||
|
||
/**
|
||
* hidedoc
|
||
* @catalog 文章
|
||
* @title 文章详情
|
||
* @description 本接口提供文章详情
|
||
* @method get
|
||
* @url /api/post/detail
|
||
* @param post_id 必选 int 文章ID
|
||
* @param alias 非必选 string 别名
|
||
* @param password 非必选 string 访问密码
|
||
* @return {"code":0,"msg":"ok","data":{"author":"","title":"文章文章文章文章1","summary":"","content":"<p>文章文章文章文章文章文章文章文章文章文章文章文章文章额</p>","cover_url":"","id":"1","rich_text_id":"1","sort":"103","is_top":"0","status":"1","created_at":"1625216065","published_at":"1625216065","viewed_num":"0","created_at_cn":"2021-07-02 16:54:25","published_at_cn":"2021-07-02 16:54:25","status_cn":"已发布"}}
|
||
* @return_param param param_type param_desc
|
||
* @remark
|
||
*/
|
||
public function actionDetail()
|
||
{
|
||
$form = new CommonPostActionForm();
|
||
$form->attributes = \Yii::$app->request->get();
|
||
$form->scene = Post::SCENE_DEFAULT;
|
||
//优先使用别名
|
||
if(!empty($form->alias) && $form->post_id == null){
|
||
$post = Post::findOne(['url_alias' => $form->alias, 'is_delete' => 0]);
|
||
$form->post_id = $post == null ? 0 : $post->id;
|
||
}
|
||
$form->cx_mch_id = $this->cx_mch_id;
|
||
$data = $form->detail();
|
||
$render = \Yii::$app->request->get('render');
|
||
if(!$render){
|
||
return $this->responseHandler($data);
|
||
}
|
||
if($data['code'] != SysErrCode::$apiReturnSuccess){
|
||
throw new NotFoundHttpException($data['msg']);
|
||
}
|
||
return $this->render('detail',[
|
||
'title' => $data['data']['title'],
|
||
'content' => $data['data']['content']
|
||
]);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|