@@ -10,23 +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
- const selectResult = await this . app . mysql . query ( selectSql , [ id ] ) ;
18
- const articleCountResult = await this . app . mysql . query ( 'SELECT count(*) as count from article' ) ;
19
- const talkCountResult = await this . app . mysql . query ( 'SELECT count(*) as count from talk' ) ;
20
- const novelCountResult = await this . app . mysql . query ( 'SELECT count(*) as count from novel' ) ;
21
- if ( selectResult . length > 0 ) {
22
- const dataObj = selectResult [ 0 ] ;
18
+ const userInfoPromise = this . app . mysql . query ( selectSql , [ id ] ) ;
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 ] ;
23
25
dataObj . articleCount = articleCountResult [ 0 ] . count ;
24
26
dataObj . talkCount = talkCountResult [ 0 ] . count ;
25
27
dataObj . novelCount = novelCountResult [ 0 ] . count ;
28
+ console . log ( 'dataObj' , dataObj ) ;
26
29
this . ctx . body = { success : true , data : dataObj } ;
30
+ console . log ( this . ctx . body ) ;
27
31
} else {
28
32
this . ctx . body = { success : false , message : '获取个人信息失败' } ;
29
33
}
34
+
30
35
}
31
36
32
37
async getAdverList ( ) {
@@ -53,19 +58,21 @@ class IndexController extends controller {
53
58
article_type.name as type
54
59
FROM article LEFT JOIN article_type
55
60
ON article.type_id = article_type.id WHERE article.is_publish = 1 ORDER BY article.publish_time DESC LIMIT ?,?` ;
56
- const result = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
57
- const countResult = await this . app . mysql . query ( 'SELECT count(*) as total FROM article' ) ;
58
- if ( result . length > 0 ) {
59
- for ( const item of result ) {
61
+ const articleListPromise = this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
62
+ const countPromise = 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 ) {
60
66
item . listType = 'article' ;
61
67
}
62
68
this . ctx . body = {
63
69
success : true ,
64
70
data : {
65
71
total : countResult [ 0 ] . total ,
66
- list : result ,
72
+ list : articleListResult ,
67
73
} ,
68
74
} ;
75
+ console . log ( this . ctx . body ) ;
69
76
} else {
70
77
this . ctx . body = {
71
78
success : false ,
@@ -82,7 +89,7 @@ class IndexController extends controller {
82
89
LEFT JOIN admin_user AS user ON talk.user_id = user.id
83
90
ORDER BY talk.publish_time DESC LIMIT ?,?` ;
84
91
const result = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
85
- 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' ) ;
86
93
if ( result . length > 0 ) {
87
94
const commentsql = 'SELECT count(*) as count FROM visitor_comment as comment WHERE comment.talk_id = ?' ;
88
95
for ( const item of result ) {
@@ -118,7 +125,7 @@ class IndexController extends controller {
118
125
LEFT JOIN novel ON chapter.novel_id = novel.id
119
126
ORDER BY chapter.updatetime DESC LIMIT ?,?` ;
120
127
const sqlResult = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
121
- 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 ' ) ;
122
129
if ( sqlResult . length > 0 ) {
123
130
for ( const item of sqlResult ) {
124
131
item . listType = 'novel' ;
@@ -156,8 +163,8 @@ class IndexController extends controller {
156
163
157
164
async getIndexListApp ( ) {
158
165
const request = this . ctx . request . body ;
159
- const chapterCountResult = await this . app . mysql . query ( 'SELECT count(*) AS total FROM novel_chapter' ) ;
160
- 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 ' ) ;
161
168
const chapterSql = 'SELECT id AS chapterId, updatetime AS updateTime FROM novel_chapter' ;
162
169
const articleSql = 'SELECT id AS articleId, publish_time AS updateTime FROM article' ;
163
170
const chapterList = await this . app . mysql . query ( chapterSql ) ;
@@ -224,7 +231,7 @@ class IndexController extends controller {
224
231
introduce_img AS introduceImg, view_count AS viewCount
225
232
FROM article where title like '%${ request . searchValue } %' AND is_publish = 1 ORDER BY publish_time DESC LIMIT ?,?` ;
226
233
const sqlResult = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
227
- 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 ' ) ;
228
235
if ( sqlResult . length > 0 ) {
229
236
for ( const item of sqlResult ) {
230
237
item . listType = 'article' ;
@@ -251,7 +258,7 @@ class IndexController extends controller {
251
258
LEFT JOIN novel ON chapter.novel_id = novel.id
252
259
WHERE chapter.name like '%${ request . searchValue } %' ORDER BY updatetime DESC LIMIT ?,?` ;
253
260
const sqlResult = await this . app . mysql . query ( sql , [ request . offset , request . limit ] ) ;
254
- 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 ' ) ;
255
262
if ( sqlResult . length > 0 ) {
256
263
for ( const item of sqlResult ) {
257
264
item . listType = 'novel' ;
0 commit comments