250 lines
6.8 KiB
Go
250 lines
6.8 KiB
Go
|
package app
|
|||
|
|
|||
|
import (
|
|||
|
. "../../../hotime"
|
|||
|
. "../../../hotime/common"
|
|||
|
"encoding/base64"
|
|||
|
"io/ioutil"
|
|||
|
"os"
|
|||
|
|
|||
|
"../../../hotime/dri/download"
|
|||
|
"time"
|
|||
|
//"strings"
|
|||
|
)
|
|||
|
|
|||
|
var User = Ctr{
|
|||
|
"test": func(this *Context) {
|
|||
|
this.Session("uid", 1)
|
|||
|
this.Display(0, "开始测试")
|
|||
|
},
|
|||
|
//获取个人信息
|
|||
|
"info": func(this *Context) {
|
|||
|
|
|||
|
if this.Session("user_id").Data == nil {
|
|||
|
this.Display(2, "还没有登录")
|
|||
|
return
|
|||
|
}
|
|||
|
user := this.Db.Get("user", "*", Map{"id": this.Session("user_id").Data})
|
|||
|
this.Display(0, user)
|
|||
|
|
|||
|
},
|
|||
|
//身份认证
|
|||
|
"auth": func(this *Context) {
|
|||
|
|
|||
|
if this.Session("wechatInfo").Data == nil {
|
|||
|
this.Display(2, "尚未登录")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//if this.Session("code").Data == nil {
|
|||
|
// this.Display(8, "验证码没有获取")
|
|||
|
// return
|
|||
|
//}
|
|||
|
orgId := ObjToInt(this.Req.FormValue("org_id"))
|
|||
|
//questionCompanyId:=ObjToInt(this.Req.FormValue("id"))
|
|||
|
if orgId == 0 {
|
|||
|
this.Display(3, "没有选择组织")
|
|||
|
return
|
|||
|
}
|
|||
|
name := this.Req.FormValue("name")
|
|||
|
phone := this.Req.FormValue("phone")
|
|||
|
idcard := this.Req.FormValue("idcard")
|
|||
|
idcardFrontImg := this.Req.FormValue("idcard_front_img")
|
|||
|
idcardBackImg := this.Req.FormValue("idcard_back_img")
|
|||
|
companyImg := this.Req.FormValue("company_img")
|
|||
|
companyName := this.Req.FormValue("company_name")
|
|||
|
companySn := this.Req.FormValue("company_sn")
|
|||
|
|
|||
|
if name == "" || phone == "" || idcard == "" || idcardFrontImg == "" || idcardBackImg == "" || companyImg == "" || companyName == "" || companySn == "" {
|
|||
|
this.Display(3, "参数异常")
|
|||
|
return
|
|||
|
}
|
|||
|
t := time.Now().Unix()
|
|||
|
|
|||
|
company := this.Db.Get("company", "id", Map{"sn": companySn})
|
|||
|
if company == nil {
|
|||
|
company = Map{
|
|||
|
"name": companyName,
|
|||
|
"sn": companySn,
|
|||
|
"create_time": t,
|
|||
|
"org_id": orgId,
|
|||
|
"modify_time": t,
|
|||
|
"status": 1,
|
|||
|
"state": 0,
|
|||
|
"img": companyImg,
|
|||
|
}
|
|||
|
|
|||
|
company["id"] = this.Db.Insert("company", company)
|
|||
|
|
|||
|
if company.GetCeilInt("id") == 0 {
|
|||
|
this.Display(4, "无法创建企业")
|
|||
|
return
|
|||
|
}
|
|||
|
} else {
|
|||
|
company["status"] = 1
|
|||
|
company["modify_time"] = t
|
|||
|
company["img"] = companyImg
|
|||
|
company["org_id"] = orgId
|
|||
|
|
|||
|
re := this.Db.Update("company", company, Map{"id": company.GetCeilInt("id")})
|
|||
|
if re == 0 {
|
|||
|
this.Display(4, "无法更新企业")
|
|||
|
return
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
userInfo := this.Session("wechatInfo").ToMap()
|
|||
|
user := this.Db.Get("user", "*", Map{"phone": phone})
|
|||
|
data := Map{"name": name,
|
|||
|
"phone": phone,
|
|||
|
"org_id": orgId,
|
|||
|
"idcard": idcard,
|
|||
|
"idcard_front_img": idcardFrontImg,
|
|||
|
"company_id": company.GetCeilInt("id"),
|
|||
|
"idcard_back_img": idcardBackImg,
|
|||
|
"modify_time": t,
|
|||
|
"status": 1,
|
|||
|
"company_img": companyImg}
|
|||
|
|
|||
|
//用户已经注册则更新
|
|||
|
if user != nil {
|
|||
|
re := this.Db.Update("user", data, Map{"id": user.GetCeilInt("id")})
|
|||
|
if re == 0 {
|
|||
|
this.Display(4, "无法更新用户")
|
|||
|
return
|
|||
|
}
|
|||
|
} else {
|
|||
|
data["nickname"] = userInfo.GetString("nickname")
|
|||
|
data["create_time"] = t
|
|||
|
path := time.Now().Format(this.Config.GetString("uimgPath"))
|
|||
|
filename := Md5(ObjToStr(t)) + ".jpg"
|
|||
|
down := download.Down(userInfo.GetString("avatar"), this.Config.GetString("tpt")+"/"+path, filename)
|
|||
|
if down {
|
|||
|
data["avatar"] = path + filename
|
|||
|
}
|
|||
|
user = data
|
|||
|
user["id"] = this.Db.Insert("user", data)
|
|||
|
if user.GetCeilInt("id") == 0 {
|
|||
|
this.Display(4, "无法创建用户")
|
|||
|
return
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
delete(userInfo, "avatar")
|
|||
|
delete(userInfo, "nickname")
|
|||
|
userInfo["modify_time"] = t
|
|||
|
userInfo["user_id"] = user.GetCeilInt("id")
|
|||
|
|
|||
|
wechatDb := this.Db.Get("wechat", "*", Map{"openid": userInfo.GetString("openid")})
|
|||
|
|
|||
|
if wechatDb != nil {
|
|||
|
|
|||
|
this.Db.Update("wechat", userInfo, Map{"id": wechatDb.GetCeilInt("id")})
|
|||
|
//userInfo["wid"]=wechatDb.GetCeilInt("wid")
|
|||
|
} else {
|
|||
|
userInfo["create_time"] = t
|
|||
|
userInfo["id"] = this.Db.Insert("wechat", userInfo)
|
|||
|
}
|
|||
|
|
|||
|
this.Session("user_id", user.GetCeilInt("id"))
|
|||
|
this.Display(0, "认证成功!")
|
|||
|
|
|||
|
},
|
|||
|
|
|||
|
//修改密码g
|
|||
|
"forget": func(this *Context) {
|
|||
|
if this.Session("code").Data == nil {
|
|||
|
this.Display(8, "验证码没有获取")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if this.Req.FormValue("code") == "" || this.Req.FormValue("umobile") == "" {
|
|||
|
this.Display(3, "验证码或者手机号没有输入")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if this.Req.FormValue("umobile") != this.Session("umobile").ToStr() ||
|
|||
|
this.Req.FormValue("code") != this.Session("code").ToStr() {
|
|||
|
this.Display(14, "验证码验证失败")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if len(this.Req.FormValue("upwd")) < 6 {
|
|||
|
this.Display(3, "密码没有输入")
|
|||
|
return
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
res := this.Db.Update("user", Map{"upwd": Md5(this.Req.FormValue("upwd"))}, Map{"umobile": this.Req.FormValue("umobile")})
|
|||
|
if res == 0 {
|
|||
|
this.Display(5, "找不到该用户")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
this.Display(0, "成功")
|
|||
|
},
|
|||
|
|
|||
|
"upload": func(this *Context) {
|
|||
|
file := this.Req.FormValue("file")
|
|||
|
if len(file) < 100 {
|
|||
|
this.Display(3, "图片上传错误")
|
|||
|
return
|
|||
|
}
|
|||
|
//fmt.Println(uimg)
|
|||
|
|
|||
|
btes, e := base64.StdEncoding.DecodeString(file) //成图片文件并把文件写入到buffer
|
|||
|
if e != nil {
|
|||
|
this.Display(3, "无法解析图片")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//uimgPath:=time.Now().Format(this.Config.GetString("uimgPath"))
|
|||
|
path := time.Now().Format(this.Config.GetString("imgPath"))
|
|||
|
os.MkdirAll(this.Config.GetString("tpt")+"/"+path, os.ModeDir)
|
|||
|
filePath := path + Md5(ObjToStr(time.Now().Unix())) + ".jpg"
|
|||
|
|
|||
|
err2 := ioutil.WriteFile(this.Config.GetString("tpt")+"/"+filePath, btes, 0666) //buffer输出到jpg文件中(不做处理,直接写到文件)
|
|||
|
|
|||
|
if err2 != nil {
|
|||
|
this.Display(3, "图片保存失败")
|
|||
|
return
|
|||
|
}
|
|||
|
this.Display(0, filePath)
|
|||
|
},
|
|||
|
|
|||
|
//更新个人资料
|
|||
|
//"update": func(this *Context) {
|
|||
|
// if this.Req.Form["unickname"] == nil ||
|
|||
|
// this.Req.Form["uemail"] == nil ||
|
|||
|
// this.Req.Form["usex"] == nil ||
|
|||
|
// this.Req.Form["ubirthday"] == nil ||
|
|||
|
// this.Req.Form["ubelieve"] == nil ||
|
|||
|
// this.Req.Form["utaste"] == nil ||
|
|||
|
// this.Req.Form["uname"] == nil ||
|
|||
|
// this.Req.Form["uaddreman"] == nil ||
|
|||
|
// this.Req.Form["uaddremobile"] == nil ||
|
|||
|
// this.Req.Form["uaddre"] == nil ||
|
|||
|
// this.Req.Form["uidcard"] == nil {
|
|||
|
// this.Display(3, "参数不足")
|
|||
|
// }
|
|||
|
// //更新代码
|
|||
|
// update := Map{
|
|||
|
// "unickname": this.Req.FormValue("unickname"),
|
|||
|
// "uemail": this.Req.FormValue("uemail"),
|
|||
|
// "usex": this.Req.FormValue("usex"),
|
|||
|
// "ubelieve": this.Req.FormValue("ubelieve"),
|
|||
|
// "utaste": this.Req.FormValue("utaste"),
|
|||
|
// "uaddreman": this.Req.FormValue("uaddreman"),
|
|||
|
// "uidcard": this.Req.FormValue("uidcard"),
|
|||
|
// "ubirthday": this.Req.FormValue("ubirthday"),
|
|||
|
// "uaddremobile": this.Req.FormValue("uaddremobile"),
|
|||
|
// "uaddre": this.Req.FormValue("uaddre"),
|
|||
|
// "uname": this.Req.FormValue("uname"),
|
|||
|
// }
|
|||
|
//
|
|||
|
// this.Db.Update("user", update, Map{"uid": this.Session("user_id").Data})
|
|||
|
// this.Display(0, "ok")
|
|||
|
//
|
|||
|
//},
|
|||
|
}
|