From d332e760f8efc264c75978d0a103dd7a7445dd27 Mon Sep 17 00:00:00 2001 From: Tension Date: Sun, 28 Dec 2025 17:08:26 +0800 Subject: [PATCH] feat(subscribe): add ShowOriginalPrice field and related database changes --- apis/admin/subscribe.api | 86 +++++------ apis/public/user.api | 1 - apis/types.api | 49 +++---- .../02123_subscribe_original.down.sql | 2 + .../database/02123_subscribe_original.up.sql | 2 + .../admin/subscribe/createSubscribeLogic.go | 45 +++--- .../admin/subscribe/updateSubscribeLogic.go | 45 +++--- internal/model/subscribe/subscribe.go | 49 +++---- internal/types/types.go | 135 +++++++++--------- 9 files changed, 213 insertions(+), 201 deletions(-) create mode 100644 initialize/migrate/database/02123_subscribe_original.down.sql create mode 100644 initialize/migrate/database/02123_subscribe_original.up.sql diff --git a/apis/admin/subscribe.api b/apis/admin/subscribe.api index bea205d..a832b3a 100644 --- a/apis/admin/subscribe.api +++ b/apis/admin/subscribe.api @@ -34,50 +34,52 @@ type ( Ids []int64 `json:"ids" validate:"required"` } CreateSubscribeRequest { - Name string `json:"name" validate:"required"` - Language string `json:"language"` - Description string `json:"description"` - UnitPrice int64 `json:"unit_price"` - UnitTime string `json:"unit_time"` - Discount []SubscribeDiscount `json:"discount"` - Replacement int64 `json:"replacement"` - Inventory int64 `json:"inventory"` - Traffic int64 `json:"traffic"` - SpeedLimit int64 `json:"speed_limit"` - DeviceLimit int64 `json:"device_limit"` - Quota int64 `json:"quota"` - Nodes []int64 `json:"nodes"` - NodeTags []string `json:"node_tags"` - Show *bool `json:"show"` - Sell *bool `json:"sell"` - DeductionRatio int64 `json:"deduction_ratio"` - AllowDeduction *bool `json:"allow_deduction"` - ResetCycle int64 `json:"reset_cycle"` - RenewalReset *bool `json:"renewal_reset"` + Name string `json:"name" validate:"required"` + Language string `json:"language"` + Description string `json:"description"` + UnitPrice int64 `json:"unit_price"` + UnitTime string `json:"unit_time"` + Discount []SubscribeDiscount `json:"discount"` + Replacement int64 `json:"replacement"` + Inventory int64 `json:"inventory"` + Traffic int64 `json:"traffic"` + SpeedLimit int64 `json:"speed_limit"` + DeviceLimit int64 `json:"device_limit"` + Quota int64 `json:"quota"` + Nodes []int64 `json:"nodes"` + NodeTags []string `json:"node_tags"` + Show *bool `json:"show"` + Sell *bool `json:"sell"` + DeductionRatio int64 `json:"deduction_ratio"` + AllowDeduction *bool `json:"allow_deduction"` + ResetCycle int64 `json:"reset_cycle"` + RenewalReset *bool `json:"renewal_reset"` + ShowOriginalPrice bool `json:"show_original_price"` } UpdateSubscribeRequest { - Id int64 `json:"id" validate:"required"` - Name string `json:"name" validate:"required"` - Language string `json:"language"` - Description string `json:"description"` - UnitPrice int64 `json:"unit_price"` - UnitTime string `json:"unit_time"` - Discount []SubscribeDiscount `json:"discount"` - Replacement int64 `json:"replacement"` - Inventory int64 `json:"inventory"` - Traffic int64 `json:"traffic"` - SpeedLimit int64 `json:"speed_limit"` - DeviceLimit int64 `json:"device_limit"` - Quota int64 `json:"quota"` - Nodes []int64 `json:"nodes"` - NodeTags []string `json:"node_tags"` - Show *bool `json:"show"` - Sell *bool `json:"sell"` - Sort int64 `json:"sort"` - DeductionRatio int64 `json:"deduction_ratio"` - AllowDeduction *bool `json:"allow_deduction"` - ResetCycle int64 `json:"reset_cycle"` - RenewalReset *bool `json:"renewal_reset"` + Id int64 `json:"id" validate:"required"` + Name string `json:"name" validate:"required"` + Language string `json:"language"` + Description string `json:"description"` + UnitPrice int64 `json:"unit_price"` + UnitTime string `json:"unit_time"` + Discount []SubscribeDiscount `json:"discount"` + Replacement int64 `json:"replacement"` + Inventory int64 `json:"inventory"` + Traffic int64 `json:"traffic"` + SpeedLimit int64 `json:"speed_limit"` + DeviceLimit int64 `json:"device_limit"` + Quota int64 `json:"quota"` + Nodes []int64 `json:"nodes"` + NodeTags []string `json:"node_tags"` + Show *bool `json:"show"` + Sell *bool `json:"sell"` + Sort int64 `json:"sort"` + DeductionRatio int64 `json:"deduction_ratio"` + AllowDeduction *bool `json:"allow_deduction"` + ResetCycle int64 `json:"reset_cycle"` + RenewalReset *bool `json:"renewal_reset"` + ShowOriginalPrice bool `json:"show_original_price"` } SubscribeSortRequest { Sort []SortItem `json:"sort"` diff --git a/apis/public/user.api b/apis/public/user.api index 3612328..a02b758 100644 --- a/apis/public/user.api +++ b/apis/public/user.api @@ -66,7 +66,6 @@ type ( UnbindOAuthRequest { Method string `json:"method"` } - GetLoginLogRequest { Page int `form:"page"` Size int `form:"size"` diff --git a/apis/types.api b/apis/types.api index b212734..cf39322 100644 --- a/apis/types.api +++ b/apis/types.api @@ -208,30 +208,31 @@ type ( Discount int64 `json:"discount"` } Subscribe { - Id int64 `json:"id"` - Name string `json:"name"` - Language string `json:"language"` - Description string `json:"description"` - UnitPrice int64 `json:"unit_price"` - UnitTime string `json:"unit_time"` - Discount []SubscribeDiscount `json:"discount"` - Replacement int64 `json:"replacement"` - Inventory int64 `json:"inventory"` - Traffic int64 `json:"traffic"` - SpeedLimit int64 `json:"speed_limit"` - DeviceLimit int64 `json:"device_limit"` - Quota int64 `json:"quota"` - Nodes []int64 `json:"nodes"` - NodeTags []string `json:"node_tags"` - Show bool `json:"show"` - Sell bool `json:"sell"` - Sort int64 `json:"sort"` - DeductionRatio int64 `json:"deduction_ratio"` - AllowDeduction bool `json:"allow_deduction"` - ResetCycle int64 `json:"reset_cycle"` - RenewalReset bool `json:"renewal_reset"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` + Id int64 `json:"id"` + Name string `json:"name"` + Language string `json:"language"` + Description string `json:"description"` + UnitPrice int64 `json:"unit_price"` + UnitTime string `json:"unit_time"` + Discount []SubscribeDiscount `json:"discount"` + Replacement int64 `json:"replacement"` + Inventory int64 `json:"inventory"` + Traffic int64 `json:"traffic"` + SpeedLimit int64 `json:"speed_limit"` + DeviceLimit int64 `json:"device_limit"` + Quota int64 `json:"quota"` + Nodes []int64 `json:"nodes"` + NodeTags []string `json:"node_tags"` + Show bool `json:"show"` + Sell bool `json:"sell"` + Sort int64 `json:"sort"` + DeductionRatio int64 `json:"deduction_ratio"` + AllowDeduction bool `json:"allow_deduction"` + ResetCycle int64 `json:"reset_cycle"` + RenewalReset bool `json:"renewal_reset"` + ShowOriginalPrice bool `json:"show_original_price"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` } SubscribeGroup { Id int64 `json:"id"` diff --git a/initialize/migrate/database/02123_subscribe_original.down.sql b/initialize/migrate/database/02123_subscribe_original.down.sql new file mode 100644 index 0000000..2527d48 --- /dev/null +++ b/initialize/migrate/database/02123_subscribe_original.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE `subscribe` +DROP COLUMN `show_original_price`; diff --git a/initialize/migrate/database/02123_subscribe_original.up.sql b/initialize/migrate/database/02123_subscribe_original.up.sql new file mode 100644 index 0000000..af04a8b --- /dev/null +++ b/initialize/migrate/database/02123_subscribe_original.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE `subscribe` + ADD COLUMN `show_original_price` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'display the original price: 0 not display, 1 display' AFTER `created_at`; diff --git a/internal/logic/admin/subscribe/createSubscribeLogic.go b/internal/logic/admin/subscribe/createSubscribeLogic.go index bf50d6a..6309e2b 100644 --- a/internal/logic/admin/subscribe/createSubscribeLogic.go +++ b/internal/logic/admin/subscribe/createSubscribeLogic.go @@ -35,28 +35,29 @@ func (l *CreateSubscribeLogic) CreateSubscribe(req *types.CreateSubscribeRequest discount = string(val) } sub := &subscribe.Subscribe{ - Id: 0, - Name: req.Name, - Language: req.Language, - Description: req.Description, - UnitPrice: req.UnitPrice, - UnitTime: req.UnitTime, - Discount: discount, - Replacement: req.Replacement, - Inventory: req.Inventory, - Traffic: req.Traffic, - SpeedLimit: req.SpeedLimit, - DeviceLimit: req.DeviceLimit, - Quota: req.Quota, - Nodes: tool.Int64SliceToString(req.Nodes), - NodeTags: tool.StringSliceToString(req.NodeTags), - Show: req.Show, - Sell: req.Sell, - Sort: 0, - DeductionRatio: req.DeductionRatio, - AllowDeduction: req.AllowDeduction, - ResetCycle: req.ResetCycle, - RenewalReset: req.RenewalReset, + Id: 0, + Name: req.Name, + Language: req.Language, + Description: req.Description, + UnitPrice: req.UnitPrice, + UnitTime: req.UnitTime, + Discount: discount, + Replacement: req.Replacement, + Inventory: req.Inventory, + Traffic: req.Traffic, + SpeedLimit: req.SpeedLimit, + DeviceLimit: req.DeviceLimit, + Quota: req.Quota, + Nodes: tool.Int64SliceToString(req.Nodes), + NodeTags: tool.StringSliceToString(req.NodeTags), + Show: req.Show, + Sell: req.Sell, + Sort: 0, + DeductionRatio: req.DeductionRatio, + AllowDeduction: req.AllowDeduction, + ResetCycle: req.ResetCycle, + RenewalReset: req.RenewalReset, + ShowOriginalPrice: req.ShowOriginalPrice, } err := l.svcCtx.SubscribeModel.Insert(l.ctx, sub) if err != nil { diff --git a/internal/logic/admin/subscribe/updateSubscribeLogic.go b/internal/logic/admin/subscribe/updateSubscribeLogic.go index 060af5a..b79fdfe 100644 --- a/internal/logic/admin/subscribe/updateSubscribeLogic.go +++ b/internal/logic/admin/subscribe/updateSubscribeLogic.go @@ -43,28 +43,29 @@ func (l *UpdateSubscribeLogic) UpdateSubscribe(req *types.UpdateSubscribeRequest discount = string(val) } sub := &subscribe.Subscribe{ - Id: req.Id, - Name: req.Name, - Language: req.Language, - Description: req.Description, - UnitPrice: req.UnitPrice, - UnitTime: req.UnitTime, - Discount: discount, - Replacement: req.Replacement, - Inventory: req.Inventory, - Traffic: req.Traffic, - SpeedLimit: req.SpeedLimit, - DeviceLimit: req.DeviceLimit, - Quota: req.Quota, - Nodes: tool.Int64SliceToString(req.Nodes), - NodeTags: tool.StringSliceToString(req.NodeTags), - Show: req.Show, - Sell: req.Sell, - Sort: req.Sort, - DeductionRatio: req.DeductionRatio, - AllowDeduction: req.AllowDeduction, - ResetCycle: req.ResetCycle, - RenewalReset: req.RenewalReset, + Id: req.Id, + Name: req.Name, + Language: req.Language, + Description: req.Description, + UnitPrice: req.UnitPrice, + UnitTime: req.UnitTime, + Discount: discount, + Replacement: req.Replacement, + Inventory: req.Inventory, + Traffic: req.Traffic, + SpeedLimit: req.SpeedLimit, + DeviceLimit: req.DeviceLimit, + Quota: req.Quota, + Nodes: tool.Int64SliceToString(req.Nodes), + NodeTags: tool.StringSliceToString(req.NodeTags), + Show: req.Show, + Sell: req.Sell, + Sort: req.Sort, + DeductionRatio: req.DeductionRatio, + AllowDeduction: req.AllowDeduction, + ResetCycle: req.ResetCycle, + RenewalReset: req.RenewalReset, + ShowOriginalPrice: req.ShowOriginalPrice, } err = l.svcCtx.SubscribeModel.Update(l.ctx, sub) if err != nil { diff --git a/internal/model/subscribe/subscribe.go b/internal/model/subscribe/subscribe.go index a80ea63..b895cb7 100644 --- a/internal/model/subscribe/subscribe.go +++ b/internal/model/subscribe/subscribe.go @@ -7,30 +7,31 @@ import ( ) type Subscribe struct { - Id int64 `gorm:"primaryKey"` - Name string `gorm:"type:varchar(255);not null;default:'';comment:Subscribe Name"` - Language string `gorm:"type:varchar(255);not null;default:'';comment:Language"` - Description string `gorm:"type:text;comment:Subscribe Description"` - UnitPrice int64 `gorm:"type:int;not null;default:0;comment:Unit Price"` - UnitTime string `gorm:"type:varchar(255);not null;default:'';comment:Unit Time"` - Discount string `gorm:"type:text;comment:Discount"` - Replacement int64 `gorm:"type:int;not null;default:0;comment:Replacement"` - Inventory int64 `gorm:"type:int;not null;default:0;comment:Inventory"` - Traffic int64 `gorm:"type:int;not null;default:0;comment:Traffic"` - SpeedLimit int64 `gorm:"type:int;not null;default:0;comment:Speed Limit"` - DeviceLimit int64 `gorm:"type:int;not null;default:0;comment:Device Limit"` - Quota int64 `gorm:"type:int;not null;default:0;comment:Quota"` - Nodes string `gorm:"type:varchar(255);comment:Node Ids"` - NodeTags string `gorm:"type:varchar(255);comment:Node Tags"` - Show *bool `gorm:"type:tinyint(1);not null;default:0;comment:Show portal page"` - Sell *bool `gorm:"type:tinyint(1);not null;default:0;comment:Sell"` - Sort int64 `gorm:"type:int;not null;default:0;comment:Sort"` - DeductionRatio int64 `gorm:"type:int;default:0;comment:Deduction Ratio"` - AllowDeduction *bool `gorm:"type:tinyint(1);default:1;comment:Allow deduction"` - ResetCycle int64 `gorm:"type:int;default:0;comment:Reset Cycle: 0: No Reset, 1: 1st, 2: Monthly, 3: Yearly"` - RenewalReset *bool `gorm:"type:tinyint(1);default:0;comment:Renew Reset"` - CreatedAt time.Time `gorm:"<-:create;comment:Create Time"` - UpdatedAt time.Time `gorm:"comment:Update Time"` + Id int64 `gorm:"primaryKey"` + Name string `gorm:"type:varchar(255);not null;default:'';comment:Subscribe Name"` + Language string `gorm:"type:varchar(255);not null;default:'';comment:Language"` + Description string `gorm:"type:text;comment:Subscribe Description"` + UnitPrice int64 `gorm:"type:int;not null;default:0;comment:Unit Price"` + UnitTime string `gorm:"type:varchar(255);not null;default:'';comment:Unit Time"` + Discount string `gorm:"type:text;comment:Discount"` + Replacement int64 `gorm:"type:int;not null;default:0;comment:Replacement"` + Inventory int64 `gorm:"type:int;not null;default:0;comment:Inventory"` + Traffic int64 `gorm:"type:int;not null;default:0;comment:Traffic"` + SpeedLimit int64 `gorm:"type:int;not null;default:0;comment:Speed Limit"` + DeviceLimit int64 `gorm:"type:int;not null;default:0;comment:Device Limit"` + Quota int64 `gorm:"type:int;not null;default:0;comment:Quota"` + Nodes string `gorm:"type:varchar(255);comment:Node Ids"` + NodeTags string `gorm:"type:varchar(255);comment:Node Tags"` + Show *bool `gorm:"type:tinyint(1);not null;default:0;comment:Show portal page"` + Sell *bool `gorm:"type:tinyint(1);not null;default:0;comment:Sell"` + Sort int64 `gorm:"type:int;not null;default:0;comment:Sort"` + DeductionRatio int64 `gorm:"type:int;default:0;comment:Deduction Ratio"` + AllowDeduction *bool `gorm:"type:tinyint(1);default:1;comment:Allow deduction"` + ResetCycle int64 `gorm:"type:int;default:0;comment:Reset Cycle: 0: No Reset, 1: 1st, 2: Monthly, 3: Yearly"` + RenewalReset *bool `gorm:"type:tinyint(1);default:0;comment:Renew Reset"` + ShowOriginalPrice bool `gorm:"type:tinyint(1);not null;default:1;comment:Show Original Price"` + CreatedAt time.Time `gorm:"<-:create;comment:Create Time"` + UpdatedAt time.Time `gorm:"comment:Update Time"` } func (*Subscribe) TableName() string { diff --git a/internal/types/types.go b/internal/types/types.go index 44180f4..cf15d7d 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -388,26 +388,27 @@ type CreateSubscribeGroupRequest struct { } type CreateSubscribeRequest struct { - Name string `json:"name" validate:"required"` - Language string `json:"language"` - Description string `json:"description"` - UnitPrice int64 `json:"unit_price"` - UnitTime string `json:"unit_time"` - Discount []SubscribeDiscount `json:"discount"` - Replacement int64 `json:"replacement"` - Inventory int64 `json:"inventory"` - Traffic int64 `json:"traffic"` - SpeedLimit int64 `json:"speed_limit"` - DeviceLimit int64 `json:"device_limit"` - Quota int64 `json:"quota"` - Nodes []int64 `json:"nodes"` - NodeTags []string `json:"node_tags"` - Show *bool `json:"show"` - Sell *bool `json:"sell"` - DeductionRatio int64 `json:"deduction_ratio"` - AllowDeduction *bool `json:"allow_deduction"` - ResetCycle int64 `json:"reset_cycle"` - RenewalReset *bool `json:"renewal_reset"` + Name string `json:"name" validate:"required"` + Language string `json:"language"` + Description string `json:"description"` + UnitPrice int64 `json:"unit_price"` + UnitTime string `json:"unit_time"` + Discount []SubscribeDiscount `json:"discount"` + Replacement int64 `json:"replacement"` + Inventory int64 `json:"inventory"` + Traffic int64 `json:"traffic"` + SpeedLimit int64 `json:"speed_limit"` + DeviceLimit int64 `json:"device_limit"` + Quota int64 `json:"quota"` + Nodes []int64 `json:"nodes"` + NodeTags []string `json:"node_tags"` + Show *bool `json:"show"` + Sell *bool `json:"sell"` + DeductionRatio int64 `json:"deduction_ratio"` + AllowDeduction *bool `json:"allow_deduction"` + ResetCycle int64 `json:"reset_cycle"` + RenewalReset *bool `json:"renewal_reset"` + ShowOriginalPrice bool `json:"show_original_price"` } type CreateTicketFollowRequest struct { @@ -2054,30 +2055,31 @@ type StripePayment struct { } type Subscribe struct { - Id int64 `json:"id"` - Name string `json:"name"` - Language string `json:"language"` - Description string `json:"description"` - UnitPrice int64 `json:"unit_price"` - UnitTime string `json:"unit_time"` - Discount []SubscribeDiscount `json:"discount"` - Replacement int64 `json:"replacement"` - Inventory int64 `json:"inventory"` - Traffic int64 `json:"traffic"` - SpeedLimit int64 `json:"speed_limit"` - DeviceLimit int64 `json:"device_limit"` - Quota int64 `json:"quota"` - Nodes []int64 `json:"nodes"` - NodeTags []string `json:"node_tags"` - Show bool `json:"show"` - Sell bool `json:"sell"` - Sort int64 `json:"sort"` - DeductionRatio int64 `json:"deduction_ratio"` - AllowDeduction bool `json:"allow_deduction"` - ResetCycle int64 `json:"reset_cycle"` - RenewalReset bool `json:"renewal_reset"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` + Id int64 `json:"id"` + Name string `json:"name"` + Language string `json:"language"` + Description string `json:"description"` + UnitPrice int64 `json:"unit_price"` + UnitTime string `json:"unit_time"` + Discount []SubscribeDiscount `json:"discount"` + Replacement int64 `json:"replacement"` + Inventory int64 `json:"inventory"` + Traffic int64 `json:"traffic"` + SpeedLimit int64 `json:"speed_limit"` + DeviceLimit int64 `json:"device_limit"` + Quota int64 `json:"quota"` + Nodes []int64 `json:"nodes"` + NodeTags []string `json:"node_tags"` + Show bool `json:"show"` + Sell bool `json:"sell"` + Sort int64 `json:"sort"` + DeductionRatio int64 `json:"deduction_ratio"` + AllowDeduction bool `json:"allow_deduction"` + ResetCycle int64 `json:"reset_cycle"` + RenewalReset bool `json:"renewal_reset"` + ShowOriginalPrice bool `json:"show_original_price"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` } type SubscribeApplication struct { @@ -2433,28 +2435,29 @@ type UpdateSubscribeGroupRequest struct { } type UpdateSubscribeRequest struct { - Id int64 `json:"id" validate:"required"` - Name string `json:"name" validate:"required"` - Language string `json:"language"` - Description string `json:"description"` - UnitPrice int64 `json:"unit_price"` - UnitTime string `json:"unit_time"` - Discount []SubscribeDiscount `json:"discount"` - Replacement int64 `json:"replacement"` - Inventory int64 `json:"inventory"` - Traffic int64 `json:"traffic"` - SpeedLimit int64 `json:"speed_limit"` - DeviceLimit int64 `json:"device_limit"` - Quota int64 `json:"quota"` - Nodes []int64 `json:"nodes"` - NodeTags []string `json:"node_tags"` - Show *bool `json:"show"` - Sell *bool `json:"sell"` - Sort int64 `json:"sort"` - DeductionRatio int64 `json:"deduction_ratio"` - AllowDeduction *bool `json:"allow_deduction"` - ResetCycle int64 `json:"reset_cycle"` - RenewalReset *bool `json:"renewal_reset"` + Id int64 `json:"id" validate:"required"` + Name string `json:"name" validate:"required"` + Language string `json:"language"` + Description string `json:"description"` + UnitPrice int64 `json:"unit_price"` + UnitTime string `json:"unit_time"` + Discount []SubscribeDiscount `json:"discount"` + Replacement int64 `json:"replacement"` + Inventory int64 `json:"inventory"` + Traffic int64 `json:"traffic"` + SpeedLimit int64 `json:"speed_limit"` + DeviceLimit int64 `json:"device_limit"` + Quota int64 `json:"quota"` + Nodes []int64 `json:"nodes"` + NodeTags []string `json:"node_tags"` + Show *bool `json:"show"` + Sell *bool `json:"sell"` + Sort int64 `json:"sort"` + DeductionRatio int64 `json:"deduction_ratio"` + AllowDeduction *bool `json:"allow_deduction"` + ResetCycle int64 `json:"reset_cycle"` + RenewalReset *bool `json:"renewal_reset"` + ShowOriginalPrice bool `json:"show_original_price"` } type UpdateTicketStatusRequest struct {