后台商品管理

This commit is contained in:
yml
2026-05-22 17:54:46 +08:00
parent 8afd94ca35
commit dfe686ce0e
12 changed files with 285 additions and 4 deletions
+33 -2
View File
@@ -137,6 +137,31 @@ func (r *Repository) ListPendingReview() ([]ListingDTO, error) {
return rowsToDTO(rows), nil
}
func (r *Repository) ListAdmin(query AdminListQuery) ([]ListingDTO, error) {
limit := query.Limit
if limit <= 0 || limit > 500 {
limit = 200
}
db := r.baseQuery()
if query.OwnerID > 0 {
db = db.Where("l.owner_id = ?", query.OwnerID)
}
if query.Status != "" {
db = db.Where("l.status = ?", query.Status)
}
if query.ReviewStatus != "" {
db = db.Where("l.review_status = ?", query.ReviewStatus)
}
var rows []listingRow
err := db.Order("l.id DESC").Limit(limit).Scan(&rows).Error
if err != nil {
return nil, err
}
return rowsToDTO(rows), nil
}
func (r *Repository) Approve(listingID uint64) (*ListingDTO, error) {
var dto *ListingDTO
err := r.db.Transaction(func(tx *gorm.DB) error {
@@ -291,8 +316,10 @@ func (r *Repository) findDTO(where string, args ...any) (*ListingDTO, error) {
func (r *Repository) baseQuery() *gorm.DB {
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, a.haf_coin_amount").
Joins("JOIN game_accounts AS a ON a.id = l.account_id")
Select(`l.*, a.title, a.description, a.game_name, a.server_region, a.login_platform, a.rank_level,
a.haf_coin_amount, 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("LEFT JOIN users AS u ON u.id = l.owner_id")
}
func (r *Repository) findForReviewUpdate(tx *gorm.DB, listingID uint64) (*model.RentalListing, *model.GameAccount, error) {
@@ -310,6 +337,8 @@ func (r *Repository) findForReviewUpdate(tx *gorm.DB, listingID uint64) (*model.
type listingRow struct {
model.RentalListing
Title string
OwnerPhone string
OwnerNickname string
Description string
GameName string
ServerRegion string
@@ -331,6 +360,8 @@ func (row listingRow) toDTO() ListingDTO {
ID: row.ID,
AccountID: row.AccountID,
OwnerID: row.OwnerID,
OwnerPhone: row.OwnerPhone,
OwnerNickname: row.OwnerNickname,
Title: row.Title,
Description: row.Description,
GameName: row.GameName,