Merge remote-tracking branch 'origin/master'

# Conflicts:
#	internal/dao/internal/rewards.go
#	internal/model/do/rewards.go
#	internal/model/entity/rewards.go
This commit is contained in:
chy
2025-06-26 16:39:45 +08:00
46 changed files with 499 additions and 472 deletions

View File

@ -27,8 +27,8 @@ type CreateReq struct {
RewardTypeId int64 `json:"rewardTypeId" v:"required#奖励类型ID不能为空" dc:"奖励类型ID"`
GameId int64 `json:"gameId" dc:"游戏ID"`
RewardImg string `json:"rewardImg" dc:"奖励图片"`
QQGoodsId string `json:"qqGoodsId" v:"required#不能为空" dc:"QQ网吧物品ID"`
QQGoodsIdStr string `json:"qqGoodsIdStr" v:"required#不能为空" dc:"QQ网吧物品ID字符串"`
QQGoodsId string `json:"qqGoodsId" dc:"QQ网吧物品ID"`
QQGoodsIdStr string `json:"qqGoodsIdStr" dc:"QQ网吧物品ID字符串"`
Status int `json:"status" dc:"状态" d:"1启用 2禁用"`
ExpireType int `json:"expireType" v:"required#过期类型只能为1或2" dc:"过期类型"`
ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间expire_type=1 时使用)"`

View File

@ -17,4 +17,5 @@ type ITaskV1 interface {
List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error)
Selector(ctx context.Context, req *v1.SelectorReq) (res *v1.SelectorRes, err error)
GetTask(ctx context.Context, req *v1.GetTaskReq) (res *v1.GetTaskRes, err error)
GetUserTaskRecordsList(ctx context.Context, req *v1.GetUserTaskRecordsListReq) (res *v1.GetUserTaskRecordsListRes, err error)
}

View File

@ -75,13 +75,28 @@ 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"`
TaskId string `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"`
GameId int `json:"gameId" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"`
TaskName string `json:"taskName" v:"required#任务名称不能为空" dc:"任务名称"`
}
type GetTaskRes struct {
Success bool `json:"success"`
}
type GetUserTaskRecordsListReq struct {
g.Meta `path:"/task/records" method:"get" tags:"Task" summary:"(PC)用户任务记录列表"`
TaskId string `json:"taskId" dc:"任务 id"`
StoreId int `json:"storeId" dc:"门店 id"`
NetbarAccount string `json:"netbarAccount" dc:"网关账号"`
Page int `json:"page" dc:"页数"`
Size int `json:"size" dc:"条数"`
StartTime int32 `json:"startTime" dc:"开始时间"`
EndTime int32 `json:"endTime" dc:"结束时间"`
}
type GetUserTaskRecordsListRes struct {
List interface{} `json:"list"`
Total int `json:"total"`
}

View File

@ -22,6 +22,6 @@ const (
)
const (
NetbarOnlineNumberKey = "%s:online:device:%s"
NetbarOnlineDeviceSetKey = "%s:online_devices"
NetbarOnlineNumberKey = "%s:online_number"
OnlineDeviceSetKey = "online:devices"
)

View File

@ -20,13 +20,11 @@ func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListR
)
out, err := service.RewardType().List(ctx, &model.RewardTypeListIn{
Page: req.Page,
Size: req.Size,
OperatorId: operatorId,
OperatorRole: operatorRole,
StoreId: req.StoreId,
Name: req.Name,
Source: req.Source,
Page: req.Page,
Size: req.Size,
StoreId: req.StoreId,
Name: req.Name,
Source: req.Source,
})
if err != nil {

View File

@ -10,6 +10,11 @@ import (
)
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
get, err := g.Redis().Get(ctx, fmt.Sprintf(consts.NetbarOnlineNumberKey, req.NetbarAccount))
if err != nil {
return nil, err
}
return &v1.GetOnlineDeviceRes{
Total: get.Int64(),
}, nil
}

View File

@ -0,0 +1,23 @@
package task
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"server/internal/model"
"server/internal/service"
"server/api/task/v1"
)
func (c *ControllerV1) GetUserTaskRecordsList(ctx context.Context, req *v1.GetUserTaskRecordsListReq) (res *v1.GetUserTaskRecordsListRes, err error) {
fromCtx := g.RequestFromCtx(ctx)
userId := fromCtx.GetCtxVar("id").Int()
out, err := service.Task().GetUserTaskRecordsList(ctx, &model.UserTaskRecordsListIn{UserId: userId})
if err != nil {
return nil, err
}
return &v1.GetUserTaskRecordsListRes{
List: out.List,
Total: out.Total,
}, nil
}

View File

@ -13,10 +13,9 @@ import (
// AdminsDao is the data access object for the table admins.
type AdminsDao 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 AdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 AdminsColumns // columns contains all the column names of Table for convenient usage.
}
// AdminsColumns defines and stores column names for the table admins.
@ -50,12 +49,11 @@ var adminsColumns = AdminsColumns{
}
// NewAdminsDao creates and returns a new DAO object for table data access.
func NewAdminsDao(handlers ...gdb.ModelHandler) *AdminsDao {
func NewAdminsDao() *AdminsDao {
return &AdminsDao{
group: "default",
table: "admins",
columns: adminsColumns,
handlers: handlers,
group: "default",
table: "admins",
columns: adminsColumns,
}
}
@ -81,11 +79,7 @@ func (dao *AdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *AdminsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// FeedbacksDao is the data access object for the table feedbacks.
type FeedbacksDao 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 FeedbacksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 FeedbacksColumns // columns contains all the column names of Table for convenient usage.
}
// FeedbacksColumns defines and stores column names for the table feedbacks.
@ -52,12 +51,11 @@ var feedbacksColumns = FeedbacksColumns{
}
// NewFeedbacksDao creates and returns a new DAO object for table data access.
func NewFeedbacksDao(handlers ...gdb.ModelHandler) *FeedbacksDao {
func NewFeedbacksDao() *FeedbacksDao {
return &FeedbacksDao{
group: "default",
table: "feedbacks",
columns: feedbacksColumns,
handlers: handlers,
group: "default",
table: "feedbacks",
columns: feedbacksColumns,
}
}
@ -83,11 +81,7 @@ func (dao *FeedbacksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *FeedbacksDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// GamesDao is the data access object for the table games.
type GamesDao 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 GamesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 GamesColumns // columns contains all the column names of Table for convenient usage.
}
// GamesColumns defines and stores column names for the table games.
@ -46,12 +45,11 @@ var gamesColumns = GamesColumns{
}
// NewGamesDao creates and returns a new DAO object for table data access.
func NewGamesDao(handlers ...gdb.ModelHandler) *GamesDao {
func NewGamesDao() *GamesDao {
return &GamesDao{
group: "default",
table: "games",
columns: gamesColumns,
handlers: handlers,
group: "default",
table: "games",
columns: gamesColumns,
}
}
@ -77,11 +75,7 @@ func (dao *GamesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *GamesDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// MerchantAdminsDao is the data access object for the table merchant_admins.
type MerchantAdminsDao 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 MerchantAdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 MerchantAdminsColumns // columns contains all the column names of Table for convenient usage.
}
// MerchantAdminsColumns defines and stores column names for the table merchant_admins.
@ -58,12 +57,11 @@ var merchantAdminsColumns = MerchantAdminsColumns{
}
// NewMerchantAdminsDao creates and returns a new DAO object for table data access.
func NewMerchantAdminsDao(handlers ...gdb.ModelHandler) *MerchantAdminsDao {
func NewMerchantAdminsDao() *MerchantAdminsDao {
return &MerchantAdminsDao{
group: "default",
table: "merchant_admins",
columns: merchantAdminsColumns,
handlers: handlers,
group: "default",
table: "merchant_admins",
columns: merchantAdminsColumns,
}
}
@ -89,11 +87,7 @@ func (dao *MerchantAdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *MerchantAdminsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// MerchantsDao is the data access object for the table merchants.
type MerchantsDao 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 MerchantsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 MerchantsColumns // columns contains all the column names of Table for convenient usage.
}
// MerchantsColumns defines and stores column names for the table merchants.
@ -72,12 +71,11 @@ var merchantsColumns = MerchantsColumns{
}
// NewMerchantsDao creates and returns a new DAO object for table data access.
func NewMerchantsDao(handlers ...gdb.ModelHandler) *MerchantsDao {
func NewMerchantsDao() *MerchantsDao {
return &MerchantsDao{
group: "default",
table: "merchants",
columns: merchantsColumns,
handlers: handlers,
group: "default",
table: "merchants",
columns: merchantsColumns,
}
}
@ -103,11 +101,7 @@ func (dao *MerchantsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *MerchantsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// NoticesDao is the data access object for the table notices.
type NoticesDao 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 NoticesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 NoticesColumns // columns contains all the column names of Table for convenient usage.
}
// NoticesColumns defines and stores column names for the table notices.
@ -50,12 +49,11 @@ var noticesColumns = NoticesColumns{
}
// NewNoticesDao creates and returns a new DAO object for table data access.
func NewNoticesDao(handlers ...gdb.ModelHandler) *NoticesDao {
func NewNoticesDao() *NoticesDao {
return &NoticesDao{
group: "default",
table: "notices",
columns: noticesColumns,
handlers: handlers,
group: "default",
table: "notices",
columns: noticesColumns,
}
}
@ -81,11 +79,7 @@ func (dao *NoticesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *NoticesDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// RewardCallbackDao is the data access object for the table reward_callback.
type RewardCallbackDao 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 RewardCallbackColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 RewardCallbackColumns // columns contains all the column names of Table for convenient usage.
}
// RewardCallbackColumns defines and stores column names for the table reward_callback.
@ -48,12 +47,11 @@ var rewardCallbackColumns = RewardCallbackColumns{
}
// NewRewardCallbackDao creates and returns a new DAO object for table data access.
func NewRewardCallbackDao(handlers ...gdb.ModelHandler) *RewardCallbackDao {
func NewRewardCallbackDao() *RewardCallbackDao {
return &RewardCallbackDao{
group: "default",
table: "reward_callback",
columns: rewardCallbackColumns,
handlers: handlers,
group: "default",
table: "reward_callback",
columns: rewardCallbackColumns,
}
}
@ -79,11 +77,7 @@ func (dao *RewardCallbackDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardCallbackDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,43 +13,39 @@ import (
// RewardTypesDao is the data access object for the table reward_types.
type RewardTypesDao 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 RewardTypesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 RewardTypesColumns // columns contains all the column names of Table for convenient usage.
}
// RewardTypesColumns defines and stores column names for the table reward_types.
type RewardTypesColumns struct {
Id string // 奖励类型ID
Name string // 类型名称
TencentTypeId string // 腾讯奖励类型ID仅系统奖励有效
Source string // 奖励来源1=腾讯系统2=本系统3=其他
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间
StoreId string // 门店 id
Id string // 奖励类型ID
Name string // 类型名称
Code string // 唯一编码
IconUrl string // 图标链接地址
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间
}
// rewardTypesColumns holds the columns for the table reward_types.
var rewardTypesColumns = RewardTypesColumns{
Id: "id",
Name: "name",
TencentTypeId: "tencent_type_id",
Source: "source",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
StoreId: "store_id",
Id: "id",
Name: "name",
Code: "code",
IconUrl: "icon_url",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
}
// NewRewardTypesDao creates and returns a new DAO object for table data access.
func NewRewardTypesDao(handlers ...gdb.ModelHandler) *RewardTypesDao {
func NewRewardTypesDao() *RewardTypesDao {
return &RewardTypesDao{
group: "default",
table: "reward_types",
columns: rewardTypesColumns,
handlers: handlers,
group: "default",
table: "reward_types",
columns: rewardTypesColumns,
}
}
@ -75,11 +71,7 @@ func (dao *RewardTypesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardTypesDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// RewardWatersDao is the data access object for the table reward_waters.
type RewardWatersDao 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 RewardWatersColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 RewardWatersColumns // columns contains all the column names of Table for convenient usage.
}
// RewardWatersColumns defines and stores column names for the table reward_waters.
@ -46,12 +45,11 @@ var rewardWatersColumns = RewardWatersColumns{
}
// NewRewardWatersDao creates and returns a new DAO object for table data access.
func NewRewardWatersDao(handlers ...gdb.ModelHandler) *RewardWatersDao {
func NewRewardWatersDao() *RewardWatersDao {
return &RewardWatersDao{
group: "default",
table: "reward_waters",
columns: rewardWatersColumns,
handlers: handlers,
group: "default",
table: "reward_waters",
columns: rewardWatersColumns,
}
}
@ -77,11 +75,7 @@ func (dao *RewardWatersDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardWatersDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// RewardsDao is the data access object for the table rewards.
type RewardsDao 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 RewardsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 RewardsColumns // columns contains all the column names of Table for convenient usage.
}
// RewardsColumns defines and stores column names for the table rewards.
@ -44,6 +43,7 @@ type RewardsColumns struct {
UpdatedAt string // 更新时间
DeletedAt string // 删除时间(软删除)
PrizeId string // 券 id
Source string // 奖励来源1 为系统奖励对接腾讯2 是门店
}
// rewardsColumns holds the columns for the table rewards.
@ -71,15 +71,15 @@ var rewardsColumns = RewardsColumns{
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
PrizeId: "prize_id",
Source: "source",
}
// NewRewardsDao creates and returns a new DAO object for table data access.
func NewRewardsDao(handlers ...gdb.ModelHandler) *RewardsDao {
func NewRewardsDao() *RewardsDao {
return &RewardsDao{
group: "default",
table: "rewards",
columns: rewardsColumns,
handlers: handlers,
group: "default",
table: "rewards",
columns: rewardsColumns,
}
}
@ -105,11 +105,7 @@ func (dao *RewardsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// RolesDao is the data access object for the table roles.
type RolesDao 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 RolesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 RolesColumns // columns contains all the column names of Table for convenient usage.
}
// RolesColumns defines and stores column names for the table roles.
@ -48,12 +47,11 @@ var rolesColumns = RolesColumns{
}
// NewRolesDao creates and returns a new DAO object for table data access.
func NewRolesDao(handlers ...gdb.ModelHandler) *RolesDao {
func NewRolesDao() *RolesDao {
return &RolesDao{
group: "default",
table: "roles",
columns: rolesColumns,
handlers: handlers,
group: "default",
table: "roles",
columns: rolesColumns,
}
}
@ -79,11 +77,7 @@ func (dao *RolesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RolesDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// StoreAdminsDao is the data access object for the table store_admins.
type StoreAdminsDao 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 StoreAdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 StoreAdminsColumns // columns contains all the column names of Table for convenient usage.
}
// StoreAdminsColumns defines and stores column names for the table store_admins.
@ -58,12 +57,11 @@ var storeAdminsColumns = StoreAdminsColumns{
}
// NewStoreAdminsDao creates and returns a new DAO object for table data access.
func NewStoreAdminsDao(handlers ...gdb.ModelHandler) *StoreAdminsDao {
func NewStoreAdminsDao() *StoreAdminsDao {
return &StoreAdminsDao{
group: "default",
table: "store_admins",
columns: storeAdminsColumns,
handlers: handlers,
group: "default",
table: "store_admins",
columns: storeAdminsColumns,
}
}
@ -89,11 +87,7 @@ func (dao *StoreAdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreAdminsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// StoreDesktopSettingsDao is the data access object for the table store_desktop_settings.
type StoreDesktopSettingsDao 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 StoreDesktopSettingsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 StoreDesktopSettingsColumns // columns contains all the column names of Table for convenient usage.
}
// StoreDesktopSettingsColumns defines and stores column names for the table store_desktop_settings.
@ -34,12 +33,11 @@ var storeDesktopSettingsColumns = StoreDesktopSettingsColumns{
}
// NewStoreDesktopSettingsDao creates and returns a new DAO object for table data access.
func NewStoreDesktopSettingsDao(handlers ...gdb.ModelHandler) *StoreDesktopSettingsDao {
func NewStoreDesktopSettingsDao() *StoreDesktopSettingsDao {
return &StoreDesktopSettingsDao{
group: "default",
table: "store_desktop_settings",
columns: storeDesktopSettingsColumns,
handlers: handlers,
group: "default",
table: "store_desktop_settings",
columns: storeDesktopSettingsColumns,
}
}
@ -65,11 +63,7 @@ func (dao *StoreDesktopSettingsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreDesktopSettingsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// 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.
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.
}
// StoreIpsColumns defines and stores column names for the table store_ips.
@ -42,12 +41,11 @@ var storeIpsColumns = StoreIpsColumns{
}
// NewStoreIpsDao creates and returns a new DAO object for table data access.
func NewStoreIpsDao(handlers ...gdb.ModelHandler) *StoreIpsDao {
func NewStoreIpsDao() *StoreIpsDao {
return &StoreIpsDao{
group: "default",
table: "store_ips",
columns: storeIpsColumns,
handlers: handlers,
group: "default",
table: "store_ips",
columns: storeIpsColumns,
}
}
@ -73,11 +71,7 @@ func (dao *StoreIpsDao) Group() string {
// 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// StoreNetfeeAreaLevelDao is the data access object for the table store_netfee_area_level.
type StoreNetfeeAreaLevelDao 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 StoreNetfeeAreaLevelColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 StoreNetfeeAreaLevelColumns // columns contains all the column names of Table for convenient usage.
}
// StoreNetfeeAreaLevelColumns defines and stores column names for the table store_netfee_area_level.
@ -50,12 +49,11 @@ var storeNetfeeAreaLevelColumns = StoreNetfeeAreaLevelColumns{
}
// NewStoreNetfeeAreaLevelDao creates and returns a new DAO object for table data access.
func NewStoreNetfeeAreaLevelDao(handlers ...gdb.ModelHandler) *StoreNetfeeAreaLevelDao {
func NewStoreNetfeeAreaLevelDao() *StoreNetfeeAreaLevelDao {
return &StoreNetfeeAreaLevelDao{
group: "default",
table: "store_netfee_area_level",
columns: storeNetfeeAreaLevelColumns,
handlers: handlers,
group: "default",
table: "store_netfee_area_level",
columns: storeNetfeeAreaLevelColumns,
}
}
@ -81,11 +79,7 @@ func (dao *StoreNetfeeAreaLevelDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreNetfeeAreaLevelDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// StoreRolesDao is the data access object for the table store_roles.
type StoreRolesDao 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 StoreRolesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 StoreRolesColumns // columns contains all the column names of Table for convenient usage.
}
// StoreRolesColumns defines and stores column names for the table store_roles.
@ -40,12 +39,11 @@ var storeRolesColumns = StoreRolesColumns{
}
// NewStoreRolesDao creates and returns a new DAO object for table data access.
func NewStoreRolesDao(handlers ...gdb.ModelHandler) *StoreRolesDao {
func NewStoreRolesDao() *StoreRolesDao {
return &StoreRolesDao{
group: "default",
table: "store_roles",
columns: storeRolesColumns,
handlers: handlers,
group: "default",
table: "store_roles",
columns: storeRolesColumns,
}
}
@ -71,11 +69,7 @@ func (dao *StoreRolesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreRolesDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// StoresDao is the data access object for the table stores.
type StoresDao 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 StoresColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 StoresColumns // columns contains all the column names of Table for convenient usage.
}
// StoresColumns defines and stores column names for the table stores.
@ -52,12 +51,11 @@ var storesColumns = StoresColumns{
}
// NewStoresDao creates and returns a new DAO object for table data access.
func NewStoresDao(handlers ...gdb.ModelHandler) *StoresDao {
func NewStoresDao() *StoresDao {
return &StoresDao{
group: "default",
table: "stores",
columns: storesColumns,
handlers: handlers,
group: "default",
table: "stores",
columns: storesColumns,
}
}
@ -83,11 +81,7 @@ func (dao *StoresDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoresDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// TaskRewardsDao is the data access object for the table task_rewards.
type TaskRewardsDao 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 TaskRewardsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 TaskRewardsColumns // columns contains all the column names of Table for convenient usage.
}
// TaskRewardsColumns defines and stores column names for the table task_rewards.
@ -32,12 +31,11 @@ var taskRewardsColumns = TaskRewardsColumns{
}
// NewTaskRewardsDao creates and returns a new DAO object for table data access.
func NewTaskRewardsDao(handlers ...gdb.ModelHandler) *TaskRewardsDao {
func NewTaskRewardsDao() *TaskRewardsDao {
return &TaskRewardsDao{
group: "default",
table: "task_rewards",
columns: taskRewardsColumns,
handlers: handlers,
group: "default",
table: "task_rewards",
columns: taskRewardsColumns,
}
}
@ -63,11 +61,7 @@ func (dao *TaskRewardsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *TaskRewardsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// TasksDao is the data access object for the table tasks.
type TasksDao 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 TasksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 TasksColumns // columns contains all the column names of Table for convenient usage.
}
// TasksColumns defines and stores column names for the table tasks.
@ -58,12 +57,11 @@ var tasksColumns = TasksColumns{
}
// NewTasksDao creates and returns a new DAO object for table data access.
func NewTasksDao(handlers ...gdb.ModelHandler) *TasksDao {
func NewTasksDao() *TasksDao {
return &TasksDao{
group: "default",
table: "tasks",
columns: tasksColumns,
handlers: handlers,
group: "default",
table: "tasks",
columns: tasksColumns,
}
}
@ -89,11 +87,7 @@ func (dao *TasksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *TasksDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// UserTaskRewardsDao is the data access object for the table user_task_rewards.
type UserTaskRewardsDao 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 UserTaskRewardsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 UserTaskRewardsColumns // columns contains all the column names of Table for convenient usage.
}
// UserTaskRewardsColumns defines and stores column names for the table user_task_rewards.
@ -32,6 +31,7 @@ type UserTaskRewardsColumns struct {
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间
ExpiredAt string // 奖励过期时间
}
// userTaskRewardsColumns holds the columns for the table user_task_rewards.
@ -47,15 +47,15 @@ var userTaskRewardsColumns = UserTaskRewardsColumns{
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
ExpiredAt: "expired_at",
}
// NewUserTaskRewardsDao creates and returns a new DAO object for table data access.
func NewUserTaskRewardsDao(handlers ...gdb.ModelHandler) *UserTaskRewardsDao {
func NewUserTaskRewardsDao() *UserTaskRewardsDao {
return &UserTaskRewardsDao{
group: "default",
table: "user_task_rewards",
columns: userTaskRewardsColumns,
handlers: handlers,
group: "default",
table: "user_task_rewards",
columns: userTaskRewardsColumns,
}
}
@ -81,11 +81,7 @@ func (dao *UserTaskRewardsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *UserTaskRewardsDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// UserTasksDao is the data access object for the table user_tasks.
type UserTasksDao 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 UserTasksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 UserTasksColumns // columns contains all the column names of Table for convenient usage.
}
// UserTasksColumns defines and stores column names for the table user_tasks.
@ -52,12 +51,11 @@ var userTasksColumns = UserTasksColumns{
}
// NewUserTasksDao creates and returns a new DAO object for table data access.
func NewUserTasksDao(handlers ...gdb.ModelHandler) *UserTasksDao {
func NewUserTasksDao() *UserTasksDao {
return &UserTasksDao{
group: "default",
table: "user_tasks",
columns: userTasksColumns,
handlers: handlers,
group: "default",
table: "user_tasks",
columns: userTasksColumns,
}
}
@ -83,11 +81,7 @@ func (dao *UserTasksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *UserTasksDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -13,10 +13,9 @@ import (
// UsersDao is the data access object for the table users.
type UsersDao 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 UsersColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
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 UsersColumns // columns contains all the column names of Table for convenient usage.
}
// UsersColumns defines and stores column names for the table users.
@ -60,12 +59,11 @@ var usersColumns = UsersColumns{
}
// NewUsersDao creates and returns a new DAO object for table data access.
func NewUsersDao(handlers ...gdb.ModelHandler) *UsersDao {
func NewUsersDao() *UsersDao {
return &UsersDao{
group: "default",
table: "users",
columns: usersColumns,
handlers: handlers,
group: "default",
table: "users",
columns: usersColumns,
}
}
@ -91,11 +89,7 @@ func (dao *UsersDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *UsersDao) 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)
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.

View File

@ -261,20 +261,18 @@ func (s *sReward) Delete(ctx context.Context, in *model.RewardDeleteIn) (out *mo
func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error) {
rewardCols := dao.Rewards.Columns()
rewardTypeCols := dao.RewardTypes.Columns()
rewardTypeIds := make([]int64, 0)
// ==== 权限校验 ====
orm := dao.Rewards.Ctx(ctx).LeftJoin(
dao.RewardTypes.Table(),
fmt.Sprintf(
"%s.%s = %s.%s",
dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId,
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id,
),
).Fields(fmt.Sprintf("%s.*,%s.name as reward_type_name", dao.Rewards.Table(), dao.RewardTypes.Table()))
switch in.OperatorRole {
case consts.AdminRoleCode:
// 系统管理员只能查询 source = 1 的奖励
array, err := dao.RewardTypes.Ctx(ctx).Where(do.RewardTypes{Source: 1}).Fields(rewardTypeCols.Id).Array()
if err != nil {
return nil, ecode.Fail.Sub("获取奖励类型列表失败")
}
for _, value := range array {
rewardTypeIds = append(rewardTypeIds, value.Int64())
}
orm = orm.Where(rewardCols.Source, 1)
case consts.MerchantRoleCode, consts.StoreRoleCode:
// 合并商户和门店角色权限校验
var exist bool
@ -309,28 +307,11 @@ func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model.
if !exist {
return nil, ecode.Params.Sub("无门店权限")
}
//
array, err := dao.RewardTypes.Ctx(ctx).Where(do.RewardTypes{Source: 2, StoreId: in.StoreId}).Fields(rewardTypeCols.Id).Array()
if err != nil {
return nil, ecode.Fail.Sub("获取奖励类型列表失败")
}
for _, value := range array {
rewardTypeIds = append(rewardTypeIds, value.Int64())
}
orm = orm.Where(rewardCols.Source, 2)
default:
return nil, ecode.Params.Sub("无效的角色")
}
orm := dao.Rewards.Ctx(ctx).LeftJoin(
dao.RewardTypes.Table(),
fmt.Sprintf(
"%s.%s = %s.%s",
dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId,
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id,
),
).Fields(fmt.Sprintf("%s.*,%s.name as reward_type_name", dao.Rewards.Table(), dao.RewardTypes.Table())).
WhereIn(dao.Rewards.Columns().RewardTypeId, rewardTypeIds)
// ==== 其他查询条件 ====
if in.Status != 0 {
orm = orm.Where(fmt.Sprintf("%s.%s = ?", dao.Rewards.Table(), rewardCols.Status), in.Status)

View File

@ -32,10 +32,7 @@ func (s *sRewardType) Create(ctx context.Context, in *model.RewardTypeCreateIn)
}
data := do.RewardTypes{
Name: in.Name,
Source: in.Source,
StoreId: in.StoreId,
TencentTypeId: in.TencentTypeId,
Name: in.Name,
}
id, err := dao.RewardTypes.Ctx(ctx).OmitEmptyData().Data(data).InsertAndGetId()
@ -110,30 +107,6 @@ func (s *sRewardType) Delete(ctx context.Context, in *model.RewardTypeDeleteIn)
func (s *sRewardType) List(ctx context.Context, in *model.RewardTypeListIn) (out *model.RewardTypeListOut, err error) {
mod := dao.RewardTypes.Ctx(ctx).Where("deleted_at IS NULL")
switch in.OperatorRole {
case consts.AdminRoleCode:
// 系统管理员只能看系统奖励类型
mod = mod.Where("source", 1)
case consts.MerchantRoleCode:
// 校验商户是否对该门店有权限
if err = checkRewardTypePermission(ctx, in.OperatorRole, in.OperatorId, 2, in.StoreId); err != nil {
return nil, err
}
// 只查询该门店的奖励类型source=2且store_id=指定门店)
mod = mod.Where("source", 2).WhereIn("store_id", in.StoreId)
case consts.StoreRoleCode:
// 校验门店权限
if err = checkRewardTypePermission(ctx, in.OperatorRole, in.OperatorId, 2, in.StoreId); err != nil {
return nil, err
}
mod = mod.Where("source", 2).Where("store_id", in.StoreId)
default:
return nil, ecode.Params.Sub("无效的操作角色")
}
// 其余过滤条件
if in.Name != "" {
mod = mod.WhereLike("name", "%"+in.Name+"%")

View File

@ -13,17 +13,10 @@ import (
)
type sStoreDesktopSetting struct {
mqttCLient mqtt.MqttClient
}
func New() service.IStoreDesktopSetting {
client, b := mqtt.GetClient("emqx")
if !b {
return nil
}
return &sStoreDesktopSetting{
mqttCLient: client,
}
return &sStoreDesktopSetting{}
}
func init() {
service.RegisterStoreDesktopSetting(New())
@ -74,7 +67,11 @@ func (s *sStoreDesktopSetting) Save(ctx context.Context, in model.SaveDesktopSet
if err != nil {
return nil, err
}
err = s.mqttCLient.Publish(fmt.Sprintf("/desktop/%d", in.StoreId), marshal)
client, b := mqtt.GetClient("emqx")
if !b {
return nil, gerror.New("获取MQTT客户端失败")
}
err = client.Publish(fmt.Sprintf("/desktop/%d", in.StoreId), marshal)
if err != nil {
return nil, err
}

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/util/guid"
"server/internal/consts"
"server/internal/dao"
"server/internal/model"
@ -189,12 +190,10 @@ func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetTaskListIn
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id,
dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId)).
Fields(
fmt.Sprintf("%s.*, `%s`.`%s` AS %s, `%s`.`%s` AS %s",
fmt.Sprintf(
"%s.*, `%s`.`%s` AS %s",
dao.Rewards.Table(),
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Name,
"reward_type_name",
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Source,
"reward_type_source",
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Name, "reward_type_name",
),
).Where(dao.TaskRewards.Columns().TaskId, task.TaskID).Scan(&data.Rewards)
if err != nil {
@ -359,6 +358,7 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge
return ecode.Fail.Sub("创建用户任务记录失败")
}
snowid.GetSnowClient()
// 查询该任务相关联的奖励, 创建对应奖励下发记录id
array, err := dao.TaskRewards.Ctx(ctx).Where(do.TaskRewards{TaskId: in.TaskId}).Fields(dao.TaskRewards.Columns().RewardId).Array()
if err != nil {
@ -366,9 +366,10 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge
}
for _, v := range array {
_, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
UserTaskId: id,
RewardId: v.Int64(),
Status: consts.RewardInitStatus,
UserTaskId: id,
RewardId: v.Int64(),
Status: consts.RewardInitStatus,
InnerOrderId: fmt.Sprintf("reward%s", guid.S()),
}).Insert()
if err != nil {
return ecode.Fail.Sub("创建用户任务奖励记录失败")
@ -382,3 +383,21 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge
Success: true,
}, nil
}
func (s *sTask) GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRecordsListIn) (out *model.UserTaskRecordsListOut, err error) {
list := make([]model.UserTask, 0)
var total int
orm := dao.UserTasks.Ctx(ctx).Where(dao.UserTasks.Columns().Id, in.UserId)
if in.StoreId != 0 {
orm = orm.Where(dao.UserTasks.Columns().StoreId, in.StoreId)
}
err = orm.Page(in.Page, in.Size).ScanAndCount(&list, &total, false)
if err != nil {
return nil, ecode.Fail.Sub("获取用户任务列表失败")
}
return &model.UserTaskRecordsListOut{
List: list,
Total: total,
}, nil
}

View File

@ -11,13 +11,12 @@ import (
// RewardTypes is the golang structure of table reward_types for DAO operations like Where/Data.
type RewardTypes struct {
g.Meta `orm:"table:reward_types, do:true"`
Id interface{} // 奖励类型ID
Name interface{} // 类型名称
TencentTypeId interface{} // 腾讯奖励类型ID仅系统奖励有效
Source interface{} // 奖励来源1=腾讯系统2=本系统3=其他
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间
StoreId interface{} // 门店 id
g.Meta `orm:"table:reward_types, do:true"`
Id interface{} // 奖励类型ID
Name interface{} // 类型名称
Code interface{} // 唯一编码
IconUrl interface{} // 图标链接地址
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间
}

View File

@ -35,4 +35,5 @@ type Rewards struct {
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 删除时间(软删除)
PrizeId interface{} // 券 id
Source interface{} // 奖励来源1 为系统奖励对接腾讯2 是门店
}

View File

@ -23,4 +23,5 @@ type UserTaskRewards struct {
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间
ExpiredAt *gtime.Time // 奖励过期时间
}

View File

@ -10,12 +10,11 @@ import (
// RewardTypes is the golang structure for table reward_types.
type RewardTypes struct {
Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID
Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称
TencentTypeId int `json:"tencentTypeId" orm:"tencent_type_id" description:"腾讯奖励类型ID仅系统奖励有效"` // 腾讯奖励类型ID仅系统奖励有效
Source int `json:"source" orm:"source" description:"奖励来源1=腾讯系统2=本系统3=其他"` // 奖励来源1=腾讯系统2=本系统3=其他
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:"软删除时间"` // 软删除时间
StoreId int64 `json:"storeId" orm:"store_id" description:"门店 id"` // 门店 id
Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID
Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称
Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码
IconUrl string `json:"iconUrl" orm:"icon_url" 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

@ -33,4 +33,5 @@ type Rewards struct {
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间(软删除)"` // 删除时间(软删除)
PrizeId string `json:"prizeId" orm:"prize_id" description:"券 id"` // 券 id
Source int `json:"source" orm:"source" description:"奖励来源1 为系统奖励对接腾讯2 是门店"` // 奖励来源1 为系统奖励对接腾讯2 是门店
}

View File

@ -21,4 +21,5 @@ type UserTaskRewards struct {
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:"软删除时间"` // 软删除时间
ExpiredAt *gtime.Time `json:"expiredAt" orm:"expired_at" description:"奖励过期时间"` // 奖励过期时间
}

View File

@ -6,30 +6,30 @@ import (
// Reward 奖励表
type Reward struct {
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID系统奖励为NULL"` // 门店ID系统奖励为NULL
Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称
RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID关联 reward_types 表"` // 奖励类型ID关联 reward_types 表
RewardTypeName string `json:"rewardTypeName" orm:"reward_type_name" description:"奖励类型名称"` // 奖励类型名称
RewardTypeSource int `json:"rewardTypeSource" orm:"reward_type_source" description:"奖励类型来源"` // 奖励类型来源
GameId int64 `json:"gameId" orm:"game_id" description:"游戏ID"` // 游戏ID
ImageUrl string `json:"imageUrl" orm:"image_url" description:"奖励图片链接"` // 奖励图片链接
QqGoodsId string `json:"qqGoodsId" orm:"qq_goods_id" description:"QQ网吧物品ID"` // QQ网吧物品ID
QqGoodsIdStr string `json:"qqGoodsIdStr" orm:"qq_goods_id_str" description:"QQ网吧物品ID字符串"` // QQ网吧物品ID字符串
Status int `json:"status" orm:"status" description:"状态1=启用2=禁用"` // 状态1=启用2=禁用
ExpireType int `json:"expireType" orm:"expire_type" description:"过期方式1=时间段过期2=领取后过期"` // 过期方式1=时间段过期2=领取后过期
ValidFrom *gtime.Time `json:"validFrom" orm:"valid_from" description:"有效期开始时间expire_type=1时"` // 有效期开始时间expire_type=1时
ValidTo *gtime.Time `json:"validTo" orm:"valid_to" description:"有效期结束时间expire_type=1时"` // 有效期结束时间expire_type=1时
ExpireDays int `json:"expireDays" orm:"expire_days" description:"领取后多少天过期expire_type=2时"` // 领取后多少天过期expire_type=2时
DailyTotalLimit uint64 `json:"dailyTotalLimit" orm:"daily_total_limit" description:"每日发放总限NULL表示不限制"` // 每日发放总限NULL表示不限制
TotalLimit uint64 `json:"totalLimit" orm:"total_limit" description:"奖励总限NULL表示不限制"` // 奖励总限NULL表示不限制
UserDailyLimit uint64 `json:"userDailyLimit" orm:"user_daily_limit" description:"用户每日领取限制NULL表示不限制"` // 用户每日领取限制NULL表示不限制
UserTotalLimit uint64 `json:"userTotalLimit" orm:"user_total_limit" description:"用户领取总次数限制NULL表示不限制"` // 用户领取总次数限制NULL表示不限制
ReceivedNum uint64 `json:"receivedNum" orm:"received_num" description:"已领取数量"` // 已领取数量
GrantQuantity uint64 `json:"grantQuantity" orm:"grant_quantity" 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:"删除时间(软删除)"` // 删除时间(软删除)
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID系统奖励为NULL"` // 门店ID系统奖励为NULL
Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称
RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID关联 reward_types 表"` // 奖励类型ID关联 reward_types 表
RewardTypeName string `json:"rewardTypeName" orm:"reward_type_name" description:"奖励类型名称"` // 奖励类型名称
Source int `json:"source" orm:"source" description:"奖励来源,1=系统奖励对接腾讯2=门店追加"` // 奖励来源,1=系统奖励对接腾讯2=门店追加
GameId int64 `json:"gameId" orm:"game_id" description:"游戏ID"` // 游戏ID
ImageUrl string `json:"imageUrl" orm:"image_url" description:"奖励图片链接"` // 奖励图片链接
QqGoodsId string `json:"qqGoodsId" orm:"qq_goods_id" description:"QQ网吧物品ID"` // QQ网吧物品ID
QqGoodsIdStr string `json:"qqGoodsIdStr" orm:"qq_goods_id_str" description:"QQ网吧物品ID字符串"` // QQ网吧物品ID字符串
Status int `json:"status" orm:"status" description:"状态1=启用2=禁用"` // 状态1=启用2=禁用
ExpireType int `json:"expireType" orm:"expire_type" description:"过期方式1=时间段过期2=领取后过期"` // 过期方式1=时间段过期2=领取后过期
ValidFrom *gtime.Time `json:"validFrom" orm:"valid_from" description:"有效期开始时间expire_type=1时"` // 有效期开始时间expire_type=1时
ValidTo *gtime.Time `json:"validTo" orm:"valid_to" description:"有效期结束时间expire_type=1时"` // 有效期结束时间expire_type=1时
ExpireDays int `json:"expireDays" orm:"expire_days" description:"领取后多少天过期expire_type=2时"` // 领取后多少天过期expire_type=2时
DailyTotalLimit uint64 `json:"dailyTotalLimit" orm:"daily_total_limit" description:"每日发放总限NULL表示不限制"` // 每日发放总限NULL表示不限制
TotalLimit uint64 `json:"totalLimit" orm:"total_limit" description:"奖励总限NULL表示不限制"` // 奖励总限NULL表示不限制
UserDailyLimit uint64 `json:"userDailyLimit" orm:"user_daily_limit" description:"用户每日领取限制NULL表示不限制"` // 用户每日领取限制NULL表示不限制
UserTotalLimit uint64 `json:"userTotalLimit" orm:"user_total_limit" description:"用户领取总次数限制NULL表示不限制"` // 用户领取总次数限制NULL表示不限制
ReceivedNum uint64 `json:"receivedNum" orm:"received_num" description:"已领取数量"` // 已领取数量
GrantQuantity uint64 `json:"grantQuantity" orm:"grant_quantity" 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:"删除时间(软删除)"` // 删除时间(软删除)
}
// RewardCreateIn 创建奖励入参

View File

@ -6,13 +6,13 @@ import (
// RewardType 奖励类型表
type RewardType struct {
Id int64 `json:"id" dc:"奖励类型ID"`
Name string `json:"name" dc:"奖励类型名称(如积分、优惠券)"`
TencentTypeId int `json:"tencentTypeId" dc:"腾讯奖励类型ID仅系统奖励有效"`
Source int `json:"source" dc:"来源1=腾讯系统2=本系统3=其他"`
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间"`
DeletedAt *gtime.Time `json:"deletedAt" dc:"软删除时间"`
Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID
Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称
Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码
IconUrl string `json:"iconUrl" orm:"icon_url" 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:"软删除时间"` // 软删除时间
}
// RewardTypeCreateIn 创建奖励类型入参
@ -59,14 +59,12 @@ type RewardTypeDeleteOut struct {
// RewardTypeListIn 获取奖励类型列表入参
type RewardTypeListIn struct {
OperatorId int64
OperatorRole string
Page int
Size int
Name string
StoreId int64
Status int
Source int
Page int
Size int
Name string
StoreId int64
Status int
Source int
}
// RewardTypeListOut 获取奖励类型列表出参

View File

@ -59,7 +59,7 @@ type LoginUserRankingNum struct {
// GetTaskIn 添加任务记录入参
type GetTaskIn struct {
TaskId int `json:"taskId"`
TaskId string `json:"taskId"`
StoreId int `json:"storeId"`
NetBarAccount string `json:"netBarAccount"`
UserId int `json:"userId"`
@ -70,3 +70,16 @@ type GetTaskIn struct {
type GetTaskOut struct {
Success bool `json:"success"`
}
type UserTaskRecordsListIn struct {
UserId int
Page int
Size int
StoreId int
NetBarAccount string
}
type UserTaskRecordsListOut struct {
List []UserTask
Total int
}

View File

@ -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"

View File

@ -29,6 +29,7 @@ type (
// GetGoodsDetails 物品详情
GetGoodsDetails(ctx context.Context, in *model.GetGoodsDetailsIn) (out *model.QueryUserGoodsDetailResponse, err error)
OperateTaskReward(ctx context.Context, in *model.OperateTaskRewardIn) (out *model.OperateTaskRewardOut, err error)
// CallBack 奖励回调
CallBack(ctx context.Context, in *model.RewardCallbackIn) (out *model.RewardCallbackOut, err error)
}
)

View File

@ -21,6 +21,7 @@ type (
GetSelectorList(ctx context.Context, in *model.SelectorIn) (out *[]model.SelectorOut, err error)
// GetTask 完成任务
GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.GetTaskOut, err error)
GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRecordsListIn) (out *model.UserTaskRecordsListOut, err error)
}
)

View File

@ -3,6 +3,9 @@ package emqx
import (
"context"
"fmt"
"github.com/gogf/gf/v2/encoding/gjson"
"server/internal/consts"
"strconv"
"sync"
"time"
@ -84,9 +87,20 @@ func (e *emqxClient) Subscribe(topic string, handler func(topic string, payload
return err
}
type DeviceData struct {
NetbarAccount string `json:"netbarAccount"`
DeviceId string `json:"deviceId"`
DeviceName string `json:"deviceName"`
IP string `json:"ip"`
MACAddress string `json:"macAddress"`
}
// init 注册emqx客户端
func init() {
// 创建可取消的上下文
ctx := context.Background()
// 加载 MQTT 配置
cfg := g.Config()
host := cfg.MustGet(ctx, "mqtt.emqx.host").String()
port := cfg.MustGet(ctx, "mqtt.emqx.port").Int()
@ -97,6 +111,122 @@ func init() {
broker := fmt.Sprintf("tcp://%s:%d", host, port)
client := New(broker, clientId, username, password)
// 注册 MQTT 客户端
mqtt.Register("emqx", client)
glog.Infof(ctx, "EMQX客户端注册完成broker=%s, clientID=%s", broker, clientId)
glog.Infof(ctx, "EMQX 客户端注册完成broker=%s, clientID=%s", broker, clientId)
// 订阅设备上线消息
go func() {
ctx := context.Background()
err := client.Subscribe("/up", func(topic string, payload []byte) {
glog.Infof(ctx, "收到 MQTT 消息topic=%s", topic)
var data DeviceData
if err := gjson.Unmarshal(payload, &data); err != nil {
glog.Errorf(ctx, "[/up] 解析设备信息失败: %v", err)
return
}
// 增加门店在线设备计数
key := fmt.Sprintf(consts.NetbarOnlineNumberKey, data.NetbarAccount)
if _, err := g.Redis().Incr(ctx, key); err != nil {
glog.Errorf(ctx, "增加 Redis 计数失败 %s: %v", key, err)
return
}
// 更新在线设备集合
setKey := "system:online:devices"
if _, err := g.Redis().HSet(ctx, setKey, map[string]interface{}{
data.DeviceId: time.Now().Unix(),
}); err != nil {
glog.Errorf(ctx, "更新在线设备集合失败 %s: %v", setKey, err)
return
}
// 存储设备信息(用于离线检测时获取 NetbarAccount
deviceKey := fmt.Sprintf("device:%s", data.DeviceId)
if _, err := g.Redis().HSet(ctx, deviceKey, map[string]interface{}{
"netbarAccount": data.NetbarAccount,
"deviceName": data.DeviceName,
"ip": data.IP,
"macAddress": data.MACAddress,
}); err != nil {
glog.Errorf(ctx, "存储设备信息失败 %s: %v", deviceKey, err)
}
})
if err != nil {
glog.Errorf(ctx, "订阅 /up 失败: %v", err)
}
}()
// 监控离线设备
go func() {
ctx := context.Background()
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
glog.Info(ctx, "停止离线设备监控")
return
case <-ticker.C:
setKey := "system:online:devices"
devicesVar, err := g.Redis().HGetAll(ctx, setKey)
if err != nil {
glog.Errorf(ctx, "获取在线设备失败: %v", err)
continue
}
// 转换为 map[string]string
devices := devicesVar.MapStrStr()
if len(devices) == 0 {
continue
}
now := time.Now().Unix()
for deviceId, timestampStr := range devices {
// 使用 strconv.ParseInt 替代 time.ParseInt
timestamp, err := strconv.ParseInt(timestampStr, 10, 64)
if err != nil {
glog.Errorf(ctx, "无效时间戳 for 设备 %s: %v", deviceId, err)
continue
}
// 检查设备是否离线(超过 10 秒未更新)
if now-timestamp > 10 {
// 获取设备信息
dataKey := fmt.Sprintf("device:%s", deviceId)
dataVar, err := g.Redis().HGetAll(ctx, dataKey)
if err != nil {
glog.Errorf(ctx, "获取设备数据失败 %s: %v", dataKey, err)
continue
}
// 转换为 map[string]string
data := dataVar.MapStrStr()
netbarAccount, exists := data["netbarAccount"]
if !exists {
glog.Errorf(ctx, "设备 %s 缺少 netbarAccount", deviceId)
continue
}
// 减少在线设备计数
key := fmt.Sprintf(consts.NetbarOnlineNumberKey, netbarAccount)
if _, err := g.Redis().Decr(ctx, key); err != nil {
glog.Errorf(ctx, "减少 Redis 计数失败 %s: %v", key, err)
}
// 从在线设备集合中移除
if _, err := g.Redis().HDel(ctx, setKey, deviceId); err != nil {
glog.Errorf(ctx, "移除设备 %s 从在线集合失败: %v", deviceId, err)
} else {
glog.Infof(ctx, "设备 %s 已标记为离线", deviceId)
}
}
}
}
}
}()
}