109 lines
4.4 KiB
Go
109 lines
4.4 KiB
Go
package v1
|
||
|
||
import "github.com/gogf/gf/v2/frame/g"
|
||
|
||
// ============================================================================
|
||
// 工具额度与次数包
|
||
//
|
||
// 额度三池:免费 / 会员 / 付费(次数包),扣减顺序 免费 → 会员 → 付费。
|
||
// 周期为滚动窗口,默认 7 天,后台可给「全局 / 会员套餐 / 单个用户」分别调整。
|
||
// ============================================================================
|
||
|
||
// QuotaToolOut 单个工具的额度状态
|
||
type QuotaToolOut struct {
|
||
ToolKey string `json:"tool_key"`
|
||
Name string `json:"name"`
|
||
Icon string `json:"icon"`
|
||
FreeTotal int `json:"free_total"`
|
||
FreeUsed int `json:"free_used"`
|
||
FreeLeft int `json:"free_left"`
|
||
MemberTotal int `json:"member_total"`
|
||
MemberUsed int `json:"member_used"`
|
||
MemberLeft int `json:"member_left"`
|
||
PaidLeft int `json:"paid_left"` // 付费额度余额(次数)
|
||
PaidExpireAt string `json:"paid_expire_at"` // 付费额度到期日 yyyy-MM-dd
|
||
PayCost int `json:"pay_cost"` // 每次使用消耗的付费额度系数
|
||
IsMember bool `json:"is_member"`
|
||
PeriodDays int `json:"period_days"`
|
||
PeriodEnd string `json:"period_end"` // 当前周期结束时间
|
||
// Source 下一次扣减会命中的池:free / member / paid / none
|
||
Source string `json:"source"`
|
||
CanUse bool `json:"can_use"`
|
||
TotalLeft int `json:"total_left"` // 本周期内还能用几次(付费额度按系数折算)
|
||
Message string `json:"message"` // 额度用尽时的可读原因
|
||
}
|
||
|
||
// QuotaPackOut 次数包档位
|
||
type QuotaPackOut struct {
|
||
PackKey string `json:"pack_key"`
|
||
Name string `json:"name"`
|
||
Times int `json:"times"`
|
||
PriceCents int64 `json:"price_cents"`
|
||
ValidDays int `json:"valid_days"`
|
||
Badge string `json:"badge"`
|
||
ToolKey string `json:"tool_key"` // 空 = 通用档位(购买时选择工具)
|
||
UnitPriceCents int64 `json:"unit_price_cents"` // 每 100 次的均价(分),服务端算好避免前端浮点误差
|
||
}
|
||
|
||
// QuotaMyReq 我的额度总览
|
||
type QuotaMyReq struct {
|
||
g.Meta `path:"/quota/my" method:"get" tags:"quota" summary:"我的工具额度总览"`
|
||
}
|
||
type QuotaMyRes struct {
|
||
PeriodDays int `json:"period_days"`
|
||
IsMember bool `json:"is_member"`
|
||
LevelKey string `json:"level_key"`
|
||
LevelName string `json:"level_name"`
|
||
LevelExpireAt string `json:"level_expire_at"`
|
||
Tools []QuotaToolOut `json:"tools"`
|
||
TotalLeft int `json:"total_left"`
|
||
Packs []QuotaPackOut `json:"packs"`
|
||
}
|
||
|
||
// QuotaToolReq 单工具额度(进入工具页时查询,用于额度条与拦截提示)
|
||
type QuotaToolReq struct {
|
||
g.Meta `path:"/quota/tool" method:"get" tags:"quota" summary:"单个工具的额度状态"`
|
||
ToolKey string `v:"required#工具标识不能为空" json:"tool_key"`
|
||
}
|
||
type QuotaToolRes struct {
|
||
Tool *QuotaToolOut `json:"tool"`
|
||
}
|
||
|
||
// QuotaConsumeReq 扣减一次额度(在「产出结果」时调用,而不是打开页面时)
|
||
type QuotaConsumeReq struct {
|
||
g.Meta `path:"/quota/consume" method:"post" tags:"quota" summary:"扣减工具额度"`
|
||
ToolKey string `v:"required#工具标识不能为空" json:"tool_key"`
|
||
}
|
||
type QuotaConsumeRes struct {
|
||
Tool *QuotaToolOut `json:"tool"`
|
||
}
|
||
|
||
// QuotaPacksReq 某工具可购买的次数包档位
|
||
type QuotaPacksReq struct {
|
||
g.Meta `path:"/quota/packs" method:"get" tags:"quota" summary:"次数包档位(按工具)"`
|
||
ToolKey string `json:"tool_key"`
|
||
}
|
||
type QuotaPacksRes struct {
|
||
List []QuotaPackOut `json:"list"`
|
||
}
|
||
|
||
// QuotaOrderCreateReq 创建次数包订单(支付参数与会员套餐完全同构)
|
||
type QuotaOrderCreateReq struct {
|
||
g.Meta `path:"/quota/order" method:"post" tags:"quota" summary:"创建次数包订单(返回支付参数)"`
|
||
PackKey string `v:"required#请选择次数包" json:"pack_key"`
|
||
ToolKey string `v:"required#请选择要购买的次数包工具" json:"tool_key"`
|
||
Code string `json:"code"`
|
||
}
|
||
type QuotaOrderCreateRes struct {
|
||
OutTradeNo string `json:"out_trade_no"`
|
||
Mode string `json:"mode"`
|
||
SignData string `json:"signData"`
|
||
PaySig string `json:"paySig"`
|
||
Signature string `json:"signature"`
|
||
Env int `json:"env"`
|
||
PackKey string `json:"pack_key"`
|
||
ToolKey string `json:"tool_key"`
|
||
Times int `json:"times"`
|
||
ValidDays int `json:"valid_days"`
|
||
}
|