交易明细操作检查订单页面添加完成订单接口调用 & 充值和扣款接口新增操作说明 字段
This commit is contained in:
@@ -44,7 +44,11 @@ export async function createCust(data: {
|
||||
return callByUser<PageRecord<User>>("/api/admin/user/create", data)
|
||||
}
|
||||
|
||||
export async function getDeposit(params: { user_id: number; amount: string }) {
|
||||
export async function getDeposit(params: {
|
||||
user_id: number
|
||||
amount: string
|
||||
remark: string
|
||||
}) {
|
||||
return callByUser<PageRecord<User>>(
|
||||
"/api/admin/user/update/balance-inc",
|
||||
params,
|
||||
@@ -54,6 +58,7 @@ export async function getDeposit(params: { user_id: number; amount: string }) {
|
||||
export async function getDeduction(params: {
|
||||
user_id: number
|
||||
amount: string
|
||||
remark: string
|
||||
}) {
|
||||
return callByUser<PageRecord<User>>(
|
||||
"/api/admin/user/update/balance-dec",
|
||||
|
||||
@@ -39,7 +39,7 @@ export async function updateTradeRemark(params: {
|
||||
}
|
||||
|
||||
type PayCloseData = {
|
||||
status: 0 | 1 | 2
|
||||
Status: 0 | 1 | 2
|
||||
TransId: string
|
||||
}
|
||||
|
||||
@@ -49,3 +49,27 @@ export async function getTradeCheckk(params: {
|
||||
}) {
|
||||
return callByUser<PayCloseData>("/api/admin/trade/check", params)
|
||||
}
|
||||
|
||||
export async function tradeComplete(params: {
|
||||
trade_no: string
|
||||
method: number
|
||||
user_id: number
|
||||
}) {
|
||||
return callByUser<PayCloseData>("/api/admin/trade/complete", params)
|
||||
}
|
||||
|
||||
export async function tradeConvert(params: {
|
||||
trade_no: string
|
||||
method: number
|
||||
user_id: number
|
||||
}) {
|
||||
return callByUser<PayCloseData>("/api/admin/trade/convert", params)
|
||||
}
|
||||
|
||||
export async function tradeCancel(params: {
|
||||
trade_no: string
|
||||
method: number
|
||||
user_id: number
|
||||
}) {
|
||||
return callByUser<PayCloseData>("/api/admin/trade/cancel", params)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from "@/components/ui/dialog"
|
||||
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import type { User } from "@/models/user"
|
||||
|
||||
const Schema = z.object({
|
||||
@@ -26,6 +27,7 @@ const Schema = z.object({
|
||||
.min(1, "请输入扣款金额")
|
||||
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
||||
.refine(val => Number(val) >= 0, "金额不能为负数"),
|
||||
remark: z.string().min(1, "请输入操作说明"),
|
||||
})
|
||||
|
||||
type FormValues = z.infer<typeof Schema>
|
||||
@@ -52,6 +54,7 @@ export function DeductionDialog({
|
||||
resolver: zodResolver(Schema),
|
||||
defaultValues: {
|
||||
deduction: "",
|
||||
remark: "",
|
||||
},
|
||||
})
|
||||
|
||||
@@ -61,6 +64,7 @@ export function DeductionDialog({
|
||||
const result = await getDeduction({
|
||||
user_id: user.id,
|
||||
amount: data.deduction,
|
||||
remark: data.remark,
|
||||
})
|
||||
|
||||
if (result.success) {
|
||||
@@ -123,6 +127,15 @@ export function DeductionDialog({
|
||||
/>
|
||||
<FieldError>{errors.deduction?.message}</FieldError>
|
||||
</Field>
|
||||
<Field data-invalid={!!errors.remark}>
|
||||
<FieldLabel>操作说明</FieldLabel>
|
||||
<Textarea
|
||||
placeholder="请输入操作说明(必填)"
|
||||
{...register("remark")}
|
||||
rows={3}
|
||||
/>
|
||||
<FieldError>{errors.remark?.message}</FieldError>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
} from "@/components/ui/dialog"
|
||||
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import type { User } from "@/models/user"
|
||||
|
||||
const Schema = z.object({
|
||||
@@ -26,6 +27,7 @@ const Schema = z.object({
|
||||
.min(1, "请输入余额")
|
||||
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
||||
.refine(val => Number(val) >= 0, "余额不能为负数"),
|
||||
remark: z.string().min(1, "请输入操作说明"),
|
||||
})
|
||||
|
||||
type FormValues = z.infer<typeof Schema>
|
||||
@@ -49,6 +51,7 @@ export function DepositDialog({ user, onSuccess }: UpdateDepositDialogProps) {
|
||||
resolver: zodResolver(Schema),
|
||||
defaultValues: {
|
||||
deposit: "",
|
||||
remark: "",
|
||||
},
|
||||
})
|
||||
|
||||
@@ -58,6 +61,7 @@ export function DepositDialog({ user, onSuccess }: UpdateDepositDialogProps) {
|
||||
const result = await getDeposit({
|
||||
user_id: user.id,
|
||||
amount: data.deposit,
|
||||
remark: data.remark,
|
||||
})
|
||||
|
||||
if (result.success) {
|
||||
@@ -120,6 +124,15 @@ export function DepositDialog({ user, onSuccess }: UpdateDepositDialogProps) {
|
||||
/>
|
||||
<FieldError>{errors.deposit?.message}</FieldError>
|
||||
</Field>
|
||||
<Field data-invalid={!!errors.remark}>
|
||||
<FieldLabel>操作说明</FieldLabel>
|
||||
<Textarea
|
||||
placeholder="请输入操作说明(必填)"
|
||||
{...register("remark")}
|
||||
rows={3}
|
||||
/>
|
||||
<FieldError>{errors.remark?.message}</FieldError>
|
||||
</Field>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
|
||||
@@ -10,6 +10,9 @@ import { z } from "zod"
|
||||
import {
|
||||
getPageTrade,
|
||||
getTradeCheckk,
|
||||
tradeCancel,
|
||||
tradeComplete,
|
||||
tradeConvert,
|
||||
updateTradeRemark,
|
||||
} from "@/actions/trade"
|
||||
import { DataTable, useDataTable } from "@/components/data-table"
|
||||
@@ -119,7 +122,6 @@ export default function TradePage() {
|
||||
setFilters(result)
|
||||
table.pagination.onPageChange(1)
|
||||
})
|
||||
// console.log(...table.data.map(i => i.remark), "tabletabletabletable")
|
||||
|
||||
return (
|
||||
<Page>
|
||||
@@ -308,9 +310,10 @@ export default function TradePage() {
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},{
|
||||
header:"订单金额",
|
||||
accessorKey:"amount",
|
||||
},
|
||||
{
|
||||
header: "订单金额",
|
||||
accessorKey: "amount",
|
||||
cell: ({ row }) => {
|
||||
const amount =
|
||||
typeof row.original.amount === "string"
|
||||
@@ -318,9 +321,7 @@ export default function TradePage() {
|
||||
: row.original.amount || 0
|
||||
return (
|
||||
<div className="flex gap-1">
|
||||
<span>
|
||||
¥{amount.toFixed(2)}
|
||||
</span>
|
||||
<span>¥{amount.toFixed(2)}</span>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
@@ -406,7 +407,12 @@ export default function TradePage() {
|
||||
meta: { pin: "right" },
|
||||
cell: ({ row }) => (
|
||||
<div className="flex gap-2">
|
||||
<CheckOrder trade={row.original} />
|
||||
{row.original.status === 0 && (
|
||||
<CheckOrder
|
||||
trade={row.original}
|
||||
onSuccess={table.refresh}
|
||||
/>
|
||||
)}
|
||||
<UpdateRole trade={row.original} onSuccess={table.refresh} />
|
||||
</div>
|
||||
),
|
||||
@@ -418,10 +424,10 @@ export default function TradePage() {
|
||||
)
|
||||
}
|
||||
type PayCloseData = {
|
||||
status: 0 | 1 | 2
|
||||
Status: 0 | 1 | 2
|
||||
TransId?: string
|
||||
}
|
||||
function CheckOrder(props: { trade: Trade }) {
|
||||
function CheckOrder(props: { trade: Trade; onSuccess: () => void }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [data, setData] = useState<PayCloseData | null>(null)
|
||||
@@ -446,7 +452,78 @@ function CheckOrder(props: { trade: Trade }) {
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [props.trade.inner_no, props.trade.method])
|
||||
}, [props])
|
||||
|
||||
const headerClick = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const result = await tradeComplete({
|
||||
trade_no: props.trade.inner_no,
|
||||
method: Number(props.trade.method),
|
||||
user_id: Number(props.trade.user_id),
|
||||
})
|
||||
|
||||
if (result.success) {
|
||||
toast.success("订单已完成")
|
||||
props.onSuccess?.()
|
||||
} else {
|
||||
toast.error(result.message)
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : error
|
||||
toast.error(`检查失败,请重试: ${message}`)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [props])
|
||||
|
||||
const convert = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const result = await tradeConvert({
|
||||
trade_no: props.trade.inner_no,
|
||||
method: Number(props.trade.method),
|
||||
user_id: Number(props.trade.user_id),
|
||||
})
|
||||
console.log(result, "resultresultresult")
|
||||
|
||||
if (result.success) {
|
||||
toast.success("补到余额完成")
|
||||
props.onSuccess?.()
|
||||
} else {
|
||||
toast.error(result.message)
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : error
|
||||
toast.error(`补到余额失败,请重试: ${message}`)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [props])
|
||||
|
||||
const cancel = useCallback(async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const result = await tradeCancel({
|
||||
trade_no: props.trade.inner_no,
|
||||
method: Number(props.trade.method),
|
||||
user_id: Number(props.trade.user_id),
|
||||
})
|
||||
console.log(result, "resultresultresult")
|
||||
|
||||
if (result.success) {
|
||||
toast.success("取消订单完成")
|
||||
props.onSuccess?.()
|
||||
} else {
|
||||
toast.error(result.message)
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : error
|
||||
toast.error(`取消订单失败,请重试: ${message}`)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [props])
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -463,20 +540,33 @@ function CheckOrder(props: { trade: Trade }) {
|
||||
{data && (
|
||||
<div className="py-4">
|
||||
<div
|
||||
className={`p-4 rounded-lg ${data.status === 1 ? "bg-green-50" : "bg-red-50"}`}
|
||||
className={`p-4 rounded-lg ${data.Status === 1 ? "bg-green-100" : "bg-red-100"}`}
|
||||
>
|
||||
<p className="font-medium">创建时间:{data?.TransId}</p>
|
||||
<p className="font-medium">创建时间:{data?.TransId}</p>
|
||||
<p className="mt-2">
|
||||
支付状态:
|
||||
{data?.status === 1
|
||||
{data?.Status === 1
|
||||
? "已支付"
|
||||
: data?.status === 0
|
||||
: data?.Status === 0
|
||||
? "待支付"
|
||||
: "已取消"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{props && props.trade.status === 0 && (
|
||||
<>
|
||||
<Button size="sm" className="w-32" onClick={headerClick}>
|
||||
完成订单
|
||||
</Button>
|
||||
<Button size="sm" className="w-32" onClick={convert}>
|
||||
补到余额
|
||||
</Button>
|
||||
<Button size="sm" className="w-32" onClick={cancel}>
|
||||
取消订单
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
|
||||
Reference in New Issue
Block a user