9c8d5f2cad
订单佣金只认关联用户;合伙人备注写入独立表;H5 增加用户管理与首页统计。 Co-authored-by: Cursor <cursoragent@cursor.com>
144 lines
3.9 KiB
TypeScript
144 lines
3.9 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import {
|
|
HqPermissionGuard,
|
|
RequireHqPermissions,
|
|
} from '../../common/guards/hq-permission.guard';
|
|
import { HqOperation } from '../../common/hq-operation/hq-operation.decorator';
|
|
import { HqOperationAction } from '../../common/hq-operation/hq-operation.constants';
|
|
import { AdminPartnersService } from './admin-partners.service';
|
|
import { PartnerAssocService } from '../store/partner-assoc.service';
|
|
import { AdminPartnerAccountsQueryDto, AdminPartnersQueryDto } from './dto/admin-query.dto';
|
|
import {
|
|
CreatePartnerAccountDto,
|
|
CreatePartnerDto,
|
|
UpdatePartnerAccountDto,
|
|
UpdatePartnerDto,
|
|
} from './dto/admin-mutate.dto';
|
|
|
|
@Controller('admin/partners')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminPartnersController {
|
|
constructor(
|
|
private readonly service: AdminPartnersService,
|
|
private readonly assoc: PartnerAssocService,
|
|
) {}
|
|
|
|
@Get()
|
|
list(@Query() query: AdminPartnersQueryDto) {
|
|
return this.service.listPartners(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.service.detailPartner(BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_CREATE,
|
|
refType: 'PARTNER',
|
|
refIdField: 'id',
|
|
includeBody: true,
|
|
})
|
|
create(@Body() dto: CreatePartnerDto) {
|
|
return this.service.createPartner(dto);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_UPDATE,
|
|
refType: 'PARTNER',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('id') id: string, @Body() dto: UpdatePartnerDto) {
|
|
return this.service.updatePartner(BigInt(id), dto);
|
|
}
|
|
|
|
@Get(':id/assoc')
|
|
assocSummary(@Param('id') id: string) {
|
|
return this.assoc.getSummary(BigInt(id));
|
|
}
|
|
|
|
@Get(':id/assoc/users')
|
|
assocUsers(
|
|
@Param('id') id: string,
|
|
@Query('page') page = '1',
|
|
@Query('pageSize') pageSize = '20',
|
|
) {
|
|
return this.assoc.listUsers(BigInt(id), Number(page) || 1, Number(pageSize) || 20);
|
|
}
|
|
|
|
@Post(':id/assoc/qrcode')
|
|
regenQrcode(@Param('id') id: string) {
|
|
return this.assoc.ensureQrcode(BigInt(id), true);
|
|
}
|
|
|
|
@Post(':id/assoc/users/:userId/unbind')
|
|
@UseGuards(HqPermissionGuard)
|
|
@RequireHqPermissions('users_partner_assoc')
|
|
@HqOperation({
|
|
action: HqOperationAction.USER_ASSOC_UPDATE,
|
|
refType: 'USER',
|
|
refIdParam: 'userId',
|
|
includeBody: true,
|
|
})
|
|
unbindUser(@Param('userId') userId: string) {
|
|
return this.assoc.unbindUser(BigInt(userId));
|
|
}
|
|
}
|
|
|
|
@Controller('admin/partner-accounts')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminPartnerAccountsController {
|
|
constructor(private readonly service: AdminPartnersService) {}
|
|
|
|
@Get('tree')
|
|
tree(@Query('partnerId') partnerId?: string) {
|
|
return this.service.listPartnerAccountTree(partnerId ? BigInt(partnerId) : undefined);
|
|
}
|
|
|
|
@Get()
|
|
list(@Query() query: AdminPartnerAccountsQueryDto) {
|
|
return this.service.listPartnerAccounts(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.service.detailPartnerAccount(BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_ACCOUNT_CREATE,
|
|
refType: 'PARTNER_ACCOUNT',
|
|
refIdField: 'id',
|
|
includeBody: true,
|
|
})
|
|
create(@Body() dto: CreatePartnerAccountDto) {
|
|
return this.service.createPartnerAccount(dto);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_ACCOUNT_UPDATE,
|
|
refType: 'PARTNER_ACCOUNT',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('id') id: string, @Body() dto: UpdatePartnerAccountDto) {
|
|
return this.service.updatePartnerAccount(BigInt(id), dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.PARTNER_ACCOUNT_DELETE,
|
|
refType: 'PARTNER_ACCOUNT',
|
|
refIdParam: 'id',
|
|
})
|
|
remove(@Param('id') id: string) {
|
|
return this.service.deletePartnerSubAccount(BigInt(id));
|
|
}
|
|
}
|