Skip to content

Wallet — Technical Map

Auto-generated bởi codebase-doc-generator ngày 2026-03-23 (v2 — verified từ code thực). Không chỉnh sửa thủ công. Re-generate khi code thay đổi lớn.

Frontend Components (phân tán — không có module riêng)

Wallet UI nằm rải trong nhiều modules. Dưới đây là các components chính:

Module: user

ComponentPath (từ diva-admin/src/modules/user/)Chức năng
EmployeeProfileCommissioncomponents/employee/EmployeeProfileCommission.tsxLịch sử commission NV
WithdrawCardscomponents/customer/WithdrawCards.tsxCards thống kê rút tiền
WithdrawTablecomponents/customer/WithdrawTable.tsxBảng yêu cầu rút tiền
WithdrawToolbarcomponents/customer/WithdrawToolbar.tsxToolbar filter rút tiền
StatisticCustomerWalletscomponents/customer/StatisticCustomerWallets.tsxThống kê ví KH (6 loại: sales, actual_revenue, debt, commission, vnd, vnd_promotion)
StatisticWalletPromotionPopupcomponents/customer/StatisticWalletPromotionPopup.tsxPopup chi tiết ví khuyến mãi
StatisticWalletVndPopupcomponents/customer/StatisticWalletVndPopup.tsxPopup chi tiết ví VND
CustomerEWalletInformationcomponents/customer/CustomerEWalletInformation.tsxThông tin e-wallet KH
CustomerWithdrawHistorycomponents/customer/CustomerWithdrawHistory.tsxLịch sử rút tiền KH
PaymentHistoriescomponents/customer/PaymentHistories.tsxLịch sử thanh toán

Module: ecommerce

ComponentPath (từ diva-admin/src/modules/ecommerce/)Chức năng
CommissionRefundConfirmFormcomponents/withdraw-request/CommissionRefundConfirmForm.tsxNhập truy thu commission
DoctorCommissionConfirmFormcomponents/withdraw-request/DoctorCommissionConfirmForm.tsxTruy thu commission bác sĩ
WithdrawRequestTablecomponents/withdraw-request/WithdrawRequestTable.tsxBảng danh sách withdraw requests
WithdrawFormcomponents/withdraw-request/WithdrawForm.tsxForm tạo withdraw
WithdrawRequestFormcomponents/withdraw-request/WithdrawRequestForm.tsxForm chỉnh sửa request
RequestLogInfocomponents/withdraw-request/RequestLogInfo.tsxLog duyệt
OrderCommissionTablecomponents/order/OrderCommissionTable.tsxBảng commission đơn hàng
OrderCommissionItemcomponents/order/OrderCommissionItem.tsxItem commission
ServiceOrderCommissionCreatecomponents/order/service-order/ServiceOrderCommissionCreate.tsxTạo commission ĐH dịch vụ
ServiceOrderCommissionFormcomponents/order/service-order/add-commission/ServiceOrderCommissionForm.tsxForm commission DV
CosmeticOrderCommissionCreatecomponents/order/cosmetic-order/CosmeticOrderCommissionCreate.tsxTạo commission ĐH mỹ phẩm
PrepaidOrderCommissionCreatecomponents/prepaid-order/PrepaidOrderCommissionCreate.tsxTạo commission ĐH trả trước
ServiceCommissionFormcomponents/service/ServiceForm/ServiceCommissionForm.tsxCấu hình commission DV
NegativeCommissionTablecomponents/negative-payment-request/NegativeCommissionTable.tsxCommission âm

Pages ecommerce:

  • pages/WithdrawRequest.tsx — Danh sách withdraw requests
  • pages/WithdrawRequestCreate.tsx — Tạo mới
  • pages/WithdrawRequestDetail.tsx — Chi tiết (12,000+ dòng)
  • pages/OrderCommissions.tsx — Commission đơn hàng

Module: settings

ComponentPath (từ diva-admin/src/modules/settings/)Chức năng
CommissionSettingpages/CommissionSetting.tsxCấu hình commission
ServiceCommissionCreatepages/ServiceCommissionCreate.tsxTạo commission theo DV
PromotionWalletpages/PromotionWallet.tsxToggle ví khuyến mãi
ServiceCommissionTablecomponents/commission-setting/service-commission/ServiceCommissionTable.tsxBảng commission DV
SettingApproverDoctorCommissioncomponents/approver/SettingApproverDoctorCommission.tsxCấu hình duyệt BS

Module: affiliate

ComponentPathChức năng
PaymentTablecomponents/payment/PaymentTable.tsxThanh toán CTV
PaymentCommissionFieldcomponents/payment/PaymentCommissionField.tsxField commission
WithdrawAffiliateFormcomponents/core/WithdrawAffiliateForm.tsxForm rút tiền CTV

Module: report

ComponentPathChức năng
CommissionReportTablecomponents/commission/CommissionReportTable.tsxBáo cáo commission
CommissionReportFiltercomponents/commission/CommissionReportFilter.tsxFilter báo cáo

Hasura Actions

ActionHandlerKindPermissions
walletBalances{\{WALLET_BASE_URL}\}/actionsasynccustomer, user
changeStatusTransaction(via actions.yaml)
addOrderCommission(via actions.yaml)
createInvoiceTransaction(via actions.yaml)
changeAffiliateWalletType(via actions.yaml)
changeCustomerCommissionPercent(via actions.yaml)

Event Triggers (chính xác từ Hasura metadata)

Table: transaction

TriggerOperationColumnsWebhookRetry
transaction_insertINSERT* (all){\{WALLET_BASE_URL}\}/events0 retries, 10s interval, 60s timeout
transaction_updateUPDATEamount only{\{WALLET_BASE_URL}\}/events0 retries, 10s interval, 60s timeout
transaction_deleteDELETE* (all){\{WALLET_BASE_URL}\}/events0 retries, 10s interval, 60s timeout

Table: transaction_request

TriggerOperationColumnsWebhookRetry
transaction_request_insertINSERT* (all){\{WALLET_BASE_URL}\}/events0 retries, 10s interval, 60s timeout
transaction_request_updateUPDATEsuccess_at, status{\{WALLET_BASE_URL}\}/events0 retries, 10s interval, 60s timeout

Table: transaction_request_user

TriggerOperationColumnsWebhookRetry
transaction_request_user_insertINSERT* (all){\{WALLET_BASE_URL}\}/events0 retries, 10s interval, 60s timeout

Database Tables (24 tables — wallet DB)

Bảng chính

#TableMô tả
1walletVí per user+type (composite key: user_id + wallet_type_id)
2wallet_typeĐịnh nghĩa loại ví (VND, COMMISSION, VND_PROMOTION, POINT)
3wallet_currencyĐồng tiền hỗ trợ (VND, P) + conversion rate
4wallet_userView user info (code, display_name, branch_id, role, glcid, disabled_at)
5transactionBút toán (amount, before_amount, after_amount)
6transaction_typeLoại GD (D=Deposit, T=Transfer, W=Withdraw)
7transaction_requestYêu cầu GD (status, behavior_id, payment_gateway_id, order_id, branch_id)
8transaction_request_statusEnum trạng thái (R/P/S/Reject/C)
9transaction_request_userMulti-party: sender/receiver per request
10transaction_request_logAudit trail duyệt
11transaction_request_campaignLiên kết request ↔ campaign

Bảng tham chiếu

#TableMô tả
12payment_gatewayPhương thức thanh toán (CASH, BANK, P, wallet_promotion)
13payment_gateway_wallet_typeMapping gateway ↔ wallet type
14user_payment_gatewayCấu hình gateway per user
15wallet_master_dataMaster data: behavior types
16wallet_master_data_typePhân loại master data
17wallet_reference_addressĐịa chỉ tham chiếu (cho rút tiền)
18wallet_reference_fileFile đính kèm (chứng từ)
19app_wallet_settingCấu hình ví app-level
20permission_walletRBAC cho wallet operations
21commission_revoke_logLog hoàn commission CTV
22order_commission_refundView: commission + refund per order per user

Computed Views/Results

#TableMô tả
23wallet_balance_resultBalance tính toán + ranking
24wallet_stats_resultThống kê inflow/outflow

SQL Functions (5)

FunctionMô tả
wallet_balance()Tính balance real-time
wallet_stats()Thống kê ví
wallet_kpi_balance()KPI metrics cho balance
wallet_kpi_stats()KPI metrics cho stats
search_employee_daily_commission_clawback()Truy thu commission theo ngày (v1.2)

Go Source Files (wallet-api)

FilePath (từ diva-backend/)Chức năng
Actions
wallet.goservices/wallet-api/action/wallet.go (159 lines)Action walletBalances: query balance, tự tạo wallet
change_status_transaction_refund.goservices/wallet-api/action/change_status_transaction_refund.goRefund logic: approve/reject, xử lý hoàn tiền
action.goservices/wallet-api/action/action.go (53 lines)Router setup
type.goservices/wallet-api/action/type.goType definitions
Events
transaction_insert.goservices/wallet-api/event/transaction_insert.goCộng/trừ ví, tạo ecommerce_transaction, gửi ZNS
transaction_update.goservices/wallet-api/event/transaction_update.goCập nhật ví khi amount thay đổi
transaction_delete.goservices/wallet-api/event/transaction_delete.goHoàn tác transaction
transaction_request_insert.goservices/wallet-api/event/transaction_request_insert.goSync HRM, cập nhật order
transaction_request_update.goservices/wallet-api/event/transaction_request_update.goNotification, xử lý refund
transaction_request_user_insert.goservices/wallet-api/event/transaction_request_user_insert.goGenerate code, update keywords
refund_log_sync.goservices/wallet-api/event/refund_log_sync.go (201 lines)Helper: isRefundBehavior(), refundStatusFromTransactionStatus()
event.goservices/wallet-api/event/event.goRouter setup
Infra
main.goservices/wallet-api/server/main.goEntry point, Gin server
env.goservices/wallet-api/env/env.goEnvironment variables
config.goservices/wallet-api/env/config.goConfig structure

Tổng: ~4,144 dòng Go code

Hasura RBAC (wallet tables)

RoleQuyềnFilter
customerSELECT hạn chế (amount, date, status) trên transaction, transaction_requestuser_id = X-Hasura-User-Id
userSELECT full trên hầu hết tablesKhông filter

Remote Relationships (cross-database)

TableRelationshipTarget
transaction_requestbranchRemoteecommerce.branch (branch_id)
transaction_requestorderRemoteecommerce.order (order_id)
transaction_requestinvoiceRemoteecommerce.invoice
transaction_request_useruserRemotedefault.account (user_id)
transactionuserRemotedefault.account (user_id)

Key Migrations

MigrationMô tả
1624088117982_initializationSchema khởi tạo
1689823985547_create_table_public_wallet_userTạo wallet_user
1694162035888_wallet_balanceBalance function
1695891769032_add_refund_commissionView order_commission_refund
1770439000000_add_checksum_column_transaction_requestChecksum validation (mới nhất)

Tổng: 57 migrations