From 672274f9fdbea1c8632a2ec71ecbc80d0209d28c Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 4 Mar 2026 11:35:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E5=A5=97?= =?UTF-8?q?=E9=A4=90=E7=B3=BB=E5=88=97=E5=88=86=E9=85=8D=E5=92=8C=E5=A5=97?= =?UTF-8?q?=E9=A4=90=E6=A8=A1=E5=9E=8B=EF=BC=8C=E6=94=AF=E6=8C=81=E6=A2=AF?= =?UTF-8?q?=E5=BA=A6=E4=BD=A3=E9=87=91=E5=92=8C=E4=BB=A3=E7=90=86=E5=BC=BA?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ShopSeriesAllocation 新增 commission_tiers_json(梯度模式专属阶梯 JSON)、enable_force_recharge(代理自设强充开关)、force_recharge_amount(强充金额,0 表示使用阈值)字段;移除与 PackageSeries 重复的三个字段。Package 模型补充 PackageSeriesID 字段,用于系列授权套餐归属校验。 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- internal/model/package.go | 6 +++ internal/model/shop_series_allocation.go | 59 +++++++++++++++++++----- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/internal/model/package.go b/internal/model/package.go index 6cce6bc..51c23ae 100644 --- a/internal/model/package.go +++ b/internal/model/package.go @@ -119,6 +119,7 @@ type OneTimeCommissionConfig struct { // OneTimeCommissionTier 一次性佣金梯度配置 type OneTimeCommissionTier struct { + Operator string `json:"operator"` // 阈值比较运算符:>、>=、<、<=,空值默认 >= Dimension string `json:"dimension"` StatScope string `json:"stat_scope"` Threshold int64 `json:"threshold"` @@ -141,6 +142,11 @@ const ( TierTypeSalesCount = "sales_count" TierTypeSalesAmount = "sales_amount" + // 阈值运算符常量 + TierOperatorGT = ">" + TierOperatorGTE = ">=" + TierOperatorLT = "<" + TierOperatorLTE = "<=" ) func (ps *PackageSeries) GetOneTimeCommissionConfig() (*OneTimeCommissionConfig, error) { diff --git a/internal/model/shop_series_allocation.go b/internal/model/shop_series_allocation.go index 00356f8..f47ab40 100644 --- a/internal/model/shop_series_allocation.go +++ b/internal/model/shop_series_allocation.go @@ -1,25 +1,60 @@ package model import ( + "encoding/json" + "gorm.io/gorm" ) +// ShopSeriesAllocation 店铺系列分配模型 +// 记录平台或上级代理授权给某代理店铺可销售的套餐系列,以及佣金上限配置 type ShopSeriesAllocation struct { gorm.Model - BaseModel `gorm:"embedded"` - ShopID uint `gorm:"column:shop_id;index;not null;comment:被分配的店铺ID" json:"shop_id"` - SeriesID uint `gorm:"column:series_id;index;not null;comment:套餐系列ID" json:"series_id"` - AllocatorShopID uint `gorm:"column:allocator_shop_id;index;not null;default:0;comment:分配者店铺ID,0表示平台分配" json:"allocator_shop_id"` - OneTimeCommissionAmount int64 `gorm:"column:one_time_commission_amount;type:bigint;default:0;not null;comment:该代理能拿的一次性佣金金额上限(分)" json:"one_time_commission_amount"` - EnableOneTimeCommission bool `gorm:"column:enable_one_time_commission;default:false;not null;comment:是否启用一次性佣金" json:"enable_one_time_commission"` - OneTimeCommissionTrigger string `gorm:"column:one_time_commission_trigger;type:varchar(50);comment:一次性佣金触发类型" json:"one_time_commission_trigger"` - OneTimeCommissionThreshold int64 `gorm:"column:one_time_commission_threshold;type:bigint;default:0;not null;comment:一次性佣金触发阈值(分)" json:"one_time_commission_threshold"` - EnableForceRecharge bool `gorm:"column:enable_force_recharge;default:false;not null;comment:是否启用强制充值" json:"enable_force_recharge"` - ForceRechargeAmount int64 `gorm:"column:force_recharge_amount;type:bigint;default:0;not null;comment:强制充值金额(分)" json:"force_recharge_amount"` - ForceRechargeTriggerType int `gorm:"column:force_recharge_trigger_type;type:int;default:2;not null;comment:强充触发类型 1-单次充值 2-累计充值" json:"force_recharge_trigger_type"` - Status int `gorm:"column:status;type:int;default:1;not null;comment:状态 1-启用 2-禁用" json:"status"` + BaseModel `gorm:"embedded"` + ShopID uint `gorm:"column:shop_id;index;not null;comment:被分配的店铺ID" json:"shop_id"` + SeriesID uint `gorm:"column:series_id;index;not null;comment:套餐系列ID" json:"series_id"` + AllocatorShopID uint `gorm:"column:allocator_shop_id;index;not null;default:0;comment:分配者店铺ID,0表示平台分配" json:"allocator_shop_id"` + OneTimeCommissionAmount int64 `gorm:"column:one_time_commission_amount;type:bigint;default:0;not null;comment:该代理能拿的一次性佣金金额上限(分),固定模式有效" json:"one_time_commission_amount"` + CommissionTiersJSON string `gorm:"column:commission_tiers_json;type:jsonb;default:'[]';not null;comment:梯度模式专属阶梯金额列表" json:"commission_tiers_json"` + EnableForceRecharge bool `gorm:"column:enable_force_recharge;default:false;not null;comment:是否启用强制充值" json:"enable_force_recharge"` + ForceRechargeAmount int64 `gorm:"column:force_recharge_amount;type:bigint;default:0;not null;comment:强制充值金额(分)" json:"force_recharge_amount"` + ForceRechargeTriggerType int `gorm:"column:force_recharge_trigger_type;type:int;default:2;not null;comment:强充触发类型 1-单次充值 2-累计充值" json:"force_recharge_trigger_type"` + Status int `gorm:"column:status;type:int;default:1;not null;comment:状态 1-启用 2-禁用" json:"status"` } +// TableName 指定表名 func (ShopSeriesAllocation) TableName() string { return "tb_shop_series_allocation" } + +// AllocationCommissionTier 代理专属梯度佣金档位(仅存金额,阈值和运算符从 PackageSeries 全局配置读取) +type AllocationCommissionTier struct { + Threshold int64 `json:"threshold"` // 阈值(与 PackageSeries.Tiers 对应) + Amount int64 `json:"amount"` // 该代理在此档位的佣金上限(分) +} + +// GetCommissionTiers 解析梯度佣金阶梯列表 +func (a *ShopSeriesAllocation) GetCommissionTiers() ([]AllocationCommissionTier, error) { + if a.CommissionTiersJSON == "" || a.CommissionTiersJSON == "[]" { + return []AllocationCommissionTier{}, nil + } + var tiers []AllocationCommissionTier + if err := json.Unmarshal([]byte(a.CommissionTiersJSON), &tiers); err != nil { + return nil, err + } + return tiers, nil +} + +// SetCommissionTiers 序列化梯度佣金阶梯列表 +func (a *ShopSeriesAllocation) SetCommissionTiers(tiers []AllocationCommissionTier) error { + if len(tiers) == 0 { + a.CommissionTiersJSON = "[]" + return nil + } + data, err := json.Marshal(tiers) + if err != nil { + return err + } + a.CommissionTiersJSON = string(data) + return nil +}