admin_user_api_controller.go 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. es, _ := service.GetAdminUserElectronicSignature(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id)
  17. if es != nil {
  18. c.ServeSuccessJSON(map[string]interface{}{
  19. "state": 1,
  20. "electronic_signature": es,
  21. })
  22. } else {
  23. c.ServeSuccessJSON(map[string]interface{}{
  24. "state": 0,
  25. })
  26. }
  27. return
  28. }
  29. func (c *AdminUserApiController) SaveAdminUserElectronicSignature() {
  30. adminUserInfo := c.GetMobileAdminUserInfo()
  31. es, _ := service.GetAdminUserElectronicSignature(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id)
  32. action := "update"
  33. timeNow := time.Now().Unix()
  34. if es == nil {
  35. es = new(models.AdminUserElectronicSignature)
  36. es.Status = 1
  37. es.OrgId = adminUserInfo.Org.Id
  38. es.AppId = adminUserInfo.App.Id
  39. es.Ctime = timeNow
  40. es.Creator = adminUserInfo.AdminUser.Id
  41. action = "create"
  42. }
  43. es.Mtime = timeNow
  44. var esdata models.AdminUserElectronicSignature
  45. var err error
  46. if err = json.Unmarshal(c.Ctx.Input.RequestBody, &esdata); err != nil {
  47. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  48. return
  49. }
  50. es.Hash = esdata.Hash
  51. es.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  52. if action == "create" {
  53. err = service.CreateAdminUserElectronicSignature(es)
  54. } else {
  55. err = service.SaveAdminUserElectronicSignature(es)
  56. }
  57. if err != nil {
  58. fmt.Println(err)
  59. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  60. return
  61. }
  62. c.ServeSuccessJSON(map[string]interface{}{
  63. "electronic_signature": es,
  64. })
  65. }
  66. func (c *AdminUserApiController) GetMyInfo() {
  67. adminUserInfo := c.GetMobileAdminUserInfo()
  68. roleInfo := adminUserInfo.AppRole
  69. es, _ := service.GetAdminUserElectronicSignature(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id)
  70. c.ServeSuccessJSON(map[string]interface{}{
  71. "electronic_signature": es,
  72. "roleInfo": roleInfo,
  73. })
  74. return
  75. }