sys_admin.go 34 KB

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