Skip to content

Affiliate - Technical Map

Auto-generated bởi codebase-doc-generator ngày 2026-03-23 (verified từ code thực). Không chỉnh sửa thủ công.

Routes

RoutePathMục đích
ROUTE_AFFILIATE/affiliateRoot shell
ROUTE_AFFILIATE_APPROVAL/affiliate/approvalDanh sách CTV chờ duyệt
ROUTE_AFFILIATE_APPROVAL_EDIT/affiliate/approval/:id/editChỉnh sửa hồ sơ duyệt
ROUTE_AFFILIATE_LIST/affiliate/listDanh sách CTV active
ROUTE_AFFILIATE_LIST_CREATE/affiliate/list/createTạo mới CTV
ROUTE_AFFILIATE_LIST_EDIT/affiliate/list/:id/editSửa CTV
ROUTE_AFFILIATE_LIST_REFERRAL/affiliate/list/:id/referralReferral summary theo CTV
ROUTE_AFFILIATE_ORDER/affiliate/orderDanh sách order affiliate
ROUTE_AFFILIATE_ORDER_DETAIL/affiliate/order/:id/detailChi tiết order affiliate
ROUTE_AFFILIATE_PAYMENT/affiliate/paymentDanh sách payment/invoice affiliate
ROUTE_AFFILIATE_PAYMENT_DETAIL/affiliate/payment/:id/detailChi tiết payment
ROUTE_AFFILIATE_PAYMENT_ORDER/affiliate/payment/order/:id/detailMở order detail từ payment
ItemGiá trị
Sidebar titleroute./affiliate-left-menu
moduleIdaffiliate_management
Permissions chínhITLeader, ITStaff
PlatformsAdmin, CRM, POS

Special routing

  • Root route redirect theo runtime:
    • POS + có module permission + BranchPOS -> vào ROUTE_AFFILIATE_LIST
    • ngược lại -> vào ROUTE_AFFILIATE_APPROVAL

FE Pages (10)

NhómFiles
Approvalpages/approval/ApprovalList.tsx
Listpages/list/List.tsx, ListCreate.tsx, ListReferral.tsx
Orderpages/order/OrderList.tsx, OrderDetail.tsx, OrderCustomerList.tsx
Paymentpages/payment/PaymentList.tsx, PaymentDetail.tsx, PaymentCustomerList.tsx

FE Components (31)

Core

ComponentVai trò
WithdrawAffiliateFormForm rút tiền / withdraw
ActionBarThanh action chuẩn
AffiliateByInfoThông tin CTV

List

ComponentVai trò
ListTableBảng danh sách CTV
ListToolbarSearch, membership, tag, date range, export
ListFormForm tạo/sửa CTV
ListReferralTableReferral summary
ListActivePopupPopup kích hoạt/thao tác

Order

ComponentVai trò
OrderTableBảng order affiliate
OrderCardsPending/approved cards
OrderToolbarFilter order/payment
OrderApproveBarAction approve/reject/cancel
OrderCommissionField, OrderItemCommissionFieldHiển thị commission
OrderLeftDetail, OrderRightDetailLayout chi tiết

Payment

ComponentVai trò
PaymentTableBảng invoice affiliate
PaymentActivePopupPopup action payment
PaymentCommissionField, PaymentItemCommissionFieldField commission
PaymentLeftDetail, PaymentRightDetailDetail layout

GraphQL Operations

File: diva-admin/src/modules/affiliate/graphql/affiliate.graphql

Queries chính

QueryMục đích
GetAffiliateUsers, GetAffiliateUsersAggregate, GetAffiliateUsersFileDanh sách CTV active/pending + export
GetAffiliateUserByPk, GetAffiliateUserIdByAccountId, GetAffiliateUserIdByPhoneNumberLookup CTV
SearchAffiliateUserSearch nhanh
GetAffiliateReferralListByUserIdReferral summary
GetAffiliateOrders, GetAffiliateOrderCards, GetAffiliateOrdersFile, GetAffiliateOrderByPkOrder affiliate
GetAffiliateInvoices, GetAffiliateInvoiceCards, GetAffiliateInvoicesFile, GetAffiliateInvoiceByPkInvoice/payment affiliate
GetAffiliateConfigConfig CTV
GetWithdrawHistory, GetWithdrawHistoryCardsWithdraw history
GetCustomerAffiliateReport, GetCustomerAffiliateReportCards, GetCustomerAffiliateReportFileReport drill-down dùng lại ở module report
GetCustomerNameAndEmailByPhoneNumberHỗ trợ đăng ký

Mutations chính

MutationBackend/action
RegisterAffiliateUseraffiliateUserRegistration
UpdateAffiliateUserHasura update
ChangeAffiliateUserStatusaffiliateUserChangeStatus
UpsertAffiliateConfigHasura insert/update
ChangeCustomerCommissionCập nhật commission cấu hình khách hàng/CTV

FE Filtering logic

PageLogic đáng chú ý
ApprovalList.tsxis_active = false, filter keyword/tag/membership/date
List.tsxis_active = true, chung toolbar với approval
OrderList.tsxMap UI status confirmed/wait_confirmed/canceled sang _statuses = {approved,pending,rejected} dùng function args
PaymentList.tsxMap status sang điều kiện is_approved + rejected, đồng thời chỉ lấy payment của order đã approved

Backend Actions

affiliate_user_registration.go

Hành viGhi chú
Kiểm tra trùng phone trong affiliate_userTrả REG_EXISTED hoặc REG_PENDING
Kiểm tra account customer theo phoneReuse account nếu có
handleRegisterAffiliateByUserTạo/duyệt ngay, yêu cầu tag hợp lệ
handleRegisterAffiliateByCustomerTạo bản ghi pending

affiliate_user_change_status.go

Reference typeActions
affiliate_user_typeapprove, revoke
affiliate_order_typeapprove, cancel, reject, unreject
affiliate_invoice_typeapprove, reject, unreject

Side effects chính:

  • Ghi affiliate_action_log
  • Tạo customer account nếu duyệt user mà chưa có account
  • Approve invoice sẽ gọi AddAffiliateCommission()
  • Ghi commission_revoke_log
  • Gửi notification / ZNS / SMS sau khi commission thành công

change_affiliate_wallet_type.go

Hành viGhi chú
Đổi wallet_receive_commission của orderChặn nếu có invoice approved
Tính lại temp_commission_amountTheo customer current level
Cập nhật invoice_affiliate.commission_amountCho các invoice liên quan chưa duyệt

get_report_affiliate.go

Hành viGhi chú
Đọc aggregate_affiliate_report theo chunksHỗ trợ limit/offset lớn
Query thêm wallet transactionsTính withdrawn_amount

Store/Data model

affiliate_user

FieldÝ nghĩa
account_idAccount customer gắn với CTV
affiliate_codeMã CTV, hiện thường lấy theo phone
customer_name, phone_numberThông tin chính
citizen_id, bank_*, tax_numberHồ sơ thanh toán/KYC
is_activeĐã duyệt hay chưa
approved_atThời điểm duyệt
tag_idNhãn CTV
kyc_filesTài liệu KYC

order_affiliate

FieldÝ nghĩa
order_idOrder gốc
affiliate_user_idCTV
type_idDirect / Referral
is_approved, rejectedTrạng thái duyệt
wallet_typeLoại ví nhận commission
order_totalGiá trị order
temp_commission_amountHoa hồng tạm tính

invoice_affiliate

FieldÝ nghĩa
invoice_idInvoice nguồn
paid_amountTiền thanh toán
commission_amountHoa hồng
current_customer_level, current_sale_percentSnapshot membership/percent
is_approved, rejected, approved_atTrạng thái
transaction_idLink sang wallet transaction request

Các bảng/view liên quan

ObjectVai trò
affiliate_action_logAudit trail
affiliate_user_logLịch sử người dùng CTV
affiliate_summary_viewReferral summary theo customer
affiliate_report / aggregate_affiliate_reportReport tổng hợp
summary_order_affiliate_result / function summary_order_affiliateCards cho order affiliate
invoice_affiliatePayment detail
affiliate_config, affiliate_user_tagConfig và phân loại

Backend services

ServiceVai trò
ecommerce-apiĐăng ký, đổi trạng thái, đổi ví, aggregate report
wallet-apiCommission/wallet transaction side
controller (Hasura)CRUD và functions trên ecommerce DB

Rủi ro / Findings kỹ thuật

#Note
1affiliate_user_registration dùng logic khác nhau theo role truy cập (user/admin so với customer/anonymous).
2PaymentList chỉ lấy payment của order đã approved và affiliate user active hoặc trường hợp approved lịch sử được giữ lại.
3Report customer affiliate trong module report dùng lại components từ affiliate, nên affiliate là source of truth cho drill-down.
4Dữ liệu withdraw không nằm hoàn toàn trong ecommerce; phải nối thêm wallet transactions theo behavior refund_collaborator.