...
|
...
|
@@ -5,6 +5,7 @@ import ( |
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/storage/redisdata"
|
|
|
"oppmg/utils"
|
|
|
"strings"
|
|
|
"time"
|
...
|
...
|
@@ -375,17 +376,31 @@ func UserEdit(param protocol.RequestUserEdit) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
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")
|
|
|
func UserDelete(userCompanyids []int64, companyid int64) error {
|
|
|
if len(userCompanyids) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
var (
|
|
|
updateIds []models.UserCompany
|
|
|
err error
|
|
|
)
|
|
|
o := orm.NewOrm()
|
|
|
_, err := o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("user_id", userid).
|
|
|
Filter("company_id").
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", userCompanyids).
|
|
|
Filter("company_id", companyid).
|
|
|
All(&updateIds, "Id", "UserId")
|
|
|
if err != nil {
|
|
|
log.Error("获取用户数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
var (
|
|
|
ids []int64
|
|
|
)
|
|
|
for _, v := range updateIds {
|
|
|
ids = append(ids, v.Id)
|
|
|
}
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", ids).
|
|
|
Update(orm.Params{
|
|
|
"delete_at": time.Now().String(),
|
|
|
})
|
...
|
...
|
@@ -394,6 +409,13 @@ func UserDelete(userid, companyid int64) error { |
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
for _, v := range updateIds {
|
|
|
e := redisdata.DeleteLoginToken(v.UserId)
|
|
|
if e != nil {
|
|
|
log.Error(e.Error())
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -510,22 +532,64 @@ func GetUserRole(usercompanyid int64) []protocol.RoleBase { |
|
|
return data
|
|
|
}
|
|
|
|
|
|
//启用、禁用用户
|
|
|
func UserForbid(userCompanyIds []int64, companyid int64, enable int8) error {
|
|
|
if len(userCompanyIds) == 0 {
|
|
|
//禁用用户
|
|
|
func UserForbid(userCompanyids []int64, companyid int64) error {
|
|
|
if len(userCompanyids) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
if !(enable == models.USERCOMPANY_ENABLE_NO || enable == models.USERCOMPANY_ENABLE_YES) {
|
|
|
log.Error("enable err")
|
|
|
var (
|
|
|
updateIds []models.UserCompany
|
|
|
err error
|
|
|
)
|
|
|
o := orm.NewOrm()
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", userCompanyids).
|
|
|
Filter("company_id", companyid).
|
|
|
All(&updateIds, "Id", "UserId")
|
|
|
if err != nil {
|
|
|
log.Error("获取用户数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
var (
|
|
|
ids []int64
|
|
|
)
|
|
|
for _, v := range updateIds {
|
|
|
ids = append(ids, v.Id)
|
|
|
}
|
|
|
num, err := o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("delete_at", 0).
|
|
|
Filter("company_id", companyid).
|
|
|
Filter("id__in", ids).
|
|
|
Update(orm.Params{
|
|
|
"enable": models.USERCOMPANY_ENABLE_NO,
|
|
|
"update_at": time.Now(),
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Error("更新user_company失败:%s", err)
|
|
|
protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
log.Info("更新记录数:%d", num)
|
|
|
for _, v := range updateIds {
|
|
|
e := redisdata.DeleteLoginToken(v.UserId)
|
|
|
if e != nil {
|
|
|
log.Error(e.Error())
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//启用用户
|
|
|
func UserAllow(userCompanyIds []int64, companyid int64) error {
|
|
|
if len(userCompanyIds) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
num, err := o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("delete_at", 0).
|
|
|
Filter("company_id", companyid).
|
|
|
Filter("id__in", userCompanyIds).
|
|
|
Update(orm.Params{
|
|
|
"enable": enable,
|
|
|
"enable": models.USERCOMPANY_ENABLE_YES,
|
|
|
"update_at": time.Now(),
|
|
|
})
|
|
|
if err != nil {
|
...
|
...
|
|