feat(order): 统一网站自交接订单24小时自动完成倒计时
This commit is contained in:
@@ -26,11 +26,16 @@ func ParseDistributionSettlementHoldDays(raw string) int {
|
||||
return days
|
||||
}
|
||||
|
||||
// AutoCompleteHandoffTimeoutKey 是「网站自交接订单自动完成倒计时(分钟)」的系统配置键。
|
||||
const AutoCompleteHandoffTimeoutKey = "handoff.auto_complete_timeout_minutes"
|
||||
|
||||
// validateConfigValue 按配置键分发校验逻辑,未注册校验的键直接放行。
|
||||
func validateConfigValue(key, value string) error {
|
||||
switch key {
|
||||
case DistributionSettlementHoldDaysKey:
|
||||
return validateDistributionSettlementHoldDays(value)
|
||||
case AutoCompleteHandoffTimeoutKey:
|
||||
return validateNonNegativeMinutes(value, 30*24*60)
|
||||
case smsnode.ConfigKey:
|
||||
if _, err := smsnode.ParseConfigValue(value); err != nil {
|
||||
return ErrInvalidConfig
|
||||
@@ -48,3 +53,11 @@ func validateDistributionSettlementHoldDays(value string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateNonNegativeMinutes(value string, maxMinutes int) error {
|
||||
minutes, err := strconv.Atoi(strings.TrimSpace(value))
|
||||
if err != nil || minutes < 0 || minutes > maxMinutes {
|
||||
return ErrInvalidConfig
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -64,3 +64,41 @@ func TestValidateConfigValueDistributionSettlementHoldDays(t *testing.T) {
|
||||
t.Fatalf("无关配置键应放行, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutoCompleteHandoffTimeoutConfig(t *testing.T) {
|
||||
visible := false
|
||||
for _, key := range adminVisibleConfigKeys {
|
||||
if key == AutoCompleteHandoffTimeoutKey {
|
||||
visible = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !visible {
|
||||
t.Fatalf("adminVisibleConfigKeys 缺少 %s", AutoCompleteHandoffTimeoutKey)
|
||||
}
|
||||
|
||||
foundDefault := false
|
||||
for _, item := range defaultConfigs {
|
||||
if item.Key == AutoCompleteHandoffTimeoutKey {
|
||||
foundDefault = true
|
||||
if item.Value != "1440" {
|
||||
t.Fatalf("default %s = %q, want 1440", AutoCompleteHandoffTimeoutKey, item.Value)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if !foundDefault {
|
||||
t.Fatalf("defaultConfigs 缺少 %s", AutoCompleteHandoffTimeoutKey)
|
||||
}
|
||||
|
||||
for _, value := range []string{"0", "60", "1440", "43200"} {
|
||||
if err := validateConfigValue(AutoCompleteHandoffTimeoutKey, value); err != nil {
|
||||
t.Fatalf("validateConfigValue(%q) = %v, want nil", value, err)
|
||||
}
|
||||
}
|
||||
for _, value := range []string{"-1", "43201", "", "abc"} {
|
||||
if err := validateConfigValue(AutoCompleteHandoffTimeoutKey, value); err != ErrInvalidConfig {
|
||||
t.Fatalf("validateConfigValue(%q) = %v, want ErrInvalidConfig", value, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ type defaultConfig struct {
|
||||
var defaultConfigs = []defaultConfig{
|
||||
{Key: "handoff.owner_submit_timeout_minutes", Value: "30", Description: "号主待交接超时分钟数"},
|
||||
{Key: "handoff.renter_confirm_timeout_minutes", Value: "30", Description: "租客待确认收号超时分钟数"},
|
||||
{Key: "handoff.auto_complete_timeout_minutes", Value: "1440", Description: "网站自交接订单自动完成倒计时分钟数(0 表示关闭)"},
|
||||
{Key: "handoff.owner_return_confirm_timeout_minutes", Value: "120", Description: "号主待确认结账超时分钟数"},
|
||||
{Key: "order.pending_payment_timeout_minutes", Value: "15", Description: "订单待支付超时取消分钟数"},
|
||||
{Key: "order.return_overdue_grace_minutes", Value: "10", Description: "预计截止后结账宽限分钟数"},
|
||||
@@ -74,6 +75,7 @@ var adminVisibleConfigKeys = []string{
|
||||
"chat.listing_group_welcome",
|
||||
"chat.renter_retention_days_after_order_end",
|
||||
"distribution.default_settlement_hold_days",
|
||||
"handoff.auto_complete_timeout_minutes",
|
||||
"handoff.owner_return_confirm_timeout_minutes",
|
||||
"handoff.owner_submit_timeout_minutes",
|
||||
"handoff.renter_confirm_timeout_minutes",
|
||||
|
||||
Reference in New Issue
Block a user