2022-05-03 00:09:25 +00:00
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "code.hoteas.com/golang/hotime"
|
|
|
|
. "code.hoteas.com/golang/hotime/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Salesman = Ctr{
|
2022-05-03 01:41:18 +00:00
|
|
|
"test": func(that *Context) {
|
|
|
|
that.Session("salesman_id", 1)
|
|
|
|
that.Session("wechat_id", 1)
|
|
|
|
that.Display(0, 1)
|
|
|
|
},
|
2022-05-03 00:09:25 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
|
|
|
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
|
|
|
|
if salesman == nil {
|
|
|
|
that.Display(4, "找不到该业务员")
|
|
|
|
return
|
|
|
|
}
|
2022-05-05 08:07:01 +00:00
|
|
|
|
|
|
|
if salesman.GetString("nickname") == "" {
|
|
|
|
wechat := that.Db.Get("wechat", "*", Map{"salesman_id": salesman.GetCeilInt64("id")})
|
|
|
|
if wechat != nil {
|
|
|
|
salesman["nickname"] = wechat.GetString("nickname")
|
|
|
|
salesman["avatar"] = wechat.GetString("avatar")
|
|
|
|
that.Db.Update("salesman", Map{"nickname": wechat.GetString("nickname"), "avatar": wechat.GetString("avatar")}, Map{"id": salesman.GetCeilInt64("id")})
|
|
|
|
}
|
|
|
|
}
|
2022-05-03 00:09:25 +00:00
|
|
|
salesman["user"] = that.Db.Count("user", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}})
|
|
|
|
salesman["matters"] = that.Db.Count("matters", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}})
|
|
|
|
|
|
|
|
salesman["admin"] = that.Db.Get("admin", "id,name,avatar", Map{"id": salesman.GetCeilInt64("admin_id")})
|
|
|
|
salesman["provider"] = that.Db.Get("provider", "*", Map{"id": salesman.GetCeilInt64("provider_id")})
|
|
|
|
if salesman["provider"] != nil {
|
|
|
|
salesman["provider_salesman"] = that.Db.Get("salesman", "id,nickname,name,avatar", Map{"id": salesman.GetMap("provider").GetCeilInt64("salesman_id")})
|
|
|
|
}
|
|
|
|
|
|
|
|
that.Display(0, salesman)
|
|
|
|
},
|
|
|
|
|
|
|
|
"search": 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
|
|
|
|
}
|
|
|
|
|
|
|
|
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
|
|
|
|
if salesman == nil {
|
|
|
|
that.Display(4, "找不到该业务员")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
provider := that.Db.Get("provider", "*", Map{"id": salesman.GetCeilInt64("provider_id")})
|
|
|
|
|
|
|
|
if provider.GetCeilInt("salesman_id") != salesman.GetCeilInt("id") {
|
|
|
|
that.Display(0, Slice{})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
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, "provider_id": salesman.GetCeilInt64("provider_id")}
|
|
|
|
keywords := that.Req.FormValue("keywords")
|
|
|
|
if keywords != "" {
|
|
|
|
data["OR"] = Map{"name[~]": keywords, "nickname[~]": keywords, "phone[~]": keywords}
|
|
|
|
}
|
|
|
|
|
|
|
|
startTime := that.Req.FormValue("starttime")
|
|
|
|
finishTime := that.Req.FormValue("finishtime")
|
|
|
|
|
|
|
|
if startTime != "" {
|
|
|
|
data["modifye_time[>=]"] = startTime
|
|
|
|
}
|
|
|
|
if finishTime != "" {
|
|
|
|
data["modifye_time[<=]"] = finishTime
|
|
|
|
}
|
|
|
|
|
|
|
|
count := that.Db.Count("salesman", data)
|
|
|
|
|
|
|
|
res := that.Db.Page(page, pageSize).PageSelect("salesman", "id,name,nickname,avatar", data)
|
|
|
|
|
|
|
|
that.Display(0, Map{"total": count, "data": res})
|
|
|
|
},
|
|
|
|
//用户微信公众号或者小程序登录
|
|
|
|
"login": func(that *Context) {
|
|
|
|
|
|
|
|
code := that.Req.FormValue("code")
|
|
|
|
phone := that.Req.FormValue("phone")
|
|
|
|
|
2022-05-03 07:17:27 +00:00
|
|
|
if phone != that.Session("phone").ToStr() && code == that.Session("code").ToStr() {
|
2022-05-03 00:09:25 +00:00
|
|
|
that.Display(3, "手机号或者验证码错误")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if that.Session("wechat_id").Data == nil {
|
|
|
|
that.Display(2, "还未登录")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
wechat := that.Db.Get("wechat", "*", Map{"id": that.Session("wechat_id").ToCeilInt()})
|
|
|
|
|
|
|
|
salesman := that.Db.Get("salesman", "*", Map{"phone": phone})
|
|
|
|
|
|
|
|
if salesman == nil {
|
|
|
|
that.Display(3, "找不到企服商")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if wechat == nil {
|
|
|
|
that.Display(2, "还未绑定微信")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//有用户直接返回
|
2022-05-17 04:31:47 +00:00
|
|
|
if wechat.GetCeilInt("salesman_id") != 0 && wechat.GetCeilInt64("salesman_id") != salesman.GetCeilInt64("id") {
|
2022-05-03 00:09:25 +00:00
|
|
|
that.Display(5, "你已经绑定了其他商户")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-05-17 04:31:47 +00:00
|
|
|
that.Db.Update("wechat", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": wechat.GetCeilInt64("id")})
|
2022-05-13 01:30:09 +00:00
|
|
|
that.Db.Update("salesman", Map{"login_time[#]": "now()", "modify_time[#]": "now()"},
|
|
|
|
Map{"id": salesman.GetCeilInt("id")})
|
2022-05-03 00:09:25 +00:00
|
|
|
|
|
|
|
wechat["salesman_id"] = salesman.GetCeilInt64("id")
|
|
|
|
that.Session("salesman_id", salesman.GetCeilInt64("id"))
|
|
|
|
that.Display(0, "登录成功!")
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|