feat(distribution): 重构分销后台为SaaS商户工作台并全面商业化优化

- 商品货架 (Accounts.tsx): 支持期望售价/固定金额/百分比多模式实时联动加价与批量调价,高亮100%独享溢价
- 订单中心 (Orders.tsx): 透传账号游戏租客信息,新增收益对账抽屉透明拆解底价、手续费、分成与自主溢价
- 结算与规则 (Settlements.tsx & Rules.tsx): 纠正角色倒错,商户视角展现周期对账单与分成合作政策
- 店铺装修 (SiteSettings.tsx): 废除手写JSON,提供横幅/公告/页脚可视化列表编辑器与前台实时模拟器
- 数据大盘 (Dashboard.tsx): 对齐最新订单字段,大字展示分销商净收益
- 后端数据层 (dto.go, repository.go, handler.go): 聚合计算分销商订单收益,支持商品与租客搜索
This commit is contained in:
yml2213
2026-09-09 14:44:02 +08:00
parent aa466051ac
commit f6ad7c34ee
12 changed files with 2257 additions and 465 deletions
+437 -62
View File
@@ -15,6 +15,9 @@ import {
Alert,
Tooltip,
Divider,
Radio,
Row,
Col,
} from 'antd'
import {
SyncOutlined,
@@ -89,12 +92,20 @@ export default function Accounts() {
const [txFilter, setTxFilter] = useState<string>('all')
const [keyword, setKeyword] = useState<string>('')
// Markup modal state
// Multi-mode Pricing modal state
const [markupModalVisible, setMarkupModalVisible] = useState(false)
const [targetAccount, setTargetAccount] = useState<AccountDisplay | null>(null)
const [pricingMode, setPricingMode] = useState<'target_price' | 'add_amount' | 'percent' | 'ratio_delta'>('target_price')
const [targetPriceYuan, setTargetPriceYuan] = useState<number>(0)
const [addAmountYuan, setAddAmountYuan] = useState<number>(0)
const [percentMarkup, setPercentMarkup] = useState<number>(0)
const [markupRatio, setMarkupRatio] = useState<number>(0)
const [markupSaving, setMarkupSaving] = useState(false)
// Batch pricing state
const [batchMode, setBatchMode] = useState<'percent' | 'add_amount' | 'ratio_delta'>('percent')
const [batchValue, setBatchValue] = useState<number>(10)
async function load(site?: number) {
if (!site) return
setLoading(true)
@@ -204,42 +215,154 @@ export default function Accounts() {
})
}
function roundRatio(value: number): number {
if (value <= 0 || isNaN(value) || !isFinite(value)) return 0
return Math.round(value * 10) / 10
}
function calcDeltaFromTargetPrice(hafCoinAmount: number, basePriceCent: number, targetPriceYuan: number): number {
if (basePriceCent <= 0 || targetPriceYuan <= 0) return 0
const coinWan = hafCoinAmount / 10000
const basePriceYuan = basePriceCent / 100
if (targetPriceYuan <= basePriceYuan) return 0
const baseRatio = roundRatio(coinWan / basePriceYuan)
if (baseRatio <= 0) return 0
const siteRatio = roundRatio(coinWan / targetPriceYuan)
const delta = roundRatio(baseRatio - siteRatio)
return Math.max(0, delta)
}
function calcPreviewPrice(hafCoinAmount: number, basePriceCent: number, delta: number): { priceCent: number; siteRatio: number; markupCent: number } {
const coinWan = hafCoinAmount / 10000
const basePriceYuan = basePriceCent / 100
const baseRatio = roundRatio(coinWan / basePriceYuan)
if (delta <= 0 || baseRatio <= 0) {
return { priceCent: basePriceCent, siteRatio: baseRatio, markupCent: 0 }
}
let siteRatio = roundRatio(baseRatio - delta)
if (siteRatio <= 0.01) siteRatio = 0.01
const priceYuan = coinWan / siteRatio
const priceCent = Math.max(basePriceCent, Math.round(priceYuan * 100))
return {
priceCent,
siteRatio,
markupCent: priceCent - basePriceCent,
}
}
function handleOpenMarkup(item?: AccountDisplay) {
if (item) {
setTargetAccount(item)
setMarkupRatio(item.shelf_ratio_delta ?? 0)
const currentDelta = item.shelf_ratio_delta ?? 0
setMarkupRatio(currentDelta)
const basePriceYuan = (item.price_cent || 0) / 100
const currentPriceYuan = (item.site_price_cent || item.price_cent || 0) / 100
setTargetPriceYuan(currentPriceYuan)
setAddAmountYuan(Math.max(0, Number((currentPriceYuan - basePriceYuan).toFixed(2))))
setPercentMarkup(
basePriceYuan > 0
? Number((((currentPriceYuan - basePriceYuan) / basePriceYuan) * 100).toFixed(1))
: 0
)
setPricingMode('target_price')
} else {
if (selectedRowKeys.length === 0) {
message.warning('请先勾选需要批量加价的账号商品')
return
}
setTargetAccount(null)
setMarkupRatio(0)
setBatchMode('percent')
setBatchValue(10)
}
setMarkupModalVisible(true)
}
function onTargetPriceChange(val: number | null) {
const nextTarget = Math.max(0, val ?? 0)
setTargetPriceYuan(nextTarget)
if (!targetAccount) return
const basePriceYuan = (targetAccount.price_cent || 0) / 100
const addYuan = Math.max(0, Number((nextTarget - basePriceYuan).toFixed(2)))
setAddAmountYuan(addYuan)
setPercentMarkup(basePriceYuan > 0 ? Number(((addYuan / basePriceYuan) * 100).toFixed(1)) : 0)
const delta = calcDeltaFromTargetPrice(targetAccount.haf_coin_amount || 0, targetAccount.price_cent || 0, nextTarget)
setMarkupRatio(delta)
}
function onAddAmountChange(val: number | null) {
const nextAdd = Math.max(0, val ?? 0)
setAddAmountYuan(nextAdd)
if (!targetAccount) return
const basePriceYuan = (targetAccount.price_cent || 0) / 100
const nextTarget = Number((basePriceYuan + nextAdd).toFixed(2))
setTargetPriceYuan(nextTarget)
setPercentMarkup(basePriceYuan > 0 ? Number(((nextAdd / basePriceYuan) * 100).toFixed(1)) : 0)
const delta = calcDeltaFromTargetPrice(targetAccount.haf_coin_amount || 0, targetAccount.price_cent || 0, nextTarget)
setMarkupRatio(delta)
}
function onPercentMarkupChange(val: number | null) {
const nextPct = Math.max(0, val ?? 0)
setPercentMarkup(nextPct)
if (!targetAccount) return
const basePriceYuan = (targetAccount.price_cent || 0) / 100
const nextTarget = Number((basePriceYuan * (1 + nextPct / 100)).toFixed(2))
setTargetPriceYuan(nextTarget)
setAddAmountYuan(Number((nextTarget - basePriceYuan).toFixed(2)))
const delta = calcDeltaFromTargetPrice(targetAccount.haf_coin_amount || 0, targetAccount.price_cent || 0, nextTarget)
setMarkupRatio(delta)
}
function onMarkupRatioChange(val: number | null) {
const nextDelta = Math.max(0, val ?? 0)
setMarkupRatio(nextDelta)
if (!targetAccount) return
const preview = calcPreviewPrice(targetAccount.haf_coin_amount || 0, targetAccount.price_cent || 0, nextDelta)
const previewYuan = Number((preview.priceCent / 100).toFixed(2))
const basePriceYuan = (targetAccount.price_cent || 0) / 100
setTargetPriceYuan(previewYuan)
const addYuan = Number((preview.markupCent / 100).toFixed(2))
setAddAmountYuan(addYuan)
setPercentMarkup(basePriceYuan > 0 ? Number(((addYuan / basePriceYuan) * 100).toFixed(1)) : 0)
}
async function handleSaveMarkup() {
if (!siteID) return
if (markupRatio < 0) {
message.error('提价调减比例不能小于0')
return
}
setMarkupSaving(true)
try {
if (targetAccount) {
await updateAccountMarkup(targetAccount.id, markupRatio)
message.success('商品加价比例设置成功')
message.success(`商品《${targetAccount.title || targetAccount.listing_no}》加价成功!`)
} else {
const listingIDs = items
.filter((it) => selectedRowKeys.includes(it.id))
.map((it) => it.listing_id)
if (listingIDs.length === 0) {
const selectedItems = items.filter((it) => selectedRowKeys.includes(it.id))
if (selectedItems.length === 0) {
message.warning('请先勾选要加价的商品')
return
}
await batchUpdateAccountMarkup(siteID, listingIDs, markupRatio)
message.success(`已成功为选中的 ${listingIDs.length} 个商品批量设置提价!`)
if (batchMode === 'ratio_delta') {
const listingIDs = selectedItems.map((it) => it.listing_id)
await batchUpdateAccountMarkup(siteID, listingIDs, batchValue)
} else if (batchMode === 'percent') {
await Promise.all(
selectedItems.map((it) => {
const basePriceYuan = (it.price_cent || 0) / 100
const targetYuan = basePriceYuan * (1 + batchValue / 100)
const delta = calcDeltaFromTargetPrice(it.haf_coin_amount || 0, it.price_cent || 0, targetYuan)
return updateAccountMarkup(it.id, delta)
})
)
} else if (batchMode === 'add_amount') {
await Promise.all(
selectedItems.map((it) => {
const basePriceYuan = (it.price_cent || 0) / 100
const targetYuan = basePriceYuan + batchValue
const delta = calcDeltaFromTargetPrice(it.haf_coin_amount || 0, it.price_cent || 0, targetYuan)
return updateAccountMarkup(it.id, delta)
})
)
}
message.success(`已成功为选中的 ${selectedItems.length} 个商品批量设置提价!`)
setSelectedRowKeys([])
}
setMarkupModalVisible(false)
@@ -742,63 +865,315 @@ export default function Accounts() {
/>
</Card>
{/* Markup Modal */}
{/* Rich Multi-mode Markup Modal */}
<Modal
title={
targetAccount
? `设置提价 - ${targetAccount.title || targetAccount.listing_no}`
: `批量提价 (${selectedRowKeys.length} 个账号商品)`
<Space>
<DollarCircleOutlined style={{ color: '#52c41a' }} />
<span>{targetAccount ? `商品加价设置 - ${targetAccount.title || targetAccount.listing_no}` : `批量调价 (${selectedRowKeys.length} 个账号商品)`}</span>
</Space>
}
open={markupModalVisible}
onCancel={() => setMarkupModalVisible(false)}
onOk={handleSaveMarkup}
confirmLoading={markupSaving}
okText="保存提价"
okText="保存并同步货架"
cancelText="取消"
width={580}
destroyOnClose
>
<Space direction="vertical" style={{ width: '100%', padding: '12px 0' }}>
<Typography.Paragraph type="secondary" style={{ marginBottom: 8 }}>
分站提价是通过调小「1 元兑换哈夫币」的兑换比例来提高销售价。比例越小售价越高;
<strong style={{ color: '#389e0d' }}>提价多挣的差价收益 100% 归本分站所有</strong>。
</Typography.Paragraph>
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
<Typography.Text strong>提价调减比例:</Typography.Text>
<InputNumber
min={0}
max={100}
precision={1}
style={{ width: 180 }}
value={markupRatio}
onChange={(val) => setMarkupRatio(val ?? 0)}
addonAfter="比例点"
placeholder="0"
/>
</div>
{targetAccount && (
<div
style={{
marginTop: 8,
padding: '8px 12px',
background: '#f6ffed',
borderRadius: 4,
border: '1px solid #b7eb8f',
fontSize: 12,
}}
>
主站基准比例 {targetAccount.base_ratio || '-'} → 分站提价后比例{' '}
<strong>{Math.max((targetAccount.base_ratio || 0) - markupRatio, 0.1).toFixed(1)}</strong>
,预计售价{' '}
<strong style={{ color: '#cf1322' }}>
{markupRatio > 0 && targetAccount.base_ratio
? `¥${(
(targetAccount.haf_coin_amount || 0) /
10000 /
Math.max(targetAccount.base_ratio - markupRatio, 0.1)
).toFixed(2)}`
: formatMoney(targetAccount.site_price_cent || targetAccount.price_cent)}
</strong>
(加价溢价全额归本站独享)
</div>
<Space direction="vertical" style={{ orientation: 'vertical', width: '100%', padding: '8px 0' }} size="middle">
<Alert
type="success"
showIcon
message="分销商 100% 独享溢价说明"
description="在主站基准租金之上增加的全部溢价金额(加价差价),100% 独立结算至本分销商账户,不与任何第三方分成!"
/>
{targetAccount ? (
<>
<div
style={{
background: '#f8fafc',
border: '1px solid #e2e8f0',
borderRadius: 6,
padding: '12px 16px',
}}
>
<Row gutter={[16, 8]}>
<Col span={24}>
<Typography.Text strong style={{ fontSize: 14 }}>
{targetAccount.title || targetAccount.listing_no}
</Typography.Text>
</Col>
<Col span={12}>
<Typography.Text type="secondary">游戏区服:</Typography.Text>
<span>{targetAccount.game_name || '-'} / {targetAccount.server_region || '-'}</span>
</Col>
<Col span={12}>
<Typography.Text type="secondary">哈夫币资产:</Typography.Text>
<span>
{(targetAccount.haf_coin_amount || 0).toLocaleString()} 币
<span style={{ color: '#8c8c8c', marginLeft: 4 }}>
({((targetAccount.haf_coin_amount || 0) / 10000).toFixed(1)} 万)
</span>
</span>
</Col>
<Col span={12}>
<Typography.Text type="secondary">主站基准价:</Typography.Text>
<strong style={{ color: '#1677ff' }}>¥{((targetAccount.price_cent || 0) / 100).toFixed(2)}</strong>
</Col>
<Col span={12}>
<Typography.Text type="secondary">主站基准比例:</Typography.Text>
<span>{targetAccount.base_ratio || '-'} 点</span>
</Col>
</Row>
</div>
<div>
<Typography.Text strong style={{ display: 'block', marginBottom: 8 }}>
加价模式选择:
</Typography.Text>
<Radio.Group
value={pricingMode}
onChange={(e) => setPricingMode(e.target.value)}
buttonStyle="solid"
style={{ width: '100%' }}
>
<Radio.Button value="target_price" style={{ width: '25%', textAlign: 'center' }}>期望售价</Radio.Button>
<Radio.Button value="add_amount" style={{ width: '25%', textAlign: 'center' }}>固定加价</Radio.Button>
<Radio.Button value="percent" style={{ width: '25%', textAlign: 'center' }}>百分比上浮</Radio.Button>
<Radio.Button value="ratio_delta" style={{ width: '25%', textAlign: 'center' }}>比例调减</Radio.Button>
</Radio.Group>
</div>
<div style={{ background: '#fafafa', padding: 12, borderRadius: 6 }}>
{pricingMode === 'target_price' && (
<div>
<div style={{ marginBottom: 6 }}>
<Typography.Text strong>最终售价(元):</Typography.Text>
</div>
<InputNumber
prefix="¥"
min={Number(((targetAccount.price_cent || 0) / 100).toFixed(2))}
precision={2}
step={1}
style={{ width: '100%' }}
value={targetPriceYuan}
onChange={onTargetPriceChange}
placeholder="输入租客最终看到的标价"
/>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 4 }}>
输入最终期望标价,系统自动换算对应比例点
</Typography.Text>
</div>
)}
{pricingMode === 'add_amount' && (
<div>
<div style={{ marginBottom: 6 }}>
<Typography.Text strong>加价金额(元):</Typography.Text>
</div>
<InputNumber
prefix="+¥"
min={0}
precision={2}
step={1}
style={{ width: '100%' }}
value={addAmountYuan}
onChange={onAddAmountChange}
placeholder="输入在主站价格基础上增加的金额"
/>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 4 }}>
在主站基准价上直接增加的纯利润金额
</Typography.Text>
</div>
)}
{pricingMode === 'percent' && (
<div>
<div style={{ marginBottom: 6 }}>
<Typography.Text strong>上浮百分比(%):</Typography.Text>
</div>
<InputNumber
prefix="+"
addonAfter="%"
min={0}
max={500}
precision={1}
step={5}
style={{ width: '100%' }}
value={percentMarkup}
onChange={onPercentMarkupChange}
placeholder="例如 15"
/>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 4 }}>
按基准价百分比上浮,例如 10% 或 20%
</Typography.Text>
</div>
)}
{pricingMode === 'ratio_delta' && (
<div>
<div style={{ marginBottom: 6 }}>
<Typography.Text strong>调减比例点(点):</Typography.Text>
</div>
<InputNumber
min={0}
max={100}
precision={1}
step={0.1}
addonAfter="点"
style={{ width: '100%' }}
value={markupRatio}
onChange={onMarkupRatioChange}
placeholder="0"
/>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 4 }}>
高级模式:直接调减 1 元兑换哈夫币比例,比例越小售价越高
</Typography.Text>
</div>
)}
</div>
{/* Real-time Earnings Comparison Card */}
<div
style={{
padding: '14px 16px',
background: '#f6ffed',
borderRadius: 6,
border: '1px solid #b7eb8f',
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
<Typography.Text type="secondary">预计本站标价:</Typography.Text>
<Typography.Text strong style={{ fontSize: 16, color: '#cf1322' }}>
¥{targetPriceYuan.toFixed(2)}
</Typography.Text>
</div>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
<Typography.Text type="secondary">本站 100% 独享溢价:</Typography.Text>
<Typography.Text strong style={{ fontSize: 18, color: '#389e0d' }}>
+¥{addAmountYuan.toFixed(2)}
</Typography.Text>
</div>
<Divider style={{ margin: '8px 0' }} />
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, color: '#595959' }}>
<span>兑换比例换算:</span>
<span>
基准 {targetAccount.base_ratio || '-'} → 标价{' '}
<strong>{Math.max((targetAccount.base_ratio || 0) - markupRatio, 0.01).toFixed(1)}</strong>{' '}
(调减 {markupRatio.toFixed(1)} 点)
</span>
</div>
</div>
</>
) : (
<>
<div>
<Typography.Text strong style={{ display: 'block', marginBottom: 8 }}>
批量加价模式(已勾选 {selectedRowKeys.length} 件商品):
</Typography.Text>
<Radio.Group
value={batchMode}
onChange={(e) => setBatchMode(e.target.value)}
buttonStyle="solid"
style={{ width: '100%' }}
>
<Radio.Button value="percent" style={{ width: '33.3%', textAlign: 'center' }}>
按百分比批量上浮 (推荐)
</Radio.Button>
<Radio.Button value="add_amount" style={{ width: '33.3%', textAlign: 'center' }}>
固定加价金额
</Radio.Button>
<Radio.Button value="ratio_delta" style={{ width: '33.3%', textAlign: 'center' }}>
统一调减比例点
</Radio.Button>
</Radio.Group>
</div>
<div style={{ background: '#fafafa', padding: 16, borderRadius: 6 }}>
{batchMode === 'percent' && (
<div>
<Typography.Text strong style={{ display: 'block', marginBottom: 6 }}>
统一上浮百分比(%):
</Typography.Text>
<InputNumber
prefix="+"
addonAfter="%"
min={0}
max={500}
precision={1}
step={5}
style={{ width: '100%' }}
value={batchValue}
onChange={(v) => setBatchValue(v ?? 0)}
placeholder="例如 10 或 15"
/>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 6 }}>
所有勾选商品将按各自底价自动上浮 {batchValue}%,并自动为每件商品精确匹配比例点
</Typography.Text>
</div>
)}
{batchMode === 'add_amount' && (
<div>
<Typography.Text strong style={{ display: 'block', marginBottom: 6 }}>
统一加价金额(元):
</Typography.Text>
<InputNumber
prefix="+¥"
addonAfter="元"
min={0}
precision={2}
step={1}
style={{ width: '100%' }}
value={batchValue}
onChange={(v) => setBatchValue(v ?? 0)}
placeholder="例如 5.00"
/>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 6 }}>
所有勾选商品统一定价加价 ¥{batchValue.toFixed(2)},溢价收益全额入账本站
</Typography.Text>
</div>
)}
{batchMode === 'ratio_delta' && (
<div>
<Typography.Text strong style={{ display: 'block', marginBottom: 6 }}>
统一调减比例点数:
</Typography.Text>
<InputNumber
min={0}
max={100}
precision={1}
step={0.1}
addonAfter="点"
style={{ width: '100%' }}
value={batchValue}
onChange={(v) => setBatchValue(v ?? 0)}
placeholder="例如 0.5"
/>
<Typography.Text type="secondary" style={{ fontSize: 12, display: 'block', marginTop: 6 }}>
统一在各商品原比例基础上调减 {batchValue} 点
</Typography.Text>
</div>
)}
</div>
<div
style={{
padding: '12px 16px',
background: '#f6ffed',
borderRadius: 6,
border: '1px solid #b7eb8f',
fontSize: 13,
color: '#389e0d',
}}
>
💡 已勾选 <strong>{selectedRowKeys.length}</strong> 件商品,批量调价后差价收益将 100% 归本分销商账户独享!
</div>
</>
)}
</Space>
</Modal>