修复(#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:
@@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -25,7 +26,7 @@ func TestCommissionReturnLogHandler_HTTPResponse(t *testing.T) {
|
||||
db, mock, cleanup := newCommissionReturnHandlerTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
expectCommissionReturnHTTPQueries(mock, 42, 3)
|
||||
expectCommissionReturnHTTPQueries(mock, 42, 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(), int64(42), "%\"type\":333%", "%\"type\":337%", "%\"type\":338%", 10).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "type", "date", "object_id", "content", "created_at"}).
|
||||
@@ -62,12 +63,10 @@ func TestWithdrawalLogHandler_CommissionRefundHTTPResponse(t *testing.T) {
|
||||
db, mock, cleanup := newCommissionReturnHandlerTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
expectCommissionReturnHTTPQueries(mock, 42, 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(), int64(42), "%\"type\":333%", "%\"type\":337%", "%\"type\":338%", 10).
|
||||
expectCommissionReturnHTTPQueries(mock, 42, 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(), int64(42), "%\"type\":333%", 10).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"id", "type", "date", "object_id", "content", "created_at"}).
|
||||
AddRow(int64(2003), logmodel.TypeCommission.Uint8(), "2023-11-14", int64(42), `{"type":338,"amount":1500,"order_no":"ORDER-3","timestamp":1700000003123}`, time.Unix(1700000000, 0)).
|
||||
AddRow(int64(2002), logmodel.TypeCommission.Uint8(), "2023-11-14", int64(42), `{"type":337,"amount":2000,"order_no":"ORDER-2","timestamp":1700000002123}`, time.Unix(1700000000, 0)).
|
||||
AddRow(int64(2001), logmodel.TypeCommission.Uint8(), "2023-11-14", int64(42), `{"type":333,"amount":2500,"order_no":"ORDER-1","timestamp":1700000001123}`, time.Unix(1700000000, 0)))
|
||||
|
||||
router := gin.New()
|
||||
@@ -85,7 +84,7 @@ func TestWithdrawalLogHandler_CommissionRefundHTTPResponse(t *testing.T) {
|
||||
|
||||
body := strings.TrimSpace(rec.Body.String())
|
||||
t.Logf("withdrawal_log commission_refund response: %s", body)
|
||||
if !strings.Contains(body, `"biz_type":"commission_refund"`) || !strings.Contains(body, `"amount":1500`) || !strings.Contains(body, `"amount":2000`) || !strings.Contains(body, `"amount":2500`) {
|
||||
if !strings.Contains(body, `"biz_type":"commission_refund"`) || !strings.Contains(body, `"amount":2500`) || strings.Contains(body, `"amount":1500`) || strings.Contains(body, `"amount":2000`) {
|
||||
t.Fatalf("response body = %s", body)
|
||||
}
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
@@ -125,8 +124,18 @@ func injectTestUser(userID int64) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func expectCommissionReturnHTTPQueries(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 expectCommissionReturnHTTPQueries(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