功能:增加订单搜索与状态筛选

This commit is contained in:
yml2213
2026-08-13 12:58:06 +08:00
parent 2b3a1b111b
commit ac44fda08b
5 changed files with 79 additions and 8 deletions
+11 -1
View File
@@ -2,6 +2,7 @@ package service
import (
"errors"
"strings"
"time"
"affiliate_dash/internal/model"
@@ -23,10 +24,15 @@ func (s *FulfillmentService) GetOrder(merchantID uint, orderNo string) (*model.F
return &order, nil
}
func (s *FulfillmentService) ListOrders(merchantID uint, page, size int, orderStatus, orderSource string) ([]model.FulfillmentOrder, int64, error) {
func (s *FulfillmentService) ListOrders(merchantID uint, page, size int, orderStatus, orderSource, keyword string) ([]model.FulfillmentOrder, int64, error) {
page, size = normalizePage(page, size)
tx := s.db.Model(&model.FulfillmentOrder{}).Where("merchant_id = ?", merchantID)
if orderStatus != "" {
switch orderStatus {
case model.OrderStatusPaid, model.OrderStatusDelivering, model.OrderStatusDelivered, model.OrderStatusShipFailed, model.OrderStatusCancelled:
default:
return nil, 0, errors.New("无效的订单状态")
}
tx = tx.Where("order_status = ?", orderStatus)
}
if orderSource != "" {
@@ -37,6 +43,10 @@ func (s *FulfillmentService) ListOrders(merchantID uint, page, size int, orderSt
return nil, 0, errors.New("无效的订单来源")
}
}
if keyword = strings.TrimSpace(keyword); keyword != "" {
like := "%" + keyword + "%"
tx = tx.Where("order_no LIKE ? OR client_order_no LIKE ?", like, like)
}
var total int64
if err := tx.Count(&total).Error; err != nil {
return nil, 0, err