feat(distribution): 支持一键同步主站商品池并在货架区分货源归属
This commit is contained in:
@@ -152,6 +152,8 @@ type AccountDisplayDTO struct {
|
|||||||
DepositAmountCent int64 `json:"deposit_amount_cent,omitempty"`
|
DepositAmountCent int64 `json:"deposit_amount_cent,omitempty"`
|
||||||
ListingStatus string `json:"listing_status,omitempty"`
|
ListingStatus string `json:"listing_status,omitempty"`
|
||||||
InTransaction bool `json:"in_transaction,omitempty"`
|
InTransaction bool `json:"in_transaction,omitempty"`
|
||||||
|
ListingSiteID *uint64 `json:"listing_site_id,omitempty"`
|
||||||
|
SourceChannel string `json:"source_channel,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncSiteAccountsRequest struct {
|
type SyncSiteAccountsRequest struct {
|
||||||
|
|||||||
@@ -480,6 +480,8 @@ func (r *Repository) ListAccountDisplays(ctx context.Context, siteID uint64, sta
|
|||||||
DepositAmountCent int64 `gorm:"column:deposit_amount_cent"`
|
DepositAmountCent int64 `gorm:"column:deposit_amount_cent"`
|
||||||
ListingStatus string `gorm:"column:listing_status"`
|
ListingStatus string `gorm:"column:listing_status"`
|
||||||
InTransaction bool `gorm:"column:in_transaction"`
|
InTransaction bool `gorm:"column:in_transaction"`
|
||||||
|
ListingSiteID *uint64 `gorm:"column:listing_site_id"`
|
||||||
|
SourceChannel string `gorm:"column:source_channel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var rows []accountDisplayRow
|
var rows []accountDisplayRow
|
||||||
@@ -494,6 +496,8 @@ func (r *Repository) ListAccountDisplays(ctx context.Context, siteID uint64, sta
|
|||||||
COALESCE(dsa.markup_amount_cent, 0) AS markup_amount_cent,
|
COALESCE(dsa.markup_amount_cent, 0) AS markup_amount_cent,
|
||||||
COALESCE(dsa.shelf_ratio_delta, 0) AS shelf_ratio_delta,
|
COALESCE(dsa.shelf_ratio_delta, 0) AS shelf_ratio_delta,
|
||||||
COALESCE(l.listing_no, '') AS listing_no,
|
COALESCE(l.listing_no, '') AS listing_no,
|
||||||
|
l.distribution_site_id AS listing_site_id,
|
||||||
|
COALESCE(l.source_channel, '') AS source_channel,
|
||||||
COALESCE(ga.title, '') AS title,
|
COALESCE(ga.title, '') AS title,
|
||||||
COALESCE(ga.game_name, '') AS game_name,
|
COALESCE(ga.game_name, '') AS game_name,
|
||||||
COALESCE(ga.server_region, '') AS server_region,
|
COALESCE(ga.server_region, '') AS server_region,
|
||||||
@@ -540,6 +544,8 @@ func (r *Repository) ListAccountDisplays(ctx context.Context, siteID uint64, sta
|
|||||||
DepositAmountCent: row.DepositAmountCent,
|
DepositAmountCent: row.DepositAmountCent,
|
||||||
ListingStatus: row.ListingStatus,
|
ListingStatus: row.ListingStatus,
|
||||||
InTransaction: row.InTransaction,
|
InTransaction: row.InTransaction,
|
||||||
|
ListingSiteID: row.ListingSiteID,
|
||||||
|
SourceChannel: row.SourceChannel,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return items, nil
|
return items, nil
|
||||||
@@ -627,13 +633,6 @@ func (r *Repository) SyncSiteAccounts(ctx context.Context, adminID, siteID uint6
|
|||||||
}
|
}
|
||||||
|
|
||||||
var candidates []model.RentalListing
|
var candidates []model.RentalListing
|
||||||
if err := r.db.WithContext(ctx).
|
|
||||||
Where("distribution_site_id = ? AND status = ? AND review_status = ?", siteID, "published", "approved").
|
|
||||||
Order("id ASC").
|
|
||||||
Find(&candidates).Error; err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(selectedIDs) > 0 {
|
if len(selectedIDs) > 0 {
|
||||||
var selected []model.RentalListing
|
var selected []model.RentalListing
|
||||||
if err := r.db.WithContext(ctx).Where("id IN ?", selectedIDs).Find(&selected).Error; err != nil {
|
if err := r.db.WithContext(ctx).Where("id IN ?", selectedIDs).Find(&selected).Error; err != nil {
|
||||||
@@ -642,16 +641,14 @@ func (r *Repository) SyncSiteAccounts(ctx context.Context, adminID, siteID uint6
|
|||||||
if len(selected) != len(selectedIDs) {
|
if len(selected) != len(selectedIDs) {
|
||||||
return nil, ErrSyncListingNotFound
|
return nil, ErrSyncListingNotFound
|
||||||
}
|
}
|
||||||
seenListing := make(map[uint64]bool, len(candidates)+len(selected))
|
candidates = selected
|
||||||
for _, l := range candidates {
|
} else {
|
||||||
seenListing[l.ID] = true
|
// 未显式指定 listingIDs 时,默认将主站自营及全网审核通过的在售商品全部同步至本分站货架
|
||||||
}
|
if err := r.db.WithContext(ctx).
|
||||||
for _, l := range selected {
|
Where("status = ? AND review_status = ?", "published", "approved").
|
||||||
if seenListing[l.ID] {
|
Order("id ASC").
|
||||||
continue
|
Find(&candidates).Error; err != nil {
|
||||||
}
|
return nil, err
|
||||||
seenListing[l.ID] = true
|
|
||||||
candidates = append(candidates, l)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -318,20 +318,20 @@ func TestSyncSiteAccountsAndPublicListings(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 默认同步不得灌入主站全量目录,只收本站上传货
|
// 默认同步全网合规商品(包含主站商品与本站上传货)
|
||||||
resMain, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, nil)
|
resMain, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("SyncSiteAccounts own-only err = %v", err)
|
t.Fatalf("SyncSiteAccounts err = %v", err)
|
||||||
}
|
}
|
||||||
if resMain.SyncedCount != 1 || resMain.SkippedCount != 0 || resMain.TotalActive != 1 {
|
if resMain.SyncedCount != 2 || resMain.SkippedCount != 0 || resMain.TotalActive != 2 {
|
||||||
t.Fatalf("unexpected own-only res: %+v", resMain)
|
t.Fatalf("unexpected sync res: %+v", resMain)
|
||||||
}
|
}
|
||||||
|
|
||||||
res2, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, nil)
|
res2, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("SyncSiteAccounts retry err = %v", err)
|
t.Fatalf("SyncSiteAccounts retry err = %v", err)
|
||||||
}
|
}
|
||||||
if res2.SyncedCount != 0 || res2.SkippedCount != 1 || res2.TotalActive != 1 {
|
if res2.SyncedCount != 0 || res2.SkippedCount != 2 || res2.TotalActive != 2 {
|
||||||
t.Fatalf("unexpected res2: %+v", res2)
|
t.Fatalf("unexpected res2: %+v", res2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +343,7 @@ func TestSyncSiteAccountsAndPublicListings(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("explicit select err = %v", err)
|
t.Fatalf("explicit select err = %v", err)
|
||||||
}
|
}
|
||||||
if resSelect.SyncedCount != 1 || resSelect.SkippedCount != 1 || resSelect.TotalActive != 2 {
|
if resSelect.SyncedCount != 0 || resSelect.SkippedCount != 1 || resSelect.TotalActive != 1 {
|
||||||
t.Fatalf("unexpected explicit select res: %+v", resSelect)
|
t.Fatalf("unexpected explicit select res: %+v", resSelect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,8 @@ export interface AccountDisplay {
|
|||||||
deposit_amount_cent?: number
|
deposit_amount_cent?: number
|
||||||
listing_status?: string
|
listing_status?: string
|
||||||
in_transaction?: boolean
|
in_transaction?: boolean
|
||||||
|
listing_site_id?: number | null
|
||||||
|
source_channel?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SyncSiteAccountsResult {
|
export interface SyncSiteAccountsResult {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState, useMemo } from 'react'
|
import { useEffect, useState, useMemo } from 'react'
|
||||||
import { Card, Table, Typography, Space, Select, Tag, message, Button, Input, Modal, InputNumber } from 'antd'
|
import { Card, Table, Typography, Space, Select, Tag, message, Button, Input, Modal, InputNumber, Empty } from 'antd'
|
||||||
import { SyncOutlined, SearchOutlined, CheckCircleOutlined, StopOutlined, EditOutlined, DollarCircleOutlined } from '@ant-design/icons'
|
import { SyncOutlined, SearchOutlined, CheckCircleOutlined, StopOutlined, EditOutlined, DollarCircleOutlined } from '@ant-design/icons'
|
||||||
import {
|
import {
|
||||||
listAccountDisplays,
|
listAccountDisplays,
|
||||||
@@ -69,13 +69,13 @@ export default function Accounts() {
|
|||||||
try {
|
try {
|
||||||
const res = await syncSiteAccounts(siteID)
|
const res = await syncSiteAccounts(siteID)
|
||||||
message.success(
|
message.success(
|
||||||
`同步完成!新增本站上传货 ${res.synced_count} 个,已存在 ${res.skipped_count} 个(本次候选 ${res.total_active} 个)`,
|
`同步完成!成功同步新增商品 ${res.synced_count} 个,已在货架 ${res.skipped_count} 个(平台在售共 ${res.total_active} 个)`,
|
||||||
5,
|
5,
|
||||||
)
|
)
|
||||||
await load(siteID, status)
|
await load(siteID, status)
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const respMessage = (error as { response?: { data?: { message?: string } } })?.response?.data?.message
|
const respMessage = (error as { response?: { data?: { message?: string } } })?.response?.data?.message
|
||||||
message.error(respMessage ?? '同步本站上传商品失败')
|
message.error(respMessage ?? '同步主站商品失败')
|
||||||
} finally {
|
} finally {
|
||||||
setSyncing(false)
|
setSyncing(false)
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ export default function Accounts() {
|
|||||||
商品与账号展示
|
商品与账号展示
|
||||||
</Typography.Title>
|
</Typography.Title>
|
||||||
<Typography.Text type="secondary">
|
<Typography.Text type="secondary">
|
||||||
管理当前分销网站对外展示的商品。默认同步本站上传货,主站货需显式勾选,不会灌入全站目录。
|
管理当前分销网站对外展示的商品货架。所有账号源均来自主站及平台共享池,支持一键同步主站商品,并进行自主提价(调小比例)销售。
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
@@ -199,7 +199,7 @@ export default function Accounts() {
|
|||||||
onClick={handleSync}
|
onClick={handleSync}
|
||||||
style={{ background: '#1677ff' }}
|
style={{ background: '#1677ff' }}
|
||||||
>
|
>
|
||||||
同步本站上传商品
|
一键同步主站商品
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -279,6 +279,23 @@ export default function Accounts() {
|
|||||||
rowKey="id"
|
rowKey="id"
|
||||||
loading={loading}
|
loading={loading}
|
||||||
dataSource={filteredItems}
|
dataSource={filteredItems}
|
||||||
|
locale={{
|
||||||
|
emptyText: (
|
||||||
|
<Empty
|
||||||
|
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||||
|
description="当前分站货架暂无商品。点击下方按钮一键同步主站账号池,即可在此设置提价并开始销售。"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
icon={<SyncOutlined spin={syncing} />}
|
||||||
|
loading={syncing}
|
||||||
|
onClick={handleSync}
|
||||||
|
>
|
||||||
|
一键同步主站商品
|
||||||
|
</Button>
|
||||||
|
</Empty>
|
||||||
|
),
|
||||||
|
}}
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
selectedRowKeys,
|
selectedRowKeys,
|
||||||
onChange: setSelectedRowKeys,
|
onChange: setSelectedRowKeys,
|
||||||
@@ -302,6 +319,19 @@ export default function Accounts() {
|
|||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: '货源归属',
|
||||||
|
width: 110,
|
||||||
|
render: (_: unknown, row: AccountDisplay) => {
|
||||||
|
if (row.listing_site_id === null || row.listing_site_id === undefined) {
|
||||||
|
return <Tag color="green">主站自营</Tag>
|
||||||
|
}
|
||||||
|
if (row.listing_site_id === siteID) {
|
||||||
|
return <Tag color="purple">本站收号</Tag>
|
||||||
|
}
|
||||||
|
return <Tag color="blue">合作分站</Tag>
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '账号信息',
|
title: '账号信息',
|
||||||
dataIndex: 'title',
|
dataIndex: 'title',
|
||||||
|
|||||||
Reference in New Issue
Block a user