ArticleController.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
//use cmf\controller\HomeBaseController;
use app\portal\model\MemberModel;
use app\portal\model\UserModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
/**
* @title 文章接口
* @description 接口说明
* @group 接口分组
*/
class ArticleController extends CommonController
{
/**
* @title 文章列表
* @description 接口说明
* @author 开发者
* @url /api/portal/Article/index
* @method POST
* @param name:articleType type:int require:1 default: other: desc:类型
* @param name:page type:int require:1 default: other: desc:页码
* @return data:''@
* @data post_id:文章id
* @data category_id:类型id
* @data name:类型名
* @data post_title:文章标题
*
*/
public function index(Request $request)
{
$page = $request->param('page');
$where_connect['j.status'] = 1;
$where_connect['p.post_status'] = 1;
$where_connect['j.category_id'] = $_POST['articleType'];
$article_list = Db::name('PortalCategoryPost')->alias('j')
->where($where_connect)
->field("j.post_id,j.category_id , c.name , p.post_title")
->join("PortalCategory c","c.id = j.category_id")
->join("PortalPost p","p.id = j.post_id")
->page("$page,5")
->select()->toArray();
if(empty($article_list)){
$this->apiResponse('1','暂无数据');
}
$this->apiResponse('1','成功',$article_list);
}
/**
* @title 文章详情
* @description 接口说明
* @author 开发者
* @url /api/portal/Article/index
* @method POST
*
* @param name:post_id type:int require:1 default: other: desc:文章id
*
* @return content:''@!
* @content thumb:文章图片
* @content title:文章标题
* @content content:文章内容
* @content update_time:创建时间
* @content category_id:类型id
* @content name:类型名
* @return hot:''@
* @hot title:文章标题
* @hot article_id:文章id
*
*/
public function detail(Request $request)
{
$where_art['p.id'] = $request->param('post_id');
$where_art['p.post_status'] = 1;
$article_list = Db::name('PortalCategoryPost')
->alias('j')
->where($where_art)
->field("p.post_title as title,p.post_content as content,p.more,p.update_time ,
c.name,c.id as category_id")
->join("PortalCategory c","c.id = j.category_id")
->join("PortalPost p","p.id = j.post_id")
->find();
if(empty($article_list)){
$this->apiResponse('1','暂无数据');
}
// 处理图片
$thumb = json_decode($article_list['more'],true);
$article_list['thumb'] = $thumb['thumbnail'];
unset($article_list['more']);
// 处理内容
$article_list['content'] = htmlspecialchars_decode($article_list['content']);
$article_list['create_time'] = date('Y-m-d',$article_list['update_time']);
$final['content'] = $article_list;
// 热门文章
$where_hot['p.recommended'] = 1;
$where_hot['p.post_status'] = 1;
$hotArticle = Db::name('PortalCategoryPost')
->alias('j')
->where($where_hot)
->field("p.post_title as title,p.id as article_id")
// ->join("PortalCategory c","c.id = j.category_id")
->join("PortalPost p","p.id = j.post_id")
->select();
$final['hot'] = $hotArticle;
$this->apiResponse('1','成功',$final);
}
}