You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package cachecurd
|
|
|
|
import (
|
|
"joybuywork/internal/repository/dao"
|
|
"joybuywork/internal/repository/mtype"
|
|
"joybuywork/internal/utils/lockdo"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
tCoinScene = "coinScene" // 金币池场次数据
|
|
)
|
|
|
|
const (
|
|
CoinSceneUserCoin = "user_coin" // 投入金币总数
|
|
CoinSceneJoinNum = "join_num" // 投入总次数
|
|
CoinSceneJoinUserNum = "join_user_num" // 投入总人数
|
|
CoinSceneGetNum = "get_num" // 领奖总人数
|
|
CoinSceneGetTotal = "get_total" // 领奖金币数
|
|
)
|
|
|
|
// 激励养成奖品选择人数
|
|
func (s *HMap) coinScene(cond *HMapBuild) (err error) {
|
|
err = lockdo.ExistDo(s.ctx, s.key, func(exist bool) (err error) {
|
|
if exist {
|
|
return
|
|
}
|
|
|
|
m := dao.FissionCoin
|
|
var total struct {
|
|
UserCoin int64 `json:"user_coin"`
|
|
JoinNum int64 `json:"join_num"`
|
|
JoinUserNum int64 `json:"join_user_num"`
|
|
}
|
|
|
|
err = m.WithContext(s.ctx).
|
|
Select(
|
|
m.UseCoin.Sum().As("user_coin"),
|
|
m.UseNum.Sum().As("join_num"),
|
|
m.UserID.Count().As("join_user_num"),
|
|
).
|
|
Where(m.SceneID.Eq(cond.SceneId), m.UseNum.Gt(0)).
|
|
Scan(&total)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
var getTotal struct {
|
|
GetNum int64 `json:"get_num"`
|
|
GetCoin int64 `json:"get_coin"`
|
|
}
|
|
err = m.WithContext(s.ctx).
|
|
Select(
|
|
m.GetCoin.Sum().As("get_coin"),
|
|
m.UserID.Count().As("get_num"),
|
|
).
|
|
Where(m.SceneID.Eq(cond.SceneId), m.Status.Eq(mtype.FissionCoinStatusOk)).
|
|
Scan(&getTotal)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// 这里初始化一下内存数据
|
|
s.data = make(map[string]string, 4)
|
|
|
|
return s.Set(
|
|
CoinSceneUserCoin, fmt.Sprint(total.UserCoin),
|
|
CoinSceneJoinNum, fmt.Sprint(total.JoinNum),
|
|
CoinSceneGetNum, fmt.Sprint(getTotal.GetNum),
|
|
CoinSceneJoinUserNum, fmt.Sprint(total.JoinUserNum),
|
|
CoinSceneGetTotal, fmt.Sprint(getTotal.GetCoin),
|
|
)
|
|
})
|
|
|
|
return
|
|
}
|