hotime/example/app/notify.go

112 lines
3.3 KiB
Go
Raw Normal View History

2022-05-03 00:09:25 +00:00
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var NotifyCtr = Ctr{
"info": func(that *Context) {
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("notify", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到通知公告")
return
}
res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1
delete(res, "click_num_base")
res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base")
delete(res, "favorite_num_base")
article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")})
if article != nil {
article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1
delete(article, "click_num_base")
article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base")
delete(article, "favorite_num_base")
}
res["article"] = article
//浏览量加1
that.Db.Update("notify", Map{"click_num[#]": "click_num+1"}, Map{"id": id})
//浏览量加1
that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")})
//查询是否已关注
if that.Session("user_id").Data != nil {
favorite := that.Db.Get("favorite", "user_id,notify_id", Map{"AND": Map{"notify_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}})
res["favorite"] = favorite
}
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "notify_id[!]": nil}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["release_date[>=]"] = startTime
}
if finishTime != "" {
data["release_date[<=]"] = finishTime
}
dispatchName := that.Req.FormValue("dispatch_name")
if dispatchName != "" {
data["dispatch_name"] = dispatchName
}
if len(data) > 1 {
2022-05-03 07:17:27 +00:00
data = Map{"AND": data, "ORDER": "release_time DESC"}
2022-05-03 00:09:25 +00:00
}
count := that.Db.Count("article", data)
res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
2022-05-04 16:29:30 +00:00
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,policy_id,declare_id,notify_id,dispatch_name,policy_level", data)
2022-05-03 00:09:25 +00:00
for _, v := range res {
if v.GetCeilInt("notify_id") > 0 {
v["notify"] = that.Db.Get("notify", "id,tag", Map{"id": v.GetCeilInt("notify_id")})
}
//if v.GetCeilInt("policy_id")>0{
// v["policy"]=that.Db.Get("policy","tag",Map{"id":v.GetCeilInt("policy_id")})
//}
//if v.GetCeilInt("declare_id")>0{
// v["declare"]=that.Db.Get("declare","money_scope_min,money_scope_max,tag,status",Map{"id":v.GetCeilInt("declare_id")})
//}
}
that.Display(0, Map{"total": count, "data": res})
},
}