Files
sundynix-pets/pets-be/internal/service/service.go
T
Blizzard 77beb9ca96 fix(pro): 会员改为「即将开放」,堵住点一下白拿会员的漏洞
原先 /api/pro/activate 直接写库开通一年会员,没有任何支付校验,
任何人调一次接口就是会员。支付暂不接入,这里必须在服务端拒绝,
只改 UI 挡不住直接调接口。

- ActivatePro 一律返回 ErrPayNotReady;真正写库的逻辑保留为
  activateProAfterPaid,等接微信支付时在校验支付单据后调用
- handler 对该错误返回参数错而非 500,前端直接展示提示文案
- 小程序 Pro 弹层按钮置灰为「即将开放」,我的页入口改为
  「Pro 会员(即将开放)」

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-25 18:15:38 +08:00

45 lines
1.2 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 (
"errors"
"gorm.io/gorm"
"github.com/sundynix/pets-be/internal/ai"
"github.com/sundynix/pets-be/internal/config"
"github.com/sundynix/pets-be/internal/model"
"github.com/sundynix/pets-be/internal/storage"
)
// ErrNotFound 资源不存在(handler 据此返回 40400
var ErrNotFound = errors.New("not found")
// ErrPayNotReady 支付未接入。会员开通必须走真实支付,未接入前一律拒绝,
// 避免「点一下白拿会员」。
var ErrPayNotReady = errors.New("支付功能即将开放,敬请期待")
// Service 业务逻辑聚合,方法按领域分散在各文件
type Service struct {
db *gorm.DB
storage *storage.Storage
cfg *config.Config
ai *ai.Engine
}
func New(db *gorm.DB, st *storage.Storage, cfg *config.Config, engine *ai.Engine) *Service {
return &Service{db: db, storage: st, cfg: cfg, ai: engine}
}
// ownedPet 校验宠物归属当前用户并返回
func (s *Service) ownedPet(userID, petID string) (*model.Pet, error) {
var pet model.Pet
err := s.db.Where("id = ? AND user_id = ?", petID, userID).First(&pet).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, ErrNotFound
}
if err != nil {
return nil, err
}
return &pet, nil
}