xcx_api_controller.go 7.0KB

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