Files
bl/modules/player/service/gold_log.go
昔念 741b938587
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
1
2026-02-27 01:00:01 +08:00

71 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/cool"
"blazing/modules/player/model"
"time"
)
type GoldService struct {
BaseService
}
// 月 周 日限购检查
func (s *GoldService) Cheak(pid, ptye uint32) int {
now := time.Now()
var va int
switch ptye {
case 0: //月限购
va = int(now.Month())
case 1: //周限购
_, va = now.ISOWeek()
case 2: //日限购
va = now.Day()
}
ret, _ := s.dbm_fix(s.Model).Where("year", now.Year()).Where("biz_id", pid).Wheref("consume ->> ?::integer = ?", ptye, va).Count()
return ret
}
func (s *GoldService) Log(pid, count uint32) {
if cool.Config.ServerInfo.IsVip != 0 {
return
}
// 获取当前时间
now := time.Now()
// 提取年份
year := uint32(now.Year())
// 构造消费时间数组 [月, 周, 日]
// ISOWeek返回周数这里只取周数Day()返回当月的第几天
_, week := now.ISOWeek()
consumeTime := []uint32{
uint32(now.Month()), // 月份
uint32(week), // 周数
uint32(now.Day()), // 日期
}
record := &model.GoldBeanConsume{
PlayerID: uint64(s.userid),
ConsumeNum: count,
BizID: pid,
Year: year, // 补充年份
Consume: consumeTime, // 补充消费时间(月-周-日)
}
s.dbm(s.Model).Data(record).Insert()
}
func NewGoldService(id uint32) *GoldService {
return &GoldService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewGoldBeanConsume()},
},
}
}