admin_user_api_controller.go 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package mobile_api_controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_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. }