hotime/example/provider/order.go
2022-05-05 00:29:30 +08:00

240 lines
6.4 KiB
Go

package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var OrderCtr = Ctr{
"info": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
res := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}})
if res == nil {
that.Display(4, "找不到对应订单")
return
}
//if res.GetCeilInt("salesman_id") != that.Session("salesman_id").ToCeilInt() {
// that.Display(4, "不是你的订单")
// return
//}
if res.GetCeilInt("user_id") > 0 {
res["user"] = that.Db.Get("user", "name,nickname,avatar", Map{"id": res.GetCeilInt("user_id")})
}
res["order_record"] = that.Db.Select("order_record", "remarks,modify_time", Map{"order_id": res.GetCeilInt("id"), "ORDER": "modify_time DESC"})
that.Display(0, res)
},
"create_order_record": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
remarks := that.Req.FormValue("remarks")
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
order := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}})
if order == nil {
that.Display(4, "不是属于你的订单")
return
}
if order.GetCeilInt("status") != 0 {
that.Display(4, "已完结订单,不可操作")
return
}
orderRecordId := that.Db.Insert("order_record", Map{
"order_id": id,
"user_id": order.GetCeilInt64("user_id"),
"remarks": salesman.GetString("name") + ":" + remarks,
"salesman_id": order.GetCeilInt64("salesman_id"),
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
that.Db.Update("order", Map{"order_record_id": orderRecordId}, Map{"id": id})
that.Display(0, "新增订单记录成功")
},
"edit": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
policyDeclareFlag := ObjToInt(that.Req.FormValue("policy_declare_flag"))
declareId := ObjToInt(that.Req.FormValue("declare_id"))
intellectualPropertyFlag := ObjToInt(that.Req.FormValue("intellectual_property_flag"))
intellectualPropertyCount := ObjToInt(that.Req.FormValue("intellectual_property_count"))
taxOnsultingFlag := ObjToInt(that.Req.FormValue("tax_onsulting_flag"))
lawFlag := ObjToInt(that.Req.FormValue("law_flag"))
status := ObjToInt(that.Req.FormValue("status"))
data := Map{
"policy_declare_flag": policyDeclareFlag,
"intellectual_property_flag": intellectualPropertyFlag,
"intellectual_property_count": intellectualPropertyCount,
"tax_onsulting_flag": taxOnsultingFlag,
"law_flag": lawFlag,
"status": status,
"modify_time[#]": "now()",
}
if declareId != 0 {
data["declare_id"] = declareId
}
order := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}})
if order == nil {
that.Display(4, "不是属于你的订单")
return
}
if order.GetCeilInt("status") != 0 {
that.Display(4, "已完结订单,不可操作")
return
}
data["order_record_id"] = that.Db.Insert("order_record", Map{
"order_id": id,
"user_id": order.GetCeilInt64("user_id"),
"remarks": salesman.GetString("name") + "变更了订单服务内容",
"salesman_id": order.GetCeilInt64("salesman_id"),
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
re := that.Db.Update("order", data, Map{"id": id})
if re == 0 {
that.Display(4, "变更订单内容失败")
return
}
that.Display(0, "变更订单内容成功")
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
userId := ObjToInt(that.Req.FormValue("id"))
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
data := Map{"del_flag": 0, "provider_id": salesman.GetCeilInt64("provider_id")}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"sn[~]": keywords, "name[~]": keywords}
}
if userId != 0 {
user := that.Db.Get("user", "id", Map{"AND": Map{"id": userId, "salesman_id": that.Session("salesman_id").Data}})
if user != nil {
data["user_id"] = userId
}
}
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("order", data)
res := that.Db.Page(page, pageSize).PageSelect("order", "*", data)
for _, v := range res {
//if v.GetCeilInt("policy_id")>0{
// v["policy"]=that.Db.Get("policy","id,tag",Map{"id":v.GetCeilInt("policy_id")})
//}
if v.GetCeilInt("user_id") > 0 {
v["user"] = that.Db.Get("user", "name,nickname,avatar", Map{"id": v.GetCeilInt("user_id")})
}
if v.GetCeilInt("order_record_id") > 0 {
v["order_record"] = that.Db.Get("order_record", "remarks,modify_time", Map{"id": v.GetCeilInt("order_record_id")})
}
}
that.Display(0, Map{"total": count, "data": res})
},
}