space.go 1.99 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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/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
44 45 46 47 48 49
	cpLevel := cp_e.CpLevel3 // 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
hujiebin's avatar
hujiebin committed
50 51 52 53 54 55
	}
	response := cp_cv.CvSpace{
		CpInfo: cp_cv.CvCpInfo{
			UserInfo:   user_cv.UserToTiny(*userInfo),
			CpUserInfo: user_cv.UserToTiny(*cpUserInfo),
		},
56 57 58 59 60 61
		CpLevel: cp_cv.CvCpLevel{
			Level:        cpLevel,
			Points:       cp_e.CpLevelPoints[cpLevel], // todo get from db
			NextPoints:   nextPoints,
			RemainPoints: remainPoints,
			ExpireAt:     expireAt,
hujiebin's avatar
hujiebin committed
62
		},
63 64
		ResLevelList:  cp_cv.CvResLevelList,
		PrivilegeList: cp_cv.CopyCpLevelPrivilegeList(cpLevel, lang),
hujiebin's avatar
hujiebin committed
65 66 67 68
	}
	resp.ResponseOk(c, response)
	return myContext, nil
}