xcx_api_controller.go 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. //beego.Router("/xcx/api/mobile/")
  30. }
  31. type XcxApiController struct {
  32. mobile_api_controllers.MobileBaseAPIController
  33. }
  34. func (this *XcxApiController) GetCodeInit() {
  35. redisClient := service.RedisClient()
  36. defer redisClient.Close()
  37. req := this.Ctx.Request
  38. addr := utils.GetIP(req)
  39. cur_time := time.Now().Format("2006-01-02")
  40. _, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result()
  41. if err != nil {
  42. redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
  43. }
  44. //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
  45. aespass := utils.AESEncrypt(addr)
  46. fmt.Println("hhhhhhh3223323232332", aespass)
  47. this.ServeSuccessJSON(map[string]interface{}{
  48. "aespass": aespass,
  49. })
  50. }
  51. func (this *XcxApiController) GetUserRegister() {
  52. //用户绑定
  53. name := this.GetString("name")
  54. id_card_no := this.GetString("id_card_no")
  55. mobile := this.GetString("mobile")
  56. code := this.GetString("code")
  57. patient, errcodes := service.GetMobilePatient(id_card_no)
  58. if errcodes == gorm.ErrRecordNotFound {
  59. role := models.XcxAdminUserRole{
  60. PatientName: name,
  61. IdCardNo: id_card_no,
  62. Mobile: mobile,
  63. Code: code,
  64. PatientId: patient.ID,
  65. UserOrgId: patient.UserOrgId,
  66. Status: 1,
  67. Ctime: time.Now().Unix(),
  68. Mtime: 0,
  69. Appid: "",
  70. Appsecret: "",
  71. SessionKey: "",
  72. }
  73. //查找该电话号码是否存在
  74. _, errcode := service.GetMobilePatient(mobile)
  75. if errcode == gorm.ErrRecordNotFound {
  76. err := service.CreateXcxAdminUser(role)
  77. if err == nil {
  78. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  79. return
  80. }
  81. this.ServeSuccessJSON(map[string]interface{}{
  82. "role": role,
  83. })
  84. } else if errcode == nil {
  85. mobilePatient, _ := service.GetMobilePatient(id_card_no)
  86. this.ServeSuccessJSON(map[string]interface{}{
  87. "is_bind": true,
  88. "patient": mobilePatient,
  89. })
  90. }
  91. fmt.Println("roler", role)
  92. } else if errcodes == nil {
  93. this.ServeSuccessJSON(map[string]interface{}{
  94. "is_bind": false,
  95. "patient": patient,
  96. })
  97. }
  98. }
  99. func (this *XcxApiController) GetCodeInfo() {
  100. mobile := this.GetString("phone")
  101. aespass := this.GetString("aespass")
  102. utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
  103. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  104. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
  105. this.ServeJSON()
  106. return
  107. }
  108. if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
  109. this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
  110. this.ServeJSON()
  111. } else {
  112. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  113. "msg": "短信发送成功,有效期为10分钟",
  114. })
  115. this.ServeJSON()
  116. }
  117. }
  118. func (this *XcxApiController) GetLoginInfor() {
  119. fmt.Println("c出啊大发阿方阿道夫发 阿方阿")
  120. mobile := this.GetString("mobile")
  121. fmt.Println(mobile)
  122. info, err := service.GetMobilePatientInfo(mobile)
  123. if info.ID == 0 {
  124. if err != nil {
  125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  126. return
  127. }
  128. this.ServeSuccessJSON(map[string]interface{}{
  129. "is_bind": false,
  130. "info": info,
  131. })
  132. } else {
  133. _, errcode := service.GetLoginInfor("18923081560")
  134. if errcode == gorm.ErrRecordNotFound {
  135. role := models.XcxAdminUserRole{
  136. PatientName: info.Name,
  137. IdCardNo: info.IdCardNo,
  138. Mobile: info.TellPhone,
  139. Code: "",
  140. PatientId: info.ID,
  141. UserOrgId: info.UserOrgId,
  142. Status: 1,
  143. Ctime: time.Now().Unix(),
  144. Mtime: 0,
  145. Appid: "",
  146. Appsecret: "",
  147. SessionKey: "",
  148. }
  149. err := service.CreateXcxAdminUser(role)
  150. fmt.Println(err)
  151. } else {
  152. this.ServeSuccessJSON(map[string]interface{}{
  153. "is_bind": true,
  154. "info": info,
  155. })
  156. }
  157. this.ServeSuccessJSON(map[string]interface{}{
  158. "is_bind": true,
  159. "info": info,
  160. })
  161. }
  162. }
  163. func (this *XcxApiController) GetPatientList() {
  164. //var appid = "wx4f4bc4dec97d474b"
  165. //var key = "tiihtNczf5v6AKRyjwEUhQ=="
  166. //var iv = "r7BXXKkLb8qrSNn05n0qiA=="
  167. //var strs = "CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew=="
  168. appid := "wx4f4bc4dec97d474b"
  169. key := "4BactRvIKCBXzvpyl2SQyQ=="
  170. strs := "Gr5gmKz9OjWGipAxt3ujQtHBBXV/Uvhsm+qvvZy6gF+HBc8c6gZhZkqIqLbs8nHkId5zm/mGVNpghvM/egYTLOOI7LxhvjRsPE1691j+jltU9OIavGIWFp3I4m3OdP9CuPohhrpZPgwsGajJmtGNNjPvGA61ssErVZ7SBceq+leag532zCmgEXN3NpZP0TRgpIpwpegCAEW07oyI0LiRYA=="
  171. iv := "aXiAcKIWKfseTyzelqcZ0w=="
  172. //data, err := service.Dncrypt(strs, key, iv)
  173. //fmt.Println(err)
  174. data, err := service.DecryptData(appid, key, iv, strs)
  175. patient_id, _ := this.GetInt64("patient_id")
  176. patient, err := service.GetPatientListByPatientId(patient_id)
  177. if err == nil {
  178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  179. return
  180. }
  181. this.ServeSuccessJSON(map[string]interface{}{
  182. "patient": patient,
  183. "data": data,
  184. })
  185. }
  186. func (this *XcxApiController) GetDataInfo() {
  187. appid := this.GetString("appid")
  188. fmt.Println(appid)
  189. key := this.GetString("key")
  190. iv := this.GetString("iv")
  191. encryptedData := this.GetString("encryptedData")
  192. list, _ := service.DecryptData(appid, key, iv, encryptedData)
  193. //list, err := service.Dncrypt(encryptedData, key, iv)
  194. this.ServeSuccessJSON(map[string]interface{}{
  195. "list": list,
  196. })
  197. }
  198. func (this *XcxApiController) GetScheduleInfo() {
  199. //patient_id, _ := this.GetInt64("patient_id")
  200. thisWeekMonday := service.GetFirstDateOfWeek()
  201. weekDayWeek := service.GetWeekDayOfWeek()
  202. TimeMonday, _ := time.Parse("2006-01-02", thisWeekMonday)
  203. weekDays, _ := time.Parse("2006-01-02", weekDayWeek)
  204. lastWeekMonday := TimeMonday.AddDate(0, 0, -7)
  205. nextWeekMonday := weekDays.AddDate(0, 0, +13)
  206. var weekMonday = lastWeekMonday.Format("2006-01-02")
  207. var weekDay = nextWeekMonday.Format("2006-01-02")
  208. fmt.Println("weekmodonday", weekMonday)
  209. fmt.Println("nextweeekday", weekDay)
  210. timeLayout := "2006-01-02 15:04:05"
  211. loc, _ := time.LoadLocation("Local")
  212. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekMonday+" 00:00:00", loc)
  213. fmt.Println("startiem", startTime)
  214. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekDay+" 00:00:00", loc)
  215. fmt.Println(startTime.Unix(), endTime.Unix())
  216. schedule, err := service.GetScheduleInfo(1630252800, 1631980800, 2448)
  217. if err != nil {
  218. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  219. return
  220. }
  221. array := []interface{}{
  222. map[string]string{"schedule_type": "1", "schedule_date": "1630252800", "schedule_week": "", "mode_id": ""},
  223. map[string]string{"schedule_type": "2", "schedule_date": "1630252800", "schedule_week": "", "mode_id": ""},
  224. map[string]string{"schedule_type": "3", "schedule_date": "1630252800", "schedule_week": "", "mode_id": ""},
  225. map[string]string{"schedule_type": "1", "schedule_date": "1630339200", "schedule_week": "", "mode_id": ""},
  226. map[string]string{"schedule_type": "2", "schedule_date": "1630339200", "schedule_week": "", "mode_id": ""},
  227. map[string]string{"schedule_type": "3", "schedule_date": "1630339200", "schedule_week": "", "mode_id": ""},
  228. map[string]string{"schedule_type": "1", "schedule_date": "1630425600", "schedule_week": "", "mode_id": ""},
  229. map[string]string{"schedule_type": "2", "schedule_date": "1630425600", "schedule_week": "", "mode_id": ""},
  230. map[string]string{"schedule_type": "3", "schedule_date": "1630425600", "schedule_week": "", "mode_id": ""},
  231. map[string]string{"schedule_type": "1", "schedule_date": "1630512000", "schedule_week": "", "mode_id": ""},
  232. map[string]string{"schedule_type": "2", "schedule_date": "1630512000", "schedule_week": "", "mode_id": ""},
  233. map[string]string{"schedule_type": "3", "schedule_date": "1630512000", "schedule_week": "", "mode_id": ""},
  234. map[string]string{"schedule_type": "1", "schedule_date": "1630598400", "schedule_week": "", "mode_id": ""},
  235. map[string]string{"schedule_type": "2", "schedule_date": "1630598400", "schedule_week": "", "mode_id": ""},
  236. map[string]string{"schedule_type": "3", "schedule_date": "1630598400", "schedule_week": "", "mode_id": ""},
  237. map[string]string{"schedule_type": "1", "schedule_date": "1630684800", "schedule_week": "", "mode_id": ""},
  238. map[string]string{"schedule_type": "2", "schedule_date": "1630684800", "schedule_week": "", "mode_id": ""},
  239. map[string]string{"schedule_type": "3", "schedule_date": "1630684800", "schedule_week": "", "mode_id": ""},
  240. map[string]string{"schedule_type": "1", "schedule_date": "1630771200", "schedule_week": "", "mode_id": ""},
  241. map[string]string{"schedule_type": "2", "schedule_date": "1630771200", "schedule_week": "", "mode_id": ""},
  242. map[string]string{"schedule_type": "3", "schedule_date": "1630771200", "schedule_week": "", "mode_id": ""},
  243. map[string]string{"schedule_type": "1", "schedule_date": "1630857600", "schedule_week": "", "mode_id": ""},
  244. map[string]string{"schedule_type": "2", "schedule_date": "1630857600", "schedule_week": "", "mode_id": ""},
  245. map[string]string{"schedule_type": "3", "schedule_date": "1630857600", "schedule_week": "", "mode_id": ""},
  246. map[string]string{"schedule_type": "1", "schedule_date": "1630944000", "schedule_week": "", "mode_id": ""},
  247. map[string]string{"schedule_type": "2", "schedule_date": "1630944000", "schedule_week": "", "mode_id": ""},
  248. map[string]string{"schedule_type": "3", "schedule_date": "1630944000", "schedule_week": "", "mode_id": ""},
  249. map[string]string{"schedule_type": "1", "schedule_date": "1631030400", "schedule_week": "", "mode_id": ""},
  250. map[string]string{"schedule_type": "2", "schedule_date": "1631030400", "schedule_week": "", "mode_id": ""},
  251. map[string]string{"schedule_type": "3", "schedule_date": "1631030400", "schedule_week": "", "mode_id": ""},
  252. map[string]string{"schedule_type": "1", "schedule_date": "1631116800", "schedule_week": "", "mode_id": ""},
  253. map[string]string{"schedule_type": "2", "schedule_date": "1631116800", "schedule_week": "", "mode_id": ""},
  254. map[string]string{"schedule_type": "3", "schedule_date": "1631116800", "schedule_week": "", "mode_id": ""},
  255. map[string]string{"schedule_type": "1", "schedule_date": "1631203200", "schedule_week": "", "mode_id": ""},
  256. map[string]string{"schedule_type": "2", "schedule_date": "1631203200", "schedule_week": "", "mode_id": ""},
  257. map[string]string{"schedule_type": "3", "schedule_date": "1631203200", "schedule_week": "", "mode_id": ""},
  258. map[string]string{"schedule_type": "1", "schedule_date": "1631289600", "schedule_week": "", "mode_id": ""},
  259. map[string]string{"schedule_type": "2", "schedule_date": "1631289600", "schedule_week": "", "mode_id": ""},
  260. map[string]string{"schedule_type": "3", "schedule_date": "1631289600", "schedule_week": "", "mode_id": ""},
  261. map[string]string{"schedule_type": "1", "schedule_date": "1631376000", "schedule_week": "", "mode_id": ""},
  262. map[string]string{"schedule_type": "2", "schedule_date": "1631376000", "schedule_week": "", "mode_id": ""},
  263. map[string]string{"schedule_type": "3", "schedule_date": "1631376000", "schedule_week": "", "mode_id": ""},
  264. map[string]string{"schedule_type": "1", "schedule_date": "1631462400", "schedule_week": "", "mode_id": ""},
  265. map[string]string{"schedule_type": "2", "schedule_date": "1631462400", "schedule_week": "", "mode_id": ""},
  266. map[string]string{"schedule_type": "3", "schedule_date": "1631462400", "schedule_week": "", "mode_id": ""},
  267. map[string]string{"schedule_type": "1", "schedule_date": "1631548800", "schedule_week": "", "mode_id": ""},
  268. map[string]string{"schedule_type": "2", "schedule_date": "1631548800", "schedule_week": "", "mode_id": ""},
  269. map[string]string{"schedule_type": "3", "schedule_date": "1631548800", "schedule_week": "", "mode_id": ""},
  270. map[string]string{"schedule_type": "1", "schedule_date": "1631635200", "schedule_week": "", "mode_id": ""},
  271. map[string]string{"schedule_type": "2", "schedule_date": "1631635200", "schedule_week": "", "mode_id": ""},
  272. map[string]string{"schedule_type": "3", "schedule_date": "1631635200", "schedule_week": "", "mode_id": ""},
  273. map[string]string{"schedule_type": "1", "schedule_date": "1631721600", "schedule_week": "", "mode_id": ""},
  274. map[string]string{"schedule_type": "2", "schedule_date": "1631721600", "schedule_week": "", "mode_id": ""},
  275. map[string]string{"schedule_type": "3", "schedule_date": "1631721600", "schedule_week": "", "mode_id": ""},
  276. map[string]string{"schedule_type": "1", "schedule_date": "1631808000", "schedule_week": "", "mode_id": ""},
  277. map[string]string{"schedule_type": "2", "schedule_date": "1631808000", "schedule_week": "", "mode_id": ""},
  278. map[string]string{"schedule_type": "3", "schedule_date": "1631808000", "schedule_week": "", "mode_id": ""},
  279. map[string]string{"schedule_type": "1", "schedule_date": "1631894400", "schedule_week": "", "mode_id": ""},
  280. map[string]string{"schedule_type": "2", "schedule_date": "1631894400", "schedule_week": "", "mode_id": ""},
  281. map[string]string{"schedule_type": "3", "schedule_date": "1631894400", "schedule_week": "", "mode_id": ""},
  282. map[string]string{"schedule_type": "1", "schedule_date": "1631980800", "schedule_week": "", "mode_id": ""},
  283. map[string]string{"schedule_type": "2", "schedule_date": "1631980800", "schedule_week": "", "mode_id": ""},
  284. map[string]string{"schedule_type": "3", "schedule_date": "1631980800", "schedule_week": "", "mode_id": ""},
  285. }
  286. this.ServeSuccessJSON(map[string]interface{}{
  287. "list": schedule,
  288. "array": array,
  289. })
  290. }