修复(#38): commission_refund 收窄到只查 type=333(移除 337/338 提现退佣混入)
Closes HIF-38 owner 业务定义:commission_refund 这个分类只应返回「下级退单导致用户拿到的佣金被扣回」记录。 改动: - queryWithdrawalLogLogic.go: ?biz_type=commission_refund 分支 SQL 过滤从 IN(333,337,338) 改为 = 333 - 同步更新 logic/handler 单测 不在范围: - /commission_return_log(新推荐接口)继续返回 333/337/338 — 前端暂未切,owner 决定不动 - 337/338 不另外开 UI 入口 — 提现记录 status 字段(rejected/cancelled)已表达
This commit is contained in:
@@ -3,6 +3,7 @@ package user
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -69,7 +70,7 @@ func TestQueryCommissionReturnLog_HappyPathIncludes333337338(t *testing.T) {
|
||||
db, mock, cleanup := newQueryWithdrawalLogTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
expectCommissionReturnQueries(mock, userID, 3)
|
||||
expectCommissionReturnQueries(mock, userID, 3, logmodel.CommissionTypeRefund, logmodel.CommissionTypeWithdrawReject, logmodel.CommissionTypeWithdrawCancel)
|
||||
mock.ExpectQuery("SELECT * FROM `system_logs` WHERE `type` = ? AND object_id = ? AND (`content` LIKE ? OR `content` LIKE ? OR `content` LIKE ?) ORDER BY id DESC LIMIT ?").
|
||||
WithArgs(logmodel.TypeCommission.Uint8(), userID, "%\"type\":333%", "%\"type\":337%", "%\"type\":338%", 10).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "type", "date", "object_id", "content", "created_at"}).
|
||||
@@ -95,19 +96,17 @@ func TestQueryCommissionReturnLog_HappyPathIncludes333337338(t *testing.T) {
|
||||
assertQueryWithdrawalLogExpectations(t, mock)
|
||||
}
|
||||
|
||||
func TestQueryWithdrawalLog_WithCommissionRefundBizTypeIncludes333337338(t *testing.T) {
|
||||
func TestQueryWithdrawalLog_WithCommissionRefundBizTypeOnlyIncludes333(t *testing.T) {
|
||||
const userID = int64(42)
|
||||
createdAt := time.Unix(1700000000, 0)
|
||||
|
||||
db, mock, cleanup := newQueryWithdrawalLogTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
expectCommissionReturnQueries(mock, userID, 3)
|
||||
mock.ExpectQuery("SELECT * FROM `system_logs` WHERE `type` = ? AND object_id = ? AND (`content` LIKE ? OR `content` LIKE ? OR `content` LIKE ?) ORDER BY id DESC LIMIT ?").
|
||||
WithArgs(logmodel.TypeCommission.Uint8(), userID, "%\"type\":333%", "%\"type\":337%", "%\"type\":338%", 10).
|
||||
expectCommissionReturnQueries(mock, userID, 1, logmodel.CommissionTypeRefund)
|
||||
mock.ExpectQuery("SELECT * FROM `system_logs` WHERE `type` = ? AND object_id = ? AND (`content` LIKE ?) ORDER BY id DESC LIMIT ?").
|
||||
WithArgs(logmodel.TypeCommission.Uint8(), userID, "%\"type\":333%", 10).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "type", "date", "object_id", "content", "created_at"}).
|
||||
AddRow(int64(2003), logmodel.TypeCommission.Uint8(), "2023-11-14", userID, `{"type":338,"amount":1500,"order_no":"ORDER-3","timestamp":1700000003123}`, createdAt).
|
||||
AddRow(int64(2002), logmodel.TypeCommission.Uint8(), "2023-11-14", userID, `{"type":337,"amount":2000,"order_no":"ORDER-2","timestamp":1700000002123}`, createdAt).
|
||||
AddRow(int64(2001), logmodel.TypeCommission.Uint8(), "2023-11-14", userID, `{"type":333,"amount":2500,"order_no":"ORDER-1","timestamp":1700000001123}`, createdAt))
|
||||
|
||||
logic := newTestQueryWithdrawalLogLogic(t, db, userID)
|
||||
@@ -119,8 +118,8 @@ func TestQueryWithdrawalLog_WithCommissionRefundBizTypeIncludes333337338(t *test
|
||||
if err != nil {
|
||||
t.Fatalf("QueryWithdrawalLog unexpected error: %v", err)
|
||||
}
|
||||
if resp.Total != 3 || len(resp.List) != 3 {
|
||||
t.Fatalf("QueryWithdrawalLog response = %+v, want three commission returns", resp)
|
||||
if resp.Total != 1 || len(resp.List) != 1 {
|
||||
t.Fatalf("QueryWithdrawalLog response = %+v, want one commission refund", resp)
|
||||
}
|
||||
for _, item := range resp.List {
|
||||
if item.BizType != withdrawalLogBizTypeCommissionRefund {
|
||||
@@ -130,6 +129,9 @@ func TestQueryWithdrawalLog_WithCommissionRefundBizTypeIncludes333337338(t *test
|
||||
t.Fatalf("withdrawal-only fields should keep zero values, got %+v", item)
|
||||
}
|
||||
}
|
||||
if resp.List[0].Id != 2001 {
|
||||
t.Fatalf("commission refund item id = %d, want 2001", resp.List[0].Id)
|
||||
}
|
||||
assertQueryWithdrawalLogExpectations(t, mock)
|
||||
}
|
||||
|
||||
@@ -140,7 +142,7 @@ func TestQueryCommissionReturnLog_SkipsInvalidJSONAndLogsWarn(t *testing.T) {
|
||||
db, mock, cleanup := newQueryWithdrawalLogTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
expectCommissionReturnQueries(mock, userID, 2)
|
||||
expectCommissionReturnQueries(mock, userID, 2, logmodel.CommissionTypeRefund, logmodel.CommissionTypeWithdrawReject, logmodel.CommissionTypeWithdrawCancel)
|
||||
mock.ExpectQuery("SELECT * FROM `system_logs` WHERE `type` = ? AND object_id = ? AND (`content` LIKE ? OR `content` LIKE ? OR `content` LIKE ?) ORDER BY id DESC LIMIT ?").
|
||||
WithArgs(logmodel.TypeCommission.Uint8(), userID, "%\"type\":333%", "%\"type\":337%", "%\"type\":338%", 10).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "type", "date", "object_id", "content", "created_at"}).
|
||||
@@ -171,7 +173,7 @@ func TestQueryCommissionReturnLog_FiltersOtherUsersByObjectID(t *testing.T) {
|
||||
db, mock, cleanup := newQueryWithdrawalLogTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
expectCommissionReturnQueries(mock, userID, 0)
|
||||
expectCommissionReturnQueries(mock, userID, 0, logmodel.CommissionTypeRefund, logmodel.CommissionTypeWithdrawReject, logmodel.CommissionTypeWithdrawCancel)
|
||||
mock.ExpectQuery("SELECT * FROM `system_logs` WHERE `type` = ? AND object_id = ? AND (`content` LIKE ? OR `content` LIKE ? OR `content` LIKE ?) ORDER BY id DESC LIMIT ?").
|
||||
WithArgs(logmodel.TypeCommission.Uint8(), userID, "%\"type\":333%", "%\"type\":337%", "%\"type\":338%", 10).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "type", "date", "object_id", "content", "created_at"}))
|
||||
@@ -243,9 +245,19 @@ func newTestQueryCtx(userID int64) context.Context {
|
||||
return context.WithValue(context.Background(), constant.CtxKeyUser, &usermodel.User{Id: userID})
|
||||
}
|
||||
|
||||
func expectCommissionReturnQueries(mock sqlmock.Sqlmock, userID int64, total int64) {
|
||||
mock.ExpectQuery("SELECT count(*) FROM `system_logs` WHERE `type` = ? AND object_id = ? AND (`content` LIKE ? OR `content` LIKE ? OR `content` LIKE ?)").
|
||||
WithArgs(logmodel.TypeCommission.Uint8(), userID, "%\"type\":333%", "%\"type\":337%", "%\"type\":338%").
|
||||
func expectCommissionReturnQueries(mock sqlmock.Sqlmock, userID int64, total int64, eventTypes ...uint16) {
|
||||
query := "SELECT count(*) FROM `system_logs` WHERE `type` = ? AND object_id = ?"
|
||||
args := []driver.Value{logmodel.TypeCommission.Uint8(), userID}
|
||||
if len(eventTypes) > 0 {
|
||||
clauses := make([]string, 0, len(eventTypes))
|
||||
for _, eventType := range eventTypes {
|
||||
clauses = append(clauses, "`content` LIKE ?")
|
||||
args = append(args, fmt.Sprintf("%%\"type\":%d%%", eventType))
|
||||
}
|
||||
query += " AND (" + strings.Join(clauses, " OR ") + ")"
|
||||
}
|
||||
mock.ExpectQuery(query).
|
||||
WithArgs(args...).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(total))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user