门店审核功能
This commit is contained in:
@@ -28,6 +28,9 @@ export class AdminStoresService {
|
||||
const where: Prisma.StoreWhereInput = {};
|
||||
if (query.name) where.name = { contains: query.name };
|
||||
if (query.status) where.status = query.status as Prisma.EnumStoreStatusFilter['equals'];
|
||||
if (query.auditStatus) {
|
||||
where.auditStatus = query.auditStatus as Prisma.EnumStoreAuditStatusFilter['equals'];
|
||||
}
|
||||
if (query.cityId) where.cityId = BigInt(query.cityId);
|
||||
if (query.partnerId) where.partnerAccountId = BigInt(query.partnerId);
|
||||
if (query.phone) where.phone = { contains: query.phone };
|
||||
@@ -57,6 +60,7 @@ export class AdminStoresService {
|
||||
items: items.map((s) =>
|
||||
mapStoreCompat({
|
||||
...s,
|
||||
partner: s.partnerAccount,
|
||||
account: s.bindings[0]?.storeAccount ?? null,
|
||||
bindings: undefined,
|
||||
}),
|
||||
@@ -118,11 +122,33 @@ export class AdminStoresService {
|
||||
async auditStore(id: bigint, dto: { approved: boolean; remark?: string }) {
|
||||
const store = await this.prisma.store.findUnique({ where: { id } });
|
||||
if (!store) throw new NotFoundException('门店不存在');
|
||||
const status = dto.approved ? 'OPEN' : 'PAUSED';
|
||||
if (store.auditStatus !== 'PENDING' && store.auditStatus !== 'REJECTED') {
|
||||
// 允许对已通过门店再次驳回/通过(总部纠错);PENDING/REJECTED/APPROVED 均可审核
|
||||
}
|
||||
if (!dto.approved) {
|
||||
const reason = dto.remark?.trim();
|
||||
if (!reason) throw new BadRequestException('驳回时必须填写原因');
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const updated = await this.prisma.store.update({
|
||||
where: { id },
|
||||
data: { status },
|
||||
data: dto.approved
|
||||
? {
|
||||
// 审核通过后保持闭店,由合伙人自行开门
|
||||
status: store.status === 'CLOSED' ? 'CLOSED' : 'PAUSED',
|
||||
auditStatus: 'APPROVED',
|
||||
rejectReason: null,
|
||||
auditedAt: now,
|
||||
}
|
||||
: {
|
||||
status: 'PAUSED',
|
||||
auditStatus: 'REJECTED',
|
||||
rejectReason: dto.remark!.trim(),
|
||||
auditedAt: now,
|
||||
},
|
||||
});
|
||||
|
||||
await this.prisma.commonEvent.create({
|
||||
data: {
|
||||
eventType: 'STORE_AUDIT',
|
||||
@@ -130,10 +156,20 @@ export class AdminStoresService {
|
||||
refId: id,
|
||||
actorType: 'HQ',
|
||||
status: dto.approved ? 'APPROVED' : 'REJECTED',
|
||||
remark: dto.remark ?? (dto.approved ? '审核通过' : '审核驳回'),
|
||||
remark: dto.approved
|
||||
? (dto.remark?.trim() || '审核通过,可开门营业')
|
||||
: dto.remark!.trim(),
|
||||
param1: dto.approved ? 'APPROVE' : 'REJECT',
|
||||
param1Desc: 'audit_action',
|
||||
},
|
||||
});
|
||||
return serializeBigInt(updated);
|
||||
|
||||
return serializeBigInt({
|
||||
...updated,
|
||||
notifyHint: dto.approved
|
||||
? '已通过审核,合伙人可在端内开门营业'
|
||||
: '已驳回,驳回原因已同步至合伙人端',
|
||||
});
|
||||
}
|
||||
|
||||
async updateStore(id: bigint, dto: UpdateStoreDto) {
|
||||
@@ -217,6 +253,9 @@ export class AdminStoresService {
|
||||
openTime: '10:00',
|
||||
closeTime: '22:00',
|
||||
status: 'OPEN',
|
||||
auditStatus: 'APPROVED',
|
||||
auditedAt: new Date(),
|
||||
rejectReason: null,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user