diff --git a/cv/user_cv/bag.go b/cv/user_cv/bag.go index e33a6385d1cc0e7fc818a7743d2d99a009d9ecf0..42033151f33ea75da6d6ccd44ecbc6aa128c943e 100644 --- a/cv/user_cv/bag.go +++ b/cv/user_cv/bag.go @@ -16,6 +16,7 @@ type UserBag struct { Count mysql.Num `json:"count"` // 拥有数量 RemainDays int `json:"remainDays"` // 有效天数 TextStyleList []*TextStyle `json:"textStyleList"` // 文本样式 + HasGiftText bool `json:"hasGiftText"` // 是否有礼物文字 } type TextStyle struct { diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 8ac46fd8d8af759ec6e29af92cd814c0721ba760..6e09de77dc321ee9a5bb0d8b90751cb0ac04299f 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -151,11 +151,15 @@ func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error) //rp := res_m.ResProperty{} //properties, err := rp.GetAll(mysql.Db) - _, myArea, err := user_m.GetUserCountryArea(domain.CreateModelNil(), myUserId) - if err != nil { - return nil, err + propertiesArea := make(map[int]map[uint64]property_cv.CvProperty) + for _, v := range []int{1, 2} { + properties, err := GetPropertyAll(mysql.Db, v) + if err != nil { + return nil, err + } + propertiesArea[v] = properties } - properties, err := GetPropertyAll(mysql.Db, myArea) + areaMap, err := user_m.GetUserAreaMap(domain.CreateModelNil(), userIds) if err != nil { return nil, err } @@ -173,6 +177,7 @@ func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error) cvUserBases := []*CvUserBase{} for i := 0; i < len(users); i++ { user := users[i] + properties := propertiesArea[areaMap[user.ID]] invisible := IfLogout(user.LogoutTime) invisibleAvatar := "" invisibleNick := user.Code diff --git a/domain/model/res_m/gift.go b/domain/model/res_m/gift.go index 79f1776dd0cee90c5ceced2d44bbbc8fc62f12c8..78bc0f8e4201aa28fc9d4722ce58e7e3ec964bd4 100644 --- a/domain/model/res_m/gift.go +++ b/domain/model/res_m/gift.go @@ -22,6 +22,7 @@ type ResGift struct { Together bool Status mysql.UserYesNo GiftType mysql.Type + HasGiftText bool } // 获取所有的礼物 diff --git a/domain/model/user_m/user.go b/domain/model/user_m/user.go index 15ee7d8d4428e36e28f1425d3784897da24204da..a9863ca6b8fb8f8a37d1fb5c88534eb9ac64b101 100755 --- a/domain/model/user_m/user.go +++ b/domain/model/user_m/user.go @@ -157,3 +157,21 @@ func GetUserCountryArea(model *domain.Model, userId mysql.ID) (string, int, erro } return res.Name, res.Area, nil } + +//获取用户的国家所属的区域(是否阿语区) +func GetUserAreaMap(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]int, error) { + type info struct { + Id mysql.ID + Area int + } + rows := make([]*info, 0) + sql := "select user.id, rc.area from user left join res_country rc on user.country = rc.name where user.id in (?);" + if err := model.DB().Raw(sql, userIds).Scan(&rows).Error; err != nil { + return nil, myerr.WrapErr(err) + } + res := make(map[mysql.ID]int) + for _, v := range rows { + res[v.Id] = v.Area + } + return res, nil +} diff --git a/domain/service/user_s/user.go b/domain/service/user_s/user.go index 71cc8c4e22f5a2f060f23df0d70f931a63105193..de797c426c033239e7d75d418e94481f67b4c48e 100644 --- a/domain/service/user_s/user.go +++ b/domain/service/user_s/user.go @@ -172,11 +172,11 @@ func (s *UserService) GetUserDetail(userId mysql.ID, myUserId mysql.ID, lang str //rp := res_m.ResProperty{} //properties, err := rp.GetAll(mysql.Db) - _, myArea, err := user_m.GetUserCountryArea(model, myUserId) + _, area, err := user_m.GetUserCountryArea(model, userId) if err != nil { return nil, err } - properties, err := property_cv.GetPropertyAll(mysql.Db, myArea) + properties, err := property_cv.GetPropertyAll(mysql.Db, area) if err != nil { return nil, err } diff --git a/resp/response.go b/resp/response.go index e4b2784bfbc40691e2930293b0669185c379959c..e28a88d7afda9b4ba0a3c8cb8a48882cf2dfa1cc 100755 --- a/resp/response.go +++ b/resp/response.go @@ -3,6 +3,7 @@ package resp import ( "encoding/json" "git.hilo.cn/hilo-common/mycontext" + "git.hilo.cn/hilo-common/utils" "github.com/gin-gonic/gin" "hilo-user/myerr" "hilo-user/req" @@ -15,6 +16,7 @@ type Response struct { MessageData interface{} `json:"messageData"` // 消息详情 OperationMessage interface{} `json:"operationMessage"` // 操作消息 Data interface{} `json:"data"` // 数据 + Edata interface{} `json:"edata"` // 加密数据 } type GameResponse struct { @@ -36,7 +38,12 @@ func ResponseOk(c *gin.Context, data interface{}) { Code: myerr.GetSuccessCode(), Message: myerr.GetSuccessMsg(), OperationMessage: myerr.GetSuccessMsg(), - Data: data, + } + if _, ok := c.Get(mycontext.InnerEncrypt); ok { + //response.Edata = utils.EncryptionData(data, []byte("484194d4d0f968a7")) + response.Edata = utils.EncryptionData(data, []byte("hilo!@#$%^&*()_+")) + } else { + response.Data = data } printResponseBody(c, &response) @@ -50,15 +57,21 @@ func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, has if data == nil { data = make([]interface{}, 0) } + pageData := req.PageRespBase{ + NextPageIndex: nextPageIndex, + HasNextPage: hasNextPage, + Data: data, + } response := Response{ Code: myerr.GetSuccessCode(), Message: myerr.GetSuccessMsg(), OperationMessage: myerr.GetSuccessMsg(), - Data: req.PageRespBase{ - NextPageIndex: nextPageIndex, - HasNextPage: hasNextPage, - Data: data, - }, + } + if _, ok := c.Get(mycontext.InnerEncrypt); ok { + //response.Edata = utils.EncryptionData(data, []byte("484194d4d0f968a7")) + response.Edata = utils.EncryptionData(pageData, []byte("hilo!@#$%^&*()_+")) + } else { + response.Data = pageData } c.JSON(http.StatusOK, response) } diff --git a/route/middleHandle.go b/route/middleHandle.go index 8cc05d91f16c0831d5b533a3f46fcabecf0aa19e..58f30c087e843c2c96b1a6f0dde9ea5e925b1c39 100755 --- a/route/middleHandle.go +++ b/route/middleHandle.go @@ -7,6 +7,7 @@ import ( "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/resource/config" + "git.hilo.cn/hilo-common/utils" "github.com/gin-gonic/gin" "hilo-user/myerr/bizerr" "hilo-user/req" @@ -137,6 +138,18 @@ func LoggerHandle(c *gin.Context) { mycontext.CreateMyContext(c.Keys).Log.Infof("request end fullPath:%v,url:%v, method: %v, traceId:%v, latency:%v userId:%v", c.FullPath(), reqUri, method, traceId, latency, userId) } +// 加密Handle +func EncryptHandle(c *gin.Context) { + header := c.Request.Header + appVersion := header.Get("Appversion") + if len(appVersion) > 0 { + if high, _ := utils.CompareVersion(appVersion, "> 3.9.0"); high { + c.Set(mycontext.InnerEncrypt, true) + } + } + c.Next() +} + //http信息解密(web) func HttpWebSecretHandle(c *gin.Context) { traceId, _ := c.Keys[mycontext.TRACEID] diff --git a/route/router.go b/route/router.go index 040479a1fee2c729fbbd59581d4e985b89ed1c5d..fb2d73520190b9401a6509e7563c8354b0e2456a 100755 --- a/route/router.go +++ b/route/router.go @@ -29,8 +29,8 @@ func InitRouter() *gin.Engine { { user.GET("/nameplate", wrapper(user_r.UserNameplate)) user.GET("/bag/:resType", wrapper(user_r.UserBag)) - user.GET("/detail", wrapper(user_r.UserDetail)) - user.GET("/detail/:userExternalId", wrapper(user_r.UserDetailByExternalId)) + user.GET("/detail", EncryptHandle, wrapper(user_r.UserDetail)) + user.GET("/detail/:userExternalId", EncryptHandle, wrapper(user_r.UserDetailByExternalId)) } cp := v2.Group("/cp") { diff --git a/route/user_r/bag.go b/route/user_r/bag.go index 3d83b3395bcbb6165f0066b6409d6ac626d958c1..bd539cc919c3a25c914acf4616df1c287ad24843 100644 --- a/route/user_r/bag.go +++ b/route/user_r/bag.go @@ -46,22 +46,24 @@ func UserBag(c *gin.Context) (*mycontext.MyContext, error) { for _, bagGift := range userBagGifts { if gift, ok := allGifts[bagGift.ResId]; ok { info := user_cv.UserBag{ - BagId: bagGift.ID, - ResType: res_e.ResUserBagGift, - ResId: gift.ID, - GiftId: 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), + BagId: bagGift.ID, + ResType: res_e.ResUserBagGift, + ResId: gift.ID, + GiftId: 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), + HasGiftText: gift.HasGiftText, } - if gift.ID == cp_e.CpConfessionGiftId { // 如果是cp告白礼物 + if gift.ID == cp_e.CpConfessionGiftId || gift.HasGiftText { // 如果是cp告白礼物 info.TextStyleList = make([]*user_cv.TextStyle, 0, 2) info.TextStyleList = append(info.TextStyleList, &user_cv.TextStyle{TextColor: "#ce0083", TextSize: 20, TextKey: "sender_name"}, &user_cv.TextStyle{TextColor: "#ce0083", TextSize: 20, TextKey: "receiver_name"}, + &user_cv.TextStyle{TextColor: "#FFFFFF", TextSize: 40, TextKey: "gift_text"}, ) }