88 lines
2.2 KiB
Go
88 lines
2.2 KiB
Go
|
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}
|
||
|
keywords := that.Req.FormValue("keywords")
|
||
|
if keywords != "" {
|
||
|
data["OR"] = Map{"name[~]": keywords, "title[~]": keywords}
|
||
|
}
|
||
|
|
||
|
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 {
|
||
|
data = Map{"AND": data}
|
||
|
}
|
||
|
|
||
|
count := that.Db.Count("provider", data)
|
||
|
|
||
|
res := that.Db.Page(page, pageSize).PageSelect("provider", "id,name,level,discount,avatar,title,description,"+
|
||
|
"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", data)
|
||
|
|
||
|
that.Display(0, Map{"total": count, "data": res})
|
||
|
},
|
||
|
}
|