v3数据表更改
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
import { loadAppConfig } from '@dukang/shared-types';
|
||||
import { PrismaService } from '../../common/prisma/prisma.module';
|
||||
import { serializeBigInt } from '../../common/decorators/current-user.decorator';
|
||||
import { mapStoreCompat } from '../../common/compat/v31-compat';
|
||||
|
||||
@Injectable()
|
||||
export class StoreService {
|
||||
@@ -16,39 +17,43 @@ export class StoreService {
|
||||
async listOpenStores(cityCode?: string) {
|
||||
const where: Record<string, unknown> = { status: 'OPEN' };
|
||||
if (cityCode) {
|
||||
const city = await this.prisma.city.findFirst({ where: { code: cityCode } });
|
||||
const city = await this.prisma.commonCity.findFirst({ where: { code: cityCode } });
|
||||
if (city) where.cityId = city.id;
|
||||
}
|
||||
const stores = await this.prisma.store.findMany({
|
||||
where: where as never,
|
||||
include: { category: true },
|
||||
include: { category: true, coverResource: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
return serializeBigInt(stores);
|
||||
return serializeBigInt(stores.map(mapStoreCompat));
|
||||
}
|
||||
|
||||
async getStore(id: bigint) {
|
||||
const store = await this.prisma.store.findFirst({
|
||||
where: { id, status: 'OPEN' },
|
||||
include: { category: true, media: true },
|
||||
include: { category: true, coverResource: true },
|
||||
});
|
||||
if (!store) throw new NotFoundException('门店不存在');
|
||||
return serializeBigInt(store);
|
||||
const media = await this.prisma.commonResource.findMany({
|
||||
where: { ownerType: 'STORE', ownerId: id, status: 'ACTIVE', bizType: 'ENV' },
|
||||
orderBy: { sortOrder: 'asc' },
|
||||
});
|
||||
return serializeBigInt(mapStoreCompat({ ...store, media }));
|
||||
}
|
||||
|
||||
async partnerListStores(partnerAccountId: bigint) {
|
||||
const account = await this.getPartnerAccount(partnerAccountId);
|
||||
const stores = await this.prisma.store.findMany({
|
||||
where: { partnerId: account.partnerId },
|
||||
include: { category: true, audits: { orderBy: { submittedAt: 'desc' }, take: 1 } },
|
||||
include: { category: true, coverResource: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
return serializeBigInt(stores);
|
||||
return serializeBigInt(stores.map(mapStoreCompat));
|
||||
}
|
||||
|
||||
async createStore(partnerAccountId: bigint, body: Record<string, unknown>) {
|
||||
const account = await this.getPartnerAccount(partnerAccountId);
|
||||
const city = await this.prisma.city.findFirst({ where: { partnerId: account.partnerId } });
|
||||
const city = await this.prisma.commonCity.findFirst({ where: { partnerId: account.partnerId } });
|
||||
if (!city) throw new BadRequestException('合伙人未绑定开城');
|
||||
|
||||
const store = await this.prisma.store.create({
|
||||
@@ -63,7 +68,7 @@ export class StoreService {
|
||||
district: String(body.district ?? ''),
|
||||
address: String(body.address),
|
||||
intro: body.intro ? String(body.intro) : null,
|
||||
coverUrl: body.coverUrl ? String(body.coverUrl) : null,
|
||||
coverResourceId: body.coverResourceId ? BigInt(String(body.coverResourceId)) : null,
|
||||
bankAccountName: body.bankAccountName ? String(body.bankAccountName) : null,
|
||||
bankAccountNo: body.bankAccountNo ? String(body.bankAccountNo) : null,
|
||||
bankBranch: body.bankBranch ? String(body.bankBranch) : null,
|
||||
@@ -73,13 +78,17 @@ export class StoreService {
|
||||
},
|
||||
});
|
||||
|
||||
const audit = await this.prisma.storeAudit.create({
|
||||
const audit = await this.prisma.commonEvent.create({
|
||||
data: {
|
||||
storeId: store.id,
|
||||
auditType: 'NEW',
|
||||
eventType: 'STORE_AUDIT',
|
||||
refType: 'STORE',
|
||||
refId: store.id,
|
||||
actorType: 'PARTNER',
|
||||
actorId: partnerAccountId,
|
||||
status: this.config.autoApproveStore ? 'APPROVED' : 'PENDING',
|
||||
submitData: body as never,
|
||||
reviewedAt: this.config.autoApproveStore ? new Date() : null,
|
||||
param1: 'NEW',
|
||||
param1Desc: 'audit_type',
|
||||
extraJson: body as never,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -97,9 +106,9 @@ export class StoreService {
|
||||
async getShopStore(storeAccountId: bigint) {
|
||||
const account = await this.prisma.storeAccount.findUniqueOrThrow({
|
||||
where: { id: storeAccountId },
|
||||
include: { store: { include: { category: true } } },
|
||||
include: { store: { include: { category: true, coverResource: true } } },
|
||||
});
|
||||
return serializeBigInt(account.store);
|
||||
return serializeBigInt(mapStoreCompat(account.store));
|
||||
}
|
||||
|
||||
async updateShopStatus(storeAccountId: bigint, status: 'OPEN' | 'PAUSED') {
|
||||
|
||||
Reference in New Issue
Block a user