初步优化 发布流程

This commit is contained in:
yml
2026-05-22 23:13:36 +08:00
parent 14efed5ebf
commit 52ac6b7827
5 changed files with 1106 additions and 290 deletions
+40 -38
View File
@@ -3,47 +3,49 @@ package listing
import "time" import "time"
type ListingDTO struct { type ListingDTO struct {
ID uint64 `json:"id"` ID uint64 `json:"id"`
AccountID uint64 `json:"account_id"` AccountID uint64 `json:"account_id"`
OwnerID uint64 `json:"owner_id"` OwnerID uint64 `json:"owner_id"`
OwnerPhone string `json:"owner_phone,omitempty"` OwnerPhone string `json:"owner_phone,omitempty"`
OwnerNickname string `json:"owner_nickname,omitempty"` OwnerNickname string `json:"owner_nickname,omitempty"`
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
GameName string `json:"game_name"` GameName string `json:"game_name"`
ServerRegion string `json:"server_region"` ServerRegion string `json:"server_region"`
LoginPlatform string `json:"login_platform"` LoginPlatform string `json:"login_platform"`
RankLevel string `json:"rank_level"` RankLevel string `json:"rank_level"`
HafCoinAmount int64 `json:"haf_coin_amount"` HafCoinAmount int64 `json:"haf_coin_amount"`
ScreenshotURLS []string `json:"screenshot_urls"` AssetSummary map[string]any `json:"asset_summary,omitempty"`
PriceHourly float64 `json:"price_hourly"` ScreenshotURLS []string `json:"screenshot_urls"`
PriceDaily float64 `json:"price_daily"` PriceHourly float64 `json:"price_hourly"`
PriceWeekly float64 `json:"price_weekly"` PriceDaily float64 `json:"price_daily"`
DepositAmount float64 `json:"deposit_amount"` PriceWeekly float64 `json:"price_weekly"`
MinRentHours int `json:"min_rent_hours"` DepositAmount float64 `json:"deposit_amount"`
MaxRentHours int `json:"max_rent_hours"` MinRentHours int `json:"min_rent_hours"`
Status string `json:"status"` MaxRentHours int `json:"max_rent_hours"`
ReviewStatus string `json:"review_status"` Status string `json:"status"`
ReviewReason string `json:"review_reason"` ReviewStatus string `json:"review_status"`
PublishedAt *time.Time `json:"published_at"` ReviewReason string `json:"review_reason"`
CreatedAt time.Time `json:"created_at"` PublishedAt *time.Time `json:"published_at"`
UpdatedAt time.Time `json:"updated_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} }
type CreateRequest struct { type CreateRequest struct {
Title string `json:"title" binding:"required"` Title string `json:"title" binding:"required"`
Description string `json:"description"` Description string `json:"description"`
ServerRegion string `json:"server_region" binding:"required"` ServerRegion string `json:"server_region" binding:"required"`
LoginPlatform string `json:"login_platform" binding:"required"` LoginPlatform string `json:"login_platform" binding:"required"`
RankLevel string `json:"rank_level"` RankLevel string `json:"rank_level"`
HafCoinAmount int64 `json:"haf_coin_amount"` HafCoinAmount int64 `json:"haf_coin_amount"`
ScreenshotURLS []string `json:"screenshot_urls"` AssetSummary map[string]any `json:"asset_summary"`
PriceHourly float64 `json:"price_hourly" binding:"required"` ScreenshotURLS []string `json:"screenshot_urls"`
PriceDaily float64 `json:"price_daily"` PriceHourly float64 `json:"price_hourly" binding:"required"`
PriceWeekly float64 `json:"price_weekly"` PriceDaily float64 `json:"price_daily"`
DepositAmount float64 `json:"deposit_amount" binding:"required"` PriceWeekly float64 `json:"price_weekly"`
MinRentHours int `json:"min_rent_hours" binding:"required"` DepositAmount float64 `json:"deposit_amount" binding:"required"`
MaxRentHours int `json:"max_rent_hours" binding:"required"` MinRentHours int `json:"min_rent_hours" binding:"required"`
MaxRentHours int `json:"max_rent_hours" binding:"required"`
} }
type UpdateRequest = CreateRequest type UpdateRequest = CreateRequest
+36 -1
View File
@@ -29,6 +29,10 @@ func (r *Repository) Create(ownerID uint64, req CreateRequest) (*ListingDTO, err
if err != nil { if err != nil {
return err return err
} }
assetSummary, err := marshalAssetSummary(req.AssetSummary)
if err != nil {
return err
}
account := model.GameAccount{ account := model.GameAccount{
OwnerID: ownerID, OwnerID: ownerID,
GameName: "delta_force", GameName: "delta_force",
@@ -38,6 +42,7 @@ func (r *Repository) Create(ownerID uint64, req CreateRequest) (*ListingDTO, err
Description: req.Description, Description: req.Description,
RankLevel: req.RankLevel, RankLevel: req.RankLevel,
HafCoinAmount: req.HafCoinAmount, HafCoinAmount: req.HafCoinAmount,
AssetSummary: assetSummary,
ScreenshotURLS: screenshots, ScreenshotURLS: screenshots,
Status: "draft", Status: "draft",
} }
@@ -82,6 +87,11 @@ func (r *Repository) Update(ownerID uint64, listingID uint64, req UpdateRequest)
account.LoginPlatform = req.LoginPlatform account.LoginPlatform = req.LoginPlatform
account.RankLevel = req.RankLevel account.RankLevel = req.RankLevel
account.HafCoinAmount = req.HafCoinAmount account.HafCoinAmount = req.HafCoinAmount
assetSummary, err := marshalAssetSummary(req.AssetSummary)
if err != nil {
return err
}
account.AssetSummary = assetSummary
screenshots, err := marshalScreenshots(req.ScreenshotURLS) screenshots, err := marshalScreenshots(req.ScreenshotURLS)
if err != nil { if err != nil {
return err return err
@@ -397,7 +407,7 @@ func (r *Repository) findDTO(where string, args ...any) (*ListingDTO, error) {
func (r *Repository) baseQuery() *gorm.DB { func (r *Repository) baseQuery() *gorm.DB {
return r.db.Table("rental_listings AS l"). return r.db.Table("rental_listings AS l").
Select(`l.*, a.title, a.description, a.game_name, a.server_region, a.login_platform, a.rank_level, Select(`l.*, a.title, a.description, a.game_name, a.server_region, a.login_platform, a.rank_level,
a.haf_coin_amount, a.screenshot_urls, COALESCE(u.phone, '') AS owner_phone, COALESCE(u.nickname, '') AS owner_nickname`). a.haf_coin_amount, a.asset_summary, a.screenshot_urls, COALESCE(u.phone, '') AS owner_phone, COALESCE(u.nickname, '') AS owner_nickname`).
Joins("JOIN game_accounts AS a ON a.id = l.account_id"). Joins("JOIN game_accounts AS a ON a.id = l.account_id").
Joins("LEFT JOIN users AS u ON u.id = l.owner_id") Joins("LEFT JOIN users AS u ON u.id = l.owner_id")
} }
@@ -425,6 +435,7 @@ type listingRow struct {
LoginPlatform string LoginPlatform string
RankLevel string RankLevel string
HafCoinAmount int64 HafCoinAmount int64
AssetSummary datatypes.JSON
ScreenshotURLS datatypes.JSON ScreenshotURLS datatypes.JSON
} }
@@ -450,6 +461,7 @@ func (row listingRow) toDTO() ListingDTO {
LoginPlatform: row.LoginPlatform, LoginPlatform: row.LoginPlatform,
RankLevel: row.RankLevel, RankLevel: row.RankLevel,
HafCoinAmount: row.HafCoinAmount, HafCoinAmount: row.HafCoinAmount,
AssetSummary: decodeAssetSummary(row.AssetSummary),
ScreenshotURLS: decodeScreenshots(row.ScreenshotURLS), ScreenshotURLS: decodeScreenshots(row.ScreenshotURLS),
PriceHourly: row.PriceHourly, PriceHourly: row.PriceHourly,
PriceDaily: row.PriceDaily, PriceDaily: row.PriceDaily,
@@ -478,6 +490,7 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
LoginPlatform: account.LoginPlatform, LoginPlatform: account.LoginPlatform,
RankLevel: account.RankLevel, RankLevel: account.RankLevel,
HafCoinAmount: account.HafCoinAmount, HafCoinAmount: account.HafCoinAmount,
AssetSummary: decodeAssetSummary(account.AssetSummary),
ScreenshotURLS: decodeScreenshots(account.ScreenshotURLS), ScreenshotURLS: decodeScreenshots(account.ScreenshotURLS),
PriceHourly: listing.PriceHourly, PriceHourly: listing.PriceHourly,
PriceDaily: listing.PriceDaily, PriceDaily: listing.PriceDaily,
@@ -518,6 +531,17 @@ func marshalScreenshots(urls []string) (datatypes.JSON, error) {
return datatypes.JSON(raw), nil return datatypes.JSON(raw), nil
} }
func marshalAssetSummary(summary map[string]any) (datatypes.JSON, error) {
if summary == nil {
return nil, nil
}
raw, err := json.Marshal(summary)
if err != nil {
return nil, err
}
return datatypes.JSON(raw), nil
}
func decodeScreenshots(raw datatypes.JSON) []string { func decodeScreenshots(raw datatypes.JSON) []string {
if len(raw) == 0 { if len(raw) == 0 {
return []string{} return []string{}
@@ -529,6 +553,17 @@ func decodeScreenshots(raw datatypes.JSON) []string {
return urls return urls
} }
func decodeAssetSummary(raw datatypes.JSON) map[string]any {
if len(raw) == 0 {
return nil
}
var summary map[string]any
if err := json.Unmarshal(raw, &summary); err != nil {
return nil
}
return summary
}
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizType string, bizID uint64, meta AuditMeta, detail map[string]any) error { func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizType string, bizID uint64, meta AuditMeta, detail map[string]any) error {
raw, err := json.Marshal(detail) raw, err := json.Marshal(detail)
if err != nil { if err != nil {
-7
View File
@@ -17,21 +17,14 @@ declare module 'vue' {
VanCell: typeof import('vant/es')['Cell'] VanCell: typeof import('vant/es')['Cell']
VanCellGroup: typeof import('vant/es')['CellGroup'] VanCellGroup: typeof import('vant/es')['CellGroup']
VanCheckbox: typeof import('vant/es')['Checkbox'] VanCheckbox: typeof import('vant/es')['Checkbox']
VanDropdownItem: typeof import('vant/es')['DropdownItem']
VanDropdownMenu: typeof import('vant/es')['DropdownMenu']
VanEmpty: typeof import('vant/es')['Empty'] VanEmpty: typeof import('vant/es')['Empty']
VanField: typeof import('vant/es')['Field'] VanField: typeof import('vant/es')['Field']
VanGrid: typeof import('vant/es')['Grid']
VanGridItem: typeof import('vant/es')['GridItem']
VanIcon: typeof import('vant/es')['Icon'] VanIcon: typeof import('vant/es')['Icon']
VanImage: typeof import('vant/es')['Image']
VanLoading: typeof import('vant/es')['Loading'] VanLoading: typeof import('vant/es')['Loading']
VanNoticeBar: typeof import('vant/es')['NoticeBar'] VanNoticeBar: typeof import('vant/es')['NoticeBar']
VanPopup: typeof import('vant/es')['Popup'] VanPopup: typeof import('vant/es')['Popup']
VanPullRefresh: typeof import('vant/es')['PullRefresh'] VanPullRefresh: typeof import('vant/es')['PullRefresh']
VanSearch: typeof import('vant/es')['Search'] VanSearch: typeof import('vant/es')['Search']
VanTabbar: typeof import('vant/es')['Tabbar']
VanTabbarItem: typeof import('vant/es')['TabbarItem']
VanTag: typeof import('vant/es')['Tag'] VanTag: typeof import('vant/es')['Tag']
} }
} }
+2
View File
@@ -13,6 +13,7 @@ export interface Listing {
login_platform: string login_platform: string
rank_level: string rank_level: string
haf_coin_amount: number haf_coin_amount: number
asset_summary?: Record<string, unknown>
screenshot_urls: string[] screenshot_urls: string[]
price_hourly: number price_hourly: number
price_daily: number price_daily: number
@@ -35,6 +36,7 @@ export interface ListingPayload {
login_platform: string login_platform: string
rank_level: string rank_level: string
haf_coin_amount: number haf_coin_amount: number
asset_summary?: Record<string, unknown>
screenshot_urls: string[] screenshot_urls: string[]
price_hourly: number price_hourly: number
price_daily: number price_daily: number
File diff suppressed because it is too large Load Diff