| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package controllers
- import (
- "github.com/go-playground/validator/v10"
- "github.com/kataras/iris/v12"
- "log"
- "xps/cache"
- "xps/viewmodels"
- )
- var (
- validate *validator.Validate
- )
- func init() {
- validate = validator.New()
- }
- func errorData(errs ...error) {
- var s string
- for _, err := range errs {
- if err != nil {
- s += err.Error() + "<br/>"
- }
- }
- }
- type Base struct {
- Ctx iris.Context
- }
- func (b *Base) GetCurOcId() int64 {
- ocId, _ := b.Ctx.Values().GetInt64("ocId")
- return ocId
- }
- func (b *Base) GetCurUserId() int64 {
- userId, _ := b.Ctx.Values().GetInt64("userId")
- return userId
- }
- func (b *Base) GetOcTypeId() int64 {
- ocTypeId, _ := b.Ctx.Values().GetInt64("ocTypeId")
- return ocTypeId
- }
- func (b *Base) buildParams() map[string]interface{} {
- var conditions QueryConditions
- err := b.Ctx.ReadURL(&conditions)
- if err != nil {
- _ =b.Ctx.JSON(ResultErr(err.Error(), nil))
- }
- ocId, err := b.Ctx.Values().GetInt64("ocId")
- if err != nil {
- _ =b.Ctx.JSON(ResultErr(err.Error(), nil))
- b.Ctx.Next()
- }
- userId, err := b.Ctx.Values().GetInt64("userId")
- if err != nil {
- _ =b.Ctx.JSON(ResultErr(err.Error(), nil))
- b.Ctx.Next()
- }
- params := make(map[string]interface{})
- params["ocId"] = ocId
- params["groupId"] = conditions.GroupId
- params["userId"] = userId
- params["limit"] = conditions.Limit
- params["page"] = conditions.Page
- params["keywords"] = conditions.Keywords
- return params
- }
- // RetCode Result Code
- type RetCode int
- // Result Code List
- const (
- RetOk RetCode = 0
- RetErr RetCode = 500
- )
- type QueryConditions struct {
- OcId int64 `url:"ocId"`
- GroupId int64 `url:"groupId"`
- UserId int64 `url:"userId"`
- Page int `url:"page"`
- Limit int `url:"limit"`
- Keywords string `url:"keywords"`
- }
- type JsonResult struct {
- Code RetCode `json:"code"`
- Msg interface{} `json:"msg"`
- Data interface{} `json:"data"`
- }
- type ClientToken struct {
- token string `json:"token"`
- }
- func ResultOk(msg string, objects interface{}) (r *JsonResult) {
- r = &JsonResult{Code: RetOk, Msg: msg, Data: objects}
- return
- }
- func ResultErr(msg string, objects interface{}) (r *JsonResult) {
- r = &JsonResult{Code: RetErr, Msg: msg, Data: objects}
- return
- }
- func GetCurUser(userId int64) *viewmodels.UserData{
- userData, err := cache.GetUserData(userId)
- if err != nil {
- log.Fatal(err.Error())
- }
- return userData
- }
|