123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- package xcx_mobile_api_controller_go
-
- import (
- "Xcx_New/controllers/mobile_api_controllers"
- "Xcx_New/enums"
- "Xcx_New/models"
- "Xcx_New/service"
- "Xcx_New/utils"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func XcxApiControllersRegisterRouters() {
- ////传送codeinit
- beego.Router("/xcx/m/api/code", &XcxApiController{}, "Get:GetCodeInit")
- //获取验证码
- beego.Router("/xcx/api/mobile/code", &XcxApiController{}, "Get:GetCodeInfo")
- //用户绑定
- beego.Router("/xcx/api/mobile/register", &XcxApiController{}, "Get:GetUserRegister")
- //登录
- beego.Router("/xcx/api/mobile/login", &XcxApiController{}, "Get:GetLoginInfor")
-
- //获取二维码信息
- beego.Router("/xcx/api/mobile/patient", &XcxApiController{}, "Get:GetPatientList")
-
- //获取登录后的信息
- beego.Router("/xcx/api/mobile/getdatainfo", &XcxApiController{}, "Get:GetDataInfo")
-
- //获取排班数据
- beego.Router("/xcx/api/mobile/schedule", &XcxApiController{}, "Get:GetScheduleInfo")
-
- //获取病历信息
- //beego.Router("/xcx/api/mobile/")
- }
-
- type XcxApiController struct {
- mobile_api_controllers.MobileBaseAPIController
- }
-
- func (this *XcxApiController) GetCodeInit() {
- redisClient := service.RedisClient()
- defer redisClient.Close()
- req := this.Ctx.Request
- addr := utils.GetIP(req)
- cur_time := time.Now().Format("2006-01-02")
- _, err := redisClient.Get("ip:host_" + cur_time + "_" + addr).Result()
- if err != nil {
- redisClient.Set("ip:host_"+cur_time+"_"+addr, 0, time.Second*24*60*60)
- }
- //将客户端的ip加密传给前端,作为短信验证的密钥,来验证短信发送的IP地址
- aespass := utils.AESEncrypt(addr)
-
- fmt.Println("hhhhhhh3223323232332", aespass)
- this.ServeSuccessJSON(map[string]interface{}{
- "aespass": aespass,
- })
-
- }
-
- func (this *XcxApiController) GetUserRegister() {
-
- //用户绑定
- name := this.GetString("name")
- id_card_no := this.GetString("id_card_no")
- mobile := this.GetString("mobile")
- code := this.GetString("code")
-
- patient, errcodes := service.GetMobilePatient(id_card_no)
- if errcodes == gorm.ErrRecordNotFound {
- role := models.XcxAdminUserRole{
- PatientName: name,
- IdCardNo: id_card_no,
- Mobile: mobile,
- Code: code,
- PatientId: patient.ID,
- UserOrgId: patient.UserOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Appid: "",
- Appsecret: "",
- SessionKey: "",
- }
-
- //查找该电话号码是否存在
- _, errcode := service.GetMobilePatient(mobile)
- if errcode == gorm.ErrRecordNotFound {
- err := service.CreateXcxAdminUser(role)
- if err == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "role": role,
- })
- } else if errcode == nil {
- mobilePatient, _ := service.GetMobilePatient(id_card_no)
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": true,
- "patient": mobilePatient,
- })
- }
-
- fmt.Println("roler", role)
- } else if errcodes == nil {
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": false,
- "patient": patient,
- })
- }
-
- }
-
- func (this *XcxApiController) GetCodeInfo() {
-
- mobile := this.GetString("phone")
- aespass := this.GetString("aespass")
- utils.TraceLog("mobile:%v aespass:%v", mobile, aespass)
- if utils.CellPhoneRegexp().MatchString(mobile) == false {
- this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeMobileFormat)
- this.ServeJSON()
- return
- }
-
- if err := service.SendVerificationCodeSMS(mobile, aespass); err != nil {
- this.Data["json"] = enums.MakeFailResponseJSON(err.Error(), 600)
- this.ServeJSON()
- } else {
- this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
- "msg": "短信发送成功,有效期为10分钟",
- })
- this.ServeJSON()
- }
- }
-
- func (this *XcxApiController) GetLoginInfor() {
- fmt.Println("c出啊大发阿方阿道夫发 阿方阿")
- mobile := this.GetString("mobile")
- fmt.Println(mobile)
- info, err := service.GetMobilePatientInfo(mobile)
- if info.ID == 0 {
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": false,
- "info": info,
- })
- } else {
- _, errcode := service.GetLoginInfor("18923081560")
- if errcode == gorm.ErrRecordNotFound {
- role := models.XcxAdminUserRole{
- PatientName: info.Name,
- IdCardNo: info.IdCardNo,
- Mobile: info.TellPhone,
- Code: "",
- PatientId: info.ID,
- UserOrgId: info.UserOrgId,
- Status: 1,
- Ctime: time.Now().Unix(),
- Mtime: 0,
- Appid: "",
- Appsecret: "",
- SessionKey: "",
- }
- err := service.CreateXcxAdminUser(role)
- fmt.Println(err)
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": true,
- "info": info,
- })
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "is_bind": true,
- "info": info,
- })
- }
-
- }
-
- func (this *XcxApiController) GetPatientList() {
- //var appid = "wx4f4bc4dec97d474b"
- //var key = "tiihtNczf5v6AKRyjwEUhQ=="
- //var iv = "r7BXXKkLb8qrSNn05n0qiA=="
- //var strs = "CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew=="
-
- appid := "wx4f4bc4dec97d474b"
- key := "4BactRvIKCBXzvpyl2SQyQ=="
- strs := "Gr5gmKz9OjWGipAxt3ujQtHBBXV/Uvhsm+qvvZy6gF+HBc8c6gZhZkqIqLbs8nHkId5zm/mGVNpghvM/egYTLOOI7LxhvjRsPE1691j+jltU9OIavGIWFp3I4m3OdP9CuPohhrpZPgwsGajJmtGNNjPvGA61ssErVZ7SBceq+leag532zCmgEXN3NpZP0TRgpIpwpegCAEW07oyI0LiRYA=="
- iv := "aXiAcKIWKfseTyzelqcZ0w=="
- //data, err := service.Dncrypt(strs, key, iv)
- //fmt.Println(err)
-
- data, err := service.DecryptData(appid, key, iv, strs)
- patient_id, _ := this.GetInt64("patient_id")
- patient, err := service.GetPatientListByPatientId(patient_id)
-
- if err == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "data": data,
- })
- }
-
- func (this *XcxApiController) GetDataInfo() {
-
- appid := this.GetString("appid")
- fmt.Println(appid)
- key := this.GetString("key")
- iv := this.GetString("iv")
- encryptedData := this.GetString("encryptedData")
- list, _ := service.DecryptData(appid, key, iv, encryptedData)
- //list, err := service.Dncrypt(encryptedData, key, iv)
-
- this.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- }
-
- func (this *XcxApiController) GetScheduleInfo() {
- //patient_id, _ := this.GetInt64("patient_id")
- thisWeekMonday := service.GetFirstDateOfWeek()
- weekDayWeek := service.GetWeekDayOfWeek()
- TimeMonday, _ := time.Parse("2006-01-02", thisWeekMonday)
- weekDays, _ := time.Parse("2006-01-02", weekDayWeek)
- lastWeekMonday := TimeMonday.AddDate(0, 0, -7)
- nextWeekMonday := weekDays.AddDate(0, 0, +13)
- var weekMonday = lastWeekMonday.Format("2006-01-02")
- var weekDay = nextWeekMonday.Format("2006-01-02")
- fmt.Println("weekmodonday", weekMonday)
- fmt.Println("nextweeekday", weekDay)
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekMonday+" 00:00:00", loc)
- fmt.Println("startiem", startTime)
- endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekDay+" 00:00:00", loc)
-
- fmt.Println(startTime.Unix(), endTime.Unix())
-
- schedule, err := service.GetScheduleInfo(1630252800, 1631980800, 2448)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- array := []interface{}{
- map[string]string{"schedule_type": "1", "schedule_date": "1630252800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630252800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630252800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1630339200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630339200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630339200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1630425600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630425600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630425600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1630512000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630512000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630512000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1630598400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630598400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630598400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1630684800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630684800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630684800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1630771200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630771200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630771200", "schedule_week": "", "mode_id": ""},
-
- map[string]string{"schedule_type": "1", "schedule_date": "1630857600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630857600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630857600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1630944000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1630944000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1630944000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631030400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631030400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631030400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631116800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631116800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631116800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631203200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631203200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631203200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631289600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631289600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631289600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631376000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631376000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631376000", "schedule_week": "", "mode_id": ""},
-
- map[string]string{"schedule_type": "1", "schedule_date": "1631462400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631462400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631462400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631548800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631548800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631548800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631635200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631635200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631635200", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631721600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631721600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631721600", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631808000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631808000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631808000", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631894400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631894400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631894400", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "1", "schedule_date": "1631980800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "2", "schedule_date": "1631980800", "schedule_week": "", "mode_id": ""},
- map[string]string{"schedule_type": "3", "schedule_date": "1631980800", "schedule_week": "", "mode_id": ""},
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": schedule,
- "array": array,
- })
- }
|