feat(ops): v4.0.4 开发任务多行与版本状态同步、合伙人/门店删除、账单合伙人列

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-31 16:08:55 +08:00
parent e26206b93c
commit ac94f5f5de
15 changed files with 568 additions and 59 deletions
@@ -1,6 +1,10 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { Prisma, CityPartnerScopeType, CityPartnerStatus } from '@prisma/client';
import { resolveMaxPartnerCommissionRate, validatePartnerCommissionRates } from '@dukang/domain';
import {
assertCanDeleteCityPartner,
resolveMaxPartnerCommissionRate,
validatePartnerCommissionRates,
} from '@dukang/domain';
import { PrismaService } from '../../common/prisma/prisma.module';
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
import { PartnerCityService } from '../city-scope/partner-city.service';
@@ -502,6 +506,62 @@ export class AdminPartnersService {
return serializeBigInt(account);
}
async deletePartner(id: bigint) {
const account = await this.prisma.partnerAccount.findFirst({
where: { id, ...PRIMARY_WHERE },
include: { children: { select: { id: true } } },
});
if (!account) throw new NotFoundException('开城合伙人不存在');
const accountIds = [id, ...account.children.map((c) => c.id)];
const [storeCount, orderCount, billCount, redeemCount] = await Promise.all([
this.prisma.store.count({ where: { partnerAccountId: { in: accountIds } } }),
this.prisma.order.count({
where: {
OR: [
{ partnerAccountIdAtPay: { in: accountIds } },
{ proxyPartnerAccountId: { in: accountIds } },
],
},
}),
this.prisma.partnerBill.count({ where: { partnerAccountId: { in: accountIds } } }),
this.prisma.redeemRecord.count({
where: { store: { partnerAccountId: { in: accountIds } } },
}),
]);
const check = assertCanDeleteCityPartner({
storeCount,
orderCount: orderCount + billCount,
redeemCount,
});
if (!check.ok) throw new BadRequestException(check.message);
await this.prisma.$transaction(async (tx) => {
await tx.user.updateMany({
where: { assocPartnerAccountId: { in: accountIds } },
data: { assocPartnerAccountId: null, assocBoundAt: null },
});
await tx.partnerUserNote.deleteMany({ where: { partnerAccountId: { in: accountIds } } });
await tx.logPartnerAnalytics.deleteMany({ where: { partnerAccountId: { in: accountIds } } });
await tx.cityWarehouse.updateMany({
where: { partnerAccountId: { in: accountIds } },
data: { partnerAccountId: null },
});
await tx.partnerAccount.updateMany({
where: { id: { in: accountIds } },
data: { managedWarehouseId: null, assocQrcodeResourceId: null, activityPosterId: null },
});
const childIds = account.children.map((c) => c.id);
if (childIds.length) {
await tx.partnerAccount.deleteMany({ where: { id: { in: childIds } } });
}
await tx.partnerAccount.delete({ where: { id } });
});
return { ok: true, message: '城市合伙人已删除' };
}
async deletePartnerSubAccount(id: bigint) {
const account = await this.prisma.partnerAccount.findUnique({ where: { id } });
if (!account) throw new NotFoundException('合伙人账号不存在');