From ae31a3f6a2e5685e8c1d5a28bae5a40d8c061e1b Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 20 Feb 2023 17:00:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=94=A8=E6=88=B7=E8=83=8C=E5=8C=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _const/enum/match_e/enum.go | 214 ------------------------- _const/enum/res_e/enum.go | 9 +- cv/user_cv/bag.go | 17 ++ domain/model/bag_m/user_bag.go | 34 ++++ domain/model/res_m/gift.go | 38 +++++ route/router.go | 1 + route/user_r/bag.go | 64 ++++++++ route/user_r/{user.go => nameplate.go} | 0 8 files changed, 160 insertions(+), 217 deletions(-) delete mode 100755 _const/enum/match_e/enum.go create mode 100644 cv/user_cv/bag.go create mode 100644 domain/model/bag_m/user_bag.go create mode 100644 domain/model/res_m/gift.go create mode 100644 route/user_r/bag.go rename route/user_r/{user.go => nameplate.go} (100%) diff --git a/_const/enum/match_e/enum.go b/_const/enum/match_e/enum.go deleted file mode 100755 index d67fb52..0000000 --- a/_const/enum/match_e/enum.go +++ /dev/null @@ -1,214 +0,0 @@ -package match_e - -import "git.hilo.cn/hilo-common/resource/mysql" - -/****************************/ -type MatchDetailDataChange mysql.NumAll - -const ( - AddDataChange MatchDetailDataChange = 1 - ReduceDataChange MatchDetailDataChange = 2 - ZeroDataChange MatchDetailDataChange = 0 -) - -/******元素分数***************/ -/*type EnumCountType mysql.Type - -const ( - PriorityEnumCountType EnumCountType = 1 - ExcellentEnumCountType EnumCountType = 2 - RelationEnumCountType EnumCountType = 3 -)*/ - -/*const ( - //接收到礼物的数量 - ReceiveGiftNumCountType EnumCountType = 1 - //接收到礼物的频率 - ReceiveGiftFCountType EnumCountType = 2 - //被举报 - BeReportCountType EnumCountType = 3 - //被拉黑 - BeBlackCountType EnumCountType = 4 - //支付次数 - PayCountType EnumCountType = 5 - //被喜欢的次数 - LikeMeType EnumCountType = 6 - //新用户 - NewUserType EnumCountType = 7 - //连续被拒 - AgainRefuse EnumCountType = 8 - //每天新登陆用户 - DailyUserType EnumCountType = 9 - //活跃等级 - ActiveGrade EnumCountType = 10 - //连续同性 - AgainSameSex EnumCountType = 11 - //匹配推送次数 - MatchSuccessNum EnumCountType = 12 - //匹配推送接受次数 - MatchConfirmNum EnumCountType = 13 - //接通率 - MatchConfirmRate EnumCountType = 14 - //免费加时 - MatchFreeTimeNum EnumCountType = 15 - //礼物加时 - MatchGiftTimeNum EnumCountType = 16 - //加时率 - MatchAddTimeRate EnumCountType = 17 - //工会成员 - TradeUnion EnumCountType = 18 - //匹配拒绝 - RelationMatchRefuse EnumCountType = 19 - //匹配用户 - RelationMatchUser EnumCountType = 20 -)*/ - -// 优先度排序 -type PriorityUserFormOriginType mysql.Type - -const ( - //钻石余额 - PriorityDiamond PriorityUserFormOriginType = 1 - //首充 - PriorityFirstCharge PriorityUserFormOriginType = 2 - //财富等级 - PriorityWealthGrade PriorityUserFormOriginType = 3 - //被举报 - PriorityBeReport PriorityUserFormOriginType = 4 - //被拉黑 - PriorityBeBlack PriorityUserFormOriginType = 5 - //近期充值 - PriorityRecentlyPay PriorityUserFormOriginType = 6 - //新用户 - PriorityNewUserType PriorityUserFormOriginType = 7 - //连续被拒 - PriorityAgainRefuse PriorityUserFormOriginType = 8 - //每天新登陆用户 - PriorityDailyUserType PriorityUserFormOriginType = 9 - //活跃等级 - PriorityActiveGrade PriorityUserFormOriginType = 10 - //工会 - PriorityTradeUnion PriorityUserFormOriginType = 11 - //多次匹配到同性 - PriorityAgainSameSex PriorityUserFormOriginType = 12 -) - -var PriorityMap = map[PriorityUserFormOriginType]string{ - PriorityDiamond: "钻石余额", - PriorityFirstCharge: "首充", - PriorityWealthGrade: "财富等级", - PriorityBeReport: "被举报", - PriorityBeBlack: "被拉黑", - PriorityRecentlyPay: "近期充值", - PriorityNewUserType: "新用户", - PriorityAgainRefuse: "连续被拒", - PriorityDailyUserType: "每天新登陆用户", - PriorityActiveGrade: "活跃等级", - PriorityTradeUnion: "工会", - PriorityAgainSameSex: "连续同性", -} - -// 质量排序 -type ExcellentUserFormOriginType mysql.Type - -const ( - //被喜欢的次数 - ExcellentLikeMe ExcellentUserFormOriginType = 1 - //接收礼物数量 - ExcellentReceiveGiftNumChange ExcellentUserFormOriginType = 2 - //接收礼物次数 - ExcellentReceiveGiftFChange ExcellentUserFormOriginType = 3 - //被投诉次数 - ExcellentBeReport ExcellentUserFormOriginType = 4 - //被拉黑的次数 - ExcellentBeBlack ExcellentUserFormOriginType = 5 - //魅力等级 - ExcellentCharmGrade ExcellentUserFormOriginType = 6 - //被付费建立融云会话 - ExcellentSessionCreate ExcellentUserFormOriginType = 7 - //接通率 - ExcellentMatchConfirmRate ExcellentUserFormOriginType = 8 - //加时率(视频通话加时次数(免费加时成功 + 礼物加时成功)/视频通话次数(匹配成功的次数)) - ExcellentAddTimeRate ExcellentUserFormOriginType = 9 - //工会成员 - ExcellentTradeUnion ExcellentUserFormOriginType = 10 - //匹配成功次数 - ExcellentMatchSuccessNum ExcellentUserFormOriginType = 11 - //匹配确认次数 - ExcellentMatchConfirmNum ExcellentUserFormOriginType = 12 - //匹配免费加时的次数 - ExcellentMatchFreeTimeNum ExcellentUserFormOriginType = 13 - //匹配礼物加时次数 - ExcellentMatchGiftTimeNum ExcellentUserFormOriginType = 14 -) - -var ExcellentMap = map[ExcellentUserFormOriginType]string{ - ExcellentLikeMe: "喜欢我", - ExcellentReceiveGiftNumChange: "接收礼物数量", - ExcellentReceiveGiftFChange: "接收礼物次数", - ExcellentBeReport: "被投诉次数", - ExcellentBeBlack: "被拉黑次数", - ExcellentCharmGrade: "魅力等级", - ExcellentSessionCreate: "被付费建立融云会话", - ExcellentMatchConfirmRate: "接通率", - ExcellentAddTimeRate: "加时率", - ExcellentTradeUnion: "工会成员", - ExcellentMatchSuccessNum: "匹配成功次数", - ExcellentMatchConfirmNum: "匹配确认次数", - ExcellentMatchFreeTimeNum: "匹配免费加时次数", - ExcellentMatchGiftTimeNum: "匹配礼物加时次数", -} - -// 关系排序 -type RelationUserFormOriginType mysql.Type - -const ( - //喜欢的用户 - RelationUserLike RelationUserFormOriginType = 1 - //匹配拒绝用户 - RelationMatchRefuse RelationUserFormOriginType = 2 - //匹配过的用户 - RelationMatchUser RelationUserFormOriginType = 3 - //付费发送过消息但没进行过视频聊天 - RelationSessionNoMatchConfirm RelationUserFormOriginType = 4 - //上一次匹配的用户 - RelationMatchUserLastTime RelationUserFormOriginType = 5 -) - -var RelationMap = map[RelationUserFormOriginType]string{ - RelationUserLike: "喜欢的用户", - RelationMatchRefuse: "匹配被拒绝", - RelationMatchUser: "匹配上的用户", - RelationSessionNoMatchConfirm: "付费发送过消息但没进行过视频聊天", - RelationMatchUserLastTime: "上一次匹配的用户", -} - -/******匹配确认***********************************/ -type MatchConfirmStatus mysql.Type - -const ( - Success MatchConfirmStatus = 1 - Fail MatchConfirmStatus = 2 - Temp MatchConfirmStatus = 3 -) - -type MatchConfirmUserAcceptRefuse mysql.Type - -const ( - AcceptMatchConfirmUser MatchConfirmUserAcceptRefuse = 1 - RefuseMatchConfirmUser MatchConfirmUserAcceptRefuse = 2 -) - -type MatchCharmUserScoreDetailType = mysql.Type - -const ( - GiftReceiveCharmType MatchCharmUserScoreDetailType = 1 - GiftReceiveVipCharmType MatchCharmUserScoreDetailType = 2 -) - -type MatchWealthUserScoreDetailType = mysql.Type - -const ( - GiftReceiveWealthType MatchWealthUserScoreDetailType = 1 - GiftReceiveVipWealthType MatchWealthUserScoreDetailType = 2 -) diff --git a/_const/enum/res_e/enum.go b/_const/enum/res_e/enum.go index 4e6f79d..ef2d565 100755 --- a/_const/enum/res_e/enum.go +++ b/_const/enum/res_e/enum.go @@ -6,9 +6,6 @@ type MsgIdType = uint const ( DEFAULT_LANG = "en" - - MSG_ID_GAME_CREATE MsgIdType = 1001 - MSG_ID_GAME_JOIN MsgIdType = 1002 ) type ResMedalType = mysql.Type @@ -55,3 +52,9 @@ const ( type ResNameplateType = mysql.Type type ResNameplateObtainType = mysql.Type type ResNameplateScope = mysql.Type + +type ResUserBag = mysql.Type + +const ( + ResUserBagGift ResUserBag = 1 // 背包道具-礼物 +) diff --git a/cv/user_cv/bag.go b/cv/user_cv/bag.go new file mode 100644 index 0000000..0c03519 --- /dev/null +++ b/cv/user_cv/bag.go @@ -0,0 +1,17 @@ +package user_cv + +import ( + "git.hilo.cn/hilo-common/resource/mysql" + "hilo-user/_const/enum/res_e" +) + +type UserBag struct { + ResType res_e.ResUserBag `json:"resType"` // 道具类型 1:礼物道具 + ResId mysql.ID `json:"resId"` // 道具资源id + Name string `json:"name"` // 资源名称 + DiamondNum mysql.Num `json:"diamondNum"` // 钻石数量 + IconUrl string `json:"iconUrl"` // icon url + SvgaUrl string `json:"svgaUrl"` // svga url + Count mysql.Num `json:"count"` // 拥有数量 + RemainDays int `json:"remainDays"` // 有效天数 +} diff --git a/domain/model/bag_m/user_bag.go b/domain/model/bag_m/user_bag.go new file mode 100644 index 0000000..f1c16c1 --- /dev/null +++ b/domain/model/bag_m/user_bag.go @@ -0,0 +1,34 @@ +package bag_m + +import ( + "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/resource/mysql" + "hilo-user/_const/enum/res_e" + "time" +) + +type UserBag struct { + mysql.Entity + UserId mysql.ID + ResType mysql.Type + ResId mysql.ID + Count mysql.Num + EndTime time.Time +} + +// 获取用户有效的背包 +// param userId 用户id +// param resType 背包类型 1:礼物 +// condition +// 1.获取end_time未到期的 +// 2.数量大于0的 +func GetUserValidUserBag(model *domain.Model, userId mysql.ID, resType res_e.ResUserBag) ([]*UserBag, error) { + var res []*UserBag + if err := model.DB().Model(UserBag{}). + Where("end_time > ?", time.Now()). + Where("count > 0"). + Where("user_id = ?", userId).Find(&res).Error; err != nil { + return nil, err + } + return res, nil +} diff --git a/domain/model/res_m/gift.go b/domain/model/res_m/gift.go new file mode 100644 index 0000000..7c62fe8 --- /dev/null +++ b/domain/model/res_m/gift.go @@ -0,0 +1,38 @@ +package res_m + +import ( + "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/resource/mysql" +) + +type ResGift struct { + mysql.Entity + Name mysql.Str + IconUrl mysql.Str + SvagUrl mysql.Str + MusicUrl mysql.Str + Column uint16 + DiamondNum mysql.Num + BeanNum mysql.Num + ReceiveDiamondNum mysql.Num + Second mysql.Num // obsolete + N mysql.Num + GroupBroadcast bool + Cp bool + Together bool + Status mysql.UserYesNo + GiftType mysql.Type +} + +// 获取所有有效的礼物 +func FindValidResGiftsMap(model *domain.Model) (map[mysql.ID]ResGift, error) { + res := make(map[mysql.ID]ResGift, 0) + rows := make([]ResGift, 0) + if err := model.DB().Model(ResGift{}).Where("status = ?", mysql.USER).Find(&rows).Error; err != nil { + return nil, err + } + for i, v := range rows { + res[v.ID] = rows[i] + } + return res, nil +} diff --git a/route/router.go b/route/router.go index 5867d84..601d1f7 100755 --- a/route/router.go +++ b/route/router.go @@ -19,6 +19,7 @@ func InitRouter() *gin.Engine { user := v1.Group("/user") { user.GET("/nameplate", wrapper(user_r.UserNameplate)) + user.GET("/bag/:resType", wrapper(user_r.UserBag)) } inner := r.Group("/inner") inner.Use(ExceptionHandle, LoggerHandle) diff --git a/route/user_r/bag.go b/route/user_r/bag.go new file mode 100644 index 0000000..0819421 --- /dev/null +++ b/route/user_r/bag.go @@ -0,0 +1,64 @@ +package user_r + +import ( + "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/mycontext" + "github.com/gin-gonic/gin" + "hilo-user/_const/enum/res_e" + "hilo-user/cv/user_cv" + "hilo-user/domain/model/bag_m" + "hilo-user/domain/model/res_m" + "hilo-user/myerr/bizerr" + "hilo-user/req" + "hilo-user/resp" + "strconv" + "time" +) + +// @Tags 用户背包 +// @Summary 获取用户的铭牌 +// @Param column path int true "分栏:1 礼物" +// @Success 200 {object} []user_cv.UserBag +// @Router /v1/user/bag/{resType} [get] +func UserBag(c *gin.Context) (*mycontext.MyContext, error) { + myCtx := mycontext.CreateMyContext(c.Keys) + userId, err := req.GetUserId(c) + if err != nil { + return myCtx, err + } + model := domain.CreateModelContext(myCtx) + resType, err := strconv.Atoi(c.Param("resType")) + if err != nil { + return myCtx, err + } + var results []user_cv.UserBag + switch res_e.ResUserBag(resType) { + case res_e.ResUserBagGift: + userBagGifts, err := bag_m.GetUserValidUserBag(model, userId, res_e.ResUserBagGift) + if err != nil { + return myCtx, err + } + allValidGifts, err := res_m.FindValidResGiftsMap(model) + if err != nil { + return myCtx, err + } + for _, bagGift := range userBagGifts { + if gift, ok := allValidGifts[bagGift.ResId]; ok { + results = append(results, user_cv.UserBag{ + ResType: res_e.ResUserBagGift, + ResId: gift.ID, + Name: gift.Name, + DiamondNum: gift.DiamondNum, + IconUrl: gift.IconUrl, + SvgaUrl: gift.SvagUrl, + Count: bagGift.Count, + RemainDays: int(bagGift.EndTime.Sub(time.Now()).Hours() / 24), + }) + } + } + default: + return myCtx, bizerr.InvalidParameter + } + resp.ResponseOk(c, results) + return myCtx, nil +} diff --git a/route/user_r/user.go b/route/user_r/nameplate.go similarity index 100% rename from route/user_r/user.go rename to route/user_r/nameplate.go -- 2.22.0