admin_user_api_controller.go 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "encoding/json"
  7. "fmt"
  8. "time"
  9. "github.com/astaxie/beego"
  10. )
  11. type AdminUserApiController struct {
  12. MobileBaseAPIAuthController
  13. }
  14. func (c *AdminUserApiController) GetAdminUserElectronicSignature() {
  15. adminUserInfo := c.GetMobileAdminUserInfo()
  16. //orgId, _ := service.GetCreatByOrgId(adminUserInfo.Org.Id)
  17. id := adminUserInfo.AdminUser.Id
  18. es, _ := service.GetAdminUserElectronicSignatureTwo(id)
  19. if es != nil {
  20. c.ServeSuccessJSON(map[string]interface{}{
  21. "state": 1,
  22. "electronic_signature": es,
  23. })
  24. } else {
  25. c.ServeSuccessJSON(map[string]interface{}{
  26. "state": 0,
  27. })
  28. }
  29. return
  30. }
  31. func (c *AdminUserApiController) SaveAdminUserElectronicSignature() {
  32. adminUserInfo := c.GetMobileAdminUserInfo()
  33. es, _ := service.GetAdminUserElectronicSignature(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id)
  34. action := "update"
  35. timeNow := time.Now().Unix()
  36. if es == nil {
  37. es = new(models.AdminUserElectronicSignature)
  38. es.Status = 1
  39. es.OrgId = adminUserInfo.Org.Id
  40. es.AppId = adminUserInfo.App.Id
  41. es.Ctime = timeNow
  42. es.Creator = adminUserInfo.AdminUser.Id
  43. action = "create"
  44. }
  45. es.Mtime = timeNow
  46. var esdata models.AdminUserElectronicSignature
  47. var err error
  48. if err = json.Unmarshal(c.Ctx.Input.RequestBody, &esdata); err != nil {
  49. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  50. return
  51. }
  52. es.Hash = esdata.Hash
  53. es.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  54. if action == "create" {
  55. err = service.CreateAdminUserElectronicSignature(es)
  56. } else {
  57. err = service.SaveAdminUserElectronicSignature(es)
  58. }
  59. if err != nil {
  60. fmt.Println(err)
  61. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  62. return
  63. }
  64. c.ServeSuccessJSON(map[string]interface{}{
  65. "electronic_signature": es,
  66. })
  67. }
  68. func (c *AdminUserApiController) GetMyInfo() {
  69. adminUserInfo := c.GetMobileAdminUserInfo()
  70. roleInfo := adminUserInfo.AppRole
  71. es, _ := service.GetAdminUserElectronicSignature(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id)
  72. c.ServeSuccessJSON(map[string]interface{}{
  73. "electronic_signature": es,
  74. "roleInfo": roleInfo,
  75. })
  76. return
  77. }