hotime/example/provider/company.go

145 lines
3.8 KiB
Go
Raw Normal View History

2022-05-03 00:09:25 +00:00
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"code.hoteas.com/golang/hotime/dri/aliyun"
"fmt"
2022-05-03 00:09:25 +00:00
)
var CompanyCtr = Ctr{
"info": func(that *Context) {
2022-05-03 07:17:27 +00:00
if that.Session("salesman_id").Data == nil {
2022-05-03 00:09:25 +00:00
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("company", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到企业")
return
}
//先不做限制
//if res.GetCeilInt("salesman_id")!=that.Session("salesman_id").ToCeilInt(){
// that.Display(4,"不是你的企业")
// return
//}
res["technology_center_flag"] = ObjToSlice(res["technology_center_flag"])
res["engineering_center_flag"] = ObjToSlice(res["engineering_center_flag"])
res["engineering_laboratory_flag"] = ObjToSlice(res["engineering_laboratory_flag"])
res["key_laboratory_flag"] = ObjToSlice(res["key_laboratory_flag"])
res["industrial_design_center_flag"] = ObjToSlice(res["industrial_design_center_flag"])
//res["high_level_talents_flag"] = ObjToSlice(res["high_level_talents_flag"])
2022-05-03 00:09:25 +00:00
that.Display(0, res)
},
"edit": func(that *Context) {
2022-05-03 07:17:27 +00:00
if that.Session("salesman_id").Data == nil {
2022-05-03 00:09:25 +00:00
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
company := that.Db.Get("company", "*", Map{"id": id})
delete(company, "id")
delete(company, "salesman_id")
delete(company, "provider_id")
delete(company, "user_id")
delete(company, "del_flag")
delete(company, "state")
delete(company, "create_time")
delete(company, "modify_time")
data := Map{}
//for k, _ := range company {
// if that.Req.Form[k] != nil {
// if k == "technology_center_flag" || k == "engineering_center_flag" || k == "engineering_laboratory_flag" || k == "key_laboratory_flag" || k == "industrial_design_center_flag" {
// data[k] = ObjToStr(that.Req.Form[k])
// } else {
// data[k] = that.Req.FormValue(k)
// }
//
// }
//}
2022-05-03 00:09:25 +00:00
for k, _ := range company {
// 前端传传值不规范
if k == "high_level_talents_flag" {
that.Req.Form[k] = that.Req.Form["highLevel_talents_flag"]
}
if k == "attendee" {
continue
}
2022-05-03 00:09:25 +00:00
if that.Req.Form[k] != nil {
if k == "technology_center_flag" || k == "engineering_center_flag" || k == "engineering_laboratory_flag" || k == "key_laboratory_flag" || k == "industrial_design_center_flag" {
data[k] = ObjToStr(that.Req.Form[k])
} else if k == "tags" || k == "high_level_talents_flag" {
keyObj := that.Req.Form[k]
if keyObj != nil && ObjToStr(keyObj) != "" {
tagsStr := ""
for k2, v2 := range keyObj {
if k == "tags" && k2 < len(keyObj)-1 {
tagsStr = tagsStr + v2 + ","
} else {
tagsStr += v2
}
}
data[k] = tagsStr
}
2022-05-03 00:09:25 +00:00
} else {
fmt.Println(that.Req.FormValue(k))
if that.Req.FormValue(k) != "" {
data[k] = that.Req.FormValue(k)
}
2022-05-03 00:09:25 +00:00
}
}
}
data["modify_time[#]"] = "NOW()"
that.Db.Update("company", data, Map{"id": id})
2022-05-03 00:09:25 +00:00
that.Display(0, "更新成功")
},
"search": func(that *Context) {
keywords := that.Req.FormValue("keywords")
if keywords == "" {
keywords = that.Req.FormValue("company_name")
}
if keywords == "" {
keywords = that.Req.FormValue("name")
}
if len(keywords) < 2 {
that.Display(0, Slice{})
return
}
res, err := aliyun.Company.GetCompanyList(keywords)
if err != nil {
fmt.Println(err)
that.Display(0, Slice{})
return
}
if res.GetCeilInt64("status") != 200 {
fmt.Println(err)
that.Display(0, Slice{})
return
}
that.Display(0, res.GetMap("data").GetSlice("list"))
},
2022-05-03 00:09:25 +00:00
}