feat(admin): 拆分经营站点与历史分销后台
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/sitecode"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
"hfb_sys/backend/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// BlockTenantLegacyDistributionAdmin 阻止经营租户后台调用历史分销管理接口。
|
||||
// 独立分销后台使用 /api/distribution/*,不经过该守卫。
|
||||
func BlockTenantLegacyDistributionAdmin() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
tenantScoped := sitecode.HasTenantScope(c.Request.Context())
|
||||
if _, ok := tenancy.FromContext(c.Request.Context()); ok {
|
||||
tenantScoped = true
|
||||
}
|
||||
if tenantScoped && strings.HasPrefix(c.Request.URL.Path, "/api/admin/distribution/") {
|
||||
response.Forbidden(c, "经营站点后台不能管理历史分销渠道")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"hfb_sys/backend/internal/sitecode"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestBlockTenantLegacyDistributionAdmin(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
engine := gin.New()
|
||||
engine.Use(BlockTenantLegacyDistributionAdmin())
|
||||
engine.GET("/api/admin/distribution/sites", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
engine.GET("/api/admin/invitations", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
engine.GET("/api/distribution/sites/1", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
|
||||
tenantMiddleware := func(c *gin.Context) {
|
||||
ctx := tenancy.WithScope(c.Request.Context(), tenancy.Scope{TenantID: 2, TenantCode: "jieyou"})
|
||||
ctx = sitecode.WithTenantScope(ctx)
|
||||
c.Request = c.Request.WithContext(ctx)
|
||||
c.Next()
|
||||
}
|
||||
tenantEngine := gin.New()
|
||||
tenantEngine.Use(tenantMiddleware, BlockTenantLegacyDistributionAdmin())
|
||||
tenantEngine.GET("/api/admin/distribution/sites", func(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
engine.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/admin/distribution/sites", nil))
|
||||
if rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("legacy request status = %d, want 204", rec.Code)
|
||||
}
|
||||
|
||||
rec = httptest.NewRecorder()
|
||||
tenantEngine.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/admin/distribution/sites", nil))
|
||||
if rec.Code != http.StatusForbidden {
|
||||
t.Fatalf("tenant legacy admin status = %d, want 403", rec.Code)
|
||||
}
|
||||
|
||||
for _, path := range []string{"/api/admin/invitations", "/api/distribution/sites/1"} {
|
||||
rec = httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, path, nil)
|
||||
engine.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusNoContent {
|
||||
t.Fatalf("%s status = %d, want 204", path, rec.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,6 +364,7 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
||||
if distributionRepo != nil {
|
||||
engine.Use(middleware.SiteDomainFallback(distributionRepo, logger))
|
||||
}
|
||||
engine.Use(middleware.BlockTenantLegacyDistributionAdmin())
|
||||
distributionHandler := distribution.NewHandler(distributionService)
|
||||
if invitationHandler != nil && distributionService != nil {
|
||||
invitationHandler.SetSiteScoper(distributionService)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Setting, User, Coin, Refresh, Search, Check, DataAnalysis } from '@element-plus/icons-vue'
|
||||
import {
|
||||
@@ -18,6 +18,11 @@ import {
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import { formatCent } from '@/shared/utils/money'
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||
|
||||
const siteStore = useDistributionSiteStore()
|
||||
const isTenantSite = computed(() => siteStore.isTenant)
|
||||
const currentSiteName = computed(() => siteStore.siteName || '大锤商行')
|
||||
|
||||
const activeTab = ref<'config' | 'invitations' | 'rebates' | 'summary'>('config')
|
||||
|
||||
@@ -71,10 +76,19 @@ const summary = ref<AdminRebateSummary | null>(null)
|
||||
|
||||
onMounted(() => {
|
||||
// 三个页签的数据一起预加载,避免邀请关系/返利流水标签在首次进入时显示 0。
|
||||
void Promise.all([loadSites(), loadConfig(), loadInvitations(), loadRebates()])
|
||||
void Promise.all([
|
||||
isTenantSite.value ? Promise.resolve() : loadSites(),
|
||||
loadConfig(),
|
||||
loadInvitations(),
|
||||
loadRebates(),
|
||||
])
|
||||
})
|
||||
|
||||
async function loadSites() {
|
||||
if (isTenantSite.value) {
|
||||
sites.value = []
|
||||
return
|
||||
}
|
||||
try {
|
||||
const list = await fetchDistributionSites()
|
||||
sites.value = list
|
||||
@@ -86,7 +100,8 @@ async function loadSites() {
|
||||
async function loadConfig() {
|
||||
loadingConfig.value = true
|
||||
try {
|
||||
const cfg: InvitationRebateConfig = await fetchAdminRebateConfig(selectedSiteId.value)
|
||||
const siteID = isTenantSite.value ? 0 : selectedSiteId.value
|
||||
const cfg: InvitationRebateConfig = await fetchAdminRebateConfig(siteID)
|
||||
configForm.firstMonthRate = Math.round((cfg.first_month_rate || 0.6) * 100)
|
||||
configForm.secondMonthRate = Math.round((cfg.second_month_rate || 0.3) * 100)
|
||||
configForm.subsequentRate = Math.round((cfg.subsequent_rate || 0.15) * 100)
|
||||
@@ -113,7 +128,8 @@ async function handleSaveConfig() {
|
||||
|
||||
savingConfig.value = true
|
||||
try {
|
||||
await updateAdminRebateConfig(selectedSiteId.value, {
|
||||
const siteID = isTenantSite.value ? 0 : selectedSiteId.value
|
||||
await updateAdminRebateConfig(siteID, {
|
||||
first_month_rate: Number((configForm.firstMonthRate / 100).toFixed(4)),
|
||||
second_month_rate: Number((configForm.secondMonthRate / 100).toFixed(4)),
|
||||
subsequent_rate: Number((configForm.subsequentRate / 100).toFixed(4)),
|
||||
@@ -136,7 +152,7 @@ async function loadInvitations() {
|
||||
}
|
||||
if (invitationQuery.phone.trim()) params.phone = invitationQuery.phone.trim()
|
||||
if (invitationQuery.invite_code.trim()) params.invite_code = invitationQuery.invite_code.trim()
|
||||
if (invitationQuery.distribution_site_id !== undefined) {
|
||||
if (!isTenantSite.value && invitationQuery.distribution_site_id !== undefined) {
|
||||
params.distribution_site_id = invitationQuery.distribution_site_id
|
||||
}
|
||||
|
||||
@@ -160,7 +176,7 @@ async function loadRebates() {
|
||||
if (rebateQuery.order_no.trim()) params.order_no = rebateQuery.order_no.trim()
|
||||
if (rebateQuery.inviter_phone.trim()) params.inviter_phone = rebateQuery.inviter_phone.trim()
|
||||
if (rebateQuery.invitee_phone.trim()) params.invitee_phone = rebateQuery.invitee_phone.trim()
|
||||
if (rebateQuery.distribution_site_id !== undefined) {
|
||||
if (!isTenantSite.value && rebateQuery.distribution_site_id !== undefined) {
|
||||
params.distribution_site_id = rebateQuery.distribution_site_id
|
||||
}
|
||||
|
||||
@@ -184,7 +200,7 @@ async function loadSummary() {
|
||||
}
|
||||
if (summaryQuery.source) params.source = summaryQuery.source
|
||||
if (summaryQuery.trade_role) params.trade_role = summaryQuery.trade_role
|
||||
if (typeof summaryQuery.distribution_site_id === 'number') {
|
||||
if (!isTenantSite.value && typeof summaryQuery.distribution_site_id === 'number') {
|
||||
params.distribution_site_id = summaryQuery.distribution_site_id
|
||||
}
|
||||
summary.value = await fetchAdminRebateSummary(params)
|
||||
@@ -246,7 +262,11 @@ function cycleLabel(cycle: string) {
|
||||
<div class="page-header">
|
||||
<h2>邀请返利与分成管理</h2>
|
||||
<p class="page-desc">
|
||||
配置主站及各分销站点的返利阶梯比例(首月、次月、往后永久),监控全网邀请关系与返利流水,快速查看每位邀请人的累计邀请、已实名与待实名人数。
|
||||
{{
|
||||
isTenantSite
|
||||
? `配置【${currentSiteName}】的返利阶梯比例,监控本站邀请关系与返利流水。`
|
||||
: '配置主站及各分销站点的返利阶梯比例(首月、次月、往后永久),监控历史分销渠道的邀请关系与返利流水。'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -264,7 +284,8 @@ function cycleLabel(cycle: string) {
|
||||
:class="{ active: activeTab === 'invitations' }"
|
||||
@click="handleTabChange('invitations')"
|
||||
>
|
||||
<el-icon><User /></el-icon> 全网邀请关系 ({{ invitationsTotal }})
|
||||
<el-icon><User /></el-icon>
|
||||
{{ isTenantSite ? '本站邀请关系' : '全网邀请关系' }} ({{ invitationsTotal }})
|
||||
</button>
|
||||
<button
|
||||
class="nav-tab-btn"
|
||||
@@ -285,7 +306,7 @@ function cycleLabel(cycle: string) {
|
||||
<!-- 配置面板 -->
|
||||
<div v-if="activeTab === 'config'" class="panel-card">
|
||||
<div class="panel-header">
|
||||
<div class="site-selector-row">
|
||||
<div v-if="!isTenantSite" class="site-selector-row">
|
||||
<label>选择配置生效目标:</label>
|
||||
<el-select v-model="selectedSiteId" style="width: 260px" @change="loadConfig">
|
||||
<el-option :value="0" label="主站(默认基础配置)" />
|
||||
@@ -298,13 +319,16 @@ function cycleLabel(cycle: string) {
|
||||
</el-select>
|
||||
<el-button :icon="Refresh" circle @click="loadConfig" />
|
||||
</div>
|
||||
<div v-if="selectedSiteId === 0" class="site-desc-hint">
|
||||
💡
|
||||
说明:当前配置为【主站平台订单默认分成比例】(分站未设置专属比例时作为全局兜底)。各加盟分销站可在其专属【分销后台】中自主调整属于该分站的返利比例,分成支出由分站自身收益承担。
|
||||
<div v-else class="site-selector-row">
|
||||
<label>当前站点:</label>
|
||||
<el-tag effect="plain">{{ currentSiteName }}</el-tag>
|
||||
<span class="tenant-config-hint">仅影响当前站点的邀请返利,不会修改其他站点。</span>
|
||||
</div>
|
||||
<div v-else class="site-desc-hint">
|
||||
💡
|
||||
说明:当前正在为指定分销站维护专属返利比例(该分站管理员亦可在其独立分销后台中自主设置,分成支出由该分站自身收益承担)。
|
||||
<div v-if="!isTenantSite && selectedSiteId === 0" class="site-desc-hint">
|
||||
说明:当前配置为历史主站订单默认分成比例;经营站点拥有各自独立配置。
|
||||
</div>
|
||||
<div v-else-if="!isTenantSite" class="site-desc-hint">
|
||||
说明:当前正在为指定历史分销站维护专属返利比例。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -378,7 +402,11 @@ function cycleLabel(cycle: string) {
|
||||
<el-button :icon="Refresh" @click="searchInvitations">刷新</el-button>
|
||||
</div>
|
||||
<div class="table-hint">
|
||||
「邀请人累计」统计该邀请人名下全部邀请人数;分站后台仅统计本站范围。
|
||||
{{
|
||||
isTenantSite
|
||||
? '仅展示当前站点的邀请关系与累计邀请人数。'
|
||||
: '「邀请人累计」统计历史分销渠道内的邀请人数。'
|
||||
}}
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
@@ -577,7 +605,7 @@ function cycleLabel(cycle: string) {
|
||||
<el-option label="卖家端" value="seller" />
|
||||
</el-select>
|
||||
<el-select
|
||||
v-if="sites.length"
|
||||
v-if="!isTenantSite && sites.length"
|
||||
v-model="summaryQuery.distribution_site_id"
|
||||
placeholder="全部分站"
|
||||
clearable
|
||||
@@ -821,6 +849,11 @@ function cycleLabel(cycle: string) {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.tenant-config-hint {
|
||||
color: #64748b;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.site-desc-hint {
|
||||
font-size: 13px;
|
||||
color: #475569;
|
||||
|
||||
@@ -29,6 +29,10 @@ import AdminTablePagination from '../components/AdminTablePagination.vue'
|
||||
import { centToYuan, formatCent, yuanToCent } from '@/shared/utils/money'
|
||||
import { formatDateTime } from '@/shared/utils/time'
|
||||
import { readError } from '@/shared/utils/error'
|
||||
import { useDistributionSiteStore } from '@/stores/distributionSite'
|
||||
|
||||
const siteStore = useDistributionSiteStore()
|
||||
const currentSiteName = computed(() => siteStore.siteName || '大锤商行')
|
||||
|
||||
const channelOptions = [
|
||||
{ label: '网吧合作', value: 'cybercafe', type: 'primary' },
|
||||
@@ -125,7 +129,7 @@ const form = reactive({
|
||||
name: '',
|
||||
code: '',
|
||||
channel_type: 'cybercafe',
|
||||
target_url: 'https://hao858.com/',
|
||||
target_url: '',
|
||||
cost_yuan: 0,
|
||||
notes: '',
|
||||
})
|
||||
@@ -148,7 +152,7 @@ function openCreateDialog() {
|
||||
form.name = ''
|
||||
form.code = ''
|
||||
form.channel_type = 'cybercafe'
|
||||
form.target_url = 'https://hao858.com/'
|
||||
form.target_url = currentOrigin.value
|
||||
form.cost_yuan = 0
|
||||
form.notes = ''
|
||||
dialogVisible.value = true
|
||||
@@ -160,7 +164,7 @@ function openEditDialog(row: TrackingLinkItem) {
|
||||
form.name = row.name
|
||||
form.code = row.code
|
||||
form.channel_type = row.channel_type || 'other'
|
||||
form.target_url = row.target_url || 'https://hao858.com/'
|
||||
form.target_url = row.target_url || currentOrigin.value
|
||||
form.cost_yuan = row.cost_cent > 0 ? Number(centToYuan(row.cost_cent)) : 0
|
||||
form.notes = row.notes || ''
|
||||
dialogVisible.value = true
|
||||
@@ -283,7 +287,7 @@ onMounted(() => {
|
||||
<div class="overview-header">
|
||||
<div class="overview-title">
|
||||
<el-icon class="title-icon"><TrendCharts /></el-icon>
|
||||
<span>推广追踪大盘</span>
|
||||
<span>{{ currentSiteName }}推广追踪</span>
|
||||
</div>
|
||||
<el-button
|
||||
link
|
||||
|
||||
@@ -74,6 +74,8 @@ interface NavGroup {
|
||||
index: string
|
||||
icon: Component
|
||||
children: NavItem[]
|
||||
tenantOnly?: boolean
|
||||
legacyOnly?: boolean
|
||||
}
|
||||
|
||||
const allNavGroups: NavGroup[] = [
|
||||
@@ -147,6 +149,7 @@ const allNavGroups: NavGroup[] = [
|
||||
label: '分销管理',
|
||||
index: 'distribution',
|
||||
icon: Share,
|
||||
legacyOnly: true,
|
||||
children: [
|
||||
{
|
||||
label: '分销站点管理',
|
||||
@@ -178,6 +181,14 @@ const allNavGroups: NavGroup[] = [
|
||||
icon: Coin,
|
||||
permission: 'distribution:settlement_view',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: '邀请与返利',
|
||||
index: 'tenant-invitation',
|
||||
icon: Present,
|
||||
tenantOnly: true,
|
||||
children: [
|
||||
{
|
||||
label: '邀请返利管理',
|
||||
to: adminPath('invitations'),
|
||||
@@ -340,6 +351,7 @@ function canAccessNavItem(item: NavItem) {
|
||||
|
||||
const navGroups = computed(() => {
|
||||
return allNavGroups
|
||||
.filter(group => (siteStore.isTenant ? !group.legacyOnly : !group.tenantOnly))
|
||||
.map(group => ({
|
||||
...group,
|
||||
children: group.children.filter(item => canAccessNavItem(item)),
|
||||
|
||||
Reference in New Issue
Block a user