|
@@ -1,6 +1,10 @@
|
|
package models
|
|
package models
|
|
|
|
|
|
-import "rdluck_tools/orm"
|
|
|
|
|
|
+import (
|
|
|
|
+ "hongze/hongze_cygx/utils"
|
|
|
|
+ "rdluck_tools/orm"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
|
|
type UserDetail struct {
|
|
type UserDetail struct {
|
|
Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
|
|
Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
|
|
@@ -9,7 +13,7 @@ type UserDetail struct {
|
|
NickName string `description:"用户昵称"`
|
|
NickName string `description:"用户昵称"`
|
|
RealName string `description:"用户实际名称"`
|
|
RealName string `description:"用户实际名称"`
|
|
CompanyName string `description:"公司名称"`
|
|
CompanyName string `description:"公司名称"`
|
|
- PermissionName string `description:"拥有权限分类"`
|
|
|
|
|
|
+ PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
|
|
HasPermission bool `description:"true:有权限,false:无权限"`
|
|
HasPermission bool `description:"true:有权限,false:无权限"`
|
|
}
|
|
}
|
|
|
|
|
|
@@ -24,3 +28,115 @@ type UserPermission struct {
|
|
CompanyName string `description:"公司名称"`
|
|
CompanyName string `description:"公司名称"`
|
|
ChartPermissionName string `description:"权限"`
|
|
ChartPermissionName string `description:"权限"`
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+type LoginReq struct {
|
|
|
|
+ LoginType int `description:"登录方式:1:手机,2:邮箱"`
|
|
|
|
+ Mobile string `description:"手机号"`
|
|
|
|
+ Email string `description:"邮箱"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {
|
|
|
|
+ //loginType 登录方式:1:手机,2:邮箱
|
|
|
|
+
|
|
|
|
+ utils.FileLog.Info("绑定参数:%s %s %d %d", unionId, mobile, userId, loginType)
|
|
|
|
+
|
|
|
|
+ sql := ``
|
|
|
|
+ if loginType == 1 {
|
|
|
|
+ sql = `SELECT * FROM wx_user WHERE mobile = ? `
|
|
|
|
+ } else {
|
|
|
|
+ sql = "SELECT * FROM wx_user WHERE email = ? "
|
|
|
|
+ }
|
|
|
|
+ user := new(WxUser)
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ err = o.Raw(sql, mobile).QueryRow(&user)
|
|
|
|
+
|
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
|
|
|
|
+ utils.FileLog.Info("用户不存在,根据union_id绑定")
|
|
|
|
+ msql := ``
|
|
|
|
+ if loginType == 1 {
|
|
|
|
+ msql = "UPDATE wx_user SET mobile = ?,bind_account = ? WHERE union_id = ? "
|
|
|
|
+ } else {
|
|
|
|
+ msql = "UPDATE wx_user SET email = ?,bind_account = ? WHERE union_id = ? "
|
|
|
|
+ }
|
|
|
|
+ _, err = o.Raw(msql, mobile, mobile, unionId).Exec()
|
|
|
|
+ wxUserId = userId
|
|
|
|
+ } else {
|
|
|
|
+ utils.FileLog.Info("用户存在,user.UnionId:%s", user.UnionId)
|
|
|
|
+ if user.UnionId == "" {
|
|
|
|
+ sql = `SELECT * FROM wx_user WHERE union_id = ? `
|
|
|
|
+ userInfo := new(WxUser)
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ err = o.Raw(sql, unionId).QueryRow(&userInfo)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ utils.FileLog.Info("user.RegisterTime %s", user.RegisterTime.Format(utils.FormatDateTime))
|
|
|
|
+ utils.FileLog.Info("userInfo.RegisterTime %s", userInfo.RegisterTime.Format(utils.FormatDateTime))
|
|
|
|
+
|
|
|
|
+ var maxRegisterTime time.Time
|
|
|
|
+ if user.RegisterTime.Before(userInfo.RegisterTime) {
|
|
|
|
+ maxRegisterTime = user.RegisterTime
|
|
|
|
+ utils.FileLog.Info("after")
|
|
|
|
+ } else {
|
|
|
|
+ maxRegisterTime = userInfo.RegisterTime
|
|
|
|
+ utils.FileLog.Info("not after")
|
|
|
|
+ }
|
|
|
|
+ utils.FileLog.Info("maxRegisterTime %s", maxRegisterTime.Format(utils.FormatDateTime))
|
|
|
|
+ wxUserId = user.UserId
|
|
|
|
+ dsql := ` DELETE FROM wx_user WHERE union_id = ? `
|
|
|
|
+ _, err = o.Raw(dsql, unionId).Exec()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return wxUserId, err
|
|
|
|
+ }
|
|
|
|
+ msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
|
|
|
|
+ _, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
|
|
|
|
+ wxUserId = user.UserId
|
|
|
|
+ } else {
|
|
|
|
+ sql = `SELECT * FROM wx_user WHERE user_id = ? `
|
|
|
|
+ userInfo := new(WxUser)
|
|
|
|
+ o := orm.NewOrm()
|
|
|
|
+ err = o.Raw(sql, userId).QueryRow(&userInfo)
|
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ dsql := ` DELETE FROM wx_user WHERE user_id = ? `
|
|
|
|
+ _, err = o.Raw(dsql, userId).Exec()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return user.UserId, err
|
|
|
|
+ }
|
|
|
|
+ if user.Mobile == "" && loginType == 1 {
|
|
|
|
+ msql := ` UPDATE wx_user SET mobile = ?,bind_account = ? WHERE user_id = ?`
|
|
|
|
+ _, err = o.Raw(msql, mobile, mobile, user.UserId).Exec()
|
|
|
|
+ wxUserId = user.UserId
|
|
|
|
+ }
|
|
|
|
+ if user.Email == "" && loginType == 2 {
|
|
|
|
+ msql := ` UPDATE wx_user SET email = ?,bind_account = ? WHERE user_id = ?`
|
|
|
|
+ _, err = o.Raw(msql, mobile, mobile, user.UserId).Exec()
|
|
|
|
+ wxUserId = user.UserId
|
|
|
|
+ }
|
|
|
|
+ utils.FileLog.Info("用户存在,bind:%s,%d,%s", unionId, wxUserId)
|
|
|
|
+ wxUserId = userId
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+type LoginResp struct {
|
|
|
|
+ UserId int `description:"用户id"`
|
|
|
|
+ Authorization string `description:"Token"`
|
|
|
|
+ Headimgurl string `description:"用户头像"`
|
|
|
|
+ Mobile string `description:"手机号"`
|
|
|
|
+ Email string `description:"邮箱"`
|
|
|
|
+ CompanyName string `description:"客户名称"`
|
|
|
|
+ Status string `description:"状态"`
|
|
|
|
+ EndDate string `description:"到期日期"`
|
|
|
|
+ ProductName string `description:"客户类型名称"`
|
|
|
|
+}
|