File tree Expand file tree Collapse file tree 4 files changed +17
-25
lines changed Expand file tree Collapse file tree 4 files changed +17
-25
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ func (this *BookController) Setting() {
185185 this .TplName = "book/setting.html"
186186}
187187
188- //保存书籍信息
188+ // SaveBook 保存书籍信息
189189func (this * BookController ) SaveBook () {
190190
191191 bookResult , err := this .IsPermission ()
@@ -260,7 +260,7 @@ func (this *BookController) SaveBook() {
260260 beego .Error (errSearch .Error ())
261261 }
262262 }()
263-
263+ go models . CountCategory ()
264264 this .JsonResult (0 , "ok" , bookResult )
265265}
266266
@@ -687,7 +687,7 @@ func (this *BookController) Delete() {
687687 beego .Error (errDel .Error ())
688688 }
689689 }()
690-
690+ go models . CountCategory ()
691691 this .JsonResult (0 , "ok" )
692692}
693693
Original file line number Diff line number Diff line change @@ -516,7 +516,7 @@ func (this *ManagerController) DeleteBook() {
516516 beego .Error (errDel .Error ())
517517 }
518518 }
519-
519+ go models . CountCategory ()
520520 this .JsonResult (0 , "书籍删除成功" )
521521}
522522
Original file line number Diff line number Diff line change @@ -189,27 +189,17 @@ func SitemapUpdate(domain string) {
189189 Sitemap .CreateSitemapIndex (si , "sitemap.xml" )
190190}
191191
192- // 统计书籍分类
193- var counting = false
194-
195192type Count struct {
196193 Cnt int
197194 CategoryId int
198195}
199196
197+ // CountCategory 统计书籍分类
200198func CountCategory () {
201- if counting {
202- return
203- }
204- counting = true
205- defer func () {
206- counting = false
207- }()
208-
209199 var count []Count
210200
211201 o := orm .NewOrm ()
212- sql := "select count(bc.id) cnt, bc.category_id from md_book_category bc left join md_books b on b.book_id=bc.book_id where b.privately_owned=0 group by bc.category_id"
202+ sql := "select count(bc.id) cnt, bc.category_id from md_book_category bc left join md_books b on b.book_id=bc.book_id where b.privately_owned=0 and bc.category_id>0 group by bc.category_id"
213203 o .Raw (sql ).QueryRows (& count )
214204 if len (count ) == 0 {
215205 return
@@ -227,21 +217,23 @@ func CountCategory() {
227217 o .Begin ()
228218 defer func () {
229219 if err != nil {
220+ beego .Error (err )
230221 o .Rollback ()
231222 } else {
232223 o .Commit ()
233224 }
234225 }()
235226
236- o .QueryTable (tableCate ).Update (orm.Params {"cnt" : 0 })
237227 cateChild := make (map [int ]int )
228+ if _ , err = o .QueryTable (tableCate ).Filter ("id__gt" , 0 ).Update (orm.Params {"cnt" : 0 }); err != nil {
229+ return
230+ }
231+
238232 for _ , item := range count {
239- if item .Cnt > 0 {
240- cateChild [item .CategoryId ] = item .Cnt
241- _ , err = o .QueryTable (tableCate ).Filter ("id" , item .CategoryId ).Update (orm.Params {"cnt" : item .Cnt })
242- if err != nil {
243- return
244- }
233+ cateChild [item .CategoryId ] = item .Cnt
234+ _ , err = o .QueryTable (tableCate ).Filter ("id" , item .CategoryId ).Update (orm.Params {"cnt" : item .Cnt })
235+ if err != nil {
236+ return
245237 }
246238 }
247239}
Original file line number Diff line number Diff line change 127127 < span class ="input-group-btn ">
128128 < button class ="btn btn-default " type ="button "> 广告标题</ button >
129129 </ span >
130- < input type ="text " placeholder ="选填 " value ="{{.Model.AdTitle}} " name ="ad_title " id =" author " class ="form-control ">
130+ < input type ="text " placeholder ="选填 " value ="{{.Model.AdTitle}} " name ="ad_title " class ="form-control ">
131131 < span class ="input-group-btn ">
132132 < button class ="btn btn-default " style ="border-left: 0px;border-right: 0px;border-radius: 0px; " type ="button "> 广告链接</ button >
133133 </ span >
134- < input type ="text " placeholder ="选填 " value ="{{.Model.AdLink}} " name ="ad_link " id =" author_url " class ="form-control ">
134+ < input type ="text " placeholder ="选填 " value ="{{.Model.AdLink}} " name ="ad_link " class ="form-control ">
135135 </ div >
136136 < p class ="text help-block "> 文字广告,可以放原作者的打赏和赞助二维码链接,也可以放开源书籍的购买链接以支持作者</ p >
137137 </ div >
You can’t perform that action at this time.
0 commit comments