sys_admin.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. package controllers
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/company"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/services"
  10. etaTrialService "eta/eta_api/services/eta_trial"
  11. "eta/eta_api/utils"
  12. "fmt"
  13. "github.com/rdlucklib/rdluck_tools/paging"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // 系统用户
  19. type SysAdminController struct {
  20. BaseAuthController
  21. }
  22. // @Title 根据分组或者部门获取系统用户列表
  23. // @Description 根据分组或者部门获取系统用户列表接口
  24. // @Param PageSize query int true "每页数据条数"
  25. // @Param CurrentIndex query int true "当前页页码,从1开始"
  26. // @Param DepartmentId query int true "部门ID"
  27. // @Param GroupId query int true "分组ID"
  28. // @Param TeamId query int true "小组ID"
  29. // @Param RoleId query int true "角色ID"
  30. // @Param KeyWord query string true "搜索关键词"
  31. // @Success 200 {object} system.SysuserListResp
  32. // @router /sysuser/list [get]
  33. func (this *SysAdminController) ListSysuser() {
  34. br := new(models.BaseResponse).Init()
  35. defer func() {
  36. this.Data["json"] = br
  37. this.ServeJSON()
  38. }()
  39. sysUser := this.SysUser
  40. if sysUser == nil {
  41. br.Msg = "请登录"
  42. br.ErrMsg = "请登录,SysUser Is Empty"
  43. return
  44. }
  45. pageSize, _ := this.GetInt("PageSize")
  46. currentIndex, _ := this.GetInt("CurrentIndex")
  47. departmentId, _ := this.GetInt("DepartmentId")
  48. groupId, _ := this.GetInt("GroupId")
  49. teamId, _ := this.GetInt("TeamId")
  50. roleId, _ := this.GetInt("RoleId")
  51. keyWord := this.GetString("KeyWord")
  52. var startSize int
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. startSize = utils.StartIndex(currentIndex, pageSize)
  60. var condition string
  61. var pars []interface{}
  62. if departmentId > 0 {
  63. condition += ` AND department_id=? `
  64. pars = append(pars, departmentId)
  65. }
  66. if roleId > 0 {
  67. condition += ` AND role_id=? `
  68. pars = append(pars, roleId)
  69. }
  70. if keyWord != "" {
  71. condition += ` AND (real_name LIKE ? OR admin_name LIKE ? OR mobile LIKE ? ) `
  72. pars = utils.GetLikeKeywordPars(pars, keyWord, 3)
  73. }
  74. var total int
  75. var err error
  76. if teamId <= 0 {
  77. if groupId > 0 {
  78. ids, err := system.GetGroupIdByParentId(groupId)
  79. if err != nil {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "获取失败,Err:" + err.Error()
  82. return
  83. }
  84. sGroupId := strconv.Itoa(groupId)
  85. ids = append(ids, &sGroupId)
  86. var idList []string
  87. for _, id := range ids {
  88. idList = append(idList, *id)
  89. }
  90. sid := strings.Join(idList, ",")
  91. condition += ` AND group_id IN (` + sid + `) `
  92. }
  93. total, err = system.GetSysuserListCount(condition, pars)
  94. if err != nil {
  95. br.Msg = "获取失败"
  96. br.ErrMsg = "获取失败,Err:" + err.Error()
  97. return
  98. }
  99. } else {
  100. nCondition := condition + ` AND group_id=? `
  101. nPars := append(pars, teamId)
  102. total, err = system.GetSysuserListCount(nCondition, nPars)
  103. if err != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取失败,Err:" + err.Error()
  106. return
  107. }
  108. }
  109. var list []*system.AdminItem
  110. adminIdArr := make([]int, 0)
  111. if teamId <= 0 {
  112. //if groupId > 0 {
  113. // ids, err := system.GetGroupIdByParentId(groupId, startSize, pageSize)
  114. // if err != nil {
  115. // br.Msg = "获取失败"
  116. // br.ErrMsg = "获取失败,Err:" + err.Error()
  117. // return
  118. // }
  119. // sGroupId := strconv.Itoa(groupId)
  120. // ids = append(ids, &sGroupId)
  121. // var idList []string
  122. // for _, id := range ids {
  123. // idList = append(idList, *id)
  124. // }
  125. // sid := strings.Join(idList,",")
  126. //
  127. // condition += ` AND group_id IN (` + sid + `) `
  128. //}
  129. list, err = system.GetSysuserList(condition, pars, startSize, pageSize)
  130. if err != nil {
  131. br.Msg = "获取失败"
  132. br.ErrMsg = "获取失败,Err:" + err.Error()
  133. return
  134. }
  135. lenList := len(list)
  136. for i := 0; i < lenList; i++ {
  137. item := list[i]
  138. //adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
  139. adminIdArr = append(adminIdArr, item.AdminId)
  140. var secondName *string
  141. if item.GroupId != 0 {
  142. pid, err := company.GetParentIdFromGroup(item.GroupId)
  143. if err != nil {
  144. br.Msg = "获取失败"
  145. br.ErrMsg = "查询父级id异常" + err.Error()
  146. return
  147. }
  148. if pid != nil && *pid != 0 {
  149. secondName, err = company.GetGroupNamesById(*pid)
  150. if err != nil {
  151. br.Msg = "获取失败"
  152. br.ErrMsg = "查询二级组名异常" + err.Error()
  153. return
  154. }
  155. }
  156. if *pid > 0 {
  157. list[i].TeamId = list[i].GroupId
  158. list[i].GroupId = *pid
  159. }
  160. }
  161. if item.DepartmentName != "" {
  162. if item.GroupName == "" {
  163. list[i].DepartmentGroup = item.DepartmentName
  164. } else if secondName != nil {
  165. list[i].DepartmentGroup = item.DepartmentName + "/" + *secondName + "/" + item.GroupName
  166. } else {
  167. list[i].DepartmentGroup = item.DepartmentName + "/" + item.GroupName
  168. }
  169. }
  170. labelVal := 0
  171. fmt.Println("item.RoleTypeCode:", item.RoleTypeCode)
  172. fmt.Println("item.Authority:", item.Authority)
  173. if item.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  174. labelVal = 1
  175. } else if item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  176. item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  177. labelVal = 2
  178. } else {
  179. if item.Authority == 1 {
  180. labelVal = 3
  181. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  182. labelVal = 4
  183. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  184. labelVal = 5
  185. } else if item.Authority == 4 {
  186. labelVal = 4
  187. }
  188. }
  189. list[i].LabelVal = labelVal
  190. }
  191. } else {
  192. condition += ` AND group_id=? `
  193. pars = append(pars, teamId)
  194. list, err = system.GetSysuserList(condition, pars, startSize, pageSize)
  195. if err != nil {
  196. br.Msg = "获取失败"
  197. br.ErrMsg = "获取失败,Err:" + err.Error()
  198. return
  199. }
  200. groupItem, err := system.GetSysGroupById(groupId)
  201. if err != nil {
  202. br.Msg = "获取失败"
  203. br.ErrMsg = "获取失败,Err:" + err.Error()
  204. return
  205. }
  206. lenList := len(list)
  207. for i := 0; i < lenList; i++ {
  208. item := list[i]
  209. //adminIdArr = append(adminIdArr, strconv.Itoa(item.AdminId))
  210. adminIdArr = append(adminIdArr, item.AdminId)
  211. if item.DepartmentName != "" {
  212. if item.GroupName == "" {
  213. list[i].DepartmentGroup = item.DepartmentName
  214. } else if item.GroupName != "" {
  215. list[i].DepartmentGroup = item.DepartmentName + "/" + groupItem.GroupName + "/" + item.GroupName
  216. } else {
  217. list[i].DepartmentGroup = item.DepartmentName + "/" + item.GroupName
  218. }
  219. }
  220. labelVal := 0
  221. if item.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  222. labelVal = 1
  223. } else if item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN ||
  224. item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  225. labelVal = 2
  226. } else {
  227. if item.Authority == 1 {
  228. labelVal = 3
  229. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  230. labelVal = 4
  231. } else if item.Authority == 2 && item.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  232. labelVal = 5
  233. } else if item.Authority == 4 {
  234. labelVal = 4
  235. }
  236. }
  237. list[i].LabelVal = labelVal
  238. }
  239. }
  240. //if teamId > 0 {
  241. // var groupIdSlice []string
  242. // var groupIds string
  243. // for _, item := range list {
  244. // groupIdSlice = append(groupIdSlice, strconv.Itoa(groupId))
  245. // }
  246. // groupIds = strings.Join(groupIdSlice, ",")
  247. // fmt.Println("groupIds:", groupIds)
  248. //}
  249. if teamId > 0 {
  250. for _, item := range list {
  251. item.TeamId = teamId
  252. item.GroupId = groupId
  253. }
  254. }
  255. // 研究方向分组
  256. if len(adminIdArr) > 0 && utils.BusinessCode == utils.BusinessCodeRelease {
  257. //adminIds := strings.Join(adminIdArr, ",")
  258. //researchGroupList, e := system.GetAdminResearchGroupListByAdminId(adminIds)
  259. researchGroupList, e := models.GetAdminVarietyTagRelationListByAdminId(adminIdArr)
  260. if e != nil {
  261. br.Msg = "获取失败"
  262. br.ErrMsg = "获取研究方向分组列表失败, Err:" + e.Error()
  263. return
  264. }
  265. researchGroupAdminIdName := make(map[int]string, 0)
  266. for _, g := range researchGroupList {
  267. researchGroupAdminIdName[g.AdminId] = g.GroupNameStr
  268. }
  269. for _, v := range list {
  270. v.ResearchGroupName = researchGroupAdminIdName[v.AdminId]
  271. }
  272. }
  273. fmt.Println("teamId:", teamId)
  274. page := paging.GetPaging(currentIndex, pageSize, total)
  275. resp := new(system.SysuserListResp)
  276. resp.List = list
  277. resp.Paging = page
  278. br.Ret = 200
  279. br.Success = true
  280. br.Msg = "获取成功"
  281. br.Data = resp
  282. }
  283. // Add
  284. // @Title 新增系统用户
  285. // @Description 新增系统用户接口
  286. // @Param request body system.SysuserAddReq true "type json string"
  287. // @Success 200 新增成功
  288. // @router /sysuser/add [post]
  289. func (this *SysAdminController) Add() {
  290. br := new(models.BaseResponse).Init()
  291. defer func() {
  292. this.Data["json"] = br
  293. this.ServeJSON()
  294. }()
  295. var req system.SysuserAddReq
  296. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  297. if err != nil {
  298. br.Msg = "参数解析异常!"
  299. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  300. return
  301. }
  302. if req.RoleId <= 0 {
  303. br.Msg = "请选择角色"
  304. br.ErrMsg = "角色ID小于等于0"
  305. return
  306. }
  307. count, err := system.GetSysAdminCount(req.AdminName)
  308. if err != nil {
  309. br.Msg = "获取数据失败"
  310. br.ErrMsg = "获取数据失败"
  311. return
  312. }
  313. if count > 0 {
  314. br.Msg = "账号已存在,请重新输入"
  315. br.IsSendEmail = false
  316. return
  317. }
  318. // 手机号和邮箱必填一个
  319. req.Mobile = strings.TrimSpace(req.Mobile)
  320. req.Email = strings.TrimSpace(req.Email)
  321. if req.Mobile == "" && req.Email == "" {
  322. br.Msg = "至少输入一个手机号或邮箱"
  323. return
  324. }
  325. if req.Mobile != "" {
  326. if req.TelAreaCode == "86" {
  327. if !utils.ValidateMobileFormatat(req.Mobile) {
  328. br.Msg = "手机号格式有误, 请检查"
  329. return
  330. }
  331. }
  332. mobileCount, err := system.GetSysAdminCountByMobile(req.Mobile, 0)
  333. if err != nil {
  334. br.Msg = "判断手机号是否存在失败"
  335. br.ErrMsg = "判断手机号是否存在失败,Err:" + err.Error()
  336. return
  337. }
  338. if mobileCount > 0 {
  339. br.Msg = "手机号已存在,请重新填写"
  340. br.IsSendEmail = false
  341. return
  342. }
  343. }
  344. if req.Email != "" {
  345. if !utils.ValidateEmailFormatat(req.Email) {
  346. br.Msg = "邮箱格式有误, 请检查"
  347. return
  348. }
  349. emailUser, e := system.GetSysUserByEmail(req.Email)
  350. if e != nil && e.Error() != utils.ErrNoRow() {
  351. br.Msg = "操作失败"
  352. br.ErrMsg = "邮箱获取用户失败"
  353. return
  354. }
  355. if emailUser != nil && emailUser.AdminId > 0 {
  356. br.Msg = "邮箱已存在, 请重新填写"
  357. return
  358. }
  359. }
  360. var roleName, departmentName, groupName, teamName string
  361. roleItem, err := system.GetSysRoleById(req.RoleId)
  362. if err != nil {
  363. if err.Error() == utils.ErrNoRow() {
  364. br.Msg = "所选角色不存在"
  365. return
  366. }
  367. br.Msg = "获取数据失败"
  368. br.ErrMsg = "获取角色数据失败,Err:" + err.Error()
  369. return
  370. }
  371. if roleItem != nil {
  372. roleName = roleItem.RoleName
  373. }
  374. if req.DepartmentId > 0 {
  375. departmentItem, err := system.GetSysDepartmentById(req.DepartmentId)
  376. if err != nil {
  377. if err.Error() == utils.ErrNoRow() {
  378. br.Msg = "所选部门不存在"
  379. return
  380. }
  381. br.Msg = "获取数据失败"
  382. br.ErrMsg = "获取部门数据失败,Err:" + err.Error()
  383. return
  384. }
  385. if departmentItem != nil {
  386. departmentName = departmentItem.DepartmentName
  387. }
  388. }
  389. if req.GroupId > 0 {
  390. groupItem, err := system.GetSysGroupById(req.GroupId)
  391. if err != nil {
  392. if err.Error() == utils.ErrNoRow() {
  393. br.Msg = "所选分组不存在"
  394. return
  395. }
  396. br.Msg = "获取数据失败"
  397. br.ErrMsg = "获取分组数据失败,Err:" + err.Error()
  398. return
  399. }
  400. if groupItem != nil {
  401. groupName = groupItem.GroupName
  402. }
  403. }
  404. if req.TeamId > 0 {
  405. teamItem, err := system.GetSysGroupById(req.TeamId)
  406. if err != nil {
  407. if err.Error() == utils.ErrNoRow() {
  408. br.Msg = "所选小组不存在"
  409. return
  410. }
  411. br.Msg = "获取数据失败"
  412. br.ErrMsg = "获取小组数据失败,Err:" + err.Error()
  413. return
  414. }
  415. if teamItem != nil {
  416. teamName = teamItem.GroupName
  417. }
  418. }
  419. pwdByte, err := base64.StdEncoding.DecodeString(req.Password)
  420. if err != nil {
  421. br.Msg = "解析数据失败"
  422. br.ErrMsg = "解析数据失败,Err:" + err.Error()
  423. return
  424. }
  425. pwdStr := string(pwdByte)
  426. //pwdStr = strings.ToLower(pwdStr)
  427. if pwdStr == "" {
  428. br.Msg = "请输入密码"
  429. return
  430. }
  431. if !utils.CheckPwd(pwdStr) {
  432. br.Msg = "密码格式错误,请重新输入"
  433. return
  434. }
  435. // 员工工号
  436. req.EmployeeId = strings.TrimSpace(req.EmployeeId)
  437. admin := new(system.Admin)
  438. admin.AdminName = req.AdminName
  439. admin.RealName = req.RealName
  440. admin.Password = utils.MD5(pwdStr)
  441. admin.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
  442. admin.Enabled = 1
  443. admin.LastLoginTime = time.Now().Format(utils.FormatDateTime)
  444. admin.CreatedTime = time.Now()
  445. admin.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  446. admin.Mobile = req.Mobile
  447. admin.RoleType = 0
  448. admin.RoleId = req.RoleId
  449. admin.RoleName = roleName
  450. admin.RoleTypeCode = roleItem.RoleTypeCode
  451. admin.DepartmentId = req.DepartmentId
  452. admin.DepartmentName = departmentName
  453. admin.AdminAvatar = req.AdminAvatar
  454. if req.TeamId <= 0 {
  455. admin.GroupId = req.GroupId
  456. admin.GroupName = groupName
  457. } else {
  458. admin.GroupId = req.TeamId
  459. admin.GroupName = teamName
  460. }
  461. if strings.Contains(admin.RoleTypeCode, "researcher") {
  462. admin.Role = "researcher"
  463. } else if strings.Contains(admin.RoleTypeCode, "seller") {
  464. admin.Role = "sales"
  465. } else {
  466. admin.Role = "admin"
  467. }
  468. admin.EmployeeId = req.EmployeeId
  469. admin.Email = req.Email
  470. var authority int
  471. if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  472. authority = 3
  473. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  474. authority = 4
  475. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  476. authority = 2
  477. } else {
  478. if strings.Contains(roleItem.RoleType, "销售主管") {
  479. authority = 2
  480. } else if strings.Contains(roleItem.RoleType, "部门经理") {
  481. authority = 1
  482. } else {
  483. authority = 0
  484. }
  485. }
  486. admin.Authority = authority
  487. admin.Position = req.Position
  488. admin.Province = req.Province
  489. admin.ProvinceCode = req.ProvinceCode
  490. admin.City = req.City
  491. admin.CityCode = req.CityCode
  492. admin.TelAreaCode = req.TelAreaCode
  493. err = system.AddAdmin(admin)
  494. if err != nil {
  495. br.Msg = "新增失败"
  496. br.ErrMsg = "新增失败,Err:" + err.Error()
  497. return
  498. }
  499. // 同步用户缓存
  500. if utils.BusinessCode == utils.BusinessCodeRelease {
  501. var syncData system.SyncAdminData
  502. syncData.Source = utils.SOURCE_ETA_FLAG
  503. syncData.AdminName = admin.AdminName
  504. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  505. e := services.UpdateResearcherTagGroup(admin.AdminId, req.ResearchGroupIds)
  506. if e != nil {
  507. br.Msg = "新增失败"
  508. br.ErrMsg = "新增用户研究方向分组失败, Err:" + e.Error()
  509. return
  510. }
  511. }
  512. // 清楚系统用户列表缓存key
  513. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  514. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  515. //thirdGroupId := 0 //角色:2=研究员,3=机构销售
  516. if admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  517. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  518. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  519. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  520. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
  521. //thirdGroupId = 2
  522. } else if admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  523. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  524. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  525. admin.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  526. //thirdGroupId = 3
  527. }
  528. //if thirdGroupId > 0 {
  529. // go roadshow.CreateOaUser(admin.Mobile, admin.RealName, thirdGroupId)
  530. //}
  531. // 新增弘则联系人
  532. //go services.AddHzCompanyUser(admin.Mobile, admin.RealName, this.SysUser.AdminId, this.SysUser.RealName)
  533. br.Ret = 200
  534. br.Success = true
  535. br.Msg = "新增成功"
  536. }
  537. // Edit
  538. // @Title 编辑系统用户
  539. // @Description 编辑系统用户接口
  540. // @Param request body system.SysuserEditReq true "type json string"
  541. // @Success 200 编辑成功
  542. // @router /sysuser/edit [post]
  543. func (this *SysAdminController) Edit() {
  544. br := new(models.BaseResponse).Init()
  545. defer func() {
  546. this.Data["json"] = br
  547. this.ServeJSON()
  548. }()
  549. var req system.SysuserEditReq
  550. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  551. if err != nil {
  552. br.Msg = "参数解析异常!"
  553. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  554. return
  555. }
  556. if req.RoleId <= 0 {
  557. br.Msg = "请选择角色"
  558. br.ErrMsg = "角色ID小于等于0"
  559. return
  560. }
  561. //根据用户id获取用户信息
  562. adminInfo, err := system.GetSysAdminById(req.AdminId)
  563. if err != nil {
  564. if err.Error() == utils.ErrNoRow() {
  565. br.Msg = "用户已被删除, 请刷新页面"
  566. return
  567. }
  568. br.Msg = "获取数据失败"
  569. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  570. return
  571. }
  572. // 根据用户登录用户名获取用户信息
  573. item, err := system.GetSysAdminByName(req.AdminName)
  574. if err != nil && err.Error() != utils.ErrNoRow() {
  575. br.Msg = "获取数据失败"
  576. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminName:" + req.AdminName
  577. return
  578. }
  579. if item != nil && item.AdminId != req.AdminId {
  580. br.Msg = "账号名称已存在,请重新输入"
  581. return
  582. }
  583. // 手机号和邮箱必填一个
  584. req.Mobile = strings.TrimSpace(req.Mobile)
  585. req.Email = strings.TrimSpace(req.Email)
  586. if req.Mobile == "" && req.Email == "" {
  587. br.Msg = "至少输入一个手机号或邮箱"
  588. return
  589. }
  590. if req.Mobile != "" {
  591. if req.TelAreaCode == "86" {
  592. if !utils.ValidateMobileFormatat(req.Mobile) {
  593. br.Msg = "手机号格式有误, 请检查"
  594. return
  595. }
  596. }
  597. mobileCount, e := system.GetSysAdminCountByMobile(req.Mobile, adminInfo.AdminId)
  598. if e != nil {
  599. br.Msg = "判断手机号是否存在失败"
  600. br.ErrMsg = "判断手机号是否存在失败,Err:" + e.Error()
  601. return
  602. }
  603. if mobileCount > 0 {
  604. br.Msg = "手机号已存在,请重新填写"
  605. br.IsSendEmail = false
  606. return
  607. }
  608. }
  609. if req.Email != "" {
  610. if !utils.ValidateEmailFormatat(req.Email) {
  611. br.Msg = "邮箱格式有误, 请检查"
  612. return
  613. }
  614. emailUser, e := system.GetSysUserByEmail(req.Email)
  615. if e != nil && e.Error() != utils.ErrNoRow() {
  616. br.Msg = "操作失败"
  617. br.ErrMsg = "邮箱获取用户信息失败, Err: " + e.Error()
  618. return
  619. }
  620. if emailUser != nil && emailUser.AdminId != adminInfo.AdminId {
  621. br.Msg = "邮箱已存在, 请检查"
  622. return
  623. }
  624. }
  625. // 角色
  626. var roleName string
  627. roleItem, err := system.GetSysRoleById(req.RoleId)
  628. if err != nil {
  629. if err.Error() == utils.ErrNoRow() {
  630. br.Msg = "角色不存在,请重新选择"
  631. br.ErrMsg = "角色不存在"
  632. return
  633. }
  634. br.Msg = "获取数据失败"
  635. br.ErrMsg = "获取角色数据失败,Err:" + err.Error()
  636. return
  637. }
  638. if roleItem != nil {
  639. roleName = roleItem.RoleName
  640. }
  641. // 员工工号
  642. req.EmployeeId = strings.TrimSpace(req.EmployeeId)
  643. if req.EmployeeId != "" && utils.BusinessCode == utils.BusinessCodeRelease {
  644. // 去重
  645. countOB := new(system.Admin)
  646. countCond := ` AND employee_id = ? AND admin_id <> ?`
  647. countPars := make([]interface{}, 0)
  648. countPars = append(countPars, req.EmployeeId, req.AdminId)
  649. countEmployee, e := countOB.GetCountByCondition(countCond, countPars)
  650. if e != nil {
  651. br.Msg = "工号去重查询失败"
  652. br.ErrMsg = "工号去重查询失败, Err: " + e.Error()
  653. return
  654. }
  655. if countEmployee > 0 {
  656. br.Msg = "工号已存在"
  657. return
  658. }
  659. }
  660. // 管理权限
  661. var authority int
  662. if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  663. authority = 3
  664. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
  665. authority = 4
  666. } else if roleItem.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  667. authority = 2
  668. } else {
  669. if strings.Contains(roleItem.RoleType, "销售主管") {
  670. authority = 2
  671. } else if strings.Contains(roleItem.RoleType, "部门经理") {
  672. authority = 1
  673. } else {
  674. authority = 0
  675. }
  676. }
  677. adminInfo.AdminName = req.AdminName
  678. adminInfo.RealName = req.RealName
  679. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  680. adminInfo.Mobile = req.Mobile
  681. adminInfo.RoleId = req.RoleId
  682. adminInfo.RoleName = roleName
  683. adminInfo.Enabled = req.Enabled
  684. adminInfo.Authority = authority
  685. adminInfo.Position = req.Position
  686. adminInfo.RoleTypeCode = roleItem.RoleTypeCode
  687. adminInfo.Province = req.Province
  688. adminInfo.ProvinceCode = req.ProvinceCode
  689. adminInfo.City = req.City
  690. adminInfo.CityCode = req.CityCode
  691. adminInfo.EmployeeId = req.EmployeeId
  692. adminInfo.Email = req.Email
  693. adminInfo.TelAreaCode = req.TelAreaCode
  694. cols := []string{
  695. "AdminName", "RealName", "LastUpdatedTime", "Mobile", "RoleId", "RoleName", "Enabled", "Authority",
  696. "Position", "RoleTypeCode", "Province", "ProvinceCode", "City", "CityCode", "EmployeeId", "Email", "TelAreaCode",
  697. }
  698. if e := adminInfo.Update(cols); e != nil {
  699. br.Msg = "编辑失败"
  700. br.ErrMsg = "更新用户信息失败, Err:" + e.Error()
  701. return
  702. }
  703. // 同步用户缓存
  704. if utils.BusinessCode == utils.BusinessCodeRelease {
  705. var syncData system.SyncAdminData
  706. syncData.Source = utils.SOURCE_ETA_FLAG
  707. syncData.AdminName = adminInfo.AdminName
  708. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  709. // 研究方向分组
  710. if e := services.UpdateResearcherTagGroup(req.AdminId, req.ResearchGroupIds); e != nil {
  711. br.Msg = "编辑失败"
  712. br.ErrMsg = "更新用户研究方向失败, Err:" + e.Error()
  713. return
  714. }
  715. }
  716. // 用户登出
  717. logOutSystemUser(adminInfo.AdminId)
  718. // 清楚系统用户列表缓存key
  719. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  720. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  721. // 试用客户更新对应信息
  722. if utils.BusinessCode == utils.BusinessCodeSandbox && adminInfo.DepartmentName == "ETA试用客户" {
  723. go func() {
  724. var r etaTrialService.EtaTrialUserEditReq
  725. r.RealName = req.RealName
  726. r.Position = req.Position
  727. r.Mobile = adminInfo.Mobile
  728. r.Enabled = req.Enabled
  729. _, _ = etaTrialService.EditEtaTrialUser(r)
  730. }()
  731. }
  732. br.Ret = 200
  733. br.Success = true
  734. br.IsAddLog = true
  735. br.Msg = "编辑成功"
  736. }
  737. // @Title 开启/禁用系统用户
  738. // @Description 开启/禁用系统用户接口
  739. // @Param request body system.SysuserEditReq true "type json string"
  740. // @Success 200 操作成功
  741. // @router /sysuser/editEnabled [post]
  742. func (this *SysAdminController) EditEnabled() {
  743. br := new(models.BaseResponse).Init()
  744. defer func() {
  745. this.Data["json"] = br
  746. this.ServeJSON()
  747. }()
  748. var req system.SysuserEditEnabledReq
  749. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  750. if err != nil {
  751. br.Msg = "参数解析异常!"
  752. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  753. return
  754. }
  755. adminItem, err := system.GetSysAdminById(req.AdminId)
  756. if err != nil {
  757. br.Msg = "获取数据失败"
  758. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  759. return
  760. }
  761. if req.Enabled == 0 {
  762. //禁用
  763. err = system.DisableAdmin(req.AdminId)
  764. if err != nil {
  765. br.Msg = "修改失败"
  766. br.ErrMsg = "修改系统用户数据失败,Err:" + err.Error()
  767. return
  768. }
  769. // 更新试用平台客户
  770. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  771. go func() {
  772. var r etaTrialService.EtaTrialUserReq
  773. r.Mobile = adminItem.Mobile
  774. _, _ = etaTrialService.DisableEtaTrialUser(r)
  775. }()
  776. }
  777. } else {
  778. admin := new(system.Admin)
  779. admin.Enabled = req.Enabled
  780. admin.AdminId = req.AdminId
  781. err = system.EditAdminEnabled(admin)
  782. if err != nil {
  783. br.Msg = "修改失败"
  784. br.ErrMsg = "修改系统用户数据失败,Err:" + err.Error()
  785. return
  786. }
  787. }
  788. // 同步用户缓存
  789. if utils.BusinessCode == utils.BusinessCodeRelease {
  790. var syncData system.SyncAdminData
  791. syncData.Source = utils.SOURCE_ETA_FLAG
  792. syncData.AdminName = adminItem.AdminName
  793. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  794. }
  795. //用户被禁用的情况下,需要将他对应的token给过期
  796. if adminItem.Enabled == 1 && req.Enabled == 0 {
  797. logOutSystemUser(adminItem.AdminId)
  798. }
  799. // 联动弘则研究公司下的联系人启禁用
  800. {
  801. go services.SwitchHzUserEnabledByMobile(req.Enabled, adminItem.Mobile)
  802. }
  803. if err != nil {
  804. br.Msg = "操作失败"
  805. br.ErrMsg = "操作失败,Err:" + err.Error()
  806. return
  807. }
  808. br.Ret = 200
  809. br.Success = true
  810. br.IsAddLog = true
  811. br.Msg = "操作成功"
  812. }
  813. // @Title 删除系统用户
  814. // @Description 删除系统用户接口
  815. // @Param request body system.SysuserDeleteReq true "type json string"
  816. // @Success 200 删除成功
  817. // @router /sysuser/delete [post]
  818. func (this *SysAdminController) Delete() {
  819. br := new(models.BaseResponse).Init()
  820. defer func() {
  821. this.Data["json"] = br
  822. this.ServeJSON()
  823. }()
  824. var req system.SysuserDeleteReq
  825. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  826. if err != nil {
  827. br.Msg = "参数解析异常!"
  828. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  829. return
  830. }
  831. if req.AdminId <= 0 {
  832. br.Msg = "参数错误"
  833. br.ErrMsg = "参数错误,GroupId 小于等于0 "
  834. return
  835. }
  836. mobile := ""
  837. adminInfo, _ := system.GetSysUserById(req.AdminId)
  838. if adminInfo != nil {
  839. mobile = adminInfo.Mobile
  840. }
  841. err = system.DeleteSysuser(req.AdminId)
  842. if err != nil {
  843. br.Msg = "删除失败"
  844. br.ErrMsg = "删除失败,Err:" + err.Error()
  845. return
  846. }
  847. // 同步用户缓存
  848. if utils.BusinessCode == utils.BusinessCodeRelease {
  849. var syncData system.SyncAdminData
  850. syncData.Source = utils.SOURCE_ETA_FLAG
  851. syncData.AdminName = adminInfo.AdminName
  852. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  853. }
  854. // 删除手工数据关联用户
  855. {
  856. go data_manage.DeleteManualUser(req.AdminId)
  857. }
  858. // 删除弘则研究公司下的相同手机号联系人
  859. {
  860. go services.DeleteHzUserByMobile(mobile)
  861. }
  862. // 清楚系统用户列表缓存key
  863. utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  864. utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  865. // 删除试用平台客户
  866. if utils.BusinessCode == utils.BusinessCodeSandbox && adminInfo.DepartmentName == "ETA试用客户" {
  867. go func() {
  868. var r etaTrialService.EtaTrialUserReq
  869. r.Mobile = mobile
  870. _, _ = etaTrialService.RemoveEtaTrialUser(r)
  871. }()
  872. }
  873. br.Ret = 200
  874. br.Success = true
  875. br.IsAddLog = true
  876. br.Msg = "删除成功"
  877. }
  878. /*
  879. func init() {
  880. fmt.Println("start")
  881. pwdStr:=`11111`
  882. //compile := `(\d+.*[^a-zA-Z]+){6,12}|([^a-zA-Z]+.*\d+){6,12}`
  883. compile := `([0-9a-z]+){6,12}|(a-z0-9]+){6,12}`
  884. ///^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/
  885. ///^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/
  886. reg := regexp.MustCompile(compile)
  887. flag := reg.MatchString(pwdStr)
  888. fmt.Println(flag)
  889. fmt.Println("end")
  890. }*/
  891. // SetConfig
  892. // @Title 用户信息配置接口
  893. // @Description 用户信息配置接口
  894. // @Success 200 {object} system.SetAdminConfigReq
  895. // @router /sysuser/config/set [post]
  896. func (this *SysAdminController) SetConfig() {
  897. br := new(models.BaseResponse).Init()
  898. defer func() {
  899. this.Data["json"] = br
  900. this.ServeJSON()
  901. }()
  902. sysUser := this.SysUser
  903. if sysUser == nil {
  904. br.Msg = "请登录"
  905. br.ErrMsg = "请登录,SysUser Is Empty"
  906. br.Ret = 408
  907. return
  908. }
  909. var req system.SetAdminConfigReq
  910. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  911. if err != nil {
  912. br.Msg = "参数解析异常!"
  913. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  914. return
  915. }
  916. item, err := system.GetConfigDetailByCode(this.SysUser.AdminId, req.ConfigCode)
  917. if err != nil {
  918. if err.Error() != utils.ErrNoRow() {
  919. br.Msg = "设置失败"
  920. br.ErrMsg = "设置失败,Err:" + err.Error()
  921. return
  922. }
  923. // 获取默认配置
  924. defaultConfig, err := system.GetDefaultConfigDetailByCode(req.ConfigCode)
  925. if err != nil {
  926. br.Msg = "设置失败"
  927. br.ErrMsg = "获取默认配置失败,Err:" + err.Error()
  928. return
  929. }
  930. adminConfigItem := &system.AdminConfig{
  931. //ConfigId: 0,
  932. AdminId: this.SysUser.AdminId,
  933. ConfigCode: req.ConfigCode,
  934. ConfigValue: req.ConfigValue,
  935. Remark: defaultConfig.Remark,
  936. CreateTime: time.Now(),
  937. }
  938. err = adminConfigItem.Create()
  939. if err != nil {
  940. br.Msg = "设置失败"
  941. br.ErrMsg = "设置失败,Err:" + err.Error()
  942. return
  943. }
  944. } else {
  945. // 存在配置,那么就修改
  946. item.ConfigValue = req.ConfigValue
  947. err = item.Update([]string{"ConfigValue"})
  948. if err != nil {
  949. br.Msg = "设置失败"
  950. br.ErrMsg = "设置失败,Err:" + err.Error()
  951. return
  952. }
  953. }
  954. br.Ret = 200
  955. br.Success = true
  956. br.Msg = "设置成功"
  957. }
  958. // logOutSystemUser 用户登出
  959. func logOutSystemUser(adminId int) {
  960. // 退出管理后台
  961. _ = system.ExpiredSysSessionByAdminId(adminId)
  962. // 退出随手办公小程序
  963. _ = system.UnBindAdminRecordByUserId(adminId)
  964. }
  965. // Move
  966. // @Title 移动分组
  967. // @Description 移动分组
  968. // @Param request body system.SysUserMoveReq true "type json string"
  969. // @Success 200 编辑成功
  970. // @router /sysuser/move [post]
  971. func (this *SysAdminController) Move() {
  972. br := new(models.BaseResponse).Init()
  973. defer func() {
  974. this.Data["json"] = br
  975. this.ServeJSON()
  976. }()
  977. var req system.SysUserMoveReq
  978. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  979. if err != nil {
  980. br.Msg = "参数解析异常!"
  981. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  982. return
  983. }
  984. if req.AdminId <= 0 {
  985. br.Msg = "参数有误"
  986. br.ErrMsg = "参数有误, AdminId"
  987. return
  988. }
  989. if req.DepartmentId <= 0 {
  990. br.Msg = "请选择部门"
  991. return
  992. }
  993. adminInfo, err := system.GetSysAdminById(req.AdminId)
  994. if err != nil && err.Error() != utils.ErrNoRow() {
  995. br.Msg = "获取数据失败"
  996. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  997. return
  998. }
  999. var departmentName, groupName, teamName string
  1000. if req.DepartmentId > 0 {
  1001. departmentItem, err := system.GetSysDepartmentById(req.DepartmentId)
  1002. if err != nil {
  1003. br.Msg = "获取数据失败"
  1004. br.ErrMsg = "获取部门数据失败,Err:" + err.Error()
  1005. return
  1006. }
  1007. if departmentItem != nil {
  1008. departmentName = departmentItem.DepartmentName
  1009. }
  1010. }
  1011. if req.GroupId > 0 {
  1012. groupItem, err := system.GetSysGroupById(req.GroupId)
  1013. if err != nil {
  1014. br.Msg = "获取数据失败"
  1015. br.ErrMsg = "获取分组数据失败,Err:" + err.Error()
  1016. return
  1017. }
  1018. if groupItem != nil {
  1019. groupName = groupItem.GroupName
  1020. }
  1021. }
  1022. if req.TeamId > 0 {
  1023. teamItem, err := system.GetSysGroupById(req.TeamId)
  1024. if err != nil {
  1025. br.Msg = "获取数据失败"
  1026. br.ErrMsg = "获取小组数据失败,Err:" + err.Error()
  1027. return
  1028. }
  1029. if teamItem != nil {
  1030. teamName = teamItem.GroupName
  1031. }
  1032. }
  1033. adminInfo.DepartmentId = req.DepartmentId
  1034. adminInfo.DepartmentName = departmentName
  1035. if req.TeamId <= 0 {
  1036. adminInfo.GroupId = req.GroupId
  1037. adminInfo.GroupName = groupName
  1038. } else {
  1039. adminInfo.GroupId = req.TeamId
  1040. adminInfo.GroupName = teamName
  1041. }
  1042. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  1043. if e := adminInfo.Update([]string{"DepartmentId", "DepartmentName", "GroupId", "GroupName", "LastUpdatedTime"}); e != nil {
  1044. br.Msg = "操作失败"
  1045. br.ErrMsg = "更新系统用户分组失败, Err: " + e.Error()
  1046. return
  1047. }
  1048. // 修改客户关联的分组
  1049. {
  1050. if req.TeamId > 0 {
  1051. if req.TeamId != adminInfo.GroupId {
  1052. err = company.ModifyCompanyGroupId(req.AdminId, req.TeamId)
  1053. if err != nil {
  1054. br.Msg = "编辑失败"
  1055. br.ErrMsg = "ModifyCompanyGroupId,Err:" + err.Error()
  1056. return
  1057. }
  1058. }
  1059. } else {
  1060. if req.GroupId != adminInfo.GroupId {
  1061. err = company.ModifyCompanyGroupId(req.AdminId, req.GroupId)
  1062. if err != nil {
  1063. br.Msg = "编辑失败"
  1064. br.ErrMsg = "ModifyCompanyGroupId,Err:" + err.Error()
  1065. return
  1066. }
  1067. }
  1068. }
  1069. if req.DepartmentId != adminInfo.DepartmentId {
  1070. err = company.ModifyCompanyDepartmentId(req.AdminId, req.DepartmentId)
  1071. if err != nil {
  1072. br.Msg = "编辑失败"
  1073. br.ErrMsg = "ModifyCompanyDepartmentId,Err:" + err.Error()
  1074. return
  1075. }
  1076. }
  1077. }
  1078. // 同步用户缓存
  1079. if utils.BusinessCode == utils.BusinessCodeRelease {
  1080. var syncData system.SyncAdminData
  1081. syncData.Source = utils.SOURCE_ETA_FLAG
  1082. syncData.AdminName = adminInfo.AdminName
  1083. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  1084. }
  1085. // 清除系统用户列表缓存key
  1086. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  1087. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  1088. br.Ret = 200
  1089. br.Success = true
  1090. br.IsAddLog = true
  1091. br.Msg = "操作成功"
  1092. }
  1093. // ResetPass
  1094. // @Title 重置密码
  1095. // @Description 重置密码
  1096. // @Param request body system.SysUserResetPassReq true "type json string"
  1097. // @Success 200 编辑成功
  1098. // @router /sysuser/reset_pass [post]
  1099. func (this *SysAdminController) ResetPass() {
  1100. br := new(models.BaseResponse).Init()
  1101. defer func() {
  1102. this.Data["json"] = br
  1103. this.ServeJSON()
  1104. }()
  1105. var req system.SysUserResetPassReq
  1106. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1107. if err != nil {
  1108. br.Msg = "参数解析异常!"
  1109. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1110. return
  1111. }
  1112. if req.AdminId <= 0 {
  1113. br.Msg = "参数有误"
  1114. br.ErrMsg = "参数有误, AdminId"
  1115. return
  1116. }
  1117. req.Password = strings.TrimSpace(req.Password)
  1118. if req.Password == "" {
  1119. br.Msg = "新密码不能为空"
  1120. return
  1121. }
  1122. req.RePassword = strings.TrimSpace(req.RePassword)
  1123. if req.RePassword == "" {
  1124. br.Msg = "确认密码不能为空"
  1125. return
  1126. }
  1127. if req.Password != req.RePassword {
  1128. br.Msg = "两次输入密码不一致,请重新填写"
  1129. return
  1130. }
  1131. adminInfo, err := system.GetSysAdminById(req.AdminId)
  1132. if err != nil {
  1133. if err.Error() == utils.ErrNoRow() {
  1134. br.Msg = "用户已被删除, 请刷新页面"
  1135. return
  1136. }
  1137. br.Msg = "获取数据失败"
  1138. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error() + ";AdminId:" + fmt.Sprint(req.AdminId)
  1139. return
  1140. }
  1141. b, err := base64.StdEncoding.DecodeString(req.Password)
  1142. if err != nil {
  1143. br.Msg = "解析数据失败"
  1144. br.ErrMsg = "解析数据失败,Err:" + err.Error()
  1145. return
  1146. }
  1147. pwd := string(b)
  1148. //pwd = strings.ToLower(pwd)
  1149. pwd = utils.MD5(pwd)
  1150. adminInfo.Password = pwd
  1151. adminInfo.LastUpdatedPasswordTime = time.Now().Format(utils.FormatDateTime)
  1152. adminInfo.LastUpdatedTime = time.Now().Format(utils.FormatDateTime)
  1153. if e := adminInfo.Update([]string{"Password", "LastUpdatedPasswordTime", "LastUpdatedTime"}); e != nil {
  1154. br.Msg = "操作失败"
  1155. br.ErrMsg = "更新系统用户分组失败, Err: " + e.Error()
  1156. return
  1157. }
  1158. // 同步用户缓存
  1159. if utils.BusinessCode == utils.BusinessCodeRelease {
  1160. var syncData system.SyncAdminData
  1161. syncData.Source = utils.SOURCE_ETA_FLAG
  1162. syncData.AdminName = adminInfo.AdminName
  1163. _ = utils.Rc.LPush(utils.CACHE_SYNC_ADMIN, syncData)
  1164. }
  1165. // 清除系统用户列表缓存key
  1166. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN)
  1167. _ = utils.Rc.Delete(utils.CACHE_KEY_ADMIN_ID)
  1168. br.Ret = 200
  1169. br.Success = true
  1170. br.IsAddLog = true
  1171. br.Msg = "重置密码成功"
  1172. }
  1173. // Add
  1174. // @Title 用户详情信息
  1175. // @Description 用户详情信息
  1176. // @Param request body system.SysuserAddReq true "type json string"
  1177. // @Success 200 新增成功
  1178. // @router /sysuser/detail [get]
  1179. func (this *SysAdminController) Detail() {
  1180. br := new(models.BaseResponse).Init()
  1181. defer func() {
  1182. this.Data["json"] = br
  1183. this.ServeJSON()
  1184. }()
  1185. br.Data = this.SysUser
  1186. br.Ret = 200
  1187. br.Success = true
  1188. br.Msg = "获取成功"
  1189. }