261 lines
8.4 KiB
TypeScript
261 lines
8.4 KiB
TypeScript
import { apiBlobRequest, apiRequest } from '@/api/http'
|
|
import type { MerchantTenantStatus } from '../contracts'
|
|
export type QualificationStatus = 'PENDING' | 'APPROVED' | 'REJECTED' | 'SUPERSEDED'
|
|
export type MerchantQualificationType = 'BUSINESS_LICENSE' | 'LEGAL_PERSON_ID' | 'FREIGHT_FORWARDER_CERTIFICATE' | 'BANK_ACCOUNT_LICENSE'
|
|
|
|
export interface MerchantTenantProfile {
|
|
id: number | string
|
|
tenantCode: string
|
|
tenantName: string
|
|
status: MerchantTenantStatus
|
|
legalName: string
|
|
legalRepresentative: string
|
|
unifiedSocialCreditCode: string | null
|
|
contactName: string
|
|
contactPhone: string
|
|
contactEmail: string | null
|
|
contactWechat: string | null
|
|
enterpriseType: string | null
|
|
establishedDate: string | null
|
|
registeredCapital: number | string | null
|
|
registeredCapitalCurrency: string | null
|
|
registeredAddress: string | null
|
|
}
|
|
|
|
export interface UpdateMerchantTenantProfileRequest {
|
|
tenantName: string
|
|
legalName: string
|
|
legalRepresentative: string
|
|
contactName: string
|
|
contactPhone: string
|
|
contactEmail: string
|
|
}
|
|
|
|
export interface MerchantQualification {
|
|
id: number | string
|
|
tenantId: number | string
|
|
qualificationType: MerchantQualificationType
|
|
certificateNo: string | null
|
|
documentUrl: string
|
|
validTo: string | null
|
|
status: QualificationStatus
|
|
reviewComment: string | null
|
|
}
|
|
|
|
export interface MerchantPermissionResource {
|
|
id: number | string
|
|
tenantId: number | string
|
|
appCode: 'MERCHANT'
|
|
permissionType: 'MENU' | 'BUTTON'
|
|
parentId: number | string
|
|
permissionCode: string
|
|
permissionName: string
|
|
routePath: string | null
|
|
httpMethod: string | null
|
|
sortNo: number
|
|
status: 'ACTIVE' | string
|
|
}
|
|
|
|
export interface QualificationUploadResult {
|
|
qualificationId: number | string
|
|
reviewId: number | string | null
|
|
tenantStatus: MerchantTenantStatus
|
|
documentUrl: string
|
|
}
|
|
|
|
export interface RequiredQualificationPackageUploadResult {
|
|
businessLicenseQualificationId: number | string
|
|
legalPersonIdQualificationId: number | string
|
|
tenantStatus: MerchantTenantStatus
|
|
businessLicenseDocumentUrl: string
|
|
legalPersonIdDocumentUrl: string
|
|
}
|
|
|
|
export interface MerchantRole {
|
|
id: number | string
|
|
tenantId: number | string
|
|
appCode: 'MERCHANT'
|
|
roleCode: string
|
|
roleName: string
|
|
roleType: 'SYSTEM' | 'CUSTOM' | string
|
|
status: 'ACTIVE' | 'INACTIVE' | string
|
|
description: string | null
|
|
memberCount: number
|
|
permissionIds: Array<number | string>
|
|
}
|
|
|
|
export interface CreateMerchantRoleRequest {
|
|
roleCode: string
|
|
roleName: string
|
|
description: string
|
|
}
|
|
|
|
export interface UpdateMerchantRoleRequest {
|
|
roleName: string
|
|
description: string
|
|
}
|
|
|
|
export interface MerchantMember {
|
|
membershipId: number | string
|
|
userId: number | string
|
|
authUserId: number | string
|
|
username: string
|
|
displayName: string
|
|
phone: string | null
|
|
email: string | null
|
|
memberType: 'OWNER' | string
|
|
memberNo: string
|
|
status: 'ACTIVE' | 'INACTIVE' | string
|
|
lastLoginAt: string | null
|
|
roleIds: Array<number | string>
|
|
}
|
|
|
|
export interface MerchantPersonalProfile {
|
|
userId: number | string
|
|
authUserId: number | string
|
|
username: string
|
|
displayName: string
|
|
phone: string | null
|
|
email: string | null
|
|
}
|
|
|
|
export interface CreateMerchantMemberRequest {
|
|
username: string
|
|
password: string
|
|
displayName: string
|
|
phone: string
|
|
email: string
|
|
memberType: 'EMPLOYEE'
|
|
memberNo: string
|
|
roleIds: Array<number | string>
|
|
}
|
|
|
|
export interface UpdateMerchantMemberRequest {
|
|
displayName: string
|
|
phone: string
|
|
email: string
|
|
memberType: string
|
|
memberNo: string
|
|
roleIds: Array<number | string>
|
|
}
|
|
|
|
export function getTenantProfile() {
|
|
return apiRequest<MerchantTenantProfile>({ method: 'GET', url: '/merchant/v1/iam/tenant/profile' })
|
|
}
|
|
|
|
export function updateTenantProfile(payload: UpdateMerchantTenantProfileRequest) {
|
|
return apiRequest<MerchantTenantProfile>({ method: 'PUT', url: '/merchant/v1/iam/tenant/profile', data: payload })
|
|
}
|
|
|
|
export function getTenantQualifications() {
|
|
return apiRequest<MerchantQualification[]>({ method: 'GET', url: '/merchant/v1/iam/tenant/qualifications' })
|
|
}
|
|
|
|
export function getMerchantPermissionResources() {
|
|
return apiRequest<MerchantPermissionResource[]>({ method: 'GET', url: '/merchant/v1/iam/permissions' })
|
|
}
|
|
|
|
export function getCurrentMerchantPermissionCodes() {
|
|
return apiRequest<string[]>({ method: 'GET', url: '/merchant/v1/iam/authorization/permissions' })
|
|
}
|
|
|
|
export function getMerchantPersonalProfile() {
|
|
return apiRequest<MerchantPersonalProfile>({ method: 'GET', url: '/merchant/v1/iam/profile' })
|
|
}
|
|
|
|
export function updateMerchantPersonalProfile(payload: Pick<MerchantPersonalProfile, 'displayName' | 'phone' | 'email'>) {
|
|
return apiRequest<MerchantPersonalProfile>({ method: 'PUT', url: '/merchant/v1/iam/profile', data: payload })
|
|
}
|
|
|
|
export function uploadMerchantQualification(
|
|
file: File,
|
|
qualificationType: MerchantQualificationType,
|
|
certificateNo?: string,
|
|
replace = false,
|
|
) {
|
|
const data = new FormData()
|
|
data.append('file', file)
|
|
return apiRequest<QualificationUploadResult>({
|
|
method: 'POST',
|
|
url: '/merchant/v1/files/qualifications',
|
|
params: { qualificationType, certificateNo, replace },
|
|
data,
|
|
})
|
|
}
|
|
|
|
export function uploadMerchantRequiredQualificationPackage(
|
|
businessLicense: File,
|
|
legalPersonId: File,
|
|
unifiedSocialCreditCode: string,
|
|
replaceBusinessLicense = false,
|
|
replaceLegalPersonId = false,
|
|
) {
|
|
const data = new FormData()
|
|
data.append('businessLicense', businessLicense)
|
|
data.append('legalPersonId', legalPersonId)
|
|
return apiRequest<RequiredQualificationPackageUploadResult>({
|
|
method: 'POST',
|
|
url: '/merchant/v1/files/qualifications/required-package',
|
|
params: { unifiedSocialCreditCode, replaceBusinessLicense, replaceLegalPersonId },
|
|
data,
|
|
})
|
|
}
|
|
|
|
export function submitTenantQualificationReview() {
|
|
return apiRequest<MerchantTenantProfile>({ method: 'POST', url: '/merchant/v1/iam/tenant/qualifications/submit-review' })
|
|
}
|
|
|
|
export function downloadQualificationImage(documentUrl: string) {
|
|
const url = documentUrl.startsWith('/api/') ? documentUrl.slice(4) : documentUrl
|
|
if (!url.startsWith('/merchant/v1/files/qualifications/')) throw new Error('资质文件地址无效')
|
|
return apiBlobRequest({ method: 'GET', url })
|
|
}
|
|
|
|
export function getMerchantRoles() {
|
|
return apiRequest<MerchantRole[]>({ method: 'GET', url: '/merchant/v1/iam/roles' })
|
|
}
|
|
|
|
export function createMerchantRole(payload: CreateMerchantRoleRequest) {
|
|
return apiRequest<MerchantRole>({ method: 'POST', url: '/merchant/v1/iam/roles', data: payload })
|
|
}
|
|
|
|
export function updateMerchantRole(roleId: number | string, payload: UpdateMerchantRoleRequest) {
|
|
return apiRequest<MerchantRole>({ method: 'PUT', url: `/merchant/v1/iam/roles/${roleId}`, data: payload })
|
|
}
|
|
|
|
export function changeMerchantRoleStatus(roleId: number | string, status: 'ACTIVE' | 'DISABLED') {
|
|
return apiRequest<MerchantRole>({ method: 'PUT', url: `/merchant/v1/iam/roles/${roleId}/status`, data: { status } })
|
|
}
|
|
|
|
export function deleteMerchantRole(roleId: number | string) {
|
|
return apiRequest<void>({ method: 'DELETE', url: `/merchant/v1/iam/roles/${roleId}` })
|
|
}
|
|
|
|
export function replaceMerchantRolePermissions(roleId: number | string, permissionIds: Array<number | string>) {
|
|
return apiRequest<void>({ method: 'PUT', url: '/merchant/v1/iam/roles/permissions', data: { roleId, permissionIds } })
|
|
}
|
|
|
|
export function getMerchantMembers() {
|
|
return apiRequest<MerchantMember[]>({ method: 'GET', url: '/merchant/v1/iam/members' })
|
|
}
|
|
|
|
export function createMerchantMember(payload: CreateMerchantMemberRequest) {
|
|
return apiRequest<MerchantMember>({ method: 'POST', url: '/merchant/v1/iam/members', data: payload })
|
|
}
|
|
|
|
export function updateMerchantMember(membershipId: number | string, payload: UpdateMerchantMemberRequest) {
|
|
return apiRequest<MerchantMember>({ method: 'PUT', url: `/merchant/v1/iam/members/${membershipId}`, data: payload })
|
|
}
|
|
|
|
export function changeMerchantMemberStatus(membershipId: number | string, status: 'ACTIVE' | 'DISABLED') {
|
|
return apiRequest<MerchantMember>({ method: 'PUT', url: `/merchant/v1/iam/members/${membershipId}/status`, data: { status } })
|
|
}
|
|
|
|
export function resetMerchantMemberPassword(membershipId: number | string, newPassword: string) {
|
|
return apiRequest<void>({ method: 'PUT', url: `/merchant/v1/iam/members/${membershipId}/password`, data: { newPassword } })
|
|
}
|
|
|
|
export function replaceMerchantMemberRoles(membershipId: number | string, roleIds: Array<number | string>) {
|
|
return apiRequest<void>({ method: 'PUT', url: '/merchant/v1/iam/members/roles', data: { membershipId, roleIds } })
|
|
}
|