merge(dev_jacy): persist package imageUrls on approve
This commit is contained in:
@@ -34,7 +34,7 @@ export const STORE_PACKAGE_IMAGE_MAX_COUNT = 20;
|
|||||||
/** 门店环境照最多张数(总部/合伙人上传) */
|
/** 门店环境照最多张数(总部/合伙人上传) */
|
||||||
export const STORE_ENV_PHOTO_MAX_COUNT = 20;
|
export const STORE_ENV_PHOTO_MAX_COUNT = 20;
|
||||||
|
|
||||||
/** 归一化套餐图片:兼容 imageUrl / imageUrls,去重后截断上限 */
|
/** 归一化套餐图片:兼容 imageUrl / imageUrls(含 JSON 字符串),去重后截断上限 */
|
||||||
export function normalizeStorePackageImageUrls(input: {
|
export function normalizeStorePackageImageUrls(input: {
|
||||||
imageUrl?: string | null;
|
imageUrl?: string | null;
|
||||||
imageUrls?: unknown;
|
imageUrls?: unknown;
|
||||||
@@ -47,8 +47,25 @@ export function normalizeStorePackageImageUrls(input: {
|
|||||||
seen.add(url);
|
seen.add(url);
|
||||||
out.push(url);
|
out.push(url);
|
||||||
};
|
};
|
||||||
if (Array.isArray(input.imageUrls)) {
|
|
||||||
for (const item of input.imageUrls) push(item);
|
let list: unknown = input.imageUrls;
|
||||||
|
if (typeof list === 'string') {
|
||||||
|
const trimmed = list.trim();
|
||||||
|
if (trimmed.startsWith('[')) {
|
||||||
|
try {
|
||||||
|
list = JSON.parse(trimmed);
|
||||||
|
} catch {
|
||||||
|
list = trimmed ? [trimmed] : [];
|
||||||
|
}
|
||||||
|
} else if (trimmed) {
|
||||||
|
list = [trimmed];
|
||||||
|
} else {
|
||||||
|
list = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(list)) {
|
||||||
|
for (const item of list) push(item);
|
||||||
}
|
}
|
||||||
if (out.length === 0) push(input.imageUrl);
|
if (out.length === 0) push(input.imageUrl);
|
||||||
return out.slice(0, STORE_PACKAGE_IMAGE_MAX_COUNT);
|
return out.slice(0, STORE_PACKAGE_IMAGE_MAX_COUNT);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export class StorePackageService {
|
|||||||
usableTime,
|
usableTime,
|
||||||
otherNotes,
|
otherNotes,
|
||||||
imageUrl: imageUrls[0] ?? null,
|
imageUrl: imageUrls[0] ?? null,
|
||||||
imageUrls: imageUrls.length ? imageUrls : null,
|
imageUrls,
|
||||||
sortOrder: Number.isFinite(sortOrder) ? sortOrder : index,
|
sortOrder: Number.isFinite(sortOrder) ? sortOrder : index,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ export class StorePackageService {
|
|||||||
usableTime: row.usableTime,
|
usableTime: row.usableTime,
|
||||||
otherNotes: row.otherNotes,
|
otherNotes: row.otherNotes,
|
||||||
imageUrl: imageUrls[0] ?? null,
|
imageUrl: imageUrls[0] ?? null,
|
||||||
imageUrls: imageUrls.length ? imageUrls : null,
|
imageUrls,
|
||||||
sortOrder: row.sortOrder,
|
sortOrder: row.sortOrder,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -229,6 +229,19 @@ export class StorePackageService {
|
|||||||
return serializeBigInt({ live });
|
return serializeBigInt({ live });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private packageImageWrite(pkg: {
|
||||||
|
imageUrl?: string | null;
|
||||||
|
imageUrls?: string[] | null;
|
||||||
|
}) {
|
||||||
|
const imageUrls = normalizeStorePackageImageUrls(pkg);
|
||||||
|
return {
|
||||||
|
imageUrl: imageUrls[0] ?? null,
|
||||||
|
imageUrls: imageUrls.length
|
||||||
|
? (imageUrls as Prisma.InputJsonValue)
|
||||||
|
: Prisma.JsonNull,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private async replaceLivePackages(storeId: bigint, packages: StorePackageItemDto[]) {
|
private async replaceLivePackages(storeId: bigint, packages: StorePackageItemDto[]) {
|
||||||
await this.prisma.$transaction([
|
await this.prisma.$transaction([
|
||||||
this.prisma.storePackage.deleteMany({ where: { storeId } }),
|
this.prisma.storePackage.deleteMany({ where: { storeId } }),
|
||||||
@@ -241,10 +254,7 @@ export class StorePackageService {
|
|||||||
dishes: pkg.dishes,
|
dishes: pkg.dishes,
|
||||||
usableTime: pkg.usableTime ?? null,
|
usableTime: pkg.usableTime ?? null,
|
||||||
otherNotes: pkg.otherNotes ?? null,
|
otherNotes: pkg.otherNotes ?? null,
|
||||||
imageUrl: pkg.imageUrl ?? null,
|
...this.packageImageWrite(pkg),
|
||||||
imageUrls: pkg.imageUrls?.length
|
|
||||||
? (pkg.imageUrls as Prisma.InputJsonValue)
|
|
||||||
: Prisma.JsonNull,
|
|
||||||
sortOrder: pkg.sortOrder ?? index,
|
sortOrder: pkg.sortOrder ?? index,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -336,7 +346,7 @@ export class StorePackageService {
|
|||||||
});
|
});
|
||||||
return serializeBigInt({ id: updated.id.toString(), status: updated.status });
|
return serializeBigInt({ id: updated.id.toString(), status: updated.status });
|
||||||
}
|
}
|
||||||
const packages = req.packagesJson as unknown as StorePackageItemDto[];
|
const packages = this.normalizePackages(req.packagesJson);
|
||||||
await this.prisma.$transaction(async (tx) => {
|
await this.prisma.$transaction(async (tx) => {
|
||||||
await tx.storePackage.deleteMany({ where: { storeId: req.storeId } });
|
await tx.storePackage.deleteMany({ where: { storeId: req.storeId } });
|
||||||
for (let i = 0; i < packages.length; i++) {
|
for (let i = 0; i < packages.length; i++) {
|
||||||
@@ -349,6 +359,7 @@ export class StorePackageService {
|
|||||||
dishes: pkg.dishes,
|
dishes: pkg.dishes,
|
||||||
usableTime: pkg.usableTime ?? null,
|
usableTime: pkg.usableTime ?? null,
|
||||||
otherNotes: pkg.otherNotes ?? null,
|
otherNotes: pkg.otherNotes ?? null,
|
||||||
|
...this.packageImageWrite(pkg),
|
||||||
sortOrder: pkg.sortOrder ?? i,
|
sortOrder: pkg.sortOrder ?? i,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -247,7 +247,8 @@ export class StoreService {
|
|||||||
usableTime: p.usableTime,
|
usableTime: p.usableTime,
|
||||||
otherNotes: p.otherNotes,
|
otherNotes: p.otherNotes,
|
||||||
imageUrl: imageUrls[0] ?? null,
|
imageUrl: imageUrls[0] ?? null,
|
||||||
imageUrls: imageUrls.length ? imageUrls : null,
|
/** C 端始终返回数组,便于多图轮播 */
|
||||||
|
imageUrls,
|
||||||
sortOrder: p.sortOrder,
|
sortOrder: p.sortOrder,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user