```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(shop): 添加商品限购功能并优化购买逻辑

- 修改购买黄金商品接口,添加商品配额检查功能
- 新增月、周、日三种限购类型检查逻辑
- 当商品超出库存或达到购买限制时返回相应错误码
- 移除gold_log表中PlayerID字段的唯一索引约束
- 修复GoldService中的Cheak方法实现,支持多种时间维度限购检查
```
This commit is contained in:
昔念
2026-02-27 00:09:23 +08:00
parent e4ad1745d4
commit a210d653d2
3 changed files with 28 additions and 6 deletions

View File

@@ -95,8 +95,14 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player.
//product, exists := xmlres.GoldProductMap[int(data.ProductID)]
pro := service.NewShopService().Get(data.ProductID)
if pro == nil {
return nil, errorcode.ErrorCodes.ErrSystemError
return nil, errorcode.ErrorCodes.ErrTooManyProducts
}
if pro.QuotaType != 0 {
if player.Service.GoldLog.Cheak(data.ProductID, pro.QuotaType-1)+int(data.Count) > int(pro.QuotaLimit) {
return nil, errorcode.ErrorCodes.ErrExceedStock
}
}
var usegold uint64
var addSuccess bool
switch data.Type {

View File

@@ -14,7 +14,7 @@ const (
type GoldBeanConsume struct {
*cool.Model
PlayerID uint64 `gorm:"not null;uniqueIndex;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
ConsumeNum uint32 `gorm:"not null;default:0;comment:'消费数量'" json:"consume_num" description:"消费数量"`
BizID uint32 `gorm:"not null;default:0;comment:'关联业务ID如道具ID/扭蛋池ID无则填0'" json:"biz_id" description:"关联业务ID"`
///消费年份

View File

@@ -10,13 +10,29 @@ type GoldService struct {
BaseService
}
func (s *GoldService) Cheak(pid, count uint32) {
// 月 周 日限购检查
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
}
// if cool.Config.ServerInfo.IsVip != 0 {
// return
// }
// 获取当前时间
now := time.Now()