新增门店 ip配置

This commit is contained in:
chy
2025-06-24 10:36:39 +08:00
parent 3166edc3dd
commit ea574905f9
14 changed files with 446 additions and 2 deletions

View File

@ -15,4 +15,8 @@ type IStoreV1 interface {
Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error)
Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error)
Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error)
AddIp(ctx context.Context, req *v1.AddIpReq) (res *v1.AddIpRes, err error)
DeleteIp(ctx context.Context, req *v1.DeleteIpReq) (res *v1.DeleteIpRes, err error)
UpdateIp(ctx context.Context, req *v1.UpdateIpReq) (res *v1.UpdateIpRes, err error)
GetIpList(ctx context.Context, req *v1.GetIpListReq) (res *v1.GetIpListRes, err error)
} }

View File

@ -42,3 +42,47 @@ type DeleteReq struct {
type DeleteRes struct { type DeleteRes struct {
Success bool `json:"success" dc:"是否成功"` Success bool `json:"success" dc:"是否成功"`
} }
type AddIpReq struct {
g.Meta `path:"/store/addIp" method:"post" tags:"Store" summary:"(系统、商户门店后台)添加门店IP"`
StoreId int64 `json:"storeId" v:"required" dc:"门店ID"`
Ip string `json:"ip" v:"required" dc:"IP"`
Remark string `json:"remark" dc:"备注"`
}
type AddIpRes struct {
Success bool `json:"success" dc:"是否成功"`
}
type DeleteIpReq struct {
g.Meta `path:"/store/del/{id}" method:"delete" tags:"Store" summary:"(系统、商户门店后台)删除门店IP"`
Id int64 `json:"id" v:"required" dc:"id"`
}
type DeleteIpRes struct {
Success bool `json:"success" dc:"是否成功"`
}
type UpdateIpReq struct {
g.Meta `path:"/store/updateIp" method:"put" tags:"Store" summary:"(系统、商户门店后台)更新门店IP"`
Id int64 `json:"id" v:"required" dc:"id"`
//StoreId int64 `json:"storeId" v:"required" dc:"storeId"`
Ip string `json:"ip" v:"required" dc:"IP"`
Remark string `json:"remark" dc:"备注"`
}
type UpdateIpRes struct {
Success bool `json:"success" dc:"是否成功"`
}
type GetIpListReq struct {
g.Meta `path:"/store/getIpList" method:"get" tags:"Store" summary:"(系统、商户门店后台)获取门店IP列表"`
StoreId int64 `json:"storeId" dc:"门店ID"`
Page int `json:"page" v:"required" dc:"页数"`
Size int `json:"size" v:"required" dc:"每页数量"`
}
type GetIpListRes struct {
List interface{} `json:"list" dc:"IP列表"`
Total int64 `json:"total" dc:"总数"`
}

View File

@ -0,0 +1,23 @@
package store
import (
"context"
"server/internal/model"
"server/internal/service"
"server/api/store/v1"
)
func (c *ControllerV1) AddIp(ctx context.Context, req *v1.AddIpReq) (res *v1.AddIpRes, err error) {
out, err := service.Store().CreateIP(ctx, &model.IPCreateIn{
Ip: req.Ip,
Remark: req.Remark,
StoreId: int(req.StoreId),
})
if err != nil {
return nil, err
}
return &v1.AddIpRes{Success: out.Success}, nil
}

View File

@ -0,0 +1,20 @@
package store
import (
"context"
"server/internal/model"
"server/internal/service"
"server/api/store/v1"
)
func (c *ControllerV1) DeleteIp(ctx context.Context, req *v1.DeleteIpReq) (res *v1.DeleteIpRes, err error) {
out, err := service.Store().DeleteIP(ctx, &model.IPDeleteIn{
Id: req.Id,
})
if err != nil {
return nil, err
}
return &v1.DeleteIpRes{Success: out.Success}, nil
}

View File

@ -0,0 +1,25 @@
package store
import (
"context"
"server/internal/model"
"server/internal/service"
"server/api/store/v1"
)
func (c *ControllerV1) GetIpList(ctx context.Context, req *v1.GetIpListReq) (res *v1.GetIpListRes, err error) {
list, err := service.Store().GetIPList(ctx, &model.IPListIn{
Page: req.Page,
Size: req.Size,
StoreId: req.StoreId,
})
if err != nil {
return nil, err
}
return &v1.GetIpListRes{
List: list.List,
Total: list.Total,
}, nil
}

View File

@ -0,0 +1,22 @@
package store
import (
"context"
"server/internal/model"
"server/internal/service"
"server/api/store/v1"
)
func (c *ControllerV1) UpdateIp(ctx context.Context, req *v1.UpdateIpReq) (res *v1.UpdateIpRes, err error) {
out, err := service.Store().UpdateIP(ctx, &model.IPUpdateIn{
Id: req.Id,
Ip: req.Ip,
Remark: req.Remark,
//StoreId: int(req.StoreId),
})
if err != nil {
return nil, err
}
return &v1.UpdateIpRes{Success: out.Success}, nil
}

View File

@ -0,0 +1,91 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// StoreIpsDao is the data access object for the table store_ips.
type StoreIpsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns StoreIpsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// StoreIpsColumns defines and stores column names for the table store_ips.
type StoreIpsColumns struct {
Id string // 主键ID
StoreId string // 关联门店ID
IpAddress string // IP地址支持IPv4或IPv6
Remark string // 备注
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间戳
}
// storeIpsColumns holds the columns for the table store_ips.
var storeIpsColumns = StoreIpsColumns{
Id: "id",
StoreId: "store_id",
IpAddress: "ip_address",
Remark: "remark",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// NewStoreIpsDao creates and returns a new DAO object for table data access.
func NewStoreIpsDao(handlers ...gdb.ModelHandler) *StoreIpsDao {
return &StoreIpsDao{
group: "default",
table: "store_ips",
columns: storeIpsColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *StoreIpsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *StoreIpsDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *StoreIpsDao) Columns() StoreIpsColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *StoreIpsDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreIpsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *StoreIpsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

22
internal/dao/store_ips.go Normal file
View File

@ -0,0 +1,22 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"server/internal/dao/internal"
)
// storeIpsDao is the data access object for the table store_ips.
// You can define custom methods on it to extend its functionality as needed.
type storeIpsDao struct {
*internal.StoreIpsDao
}
var (
// StoreIps is a globally accessible object for table store_ips operations.
StoreIps = storeIpsDao{internal.NewStoreIpsDao()}
)
// Add your custom methods and functionality below.

View File

@ -173,3 +173,93 @@ func (s *sStore) GetDesktopSetting(ctx context.Context, in *model.StoreGetDeskto
return out, nil return out, nil
} }
func (s *sStore) GetIPList(ctx context.Context, in *model.IPListIn) (*model.IPListout, error) {
m := dao.StoreIps.Ctx(ctx)
if in.StoreId > 0 {
m = m.Where(do.StoreIps{
StoreId: in.StoreId,
})
}
var list []model.StoreIps
var total int
err := m.Page(in.Page, in.Size).ScanAndCount(&list, &total, false)
if err != nil {
return nil, ecode.Fail.Sub("IP列表获取失败")
}
return &model.IPListout{
List: list,
Total: int64(total),
}, nil
}
func (s *sStore) CreateIP(ctx context.Context, in *model.IPCreateIn) (*model.IPCreateOut, error) {
exist, err := dao.StoreIps.Ctx(ctx).Where(do.StoreIps{StoreId: in.StoreId, IpAddress: in.Ip}).Exist()
if err != nil {
return nil, ecode.Fail.Sub("门店IP创建失败")
}
if exist {
return nil, ecode.Params.Sub("门店IP已存在")
}
_, err = dao.StoreIps.Ctx(ctx).Insert(do.StoreIps{
IpAddress: in.Ip,
Remark: in.Remark,
StoreId: in.StoreId,
})
if err != nil {
return nil, ecode.Fail.Sub("门店IP创建失败")
}
return &model.IPCreateOut{
Success: true,
}, nil
}
func (s *sStore) UpdateIP(ctx context.Context, in *model.IPUpdateIn) (*model.IPUpdateOut, error) {
//exist, err := dao.StoreIps.Ctx(ctx).Where(do.StoreIps{StoreId: in.StoreId, IpAddress: in.Ip}).Exist()
//
//if err != nil {
// return nil, ecode.Fail.Sub("门店IP更新失败")
//}
//
//if exist {
// return nil, ecode.Params.Sub("门店IP已存在")
//}
_, err := dao.StoreIps.Ctx(ctx).Where(do.StoreIps{Id: in.Id}).Data(do.StoreIps{IpAddress: in.Ip, Remark: in.Remark}).Update()
if err != nil {
return nil, ecode.Fail.Sub("门店IP更新失败")
}
return &model.IPUpdateOut{
Success: true,
}, nil
}
func (s *sStore) DeleteIP(ctx context.Context, in *model.IPDeleteIn) (*model.IPDeleteOut, error) {
exist, err := dao.StoreIps.Ctx(ctx).Where(do.StoreIps{Id: in.Id}).Exist()
if err != nil {
return nil, ecode.Fail.Sub("门店IP查询失败")
}
if !exist {
return nil, ecode.Params.Sub("门店不已存在")
}
_, err = dao.StoreIps.Ctx(ctx).Where(do.StoreIps{Id: in.Id}).Delete()
if err != nil {
return nil, ecode.Fail.Sub("删除门店IP失败")
}
return &model.IPDeleteOut{
Success: true,
}, nil
}

View File

@ -0,0 +1,22 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// StoreIps is the golang structure of table store_ips for DAO operations like Where/Data.
type StoreIps struct {
g.Meta `orm:"table:store_ips, do:true"`
Id interface{} // 主键ID
StoreId interface{} // 关联门店ID
IpAddress interface{} // IP地址支持IPv4或IPv6
Remark interface{} // 备注
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间戳
}

View File

@ -0,0 +1,20 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// StoreIps is the golang structure for table store_ips.
type StoreIps struct {
Id int64 `json:"id" orm:"id" description:"主键ID"` // 主键ID
StoreId int64 `json:"storeId" orm:"store_id" description:"关联门店ID"` // 关联门店ID
IpAddress string `json:"ipAddress" orm:"ip_address" description:"IP地址支持IPv4或IPv6"` // IP地址支持IPv4或IPv6
Remark string `json:"remark" orm:"remark" description:"备注"` // 备注
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳
}

View File

@ -2,6 +2,7 @@ package model
import ( import (
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
) )
type Store struct { type Store struct {
@ -17,6 +18,16 @@ type Store struct {
NetbarAccount string `json:"netbarAccount" orm:"netbar_account" dc:"网吧网关账号"` NetbarAccount string `json:"netbarAccount" orm:"netbar_account" dc:"网吧网关账号"`
} }
type StoreIps struct {
Id int64 `json:"id" orm:"id" description:"主键ID"` // 主键ID
StoreId int64 `json:"storeId" orm:"store_id" description:"关联门店ID"` // 关联门店ID
IpAddress string `json:"ipAddress" orm:"ip_address" description:"IP地址支持IPv4或IPv6"` // IP地址支持IPv4或IPv6
Remark string `json:"remark" orm:"remark" description:"备注"` // 备注
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳
}
type StoreCreateIn struct { type StoreCreateIn struct {
OperatorId int64 OperatorId int64
OperatorRole string OperatorRole string
@ -59,3 +70,43 @@ type StoreDeleteIn struct {
OperatorId int OperatorId int
OperatorRole string OperatorRole string
} }
type IPListIn struct {
StoreId int64 `json:"storeId" dc:"IP列表ID"`
Page int `json:"page"`
Size int `json:"size"`
}
type IPListout struct {
List interface{} `json:"list"`
Total int64 `json:"total"`
}
type IPUpdateIn struct {
Id int64 `json:"id" dc:"IP列表ID"`
Ip string `json:"ip" dc:"IP地址"`
StoreId int `json:"storeId" dc:"门店ID"`
Remark string `json:"remark" dc:"备注"`
}
type IPUpdateOut struct {
Success bool `json:"success"`
}
type IPDeleteIn struct {
Id int64
}
type IPDeleteOut struct {
Success bool `json:"success"`
}
type IPCreateIn struct {
Ip string `json:"ip" dc:"IP地址"`
StoreId int `json:"storeId" dc:"门店ID"`
Remark string `json:"remark" dc:"备注"`
}
type IPCreateOut struct {
Success bool `json:"success"`
}

View File

@ -18,6 +18,10 @@ type (
Delete(ctx context.Context, in *model.StoreDeleteIn) (out *model.DeleteOut, err error) Delete(ctx context.Context, in *model.StoreDeleteIn) (out *model.DeleteOut, err error)
Info(ctx context.Context, in *model.StoreInfoIn) (out *model.StoreInfoOut, err error) Info(ctx context.Context, in *model.StoreInfoIn) (out *model.StoreInfoOut, err error)
GetDesktopSetting(ctx context.Context, in *model.StoreGetDesktopSettingIn) (*model.StoreGetDesktopSettingOut, error) GetDesktopSetting(ctx context.Context, in *model.StoreGetDesktopSettingIn) (*model.StoreGetDesktopSettingOut, error)
GetIPList(ctx context.Context, in *model.IPListIn) (*model.IPListout, error)
CreateIP(ctx context.Context, in *model.IPCreateIn) (*model.IPCreateOut, error)
UpdateIP(ctx context.Context, in *model.IPUpdateIn) (*model.IPUpdateOut, error)
DeleteIP(ctx context.Context, in *model.IPDeleteIn) (*model.IPDeleteOut, error)
} }
) )

View File

@ -43,7 +43,7 @@ func init() {
// 任务 // 任务
enforcer.AddPolicy("guest", "/x/task/ranking", "GET", "获取排行榜") enforcer.AddPolicy("guest", "/x/task/ranking", "GET", "获取排行榜")
enforcer.AddPolicy("guest", "/x/task/getNonLoginTaskList", "GET", "未登录获取任务列表") enforcer.AddPolicy("guest", "/x/task/getNonLoginTaskList", "GET", "未登录获取任务列表")
enforcer.AddPolicy("guest", "/x/reward/callback", "POST", "") enforcer.AddPolicy("guest", "/x/reward/callback", "POST", "tencent回调")
// 游戏列表 // 游戏列表
enforcer.AddPolicy("guest", "/x/game", "GET", "获取游戏列表") enforcer.AddPolicy("guest", "/x/game", "GET", "获取游戏列表")
@ -127,6 +127,12 @@ func init() {
enforcer.AddPolicy("guest", "/x/task/completed/list", "GET", "获取游戏列表") enforcer.AddPolicy("guest", "/x/task/completed/list", "GET", "获取游戏列表")
// 获取门店 ip信息
enforcer.AddPolicy("store", "/x/store/getIpList", "GET", "获取门店 ip信息列表")
enforcer.AddPolicy("store", "/x/store/addIp", "POST", "添加ip信息")
enforcer.AddPolicy("store", "/x/store/del/*", "DELETE", "删除门店 ip信息")
enforcer.AddPolicy("store", "/x/store/updateIp", "PUT", "修改门店 ip信息")
} }
// 商户 // 商户
{ {
@ -159,7 +165,7 @@ func init() {
enforcer.AddPolicy("admin", "/x/task/selector", "GET", "管理员获取任务列表二级选择器") enforcer.AddPolicy("admin", "/x/task/selector", "GET", "管理员获取任务列表二级选择器")
// 用户:删除 // 用户:删除
enforcer.AddPolicy("admin", "/x/user/del/{id}", "DELETE", "删除用户") enforcer.AddPolicy("admin", "/x/user/del/*", "DELETE", "删除用户")
} }
instance = &myCasbin{Enforcer: enforcer} instance = &myCasbin{Enforcer: enforcer}