fix: 需要资格的商品每个订单消耗1个资格
- 移除后台商品管理的资格消耗设置 - 修改后端资格检查和扣除逻辑为每个订单项消耗1个资格 - 修改前端显示为需要1个资格 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -133,17 +133,13 @@
|
||||
<div class="form-section">
|
||||
<div class="section-title">资格设置</div>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="8">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="需要资格">
|
||||
<el-switch v-model="form.require_credit" />
|
||||
<span class="form-tip" v-if="form.require_credit" style="margin-left: 8px; color: rgba(255,255,255,0.5);">订单消耗1个资格</span>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="资格消耗">
|
||||
<el-input-number v-model="form.credit_cost" :min="0" style="width: 100%" :disabled="!form.require_credit" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="资格奖励">
|
||||
<el-input-number v-model="form.credit_reward" :min="0" style="width: 100%" />
|
||||
</el-form-item>
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<!-- 标签 -->
|
||||
<div class="item-tags" v-if="item.product?.require_credit || item.product?.credit_reward > 0">
|
||||
<el-tag v-if="item.product?.require_credit" size="small" type="warning">
|
||||
需要: {{ item.product?.credit_cost }}
|
||||
需要: 1 资格
|
||||
</el-tag>
|
||||
<el-tag v-if="item.product?.credit_reward > 0" size="small" type="success">
|
||||
+{{ item.product?.credit_reward }}
|
||||
@@ -430,7 +430,7 @@ function isOutOfStock(product: any): boolean {
|
||||
// 检查用户是否有足够资格购买
|
||||
function hasEnoughCredit(product: any): boolean {
|
||||
if (!product || !product.require_credit) return true
|
||||
return userCredits.value >= (product.credit_cost || 0)
|
||||
return userCredits.value >= 1
|
||||
}
|
||||
|
||||
// 检查商品是否可以选择
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<p class="description">{{ product.description }}</p>
|
||||
<div class="meta">
|
||||
<el-tag v-if="product.require_credit" :type="hasEnoughCredit() ? 'warning' : 'danger'">
|
||||
{{ $t('product.requireCredit') }}: {{ product.credit_cost * quantity }}
|
||||
{{ $t('product.requireCredit') }}: 1
|
||||
<span v-if="!hasEnoughCredit()"> (资格不足)</span>
|
||||
</el-tag>
|
||||
<el-tag v-if="product.credit_reward > 0" type="success">+{{ product.credit_reward * quantity }} {{ $t('product.creditReward') }}</el-tag>
|
||||
@@ -88,8 +88,7 @@ const productImages = computed(() => {
|
||||
// 检查用户是否有足够资格购买
|
||||
function hasEnoughCredit(): boolean {
|
||||
if (!product.value || !product.value.require_credit) return true
|
||||
const totalCost = product.value.credit_cost * quantity.value
|
||||
return userCredits.value >= totalCost
|
||||
return userCredits.value >= 1
|
||||
}
|
||||
|
||||
// 获取用户资格信息
|
||||
@@ -114,8 +113,7 @@ onMounted(async () => {
|
||||
async function addToCart() {
|
||||
// 检查购物资格
|
||||
if (!hasEnoughCredit()) {
|
||||
const totalCost = product.value.credit_cost * quantity.value
|
||||
ElMessage.warning(`资格不足!需要 ${totalCost} 资格,您当前只有 ${userCredits.value} 资格`)
|
||||
ElMessage.warning(`资格不足!该商品需要1个资格,您当前只有 ${userCredits.value} 资格`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user