统一财务统计与线下提号出款口径
This commit is contained in:
@@ -95,6 +95,83 @@ func (r *Repository) disbursementListBaseQuery(ctx context.Context) *gorm.DB {
|
||||
Where("ro.offline_settlement_status IN ?", []string{"pending", "settled"}).
|
||||
Where("ro.offline_settlement_amount_cent > 0")
|
||||
|
||||
pickupManaged := db.Table("admin_pickups AS ap").
|
||||
Select(`'pickup' AS source_type,
|
||||
ap.id AS source_id,
|
||||
ap.pickup_no AS business_no,
|
||||
0 AS order_id,
|
||||
0 AS withdrawal_id,
|
||||
ap.owner_id AS user_id,
|
||||
'外部卖家' AS payee_name,
|
||||
'' AS payee_phone,
|
||||
'' AS uploader_name,
|
||||
ap.source_channel,
|
||||
'' AS account_type,
|
||||
'' AS account_name,
|
||||
'' AS account_no,
|
||||
'' AS bank_name,
|
||||
ap.settle_amount_cent AS amount_cent,
|
||||
0 AS fee_cent,
|
||||
ap.settle_amount_cent AS actual_amount_cent,
|
||||
CASE WHEN ap.offline_settlement_status = 'settled' THEN 'paid' ELSE 'payment_pending' END AS status,
|
||||
ap.offline_settlement_status AS raw_status,
|
||||
ap.completed_at AS business_created_at,
|
||||
ap.offline_settled_at AS paid_at,
|
||||
ap.offline_settled_by AS operator_id,
|
||||
COALESCE(NULLIF(operator.nickname, ''), operator.username, '') AS operator_name,
|
||||
ap.offline_settlement_remark AS remark,
|
||||
'' AS category,
|
||||
'' AS custom_category_name,
|
||||
'' AS voucher_url,
|
||||
NULL AS voided_at,
|
||||
NULL AS voided_by,
|
||||
'' AS voided_by_name,
|
||||
'' AS void_reason,
|
||||
ap.account_snapshot AS source_payload`).
|
||||
Joins("LEFT JOIN admin_users AS operator ON operator.id = ap.offline_settled_by").
|
||||
Where("ap.settlement_mode = ?", "platform_managed").
|
||||
Where("ap.offline_settlement_status IN ?", []string{"pending", "settled"}).
|
||||
Where("ap.settle_amount_cent > 0")
|
||||
|
||||
pickupAdjustments := db.Table("admin_pickup_financial_adjustments AS fa").
|
||||
Select(`'pickup_adjustment' AS source_type,
|
||||
fa.id AS source_id,
|
||||
CAST(fa.id AS CHAR) AS business_no,
|
||||
0 AS order_id,
|
||||
0 AS withdrawal_id,
|
||||
ap.owner_id AS user_id,
|
||||
'外部卖家' AS payee_name,
|
||||
'' AS payee_phone,
|
||||
'' AS uploader_name,
|
||||
ap.source_channel,
|
||||
'' AS account_type,
|
||||
'' AS account_name,
|
||||
'' AS account_no,
|
||||
'' AS bank_name,
|
||||
fa.settle_delta_cent AS amount_cent,
|
||||
0 AS fee_cent,
|
||||
fa.settle_delta_cent AS actual_amount_cent,
|
||||
CASE WHEN fa.status = 'settled' THEN 'paid' ELSE 'payment_pending' END AS status,
|
||||
fa.status AS raw_status,
|
||||
fa.created_at AS business_created_at,
|
||||
fa.settled_at AS paid_at,
|
||||
fa.settled_by AS operator_id,
|
||||
COALESCE(NULLIF(operator.nickname, ''), operator.username, '') AS operator_name,
|
||||
fa.reason AS remark,
|
||||
'' AS category,
|
||||
'' AS custom_category_name,
|
||||
'' AS voucher_url,
|
||||
NULL AS voided_at,
|
||||
NULL AS voided_by,
|
||||
'' AS voided_by_name,
|
||||
'' AS void_reason,
|
||||
ap.account_snapshot AS source_payload`).
|
||||
Joins("JOIN admin_pickups AS ap ON ap.id = fa.pickup_id").
|
||||
Joins("LEFT JOIN admin_users AS operator ON operator.id = fa.settled_by").
|
||||
Where("fa.settlement_mode = ?", "platform_managed").
|
||||
Where("fa.status IN ?", []string{"pending", "settled"}).
|
||||
Where("fa.settle_delta_cent > 0")
|
||||
|
||||
withdrawal := db.Table("withdrawal_requests AS wr").
|
||||
Select(`'withdrawal' AS source_type,
|
||||
wr.id AS source_id,
|
||||
@@ -172,7 +249,7 @@ func (r *Repository) disbursementListBaseQuery(ctx context.Context) *gorm.DB {
|
||||
Joins("LEFT JOIN admin_users AS creator ON creator.id = md.created_by").
|
||||
Joins("LEFT JOIN admin_users AS voider ON voider.id = md.voided_by")
|
||||
|
||||
union := db.Raw("? UNION ALL ? UNION ALL ?", platformManaged, withdrawal, manualOffline)
|
||||
union := db.Raw("? UNION ALL ? UNION ALL ? UNION ALL ? UNION ALL ?", platformManaged, pickupManaged, pickupAdjustments, withdrawal, manualOffline)
|
||||
return db.Table("(?) AS d", union)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user