forked from golang/hotime
160 lines
3.7 KiB
Go
160 lines
3.7 KiB
Go
package app
|
|
|
|
import (
|
|
. "code.hoteas.com/golang/hotime"
|
|
. "code.hoteas.com/golang/hotime/common"
|
|
)
|
|
|
|
var MattersCtr = Ctr{
|
|
"create": func(that *Context) {
|
|
|
|
if that.Session("user_id").Data == nil {
|
|
that.Display(2, "没有登录")
|
|
return
|
|
}
|
|
|
|
sn := that.Req.FormValue("sn")
|
|
if sn == "" {
|
|
that.Display(3, "没有SN码")
|
|
return
|
|
}
|
|
serviceContent := that.Req.FormValue("service_content")
|
|
if serviceContent == "" {
|
|
that.Display(3, "没有服务内容")
|
|
return
|
|
}
|
|
|
|
salesman := that.Db.Get("salesman", "*", Map{"AND": Map{"sn": sn, "del_flag": 0}})
|
|
if salesman == nil {
|
|
that.Display(4, "找不到服务商")
|
|
return
|
|
}
|
|
|
|
re := that.Db.Insert("matters", Map{
|
|
"user_id": that.Session("user_id").Data,
|
|
"salesman_id": salesman.GetCeilInt64("id"),
|
|
"provider_id": salesman.GetCeilInt64("provider_id"),
|
|
"type": 1,
|
|
"service_content": serviceContent,
|
|
"complete_flag": 0,
|
|
"create_time[#]": "now()",
|
|
"modify_time[#]": "now()",
|
|
"del_flag": 0,
|
|
})
|
|
|
|
that.Display(0, re)
|
|
},
|
|
"info": func(that *Context) {
|
|
if that.Session("user_id").Data == nil {
|
|
that.Display(2, "没有登录")
|
|
return
|
|
}
|
|
id := ObjToInt(that.Req.FormValue("id"))
|
|
|
|
if id == 0 {
|
|
that.Display(3, "请求参数异常")
|
|
return
|
|
}
|
|
|
|
res := that.Db.Get("matters", "*", Map{"id": id})
|
|
if res == nil {
|
|
that.Display(4, "找不到事项")
|
|
return
|
|
}
|
|
|
|
res["salesman"] = that.Db.Get("salesman", "name,id", Map{"id": res.GetCeilInt64("salesman_id")})
|
|
|
|
res["provider"] = that.Db.Get("provider", "name,id", Map{"id": res.GetCeilInt64("provider_id")})
|
|
|
|
that.Display(0, res)
|
|
},
|
|
"edit": func(that *Context) {
|
|
|
|
if that.Session("user_id").Data == nil {
|
|
that.Display(2, "没有登录")
|
|
return
|
|
}
|
|
|
|
id := ObjToInt(that.Req.FormValue("id"))
|
|
|
|
if id == 0 {
|
|
that.Display(3, "请求参数异常")
|
|
return
|
|
}
|
|
|
|
serviceEvaluation := ObjToInt(that.Req.FormValue("service_evaluation"))
|
|
evaluationRemark := that.Req.FormValue("evaluation_remark")
|
|
|
|
if serviceEvaluation == 0 {
|
|
that.Display(3, "请求参数异常")
|
|
return
|
|
}
|
|
|
|
matters := that.Db.Get("matters", "*", Map{"AND": Map{"id": id, "user_id": that.Session("user_id").Data}})
|
|
if matters == nil {
|
|
that.Display(4, "不是属于你的评价")
|
|
return
|
|
}
|
|
|
|
if matters.GetCeilInt("complete_flag") == 1 {
|
|
that.Display(4, "已完成评价,不可重复评价")
|
|
return
|
|
}
|
|
|
|
that.Db.Update("matters", Map{"service_evaluation": serviceEvaluation, "evaluation_remark": evaluationRemark, "complete_flag": 1, "modify_time[#]": "now()"}, Map{"id": id})
|
|
|
|
that.Display(0, "评价成功")
|
|
},
|
|
//用户微信公众号或者小程序登录
|
|
"search": func(that *Context) {
|
|
|
|
if that.Session("user_id").Data == nil {
|
|
that.Display(2, "没有登录")
|
|
return
|
|
}
|
|
|
|
page := ObjToInt(that.Req.FormValue("page"))
|
|
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
|
|
|
tp := that.Req.FormValue("type")
|
|
|
|
if page < 1 {
|
|
page = 1
|
|
}
|
|
|
|
if pageSize <= 0 {
|
|
pageSize = 20
|
|
}
|
|
|
|
data := Map{"del_flag": 0, "user_id": that.Session("user_id").Data}
|
|
keywords := that.Req.FormValue("keywords")
|
|
if keywords != "" {
|
|
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
|
|
}
|
|
|
|
if tp != "" {
|
|
data["type"] = ObjToInt("tp")
|
|
}
|
|
|
|
startTime := that.Req.FormValue("starttime")
|
|
finishTime := that.Req.FormValue("finishtime")
|
|
|
|
if startTime != "" {
|
|
data["modify_time[>=]"] = startTime
|
|
}
|
|
if finishTime != "" {
|
|
data["modify_time[<=]"] = finishTime
|
|
}
|
|
|
|
if len(data) > 1 {
|
|
data = Map{"AND": data}
|
|
}
|
|
|
|
count := that.Db.Count("matters", data)
|
|
|
|
res := that.Db.Page(page, pageSize).PageSelect("matters", "*", data)
|
|
|
|
that.Display(0, Map{"total": count, "data": res})
|
|
},
|
|
}
|