Files
boursecu_admin/src/api/tahesab.ts
T

203 lines
5.6 KiB
TypeScript
Raw Normal View History

2026-06-26 17:41:52 +03:30
import useAxios from '@core/utils/useAxios'
import type { TableInput } from '@core/type/baseTable'
export interface TahesabRecord {
2026-08-27 16:15:11 +03:30
id?: number | null
2026-06-26 17:41:52 +03:30
customer_id?: number
amount?: number
desc?: string
type?: string
2026-08-27 16:15:11 +03:30
sync_status?: 'pending' | 'success' | 'failed' | 'missing'
2026-06-26 17:41:52 +03:30
sync_log?: string | null
tahesab_id?: string | null
data?: string | null
res?: string | null
created_at?: string
2026-08-27 16:15:11 +03:30
withdraw_id?: number | null
order_id?: number | null
issue_kind?: 'failed' | 'missing'
sync_target?: { type: 'row' | 'withdraw' | 'order'; id: number }
2026-06-26 17:41:52 +03:30
customer?: {
id?: number
name?: string
mobile?: string
moshtari_code?: string | number | null
}
}
2026-08-27 16:15:11 +03:30
export const getTahesabTable = async (params: TableInput & { view?: string }) =>
2026-06-26 17:41:52 +03:30
await useAxios.post<TahesabRecord[]>('/admin/tahesab/table', params)
export const getTahesabDetail = async (id: number) =>
await useAxios.get<TahesabRecord>(`/admin/tahesab/${id}`)
export const retryTahesabSanad = async (id: number) =>
await useAxios.post<{ ok: boolean; message: string; tahesab?: TahesabRecord }>(`/admin/tahesab/${id}/retry`)
2026-08-27 16:15:11 +03:30
export interface TahesabPendingSummary {
failed_rows: number
missing_withdraws: number
missing_orders: number
total: number
}
export interface TahesabSyncAllResult {
ok: boolean
retried: number
backfilled_withdraws: number
backfilled_orders: number
failed: number
errors: string[]
summary: TahesabPendingSummary
}
export const getTahesabPendingSummary = async (customerId?: number) =>
await useAxios.get<TahesabPendingSummary>('/admin/tahesab/pending-summary', {
params: customerId ? { customer_id: customerId } : undefined
})
export const getTahesabPendingDocs = async (customerId?: number, limit = 200) =>
await useAxios.get<{ rows: TahesabRecord[]; summary: TahesabPendingSummary }>(
'/admin/tahesab/pending-docs',
{ params: { ...(customerId ? { customer_id: customerId } : {}), limit } }
)
export const syncOneTahesab = async (type: 'row' | 'withdraw' | 'order', id: number) =>
await useAxios.post<{ ok: boolean; message: string }>('/admin/tahesab/sync-one', { type, id })
export const syncAllTahesabPending = async (limit = 80, customerId?: number) =>
await useAxios.post<TahesabSyncAllResult>('/admin/tahesab/sync-all-pending', {
limit,
...(customerId ? { customer_id: customerId } : {})
})
2026-06-26 17:41:52 +03:30
export const registerCustomerInTahesab = async (customerId: number) =>
await useAxios.post<{ ok: boolean; message: string; moshtari_code?: string | number }>(
`/admin/customer/${customerId}/tahesab/register`
)
2026-06-28 21:48:17 +03:30
export interface PanelOnlyCustomer {
id: number
name: string
mobile: string
created_at: string
}
export interface TahesabOnlyCustomer {
code: number
name: string
tel: string
gid: number | null
group: string
}
export interface CustomerSyncStatus {
panel_total: number
panel_registered: number
panel_only: number
tahesab_total: number
tahesab_only_count: number
panel_only_list: {
data: PanelOnlyCustomer[]
current_page: number
last_page: number
total: number
}
tahesab_only_list: {
data: TahesabOnlyCustomer[]
current_page: number
last_page: number
total: number
}
}
export const getCustomerSyncStatus = async (params?: {
search?: string
page?: number
tahesab_page?: number
}) => await useAxios.get<CustomerSyncStatus>('/admin/tahesab/customer-sync/status', { params })
export interface SyncPanelResult {
ok: boolean
success: number
failed: number
errors: { name: string; mobile: string; error: string }[]
}
export const syncPanelToTahesab = async () =>
await useAxios.post<SyncPanelResult>('/admin/tahesab/customer-sync/panel-to-tahesab')
export const importFromTahesab = async (customers: TahesabOnlyCustomer[]) =>
await useAxios.post<SyncPanelResult>('/admin/tahesab/customer-sync/import-from-tahesab', {
customers,
})
export interface TahesabWalletSyncResult {
ok: boolean
needs_decision?: boolean
message: string
result?: {
applied: boolean
needs_decision?: boolean
skipped?: boolean
gold_delta?: number
rial_delta?: number
app_gold?: number
app_cash?: number
tahesab_gold?: number
tahesab_cash?: number
message: string
}
}
/** همگام‌سازی مانده یک مشتری با ته‌حساب */
export const syncCustomerWalletFromTahesab = async (
customerId: number,
opts?: { overwrite?: boolean; keep?: boolean; ask_if_conflict?: boolean }
) =>
await useAxios.post<TahesabWalletSyncResult>(
`/admin/customer/${customerId}/tahesab/sync-wallet`,
{
overwrite: opts?.overwrite ?? false,
keep: opts?.keep ?? false,
ask_if_conflict: opts?.ask_if_conflict ?? true,
}
)
export interface TahesabBulkWalletSyncChunk {
ok: boolean
message: string
total: number
offset: number
processed: number
next_offset: number
done: boolean
success: number
changed: number
needs_decision: number
failed: number
errors: { id: number; name: string; mobile?: string; error: string }[]
decisions: {
id: number
name: string
mobile?: string
app_gold?: number
app_cash?: number
tahesab_gold?: number
tahesab_cash?: number
message: string
}[]
}
/** یک دسته از همگام‌سازی ماندهٔ همهٔ مشتریان دارای کد ته‌حساب */
export const syncAllWalletsFromTahesabChunk = async (params?: {
offset?: number
limit?: number
overwrite?: boolean
}) =>
await useAxios.post<TahesabBulkWalletSyncChunk>('/admin/tahesab/wallet-sync/all', {
offset: params?.offset ?? 0,
limit: params?.limit ?? 20,
overwrite: params?.overwrite ?? false,
})