xcx_api_controller.go 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package xcx_mobile_api_controller_go
  2. import (
  3. "Xcx_New/controllers/mobile_api_controllers"
  4. "Xcx_New/enums"
  5. "Xcx_New/models"
  6. "Xcx_New/service"
  7. "Xcx_New/utils"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "time"
  12. )
  13. func XcxApiControllersRegisterRouters() {
  14. ////传送codeinit
  15. beego.Router("/xcx/m/api/code", &XcxApiController{}, "Get:GetCodeInit")
  16. //获取验证码
  17. beego.Router("/xcx/api/mobile/code", &XcxApiController{}, "Get:GetCodeInfo")
  18. //用户绑定
  19. beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetUserRegister")
  20. //登录
  21. beego.Router("/xcx/api/mobile/login", &XcxApiController{}, "Get:GetLoginInfor")
  22. //获取二维码信息
  23. beego.Router("/xcx/api/mobile/patient", &XcxApiController{}, "Get:GetPatientList")
  24. //获取登录后的信息
  25. beego.Router("/xcx/api/mobile/getdatainfo", &XcxApiController{}, "Get:GetDataInfo")
  26. //获取排班数据
  27. beego.Router("/xcx/api/mobile/schedule", &XcxApiController{}, "Get:GetScheduleInfo")
  28. }
  29. type XcxApiController struct {
  30. mobile_api_controllers.MobileBaseAPIController
  31. }
  32. func (this *XcxApiController) GetCodeInit() {
  33. redisClient := service.RedisClient()
  34. defer redisClient.Close()
  35. req := this.Ctx.Request
  36. addr := utils.GetIP(req)
  37. cur_time := time.Now().Format("2006-01-02")
  38. _, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result()
  39. if err != nil {
  40. redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
  41. }
  42. //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
  43. aespass := utils.AESEncrypt(addr)
  44. fmt.Println("hhhhhhh3223323232332", aespass)
  45. this.ServeSuccessJSON(map[string]interface{}{
  46. "aespass": aespass,
  47. })
  48. }
  49. func (this *XcxApiController) GetUserRegister() {
  50. //用户绑定
  51. name := this.GetString("name")
  52. id_card_no := this.GetString("id_card_no")
  53. mobile := this.GetString("mobile")
  54. code := this.GetString("code")
  55. patient, errcodes := service.GetMobilePatient(id_card_no)
  56. if errcodes == gorm.ErrRecordNotFound {
  57. role := models.XcxAdminUserRole{
  58. PatientName: name,
  59. IdCardNo: id_card_no,
  60. Mobile: mobile,
  61. Code: code,
  62. PatientId: patient.ID,
  63. UserOrgId: patient.UserOrgId,
  64. Status: 1,
  65. Ctime: time.Now().Unix(),
  66. Mtime: 0,
  67. Appid: "",
  68. Appsecret: "",
  69. SessionKey: "",
  70. }
  71. //查找该电话号码是否存在
  72. _, errcode := service.GetMobilePatient(mobile)
  73. if errcode == gorm.ErrRecordNotFound {
  74. err := service.CreateXcxAdminUser(role)
  75. if err == nil {
  76. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  77. return
  78. }
  79. this.ServeSuccessJSON(map[string]interface{}{
  80. "role": role,
  81. })
  82. } else if errcode == nil {
  83. mobilePatient, _ := service.GetMobilePatient(id_card_no)
  84. this.ServeSuccessJSON(map[string]interface{}{
  85. "is_bind": true,
  86. "patient": mobilePatient,
  87. })
  88. }
  89. fmt.Println("roler", role)
  90. } else if errcodes == nil {
  91. this.ServeSuccessJSON(map[string]interface{}{
  92. "is_bind": false,
  93. "patient": patient,
  94. })
  95. }
  96. }
  97. func (this *XcxApiController) GetCodeInfo() {
  98. mobile := this.GetString("phone")
  99. aespass := this.GetString("aespass")
  100. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  101. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  102. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  103. this.ServeJSON()
  104. return
  105. }
  106. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  107. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  108. this.ServeJSON()
  109. } else {
  110. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  111. "msg": "短信发送成功,有效期为10分钟",
  112. })
  113. this.ServeJSON()
  114. }
  115. }
  116. func (this *XcxApiController) GetLoginInfor() {
  117. fmt.Println("c出啊大发阿方阿道夫发 阿方阿")
  118. mobile := this.GetString("mobile")
  119. fmt.Println(mobile)
  120. info, err := service.GetMobilePatientInfo(mobile)
  121. if info.ID == 0 {
  122. if err == nil {
  123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  124. return
  125. }
  126. this.ServeSuccessJSON(map[string]interface{}{
  127. "is_bind": false,
  128. "info": info,
  129. })
  130. } else {
  131. _, errcode := service.GetLoginInfor("18923081560")
  132. if errcode == gorm.ErrRecordNotFound {
  133. role := models.XcxAdminUserRole{
  134. PatientName: info.Name,
  135. IdCardNo: info.IdCardNo,
  136. Mobile: info.TellPhone,
  137. Code: "",
  138. PatientId: info.ID,
  139. UserOrgId: info.UserOrgId,
  140. Status: 1,
  141. Ctime: time.Now().Unix(),
  142. Mtime: 0,
  143. Appid: "",
  144. Appsecret: "",
  145. SessionKey: "",
  146. }
  147. err := service.CreateXcxAdminUser(role)
  148. fmt.Println(err)
  149. } else {
  150. this.ServeSuccessJSON(map[string]interface{}{
  151. "is_bind": true,
  152. "info": info,
  153. })
  154. }
  155. this.ServeSuccessJSON(map[string]interface{}{
  156. "is_bind": true,
  157. "info": info,
  158. })
  159. }
  160. }
  161. func (this *XcxApiController) GetPatientList() {
  162. var appid = "wx20b60369111b063a"
  163. var key = "HobHcmPatZ0O5emMYcFo1Q=="
  164. var iv = "wJjr8o47Jv8zBoZF5la+jw=="
  165. var strs = "DKj+ZzSKd77D2X84UqySTfTOxcZ9W5yAArqt74g3Fek+/8N97XI3nKzLO4QadJxwl9f8BDqrpl2dauqNBC4HbkggFcEB9j1zsYDKAm5cM0NPOkjcHeGF8dxpuJGdXWFKZErD957XEPtyODbE3IUMIx/n8haGtCa3W9v5Gqosqxrb6eNY9ogf8V1dy2guuxVAxWojuZ2DLyYovksFLccD5Q=="
  166. data, err := service.DecryptData(appid, key, iv, strs)
  167. patient_id, _ := this.GetInt64("patient_id")
  168. patient, err := service.GetPatientListByPatientId(patient_id)
  169. if err == nil {
  170. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  171. return
  172. }
  173. this.ServeSuccessJSON(map[string]interface{}{
  174. "patient": patient,
  175. "data": data,
  176. })
  177. }
  178. func (this *XcxApiController) GetDataInfo() {
  179. appid := this.GetString("appid")
  180. key := this.GetString("key")
  181. iv := this.GetString("iv")
  182. encryptedData := this.GetString("encryptedData")
  183. list, _ := service.DecryptData(appid, key, iv, encryptedData)
  184. fmt.Println(list)
  185. this.ServeSuccessJSON(map[string]interface{}{
  186. "list": list,
  187. })
  188. }
  189. func (this *XcxApiController) GetScheduleInfo() {
  190. thisWeekMonday := service.GetFirstDateOfWeek()
  191. weekDayWeek := service.GetWeekDayOfWeek()
  192. TimeMonday, _ := time.Parse("2006-01-02", thisWeekMonday)
  193. weekDays, _ := time.Parse("2006-01-02", weekDayWeek)
  194. lastWeekMonday := TimeMonday.AddDate(0, 0, -7)
  195. nextWeekMonday := weekDays.AddDate(0, 0, +13)
  196. var weekMonday = lastWeekMonday.Format("2006-01-02")
  197. var weekDay = nextWeekMonday.Format("2006-01-02")
  198. fmt.Println("weekmodonday", weekMonday)
  199. fmt.Println("nextweeekday", weekDay)
  200. timeLayout := "2006-01-02 15:04:05"
  201. loc, _ := time.LoadLocation("Local")
  202. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekMonday+" 00:00:00", loc)
  203. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekDay+" 00:00:00", loc)
  204. fmt.Println(startTime.Unix(), endTime.Unix())
  205. }