medal.go 2 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
package medal_cv

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"gorm.io/gorm"
	"hilo-group/cv/gift_cv"
	"hilo-group/domain/model/res_m"
	"sort"
)

type CvMedal struct {
	Id        uint32    `json:"id"`
	PicUrl    mysql.Str `json:"picUrl"`
	EffectUrl mysql.Str `json:"effectUrl"`
}

type ReturnGroupMedal struct {
	PicUrl  string `json:"picUrl"`
	SvgaUrl string `json:"svgaUrl"`
}

// 查询群流水勋章
func GetGroupConsumeMedal(model *domain.Model, groupId string) (uint64, *PicElement, error) {
	consumeTotal, err := gift_cv.GetGroupConsumeTotal(model, groupId)
	if err != nil {
		return 0, nil, err
	}
	rec, err := res_m.GetRoomMedalConfig(model.Db)
	if err != nil {
		return consumeTotal, nil, err
	}
	// 只显示最高等级的,所以要倒序遍历
	for i := len(rec) - 1; i >= 0; i-- {
		if consumeTotal >= rec[i].Threshold {
			return consumeTotal, &PicElement{PicUrl: rec[i].ActiveUrl}, nil
		}
	}
	return consumeTotal, nil, nil
}

type PicElement struct {
	PicUrl  string `json:"picUrl"`
	SvgaUrl string `json:"svgaUrl"`
}

func GetMedalInfoMap(db *gorm.DB, medals map[uint64][]uint32) (map[uint64][]uint32, map[uint64][]CvMedal, error) {
	resMedals, err := res_m.MedalGetAllMap(db)
	if err != nil {
		return nil, nil, err
	}

	medalIds := make(map[uint64][]uint32)
	medalMap := make(map[uint64][]CvMedal, 0)

	// 只选择合法的勋章
	for u, i := range medals {
		medalIds[u] = make([]uint32, 0)
		medalMap[u] = make([]CvMedal, 0)

		for _, j := range i {
			if e, ok := resMedals[j]; ok {
				medalIds[u] = append(medalIds[u], j)
				medalMap[u] = append(medalMap[u], CvMedal{
					Id:        j,
					PicUrl:    e.PicUrl,
					EffectUrl: e.SvgaUrl,
				})
			}
		}
		// 按照勋章排序
		sort.Slice(medalIds[u], func(i, j int) bool {
			return resMedals[medalIds[u][i]].Sort < resMedals[medalIds[u][j]].Sort
		})

		sort.Slice(medalMap[u], func(i, j int) bool {
			return resMedals[medalMap[u][i].Id].Sort < resMedals[medalMap[u][j].Id].Sort
		})
	}
	return medalIds, medalMap, nil
}