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" "encoding/json" "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{}, "Post:GetDataInfo") //获取排班数据 beego.Router("/xcx/api/mobile/schedule", &XcxApiController{}, "Get:GetScheduleInfo") } 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 = "wx20b60369111b063a" var key = "HobHcmPatZ0O5emMYcFo1Q==" var iv = "wJjr8o47Jv8zBoZF5la+jw==" var strs = "DKj+ZzSKd77D2X84UqySTfTOxcZ9W5yAArqt74g3Fek+/8N97XI3nKzLO4QadJxwl9f8BDqrpl2dauqNBC4HbkggFcEB9j1zsYDKAm5cM0NPOkjcHeGF8dxpuJGdXWFKZErD957XEPtyODbE3IUMIx/n8haGtCa3W9v5Gqosqxrb6eNY9ogf8V1dy2guuxVAxWojuZ2DLyYovksFLccD5Q==" 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() { dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } appid, _ := dataBody["appid"].(string) key, _ := dataBody["key"].(string) iv, _ := dataBody["iv"].(string) encryptedData, _ := dataBody["encryptedData"].(string) list, err := service.DecryptData(appid, key, iv, encryptedData) if err == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } this.ServeSuccessJSON(map[string]interface{}{ "list": list, }) } func (this *XcxApiController) GetScheduleInfo() { 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) endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", weekDay+" 00:00:00", loc) fmt.Println(startTime.Unix(), endTime.Unix()) }