package controllers import ( "SCRM/enums" ) type BaseAPIController struct { BaseController } // 输出数据格式化 /* success json: { "state": 1, "code": 0, "data": json, } fail json: { "state": 0, "code": int, "msg": string, } */ func (this *BaseAPIController) ServeSuccessJSON(data map[string]interface{}) { this.Data["json"] = enums.MakeSuccessResponseJSON(data) this.ServeJSON() } func (this *BaseAPIController) ServeFailJSONWithSGJErrorCode(code int) { this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(code) this.ServeJSON() } func (this *BaseAPIController) ServeFailJSONWithSGJError(err *enums.SGJError) { this.Data["json"] = enums.MakeFailResponseJSONWithSGJError(err) this.ServeJSON() } func (this *BaseAPIController) ServeFailJsonSend(code int, msg string) { this.Data["json"] = enums.MakeFailResponseJSON(msg, code) this.ServeJSON() } type BaseAuthAPIController struct { BaseAPIController } func (this *BaseAuthAPIController) Prepare() { this.BaseAPIController.Prepare() if this.GetAdminUserInfo() == nil { // var userAdmin models.AdminUser // userAdmin.Id = 380 // userAdmin.Mobile = "13532250447" // userAdmin.IsSuperAdmin = true // userAdmin.Status = 1 // userAdmin.CreateTime = 1530786071 // userAdmin.ModifyTime = 1530786071 // var subscibe models.ServeSubscibe // subscibe.ID = 1 // subscibe.OrgId = 4 // subscibe.PeriodStart = 1538035409 // subscibe.PeriodEnd = 1569571409 // subscibe.State = 1 // subscibe.Status = 1 // subscibe.CreatedTime = 1538035409 // subscibe.UpdatedTime = 1538035409 // subscibes := make(map[int64]*models.ServeSubscibe, 0) // subscibes[4] = &subscibe // var adminUserInfo admin_service.AdminUserInfo // adminUserInfo.CurrentOrgId = 4 // adminUserInfo.CurrentAppId = 5 // adminUserInfo.AdminUser = &userAdmin // adminUserInfo.Subscibes = subscibes // this.SetSession("admin_user_info", &adminUserInfo) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin) this.StopRun() } } type BaseServeAPIController struct { BaseAPIController } func (this *BaseServeAPIController) Prepare() { this.BaseAPIController.Prepare() if this.GetAdminUserInfo() == nil { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin) this.StopRun() } }