123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package controllers
-
- import (
- "XT_Admin_Api/enums"
- )
-
- type BaseAPIController struct {
- BaseController
- }
-
- // func (this *BaseAPIController) Prepare() {
- // this.BaseController.Prepare()
- // beego.Trace("============================================================")
- // beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID"))
- // beego.Trace("session : %v", this.GetSession("info"))
- // this.SetSession("info", time.Now().Format("2006/01/02 15:04:05"))
- // beego.Trace("============================================================")
- // }
-
- // 输出数据格式化
- /*
- 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 template models.GobalTemplate
- //template.TemplateId = 2
- //
- //
- //var adminUserInfo 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 {
- //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 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()
- }
- }
|