支持客服主动发起申诉
This commit is contained in:
@@ -5,22 +5,18 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (r *Repository) ListForUser(ctx context.Context, userID uint64, page, pageSize int) (*PaginatedResult, error) {
|
||||
db := r.db.WithContext(ctx)
|
||||
conditions := db.Model(&model.Dispute{}).Where("initiator_id = ? OR target_user_id = ?", userID, userID)
|
||||
conditions := r.userVisibleQuery(ctx, userID)
|
||||
var total int64
|
||||
if err := conditions.Count(&total).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
var rows []disputeRow
|
||||
err := r.baseQuery(ctx).
|
||||
Where("d.initiator_id = ? OR d.target_user_id = ?", userID, userID).
|
||||
err := applyUserVisibleFilter(r.baseQuery(ctx), userID).
|
||||
Order("d.id DESC").
|
||||
Offset(offset).Limit(pageSize).
|
||||
Scan(&rows).Error
|
||||
@@ -32,8 +28,7 @@ func (r *Repository) ListForUser(ctx context.Context, userID uint64, page, pageS
|
||||
|
||||
func (r *Repository) FindForUser(ctx context.Context, userID uint64, id uint64) (*DisputeDTO, error) {
|
||||
var row disputeRow
|
||||
if err := r.baseQuery(ctx).
|
||||
Where("d.id = ? AND (d.initiator_id = ? OR d.target_user_id = ?)", id, userID, userID).
|
||||
if err := applyUserVisibleFilter(r.baseQuery(ctx).Where("d.id = ?", id), userID).
|
||||
First(&row).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -68,6 +63,31 @@ func (r *Repository) ListAdmin(ctx context.Context, query AdminListQuery) (*Pagi
|
||||
return &PaginatedResult{Items: toDTOs(rows), Total: total, Page: page, PageSize: pageSize}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) FindAdminByID(ctx context.Context, id uint64) (*DisputeDTO, error) {
|
||||
var row disputeRow
|
||||
if err := r.baseQuery(ctx).Where("d.id = ?", id).First(&row).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dto := row.toDTO()
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func (r *Repository) userVisibleQuery(ctx context.Context, userID uint64) *gorm.DB {
|
||||
return applyUserVisibleFilter(r.adminFilterQuery(ctx), userID)
|
||||
}
|
||||
|
||||
func applyUserVisibleFilter(db *gorm.DB, userID uint64) *gorm.DB {
|
||||
return db.Where(
|
||||
`((d.initiator_type = ? AND d.initiator_id = ?) OR d.target_user_id = ? OR (d.initiator_type = ? AND (o.owner_id = ? OR o.renter_id = ?)))`,
|
||||
disputeInitiatorUser,
|
||||
userID,
|
||||
userID,
|
||||
disputeInitiatorAdmin,
|
||||
userID,
|
||||
userID,
|
||||
)
|
||||
}
|
||||
|
||||
func (r *Repository) baseQuery(ctx context.Context) *gorm.DB {
|
||||
return r.adminFilterQuery(ctx).
|
||||
Select(`d.*, o.order_no, o.status AS order_status, o.handoff_status, o.settlement_status,
|
||||
|
||||
Reference in New Issue
Block a user