Files
sundynix-pets/pets-be/internal/service/pro.go
T
Blizzard 609f7d06cf init: 毛孩子计划 小程序 + Go 后端 + 内嵌后台
- pets-fe: 微信原生小程序(首页/计划/记录/报告/社区/引导),
  服务端驱动、无假数据;弹层改用 scroll-view,打开时隐藏自定义 tabBar
- pets-be: Gin + GORM(MySQL, sundynix_ 前缀) + MinIO,统一响应/分页,
  微信 code2session 登录,provider-neutral AI(DeepSeek),go:embed React 后台
- 修复:分段选择类型不匹配(字符串 vs 数字)导致选不中

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 15:36:55 +08:00

63 lines
1.6 KiB
Go

package service
import (
"time"
"gorm.io/gorm"
"github.com/sundynix/pets-be/internal/model"
)
// ProFeatures Pro 权益列表
var ProFeatures = []string{
"365 天养宠计划",
"多宠物管理",
"月度成长报告",
"PDF 健康档案",
"年度养宠账单",
}
// ProInfo Pro 状态 + 权益
type ProInfo struct {
Status string `json:"status"`
PlanType string `json:"plan_type"`
Price float64 `json:"price"`
EndDate *time.Time `json:"end_date"`
Features []string `json:"features"`
}
// GetPro 取会员信息
func (s *Service) GetPro(userID uint) (*ProInfo, error) {
var m model.ProMembership
err := s.db.Where("user_id = ?", userID).First(&m).Error
if err == gorm.ErrRecordNotFound {
return &ProInfo{Status: model.ProNone, Features: ProFeatures}, nil
}
if err != nil {
return nil, err
}
return &ProInfo{Status: m.Status, PlanType: m.PlanType, Price: m.Price, EndDate: m.EndDate, Features: ProFeatures}, nil
}
// ActivatePro 开通年费会员
func (s *Service) ActivatePro(userID uint) (*ProInfo, error) {
now := time.Now()
end := now.AddDate(1, 0, 0)
var m model.ProMembership
err := s.db.Where("user_id = ?", userID).First(&m).Error
if err == gorm.ErrRecordNotFound {
m = model.ProMembership{UserID: userID}
} else if err != nil {
return nil, err
}
m.Status = model.ProActive
m.PlanType = "yearly"
m.Price = 29.9
m.StartDate = &now
m.EndDate = &end
if err := s.db.Save(&m).Error; err != nil {
return nil, err
}
return &ProInfo{Status: m.Status, PlanType: m.PlanType, Price: m.Price, EndDate: m.EndDate, Features: ProFeatures}, nil
}