...
|
...
|
@@ -137,32 +137,41 @@ func validCompanyPosition(companyid int64, positionid []int64) error { |
|
|
//registUser 注册用户
|
|
|
func registUser(userIn *models.User, companyid int64, o orm.Ormer) error {
|
|
|
var (
|
|
|
err error
|
|
|
// usrData *models.User
|
|
|
err error
|
|
|
usrData *models.User
|
|
|
)
|
|
|
_, err = models.GetUserByPhone(userIn.Phone)
|
|
|
if err == nil {
|
|
|
return nil
|
|
|
}
|
|
|
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
|
|
|
ok := models.ExistUserCompany(usrData.Id, companyid)
|
|
|
if !ok {
|
|
|
_, err = models.AddUserCompany(musercompany, o)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
//更新
|
|
|
return nil
|
|
|
err = models.EnableUserCompany(usrData.Id, companyid)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func editUserDepart(userid int64, companyid int64, departids []int64, o orm.Ormer) error {
|
...
|
...
|
@@ -338,10 +347,77 @@ func UserEdit(param protocol.RequestUserEdit) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func UserDelete(param protocol.RequestUserAdd) error {
|
|
|
func UserDelete(userid, companyid int64) error {
|
|
|
ok := models.ExistUserCompany(userid, companyid)
|
|
|
if !ok {
|
|
|
e := fmt.Errorf("ExistUserCompany(userid, companyid) [%d,%d] ==false ", userid, companyid)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
_, err := o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("user_id", userid).
|
|
|
Filter("company_id").
|
|
|
Update(orm.Params{
|
|
|
"delete_at": time.Now().String(),
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("UserDelete err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func UserList() error {
|
|
|
return nil
|
|
|
func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) {
|
|
|
|
|
|
datasql := `SELECT a.company_id,a.user_id,a.enable, b.phone,b.nick_name
|
|
|
FROM user_company AS a
|
|
|
LEFT JOIN user AS b ON a.user_id = b.id
|
|
|
WHERE a.company_id=? AND a.delete_at = 0 `
|
|
|
countSql := `SELECT count(*)
|
|
|
FROM user_company AS a
|
|
|
LEFT JOIN user AS b ON a.user_id = b.id
|
|
|
WHERE a.company_id=? AND a.delete_at = 0 `
|
|
|
var (
|
|
|
whereString string
|
|
|
cond []interface{}
|
|
|
)
|
|
|
cond = append(cond, param.Companyid)
|
|
|
if len(param.NickName) > 0 {
|
|
|
whereString += ` AND b.nick_name LIKE ? `
|
|
|
likeCond := "%" + param.NickName + "%"
|
|
|
cond = append(cond, likeCond)
|
|
|
}
|
|
|
var (
|
|
|
result []protocol.UserListItem
|
|
|
pageInfo protocol.ResponsePageInfo
|
|
|
err error
|
|
|
responseData protocol.ResponseUserList
|
|
|
)
|
|
|
p := utils.NewQueryDataByPage(countSql+whereString, datasql+whereString)
|
|
|
p.AddParam(cond...)
|
|
|
p.LimitPage(param.PageIndex, param.PageSize)
|
|
|
pageInfo, err = p.Query(&result)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("page data err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return responseData, protocol.NewErrWithMessage("0")
|
|
|
}
|
|
|
// for k, v := range result {
|
|
|
// positions, _ := models.GetUserPosition(v.UserId, param.Companyid)
|
|
|
// departments, _ := models.GetUserDepartment(v.UserId, param.Companyid)
|
|
|
// roles, _ := models.GetUserRole(v.UserId, param.Companyid)
|
|
|
// }
|
|
|
responseData.ResponsePageInfo = pageInfo
|
|
|
responseData.List = result
|
|
|
return responseData, nil
|
|
|
}
|
|
|
|
|
|
func GetUserDepartment(user int64, companyid int64) {
|
|
|
|
|
|
}
|
|
|
|
|
|
func GetUserPosition(user int64, companyid int64) {
|
|
|
|
|
|
} |
...
|
...
|
|