iedc-go/example/app/provider.go

93 lines
2.4 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 ProviderCtr = Ctr{
//用户微信公众号或者小程序登录
"info": func(that *Context) {
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("provider", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到服务商")
return
}
//浏览量加1
that.Db.Update("provider", Map{"click_num[#]": "click_num+1"}, Map{"id": id})
//查询是否已关注
if that.Session("user_id").Data != nil {
favorite := that.Db.Get("favorite", "user_id,provider_id", Map{"AND": Map{"provider_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, "state": 0}
2022-05-03 00:09:25 +00:00
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"name[~]": keywords, "title[~]": keywords}
}
2022-05-03 07:17:27 +00:00
tp := that.Req.FormValue("type")
if tp != "" {
data[tp] = 1
}
2022-05-03 00:09:25 +00:00
policyDeclareFlag := that.Req.FormValue("policy_declare_flag")
if policyDeclareFlag != "" {
data["policy_declare_flag"] = ObjToInt(policyDeclareFlag)
}
intellectualPropertyFlag := that.Req.FormValue("intellectual_property_flag")
if intellectualPropertyFlag != "" {
data["intellectual_property_flag"] = ObjToInt(intellectualPropertyFlag)
}
taxOnsultingFlag := that.Req.FormValue("tax_onsulting_flag")
if taxOnsultingFlag != "" {
data["tax_onsulting_flag"] = ObjToInt(taxOnsultingFlag)
}
lawFlag := that.Req.FormValue("law_flag")
if lawFlag != "" {
data["law_flag"] = ObjToInt(lawFlag)
}
if len(data) > 1 {
2022-05-03 14:40:02 +00:00
data = Map{"AND": data, "ORDER": "id DESC"}
2022-05-03 00:09:25 +00:00
}
count := that.Db.Count("provider", data)
res := that.Db.Page(page, pageSize).PageSelect("provider", "id,name,level,discount,avatar,title,description,"+
2022-05-03 07:17:27 +00:00
"click_num_base+click_num AS click_num,handle_num_base+handle_num AS handle_num,favorite_num_base+favorite_num AS favorite_num,modify_time,policy_declare_flag,intellectual_property_flag,tax_onsulting_flag,law_flag", data)
2022-05-03 00:09:25 +00:00
that.Display(0, Map{"total": count, "data": res})
},
}