new_dialysis_api_controller.go 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package new_mobile_api_controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. "Xcx_New/utils"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "time"
  10. )
  11. type NewDialysisApiController struct {
  12. NewMobileBaseAPIAuthController
  13. }
  14. func (this *NewDialysisApiController) GetCodeInit() {
  15. redisClient := service.RedisClient()
  16. defer redisClient.Close()
  17. req := this.Ctx.Request
  18. addr := utils.GetIP(req)
  19. cur_time := time.Now().Format("2006-01-02")
  20. _, err := redisClient.Get(redisClient.Context(),"ip:host_" + cur_time + "_" + addr).Result()
  21. if err != nil {
  22. redisClient.Set(redisClient.Context(),"ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
  23. }
  24. //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
  25. aespass := utils.AESEncrypt(addr)
  26. fmt.Println("hhhhhhh3223323232332", aespass)
  27. this.ServeSuccessJSON(map[string]interface{}{
  28. "aespass": aespass,
  29. })
  30. }
  31. func (this *NewDialysisApiController) GetUserRegister() {
  32. //用户绑定
  33. name := this.GetString("name")
  34. id_card_no := this.GetString("id_card_no")
  35. mobile := this.GetString("mobile")
  36. code := this.GetString("code")
  37. role := models.XcxAdminUserRole{
  38. PatientName: name,
  39. IdCardNo: id_card_no,
  40. Mobile: mobile,
  41. Code: code,
  42. PatientId: 0,
  43. UserOrgId: 0,
  44. Status: 0,
  45. Ctime: 0,
  46. Mtime: 0,
  47. Appid: "",
  48. Appsecret: "",
  49. SessionKey: "",
  50. }
  51. //查找该电话号码是否存在
  52. _, errcode := service.GetXcxMobileInformation(mobile)
  53. if errcode == gorm.ErrRecordNotFound {
  54. err := service.CreateXcxAdminUser(role)
  55. if err == nil {
  56. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  57. return
  58. }
  59. this.ServeSuccessJSON(map[string]interface{}{
  60. "role": role,
  61. })
  62. } else if errcode == nil {
  63. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  64. return
  65. }
  66. fmt.Println("roler", role)
  67. }
  68. func (this *NewDialysisApiController) GetCodeInfo() {
  69. mobile := this.GetString("phone")
  70. aespass := this.GetString("aespass")
  71. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  72. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  73. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  74. this.ServeJSON()
  75. return
  76. }
  77. adminUser, _ := service.GetValidAdminUserByMobileReturnErr(mobile)
  78. if adminUser != nil {
  79. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRegisterExist)
  80. this.ServeJSON()
  81. return
  82. }
  83. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  84. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  85. this.ServeJSON()
  86. } else {
  87. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  88. "msg": "短信发送成功,有效期为10分钟",
  89. })
  90. this.ServeJSON()
  91. }
  92. }
  93. func (this *NewDialysisApiController) GetLoginInfor() {
  94. fmt.Println("c出啊大发阿方阿道夫发 阿方阿")
  95. //mobile := this.GetString("mobile")
  96. //fmt.Println(mobile)
  97. role, err := service.GetLoginInfor("18923081560")
  98. fmt.Println("err2332323232", err)
  99. if err == nil {
  100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  101. return
  102. }
  103. this.ServeSuccessJSON(map[string]interface{}{
  104. "role": role,
  105. })
  106. }