cxgj/modules/api/controllers/PageController.php
2023-11-27 09:45:13 +08:00

144 lines
5.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @author Any
* @description KISS
* @date 2021年7月29日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\api\controllers;
use app\models\Option;
use app\modules\api\behaviors\LoginBehavior;
use app\components\SiteHelper;
use app\components\SysConst;
use app\models\common\cms\CommonPageActionForm;
use app\models\common\cms\CommonPageListForm;
use app\models\cms\Page;
use app\components\SysErrCode;
use yii\web\NotFoundHttpException;
class PageController extends Controller
{
public function behaviors() {
return array_merge(parent::behaviors(),[
'login' => [
'class' => LoginBehavior::className(),
'ignore' => [
'api/page/index',
'api/page/detail',
'api/page/get-project-introduction',
]
]
]);
}
/**
* hidedoc
* @catalog 页面
* @title 页面列表
* @description 本接口提供页面列表
* @method get
* @url /api/page/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 CommonPageListForm();
$form->attributes = \Yii::$app->request->get();
$form->cx_mch_id = $this->cx_mch_id;
$form->status = Page::STATUS_PUBLISHED;
$data = $form->search();
return $this->responseHandler($data);
}
/**
* hidedoc
* @catalog 页面
* @title 页面详情
* @description 本接口提供页面详情
* @method get
* @url /api/page/detail
* @param page_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 CommonPageActionForm();
$form->attributes = \Yii::$app->request->get();
//优先使用别名
if(!empty($form->alias) && $form->page_id == null){
$page = Page::findOne(['url_alias' => $form->alias, 'is_delete' => 0]);
$form->page_id = $page == null ? 0 : $page->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']
]);
}
/**
* showdoc
* @catalog 项目介绍
* @title 项目介绍
* @description 本接口提供项目介绍接口
* @method get
* @url /api/page/get-project-introduction
* @param page_id 必选 int 页面ID
* @param alias 非必选 string 别名
* @param password 非必选 string 访问密码
* @return {"code":0,"msg":"ok","data":"<p>123124214</p><p>234</p><p>345</p><p>43</p><p>6554</p><p>6</p><p>54</p><p>654</p><p>6</p><p>54</p><p>6546</p><p>54</p><p>6</p><p>546</p><p>54</p><p>654</p><p>6</p><p>546</p><p>54654</p>"}
* @return_param data string 内容
* @remark
*/
public function actionGetProjectIntroduction(){
$key = "_page_project_introduction_";
$find = Option::findOne([
'key'=>$key,
]);
$data = '';
if(!empty($find)){
$data = base64_decode(unserialize($find->value));
}
// 图片添加域名
$data = str_replace("/upload/0/1/upload/image",\Yii::$app->request->getHostInfo()."/upload/0/1/upload/image",$data);
return $this->responseHandler([
'code' => 0,
'msg' => 'ok',
'data' => $data,
]);
}
}