作者 tangxvhui

新增

1 module gitlab.fjmaimaimai.com/mmm-go/partner 1 module gitlab.fjmaimaimai.com/mmm-go/partner
2 2
3 -go 1.13 3 +go 1.14
4 4
5 require ( 5 require (
6 github.com/ajg/form v1.5.1 // indirect 6 github.com/ajg/form v1.5.1 // indirect
7 github.com/astaxie/beego v1.12.1 7 github.com/astaxie/beego v1.12.1
  8 + github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
8 github.com/fatih/structs v1.1.0 // indirect 9 github.com/fatih/structs v1.1.0 // indirect
9 github.com/gavv/httpexpect v2.0.0+incompatible 10 github.com/gavv/httpexpect v2.0.0+incompatible
10 github.com/go-pg/pg/v10 v10.0.0-beta.2 11 github.com/go-pg/pg/v10 v10.0.0-beta.2
11 github.com/google/go-querystring v1.0.0 // indirect 12 github.com/google/go-querystring v1.0.0 // indirect
12 github.com/gorilla/websocket v1.4.2 // indirect 13 github.com/gorilla/websocket v1.4.2 // indirect
13 github.com/imkira/go-interpol v1.1.0 // indirect 14 github.com/imkira/go-interpol v1.1.0 // indirect
  15 + github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
14 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 16 github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
  17 + github.com/mattn/go-colorable v0.1.6 // indirect
15 github.com/moul/http2curl v1.0.0 // indirect 18 github.com/moul/http2curl v1.0.0 // indirect
16 github.com/onsi/ginkgo v1.10.3 19 github.com/onsi/ginkgo v1.10.3
17 github.com/onsi/gomega v1.7.1 20 github.com/onsi/gomega v1.7.1
18 github.com/sergi/go-diff v1.1.0 // indirect 21 github.com/sergi/go-diff v1.1.0 // indirect
19 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect 22 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
  23 + github.com/smartystreets/goconvey v1.6.4 // indirect
20 github.com/valyala/fasthttp v1.14.0 // indirect 24 github.com/valyala/fasthttp v1.14.0 // indirect
21 github.com/xeipuuv/gojsonschema v1.2.0 // indirect 25 github.com/xeipuuv/gojsonschema v1.2.0 // indirect
22 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect 26 github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
23 github.com/yudai/gojsondiff v1.0.0 // indirect 27 github.com/yudai/gojsondiff v1.0.0 // indirect
24 github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect 28 github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
  29 + github.com/yudai/pp v2.0.1+incompatible // indirect
25 ) 30 )
  31 +
  32 +replace gitlab.fjmaimaimai.com/mmm-go/partner => ../partner
  1 +package domain
  2 +
  3 +//权限代码
  4 +const (
  5 + PERMINSSION_ADMIN_USER string = "ADMIN_USER"
  6 + PERMINSSION_PARTNER string = "PARTNER"
  7 +)
  8 +
  9 +//权限数据
  10 +var ConstAdminPermissions = map[string]AdminPermission{
  11 + PERMINSSION_ADMIN_USER: AdminPermission{
  12 + Code: PERMINSSION_ADMIN_USER,
  13 + Name: "管理员管理",
  14 + },
  15 + PERMINSSION_PARTNER: AdminPermission{
  16 + Code: PERMINSSION_PARTNER,
  17 + Name: "合伙人管理",
  18 + },
  19 +}
  20 +
  21 +// 权限结构
  22 +type AdminPermission struct {
  23 + Code string `json:"code"`
  24 + Name string `json:"name"`
  25 +}
  26 +
  27 +func (permission AdminPermission) GetPermissions(codes []string) []AdminPermission {
  28 + newPermissions := []AdminPermission{}
  29 + if len(codes) == 0 {
  30 + return newPermissions
  31 + }
  32 + for i := range codes {
  33 + code := codes[i]
  34 + if _, ok := ConstAdminPermissions[code]; ok {
  35 + newPermissions = append(newPermissions, ConstAdminPermissions[code])
  36 + }
  37 + }
  38 + return newPermissions
  39 +}
  1 +package domain
  2 +
  3 +//AdminUser 管理员
  4 +type AdminUser struct {
  5 + //id
  6 + Id int64 `json:"id"`
  7 + //账号
  8 + Account string `json:"account"`
  9 + //密码
  10 + Password string `json:"password"`
  11 + //管理员名称
  12 + AdminName string `json:"admin_name"`
  13 + //是否是默认系统账号
  14 + IsDefault bool `json:"is_default"`
  15 + //创建时间
  16 + CreateAt string `json:"create_at"`
  17 + //用户权限
  18 + Permission []string `json:"permission"`
  19 +}
  20 +
  21 +type AdminUserFindQuery struct {
  22 + AccountLike string
  23 + Offset int
  24 + Limit int
  25 +}
  26 +
  27 +type AdminUserFindOneQuery struct {
  28 + AdminUserId int64
  29 + AccountEqual string
  30 +}
  31 +
  32 +type AdminUserRepository interface {
  33 + Save(*AdminUser) (*AdminUser, error)
  34 + Remove(user *AdminUser) (*AdminUser, error)
  35 + FindOne(qureyOptions AdminUserFindOneQuery) (*AdminUser, error)
  36 + Find(queryOptions AdminUserFindQuery) (int, []AdminUser, error)
  37 +}
  1 +package models
  2 +
  3 +import (
  4 + "context"
  5 + "time"
  6 +
  7 + "github.com/go-pg/pg/v10"
  8 +)
  9 +
  10 +type AdminUser struct {
  11 + tableName struct{} `pg:"admin_user"`
  12 + //id
  13 + Id int64 `pg:",pk"`
  14 + //用户账号
  15 + AdminAccount string `pg:",unique"`
  16 + //用户名称
  17 + AdminName string
  18 + //账号密码
  19 + Password string
  20 + //是否是默认账号
  21 + IsDefault bool `pg:",use_zero"`
  22 + //删除时间
  23 + DeleteAt int64
  24 + CreateAt time.Time
  25 + UpdateAt time.Time
  26 +}
  27 +
  28 +var _ pg.BeforeUpdateHook = (*AdminUser)(nil)
  29 +
  30 +func (user *AdminUser) BeforeUpdate(ctx context.Context) (context.Context, error) {
  31 + user.UpdateAt = time.Now()
  32 + return ctx, nil
  33 +}
  34 +
  35 +var _ pg.BeforeInsertHook = (*AdminUser)(nil)
  36 +
  37 +func (user *AdminUser) BeforeInsert(ctx context.Context) (context.Context, error) {
  38 + user.CreateAt = time.Now()
  39 + user.UpdateAt = time.Now()
  40 + user.DeleteAt = 0
  41 + return ctx, nil
  42 +}
1 package models 1 package models
2 2
3 import ( 3 import (
4 - "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"  
5 "time" 4 "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
6 ) 7 )
7 8
8 type PartnerInfo struct { 9 type PartnerInfo struct {
  1 +package middleware
  2 +
  3 +import (
  4 + "github.com/astaxie/beego/context"
  5 +)
  6 +
  7 +func PermissionCheck(permissionCode string, excludeUrl ...string) func(ctx *context.Context) {
  8 +
  9 + return func(ctx *context.Context) {
  10 + //根据code检查权限数据,并排除excludeUrl指定的url
  11 + }
  12 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/beego/middleware"
  7 +)
  8 +
  9 +func init() {
  10 + adminRouter := beego.NewNamespace("/admin_user",
  11 + //验证权限
  12 + beego.NSBefore(middleware.PermissionCheck(domain.PERMINSSION_ADMIN_USER)),
  13 + //其余的路由
  14 + //...
  15 + )
  16 + beego.AddNamespace(adminRouter)
  17 +}