mirror of
https://github.com/34892002/edgeKey.git
synced 2026-09-03 06:47:41 +08:00
fix: 商品库存优化
This commit is contained in:
@@ -9,6 +9,13 @@ export async function listHomeProducts(prisma: PrismaClient): Promise<ProductSum
|
||||
},
|
||||
include: {
|
||||
category: true,
|
||||
_count: {
|
||||
select: {
|
||||
cards: {
|
||||
where: { status: "UNUSED" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [{ sort: "asc" }, { id: "desc" }],
|
||||
take: 12,
|
||||
@@ -22,6 +29,8 @@ export async function listHomeProducts(prisma: PrismaClient): Promise<ProductSum
|
||||
slug: item.slug,
|
||||
coverImage: item.coverImage,
|
||||
price: item.price,
|
||||
stockMode: item.stockMode as "FINITE" | "UNLIMITED",
|
||||
availableStock: item.stockMode === "UNLIMITED" ? -1 : item._count.cards,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -99,6 +108,15 @@ export async function getProductDetailBySlug(prisma: PrismaClient, slug: string)
|
||||
slug,
|
||||
status: "ACTIVE",
|
||||
},
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
cards: {
|
||||
where: { status: "UNUSED" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
@@ -119,5 +137,7 @@ export async function getProductDetailBySlug(prisma: PrismaClient, slug: string)
|
||||
maxBuy: record.maxBuy,
|
||||
sort: record.sort,
|
||||
purchaseNote: record.purchaseNote,
|
||||
stockMode: record.stockMode as "FINITE" | "UNLIMITED",
|
||||
availableStock: record.stockMode === "UNLIMITED" ? -1 : record._count.cards,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ export interface ProductSummary {
|
||||
slug: string;
|
||||
coverImage?: string | null;
|
||||
price: number;
|
||||
stockMode: "FINITE" | "UNLIMITED";
|
||||
availableStock: number;
|
||||
}
|
||||
|
||||
export interface CategorySummary {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"scripts": {
|
||||
"dev": "vike dev",
|
||||
"build": "bun run db:generate && vike build",
|
||||
|
||||
@@ -43,10 +43,10 @@
|
||||
:disabled="!webpSupported"
|
||||
class="checkbox checkbox-primary checkbox-sm"
|
||||
/>
|
||||
<span class="text-sm text-base-content/70">图片自动压缩为 WebP</span>
|
||||
<span class="text-sm text-base-content/70">图片自动压缩为WebP</span>
|
||||
</label>
|
||||
<p v-if="!webpSupported" class="text-xs text-warning">当前浏览器环境不支持 WebP 压缩</p>
|
||||
<p class="text-xs text-base-content/50">支持图片、视频、音频、PDF 等文件格式</p>
|
||||
<p class="text-xs text-base-content/50">支持上传图片、视频、音频、PDF 等格式文件</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -120,9 +120,13 @@
|
||||
|
||||
<!-- 底部画师/版权说明文字 -->
|
||||
<div class="mt-3 text-center">
|
||||
<!-- <p class="text-[10px] font-mono tracking-widest text-white/80 drop-shadow-[0_1px_1px_rgba(0,0,0,1)]">
|
||||
Illus. {{ product.slug }} ©2026 EdgeKey
|
||||
</p> -->
|
||||
<div
|
||||
v-if="product.stockMode === 'FINITE' && product.availableStock >= 0 && product.availableStock < 10"
|
||||
class="absolute left-5 text-sm font-bold tracking-wide px-2 py-1 rounded-full shadow-lg border"
|
||||
:class="product.availableStock === 0 ? 'bg-gray-800/90 text-gray-200 border-gray-600' : 'bg-amber-500/90 text-white border-amber-400 animate-pulse'"
|
||||
>
|
||||
{{ product.availableStock === 0 ? '已售罄' : `库存紧张(${product.availableStock})` }}
|
||||
</div>
|
||||
<div class="flex items-end gap-0.5 font-black text-red-500 absolute right-6" style="text-shadow: 2px 2px 0 #fff, -1.5px -1.5px 0 #fff, 1.5px -1.5px 0 #fff, -1.5px 1.5px 0 #fff, 1.5px 1.5px 0 #fff, 2px 2px 4px rgba(0,0,0,0.3);">
|
||||
<span class="text-sm font-bold italic text-red-600 mb-1">¥</span>
|
||||
<span class="text-3xl italic leading-none tracking-tighter">{{ formatCents(product.price) }}</span>
|
||||
|
||||
@@ -71,7 +71,13 @@
|
||||
|
||||
|
||||
|
||||
<AppButton variant="primary" :loading="submitting" :disabled="!paymentMethods.length" @click="handleCreateOrder">提交订单</AppButton>
|
||||
<p v-if="product.stockMode === 'FINITE' && product.availableStock >= 0 && product.availableStock < 10" class="text-sm" :class="product.availableStock === 0 ? 'text-error' : 'text-warning'">
|
||||
{{ product.availableStock === 0 ? '商品都卖光了,看看其他商品' : `库存紧张,仅剩 ${product.availableStock} 件` }}
|
||||
</p>
|
||||
|
||||
<AppButton variant="primary" :loading="submitting" :disabled="!paymentMethods.length || (product.stockMode === 'FINITE' && product.availableStock === 0)" @click="handleCreateOrder">
|
||||
{{ product.stockMode === 'FINITE' && product.availableStock === 0 ? '已售罄' : '提交订单' }}
|
||||
</AppButton>
|
||||
<p v-if="!paymentMethods.length" class="text-sm text-warning">当前没有可用支付方式,请联系管理员启用支付配置。</p>
|
||||
<p v-if="errorMessage" class="text-sm text-error">{{ errorMessage }}</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user