Appearance
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
| Component | Path (từ diva-admin/src/modules/user/) | Chức năng |
|---|---|---|
| EmployeeProfileCommission | components/employee/EmployeeProfileCommission.tsx | Lịch sử commission NV |
| WithdrawCards | components/customer/WithdrawCards.tsx | Cards thống kê rút tiền |
| WithdrawTable | components/customer/WithdrawTable.tsx | Bảng yêu cầu rút tiền |
| WithdrawToolbar | components/customer/WithdrawToolbar.tsx | Toolbar filter rút tiền |
| StatisticCustomerWallets | components/customer/StatisticCustomerWallets.tsx | Thống kê ví KH (6 loại: sales, actual_revenue, debt, commission, vnd, vnd_promotion) |
| StatisticWalletPromotionPopup | components/customer/StatisticWalletPromotionPopup.tsx | Popup chi tiết ví khuyến mãi |
| StatisticWalletVndPopup | components/customer/StatisticWalletVndPopup.tsx | Popup chi tiết ví VND |
| CustomerEWalletInformation | components/customer/CustomerEWalletInformation.tsx | Thông tin e-wallet KH |
| CustomerWithdrawHistory | components/customer/CustomerWithdrawHistory.tsx | Lịch sử rút tiền KH |
| PaymentHistories | components/customer/PaymentHistories.tsx | Lịch sử thanh toán |
Module: ecommerce
| Component | Path (từ diva-admin/src/modules/ecommerce/) | Chức năng |
|---|---|---|
| CommissionRefundConfirmForm | components/withdraw-request/CommissionRefundConfirmForm.tsx | Nhập truy thu commission |
| DoctorCommissionConfirmForm | components/withdraw-request/DoctorCommissionConfirmForm.tsx | Truy thu commission bác sĩ |
| WithdrawRequestTable | components/withdraw-request/WithdrawRequestTable.tsx | Bảng danh sách withdraw requests |
| WithdrawForm | components/withdraw-request/WithdrawForm.tsx | Form tạo withdraw |
| WithdrawRequestForm | components/withdraw-request/WithdrawRequestForm.tsx | Form chỉnh sửa request |
| RequestLogInfo | components/withdraw-request/RequestLogInfo.tsx | Log duyệt |
| OrderCommissionTable | components/order/OrderCommissionTable.tsx | Bảng commission đơn hàng |
| OrderCommissionItem | components/order/OrderCommissionItem.tsx | Item commission |
| ServiceOrderCommissionCreate | components/order/service-order/ServiceOrderCommissionCreate.tsx | Tạo commission ĐH dịch vụ |
| ServiceOrderCommissionForm | components/order/service-order/add-commission/ServiceOrderCommissionForm.tsx | Form commission DV |
| CosmeticOrderCommissionCreate | components/order/cosmetic-order/CosmeticOrderCommissionCreate.tsx | Tạo commission ĐH mỹ phẩm |
| PrepaidOrderCommissionCreate | components/prepaid-order/PrepaidOrderCommissionCreate.tsx | Tạo commission ĐH trả trước |
| ServiceCommissionForm | components/service/ServiceForm/ServiceCommissionForm.tsx | Cấu hình commission DV |
| NegativeCommissionTable | components/negative-payment-request/NegativeCommissionTable.tsx | Commission âm |
Pages ecommerce:
pages/WithdrawRequest.tsx— Danh sách withdraw requestspages/WithdrawRequestCreate.tsx— Tạo mớipages/WithdrawRequestDetail.tsx— Chi tiết (12,000+ dòng)pages/OrderCommissions.tsx— Commission đơn hàng
Module: settings
| Component | Path (từ diva-admin/src/modules/settings/) | Chức năng |
|---|---|---|
| CommissionSetting | pages/CommissionSetting.tsx | Cấu hình commission |
| ServiceCommissionCreate | pages/ServiceCommissionCreate.tsx | Tạo commission theo DV |
| PromotionWallet | pages/PromotionWallet.tsx | Toggle ví khuyến mãi |
| ServiceCommissionTable | components/commission-setting/service-commission/ServiceCommissionTable.tsx | Bảng commission DV |
| SettingApproverDoctorCommission | components/approver/SettingApproverDoctorCommission.tsx | Cấu hình duyệt BS |
Module: affiliate
| Component | Path | Chức năng |
|---|---|---|
| PaymentTable | components/payment/PaymentTable.tsx | Thanh toán CTV |
| PaymentCommissionField | components/payment/PaymentCommissionField.tsx | Field commission |
| WithdrawAffiliateForm | components/core/WithdrawAffiliateForm.tsx | Form rút tiền CTV |
Module: report
| Component | Path | Chức năng |
|---|---|---|
| CommissionReportTable | components/commission/CommissionReportTable.tsx | Báo cáo commission |
| CommissionReportFilter | components/commission/CommissionReportFilter.tsx | Filter báo cáo |
Hasura Actions
| Action | Handler | Kind | Permissions |
|---|---|---|---|
walletBalances | {\{WALLET_BASE_URL}\}/actions | async | customer, 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
| Trigger | Operation | Columns | Webhook | Retry |
|---|---|---|---|---|
transaction_insert | INSERT | * (all) | {\{WALLET_BASE_URL}\}/events | 0 retries, 10s interval, 60s timeout |
transaction_update | UPDATE | amount only | {\{WALLET_BASE_URL}\}/events | 0 retries, 10s interval, 60s timeout |
transaction_delete | DELETE | * (all) | {\{WALLET_BASE_URL}\}/events | 0 retries, 10s interval, 60s timeout |
Table: transaction_request
| Trigger | Operation | Columns | Webhook | Retry |
|---|---|---|---|---|
transaction_request_insert | INSERT | * (all) | {\{WALLET_BASE_URL}\}/events | 0 retries, 10s interval, 60s timeout |
transaction_request_update | UPDATE | success_at, status | {\{WALLET_BASE_URL}\}/events | 0 retries, 10s interval, 60s timeout |
Table: transaction_request_user
| Trigger | Operation | Columns | Webhook | Retry |
|---|---|---|---|---|
transaction_request_user_insert | INSERT | * (all) | {\{WALLET_BASE_URL}\}/events | 0 retries, 10s interval, 60s timeout |
Database Tables (24 tables — wallet DB)
Bảng chính
| # | Table | Mô tả |
|---|---|---|
| 1 | wallet | Ví per user+type (composite key: user_id + wallet_type_id) |
| 2 | wallet_type | Định nghĩa loại ví (VND, COMMISSION, VND_PROMOTION, POINT) |
| 3 | wallet_currency | Đồng tiền hỗ trợ (VND, P) + conversion rate |
| 4 | wallet_user | View user info (code, display_name, branch_id, role, glcid, disabled_at) |
| 5 | transaction | Bút toán (amount, before_amount, after_amount) |
| 6 | transaction_type | Loại GD (D=Deposit, T=Transfer, W=Withdraw) |
| 7 | transaction_request | Yêu cầu GD (status, behavior_id, payment_gateway_id, order_id, branch_id) |
| 8 | transaction_request_status | Enum trạng thái (R/P/S/Reject/C) |
| 9 | transaction_request_user | Multi-party: sender/receiver per request |
| 10 | transaction_request_log | Audit trail duyệt |
| 11 | transaction_request_campaign | Liên kết request ↔ campaign |
Bảng tham chiếu
| # | Table | Mô tả |
|---|---|---|
| 12 | payment_gateway | Phương thức thanh toán (CASH, BANK, P, wallet_promotion) |
| 13 | payment_gateway_wallet_type | Mapping gateway ↔ wallet type |
| 14 | user_payment_gateway | Cấu hình gateway per user |
| 15 | wallet_master_data | Master data: behavior types |
| 16 | wallet_master_data_type | Phân loại master data |
| 17 | wallet_reference_address | Địa chỉ tham chiếu (cho rút tiền) |
| 18 | wallet_reference_file | File đính kèm (chứng từ) |
| 19 | app_wallet_setting | Cấu hình ví app-level |
| 20 | permission_wallet | RBAC cho wallet operations |
| 21 | commission_revoke_log | Log hoàn commission CTV |
| 22 | order_commission_refund | View: commission + refund per order per user |
Computed Views/Results
| # | Table | Mô tả |
|---|---|---|
| 23 | wallet_balance_result | Balance tính toán + ranking |
| 24 | wallet_stats_result | Thống kê inflow/outflow |
SQL Functions (5)
| Function | Mô 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)
| File | Path (từ diva-backend/) | Chức năng |
|---|---|---|
| Actions | ||
| wallet.go | services/wallet-api/action/wallet.go (159 lines) | Action walletBalances: query balance, tự tạo wallet |
| change_status_transaction_refund.go | services/wallet-api/action/change_status_transaction_refund.go | Refund logic: approve/reject, xử lý hoàn tiền |
| action.go | services/wallet-api/action/action.go (53 lines) | Router setup |
| type.go | services/wallet-api/action/type.go | Type definitions |
| Events | ||
| transaction_insert.go | services/wallet-api/event/transaction_insert.go | Cộng/trừ ví, tạo ecommerce_transaction, gửi ZNS |
| transaction_update.go | services/wallet-api/event/transaction_update.go | Cập nhật ví khi amount thay đổi |
| transaction_delete.go | services/wallet-api/event/transaction_delete.go | Hoàn tác transaction |
| transaction_request_insert.go | services/wallet-api/event/transaction_request_insert.go | Sync HRM, cập nhật order |
| transaction_request_update.go | services/wallet-api/event/transaction_request_update.go | Notification, xử lý refund |
| transaction_request_user_insert.go | services/wallet-api/event/transaction_request_user_insert.go | Generate code, update keywords |
| refund_log_sync.go | services/wallet-api/event/refund_log_sync.go (201 lines) | Helper: isRefundBehavior(), refundStatusFromTransactionStatus() |
| event.go | services/wallet-api/event/event.go | Router setup |
| Infra | ||
| main.go | services/wallet-api/server/main.go | Entry point, Gin server |
| env.go | services/wallet-api/env/env.go | Environment variables |
| config.go | services/wallet-api/env/config.go | Config structure |
Tổng: ~4,144 dòng Go code
Hasura RBAC (wallet tables)
| Role | Quyền | Filter |
|---|---|---|
customer | SELECT hạn chế (amount, date, status) trên transaction, transaction_request | user_id = X-Hasura-User-Id |
user | SELECT full trên hầu hết tables | Không filter |
Remote Relationships (cross-database)
| Table | Relationship | Target |
|---|---|---|
transaction_request → branch | Remote | ecommerce.branch (branch_id) |
transaction_request → order | Remote | ecommerce.order (order_id) |
transaction_request → invoice | Remote | ecommerce.invoice |
transaction_request_user → user | Remote | default.account (user_id) |
transaction → user | Remote | default.account (user_id) |
Key Migrations
| Migration | Mô tả |
|---|---|
1624088117982_initialization | Schema khởi tạo |
1689823985547_create_table_public_wallet_user | Tạo wallet_user |
1694162035888_wallet_balance | Balance function |
1695891769032_add_refund_commission | View order_commission_refund |
1770439000000_add_checksum_column_transaction_request | Checksum validation (mới nhất) |
Tổng: 57 migrations