feat(item_buy): 优化商品购买限额检查逻辑 - 修改购买黄金商品时的限额验证方式,直接检查单次购买数量是否超过限制 - 调整GoldLog.Cheak方法参数顺序,增加总量控制参数 - 更新错误返回条件,提高限额检查准确性 fix(player_service): 添加时间范围检查功能 - 引入utils工具包用于时间范围验证 - 在IsMatch方法中添加活动开始时间和结束时间的范围检查 - 如果当前时间不在活动时间内则返回匹配失败 refactor(gold_log):
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package service
|
||
|
||
import (
|
||
"blazing/cool"
|
||
"blazing/modules/player/model"
|
||
"time"
|
||
)
|
||
|
||
type GoldService struct {
|
||
BaseService
|
||
}
|
||
|
||
// 月 周 日限购检查
|
||
func (s *GoldService) Cheak(allcount, pid, ptye uint32) bool {
|
||
|
||
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, err := s.dbm_fix(s.Model).Where("year", now.Year()).Where("biz_id", pid).Wheref("consume ->> ?::integer = ?", ptye, va).Count()
|
||
if err != nil {
|
||
return false
|
||
}
|
||
if uint32(ret) < allcount {
|
||
return true
|
||
}
|
||
|
||
return false
|
||
|
||
}
|
||
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()},
|
||
},
|
||
}
|
||
|
||
}
|