@@ -10,26 +10,28 @@ class IndexController extends controller {
10
10
11
11
async getUserInfoById ( ) {
12
12
const id = this . ctx . params . id ;
13
+ console . log ( 'id' , id ) ;
13
14
const selectSql = `SELECT username as username, portrait as portrait, bg_img as bgImg,
14
15
qq_account as qqAccount, wechat_account as weChatAccount, github_url as githubUrl,
15
16
logo_name as logoName, logo_sub as logoSub
16
17
FROM admin_user WHERE id = ?` ;
17
18
const userInfoPromise = this . app . mysql . query ( selectSql , [ id ] ) ;
18
- const articleCountPromise = this . app . mysql . query ( 'SELECT count(*) as count from article' ) ;
19
- const talkCountPromise = this . app . mysql . query ( 'SELECT count(*) as count from talk' ) ;
20
- const novelCountPromise = this . app . mysql . query ( 'SELECT count(*) as count from novel' ) ;
21
- Promise . all ( [ userInfoPromise , articleCountPromise , talkCountPromise , novelCountPromise ] )
22
- . then ( ( [ userInfoResult , articleCountResult , talkCountResult , novelCountResult ] ) => {
23
- if ( userInfoResult . length > 0 ) {
24
- const dataObj = userInfoResult [ 0 ] ;
25
- dataObj . articleCount = articleCountResult [ 0 ] . count ;
26
- dataObj . talkCount = talkCountResult [ 0 ] . count ;
27
- dataObj . novelCount = novelCountResult [ 0 ] . count ;
28
- this . ctx . body = { success : true , data : dataObj } ;
29
- } else {
30
- this . ctx . body = { success : false , message : '获取个人信息失败' } ;
31
- }
32
- } )
19
+ const articleCountPromise = this . app . mysql . query ( 'SELECT count(id) as count from article' ) ;
20
+ const talkCountPromise = this . app . mysql . query ( 'SELECT count(id) as count from talk' ) ;
21
+ const novelCountPromise = this . app . mysql . query ( 'SELECT (max(id)-min(id)+1) as count from novel where is_deleted = 0' ) ;
22
+ const [ userInfoResult , articleCountResult , talkCountResult , novelCountResult ] = await Promise . all ( [ userInfoPromise , articleCountPromise , talkCountPromise , novelCountPromise ] )
23
+ if ( userInfoResult . length > 0 ) {
24
+ const dataObj = userInfoResult [ 0 ] ;
25
+ dataObj . articleCount = articleCountResult [ 0 ] . count ;
26
+ dataObj . talkCount = talkCountResult [ 0 ] . count ;
27
+ dataObj . novelCount = novelCountResult [ 0 ] . count ;
28
+ console . log ( 'dataObj' , dataObj ) ;
29
+ this . ctx . body = { success : true , data : dataObj } ;
30
+ console . log ( this . ctx . body ) ;
31
+ } else {
32
+ this . ctx . body = { success : false , message : '获取个人信息失败' } ;
33
+ }
34
+
33
35
}
34
36
35
37
async getAdverList ( ) {
@@ -57,27 +59,26 @@ class IndexController extends controller {
57
59
FROM article LEFT JOIN article_type
58
60
ON article.type_id = article_type.id WHERE article.is_publish = 1 ORDER BY article.publish_time DESC LIMIT ?,?` ;
59
61
const articleListPromise = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
60
- const countPromise = await this . app . mysql . query ( 'SELECT count(*) as total FROM article' ) ;
61
- Promise . all ( [ articleListPromise , countPromise ] )
62
- . then ( ( [ articleListResult , countResult ] ) => {
63
- if ( articleListResult . length > 0 ) {
64
- for ( const item of articleListResult ) {
65
- item . listType = 'article' ;
66
- }
67
- this . ctx . body = {
68
- success : true ,
69
- data : {
70
- total : countResult [ 0 ] . total ,
71
- list : articleListResult ,
72
- } ,
73
- } ;
74
- } else {
75
- this . ctx . body = {
76
- success : false ,
77
- message : '获取文章列表失败' ,
78
- } ;
62
+ const countPromise = await this . app . mysql . query ( 'SELECT (max(id)-min(id)+1) as count from novel where is_deleted = 0' ) ;
63
+ const [ articleListResult , countResult ] = await Promise . all ( [ articleListPromise , countPromise ] )
64
+ if ( articleListResult . length > 0 ) {
65
+ for ( const item of articleListResult ) {
66
+ item . listType = 'article' ;
79
67
}
80
- } )
68
+ this . ctx . body = {
69
+ success : true ,
70
+ data : {
71
+ total : countResult [ 0 ] . total ,
72
+ list : articleListResult ,
73
+ } ,
74
+ } ;
75
+ console . log ( this . ctx . body ) ;
76
+ } else {
77
+ this . ctx . body = {
78
+ success : false ,
79
+ message : '获取文章列表失败' ,
80
+ } ;
81
+ }
81
82
}
82
83
83
84
async getTalkList ( ) {
@@ -88,7 +89,7 @@ class IndexController extends controller {
88
89
LEFT JOIN admin_user AS user ON talk.user_id = user.id
89
90
ORDER BY talk.publish_time DESC LIMIT ?,?` ;
90
91
const result = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
91
- const countResult = await this . app . mysql . query ( 'SELECT count(* ) as total FROM talk' ) ;
92
+ const countResult = await this . app . mysql . query ( 'SELECT count(id ) as total FROM talk' ) ;
92
93
if ( result . length > 0 ) {
93
94
const commentsql = 'SELECT count(*) as count FROM visitor_comment as comment WHERE comment.talk_id = ?' ;
94
95
for ( const item of result ) {
@@ -124,7 +125,7 @@ class IndexController extends controller {
124
125
LEFT JOIN novel ON chapter.novel_id = novel.id
125
126
ORDER BY chapter.updatetime DESC LIMIT ?,?` ;
126
127
const sqlResult = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
127
- const countResult = await this . app . mysql . query ( 'SELECT count(*) as total FROM novel_chapter' ) ;
128
+ const countResult = await this . app . mysql . query ( 'SELECT (max(id)-min(id)+1) as count from novel_chapter where is_deleted = 0 ' ) ;
128
129
if ( sqlResult . length > 0 ) {
129
130
for ( const item of sqlResult ) {
130
131
item . listType = 'novel' ;
@@ -162,8 +163,8 @@ class IndexController extends controller {
162
163
163
164
async getIndexListApp ( ) {
164
165
const request = this . ctx . request . body ;
165
- const chapterCountResult = await this . app . mysql . query ( 'SELECT count(*) AS total FROM novel_chapter' ) ;
166
- const articleCountResult = await this . app . mysql . query ( 'SELECT count(*) AS total FROM article' ) ;
166
+ const chapterCountResult = await this . app . mysql . query ( 'SELECT (max(id)-min(id)+1) AS total FROM novel_chapter where is_deleted = 0 ' ) ;
167
+ const articleCountResult = await this . app . mysql . query ( 'SELECT (max(id)-min(id)+1) AS total FROM article where is_deleted = 0 ' ) ;
167
168
const chapterSql = 'SELECT id AS chapterId, updatetime AS updateTime FROM novel_chapter' ;
168
169
const articleSql = 'SELECT id AS articleId, publish_time AS updateTime FROM article' ;
169
170
const chapterList = await this . app . mysql . query ( chapterSql ) ;
@@ -230,7 +231,7 @@ class IndexController extends controller {
230
231
introduce_img AS introduceImg, view_count AS viewCount
231
232
FROM article where title like '%${ request . searchValue } %' AND is_publish = 1 ORDER BY publish_time DESC LIMIT ?,?` ;
232
233
const sqlResult = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
233
- const countResult = await this . app . mysql . query ( 'SELECT count(*) as total FROM article' ) ;
234
+ const countResult = await this . app . mysql . query ( 'SELECT (max(id)-min(id)+1) as total FROM article where is_deleted = 0 ' ) ;
234
235
if ( sqlResult . length > 0 ) {
235
236
for ( const item of sqlResult ) {
236
237
item . listType = 'article' ;
@@ -257,7 +258,7 @@ class IndexController extends controller {
257
258
LEFT JOIN novel ON chapter.novel_id = novel.id
258
259
WHERE chapter.name like '%${ request . searchValue } %' ORDER BY updatetime DESC LIMIT ?,?` ;
259
260
const sqlResult = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
260
- const countResult = await this . app . mysql . query ( 'SELECT count(*) as total FROM novel_chapter' ) ;
261
+ const countResult = await this . app . mysql . query ( 'SELECT (max(id)-min(id)+1) as total FROM novel_chapter where is_deleted = 0 ' ) ;
261
262
if ( sqlResult . length > 0 ) {
262
263
for ( const item of sqlResult ) {
263
264
item . listType = 'novel' ;
0 commit comments