feat: 商品/套餐支持全部项目通用 (project_id=0)

- 新增/筛选通用商品, 列表标「通用」
- 商城套餐列表含通用商品, 下单/创建授权/代理发卡可用通用套餐
- 项目套餐列表附带展示通用套餐
This commit is contained in:
root committed 2026-10-12 15:17:14 +08:00
1 parent cf65cbd72d
commit 2f10919196
6 files changed
+42 -14

No files matched your search

+1 -1
View File
@@ -397,7 +397,7 @@ class AgentController extends Controller
// 验证卡密类型
$cardType = $db->fetch(
"SELECT * FROM {$db->table('card_types')} WHERE id = ? AND project_id = ? AND status = 1",
"SELECT * FROM {$db->table('card_types')} WHERE id = ? AND (project_id = ? OR project_id = 0) AND status = 1",
[$cardTypeId, $projectId]
);
if (!$cardType) {
@@ -169,10 +169,10 @@ class AuthorizationController extends Controller
}
// 验证套餐
$cardType = $db->fetch(
"SELECT * FROM {$db->table('card_types')} WHERE id = ? AND project_id = ?",
[$cardTypeId, $projectId]
);
$cardType = $db->fetch(
"SELECT * FROM {$db->table('card_types')} WHERE id = ? AND (project_id = ? OR project_id = 0)",
[$input['card_type_id'], $input['project_id']]
);
if (!$cardType) {
$this->error('套餐不存在或不属于该项目');
}
@@ -170,8 +170,11 @@ class ProjectController extends Controller
public function cardTypes(int $projectId): void
{
$db = Database::getInstance();
// 返回本项目套餐 + 通用套餐(project_id=0)
$types = $db->fetchAll(
"SELECT * FROM {$db->table('card_types')} WHERE project_id = ? ORDER BY sort ASC",
"SELECT * FROM {$db->table('card_types')}
WHERE (project_id = ? OR project_id = 0) AND status = 1
ORDER BY project_id ASC, sort ASC",
[$projectId]
);
$this->success($types);
@@ -179,6 +182,7 @@ class ProjectController extends Controller
/**
* 创建卡密类型
* projectId=0 表示全部项目通用商品(仅 admin)
*/
public function createCardType(int $projectId): void
{
@@ -193,6 +197,10 @@ class ProjectController extends Controller
$this->error($validator->getFirstError());
}
if ($projectId === 0 && $this->getUserRole() !== 'admin') {
$this->error('通用商品仅超级管理员可创建', 403);
}
$db = Database::getInstance();
$id = $db->insert(
"INSERT INTO {$db->table('card_types')} (project_id, name, description, duration_days, price, original_price, agent_cost, sort, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+7 -4
View File
@@ -51,9 +51,11 @@ class PublicController extends Controller
public function cardTypes(int $projectId): void
{
$db = Database::getInstance();
// 本项目套餐 + 通用套餐(project_id=0)
$types = $db->fetchAll(
"SELECT id, name, description, duration_days, price, original_price FROM {$db->table('card_types')}
WHERE project_id = ? AND status = 1 ORDER BY sort ASC",
"SELECT id, name, description, duration_days, price, original_price, project_id FROM {$db->table('card_types')}
WHERE (project_id = ? OR project_id = 0) AND status = 1
ORDER BY project_id ASC, sort ASC",
[$projectId]
);
$this->success($types);
@@ -108,9 +110,10 @@ class PublicController extends Controller
$this->error('项目不存在或已下架');
}
// 验证卡密类型
// 验证卡密类型(本项目或通用套餐)
$cardType = $db->fetch(
"SELECT * FROM {$db->table('card_types')} WHERE id = ? AND project_id = ? AND status = 1",
"SELECT * FROM {$db->table('card_types')}
WHERE id = ? AND status = 1 AND (project_id = ? OR project_id = 0)",
[$cardTypeId, $projectId]
);
if (!$cardType) {
+14 -2
View File
@@ -35,6 +35,7 @@
<el-form :inline="true" :model="filters" class="search-form" label-width="80px">
<el-form-item label="项目">
<el-select v-model="filters.project_id" placeholder="全部项目" clearable style="width: 180px" @change="handleFilterChange">
<el-option v-if="user?.role === 'admin'" label="通用商品(全部项目)" :value="0" />
<el-option v-for="p in projects" :key="p.id" :label="p.name" :value="p.id" />
</el-select>
</el-form-item>
@@ -83,7 +84,12 @@
<el-table ref="tableRef" :data="list" v-loading="loading" stripe border highlight-current-row @selection-change="handleSelectionChange" @sort-change="handleSortChange" row-key="id" :max-height="tableMaxHeight" class="data-table">
<el-table-column type="selection" width="50" align="center" fixed="left" />
<el-table-column prop="id" label="ID" width="70" sortable="custom" align="center" v-if="visibleColumns.id" />
<el-table-column prop="project_name" label="所属项目" width="140" sortable="custom" v-if="visibleColumns.project_name" />
<el-table-column prop="project_name" label="所属项目" width="140" sortable="custom" v-if="visibleColumns.project_name">
<template #default="{ row }">
<el-tag v-if="Number(row.project_id) === 0" type="warning" size="small">通用</el-tag>
<span v-else>{{ row.project_name || row.project_id }}</span>
</template>
</el-table-column>
<el-table-column prop="name" label="商品名称" min-width="150" sortable="custom" v-if="visibleColumns.name" />
<el-table-column prop="duration_days" label="有效期" width="110" align="center" sortable="custom" v-if="visibleColumns.duration_days">
<template #default="{ row }"><el-tag :type="row.duration_days == 0 ? 'success' : 'warning'" size="small">{{ row.duration_days == 0 ? '永久' : row.duration_days + '天' }}</el-tag></template>
@@ -113,7 +119,13 @@
<!-- 创建/编辑弹窗 -->
<el-dialog v-model="dialogVisible" :title="isEdit ? '编辑商品' : '新增商品'" width="520px" :close-on-click-modal="false" destroy-on-close>
<el-form ref="formRef" :model="form" :rules="formRules" label-width="100px">
<el-form-item label="所属项目" prop="project_id"><el-select v-model="form.project_id" placeholder="请选择项目" style="width:100%" :disabled="isEdit"><el-option v-for="p in projects" :key="p.id" :label="p.name" :value="p.id" /></el-select></el-form-item>
<el-form-item label="所属项目" prop="project_id">
<el-select v-model="form.project_id" placeholder="请选择项目" style="width:100%" :disabled="isEdit">
<el-option v-if="user?.role === 'admin'" label="全部项目(通用商品)" :value="0" />
<el-option v-for="p in projects" :key="p.id" :label="p.name" :value="p.id" />
</el-select>
<div v-if="form.project_id === 0" style="font-size:12px;color:#909399;margin-top:4px;">通用商品对所有项目可见,可购买、可生成通用卡</div>
</el-form-item>
<el-form-item label="商品名称" prop="name"><el-input v-model="form.name" placeholder="如:月卡、季卡、年卡、永久卡" /></el-form-item>
<el-form-item label="商品简介" prop="description"><el-input v-model="form.description" type="textarea" :rows="2" placeholder="简要描述商品特性,前台购买页会展示" maxlength="255" show-word-limit /></el-form-item>
<el-form-item label="有效天数" prop="duration_days"><el-input-number v-model="form.duration_days" :min="0" style="width:100%" /><span style="color:#999;margin-left:8px">0=永久</span></el-form-item>
+7 -2
View File
@@ -87,8 +87,13 @@
<!-- 套餐管理弹窗 -->
<el-dialog v-model="typeDialogVisible" :title="'套餐管理 - ' + curProject?.name" width="800px" :close-on-click-modal="false" destroy-on-close>
<div style="margin-bottom:12px"><el-button type="primary" size="small" @click="showTypeForm(null)" :icon="Plus">新增套餐</el-button></div>
<el-table :data="cardTypes" v-loading="typeLoading" stripe border class="data-table" :max-height="360">
<el-table-column prop="name" label="名称" width="120" />
<el-table :data="cardTypes" v-loading="typeLoading" stripe border class="data-table" :max-height="360">
<el-table-column prop="name" label="名称" width="120">
<template #default="{ row }">
<el-tag v-if="Number(row.project_id) === 0" type="warning" size="small" style="margin-right:4px">通用</el-tag>
{{ row.name }}
</template>
</el-table-column>
<el-table-column prop="duration_days" label="有效天数" width="100"><template #default="{ row }">{{ row.duration_days==0?'永久':row.duration_days+'天' }}</template></el-table-column>
<el-table-column prop="price" label="售价(元)" width="100"><template #default="{ row }">¥{{ parseFloat(row.price||0).toFixed(2) }}</template></el-table-column>
<el-table-column prop="agent_cost" label="代理价格(元)" width="120"><template #default="{ row }">¥{{ parseFloat(row.agent_cost||0).toFixed(2) }}</template></el-table-column>