作者 yangfu

切换公司

... ... @@ -11,6 +11,8 @@
|修改手机号|完成|2019.11.20|/v1/user/changePhone|
|修改密码|完成|2019.11.20|v1/user/changePassword|
|忘记密码|完成|2019.11.20|v1/user/resetPassword|
|切换企业| | |v1/user/switchCompany|
|用户公司列表| | |v1/user/companys|
|机会评论列表|完成|2019.11.21|/v1/chance/comments|
|我来评论|完成|2019.11.21|/v1/chance/iComment|
|我的评论|完成|2019.11.21|/v1/chance/iComments|
... ... @@ -33,7 +35,6 @@
|模板列表|进行中| |v1/chance/templates|
|提交机会|进行中| |v1/chance/submit|
|部门列表|完成|2019.12.3|v1/department/departments|
|配置-机会类型| | |v1/config/chanceType|
|配置-评分| | |v1/config/score|
|机会审核| | |v1/chance/audit|
|机会修改评分| | |v1/chance/editScore|
... ...
... ... @@ -95,3 +95,45 @@ func (this *UserController) ChangePassword() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(user.ChangePassword(header, request))
}
//UserCompanys
//@router /userCompanys [post]
func (this *UserController) UserCompanys() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.UserCompanysRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(user.UserCompanys(header, request))
}
//SwitchCompany
//@router /switchCompany [post]
func (this *UserController) SwitchCompany() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SwitchCompanyRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(user.SwitchCompany(header, request))
}
... ...
... ... @@ -3,7 +3,6 @@ package utils
import (
"errors"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"reflect"
... ... @@ -13,11 +12,11 @@ import (
func UpdateTableByMap(tabeleStruct interface{}, changeMap map[string]interface{}) error {
if reflect.TypeOf(tabeleStruct).Kind() != reflect.Ptr {
err := errors.New("UpdateTableByMap: tableStruct must ptr")
beego.Error(err)
log.Error(err)
return err
}
if len(changeMap) < 1 {
beego.Info("changeMap is nil")
log.Info("changeMap is nil")
return nil
}
o := orm.NewOrm()
... ... @@ -25,13 +24,13 @@ func UpdateTableByMap(tabeleStruct interface{}, changeMap map[string]interface{}
for i, v := range changeMap {
changeColumn = append(changeColumn, i)
if err := SetStructValueByType(tabeleStruct, i, v); err != nil {
beego.Error(err, i, v)
log.Error(err, i, v)
return err
}
}
num, err := o.Update(tabeleStruct, changeColumn...)
if err != nil {
beego.Error(err)
log.Error(err)
return err
}
log.Info(fmt.Sprintf("UpdateTableByMap: table:%s effect records:%d column:%v", GetTableName(tabeleStruct), num, changeColumn))
... ...
... ... @@ -31,3 +31,16 @@ type ChangePasswordRequest struct {
}
type ChangePasswordResponse struct {
}
/*UserCompanys */
type UserCompanysRequest struct {
}
type UserCompanysResponse struct {
}
/*SwitchCompany */
type SwitchCompanyRequest struct {
CompanyId int64 `json:"company_id" valid:"Required"`
}
type SwitchCompanyResponse struct {
}
... ...
... ... @@ -239,4 +239,20 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "SwitchCompany",
Router: `/switchCompany`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UserController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UserController"],
beego.ControllerComments{
Method: "UserCompanys",
Router: `/userCompanys`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
}
... ...
... ... @@ -108,3 +108,31 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
err = utils.UpdateTableByMap(&models.User{Id: user.Id}, map[string]interface{}{"Passwd": request.NewPwd})
return
}
func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanysRequest) (rsp *protocol.UserCompanysResponse, err error) {
var ()
rsp = &protocol.UserCompanysResponse{}
return
}
//切换公司
func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
var (
company *models.UserCompany
auth *models.UserAuth
)
rsp = &protocol.SwitchCompanyResponse{}
if company, err = repository.UserCompany.GetUserCompanyByUserId(header.Uid, int64(request.CompanyId)); err != nil {
log.Error(err)
return
}
if auth, err = repository.UserAuth.GetUserAuthByUserId(header.Uid, header.DeviceType); err != nil {
log.Error(err)
return
}
if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{"CurrentCompanyId": company.CompanyId}); err != nil {
log.Error(err)
return
}
return
}
... ...