feat: add media supply billing center
This commit is contained in:
@@ -763,9 +763,10 @@ func (s *MediaSupplyService) AdjustWallet(ctx context.Context, req AdjustMediaSu
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO media_supply_wallet_ledgers (
|
||||
tenant_id, user_id, delta_cents, balance_after_cents, reason, note, created_by
|
||||
tenant_id, user_id, delta_cents, balance_after_cents, reason, note, created_by,
|
||||
sales_cents, cost_cents, gross_profit_cents
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, 0, 0, 0)
|
||||
`, actor.TenantID, req.UserID, req.DeltaCents, balanceAfter, reason, nullableTrimmedString(req.Note), actor.UserID); err != nil {
|
||||
return nil, response.ErrInternal(50084, "media_supply_wallet_ledger_create_failed", "媒体投稿账单创建失败")
|
||||
}
|
||||
@@ -848,9 +849,15 @@ func (s *MediaSupplyService) debitMediaSupplyWallet(ctx context.Context, tx pgx.
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO media_supply_wallet_ledgers (
|
||||
tenant_id, user_id, order_id, delta_cents, balance_after_cents, reason, note, created_by
|
||||
tenant_id, user_id, order_id, delta_cents, balance_after_cents, reason, note, created_by,
|
||||
sales_cents, cost_cents, gross_profit_cents
|
||||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8,
|
||||
(SELECT sell_total_cents FROM media_supply_orders WHERE id = $3),
|
||||
(SELECT cost_total_cents FROM media_supply_orders WHERE id = $3),
|
||||
(SELECT sell_total_cents - cost_total_cents FROM media_supply_orders WHERE id = $3)
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
`, tenantID, userID, orderID, -amountCents, balanceAfter, "order_debit", nullableTrimmedString(orderTitle), createdBy); err != nil {
|
||||
return 0, response.ErrInternal(50084, "media_supply_wallet_ledger_create_failed", "媒体投稿账单创建失败")
|
||||
}
|
||||
@@ -900,9 +907,15 @@ func (s *MediaSupplyService) refundMediaSupplyWalletForOrder(ctx context.Context
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO media_supply_wallet_ledgers (
|
||||
tenant_id, user_id, order_id, delta_cents, balance_after_cents, reason, note, created_by
|
||||
tenant_id, user_id, order_id, delta_cents, balance_after_cents, reason, note, created_by,
|
||||
sales_cents, cost_cents, gross_profit_cents
|
||||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8,
|
||||
(SELECT -sell_total_cents FROM media_supply_orders WHERE id = $3),
|
||||
(SELECT -cost_total_cents FROM media_supply_orders WHERE id = $3),
|
||||
(SELECT -(sell_total_cents - cost_total_cents) FROM media_supply_orders WHERE id = $3)
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
`, tenantID, userID, orderID, debitCents, balanceAfter, "order_refund", nullableTrimmedString(ledgerNote), userID); err != nil {
|
||||
return response.ErrInternal(50084, "media_supply_wallet_ledger_create_failed", "媒体投稿账单创建失败")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user