...
|
...
|
@@ -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 {
|
...
|
...
|
|