From 853ee2190a4d4796a6a7eb9d28a35c6a3c94c923 Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Wed, 25 Jun 2025 19:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/statistic/statistic.go | 15 ++++++++++ api/statistic/v1/statistic.go | 11 +++++++ api/store/store.go | 1 + api/store/v1/store.go | 7 +++++ api/task/v1/task.go | 22 +++++++------- internal/cmd/cmd.go | 2 ++ internal/consts/redis.go | 5 ++++ internal/controller/statistic/statistic.go | 5 ++++ .../controller/statistic/statistic_new.go | 15 ++++++++++ .../statistic_v1_get_online_device.go | 15 ++++++++++ internal/controller/store/store_v1_detail.go | 17 +++++++++++ internal/controller/task/task_v1_get_task.go | 11 +++---- internal/controller/task/task_v1_ranking.go | 11 +++---- internal/logic/store/store.go | 13 ++++++++ .../storeDesktopSetting.go | 15 ++++++---- internal/logic/task/task.go | 30 +++++++++++++++++-- internal/model/store.go | 6 ++++ internal/model/userTask.go | 22 +++++++------- internal/packed/packed.go | 2 +- internal/service/reward.go | 1 + internal/service/store.go | 1 + utility/myCasbin/casbin.go | 2 ++ 22 files changed, 189 insertions(+), 40 deletions(-) create mode 100644 api/statistic/statistic.go create mode 100644 api/statistic/v1/statistic.go create mode 100644 internal/controller/statistic/statistic.go create mode 100644 internal/controller/statistic/statistic_new.go create mode 100644 internal/controller/statistic/statistic_v1_get_online_device.go create mode 100644 internal/controller/store/store_v1_detail.go diff --git a/api/statistic/statistic.go b/api/statistic/statistic.go new file mode 100644 index 0000000..5b9cbb3 --- /dev/null +++ b/api/statistic/statistic.go @@ -0,0 +1,15 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package statistic + +import ( + "context" + + "server/api/statistic/v1" +) + +type IStatisticV1 interface { + GetOnlineDevice(ctx context.Context, req *v1.GetOnlineDeviceReq) (res *v1.GetOnlineDeviceRes, err error) +} diff --git a/api/statistic/v1/statistic.go b/api/statistic/v1/statistic.go new file mode 100644 index 0000000..52e0e2c --- /dev/null +++ b/api/statistic/v1/statistic.go @@ -0,0 +1,11 @@ +package v1 + +import "github.com/gogf/gf/v2/frame/g" + +type GetOnlineDeviceReq struct { + g.Meta `path:"/statistic/onlineDevice" method:"get" tags:"Statistic" summary:"获取门店设备在线列表"` + NetbarAccount string `json:"netbarAccount" v:"required#网吧网关账号不能为空" dc:"网吧网关账号"` +} +type GetOnlineDeviceRes struct { + Total int64 `json:"total"` +} diff --git a/api/store/store.go b/api/store/store.go index 1e57984..5ca3005 100644 --- a/api/store/store.go +++ b/api/store/store.go @@ -19,4 +19,5 @@ type IStoreV1 interface { 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) + Detail(ctx context.Context, req *v1.DetailReq) (res *v1.DetailRes, err error) } diff --git a/api/store/v1/store.go b/api/store/v1/store.go index 0757355..a5e1582 100644 --- a/api/store/v1/store.go +++ b/api/store/v1/store.go @@ -86,3 +86,10 @@ type GetIpListRes struct { List interface{} `json:"list" dc:"IP列表"` Total int64 `json:"total" dc:"总数"` } +type DetailReq struct { + g.Meta `path:"/store/detail" method:"get" tags:"Store" summary:"(系统、商户门店后台)门店详情"` + NetbarAccount string `json:"netbarAccount" v:"required" dc:"门店账号"` +} +type DetailRes struct { + Id int64 `json:"id" dc:"门店ID"` +} diff --git a/api/task/v1/task.go b/api/task/v1/task.go index c9edb7f..811afc4 100644 --- a/api/task/v1/task.go +++ b/api/task/v1/task.go @@ -3,11 +3,12 @@ package v1 import "github.com/gogf/gf/v2/frame/g" type RankingReq struct { - g.Meta `path:"/task/ranking" method:"get" tags:"Task" summary:"(PC)任务排行榜"` - StoreId int `json:"storeId" v:"required#请选择店铺" dc:"门店id"` - Page int `json:"page" dc:"页数"` - Size int `json:"size" dc:"条数"` - Type int `json:"type" v:"required#请选择排行榜类型" dc:"排行榜类型"` + g.Meta `path:"/task/ranking" method:"get" tags:"Task" summary:"(PC)任务排行榜"` + StoreId int `json:"storeId" dc:"门店id"` + NetBarAccount string `json:"netBarAccount" dc:"网关账号"` + Page int `json:"page" dc:"页数"` + Size int `json:"size" dc:"条数"` + Type int `json:"type" v:"required#请选择排行榜类型" dc:"排行榜类型"` } type RankingRes struct { @@ -73,11 +74,12 @@ type SelectorRes struct { // GetTaskReq 添加任务记录 type GetTaskReq struct { - g.Meta `path:"/task/get" method:"post" tags:"Task" summary:"(PC)任务领取"` - TaskId int `json:"taskId" v:"required#任务id不能为空" dc:"任务id"` - StoreId int `json:"storeId" v:"required#门店 id不能为空" dc:"门店 id"` - GameId int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"` - TaskName string `json:"taskName" v:"required#任务名称不能为空" dc:"任务名称"` + g.Meta `path:"/task/get" method:"post" tags:"Task" summary:"(PC)任务领取"` + TaskId int `json:"taskId" v:"required#任务id不能为空" dc:"任务id"` + StoreId int `json:"storeId" dc:"门店 id、网关账号必传一个"` + NetBarAccount string `json:"netBarAccount" dc:"门店 id、网关账号必传一个"` + GameId int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"` + TaskName string `json:"taskName" v:"required#任务名称不能为空" dc:"任务名称"` } type GetTaskRes struct { diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index ef0cf99..305eba5 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -15,6 +15,7 @@ import ( "server/internal/controller/reward" "server/internal/controller/rewardType" "server/internal/controller/role" + "server/internal/controller/statistic" "server/internal/controller/store" "server/internal/controller/storeAdmin" "server/internal/controller/storeRole" @@ -58,6 +59,7 @@ var ( rewardType.NewV1(), reward.NewV1(), desktop.NewV1(), + statistic.NewV1(), ) }) }) diff --git a/internal/consts/redis.go b/internal/consts/redis.go index 16973b9..2ef0834 100644 --- a/internal/consts/redis.go +++ b/internal/consts/redis.go @@ -20,3 +20,8 @@ const ( const ( WechatAccessTokenKey = "wechat:access_token" ) + +const ( + NetbarOnlineNumberKey = "%s:online:device:%s" + NetbarOnlineDeviceSetKey = "%s:online_devices" +) diff --git a/internal/controller/statistic/statistic.go b/internal/controller/statistic/statistic.go new file mode 100644 index 0000000..afd7c37 --- /dev/null +++ b/internal/controller/statistic/statistic.go @@ -0,0 +1,5 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package statistic diff --git a/internal/controller/statistic/statistic_new.go b/internal/controller/statistic/statistic_new.go new file mode 100644 index 0000000..97eeb8e --- /dev/null +++ b/internal/controller/statistic/statistic_new.go @@ -0,0 +1,15 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package statistic + +import ( + "server/api/statistic" +) + +type ControllerV1 struct{} + +func NewV1() statistic.IStatisticV1 { + return &ControllerV1{} +} diff --git a/internal/controller/statistic/statistic_v1_get_online_device.go b/internal/controller/statistic/statistic_v1_get_online_device.go new file mode 100644 index 0000000..adbbf6e --- /dev/null +++ b/internal/controller/statistic/statistic_v1_get_online_device.go @@ -0,0 +1,15 @@ +package statistic + +import ( + "context" + "fmt" + "github.com/gogf/gf/v2/frame/g" + "server/internal/consts" + + "server/api/statistic/v1" +) + +func (c *ControllerV1) GetOnlineDevice(ctx context.Context, req *v1.GetOnlineDeviceReq) (res *v1.GetOnlineDeviceRes, err error) { + card, err := g.Redis().SCard(ctx, fmt.Sprintf(consts.NetbarOnlineDeviceSetKey, req.NetbarAccount)) + return &v1.GetOnlineDeviceRes{Total: card}, err +} diff --git a/internal/controller/store/store_v1_detail.go b/internal/controller/store/store_v1_detail.go new file mode 100644 index 0000000..321aa29 --- /dev/null +++ b/internal/controller/store/store_v1_detail.go @@ -0,0 +1,17 @@ +package store + +import ( + "context" + "server/internal/model" + "server/internal/service" + + "server/api/store/v1" +) + +func (c *ControllerV1) Detail(ctx context.Context, req *v1.DetailReq) (res *v1.DetailRes, err error) { + out, err := service.Store().Detail(ctx, &model.StoreDetailIn{NetbarAccount: req.NetbarAccount}) + if err != nil { + return nil, err + } + return &v1.DetailRes{Id: out.Id}, nil +} diff --git a/internal/controller/task/task_v1_get_task.go b/internal/controller/task/task_v1_get_task.go index 5a30cab..2c4092d 100644 --- a/internal/controller/task/task_v1_get_task.go +++ b/internal/controller/task/task_v1_get_task.go @@ -13,11 +13,12 @@ func (c *ControllerV1) GetTask(ctx context.Context, req *v1.GetTaskReq) (res *v1 userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int() out, err := service.Task().GetTask(ctx, &model.GetTaskIn{ - TaskId: req.TaskId, - StoreId: req.StoreId, - UserId: userId, - GameId: req.GameId, - TaskName: req.TaskName, + TaskId: req.TaskId, + StoreId: req.StoreId, + NetBarAccount: req.NetBarAccount, + UserId: userId, + GameId: req.GameId, + TaskName: req.TaskName, }) if err != nil { return nil, err diff --git a/internal/controller/task/task_v1_ranking.go b/internal/controller/task/task_v1_ranking.go index f8cb751..24cab02 100644 --- a/internal/controller/task/task_v1_ranking.go +++ b/internal/controller/task/task_v1_ranking.go @@ -13,11 +13,12 @@ func (c *ControllerV1) Ranking(ctx context.Context, req *v1.RankingReq) (res *v1 //operatorId := g.RequestFromCtx(ctx).GetCtxVar("id").Int() operatorId := 4 out, err := service.Task().UserTaskRankingList(ctx, &model.UserTaskRankingIn{ - Page: req.Page, - Size: req.Size, - StoreId: req.StoreId, - Type: req.Type, - OperatorId: operatorId, + Page: req.Page, + Size: req.Size, + StoreId: req.StoreId, + NetBarAccount: req.NetBarAccount, + Type: req.Type, + OperatorId: operatorId, }) if err != nil { diff --git a/internal/logic/store/store.go b/internal/logic/store/store.go index 4c8a9ad..6303050 100644 --- a/internal/logic/store/store.go +++ b/internal/logic/store/store.go @@ -263,3 +263,16 @@ func (s *sStore) DeleteIP(ctx context.Context, in *model.IPDeleteIn) (*model.IPD Success: true, }, nil } + +func (s *sStore) Detail(ctx context.Context, in *model.StoreDetailIn) (out *model.StoreDetailOut, err error) { + one, err := dao.Stores.Ctx(ctx).Where(do.Stores{NetbarAccount: in.NetbarAccount}).One() + if err != nil { + return nil, ecode.Fail.Sub("查询门店出现异常") + } + if one.IsEmpty() { + return nil, ecode.Params.Sub("门店不存在") + } + return &model.StoreDetailOut{ + Id: one[dao.Stores.Columns().Id].Int64(), + }, nil +} diff --git a/internal/logic/storeDesktopSetting/storeDesktopSetting.go b/internal/logic/storeDesktopSetting/storeDesktopSetting.go index db4e4c6..9a3a444 100644 --- a/internal/logic/storeDesktopSetting/storeDesktopSetting.go +++ b/internal/logic/storeDesktopSetting/storeDesktopSetting.go @@ -13,10 +13,17 @@ import ( ) type sStoreDesktopSetting struct { + mqttCLient mqtt.MqttClient } func New() service.IStoreDesktopSetting { - return &sStoreDesktopSetting{} + client, b := mqtt.GetClient("emqx") + if !b { + return nil + } + return &sStoreDesktopSetting{ + mqttCLient: client, + } } func init() { service.RegisterStoreDesktopSetting(New()) @@ -63,15 +70,11 @@ func (s *sStoreDesktopSetting) Save(ctx context.Context, in model.SaveDesktopSet if err != nil { return nil, err } - client, b := mqtt.GetClient("emqx") - if !b { - return nil, gerror.New("获取MQTT客户端失败") - } marshal, err := json.Marshal(in) if err != nil { return nil, err } - err = client.Publish(fmt.Sprintf("/desktop/%d", in.StoreId), marshal) + err = s.mqttCLient.Publish(fmt.Sprintf("/desktop/%d", in.StoreId), marshal) if err != nil { return nil, err } diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go index 6ec29e8..e757e1f 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -76,6 +76,17 @@ func (s *sTask) UserTaskRankingList(ctx context.Context, in *model.UserTaskRanki if in.StoreId > 0 { m = m.Where(dao.UserTasks.Columns().StoreId, in.StoreId) + } else if in.NetBarAccount != "" && in.StoreId <= 0 { + value, err := dao.Stores.Ctx(ctx).Where(dao.Stores.Columns().NetbarAccount, in.NetBarAccount).Fields(dao.Stores.Columns().Id).Value() + if err != nil { + return nil, ecode.Fail.Sub("查询门店ID失败") + } + if value.IsEmpty() { + return nil, ecode.Fail.Sub("门店不存在") + } + + m = m.Where(dao.UserTasks.Columns().StoreId, value.Int()) + } list := make([]model.UserTaskRankingArgs, 0) @@ -302,9 +313,22 @@ func (s *sTask) GetSelectorList(ctx context.Context, in *model.SelectorIn) (out // GetTask 完成任务 func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.GetTaskOut, err error) { - + var storeId int + if in.StoreId > 0 { + storeId = in.StoreId + } else if in.NetBarAccount != "" && in.StoreId <= 0 { + value, err := dao.Stores.Ctx(ctx).Where(do.Stores{NetbarAccount: in.NetBarAccount}).Fields(dao.Stores.Columns().Id).Value() + if err != nil { + return nil, ecode.Fail.Sub("获取门店ID异常") + } + if value.IsEmpty() { + return nil, ecode.Fail.Sub("获取门店ID异常") + } + storeId = value.Int() + } var userTask []*model.UserTask - err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: in.StoreId, GameId: in.GameId}).WhereNot("status", 3).Scan(&userTask) + + err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).WhereNot("status", 3).Scan(&userTask) if err != nil { return nil, ecode.Fail.Sub("查询用户该任务记录失败") } @@ -323,7 +347,7 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge _, err = dao.UserTasks.Ctx(ctx).Insert(do.UserTasks{ UserId: in.UserId, TaskId: in.TaskId, - StoreId: in.StoreId, + StoreId: storeId, Status: 1, SerialNumber: serialNumber, TaskName: in.TaskName, diff --git a/internal/model/store.go b/internal/model/store.go index d03c9d7..fcc9ab0 100644 --- a/internal/model/store.go +++ b/internal/model/store.go @@ -110,3 +110,9 @@ type IPCreateIn struct { type IPCreateOut struct { Success bool `json:"success"` } +type StoreDetailIn struct { + NetbarAccount string +} +type StoreDetailOut struct { + Id int64 `json:"id"` +} diff --git a/internal/model/userTask.go b/internal/model/userTask.go index f20a479..b2cd648 100644 --- a/internal/model/userTask.go +++ b/internal/model/userTask.go @@ -26,11 +26,12 @@ type UserTask struct { // UserTaskRankingIn 任务排行榜入参 type UserTaskRankingIn struct { - Page int - Size int - StoreId int - Type int // 排行榜类型 1:日 2:周 3:月 - OperatorId int + Page int + Size int + StoreId int + NetBarAccount string + Type int // 排行榜类型 1:日 2:周 3:月 + OperatorId int } // UserTaskRankingOut 用户排行榜出参 @@ -58,11 +59,12 @@ type LoginUserRankingNum struct { // GetTaskIn 添加任务记录入参 type GetTaskIn struct { - TaskId int `json:"taskId"` - StoreId int `json:"storeId"` - UserId int `json:"userId"` - TaskName string `json:"taskName"` - GameId int `json:"gid"` + TaskId int `json:"taskId"` + StoreId int `json:"storeId"` + NetBarAccount string `json:"netBarAccount"` + UserId int `json:"userId"` + TaskName string `json:"taskName"` + GameId int `json:"gid"` } type GetTaskOut struct { diff --git a/internal/packed/packed.go b/internal/packed/packed.go index e61b667..d483800 100644 --- a/internal/packed/packed.go +++ b/internal/packed/packed.go @@ -4,7 +4,7 @@ import ( _ "github.com/gogf/gf/contrib/drivers/mysql/v2" _ "github.com/gogf/gf/contrib/nosql/redis/v2" _ "server/utility/gamelife" - //_ "server/utility/mqtt/emqx" + _ "server/utility/mqtt/emqx" _ "server/utility/myCasbin" _ "server/utility/oss/aliyun" _ "server/utility/rsa" diff --git a/internal/service/reward.go b/internal/service/reward.go index 76d8523..85e0ccb 100644 --- a/internal/service/reward.go +++ b/internal/service/reward.go @@ -18,6 +18,7 @@ type ( Update(ctx context.Context, in *model.RewardUpdateIn) (out *model.RewardUpdateOut, err error) // Delete 删除奖励 Delete(ctx context.Context, in *model.RewardDeleteIn) (out *model.RewardDeleteOut, err error) + // List 奖励列表 List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error) // GetLift 领取奖励 GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error) diff --git a/internal/service/store.go b/internal/service/store.go index 76b2aab..7cc79dd 100644 --- a/internal/service/store.go +++ b/internal/service/store.go @@ -22,6 +22,7 @@ type ( 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) + Detail(ctx context.Context, in *model.StoreDetailIn) (out *model.StoreDetailOut, err error) } ) diff --git a/utility/myCasbin/casbin.go b/utility/myCasbin/casbin.go index 81f8caf..2956513 100644 --- a/utility/myCasbin/casbin.go +++ b/utility/myCasbin/casbin.go @@ -133,6 +133,8 @@ func init() { enforcer.AddPolicy("store", "/x/store/del/*", "DELETE", "删除门店 ip信息") enforcer.AddPolicy("store", "/x/store/updateIp", "PUT", "修改门店 ip信息") + // statistics + enforcer.AddPolicy("store", "/x/statistic/onlineDevice", "GET", "获取门店在线设备列表") } // 商户 {