优化线下提号利润修改
This commit is contained in:
@@ -66,6 +66,11 @@ type CompleteRequest struct {
|
|||||||
CompleteRemark string `json:"complete_remark"`
|
CompleteRemark string `json:"complete_remark"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateProfitRequest struct {
|
||||||
|
ProfitAmountCent int64 `json:"profit_amount_cent" binding:"min=0"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
}
|
||||||
|
|
||||||
type CancelRequest struct {
|
type CancelRequest struct {
|
||||||
Reason string `json:"reason" binding:"required"`
|
Reason string `json:"reason" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,30 @@ func (h *Handler) Complete(c *gin.Context) {
|
|||||||
response.OK(c, item)
|
response.OK(c, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateProfit 修改提号中的线下利润(管理员)
|
||||||
|
func (h *Handler) UpdateProfit(c *gin.Context) {
|
||||||
|
adminID, ok := currentAdminID(c)
|
||||||
|
if !ok {
|
||||||
|
response.Unauthorized(c, "缺少管理员上下文")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id, ok := parseID(c)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req UpdateProfitRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.BadRequest(c, "利润金额不正确")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
item, err := h.service.UpdateProfit(c.Request.Context(), id, req, adminID, auditMeta(c))
|
||||||
|
if err != nil {
|
||||||
|
writePickupError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.OK(c, item)
|
||||||
|
}
|
||||||
|
|
||||||
// Cancel 取消提号(管理员)
|
// Cancel 取消提号(管理员)
|
||||||
func (h *Handler) Cancel(c *gin.Context) {
|
func (h *Handler) Cancel(c *gin.Context) {
|
||||||
adminID, ok := currentAdminID(c)
|
adminID, ok := currentAdminID(c)
|
||||||
|
|||||||
@@ -270,6 +270,51 @@ func (r *Repository) Complete(ctx context.Context, pickupID uint64, req Complete
|
|||||||
return r.FindByID(ctx, pickupID)
|
return r.FindByID(ctx, pickupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateProfit 修改提号中的线下利润,已完成和已取消的提号不可修改。
|
||||||
|
func (r *Repository) UpdateProfit(ctx context.Context, pickupID uint64, req UpdateProfitRequest, adminID uint64, meta auditlog.Meta) (*PickupDTO, error) {
|
||||||
|
if r == nil || r.db == nil {
|
||||||
|
return nil, ErrDependencyUnavailable
|
||||||
|
}
|
||||||
|
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
|
var pickup model.AdminPickup
|
||||||
|
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&pickup, pickupID).Error; err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return ErrPickupNotFound
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if pickup.Status != StatusPickingUp {
|
||||||
|
return ErrPickupNotPickingUp
|
||||||
|
}
|
||||||
|
|
||||||
|
oldProfitAmountCent := pickup.ProfitAmountCent
|
||||||
|
pickup.ProfitAmountCent = req.ProfitAmountCent
|
||||||
|
if err := tx.Model(&pickup).Update("profit_amount_cent", pickup.ProfitAmountCent).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bid := pickup.ID
|
||||||
|
return auditlog.Append(tx, auditlog.Entry{
|
||||||
|
ActorType: "admin",
|
||||||
|
ActorID: adminID,
|
||||||
|
Action: "pickup_profit_update",
|
||||||
|
BizType: "admin_pickup",
|
||||||
|
BizID: &bid,
|
||||||
|
Meta: meta,
|
||||||
|
Detail: map[string]any{
|
||||||
|
"pickup_no": pickup.PickupNo,
|
||||||
|
"old_profit_amount_cent": oldProfitAmountCent,
|
||||||
|
"new_profit_amount_cent": pickup.ProfitAmountCent,
|
||||||
|
"reason": strings.TrimSpace(req.Reason),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return r.FindByID(ctx, pickupID)
|
||||||
|
}
|
||||||
|
|
||||||
// Cancel 取消提号:恢复 listing 为 published + 解锁 in_transaction,账号恢复可租。
|
// Cancel 取消提号:恢复 listing 为 published + 解锁 in_transaction,账号恢复可租。
|
||||||
func (r *Repository) Cancel(ctx context.Context, pickupID uint64, reason string, adminID uint64, meta auditlog.Meta) error {
|
func (r *Repository) Cancel(ctx context.Context, pickupID uint64, reason string, adminID uint64, meta auditlog.Meta) error {
|
||||||
if r == nil || r.db == nil {
|
if r == nil || r.db == nil {
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ package pickup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"hfb_sys/backend/internal/auditlog"
|
||||||
"hfb_sys/backend/internal/model"
|
"hfb_sys/backend/internal/model"
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
"gorm.io/datatypes"
|
||||||
|
"gorm.io/driver/sqlite"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildPickupPriceSnapshotSplitsOwnerPrice(t *testing.T) {
|
func TestBuildPickupPriceSnapshotSplitsOwnerPrice(t *testing.T) {
|
||||||
@@ -62,9 +67,137 @@ func TestBuildPickupPriceSnapshotFallsBackToSplitSum(t *testing.T) {
|
|||||||
assertInt64(t, "网站加价兜底", snapshot.WebsiteProfitCent, 5000)
|
assertInt64(t, "网站加价兜底", snapshot.WebsiteProfitCent, 5000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRepositoryUpdateProfitAllowsPickingUp(t *testing.T) {
|
||||||
|
repo, db := newPickupTestRepo(t)
|
||||||
|
pickup := seedPickup(t, db, StatusPickingUp)
|
||||||
|
|
||||||
|
item, err := repo.UpdateProfit(t.Context(), pickup.ID, UpdateProfitRequest{
|
||||||
|
ProfitAmountCent: 2500,
|
||||||
|
Reason: "线下扣点调整",
|
||||||
|
}, 99, auditlog.Meta{RequestID: "req-profit"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("UpdateProfit() error = %v", err)
|
||||||
|
}
|
||||||
|
assertInt64(t, "修改后利润", item.ProfitAmountCent, 2500)
|
||||||
|
|
||||||
|
var stored model.AdminPickup
|
||||||
|
if err := db.First(&stored, pickup.ID).Error; err != nil {
|
||||||
|
t.Fatalf("查询提号失败: %v", err)
|
||||||
|
}
|
||||||
|
assertInt64(t, "数据库利润", stored.ProfitAmountCent, 2500)
|
||||||
|
|
||||||
|
var audit model.AuditLog
|
||||||
|
if err := db.Where("action = ?", "pickup_profit_update").First(&audit).Error; err != nil {
|
||||||
|
t.Fatalf("查询审计日志失败: %v", err)
|
||||||
|
}
|
||||||
|
var detail map[string]any
|
||||||
|
if err := json.Unmarshal(audit.Detail, &detail); err != nil {
|
||||||
|
t.Fatalf("解析审计日志失败: %v", err)
|
||||||
|
}
|
||||||
|
assertJSONNumber(t, "旧利润", detail["old_profit_amount_cent"], 1000)
|
||||||
|
assertJSONNumber(t, "新利润", detail["new_profit_amount_cent"], 2500)
|
||||||
|
if detail["reason"] != "线下扣点调整" {
|
||||||
|
t.Fatalf("reason = %v, want 线下扣点调整", detail["reason"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRepositoryUpdateProfitRejectsCompleted(t *testing.T) {
|
||||||
|
repo, db := newPickupTestRepo(t)
|
||||||
|
pickup := seedPickup(t, db, StatusCompleted)
|
||||||
|
|
||||||
|
_, err := repo.UpdateProfit(t.Context(), pickup.ID, UpdateProfitRequest{ProfitAmountCent: 2500}, 99, auditlog.Meta{})
|
||||||
|
if !errors.Is(err, ErrPickupNotPickingUp) {
|
||||||
|
t.Fatalf("UpdateProfit() error = %v, want ErrPickupNotPickingUp", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var stored model.AdminPickup
|
||||||
|
if err := db.First(&stored, pickup.ID).Error; err != nil {
|
||||||
|
t.Fatalf("查询提号失败: %v", err)
|
||||||
|
}
|
||||||
|
assertInt64(t, "已完成提号利润", stored.ProfitAmountCent, 1000)
|
||||||
|
|
||||||
|
var auditCount int64
|
||||||
|
if err := db.Model(&model.AuditLog{}).Where("action = ?", "pickup_profit_update").Count(&auditCount).Error; err != nil {
|
||||||
|
t.Fatalf("统计审计日志失败: %v", err)
|
||||||
|
}
|
||||||
|
if auditCount != 0 {
|
||||||
|
t.Fatalf("审计日志数量 = %d, want 0", auditCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func assertInt64(t *testing.T, name string, got, want int64) {
|
func assertInt64(t *testing.T, name string, got, want int64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Fatalf("%s = %d, want %d", name, got, want)
|
t.Fatalf("%s = %d, want %d", name, got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func assertJSONNumber(t *testing.T, name string, got any, want float64) {
|
||||||
|
t.Helper()
|
||||||
|
value, ok := got.(float64)
|
||||||
|
if !ok || value != want {
|
||||||
|
t.Fatalf("%s = %v, want %.0f", name, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newPickupTestRepo(t *testing.T) (*Repository, *gorm.DB) {
|
||||||
|
t.Helper()
|
||||||
|
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{
|
||||||
|
Logger: logger.Default.LogMode(logger.Silent),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("打开测试数据库失败: %v", err)
|
||||||
|
}
|
||||||
|
if err := db.AutoMigrate(
|
||||||
|
&model.User{},
|
||||||
|
&model.GameAccount{},
|
||||||
|
&model.RentalListing{},
|
||||||
|
&model.AdminPickup{},
|
||||||
|
&model.AuditLog{},
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("迁移测试表失败: %v", err)
|
||||||
|
}
|
||||||
|
return NewRepository(db), db
|
||||||
|
}
|
||||||
|
|
||||||
|
func seedPickup(t *testing.T, db *gorm.DB, status string) model.AdminPickup {
|
||||||
|
t.Helper()
|
||||||
|
owner := model.User{Phone: "18800000000"}
|
||||||
|
if err := db.Create(&owner).Error; err != nil {
|
||||||
|
t.Fatalf("创建号主失败: %v", err)
|
||||||
|
}
|
||||||
|
account := model.GameAccount{
|
||||||
|
OwnerID: owner.ID,
|
||||||
|
ServerRegion: "测试区",
|
||||||
|
LoginPlatform: "微信",
|
||||||
|
Title: "测试账号",
|
||||||
|
Status: "rented",
|
||||||
|
}
|
||||||
|
if err := db.Create(&account).Error; err != nil {
|
||||||
|
t.Fatalf("创建账号失败: %v", err)
|
||||||
|
}
|
||||||
|
listing := model.RentalListing{
|
||||||
|
ListingNo: "LST-PROFIT-001",
|
||||||
|
AccountID: account.ID,
|
||||||
|
OwnerID: owner.ID,
|
||||||
|
PriceCent: 10000,
|
||||||
|
Status: "rented",
|
||||||
|
ReviewStatus: "approved",
|
||||||
|
}
|
||||||
|
if err := db.Create(&listing).Error; err != nil {
|
||||||
|
t.Fatalf("创建上架记录失败: %v", err)
|
||||||
|
}
|
||||||
|
pickup := model.AdminPickup{
|
||||||
|
PickupNo: "PK-PROFIT-001",
|
||||||
|
ListingID: listing.ID,
|
||||||
|
AccountID: account.ID,
|
||||||
|
OwnerID: owner.ID,
|
||||||
|
AdminID: 1,
|
||||||
|
ProfitAmountCent: 1000,
|
||||||
|
Status: status,
|
||||||
|
}
|
||||||
|
if err := db.Create(&pickup).Error; err != nil {
|
||||||
|
t.Fatalf("创建提号记录失败: %v", err)
|
||||||
|
}
|
||||||
|
return pickup
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,6 +40,19 @@ func (s *Service) Complete(ctx context.Context, pickupID uint64, req CompleteReq
|
|||||||
return s.repo.Complete(ctx, pickupID, req, adminID, meta)
|
return s.repo.Complete(ctx, pickupID, req, adminID, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) UpdateProfit(ctx context.Context, pickupID uint64, req UpdateProfitRequest, adminID uint64, meta auditlog.Meta) (*PickupDTO, error) {
|
||||||
|
if s.repo == nil {
|
||||||
|
return nil, ErrDependencyUnavailable
|
||||||
|
}
|
||||||
|
if pickupID == 0 {
|
||||||
|
return nil, ErrPickupNotFound
|
||||||
|
}
|
||||||
|
if req.ProfitAmountCent < 0 {
|
||||||
|
return nil, ErrInvalidProfit
|
||||||
|
}
|
||||||
|
return s.repo.UpdateProfit(ctx, pickupID, req, adminID, meta)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) Cancel(ctx context.Context, pickupID uint64, reason string, adminID uint64, meta auditlog.Meta) error {
|
func (s *Service) Cancel(ctx context.Context, pickupID uint64, reason string, adminID uint64, meta auditlog.Meta) error {
|
||||||
if s.repo == nil {
|
if s.repo == nil {
|
||||||
return ErrDependencyUnavailable
|
return ErrDependencyUnavailable
|
||||||
|
|||||||
@@ -590,6 +590,7 @@ func New(cfg config.Config, deps Dependencies, logger *zap.Logger) *gin.Engine {
|
|||||||
adminRoutes.GET("/pickups/available-listings", requirePerm("order:pickup"), pickupHandler.AvailableListings)
|
adminRoutes.GET("/pickups/available-listings", requirePerm("order:pickup"), pickupHandler.AvailableListings)
|
||||||
adminRoutes.GET("/pickups/:id", requirePerm("order:pickup"), pickupHandler.Detail)
|
adminRoutes.GET("/pickups/:id", requirePerm("order:pickup"), pickupHandler.Detail)
|
||||||
adminRoutes.POST("/pickups/:id/complete", requirePerm("order:pickup"), pickupHandler.Complete)
|
adminRoutes.POST("/pickups/:id/complete", requirePerm("order:pickup"), pickupHandler.Complete)
|
||||||
|
adminRoutes.PUT("/pickups/:id/profit", requirePerm("order:pickup"), pickupHandler.UpdateProfit)
|
||||||
adminRoutes.POST("/pickups/:id/cancel", requirePerm("order:pickup"), pickupHandler.Cancel)
|
adminRoutes.POST("/pickups/:id/cancel", requirePerm("order:pickup"), pickupHandler.Cancel)
|
||||||
|
|
||||||
adminRoutes.GET("/listings", requirePerm("listing:view"), listingHandler.ListAdmin)
|
adminRoutes.GET("/listings", requirePerm("listing:view"), listingHandler.ListAdmin)
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ export interface AdminPickupCompleteRequest {
|
|||||||
complete_remark?: string
|
complete_remark?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AdminPickupProfitUpdateRequest {
|
||||||
|
profit_amount_cent: number
|
||||||
|
reason?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface AdminPickupListQuery {
|
export interface AdminPickupListQuery {
|
||||||
page?: number
|
page?: number
|
||||||
page_size?: number
|
page_size?: number
|
||||||
@@ -119,6 +124,11 @@ export async function completeAdminPickup(id: number, req: AdminPickupCompleteRe
|
|||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateAdminPickupProfit(id: number, req: AdminPickupProfitUpdateRequest) {
|
||||||
|
const { data } = await apiClient.put<ApiResponse<AdminPickup>>(`/admin/pickups/${id}/profit`, req)
|
||||||
|
return data.data
|
||||||
|
}
|
||||||
|
|
||||||
export async function cancelAdminPickup(id: number, reason: string) {
|
export async function cancelAdminPickup(id: number, reason: string) {
|
||||||
const { data } = await apiClient.post<ApiResponse<{ cancelled: boolean }>>(
|
const { data } = await apiClient.post<ApiResponse<{ cancelled: boolean }>>(
|
||||||
`/admin/pickups/${id}/cancel`,
|
`/admin/pickups/${id}/cancel`,
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
|
import { EditPen } from '@element-plus/icons-vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
import { fetchAdminPickup, type AdminPickup } from '@/features/admin/api/adminPickup'
|
import {
|
||||||
|
fetchAdminPickup,
|
||||||
|
updateAdminPickupProfit,
|
||||||
|
type AdminPickup,
|
||||||
|
} from '@/features/admin/api/adminPickup'
|
||||||
import { quantity, readNumber, readUnitPrice } from '@/features/orders/composables/useOrderSnapshot'
|
import { quantity, readNumber, readUnitPrice } from '@/features/orders/composables/useOrderSnapshot'
|
||||||
import { adminPath } from '@/shared/utils/adminPath'
|
import { adminPath } from '@/shared/utils/adminPath'
|
||||||
import { formatListingNo } from '@/shared/utils/listingDisplay'
|
import { formatListingNo } from '@/shared/utils/listingDisplay'
|
||||||
import { formatCentWithSymbol, formatMoneyWithSymbol } from '@/shared/utils/money'
|
import {
|
||||||
|
centToYuan,
|
||||||
|
formatCentWithSymbol,
|
||||||
|
formatMoneyWithSymbol,
|
||||||
|
yuanToCent,
|
||||||
|
} from '@/shared/utils/money'
|
||||||
import { pickupStatusLabel } from '@/shared/utils/statusLabels'
|
import { pickupStatusLabel } from '@/shared/utils/statusLabels'
|
||||||
import { formatDateTime } from '@/shared/utils/time'
|
import { formatDateTime } from '@/shared/utils/time'
|
||||||
|
|
||||||
@@ -22,10 +33,14 @@ interface SnapshotResource {
|
|||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const pickup = ref<AdminPickup | null>(null)
|
const pickup = ref<AdminPickup | null>(null)
|
||||||
|
const profitDialogVisible = ref(false)
|
||||||
|
const profitSaving = ref(false)
|
||||||
|
const profitForm = reactive({ profit_amount: 0, reason: '' })
|
||||||
|
|
||||||
const listingCode = computed(() =>
|
const listingCode = computed(() =>
|
||||||
pickup.value ? formatListingNo(pickup.value.listing_no, pickup.value.listing_id) : '-'
|
pickup.value ? formatListingNo(pickup.value.listing_no, pickup.value.listing_id) : '-'
|
||||||
)
|
)
|
||||||
|
const canEditProfit = computed(() => pickup.value?.status === 'picking_up')
|
||||||
const snapshot = computed(() => normalizeRecord(pickup.value?.account_snapshot))
|
const snapshot = computed(() => normalizeRecord(pickup.value?.account_snapshot))
|
||||||
const assetSummary = computed(() => normalizeRecord(snapshot.value?.asset_summary))
|
const assetSummary = computed(() => normalizeRecord(snapshot.value?.asset_summary))
|
||||||
const priceBreakdown = computed(() => normalizeRecord(assetSummary.value?.price_breakdown))
|
const priceBreakdown = computed(() => normalizeRecord(assetSummary.value?.price_breakdown))
|
||||||
@@ -99,6 +114,34 @@ async function loadPickup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openProfitDialog() {
|
||||||
|
if (!pickup.value) return
|
||||||
|
profitForm.profit_amount = centToYuan(pickup.value.profit_amount_cent)
|
||||||
|
profitForm.reason = ''
|
||||||
|
profitDialogVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleUpdateProfit() {
|
||||||
|
if (!pickup.value) return
|
||||||
|
if (profitForm.profit_amount < 0) {
|
||||||
|
ElMessage.warning('线下利润不能为负数')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
profitSaving.value = true
|
||||||
|
try {
|
||||||
|
pickup.value = await updateAdminPickupProfit(pickup.value.id, {
|
||||||
|
profit_amount_cent: yuanToCent(profitForm.profit_amount),
|
||||||
|
reason: profitForm.reason,
|
||||||
|
})
|
||||||
|
ElMessage.success('线下利润已更新')
|
||||||
|
profitDialogVisible.value = false
|
||||||
|
} catch (e: unknown) {
|
||||||
|
ElMessage.error(errorMessage(e) || '修改失败')
|
||||||
|
} finally {
|
||||||
|
profitSaving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function statusType(status: string) {
|
function statusType(status: string) {
|
||||||
if (status === 'picking_up') return 'warning'
|
if (status === 'picking_up') return 'warning'
|
||||||
if (status === 'completed') return 'success'
|
if (status === 'completed') return 'success'
|
||||||
@@ -118,6 +161,13 @@ function displayValue(value: unknown) {
|
|||||||
return String(value)
|
return String(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function errorMessage(e: unknown) {
|
||||||
|
if (typeof e === 'object' && e !== null && 'message' in e) {
|
||||||
|
return String((e as { message?: unknown }).message)
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
function readBreakdownCent(key: string) {
|
function readBreakdownCent(key: string) {
|
||||||
const value = readNumber(priceBreakdown.value?.[key])
|
const value = readNumber(priceBreakdown.value?.[key])
|
||||||
return value > 0 ? Math.round(value * 100) : null
|
return value > 0 ? Math.round(value * 100) : null
|
||||||
@@ -183,6 +233,15 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="toolbar-actions">
|
<div class="toolbar-actions">
|
||||||
|
<el-button
|
||||||
|
v-if="canEditProfit"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
:icon="EditPen"
|
||||||
|
@click="openProfitDialog"
|
||||||
|
>
|
||||||
|
修改利润
|
||||||
|
</el-button>
|
||||||
<RouterLink :to="adminPath('pickup')">
|
<RouterLink :to="adminPath('pickup')">
|
||||||
<el-button>返回列表</el-button>
|
<el-button>返回列表</el-button>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
@@ -259,7 +318,7 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
|||||||
<section class="dashboard-panel detail-panel">
|
<section class="dashboard-panel detail-panel">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h2>资金拆分</h2>
|
<h2>资金拆分</h2>
|
||||||
<span class="panel-subtitle">提号创建时固化</span>
|
<span class="panel-subtitle">价格快照来自创建时</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="money-list">
|
<div class="money-list">
|
||||||
<div
|
<div
|
||||||
@@ -333,6 +392,37 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
|||||||
<pre class="snapshot-json">{{ snapshotText }}</pre>
|
<pre class="snapshot-json">{{ snapshotText }}</pre>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<el-dialog v-model="profitDialogVisible" title="修改线下利润" width="460px">
|
||||||
|
<el-form label-width="110px">
|
||||||
|
<el-form-item label="线下利润(元)" required>
|
||||||
|
<el-input-number
|
||||||
|
v-model="profitForm.profit_amount"
|
||||||
|
:min="0"
|
||||||
|
:step="1"
|
||||||
|
:precision="2"
|
||||||
|
controls-position="right"
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="修改原因">
|
||||||
|
<el-input
|
||||||
|
v-model="profitForm.reason"
|
||||||
|
type="textarea"
|
||||||
|
:rows="3"
|
||||||
|
maxlength="255"
|
||||||
|
show-word-limit
|
||||||
|
placeholder="可选"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="profitDialogVisible = false">取消</el-button>
|
||||||
|
<el-button type="primary" :loading="profitSaving" @click="handleUpdateProfit">
|
||||||
|
保存
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { Plus, Refresh, Search } from '@element-plus/icons-vue'
|
import { EditPen, Plus, Refresh, Search } from '@element-plus/icons-vue'
|
||||||
import {
|
import {
|
||||||
cancelAdminPickup,
|
cancelAdminPickup,
|
||||||
completeAdminPickup,
|
completeAdminPickup,
|
||||||
createAdminPickup,
|
createAdminPickup,
|
||||||
fetchAdminPickups,
|
fetchAdminPickups,
|
||||||
fetchAvailableListings,
|
fetchAvailableListings,
|
||||||
|
updateAdminPickupProfit,
|
||||||
type AdminPickup,
|
type AdminPickup,
|
||||||
type AvailableListing,
|
type AvailableListing,
|
||||||
} from '@/features/admin/api/adminPickup'
|
} from '@/features/admin/api/adminPickup'
|
||||||
@@ -23,7 +24,9 @@ const filters = reactive({ page: 1, page_size: 20, keyword: '', status: '' })
|
|||||||
|
|
||||||
const createDialogVisible = ref(false)
|
const createDialogVisible = ref(false)
|
||||||
const completeDialogVisible = ref(false)
|
const completeDialogVisible = ref(false)
|
||||||
|
const profitDialogVisible = ref(false)
|
||||||
const activePickupId = ref(0)
|
const activePickupId = ref(0)
|
||||||
|
const profitSaving = ref(false)
|
||||||
|
|
||||||
const createForm = reactive({
|
const createForm = reactive({
|
||||||
listing_id: null as number | null,
|
listing_id: null as number | null,
|
||||||
@@ -32,6 +35,7 @@ const createForm = reactive({
|
|||||||
remark: '',
|
remark: '',
|
||||||
})
|
})
|
||||||
const completeForm = reactive({ settle_amount: 0, profit_amount: 0, complete_remark: '' })
|
const completeForm = reactive({ settle_amount: 0, profit_amount: 0, complete_remark: '' })
|
||||||
|
const profitForm = reactive({ profit_amount: 0, reason: '' })
|
||||||
|
|
||||||
const listingOptions = ref<AvailableListing[]>([])
|
const listingOptions = ref<AvailableListing[]>([])
|
||||||
const listingLoading = ref(false)
|
const listingLoading = ref(false)
|
||||||
@@ -139,6 +143,13 @@ function openCompleteDialog(row: AdminPickup) {
|
|||||||
completeDialogVisible.value = true
|
completeDialogVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openProfitDialog(row: AdminPickup) {
|
||||||
|
activePickupId.value = row.id
|
||||||
|
profitForm.profit_amount = centToYuan(row.profit_amount_cent)
|
||||||
|
profitForm.reason = ''
|
||||||
|
profitDialogVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
async function handleComplete() {
|
async function handleComplete() {
|
||||||
if (completeForm.settle_amount <= 0) {
|
if (completeForm.settle_amount <= 0) {
|
||||||
ElMessage.warning('请输入结算金额')
|
ElMessage.warning('请输入结算金额')
|
||||||
@@ -165,6 +176,27 @@ async function handleComplete() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleUpdateProfit() {
|
||||||
|
if (profitForm.profit_amount < 0) {
|
||||||
|
ElMessage.warning('线下利润不能为负数')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
profitSaving.value = true
|
||||||
|
try {
|
||||||
|
await updateAdminPickupProfit(activePickupId.value, {
|
||||||
|
profit_amount_cent: yuanToCent(profitForm.profit_amount),
|
||||||
|
reason: profitForm.reason,
|
||||||
|
})
|
||||||
|
ElMessage.success('线下利润已更新')
|
||||||
|
profitDialogVisible.value = false
|
||||||
|
loadList()
|
||||||
|
} catch (e: unknown) {
|
||||||
|
ElMessage.error(errorMessage(e) || '修改失败')
|
||||||
|
} finally {
|
||||||
|
profitSaving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleCancel(id: number) {
|
async function handleCancel(id: number) {
|
||||||
try {
|
try {
|
||||||
const { value } = await ElMessageBox.prompt('请输入取消原因', '取消提号', {
|
const { value } = await ElMessageBox.prompt('请输入取消原因', '取消提号', {
|
||||||
@@ -275,6 +307,9 @@ function listingOwnerTotalCent(item: AvailableListing) {
|
|||||||
<span v-else class="text-muted">待结算</span>
|
<span v-else class="text-muted">待结算</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column label="线下利润" width="120">
|
||||||
|
<template #default="{ row }">{{ formatCentWithSymbol(row.profit_amount_cent) }}</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="状态" width="100">
|
<el-table-column label="状态" width="100">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="statusType(row.status)" effect="light">
|
<el-tag :type="statusType(row.status)" effect="light">
|
||||||
@@ -285,12 +320,22 @@ function listingOwnerTotalCent(item: AvailableListing) {
|
|||||||
<el-table-column label="创建时间" width="170">
|
<el-table-column label="创建时间" width="170">
|
||||||
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="操作" width="220" fixed="right">
|
<el-table-column label="操作" width="300" fixed="right">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
<RouterLink :to="adminPath(`pickup/${row.id}`)">
|
<RouterLink :to="adminPath(`pickup/${row.id}`)">
|
||||||
<el-button size="small">详情</el-button>
|
<el-button size="small">详情</el-button>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
|
<el-button
|
||||||
|
v-if="row.status === 'picking_up'"
|
||||||
|
type="success"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
:icon="EditPen"
|
||||||
|
@click="openProfitDialog(row)"
|
||||||
|
>
|
||||||
|
改利润
|
||||||
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-if="row.status === 'picking_up'"
|
v-if="row.status === 'picking_up'"
|
||||||
type="primary"
|
type="primary"
|
||||||
@@ -433,6 +478,37 @@ function listingOwnerTotalCent(item: AvailableListing) {
|
|||||||
<el-button type="primary" :loading="loading" @click="handleComplete">确认结算</el-button>
|
<el-button type="primary" :loading="loading" @click="handleComplete">确认结算</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog v-model="profitDialogVisible" title="修改线下利润" width="460px">
|
||||||
|
<el-form label-width="110px">
|
||||||
|
<el-form-item label="线下利润(元)" required>
|
||||||
|
<el-input-number
|
||||||
|
v-model="profitForm.profit_amount"
|
||||||
|
:min="0"
|
||||||
|
:step="1"
|
||||||
|
:precision="2"
|
||||||
|
controls-position="right"
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="修改原因">
|
||||||
|
<el-input
|
||||||
|
v-model="profitForm.reason"
|
||||||
|
type="textarea"
|
||||||
|
:rows="3"
|
||||||
|
maxlength="255"
|
||||||
|
show-word-limit
|
||||||
|
placeholder="可选"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="profitDialogVisible = false">取消</el-button>
|
||||||
|
<el-button type="primary" :loading="profitSaving" @click="handleUpdateProfit">
|
||||||
|
保存
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export const AUDIT_ACTION_OPTIONS: AuditOption[] = [
|
|||||||
// 提号
|
// 提号
|
||||||
{ value: 'pickup_create', label: '创建提号', group: '提号' },
|
{ value: 'pickup_create', label: '创建提号', group: '提号' },
|
||||||
{ value: 'pickup_complete', label: '完成提号结算', group: '提号', highRisk: true },
|
{ value: 'pickup_complete', label: '完成提号结算', group: '提号', highRisk: true },
|
||||||
|
{ value: 'pickup_profit_update', label: '修改提号利润', group: '提号', highRisk: true },
|
||||||
{ value: 'pickup_cancel', label: '取消提号', group: '提号' },
|
{ value: 'pickup_cancel', label: '取消提号', group: '提号' },
|
||||||
// 申诉
|
// 申诉
|
||||||
{ value: 'dispute.arbitrate', label: '申诉仲裁', group: '申诉', highRisk: true },
|
{ value: 'dispute.arbitrate', label: '申诉仲裁', group: '申诉', highRisk: true },
|
||||||
|
|||||||
Reference in New Issue
Block a user