hotime/example/provider/user.go

151 lines
3.2 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"
2022-05-04 16:29:30 +00:00
"time"
2022-05-03 00:09:25 +00:00
)
var UserCtr = 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
}
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) {
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
}
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) {
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
}
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已认证3VIP会员
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
2022-05-04 16:29:30 +00:00
data["OR"] = Map{"expiration_time": nil, "expiration_time[#]": "now()"}
2022-05-03 00:09:25 +00:00
}
if tp == 3 {
data["certification_flag"] = 1
2022-05-04 16:29:30 +00:00
data["expiration_time[>]"] = time.Now().Format("2006-01-02 15:04:05")
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "modify_time DESC"}
2022-05-03 00:09:25 +00:00
}
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})
},
}