作者 唐旭辉

添加人员 bug 修改

... ... @@ -83,7 +83,7 @@ func (c *AuthController) Login() {
return
}
// LoginSms 登录
// LoginSms 短信验证码登录
// @router /login_sms [post]
func (c *AuthController) LoginSms() {
var msg *protocol.ResponseMessage
... ... @@ -102,9 +102,11 @@ func (c *AuthController) LoginSms() {
return
}
// logintoken
msg = protocol.NewReturnResponse(nil, nil)
logintoken, err := serveauth.LoginAuthBySmsCode(param.Account, param.Code)
data := protocol.ResponseLogin{
Access: logintoken,
}
msg = protocol.NewReturnResponse(data, err)
return
}
... ...
package company
import (
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
... ... @@ -234,6 +235,7 @@ func initDepartment(newCompany *models.Company, newusercompany *models.UserCompa
Name: newCompany.Name,
IsTop: 1,
ParentId: 0,
Relation: fmt.Sprint(utils.GenerateIDBySonyflake()),
}
newDepartment.SetManages([]int64{newusercompany.Id})
_, err = models.AddDepartment(newDepartment, o)
... ...
... ... @@ -50,6 +50,7 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
UpdateAt: time.Now(),
DeleteAt: time.Now(),
ParentId: param.ParentID,
Relation: fmt.Sprint(utils.GenerateIDBySonyflake()),
}
departmentAdd.SetManages(nil)
o := orm.NewOrm()
... ...
... ... @@ -5,6 +5,7 @@ import (
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/services/ucenter"
"oppmg/storage/redisdata"
"oppmg/utils"
"strings"
... ... @@ -44,10 +45,16 @@ func UserAdd(param protocol.RequestUserAdd) error {
userId int64
userCompanyid int64
)
resp, err := ucenter.RequestUCenterAddUser(param.Name, param.Phone, "")
if err != nil {
log.Error("用户数据提交用户中心失败:%s", err)
return protocol.NewErrWithMessage("1")
}
o := orm.NewOrm()
o.Begin()
//添加用户
userId, err = addNewUser(param.Name, param.Phone, o)
userId, err = addNewUser(resp.Data.Nickname, resp.Data.Phone,
resp.Data.Id, resp.Data.Avatar, resp.Data.Accid, resp.Data.CustomerAccount, o)
if err != nil {
o.Rollback()
log.Error("addNewUser err:%s", err)
... ... @@ -99,7 +106,6 @@ func validCompanyRole(companyid int64, roleid []int64) error {
log.Error(e.Error())
return protocol.NewErrWithMessage("10031")
}
}
return nil
}
... ... @@ -164,44 +170,9 @@ func existCompanyUser(companyid int64, phone string) error {
return nil
}
//registUser 注册用户
// func registUser(userIn *models.User, companyid int64, o orm.Ormer) error {
// var (
// err error
// usrData *models.User
// )
// usrData, err = models.GetUserByPhone(userIn.Phone)
// if err != nil && err != orm.ErrNoRows {
// return err
// }
// if err == orm.ErrNoRows {
// //用户不存在 添加用户
// _, err := models.AddUser(userIn, o)
// if err != nil {
// return err
// }
// }
// if err == nil {
// // 用户存在,更新用户
// usrData.NickName = userIn.NickName
// err = models.UpdateUserById(usrData, []string{"NickName"}, o)
// if err != nil {
// return err
// }
// }
// musercompany := &models.UserCompany{
// CompanyId: companyid,
// UserId: userIn.Id,
// }
// _, err = models.AddUserCompany(musercompany, o)
// if err != nil {
// return err
// }
// return nil
// }
func addNewUser(name string, phone string, o orm.Ormer) (userid int64, err error) {
// /resp.Data.Avatar, resp.Data.Accid, resp.Data.CustomerAccount
func addNewUser(name string, phone string, ucenterId int64, avatar string, accid int64, customerAccout int64,
o orm.Ormer) (userid int64, err error) {
var (
usrData *models.User
)
... ... @@ -212,8 +183,11 @@ func addNewUser(name string, phone string, o orm.Ormer) (userid int64, err error
if err == orm.ErrNoRows {
//用户不存在 添加用户
usrData = &models.User{
Phone: phone,
NickName: name,
Phone: phone,
NickName: name,
Icon: avatar,
Accid: accid,
CsAccount: customerAccout,
}
_, err := models.AddUser(usrData, o)
if err != nil {
... ...