151 lines
3.2 KiB
Go
151 lines
3.2 KiB
Go
package provider
|
||
|
||
import (
|
||
. "code.hoteas.com/golang/hotime"
|
||
. "code.hoteas.com/golang/hotime/common"
|
||
"time"
|
||
)
|
||
|
||
var UserCtr = Ctr{
|
||
//用户微信公众号或者小程序登录
|
||
"info": func(that *Context) {
|
||
if that.Session("salesman_id").Data == nil {
|
||
that.Display(2, "没有登录")
|
||
return
|
||
}
|
||
userId := ObjToInt(that.Req.FormValue("id"))
|
||
|
||
if userId == 0 {
|
||
that.Display(3, "参数错误")
|
||
return
|
||
}
|
||
|
||
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()})
|
||
if user == nil {
|
||
that.Display(4, "获取个人信息失败")
|
||
return
|
||
}
|
||
|
||
delete(user, "password")
|
||
|
||
that.Display(0, user)
|
||
},
|
||
|
||
"edit": func(that *Context) {
|
||
|
||
if that.Session("salesman_id").Data == nil {
|
||
that.Display(2, "没有登录")
|
||
return
|
||
}
|
||
userId := ObjToInt(that.Req.FormValue("id"))
|
||
|
||
if userId == 0 {
|
||
that.Display(3, "参数错误")
|
||
return
|
||
}
|
||
|
||
name := that.Req.FormValue("name")
|
||
nickname := that.Req.FormValue("nickname")
|
||
sex := that.Req.FormValue("sex")
|
||
email := that.Req.FormValue("email")
|
||
avatar := that.Req.FormValue("avatar")
|
||
address := that.Req.FormValue("address")
|
||
phone := that.Req.FormValue("phone") //如果更换手机号则要有新的短信验证码
|
||
|
||
data := Map{"modify_time[#]": "now()"}
|
||
if name != "" {
|
||
data["name"] = name
|
||
}
|
||
if nickname != "" {
|
||
data["nickname"] = nickname
|
||
}
|
||
if sex != "" {
|
||
data["sex"] = sex
|
||
}
|
||
if email != "" {
|
||
data["email"] = email
|
||
}
|
||
if avatar != "" {
|
||
data["avatar"] = avatar
|
||
}
|
||
if address != "" {
|
||
data["address"] = address
|
||
}
|
||
if phone != "" {
|
||
|
||
data["phone"] = phone
|
||
}
|
||
|
||
re := that.Db.Update("user", data, Map{"id": userId})
|
||
if re == 0 {
|
||
that.Display(4, "更新失败")
|
||
return
|
||
}
|
||
|
||
that.Display(4, "修改成功")
|
||
},
|
||
|
||
"search": func(that *Context) {
|
||
if that.Session("salesman_id").Data == nil {
|
||
that.Display(2, "没有登录")
|
||
return
|
||
}
|
||
|
||
page := ObjToInt(that.Req.FormValue("page"))
|
||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||
|
||
if page < 1 {
|
||
page = 1
|
||
}
|
||
|
||
if pageSize <= 0 {
|
||
pageSize = 20
|
||
}
|
||
|
||
tp := ObjToInt(that.Req.FormValue("type")) //0,无操作,1,已扫码未认证,2,已认证,3,VIP会员
|
||
|
||
data := Map{"del_flag": 0, "salesman_id": that.Session("salesman_id").Data}
|
||
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
|
||
}
|
||
if tp == 1 {
|
||
data["certification_flag"] = 0
|
||
}
|
||
|
||
if tp == 2 {
|
||
data["certification_flag"] = 1
|
||
data["OR"] = Map{"expiration_time": nil, "expiration_time[#]": "now()"}
|
||
}
|
||
|
||
if tp == 3 {
|
||
data["certification_flag"] = 1
|
||
data["expiration_time[>]"] = time.Now().Format("2006-01-02 15:04:05")
|
||
}
|
||
|
||
if len(data) > 1 {
|
||
data = Map{"AND": data, "ORDER": "modify_time DESC"}
|
||
}
|
||
|
||
count := that.Db.Count("user", data)
|
||
|
||
res := that.Db.Page(page, pageSize).PageSelect("user", "*", data)
|
||
|
||
for _, v := range res {
|
||
delete(v, "password")
|
||
}
|
||
|
||
that.Display(0, Map{"total": count, "data": res})
|
||
},
|
||
}
|