Parcourir la source

update

master
dengbiao il y a 1 mois
Parent
révision
5189d42867
8 fichiers modifiés avec 246 ajouts et 2 suppressions
  1. +109
    -0
      app/hdl/hdl_comm.go
  2. +50
    -0
      app/lib/youlianghui/api.go
  3. +28
    -0
      app/lib/youlianghui/helpers.go
  4. +14
    -0
      app/lib/youlianghui/md/api_md.go
  5. +2
    -0
      app/md/app_redis_key.go
  6. +33
    -0
      app/mw/mw_admin_permission.go
  7. +9
    -1
      app/router/router.go
  8. +1
    -1
      go.mod

+ 109
- 0
app/hdl/hdl_comm.go Voir le fichier

@@ -0,0 +1,109 @@
package hdl

import (
"applet/app/e"
"applet/app/enum"
"applet/app/md"
"applet/app/svc"
"applet/app/utils"
db "code.fnuoos.com/zhimeng/model.git/src"
"code.fnuoos.com/zhimeng/model.git/src/implement"
"github.com/gin-gonic/gin"
)

func MenuList(c *gin.Context) {
masterId := svc.GetMasterId(c)
engine := db.DBs[masterId]
admin := svc.GetUser(c)
qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroupV2()
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}

// 1、查询出当前用户所有角色
adminRoleDb := implement.NewAdminRoleDb(engine)
roles, err := adminRoleDb.FindAdminRole(admin.AdmId)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}

roleDb := implement.NewRoleDb(engine, 0)
var adminHasPermissionGroupIds []string
for _, v := range *roles {
list, _, err1 := roleDb.FindPermissionGroupByRole(v.RoleId)
if err1 != nil {
e.OutErr(c, e.ERR_DB_ORM, err1.Error())
return
}
for _, v1 := range list {
adminHasPermissionGroupIds = append(adminHasPermissionGroupIds, utils.IntToStr(v1.PermissionGroup.Id))
}
}

var tempRespMap = map[string]*md.PermissionGroupListResp{}
var tempRespMapKeys []string
for _, v := range *groupList {

var isCheck bool
if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
isCheck = true
} else {
isCheck = false
}

if utils.InArr(utils.IntToStr(v.Id), adminHasPermissionGroupIds) {
isCheck = true
}

if v.State == enum.PermissionGroupStateForDiscard {
isCheck = false
}

tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
Id: v.Id,
Name: v.Name,
Key: v.Key,
State: v.State,
ParentId: v.ParentId,
CreateAt: v.CreateAt,
UpdateAt: v.UpdateAt,
IsCheck: isCheck,
}
tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
}
for _, v := range tempRespMap {
if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
}
}
for _, v := range tempRespMap {
if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
}
}

var resp []*md.PermissionGroupListResp
for _, v := range tempRespMapKeys {
if tempRespMap[v].ParentId == 0 {
resp = append(resp, tempRespMap[v])
}
}

e.OutSuc(c, map[string]interface{}{
"list": resp,
"state": []map[string]interface{}{
{
"name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
"value": enum.PermissionGroupStateForNormal,
},
{
"name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
"value": enum.PermissionGroupStateForDiscard,
},
},
}, nil)
return
}

+ 50
- 0
app/lib/youlianghui/api.go Voir le fichier

@@ -0,0 +1,50 @@
package youlianghui

import (
"applet/app/cfg"
)

type ApiService struct {
MemberId string `json:"member_id"`
Secret string `json:"secret"`
Host string `json:"host"`
}

func NewApiService(memberId, secret string) (apiService ApiService, err error) { // set方法
apiService.MemberId = memberId
apiService.Secret = secret
apiService.Host = "https://test-api.adnet.qq.com/open/v1.1"
if cfg.Prd {
apiService.Host = "http://api.adnet.qq.com/open/v1.1"
}

return
}

// MediumAdd 创建媒体
// func (apiService *ApiService) MediumAdd() (appId string, err error) { // set方法
// token := GetToken(apiService.MemberId, apiService.Secret)
// url := apiService.Host + "/medium/add"
// params := map[string]interface{}{
// "name": name,
// "type": string(adunitType),
// }
// if adunitType == enum.AdunitTypeForVideoFeeds {
// params["video_duration_min"] = 6
// params["video_duration_max"] = 60
// }
// postBody, err := utils.CurlPost(url, utils.SerializeStr(params), nil)
// if err != nil {
// return
// }
// var resp md.AgencyCreateAdunit
// err = json.Unmarshal(postBody, &resp)
// if err != nil {
// return
// }
// if resp.Ret != 0 {
// err = errors.New(resp.ErrMsg)
// }
// adUnitId = resp.AdUnitId
// return
// }

+ 28
- 0
app/lib/youlianghui/helpers.go Voir le fichier

@@ -0,0 +1,28 @@
package youlianghui

import (
"crypto/sha1"
"encoding/base64"
"fmt"
"strconv"
"strings"
"time"
)

// GetToken 获取token
func GetToken(memberId, secret string) (token string) {
timestamp := strconv.FormatInt(time.Now().Unix(), 10) // 时间戳,精确到秒
// 计算签名
hash := sha1.New()
hash.Write([]byte(memberId + secret + timestamp))
sign := fmt.Sprintf("%x", hash.Sum(nil))

// 构建列表
listV := []string{memberId, timestamp, sign}
plain := strings.Join(listV, ",")

// 编码为Base64
token = base64.StdEncoding.EncodeToString([]byte(plain))

return
}

+ 14
- 0
app/lib/youlianghui/md/api_md.go Voir le fichier

@@ -0,0 +1,14 @@
package md

type MediumAdd struct {
MediumName string `json:"medium_name" example:"媒体名字"`
IndustryIdV2 int `json:"industry_id_v2" example:"媒体所属新3级行业id"`
Os int `json:"os" example:"操作系统,数字含义1-Android, 2-iOS"`
DetailUrl string `json:"detail_url" example:"详情页url(支持的各个商店域名约束)"`
Affiliation string `json:"affiliation" example:"媒体隶属关系"`
PackageName string `json:"package_name" example:"主程序包名"`
FullPackageName string `json:"full_package_name" example:"完整的程序包名(当OS为Android时必填)"`
WechatAppId string `json:"wechat_app_id" example:"微信开放平台AppId(当OS为iOS时非必填)"`
PackageNameWxAppidRel string `json:"package_name_wx_appid_rel" example:"当OS为Android时选填,例如:{"com.xx.xx":"wx9b1xxx3449f","com.xx.xx.xx":"wx9b1xxx3xxx9x"}"`
WechatUniversalLink string `json:"wechat_universal_link" example:"微信开放平台Universal link"`
}

+ 2
- 0
app/md/app_redis_key.go Voir le fichier

@@ -13,4 +13,6 @@ const (
KEY_SYS_CFG_CACHE = "sys_cfg_cache"

CfgCacheTime = 86400

AdminRolePermissionKey = "%s:advertisement_admin_role_permission:%s" // 占位符:ip, admin:id
)

+ 33
- 0
app/mw/mw_admin_permission.go Voir le fichier

@@ -0,0 +1,33 @@
package mw

import (
"applet/app/e"
"applet/app/enum"
"applet/app/md"
"applet/app/svc"
"applet/app/utils"
"fmt"
"github.com/gin-gonic/gin"
)

// CheckPermission 检查权限
func CheckPermission(c *gin.Context) {
admin := svc.GetUser(c)
masterId := svc.GetMasterId(c)
// TODO::判断是否为超管
if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
c.Next()
} else {
rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, masterId, utils.AnyToString(admin.AdmId))
isHasPermission, err := svc.CheckUserRole(c, rolePermissionKey, c.Request.RequestURI, admin.AdmId)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
if !isHasPermission {
e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员")
return
}
c.Next()
}
}

+ 9
- 1
app/router/router.go Voir le fichier

@@ -67,7 +67,10 @@ func route(r *gin.RouterGroup) {
r.POST("/registerForMedium", hdl.RegisterForMedium)
r.POST("/registerForAgent", hdl.RegisterForAgent)

r.Use(mw.Auth) // 以下接口需要JWT验证
r.Use(mw.Auth) // 以下接口需要JWT验证
rComm(r.Group("/comm"))

r.Use(mw.CheckPermission) // 检测权限
rRole(r.Group("/role")) // 权限管理
rQualification(r.Group("/qualification")) // 资质认证公共数据
rAgentQualification(r.Group("/agentQualification")) // 渠道-资质
@@ -81,6 +84,11 @@ func route(r *gin.RouterGroup) {
rIndex(r.Group("/index")) // 首页
rFinancialDynamics(r.Group("/financialDynamics")) // 资产动态
}

func rComm(r *gin.RouterGroup) {
r.POST("/getMenuList", hdl.MenuList) // 获取菜单栏列表
}

func rIndex(r *gin.RouterGroup) {
r.GET("/base", hdl.Base) // 首页-基本信息
r.GET("/total", hdl.IndexTotal) // 首页-统计数据


+ 1
- 1
go.mod Voir le fichier

@@ -36,11 +36,11 @@ require (
require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240830072333-a1980ffb256e
code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240930064359-f120af0d8ade
github.com/jinzhu/copier v0.4.0
)

require (
code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240930064359-f120af0d8ade // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect


Chargement…
Annuler
Enregistrer