fix(platform-orders): syncable_only excludes sync failed orders

This commit is contained in:
萝卜
2026-03-16 19:40:23 +08:00
parent f297ffacd5
commit 97326e9922
2 changed files with 94 additions and 1 deletions

View File

@@ -419,6 +419,8 @@ class PlatformOrderController extends Controller
->where('payment_status', 'paid')
->where('status', 'activated')
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
// 口径一致syncable_only=1 隐含 sync_status=unsynced排除同步失败等异常单
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL")
// 口径一致:排除(续费但未绑定订阅)的脏数据
->where(function (\Illuminate\Database\Eloquent\Builder $q) {
$q->where('order_type', '!=', 'renewal')
@@ -2245,11 +2247,14 @@ class PlatformOrderController extends Controller
}
})
->when(($filters['syncable_only'] ?? '') === '1', function (Builder $builder) {
// 只看可同步:已支付 + 已生效 + 尚未写入 subscription_activation.subscription_id
// 只看可同步:已支付 + 已生效 + 未同步 + 非失败
// - 未同步subscription_activation.subscription_id 为空
// - 非失败subscription_activation_error.message 为空
// 额外治理口径:排除(续费但未绑定订阅)的脏数据,避免误入可同步集合导致串单风险
$builder->where('payment_status', 'paid')
->where('status', 'activated')
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation.subscription_id') IS NULL")
->whereRaw("JSON_EXTRACT(meta, '$.subscription_activation_error.message') IS NULL")
->where(function (Builder $q) {
$q->where('order_type', '!=', 'renewal')
->orWhereNotNull('site_subscription_id');