V4.0.9版本更新合伙人H5端调整
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { Body, Controller, Get, Param, Post, Put, Query, Res, UseGuards } from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { IsOptional, IsString, MaxLength } from 'class-validator';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsBoolean, IsOptional, IsString, MaxLength } from 'class-validator';
|
||||
import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
|
||||
import { OptionalJwtAuthGuard } from '../../common/guards/optional-jwt-auth.guard';
|
||||
import { PartnerPrimaryGuard } from '../../common/guards/partner-primary.guard';
|
||||
import { PartnerPermissionGuard } from '../../common/guards/partner-permission.guard';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
import { PartnerAssocService } from './partner-assoc.service';
|
||||
|
||||
@@ -16,6 +19,17 @@ class BindPartnerAssocDto {
|
||||
partnerId?: string;
|
||||
}
|
||||
|
||||
class TouchPartnerAssocDto extends BindPartnerAssocDto {
|
||||
@IsOptional()
|
||||
@Transform(({ value }) => {
|
||||
if (value === false || value === 'false' || value === 0 || value === '0') return false;
|
||||
if (value === true || value === 'true' || value === 1 || value === '1') return true;
|
||||
return undefined;
|
||||
})
|
||||
@IsBoolean()
|
||||
countScan?: boolean;
|
||||
}
|
||||
|
||||
class PartnerAssocRemarkDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@@ -23,6 +37,21 @@ class PartnerAssocRemarkDto {
|
||||
remark?: string | null;
|
||||
}
|
||||
|
||||
@Controller('user/partner-assoc')
|
||||
export class UserPartnerAssocPublicController {
|
||||
constructor(private readonly assoc: PartnerAssocService) {}
|
||||
|
||||
@Post('touch')
|
||||
@UseGuards(OptionalJwtAuthGuard)
|
||||
touch(@Body() dto: TouchPartnerAssocDto) {
|
||||
return this.assoc.touchScan({
|
||||
scene: dto.scene,
|
||||
partnerId: dto.partnerId,
|
||||
countScan: dto.countScan,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Controller('user/partner-assoc')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class UserPartnerAssocController {
|
||||
@@ -35,7 +64,7 @@ export class UserPartnerAssocController {
|
||||
}
|
||||
|
||||
@Controller('partner/assoc')
|
||||
@UseGuards(JwtAuthGuard, PartnerPrimaryGuard)
|
||||
@UseGuards(JwtAuthGuard, PartnerPermissionGuard)
|
||||
export class PartnerAssocController {
|
||||
constructor(private readonly assoc: PartnerAssocService) {}
|
||||
|
||||
|
||||
@@ -92,6 +92,32 @@ export class PartnerAssocService {
|
||||
};
|
||||
}
|
||||
|
||||
async touchScan(input: { scene?: string; partnerId?: string; countScan?: boolean }) {
|
||||
const partnerIdRaw = parseAssocScene(input.scene) || input.partnerId?.trim();
|
||||
if (!partnerIdRaw || !/^\d+$/.test(partnerIdRaw)) {
|
||||
throw new BadRequestException('关联码无效');
|
||||
}
|
||||
const primary = await this.partnerCityService.resolvePrimaryAccount(BigInt(partnerIdRaw));
|
||||
if (primary.isPrimary !== 1 || primary.status !== 'ACTIVE') {
|
||||
throw new BadRequestException('合伙人不存在或已停用');
|
||||
}
|
||||
const shouldCountScan = input.countScan !== false;
|
||||
let scanCount = primary.assocScanCount ?? 0;
|
||||
if (shouldCountScan) {
|
||||
const updated = await this.prisma.partnerAccount.update({
|
||||
where: { id: primary.id },
|
||||
data: { assocScanCount: { increment: 1 } },
|
||||
select: { assocScanCount: true },
|
||||
});
|
||||
scanCount = updated.assocScanCount;
|
||||
}
|
||||
return {
|
||||
partnerId: primary.id.toString(),
|
||||
scanCounted: shouldCountScan,
|
||||
scanCount,
|
||||
};
|
||||
}
|
||||
|
||||
async unbindUser(userId: bigint) {
|
||||
const user = await this.prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user) throw new NotFoundException('用户不存在');
|
||||
@@ -149,9 +175,10 @@ export class PartnerAssocService {
|
||||
partnerId: primary.id.toString(),
|
||||
qrcodeUrl: ensured.qrcodeUrl,
|
||||
userCount,
|
||||
scanCount: primary.assocScanCount ?? 0,
|
||||
companyName: primary.companyName,
|
||||
name: primary.name,
|
||||
activityPosterId,
|
||||
activityPosterId: partnerAccountId === primary.id ? activityPosterId : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
PartnerAssocController,
|
||||
PartnerCommissionController,
|
||||
UserPartnerAssocController,
|
||||
UserPartnerAssocPublicController,
|
||||
} from './partner-assoc.controller';
|
||||
|
||||
@Module({
|
||||
@@ -62,6 +63,7 @@ import {
|
||||
PartnerStoreInfoChangeController,
|
||||
ShopStoreInfoChangeController,
|
||||
AdminStoreInfoChangeController,
|
||||
UserPartnerAssocPublicController,
|
||||
UserPartnerAssocController,
|
||||
PartnerAssocController,
|
||||
PartnerCommissionController,
|
||||
|
||||
Reference in New Issue
Block a user