fix: add new fields on subscribe plan, and change status type to number in subscribe

This commit is contained in:
ericprd 2025-03-10 11:48:20 +08:00
parent 52dfb7e0f2
commit ce341dbc13
8 changed files with 39 additions and 11 deletions

View File

@ -9,7 +9,7 @@ type Subscribe struct {
SubscribePlanID string `gorm:"not null" json:"subscribe_plan_id"`
StartDate time.Time `gorm:"default:CURRENT_TIMESTAMP"`
EndDate time.Time `gorm:"default:null"`
Status string `gorm:"default:'inactive'"`
Status int8 `gorm:"default:0"`
AutoRenew bool `gorm:"default:true"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
@ -22,6 +22,9 @@ type SubscribePlan struct {
ID string `gorm:"primaryKey" json:"id"`
Code string `gorm:"not null;unique" json:"code"`
Name string `gorm:"not null" json:"name"`
Length int `gorm:"default:0" json:"length"`
Price float32 `gorm:"default:0" json:"price"`
Status int8 `gorm:"default:1" json:"status"`
CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

View File

@ -18,11 +18,11 @@ func (a *accessor) Delete(id string) error {
if err := a.db.
Model(&subscribedomain.Subscribe{}).
Where("subscribe_plan_id = ?", id).
Update("subscribe_plan_id", basicPlan.ID); err != nil {
Update("subscribe_plan_id", basicPlan.ID).Error; err != nil {
return fmt.Errorf("failed to change subscribe plan: %v", err)
}
if err := a.db.Where("id = ?", id).Delete(&subsPlan).Error; err != nil {
if err := a.db.Delete(&subsPlan, "id = ?", id).Error; err != nil {
return fmt.Errorf("failed to delete subscribe plan %s : %v", id, err)
}

View File

@ -13,9 +13,19 @@ func (a *accessor) Update(spec subscribeplandomain.SubscribePlan) error {
DoUpdates: clause.AssignmentColumns([]string{
"name",
"code",
"length",
"price",
"status",
"updated_at",
}),
}).Select("name", "code", "updated_at").Save(&spec).Error; err != nil {
}).Select(
"name",
"code",
"length",
"price",
"status",
"updated_at",
).Save(&spec).Error; err != nil {
return fmt.Errorf("failed to update tag: %v", err)
}

View File

@ -10,7 +10,7 @@ type Subscribe struct {
SubscribePlanID string `json:"subscribe_plan_id"`
StartDate time.Time `json:"start_date"`
EndDate *time.Time `json:"end_date"`
Status string `json:"status"`
Status int8 `json:"status"`
AutoRenew bool `json:"auto_renew"`
UpdatedAt time.Time `json:"updated_at"`

View File

@ -6,6 +6,9 @@ type SubscribePlan struct {
ID string `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Length int `json:"length"`
Price float32 `json:"price"`
Status int8 `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
@ -13,10 +16,16 @@ type SubscribePlan struct {
type SubscribePlanUpdate struct {
Code string `json:"code" validate:"required"`
Name string `json:"name" validate:"required"`
Length int `json:"length"`
Price float32 `json:"price"`
Status int8 `json:"status"`
UpdatedAt time.Time `json:"updated_at"`
}
type SubscribePlanReq struct {
Code string `json:"code" validate:"required"`
Name string `json:"name" validate:"required"`
Code string `json:"code" validate:"required"`
Name string `json:"name" validate:"required"`
Status int8 `json:"status"`
Length int `json:"length"`
Price float32 `json:"price"`
}

View File

@ -37,7 +37,7 @@ type UserLogin struct {
type UserSubsUpdate struct {
ID string `json:"id"`
Status string `json:"status"`
Status int8 `json:"status"`
SubscribePlanID string `json:"subscribe_plan_id"`
AutoRenew bool `json:"auto_renew"`
StartDate time.Time `json:"start_date"`

View File

@ -8,9 +8,12 @@ import (
func (sb *impl) Create(spec subscribeplandomain.SubscribePlanReq) error {
data := subscribeplandomain.SubscribePlan{
ID: uuid.NewString(),
Code: spec.Code,
Name: spec.Name,
ID: uuid.NewString(),
Code: spec.Code,
Name: spec.Name,
Length: spec.Length,
Price: spec.Price,
Status: spec.Status,
}
return sb.subsRepo.Create(data)
}

View File

@ -10,6 +10,9 @@ func (i *impl) Update(id string, spec subscribeplandomain.SubscribePlanUpdate) e
ID: id,
Code: spec.Code,
Name: spec.Name,
Length: spec.Length,
Price: spec.Price,
Status: spec.Status,
UpdatedAt: timeutils.Now(),
}
return i.subsRepo.Update(newData)