feat(admin-payment): 支付订单 - 补充用户身份与详情
This commit is contained in:
1 parent
15e5b4a8bf
commit
abc7481ac1
9 files changed
+201
-39
No files matched your search
@@ -101,10 +101,22 @@ type PaymentOrderView struct {
|
||||
}
|
||||
|
||||
type AdminPaymentOrderPage struct {
|
||||
Orders []PaymentOrderView `json:"orders"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
Limit int `json:"pageSize"`
|
||||
Orders []AdminPaymentOrderView `json:"orders"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
Limit int `json:"pageSize"`
|
||||
}
|
||||
|
||||
type AdminPaymentOrderUser struct {
|
||||
ID string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
type AdminPaymentOrderView struct {
|
||||
PaymentOrderView
|
||||
User *AdminPaymentOrderUser `json:"user"`
|
||||
}
|
||||
|
||||
func (s *Service) PaymentNotificationResponse(providerID string, success bool) (int, string, string) {
|
||||
@@ -876,9 +888,21 @@ func (s *Service) AdminPaymentOrderPage(actor *model.User, status, keyword strin
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
views := make([]PaymentOrderView, 0, len(orders))
|
||||
userIDs := make([]string, 0, len(orders))
|
||||
for _, order := range orders {
|
||||
views = append(views, paymentOrderView(order))
|
||||
userIDs = append(userIDs, order.UserID)
|
||||
}
|
||||
users, err := s.repo.UsersByIDs(userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
views := make([]AdminPaymentOrderView, 0, len(orders))
|
||||
for _, order := range orders {
|
||||
view := AdminPaymentOrderView{PaymentOrderView: paymentOrderView(order)}
|
||||
if user, ok := users[order.UserID]; ok {
|
||||
view.User = &AdminPaymentOrderUser{ID: user.ID, Username: user.Username, DisplayName: user.DisplayName, Email: user.Email}
|
||||
}
|
||||
views = append(views, view)
|
||||
}
|
||||
return &AdminPaymentOrderPage{Orders: views, Total: total, Page: page, Limit: limit}, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPaymentOrderIdentityOnlyInAdminList(t *testing.T) {
|
||||
base := PaymentOrderView{ID: "order", UserID: "user", MerchantOrderNo: "merchant"}
|
||||
ordinary, err := json.Marshal(base)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(ordinary), `"user":`) || strings.Contains(string(ordinary), `"email":`) {
|
||||
t.Fatalf("ordinary response includes identity: %s", ordinary)
|
||||
}
|
||||
admin, err := json.Marshal(AdminPaymentOrderView{PaymentOrderView: base, User: &AdminPaymentOrderUser{ID: "user", Username: "alice", DisplayName: "小林", Email: "alice@example.com"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var result struct {
|
||||
ID string `json:"id"`
|
||||
User *AdminPaymentOrderUser `json:"user"`
|
||||
}
|
||||
if err := json.Unmarshal(admin, &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.ID != "order" || result.User == nil || result.User.Email != "alice@example.com" {
|
||||
t.Fatalf("invalid admin response: %s", admin)
|
||||
}
|
||||
missing, err := json.Marshal(AdminPaymentOrderView{PaymentOrderView: base})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(missing), `"user":null`) || !strings.Contains(string(missing), `"userId":"user"`) {
|
||||
t.Fatalf("missing user loses original identity: %s", missing)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user