123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package eta_trial
- import (
- "eta/eta_forum_hub/models/eta_trial"
- "fmt"
- "time"
- )
- func EtaTrialManualUserAddAuth(adminId int, adminName string) (err error) {
- if adminId <= 0 {
- err = fmt.Errorf("CreateManualAuth参数有误, AdminId: %d", adminId)
- return
- }
- // 从ETA试用平台的edb库中读取手工数据分类
- classifyIds := make([]int, 0)
- {
- classifyOb := new(eta_trial.EdbdataClassify)
- cond := `is_show = 1`
- pars := make([]interface{}, 0)
- list, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, "")
- if e != nil {
- err = fmt.Errorf("操作失败", "获取手工数据分类失败, Err: "+e.Error())
- return
- }
- for _, v := range list {
- classifyIds = append(classifyIds, v.ClassifyId)
- }
- }
- // 新增用户及权限
- manualUser := new(eta_trial.ManualUser)
- manualUser.AdminId = adminId
- manualUser.AdminRealName = adminName
- manualUser.CreateTime = time.Now().Local()
- if e := manualUser.Create(); e != nil {
- err = fmt.Errorf("操作失败", "新增权限用户失败, Err: "+e.Error())
- return
- }
- userClassifies := make([]*eta_trial.ManualUserClassify, 0)
- for _, v := range classifyIds {
- userClassifies = append(userClassifies, &eta_trial.ManualUserClassify{
- AdminId: adminId,
- ClassifyId: v,
- CreateTime: time.Now().Local(),
- })
- }
- userClassifyOb := new(eta_trial.ManualUserClassify)
- if e := userClassifyOb.BatchCreate(userClassifies); e != nil {
- err = fmt.Errorf("操作失败", "批量新增权限用户分类失败, Err: "+e.Error())
- return
- }
- return
- }
|