package cp_r import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/resource/mysql" "github.com/gin-gonic/gin" "hilo-user/_const/enum/cp_e" "hilo-user/cv/cp_cv" "hilo-user/cv/user_cv" "hilo-user/domain/model/cp_m" "hilo-user/domain/model/user_m" "hilo-user/myerr/bizerr" "hilo-user/req" "hilo-user/resp" ) // @Tags CP v2 // @Summary cp空间 // @Param token header string true "token" // @Param nonce header string true "随机数字" // @Param externalId query string true "查看用户的externalId" // @Success 200 {object} cp_cv.CvSpace // @Router /v2/cp/space [get] func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { myContext := mycontext.CreateMyContext(c.Keys) userId, lang, err := req.GetUserIdLang(c, myContext) if err != nil { return myContext, err } externalId := c.Query("externalId") if len(externalId) <= 0 { return myContext, bizerr.InvalidParameter } var model = domain.CreateModelContext(myContext) userInfo, err := user_m.GetUser(model, userId) if err != nil { return myContext, err } cpUserInfo, err := user_m.GetUserByExtId(model, externalId) // todo get from cp2 db if err != nil { return myContext, err } expireAt := "" // todo cpLevel := cp_e.CpLevel5 // todo get from db nextPoints := cp_e.CpLevelPoints[cp_e.CpLevelMax] remainPoints := mysql.Num(0) if cpLevel != cp_e.CpLevelMax { nextPoints = cp_e.CpLevelPoints[cpLevel+1] remainPoints = nextPoints - cp_e.CpLevelPoints[cpLevel] // todo get from db } privilegeList := cp_cv.CopyCpLevelPrivilegeList(cpLevel, lang) userPrivileges, err := cp_m.MGetUserSvipPrivilege(model, []uint64{userId}) if err != nil { return myContext, err } for i, v := range privilegeList { if v.CanSwitch { privilegeList[i].UserSwitch = userPrivileges[userId][v.Type] } } response := cp_cv.CvSpace{ CpInfo: cp_cv.CvCpInfo{ UserInfo: user_cv.UserToTiny(*userInfo), CpUserInfo: user_cv.UserToTiny(*cpUserInfo), }, CpLevel: cp_cv.CvCpLevel{ Level: cpLevel, Points: cp_e.CpLevelPoints[cpLevel], // todo get from db NextPoints: nextPoints, RemainPoints: remainPoints, ExpireAt: expireAt, }, ResLevelList: cp_cv.CvResLevelList, PrivilegeList: privilegeList, } resp.ResponseOk(c, response) return myContext, nil } type CpPrivilegeOpenCloseReq struct { Type cp_e.CpPrivilege `form:"type" binding:"required"` OpenClose mysql.OpenClose `form:"openClose" binding:"required"` } // @Tags CP v2 // @Summary cp特权开关 // @Param token header string true "token" // @Param nonce header string true "随机数字" // @Param type formData int true "1.空间 2.横幅 3.等级勋章 4.证书 5.进场特效 6.头像头饰 7.动态资料卡 8.麦位特效" // @Param openClose formData int true "1:open 2:close" // @Success 200 // @Router /v2/cp/privilege/openClose [put] func CpPrivilegeOpenClose(c *gin.Context) (*mycontext.MyContext, error) { myCtx := mycontext.CreateMyContext(c.Keys) var request CpPrivilegeOpenCloseReq if err := c.ShouldBind(&request); err != nil { return myCtx, err } userId, err := req.GetUserId(c) if err != nil { return myCtx, err } var model = domain.CreateModelContext(myCtx) if err := cp_m.OpenCLoseUserSvipPrivilege(model, userId, request.Type, request.OpenClose); err != nil { return myCtx, err } resp.ResponseOk(c, "") return myCtx, nil }