作者 tangxvhui

同步数据添加 员工

... ... @@ -7,6 +7,7 @@ import (
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/services/ucenter"
"oppmg/utils"
"time"
... ... @@ -170,17 +171,27 @@ func AddEmployeeData(data []ModuleEmployee) error {
var (
userdata *models.User
)
ucenterReturn, err := ucenter.RequestUCenterAddUser(v.Phone, v.Name, "")
if err != nil {
log.Error("请求统一用户中心数据失败:%s", err)
continue
}
v.OpenId = ucenterReturn.Data.Id
userdata, err = models.GetUserByUCenter(v.OpenId)
if err != nil && err != orm.ErrNoRows {
log.Error("获取用户数据失败,err:%s", err)
return errors.New("获取用户数据失败")
}
if err == orm.ErrNoRows {
//添加用户
userdata = &models.User{
UserCenterId: v.OpenId,
NickName: v.Name,
Phone: v.Phone,
Accid: ucenterReturn.Data.Accid,
Icon: ucenterReturn.Data.Avatar,
CsAccount: ucenterReturn.Data.CustomerAccount,
}
_, err = models.AddUser(userdata)
if err != nil {
... ...