Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
正在显示
20 个修改的文件
包含
160 行增加
和
55 行删除
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | config_name = "dev" | 2 | config_name = "dev" |
| 3 | #----beego的默认配置 开始--- | 3 | #----beego的默认配置 开始--- |
| 4 | #端口号 | 4 | #端口号 |
| 5 | -httpport = 8080 | 5 | +httpport = 8080 |
| 6 | #开启应用内监控 | 6 | #开启应用内监控 |
| 7 | EnableAdmin = false | 7 | EnableAdmin = false |
| 8 | AdminPort = 8088 | 8 | AdminPort = 8088 |
| @@ -34,7 +34,7 @@ ucenter_secret = "cykbjnfqgctn" | @@ -34,7 +34,7 @@ ucenter_secret = "cykbjnfqgctn" | ||
| 34 | 34 | ||
| 35 | # 上传文件保存路径 | 35 | # 上传文件保存路径 |
| 36 | file_save_path = "/var/www/opp/file" | 36 | file_save_path = "/var/www/opp/file" |
| 37 | -file_host = "http://mmm-opp-dev.fjmaimaimai.com" | 37 | +file_host = "http://mmm-oppmg-dev.fjmaimaimai.com" |
| 38 | file_host_path = "/file/opp" | 38 | file_host_path = "/file/opp" |
| 39 | # 审批流程修改 消息发布 | 39 | # 审批流程修改 消息发布 |
| 40 | message_publish = "audit_change" | 40 | message_publish = "audit_change" |
| @@ -34,7 +34,7 @@ ucenter_secret = "cykbjnfqgctn" | @@ -34,7 +34,7 @@ ucenter_secret = "cykbjnfqgctn" | ||
| 34 | 34 | ||
| 35 | # 上传文件保存路径 | 35 | # 上传文件保存路径 |
| 36 | file_save_path = "/var/www/opp/file" | 36 | file_save_path = "/var/www/opp/file" |
| 37 | -file_host = "http://mmm-opp-dev.fjmaimaimai.com" | 37 | +file_host = "http://mmm-oppmg-test.fjmaimaimai.com" |
| 38 | file_host_path = "/file/opp" | 38 | file_host_path = "/file/opp" |
| 39 | # 审批流程修改 消息发布 | 39 | # 审批流程修改 消息发布 |
| 40 | message_publish = "audit_change" | 40 | message_publish = "audit_change" |
| @@ -37,7 +37,10 @@ func (c *AuthController) RefreshToken() { | @@ -37,7 +37,10 @@ func (c *AuthController) RefreshToken() { | ||
| 37 | return | 37 | return |
| 38 | } | 38 | } |
| 39 | err = serveauth.ResetLoginTokenRedis(logintoken) | 39 | err = serveauth.ResetLoginTokenRedis(logintoken) |
| 40 | - msg = protocol.NewReturnResponse(logintoken, err) | 40 | + data := protocol.ResponseLogin{ |
| 41 | + Access: logintoken, | ||
| 42 | + } | ||
| 43 | + msg = protocol.NewReturnResponse(data, err) | ||
| 41 | return | 44 | return |
| 42 | } | 45 | } |
| 43 | 46 | ||
| @@ -72,13 +75,51 @@ func (c *AuthController) Login() { | @@ -72,13 +75,51 @@ func (c *AuthController) Login() { | ||
| 72 | if err != nil { | 75 | if err != nil { |
| 73 | log.Error("token 信息记录redis失败") | 76 | log.Error("token 信息记录redis失败") |
| 74 | } | 77 | } |
| 75 | - data := map[string]interface{}{ | ||
| 76 | - "access": logintoken, | 78 | + data := protocol.ResponseLogin{ |
| 79 | + Access: logintoken, | ||
| 77 | } | 80 | } |
| 78 | msg = protocol.NewReturnResponse(data, nil) | 81 | msg = protocol.NewReturnResponse(data, nil) |
| 79 | return | 82 | return |
| 80 | } | 83 | } |
| 81 | 84 | ||
| 85 | +// LoginSms 登录 | ||
| 86 | +// @router /login [post] | ||
| 87 | +func (c *AuthController) LoginSms() { | ||
| 88 | + var msg *protocol.ResponseMessage | ||
| 89 | + defer func() { | ||
| 90 | + c.ResposeJson(msg) | ||
| 91 | + }() | ||
| 92 | + | ||
| 93 | + var param protocol.RequestLogin | ||
| 94 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 95 | + log.Error("json 解析失败", err) | ||
| 96 | + msg = protocol.BadRequestParam("1") | ||
| 97 | + return | ||
| 98 | + } | ||
| 99 | + // if len(param.Account) == 0 || len(param.Password) == 0 { | ||
| 100 | + // msg = protocol.BadRequestParam("10021") | ||
| 101 | + // return | ||
| 102 | + // } | ||
| 103 | + // logintoken, err := serveauth.LoginAuthByUCenter(param.Account, param.Password) | ||
| 104 | + // if err != nil { | ||
| 105 | + // msg = protocol.NewReturnResponse(nil, err) | ||
| 106 | + // return | ||
| 107 | + // } | ||
| 108 | + // err = serveauth.ResetLoginToken(logintoken) | ||
| 109 | + // if err != nil { | ||
| 110 | + // log.Error("token 信息记录数据库失败") | ||
| 111 | + // } | ||
| 112 | + // err = serveauth.ResetLoginTokenRedis(logintoken) | ||
| 113 | + // if err != nil { | ||
| 114 | + // log.Error("token 信息记录redis失败") | ||
| 115 | + // } | ||
| 116 | + // data := map[string]interface{}{ | ||
| 117 | + // "access": logintoken, | ||
| 118 | + // } | ||
| 119 | + // msg = protocol.NewReturnResponse(data, nil) | ||
| 120 | + return | ||
| 121 | +} | ||
| 122 | + | ||
| 82 | //ChangeCompany 切换公司 | 123 | //ChangeCompany 切换公司 |
| 83 | //@Router /change_company [post] | 124 | //@Router /change_company [post] |
| 84 | func (c *AuthController) ChangeCompany() { | 125 | func (c *AuthController) ChangeCompany() { |
| @@ -103,11 +144,18 @@ func (c *AuthController) ChangeCompany() { | @@ -103,11 +144,18 @@ func (c *AuthController) ChangeCompany() { | ||
| 103 | msg = protocol.NewReturnResponse(nil, err) | 144 | msg = protocol.NewReturnResponse(nil, err) |
| 104 | return | 145 | return |
| 105 | } | 146 | } |
| 147 | + err = serveauth.ResetLoginToken(logintoken) | ||
| 148 | + if err != nil { | ||
| 149 | + log.Error("token 信息记录数据库失败") | ||
| 150 | + } | ||
| 106 | err = redisdata.SetLoginToken(logintoken, userid, param.CompanyId) | 151 | err = redisdata.SetLoginToken(logintoken, userid, param.CompanyId) |
| 107 | if err != nil { | 152 | if err != nil { |
| 108 | log.Error("redisdata.SetLoginToken err:%s", err) | 153 | log.Error("redisdata.SetLoginToken err:%s", err) |
| 109 | } | 154 | } |
| 110 | - msg = protocol.NewReturnResponse(logintoken, err) | 155 | + data := protocol.ResponseLogin{ |
| 156 | + Access: logintoken, | ||
| 157 | + } | ||
| 158 | + msg = protocol.NewReturnResponse(data, err) | ||
| 111 | return | 159 | return |
| 112 | } | 160 | } |
| 113 | 161 | ||
| @@ -142,13 +190,14 @@ func (c *AuthController) Me() { | @@ -142,13 +190,14 @@ func (c *AuthController) Me() { | ||
| 142 | } | 190 | } |
| 143 | 191 | ||
| 144 | const ( | 192 | const ( |
| 145 | - captchaID = "48a6ebac4ebc6642d68c217fca33eb4d" | ||
| 146 | - privateKey = "4f1c085290bec5afdc54df73535fc361" | 193 | + captchaID = "33a2abf9c5df0d6bc3b89fb39280114b" |
| 194 | + privateKey = "13320fd2b10199e9a2440a4fbb4d46f7" | ||
| 147 | ) | 195 | ) |
| 148 | 196 | ||
| 149 | func (c *AuthController) RegisterGeetest() { | 197 | func (c *AuthController) RegisterGeetest() { |
| 150 | geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second) | 198 | geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second) |
| 151 | - status, responseBt := geetest.PreProcess("", "") | 199 | + userip := c.Ctx.Input.IP() |
| 200 | + status, responseBt := geetest.PreProcess("", userip) | ||
| 152 | c.SetSession("geetest_status", status) | 201 | c.SetSession("geetest_status", status) |
| 153 | c.Ctx.Output.Body(responseBt) | 202 | c.Ctx.Output.Body(responseBt) |
| 154 | return | 203 | return |
| @@ -20,14 +20,14 @@ type BaseController struct { | @@ -20,14 +20,14 @@ type BaseController struct { | ||
| 20 | 20 | ||
| 21 | //Prepare 实现beego.ControllerInterface 的接口 | 21 | //Prepare 实现beego.ControllerInterface 的接口 |
| 22 | func (this *BaseController) Prepare() { | 22 | func (this *BaseController) Prepare() { |
| 23 | - // this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") | ||
| 24 | - // this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") | ||
| 25 | - // if this.Ctx.Input.Method() == "OPTIONS" { | ||
| 26 | - // this.Ctx.ResponseWriter.WriteHeader(204) | ||
| 27 | - // this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") | ||
| 28 | - // //this.Ctx.WriteString("") | ||
| 29 | - // return | ||
| 30 | - // } | 23 | + this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") |
| 24 | + this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") | ||
| 25 | + if this.Ctx.Input.Method() == "OPTIONS" { | ||
| 26 | + this.Ctx.ResponseWriter.WriteHeader(204) | ||
| 27 | + this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") | ||
| 28 | + this.Ctx.WriteString("") | ||
| 29 | + return | ||
| 30 | + } | ||
| 31 | p := this.Ctx.Input.GetData("RouterPattern") | 31 | p := this.Ctx.Input.GetData("RouterPattern") |
| 32 | fmt.Println("====>r:", p) | 32 | fmt.Println("====>r:", p) |
| 33 | } | 33 | } |
| @@ -420,6 +420,7 @@ func (c *CompanyController) InitCompany() { | @@ -420,6 +420,7 @@ func (c *CompanyController) InitCompany() { | ||
| 420 | return | 420 | return |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | +// GetCompanyForUCenter 总后台调用 | ||
| 423 | //@router /ucenter/company/info [post] | 424 | //@router /ucenter/company/info [post] |
| 424 | func (c *CompanyController) GetCompanyForUCenter() { | 425 | func (c *CompanyController) GetCompanyForUCenter() { |
| 425 | var msg *protocol.ResponseMessage | 426 | var msg *protocol.ResponseMessage |
| @@ -427,6 +428,28 @@ func (c *CompanyController) GetCompanyForUCenter() { | @@ -427,6 +428,28 @@ func (c *CompanyController) GetCompanyForUCenter() { | ||
| 427 | c.ResposeJson(msg) | 428 | c.ResposeJson(msg) |
| 428 | }() | 429 | }() |
| 429 | type Paremeter struct { | 430 | type Paremeter struct { |
| 431 | + Companyid int64 `json:"company_id"` | ||
| 432 | + CompanyName string `json:"company_name"` | ||
| 433 | + } | ||
| 434 | + var param Paremeter | ||
| 435 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 436 | + log.Error("json 解析失败 err:%s", err) | ||
| 437 | + msg = protocol.BadRequestParam("1") | ||
| 438 | + return | ||
| 439 | + } | ||
| 440 | + err := servecompany.CompanyEditFromUcenter(param.Companyid, param.CompanyName) | ||
| 441 | + msg = protocol.NewReturnResponse(nil, err) | ||
| 442 | + return | ||
| 443 | +} | ||
| 444 | + | ||
| 445 | +//EditCompanyForUCenter | ||
| 446 | +//@router /ucenter/company/edit [post] | ||
| 447 | +func (c *CompanyController) EditCompanyForUCenter() { | ||
| 448 | + var msg *protocol.ResponseMessage | ||
| 449 | + defer func() { | ||
| 450 | + c.ResposeJson(msg) | ||
| 451 | + }() | ||
| 452 | + type Paremeter struct { | ||
| 430 | Companyid int64 `json:"company_id"` | 453 | Companyid int64 `json:"company_id"` |
| 431 | } | 454 | } |
| 432 | var param Paremeter | 455 | var param Paremeter |
| @@ -59,6 +59,7 @@ func saveFile(fileData *multipart.FileHeader, fileType string) (hostpath string, | @@ -59,6 +59,7 @@ func saveFile(fileData *multipart.FileHeader, fileType string) (hostpath string, | ||
| 59 | subfix := path.Ext(fileData.Filename) | 59 | subfix := path.Ext(fileData.Filename) |
| 60 | mfileName := fmt.Sprint(utils.GenerateIDBySonyflake()) | 60 | mfileName := fmt.Sprint(utils.GenerateIDBySonyflake()) |
| 61 | mfileName = fmt.Sprintf("%d_%s%s", time.Now().Unix(), mfileName, subfix) | 61 | mfileName = fmt.Sprintf("%d_%s%s", time.Now().Unix(), mfileName, subfix) |
| 62 | + log.Debug("文件保存地址%s", filepath.Join(savepath, mfileName)) | ||
| 62 | dst, err := os.Create(filepath.Join(savepath, mfileName)) | 63 | dst, err := os.Create(filepath.Join(savepath, mfileName)) |
| 63 | defer dst.Close() | 64 | defer dst.Close() |
| 64 | if err != nil { | 65 | if err != nil { |
| @@ -51,7 +51,7 @@ var AuthToken = func(ctx *context.Context) { | @@ -51,7 +51,7 @@ var AuthToken = func(ctx *context.Context) { | ||
| 51 | } | 51 | } |
| 52 | mtoken, err = serveauth.ValidJWTToken(accesstoken) | 52 | mtoken, err = serveauth.ValidJWTToken(accesstoken) |
| 53 | if err == nil { | 53 | if err == nil { |
| 54 | - storetoken, err = redisdata.GetLoginToken(mtoken.UID) | 54 | + storetoken, err = redisdata.GetLoginToken(mtoken.UID, mtoken.CompanyID) |
| 55 | if err != nil { | 55 | if err != nil { |
| 56 | log.Error("redisdata.GetLoginToken err:%s", err) | 56 | log.Error("redisdata.GetLoginToken err:%s", err) |
| 57 | msg = protocol.NewMessage("10024") | 57 | msg = protocol.NewMessage("10024") |
| @@ -91,7 +91,7 @@ var AllowOption = func(ctx *context.Context) { | @@ -91,7 +91,7 @@ var AllowOption = func(ctx *context.Context) { | ||
| 91 | AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization", | 91 | AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization", |
| 92 | "x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息 | 92 | "x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息 |
| 93 | ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息 | 93 | ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息 |
| 94 | - AllowCredentials: true, //不允许共享AuthTuffic证书 | 94 | + AllowCredentials: false, //不允许共享AuthTuffic证书 |
| 95 | AllowAllOrigins: true, //允许的请求来源 | 95 | AllowAllOrigins: true, //允许的请求来源 |
| 96 | }) | 96 | }) |
| 97 | f(ctx) | 97 | f(ctx) |
| @@ -28,7 +28,7 @@ type RequestLogin struct { | @@ -28,7 +28,7 @@ type RequestLogin struct { | ||
| 28 | 28 | ||
| 29 | //ResponseLogin 登录响应 | 29 | //ResponseLogin 登录响应 |
| 30 | type ResponseLogin struct { | 30 | type ResponseLogin struct { |
| 31 | - LoginAuthToken | 31 | + Access LoginAuthToken `json:"access"` |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | type LoginAuthToken struct { | 34 | type LoginAuthToken struct { |
| @@ -62,4 +62,5 @@ type ResponseMeInfo struct { | @@ -62,4 +62,5 @@ type ResponseMeInfo struct { | ||
| 62 | type MeCompany struct { | 62 | type MeCompany struct { |
| 63 | Id int64 `json:"id"` | 63 | Id int64 `json:"id"` |
| 64 | Name string `json:"name"` | 64 | Name string `json:"name"` |
| 65 | + Logo string `json:"logo"` | ||
| 65 | } | 66 | } |
| @@ -2,8 +2,8 @@ package protocol | @@ -2,8 +2,8 @@ package protocol | ||
| 2 | 2 | ||
| 3 | //RequestPageInfo 分页获取数据 | 3 | //RequestPageInfo 分页获取数据 |
| 4 | type RequestPageInfo struct { | 4 | type RequestPageInfo struct { |
| 5 | - PageIndex int `json:"page_index"` | ||
| 6 | - PageSize int `json:"page_size"` | 5 | + PageIndex int `json:"pageNumber"` |
| 6 | + PageSize int `json:"pageSize"` | ||
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | //ResponsePageInfo 分页信息 | 9 | //ResponsePageInfo 分页信息 |
| @@ -112,6 +112,7 @@ type UserListItem struct { | @@ -112,6 +112,7 @@ type UserListItem struct { | ||
| 112 | Positions string `json:"positions" orm:"-"` | 112 | Positions string `json:"positions" orm:"-"` |
| 113 | Roles string `json:"roles" orm:"-"` | 113 | Roles string `json:"roles" orm:"-"` |
| 114 | Departments string `json:"departments" orm:"-"` | 114 | Departments string `json:"departments" orm:"-"` |
| 115 | + Phone string `json:"phone" orm:"column(phone)"` | ||
| 115 | Enable int8 `json:"enable" orm:"column(enable)"` | 116 | Enable int8 `json:"enable" orm:"column(enable)"` |
| 116 | } | 117 | } |
| 117 | 118 | ||
| @@ -123,9 +124,8 @@ type ResponseCompanyBase struct { | @@ -123,9 +124,8 @@ type ResponseCompanyBase struct { | ||
| 123 | 124 | ||
| 124 | //CenterCompanyInfo 统一用户中心调用的公司数据 | 125 | //CenterCompanyInfo 统一用户中心调用的公司数据 |
| 125 | type CenterCompanyInfo struct { | 126 | type CenterCompanyInfo struct { |
| 126 | - CompanyId int64 `json:"company_id"` //总后台的公司id | ||
| 127 | - CompanyName string `json:"company_name"` // | ||
| 128 | - // AdminId int64 `json:"admin_id"` //统一用户中心的用户id | 127 | + CompanyId int64 `json:"company_id"` //总后台的公司id |
| 128 | + CompanyName string `json:"company_name"` // | ||
| 129 | AdminAccount string `json:"admin_account"` | 129 | AdminAccount string `json:"admin_account"` |
| 130 | AdminName string `json:"admin_name"` | 130 | AdminName string `json:"admin_name"` |
| 131 | Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】 | 131 | Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】 |
| 1 | package protocol | 1 | package protocol |
| 2 | 2 | ||
| 3 | -var NullData = struct{}{} | 3 | +var ( |
| 4 | + NullData = struct{}{} | ||
| 5 | + NullSlice = []interface{}{} | ||
| 6 | +) | ||
| 4 | 7 | ||
| 5 | //CustomErrParse 解析自定义错误结构体 | 8 | //CustomErrParse 解析自定义错误结构体 |
| 6 | type CustomErrParse interface { | 9 | type CustomErrParse interface { |
| @@ -94,9 +97,9 @@ func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { | @@ -94,9 +97,9 @@ func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) { | ||
| 94 | if data == nil { | 97 | if data == nil { |
| 95 | data = NullData | 98 | data = NullData |
| 96 | } | 99 | } |
| 100 | + | ||
| 97 | if eRR == nil { | 101 | if eRR == nil { |
| 98 | msg = NewMessage("0") | 102 | msg = NewMessage("0") |
| 99 | - | ||
| 100 | msg.Data = data | 103 | msg.Data = data |
| 101 | return msg | 104 | return msg |
| 102 | } | 105 | } |
| @@ -97,6 +97,7 @@ func init() { | @@ -97,6 +97,7 @@ func init() { | ||
| 97 | beego.NSBefore(middleware.LogRequestData), | 97 | beego.NSBefore(middleware.LogRequestData), |
| 98 | beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"), | 98 | beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"), |
| 99 | beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"), | 99 | beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"), |
| 100 | + beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"), | ||
| 100 | ) | 101 | ) |
| 101 | 102 | ||
| 102 | beego.AddNamespace(nsV1) | 103 | beego.AddNamespace(nsV1) |
| @@ -158,7 +158,7 @@ func RefreshLoginToken(refreshtoken string) (protocol.LoginAuthToken, error) { | @@ -158,7 +158,7 @@ func RefreshLoginToken(refreshtoken string) (protocol.LoginAuthToken, error) { | ||
| 158 | log.Debug("token失效 err:%s", err) | 158 | log.Debug("token失效 err:%s", err) |
| 159 | return logintoken, protocol.NewErrWithMessage("10024") | 159 | return logintoken, protocol.NewErrWithMessage("10024") |
| 160 | } | 160 | } |
| 161 | - storetoken, err = redisdata.GetLoginToken(mtoken.UID) | 161 | + storetoken, err = redisdata.GetLoginToken(mtoken.UID, mtoken.CompanyID) |
| 162 | if err != nil { | 162 | if err != nil { |
| 163 | log.Error("redis err:%s", err) | 163 | log.Error("redis err:%s", err) |
| 164 | return logintoken, protocol.NewErrWithMessage("10024") | 164 | return logintoken, protocol.NewErrWithMessage("10024") |
| @@ -308,6 +308,7 @@ func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) { | @@ -308,6 +308,7 @@ func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) { | ||
| 308 | t := protocol.MeCompany{ | 308 | t := protocol.MeCompany{ |
| 309 | Id: v.Id, | 309 | Id: v.Id, |
| 310 | Name: v.Name, | 310 | Name: v.Name, |
| 311 | + Logo: v.Logo, | ||
| 311 | } | 312 | } |
| 312 | mecompanys = append(mecompanys, t) | 313 | mecompanys = append(mecompanys, t) |
| 313 | } | 314 | } |
| @@ -155,9 +155,10 @@ func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*mode | @@ -155,9 +155,10 @@ func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*mode | ||
| 155 | return nil, err | 155 | return nil, err |
| 156 | } | 156 | } |
| 157 | } else if err == orm.ErrNoRows { | 157 | } else if err == orm.ErrNoRows { |
| 158 | - ucenterUser, err := ucenter.RequestUCenterAddUser(centerCompany.AdminAccount, centerCompany.AdminName, "") | 158 | + ucenterUser, err := ucenter.RequestUCenterAddUser(centerCompany.AdminAccount, centerCompany.AdminName, "http://这是默认图.jpeg") |
| 159 | if err != nil { | 159 | if err != nil { |
| 160 | log.Error("获取统一用户中心数据失败 :%s", err) | 160 | log.Error("获取统一用户中心数据失败 :%s", err) |
| 161 | + return nil, err | ||
| 161 | } | 162 | } |
| 162 | //添加用户 | 163 | //添加用户 |
| 163 | newUser = &models.User{ | 164 | newUser = &models.User{ |
| @@ -403,6 +404,23 @@ func CompanyInfoEdit(companyid int64, logo string) error { | @@ -403,6 +404,23 @@ func CompanyInfoEdit(companyid int64, logo string) error { | ||
| 403 | 404 | ||
| 404 | return nil | 405 | return nil |
| 405 | } | 406 | } |
| 407 | + | ||
| 408 | +// | ||
| 409 | +func CompanyEditFromUcenter(companyid int64, companyname string) error { | ||
| 410 | + companyinfo, err := models.GetCompanyByUCenter(companyid) | ||
| 411 | + if err != nil { | ||
| 412 | + log.Error("获取公司数据失败") | ||
| 413 | + return protocol.NewErrWithMessage("1") | ||
| 414 | + } | ||
| 415 | + companyinfo.Name = companyname | ||
| 416 | + err = models.UpdateCompanyById(companyinfo, []string{"Name"}) | ||
| 417 | + if err != nil { | ||
| 418 | + log.Info("更新公司数据失败:%s", err) | ||
| 419 | + return protocol.NewErrWithMessage("1") | ||
| 420 | + } | ||
| 421 | + return nil | ||
| 422 | +} | ||
| 423 | + | ||
| 406 | func CompanyBaseInfo(companyid int64) (*protocol.ResponseCompanyBase, error) { | 424 | func CompanyBaseInfo(companyid int64) (*protocol.ResponseCompanyBase, error) { |
| 407 | var ( | 425 | var ( |
| 408 | err error | 426 | err error |
| @@ -377,25 +377,26 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs | @@ -377,25 +377,26 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs | ||
| 377 | department *models.Department | 377 | department *models.Department |
| 378 | err error | 378 | err error |
| 379 | ) | 379 | ) |
| 380 | + var ( | ||
| 381 | + returnData []protocol.DepartUserBase | ||
| 382 | + ) | ||
| 380 | department, err = models.GetDepartmentById(departmentid) | 383 | department, err = models.GetDepartmentById(departmentid) |
| 381 | if err != nil { | 384 | if err != nil { |
| 382 | log.Error("获取部门失败:%s", err) | 385 | log.Error("获取部门失败:%s", err) |
| 383 | - return nil, nil | 386 | + return returnData, nil |
| 384 | } | 387 | } |
| 385 | if department.CompanyId != companyid { | 388 | if department.CompanyId != companyid { |
| 386 | log.Error("deparment.CompanyId err") | 389 | log.Error("deparment.CompanyId err") |
| 387 | - return nil, protocol.NewErrWithMessage("1") | 390 | + return returnData, protocol.NewErrWithMessage("1") |
| 388 | } | 391 | } |
| 389 | const dataSql string = `SELECT b.nick_name,a.user_company_id FROM user_department AS a | 392 | const dataSql string = `SELECT b.nick_name,a.user_company_id FROM user_department AS a |
| 390 | JOIN user_company AS b ON a.user_company_id = b.id | 393 | JOIN user_company AS b ON a.user_company_id = b.id |
| 391 | WHERE a.department_id=? AND b.delete_at=0 AND a.enable_status = 1 ` | 394 | WHERE a.department_id=? AND b.delete_at=0 AND a.enable_status = 1 ` |
| 392 | - var ( | ||
| 393 | - returnData []protocol.DepartUserBase | ||
| 394 | - ) | 395 | + |
| 395 | err = utils.ExecuteQueryAll(&returnData, dataSql, department.Id) | 396 | err = utils.ExecuteQueryAll(&returnData, dataSql, department.Id) |
| 396 | if err != nil { | 397 | if err != nil { |
| 397 | log.Error("EXECUTE SQL err:%s", err) | 398 | log.Error("EXECUTE SQL err:%s", err) |
| 398 | - return nil, protocol.NewErrWithMessage("1") | 399 | + return returnData, protocol.NewErrWithMessage("1") |
| 399 | } | 400 | } |
| 400 | return returnData, nil | 401 | return returnData, nil |
| 401 | } | 402 | } |
| @@ -493,7 +493,7 @@ func UserDelete(userCompanyids []int64, companyid int64) error { | @@ -493,7 +493,7 @@ func UserDelete(userCompanyids []int64, companyid int64) error { | ||
| 493 | return protocol.NewErrWithMessage("1") | 493 | return protocol.NewErrWithMessage("1") |
| 494 | } | 494 | } |
| 495 | for _, v := range updateIds { | 495 | for _, v := range updateIds { |
| 496 | - e := redisdata.DeleteLoginToken(v.UserId) | 496 | + e := redisdata.DeleteLoginToken(v.UserId, companyid) |
| 497 | if e != nil { | 497 | if e != nil { |
| 498 | log.Error(e.Error()) | 498 | log.Error(e.Error()) |
| 499 | } | 499 | } |
| @@ -517,7 +517,7 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) | @@ -517,7 +517,7 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) | ||
| 517 | ) | 517 | ) |
| 518 | cond = append(cond, param.Companyid) | 518 | cond = append(cond, param.Companyid) |
| 519 | if len(param.NickName) > 0 { | 519 | if len(param.NickName) > 0 { |
| 520 | - whereString += ` AND b.nick_name LIKE ? ` | 520 | + whereString += ` AND a.nick_name LIKE ? ` |
| 521 | likeCond := "%" + param.NickName + "%" | 521 | likeCond := "%" + param.NickName + "%" |
| 522 | cond = append(cond, likeCond) | 522 | cond = append(cond, likeCond) |
| 523 | } | 523 | } |
| @@ -538,9 +538,9 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) | @@ -538,9 +538,9 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) | ||
| 538 | } | 538 | } |
| 539 | for k, v := range result { | 539 | for k, v := range result { |
| 540 | var ( | 540 | var ( |
| 541 | - pname []string | ||
| 542 | - dname []string | ||
| 543 | - rname []string | 541 | + pname = make([]string, 0) |
| 542 | + dname = make([]string, 0) | ||
| 543 | + rname = make([]string, 0) | ||
| 544 | ) | 544 | ) |
| 545 | positions := GetUserPosition(v.UserCompanydId) | 545 | positions := GetUserPosition(v.UserCompanydId) |
| 546 | for i := range positions { | 546 | for i := range positions { |
| @@ -570,7 +570,7 @@ func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase { | @@ -570,7 +570,7 @@ func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase { | ||
| 570 | WHERE a.enable_status =1 AND a.user_company_id =? ` | 570 | WHERE a.enable_status =1 AND a.user_company_id =? ` |
| 571 | var ( | 571 | var ( |
| 572 | err error | 572 | err error |
| 573 | - data []protocol.DepartmentBase | 573 | + data = make([]protocol.DepartmentBase, 0) |
| 574 | ) | 574 | ) |
| 575 | err = utils.ExecuteQueryAll(&data, datasql, usercompanyid) | 575 | err = utils.ExecuteQueryAll(&data, datasql, usercompanyid) |
| 576 | if err != nil { | 576 | if err != nil { |
| @@ -676,7 +676,7 @@ func UserForbid(userCompanyids []int64, companyid int64) error { | @@ -676,7 +676,7 @@ func UserForbid(userCompanyids []int64, companyid int64) error { | ||
| 676 | } | 676 | } |
| 677 | log.Info("更新记录数:%d", num) | 677 | log.Info("更新记录数:%d", num) |
| 678 | for _, v := range updateIds { | 678 | for _, v := range updateIds { |
| 679 | - e := redisdata.DeleteLoginToken(v.UserId) | 679 | + e := redisdata.DeleteLoginToken(v.UserId, companyid) |
| 680 | if e != nil { | 680 | if e != nil { |
| 681 | log.Error(e.Error()) | 681 | log.Error(e.Error()) |
| 682 | } | 682 | } |
| @@ -43,6 +43,7 @@ func (client UCenterClient) buildHeader() http.Header { | @@ -43,6 +43,7 @@ func (client UCenterClient) buildHeader() http.Header { | ||
| 43 | h.Set("nonce", "") | 43 | h.Set("nonce", "") |
| 44 | h.Set("curTime", nowTime) | 44 | h.Set("curTime", nowTime) |
| 45 | h.Set("checkSum", checksum) | 45 | h.Set("checkSum", checksum) |
| 46 | + h.Set("Accept", "application/json") | ||
| 46 | return h | 47 | return h |
| 47 | } | 48 | } |
| 48 | 49 | ||
| @@ -64,7 +65,7 @@ func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([] | @@ -64,7 +65,7 @@ func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([] | ||
| 64 | } | 65 | } |
| 65 | req.Header = client.buildHeader() | 66 | req.Header = client.buildHeader() |
| 66 | resp, err := httpclient.Do(req) | 67 | resp, err := httpclient.Do(req) |
| 67 | - | 68 | + log.Info("====>Send To URL:%s", reqURL) |
| 68 | log.Info("====>Send To UCenter:%s", string(posts)) | 69 | log.Info("====>Send To UCenter:%s", string(posts)) |
| 69 | // log.Info("====>Send Header:%v", req.Header) | 70 | // log.Info("====>Send Header:%v", req.Header) |
| 70 | if err != nil { | 71 | if err != nil { |
| 1 | package redisdata | 1 | package redisdata |
| 2 | 2 | ||
| 3 | +import "fmt" | ||
| 4 | + | ||
| 3 | const ( | 5 | const ( |
| 4 | KEY_PREFIX string = "oppmg_" //统一前缀 | 6 | KEY_PREFIX string = "oppmg_" //统一前缀 |
| 5 | KEY_USER_TOKEN string = "token" //登录token存储 | 7 | KEY_USER_TOKEN string = "token" //登录token存储 |
| @@ -10,3 +12,8 @@ type RedisLoginToken struct { | @@ -10,3 +12,8 @@ type RedisLoginToken struct { | ||
| 10 | RefreshToken string `json:"refresh_token"` | 12 | RefreshToken string `json:"refresh_token"` |
| 11 | CurrentCompany int64 `json:"current_company"` | 13 | CurrentCompany int64 `json:"current_company"` |
| 12 | } | 14 | } |
| 15 | + | ||
| 16 | +func GetKeyLoginToken(userid int64, companyid int64) string { | ||
| 17 | + key := fmt.Sprintf("%s%s:%d_%d", KEY_PREFIX, KEY_USER_TOKEN, userid, companyid) | ||
| 18 | + return key | ||
| 19 | +} |
| @@ -2,7 +2,6 @@ package redisdata | @@ -2,7 +2,6 @@ package redisdata | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "encoding/json" | 4 | "encoding/json" |
| 5 | - "fmt" | ||
| 6 | "oppmg/common/log" | 5 | "oppmg/common/log" |
| 7 | "oppmg/common/redis" | 6 | "oppmg/common/redis" |
| 8 | "oppmg/protocol" | 7 | "oppmg/protocol" |
| @@ -26,12 +25,12 @@ func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64) | @@ -26,12 +25,12 @@ func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64) | ||
| 26 | } | 25 | } |
| 27 | value, _ = json.Marshal(data) | 26 | value, _ = json.Marshal(data) |
| 28 | exp = param.RefreshExpires - nowTime | 27 | exp = param.RefreshExpires - nowTime |
| 29 | - key = fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) | 28 | + key = GetKeyLoginToken(userid, companyid) |
| 30 | err = client.Set(key, string(value), time.Duration(exp)*time.Second).Err() | 29 | err = client.Set(key, string(value), time.Duration(exp)*time.Second).Err() |
| 31 | return err | 30 | return err |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | -func GetLoginToken(userid int64) (RedisLoginToken, error) { | 33 | +func GetLoginToken(userid int64, companyid int64) (RedisLoginToken, error) { |
| 35 | client := redis.GetRedis() | 34 | client := redis.GetRedis() |
| 36 | var ( | 35 | var ( |
| 37 | key string | 36 | key string |
| @@ -39,7 +38,7 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) { | @@ -39,7 +38,7 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) { | ||
| 39 | err error | 38 | err error |
| 40 | result RedisLoginToken | 39 | result RedisLoginToken |
| 41 | ) | 40 | ) |
| 42 | - key = fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) | 41 | + key = GetKeyLoginToken(userid, companyid) |
| 43 | value, err = client.Get(key).Result() | 42 | value, err = client.Get(key).Result() |
| 44 | if err != nil { | 43 | if err != nil { |
| 45 | return result, err | 44 | return result, err |
| @@ -53,9 +52,9 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) { | @@ -53,9 +52,9 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) { | ||
| 53 | return result, nil | 52 | return result, nil |
| 54 | } | 53 | } |
| 55 | 54 | ||
| 56 | -func ExistLoginToken(userid int64) bool { | 55 | +func ExistLoginToken(userid int64, companyid int64) bool { |
| 57 | client := redis.GetRedis() | 56 | client := redis.GetRedis() |
| 58 | - key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) | 57 | + key := GetKeyLoginToken(userid, companyid) |
| 59 | value := client.Exists(key).Val() | 58 | value := client.Exists(key).Val() |
| 60 | if value > 0 { | 59 | if value > 0 { |
| 61 | return true | 60 | return true |
| @@ -63,17 +62,17 @@ func ExistLoginToken(userid int64) bool { | @@ -63,17 +62,17 @@ func ExistLoginToken(userid int64) bool { | ||
| 63 | return false | 62 | return false |
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | -func DeleteLoginToken(userid int64) error { | 65 | +func DeleteLoginToken(userid int64, companyid int64) error { |
| 67 | client := redis.GetRedis() | 66 | client := redis.GetRedis() |
| 68 | - key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) | 67 | + key := GetKeyLoginToken(userid, companyid) |
| 69 | err := client.Del(key).Err() | 68 | err := client.Del(key).Err() |
| 70 | return err | 69 | return err |
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | // 刷新token 的有效期 | 72 | // 刷新token 的有效期 |
| 74 | -func RefreshLoginTokenExpires(userid int64) error { | 73 | +func RefreshLoginTokenExpires(userid int64, companyid int64) error { |
| 75 | client := redis.GetRedis() | 74 | client := redis.GetRedis() |
| 76 | - key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid) | 75 | + key := GetKeyLoginToken(userid, companyid) |
| 77 | result, err := client.Exists(key).Result() | 76 | result, err := client.Exists(key).Result() |
| 78 | if err != nil { | 77 | if err != nil { |
| 79 | return err | 78 | return err |
-
请 注册 或 登录 后发表评论