70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package user_services
|
|
|
|
import (
|
|
"cron_admin/app/constants/common"
|
|
"cron_admin/app/http/entities/backend"
|
|
"cron_admin/app/models/crondbmodel"
|
|
"cron_admin/app/models/cronusermodel"
|
|
"cron_admin/app/utils/mapstructure"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
func GetListByWhere(request *backend.UserListRequest, page int, limit int) (count int64, UserListInfo []cronusermodel.CronUser, err error) {
|
|
cond := builder.NewCond()
|
|
|
|
if request.Name != "" {
|
|
cond = cond.And(builder.Like{"name", request.Name})
|
|
}
|
|
if request.Tel != "" {
|
|
cond = cond.And(builder.Like{"tel", request.Tel})
|
|
}
|
|
if request.Status != 0 {
|
|
cond = cond.And(builder.Eq{"status": request.Status})
|
|
}
|
|
if request.DtalkDepId != "" {
|
|
cond = cond.And(builder.Like{"dtalk_dep_id", request.DtalkDepId})
|
|
}
|
|
if request.DtalkUserId != "" {
|
|
cond = cond.And(builder.Like{"dtalk_user_id", request.DtalkUserId})
|
|
}
|
|
if request.WxOpenId != "" {
|
|
cond = cond.And(builder.Like{"wx_open_id", request.WxOpenId})
|
|
}
|
|
if len(request.UserIds) > 0 {
|
|
// 使用IN查询
|
|
cond = cond.And(builder.In("user_id", request.UserIds))
|
|
}
|
|
|
|
session := cronusermodel.GetInstance().GetDb().Where(cond).OrderBy("update_time desc")
|
|
|
|
if page != 0 && limit != 0 {
|
|
session = session.Limit(limit, (page-1)*limit)
|
|
}
|
|
count, err = session.FindAndCount(&UserListInfo)
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func UserAdd(request *backend.UserAddRequest) (err error) {
|
|
var db cronusermodel.CronUser
|
|
_ = mapstructure.Decode(request, &db)
|
|
db.Status = common.STATUS_ENABLE
|
|
_, err = cronusermodel.GetInstance().GetDb().InsertOne(db)
|
|
return
|
|
}
|
|
|
|
func UserEdit(request *backend.UserEditRequest) (err error) {
|
|
var db cronusermodel.CronUser
|
|
_ = mapstructure.Decode(request, &db)
|
|
_, err = cronusermodel.GetInstance().GetDb().ID(request.UserId).Update(&db)
|
|
return
|
|
}
|
|
|
|
func UserDel(request *backend.UserDeleteRequest) (err error) {
|
|
_, err = crondbmodel.GetInstance().GetDb().ID(request.UserId).Delete(&cronusermodel.CronUser{})
|
|
return
|
|
}
|