Merge branch '20260604-long'
This commit is contained in:
@@ -1096,6 +1096,11 @@
|
||||
<el-tag v-if="row.is_exempt === 1" type="warning" size="small" class="ml-1">豁免</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="方式" min-width="120" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ formatPayOrderSource(row) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator_name" label="创建人" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="创建时间" min-width="136">
|
||||
<template #default="{ row }">
|
||||
@@ -1154,6 +1159,11 @@
|
||||
<el-tag v-if="row.is_exempt === 1" type="warning" size="small" class="ml-1">豁免</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="方式" min-width="120" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ formatPayOrderSource(row) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator_name" label="创建人" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="创建时间" min-width="136">
|
||||
<template #default="{ row }">
|
||||
@@ -1783,7 +1793,7 @@
|
||||
<el-option
|
||||
v-for="o in editPaidOrders"
|
||||
:key="o.id"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)}`"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)} · ${formatPayOrderSource(o)}`"
|
||||
:value="o.id"
|
||||
class="!h-auto py-1.5"
|
||||
>
|
||||
@@ -1793,7 +1803,7 @@
|
||||
<span class="text-orange-500 font-medium ml-4">¥{{ o.amount }}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between text-xs text-gray-400 mt-1">
|
||||
<span class="truncate pr-2">{{ formatPoCategory(o.order_type) }}<template v-if="o.remark"> · {{ o.remark }}</template></span>
|
||||
<span class="truncate pr-2">{{ formatPoCategory(o.order_type) }} · {{ formatPayOrderSource(o) }}<template v-if="o.remark"> · {{ o.remark }}</template></span>
|
||||
<span class="shrink-0">{{ String(o.create_time || '').substring(0, 16) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2287,13 +2297,13 @@
|
||||
>
|
||||
<el-form-item label="添加方式" prop="add_mode">
|
||||
<el-radio-group v-model="addPayOrderForm.add_mode">
|
||||
<el-radio value="create">手动创建</el-radio>
|
||||
<el-radio value="create">付呗</el-radio>
|
||||
<el-radio value="link">关联已有</el-radio>
|
||||
<el-radio value="completion_only">直接完单申请</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 手动创建模式 -->
|
||||
<!-- 付呗(手动创建支付单) -->
|
||||
<template v-if="addPayOrderForm.add_mode === 'create'">
|
||||
<el-form-item label="费用类别" prop="order_type">
|
||||
<el-select v-model="addPayOrderForm.order_type" class="w-full">
|
||||
@@ -2358,13 +2368,18 @@
|
||||
<el-option
|
||||
v-for="o in addPayOrderAvailableList"
|
||||
:key="o.id"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)}`"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)} · ${formatPayOrderSource(o)}`"
|
||||
:value="o.id"
|
||||
>
|
||||
<div class="flex flex-col gap-0.5 py-0.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm">{{ o.order_no }}</span>
|
||||
<span class="text-orange-500 font-medium ml-4">¥{{ o.amount }}</span>
|
||||
</div>
|
||||
<div class="text-xs text-gray-400">
|
||||
{{ formatPoCategory(o.order_type) }} · {{ formatPayOrderSource(o) }}
|
||||
</div>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<div class="text-xs text-gray-500 mt-1.5">
|
||||
@@ -3980,10 +3995,14 @@ const detailLinkedPayOrders = computed(() => {
|
||||
return Array.isArray(arr) ? arr : []
|
||||
})
|
||||
|
||||
/** 需代收:业务订单总金额 − 关联已付总额 */
|
||||
/** 需代收:优先用关联时记录的固定快照值;历史单(无快照)回退实时计算 总金额 − 关联已付总额 */
|
||||
const detailAgencyToCollect = computed(() => {
|
||||
const d = detailData.value
|
||||
if (!d) return 0
|
||||
const snap = d.agency_collect_amount
|
||||
if (snap !== null && snap !== undefined && snap !== '') {
|
||||
return Number(snap) || 0
|
||||
}
|
||||
const total = Number(d.amount) || 0
|
||||
const paid = Number(d.linked_pay_paid_total) || 0
|
||||
return Math.round((total - paid) * 100) / 100
|
||||
@@ -4692,7 +4711,7 @@ const editDiagnosisCreatorDeptBreadcrumbs = computed(() => {
|
||||
.filter((segs) => segs.length > 0)
|
||||
})
|
||||
|
||||
const editPaidOrders = ref<Array<{ id: number; order_no?: string; amount?: number | string; order_type?: number | string; remark?: string; create_time?: string }>>([])
|
||||
const editPaidOrders = ref<Array<{ id: number; order_no?: string; amount?: number | string; order_type?: number | string; remark?: string; create_time?: string; payment_method?: string; create_type?: string }>>([])
|
||||
const editPaidOrdersLoading = ref(false)
|
||||
const editDepositMin = ref(0)
|
||||
|
||||
@@ -4708,6 +4727,24 @@ function formatPoCategory(t: unknown) {
|
||||
return m[Number(t)] || '未知'
|
||||
}
|
||||
|
||||
function formatPayOrderSource(row: { payment_method?: unknown; create_type?: unknown }) {
|
||||
const createType = String(row?.create_type || '')
|
||||
if (createType === 'wechat_work') return '企业微信对外收款'
|
||||
if (createType === 'fubei') return '付呗'
|
||||
const paymentMethod = String(row?.payment_method || '')
|
||||
const methodMap: Record<string, string> = {
|
||||
alipay: '支付宝',
|
||||
wechat: '微信',
|
||||
wechat_work: '企业微信',
|
||||
fubei: '付呗',
|
||||
manual: '手动确认到账'
|
||||
}
|
||||
if (paymentMethod && methodMap[paymentMethod]) {
|
||||
return methodMap[paymentMethod]
|
||||
}
|
||||
return '普通订单'
|
||||
}
|
||||
|
||||
const editLinkedPaidTotal = computed(() => {
|
||||
const ids = new Set(editForm.pay_order_ids.map((x) => Number(x)))
|
||||
let s = 0
|
||||
@@ -5701,7 +5738,7 @@ const addPayOrderAlertTitle = computed(() => {
|
||||
if (addPayOrderForm.add_mode === 'completion_only') {
|
||||
return '不创建或关联支付单,仅提交完单申请,由审核人员在支付审核时处理。'
|
||||
}
|
||||
return '可以手动创建新支付单,或关联已存在但未绑定的支付单。'
|
||||
return '可以通过付呗创建新支付单,或关联已存在但未绑定的支付单。'
|
||||
})
|
||||
|
||||
const addPayOrderForm = reactive({
|
||||
|
||||
@@ -962,6 +962,11 @@
|
||||
<el-tag v-if="row.is_exempt === 1" type="warning" size="small" class="ml-1">豁免</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="方式" min-width="120" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ formatPayOrderSource(row) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator_name" label="创建人" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="创建时间" min-width="136">
|
||||
<template #default="{ row }">
|
||||
@@ -1020,6 +1025,11 @@
|
||||
<el-tag v-if="row.is_exempt === 1" type="warning" size="small" class="ml-1">豁免</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="方式" min-width="120" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ formatPayOrderSource(row) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="creator_name" label="创建人" width="80" show-overflow-tooltip />
|
||||
<el-table-column label="创建时间" min-width="136">
|
||||
<template #default="{ row }">
|
||||
@@ -1555,7 +1565,7 @@
|
||||
<el-option
|
||||
v-for="o in editPaidOrders"
|
||||
:key="o.id"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)}`"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)} · ${formatPayOrderSource(o)}`"
|
||||
:value="o.id"
|
||||
class="!h-auto py-1.5"
|
||||
>
|
||||
@@ -1565,7 +1575,7 @@
|
||||
<span class="text-orange-500 font-medium ml-4">¥{{ o.amount }}</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between text-xs text-gray-400 mt-1">
|
||||
<span class="truncate pr-2">{{ formatPoCategory(o.order_type) }}<template v-if="o.remark"> · {{ o.remark }}</template></span>
|
||||
<span class="truncate pr-2">{{ formatPoCategory(o.order_type) }} · {{ formatPayOrderSource(o) }}<template v-if="o.remark"> · {{ o.remark }}</template></span>
|
||||
<span class="shrink-0">{{ String(o.create_time || '').substring(0, 16) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1971,7 +1981,7 @@
|
||||
@closed="addPayOrderFormRef?.clearValidate()"
|
||||
>
|
||||
<el-alert
|
||||
title="可以手动创建新支付单,或关联已存在但未绑定的支付单。"
|
||||
:title="addPayOrderAlertTitle"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
@@ -1987,12 +1997,13 @@
|
||||
>
|
||||
<el-form-item label="添加方式" prop="add_mode">
|
||||
<el-radio-group v-model="addPayOrderForm.add_mode">
|
||||
<el-radio value="create">手动创建</el-radio>
|
||||
<el-radio value="create">付呗</el-radio>
|
||||
<el-radio value="link">关联已有</el-radio>
|
||||
<el-radio value="completion_only">直接完单申请</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 手动创建模式 -->
|
||||
<!-- 付呗(手动创建支付单) -->
|
||||
<template v-if="addPayOrderForm.add_mode === 'create'">
|
||||
<el-form-item label="费用类别" prop="order_type">
|
||||
<el-select v-model="addPayOrderForm.order_type" class="w-full">
|
||||
@@ -2028,6 +2039,20 @@
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<!-- 直接完单申请(不创建/关联支付单) -->
|
||||
<template v-else-if="addPayOrderForm.add_mode === 'completion_only'">
|
||||
<el-alert
|
||||
type="warning"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="!mb-0"
|
||||
>
|
||||
<template #title>
|
||||
不新增或关联支付单,仅向审核人员提交「完成订单」申请;提交后支付审核将变为待审核,审核通过后将自动结案。
|
||||
</template>
|
||||
</el-alert>
|
||||
</template>
|
||||
|
||||
<!-- 关联已有模式 -->
|
||||
<template v-else>
|
||||
<el-form-item label="选择支付单" prop="link_pay_order_id">
|
||||
@@ -2043,13 +2068,18 @@
|
||||
<el-option
|
||||
v-for="o in addPayOrderAvailableList"
|
||||
:key="o.id"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)}`"
|
||||
:label="`${o.order_no} · ¥${o.amount} · ${formatPoCategory(o.order_type)} · ${formatPayOrderSource(o)}`"
|
||||
:value="o.id"
|
||||
>
|
||||
<div class="flex flex-col gap-0.5 py-0.5">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-sm">{{ o.order_no }}</span>
|
||||
<span class="text-orange-500 font-medium ml-4">¥{{ o.amount }}</span>
|
||||
</div>
|
||||
<div class="text-xs text-gray-400">
|
||||
{{ formatPoCategory(o.order_type) }} · {{ formatPayOrderSource(o) }}
|
||||
</div>
|
||||
</div>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<div class="text-xs text-gray-500 mt-1.5">
|
||||
@@ -2059,7 +2089,7 @@
|
||||
</template>
|
||||
|
||||
<!-- 完单申请选项 -->
|
||||
<el-form-item label="完单申请">
|
||||
<el-form-item v-if="addPayOrderForm.add_mode !== 'completion_only'" label="完单申请">
|
||||
<el-radio-group v-model="addPayOrderForm.completion_request">
|
||||
<el-radio :value="0">不申请</el-radio>
|
||||
<el-radio :value="1">申请完成订单</el-radio>
|
||||
@@ -2531,6 +2561,7 @@ import {
|
||||
prescriptionOrderRevokePayAudit,
|
||||
prescriptionOrderPatchPrescriptionPatient,
|
||||
prescriptionOrderLinkPayOrder,
|
||||
prescriptionOrderRequestCompletion,
|
||||
prescriptionOrderSubmitGancaoRecipel,
|
||||
prescriptionOrderPreviewGancaoRecipel,
|
||||
prescriptionDetail,
|
||||
@@ -3495,10 +3526,14 @@ const detailLinkedPayOrders = computed(() => {
|
||||
return Array.isArray(arr) ? arr : []
|
||||
})
|
||||
|
||||
/** 需代收:业务订单总金额 − 关联已付总额 */
|
||||
/** 需代收:优先用关联时记录的固定快照值;历史单(无快照)回退实时计算 总金额 − 关联已付总额 */
|
||||
const detailAgencyToCollect = computed(() => {
|
||||
const d = detailData.value
|
||||
if (!d) return 0
|
||||
const snap = d.agency_collect_amount
|
||||
if (snap !== null && snap !== undefined && snap !== '') {
|
||||
return Number(snap) || 0
|
||||
}
|
||||
const total = Number(d.amount) || 0
|
||||
const paid = Number(d.linked_pay_paid_total) || 0
|
||||
return Math.round((total - paid) * 100) / 100
|
||||
@@ -4041,7 +4076,7 @@ const editDiagnosisCreatorDeptBreadcrumbs = computed(() => {
|
||||
.filter((segs) => segs.length > 0)
|
||||
})
|
||||
|
||||
const editPaidOrders = ref<Array<{ id: number; order_no?: string; amount?: number | string; order_type?: number | string; remark?: string; create_time?: string }>>([])
|
||||
const editPaidOrders = ref<Array<{ id: number; order_no?: string; amount?: number | string; order_type?: number | string; remark?: string; create_time?: string; payment_method?: string; create_type?: string }>>([])
|
||||
const editPaidOrdersLoading = ref(false)
|
||||
const editDepositMin = ref(0)
|
||||
|
||||
@@ -4057,6 +4092,24 @@ function formatPoCategory(t: unknown) {
|
||||
return m[Number(t)] || '未知'
|
||||
}
|
||||
|
||||
function formatPayOrderSource(row: { payment_method?: unknown; create_type?: unknown }) {
|
||||
const createType = String(row?.create_type || '')
|
||||
if (createType === 'wechat_work') return '企业微信对外收款'
|
||||
if (createType === 'fubei') return '付呗'
|
||||
const paymentMethod = String(row?.payment_method || '')
|
||||
const methodMap: Record<string, string> = {
|
||||
alipay: '支付宝',
|
||||
wechat: '微信',
|
||||
wechat_work: '企业微信',
|
||||
fubei: '付呗',
|
||||
manual: '手动确认到账'
|
||||
}
|
||||
if (paymentMethod && methodMap[paymentMethod]) {
|
||||
return methodMap[paymentMethod]
|
||||
}
|
||||
return '普通订单'
|
||||
}
|
||||
|
||||
const editLinkedPaidTotal = computed(() => {
|
||||
const ids = new Set(editForm.pay_order_ids.map((x) => Number(x)))
|
||||
let s = 0
|
||||
@@ -4898,8 +4951,14 @@ const addPayOrderRowId = ref(0)
|
||||
const addPayOrderFormRef = ref<FormInstance>()
|
||||
const addPayOrderAvailableLoading = ref(false)
|
||||
const addPayOrderAvailableList = ref<any[]>([])
|
||||
const addPayOrderAlertTitle = computed(() => {
|
||||
if (addPayOrderForm.add_mode === 'completion_only') {
|
||||
return '不创建或关联支付单,仅提交完单申请,由审核人员在支付审核时处理。'
|
||||
}
|
||||
return '可以通过付呗创建新支付单,或关联已存在但未绑定的支付单。'
|
||||
})
|
||||
const addPayOrderForm = reactive({
|
||||
add_mode: 'create' as 'create' | 'link',
|
||||
add_mode: 'create' as 'create' | 'link' | 'completion_only',
|
||||
order_type: 3,
|
||||
pay_amount: undefined as number | undefined,
|
||||
pay_remark: '',
|
||||
@@ -4907,10 +4966,13 @@ const addPayOrderForm = reactive({
|
||||
completion_request: 0
|
||||
})
|
||||
|
||||
const addPayOrderRules: FormRules = {
|
||||
add_mode: [{ required: true, message: '请选择添加方式', trigger: 'change' }],
|
||||
order_type: [{ required: true, message: '请选择费用类别', trigger: 'change' }],
|
||||
pay_amount: [
|
||||
const addPayOrderRules = computed<FormRules>(() => {
|
||||
const rules: FormRules = {
|
||||
add_mode: [{ required: true, message: '请选择添加方式', trigger: 'change' }]
|
||||
}
|
||||
if (addPayOrderForm.add_mode === 'create') {
|
||||
rules.order_type = [{ required: true, message: '请选择费用类别', trigger: 'change' }]
|
||||
rules.pay_amount = [
|
||||
{ required: true, message: '请输入支付金额', trigger: 'blur' },
|
||||
{
|
||||
validator: (_rule, v, cb) => {
|
||||
@@ -4923,8 +4985,9 @@ const addPayOrderRules: FormRules = {
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
link_pay_order_ids: [
|
||||
]
|
||||
} else if (addPayOrderForm.add_mode === 'link') {
|
||||
rules.link_pay_order_ids = [
|
||||
{
|
||||
required: true,
|
||||
message: '请至少选择一个支付单',
|
||||
@@ -4938,7 +5001,9 @@ const addPayOrderRules: FormRules = {
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
return rules
|
||||
})
|
||||
|
||||
async function loadAddPayOrderAvailable(diagnosisId: number, currentLinkedIds: number[] = []) {
|
||||
if (!diagnosisId) {
|
||||
@@ -4986,7 +5051,10 @@ async function submitAddPayOrder() {
|
||||
await addPayOrderFormRef.value.validate()
|
||||
addPayOrderSaving.value = true
|
||||
try {
|
||||
if (addPayOrderForm.add_mode === 'create') {
|
||||
if (addPayOrderForm.add_mode === 'completion_only') {
|
||||
await prescriptionOrderRequestCompletion({ id: addPayOrderRowId.value })
|
||||
feedback.msgSuccess('完单申请已提交,请等待支付审核')
|
||||
} else if (addPayOrderForm.add_mode === 'create') {
|
||||
// 手动创建新支付单
|
||||
await prescriptionOrderAddPayOrder({
|
||||
id: addPayOrderRowId.value,
|
||||
|
||||
@@ -174,9 +174,9 @@
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="支付方式" width="100">
|
||||
<el-table-column label="支付方式" width="120">
|
||||
<template #default="{ row }">
|
||||
{{ getPaymentMethodText(row.payment_method) }}
|
||||
{{ getCreateTypeText(row) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
@@ -327,7 +327,7 @@
|
||||
<span class="text-red-500 font-semibold">¥{{ detailData.amount }}</span>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="支付方式">
|
||||
{{ getPaymentMethodText(detailData.payment_method) }}
|
||||
{{ getCreateTypeText(detailData) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="支付时间">
|
||||
{{ detailData.payment_time || '-' }}
|
||||
@@ -1148,7 +1148,8 @@ const submitCreateOrder = async () => {
|
||||
patient_id: createForm.patient_id,
|
||||
order_type: createForm.order_type,
|
||||
amount: createForm.amount,
|
||||
remark: createForm.remark
|
||||
remark: createForm.remark,
|
||||
create_type: 'wechat_work'
|
||||
}
|
||||
const res: any = await orderCreateForWechatWork(params)
|
||||
const orderNo = res?.order_no ?? res?.data?.order_no
|
||||
@@ -1160,7 +1161,8 @@ const submitCreateOrder = async () => {
|
||||
patient_id: createForm.patient_id,
|
||||
order_type: createForm.order_type,
|
||||
amount: createForm.amount,
|
||||
remark: createForm.remark
|
||||
remark: createForm.remark,
|
||||
create_type: createForm.createType
|
||||
}
|
||||
if (createForm.createType === 'fubei') {
|
||||
params.payment_channel = 'fubei'
|
||||
@@ -1247,6 +1249,26 @@ const getPaymentMethodText = (method: string | null) => {
|
||||
return methodMap[method] || '未知'
|
||||
}
|
||||
|
||||
// 支付方式展示:优先按「创建方式」三值显示;历史单/无 create_type 时回退真实支付渠道文案
|
||||
const getCreateTypeText = (row: any) => {
|
||||
const createTypeMap: Record<string, string> = {
|
||||
normal: '普通订单',
|
||||
wechat_work: '企业微信对外收款',
|
||||
fubei: '付呗'
|
||||
}
|
||||
const ct = row?.create_type
|
||||
if (ct === 'wechat_work' || ct === 'fubei') {
|
||||
return createTypeMap[ct]
|
||||
}
|
||||
if (ct === 'normal' && row?.payment_method) {
|
||||
return getPaymentMethodText(row.payment_method)
|
||||
}
|
||||
if (ct && createTypeMap[ct]) {
|
||||
return createTypeMap[ct]
|
||||
}
|
||||
return getPaymentMethodText(row?.payment_method)
|
||||
}
|
||||
|
||||
// 编辑订单
|
||||
const handleEditOrder = (row: any) => {
|
||||
editOrderForm.value = {
|
||||
|
||||
@@ -415,6 +415,10 @@ const detailLinkedPayOrders = computed(() => {
|
||||
const detailAgencyToCollect = computed(() => {
|
||||
const d = detailData.value
|
||||
if (!d) return 0
|
||||
const snap = d.agency_collect_amount
|
||||
if (snap !== null && snap !== undefined && snap !== '') {
|
||||
return Number(snap) || 0
|
||||
}
|
||||
const total = Number(d.amount) || 0
|
||||
const paid = Number(d.linked_pay_paid_total) || 0
|
||||
return Math.round((total - paid) * 100) / 100
|
||||
|
||||
@@ -207,6 +207,11 @@ class OrderController extends BaseAdminController
|
||||
$params['creator_id'] = $this->adminId;
|
||||
$params['payment_channel'] = (string)$this->request->post('payment_channel', 'normal');
|
||||
$params['require_payment_slip_audit'] = (int)$this->request->post('require_payment_slip_audit', 0);
|
||||
// 创建方式:优先取前端透传的 create_type,否则按 payment_channel 派生(fubei→fubei,其余 normal)
|
||||
$createTypeReq = (string)$this->request->post('create_type', '');
|
||||
$params['create_type'] = in_array($createTypeReq, ['normal', 'wechat_work', 'fubei'], true)
|
||||
? $createTypeReq
|
||||
: ($params['payment_channel'] === 'fubei' ? 'fubei' : 'normal');
|
||||
|
||||
$result = OrderLogic::create($params);
|
||||
if (!$result) {
|
||||
@@ -227,6 +232,7 @@ class OrderController extends BaseAdminController
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('create');
|
||||
$params['creator_id'] = $this->adminId;
|
||||
$params['create_type'] = 'wechat_work';
|
||||
|
||||
$result = OrderLogic::createForWechatWork($params);
|
||||
if (!$result) {
|
||||
|
||||
@@ -22,6 +22,11 @@ use think\facade\Log;
|
||||
*/
|
||||
class OrderLogic
|
||||
{
|
||||
/**
|
||||
* 创建方式统一三值:normal 普通订单 / wechat_work 企业微信对外收款 / fubei 付呗
|
||||
*/
|
||||
private const CREATE_TYPES = ['normal', 'wechat_work', 'fubei'];
|
||||
|
||||
/**
|
||||
* @notes 生成订单号
|
||||
* @return string
|
||||
@@ -31,6 +36,34 @@ class OrderLogic
|
||||
return 'ORD' . date('YmdHis') . mt_rand(100000, 999999);
|
||||
}
|
||||
|
||||
private static function normalizeCreateType(
|
||||
?string $createType,
|
||||
?string $paymentMethod = null,
|
||||
?string $payeeUserid = null,
|
||||
?string $payerExternalUserid = null,
|
||||
?string $remark = null
|
||||
): string {
|
||||
$raw = trim((string) $createType);
|
||||
if (in_array($raw, self::CREATE_TYPES, true)) {
|
||||
return $raw;
|
||||
}
|
||||
|
||||
$paymentMethod = trim((string) $paymentMethod);
|
||||
if ($paymentMethod === 'fubei') {
|
||||
return 'fubei';
|
||||
}
|
||||
|
||||
if (
|
||||
trim((string) $payeeUserid) !== ''
|
||||
|| trim((string) $payerExternalUserid) !== ''
|
||||
|| str_contains((string) $remark, '企业微信')
|
||||
) {
|
||||
return 'wechat_work';
|
||||
}
|
||||
|
||||
return 'normal';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 创建订单
|
||||
* @param array $params
|
||||
@@ -43,6 +76,8 @@ class OrderLogic
|
||||
if (!in_array($channel, ['normal', 'fubei'], true)) {
|
||||
$channel = 'normal';
|
||||
}
|
||||
$paymentMethod = $channel === 'fubei' ? 'fubei' : null;
|
||||
$createType = self::normalizeCreateType((string)($params['create_type'] ?? ''), $paymentMethod);
|
||||
$requirePaymentSlipAudit = (int)($params['require_payment_slip_audit'] ?? 0) === 1;
|
||||
|
||||
$order = new Order();
|
||||
@@ -51,6 +86,7 @@ class OrderLogic
|
||||
$order->creator_id = $params['creator_id'];
|
||||
$order->order_type = $params['order_type'];
|
||||
$order->amount = $params['amount'];
|
||||
$order->create_type = $createType;
|
||||
// 付呗且申请审核支付单:待审核(5);否则待支付(1)
|
||||
if ($channel === 'fubei') {
|
||||
$order->payment_method = 'fubei';
|
||||
@@ -183,6 +219,10 @@ class OrderLogic
|
||||
$order->payment_method = 'wechat';
|
||||
$needSave = true;
|
||||
}
|
||||
if ((string) ($order->create_type ?? '') !== 'wechat_work') {
|
||||
$order->create_type = 'wechat_work';
|
||||
$needSave = true;
|
||||
}
|
||||
if ($paymentTimeStr !== '' && (string)$order->payment_time !== $paymentTimeStr) {
|
||||
$order->payment_time = $paymentTimeStr;
|
||||
$needSave = true;
|
||||
@@ -235,6 +275,7 @@ class OrderLogic
|
||||
$order->amount = $amount;
|
||||
$order->status = $targetStatus;
|
||||
$order->payment_method = 'wechat';
|
||||
$order->create_type = 'wechat_work';
|
||||
$order->payment_time = $paymentTimeStr;
|
||||
$order->trade_no = $tradeNo;
|
||||
$remark = '企业微信直接收款同步,待关联患者';
|
||||
@@ -283,6 +324,7 @@ class OrderLogic
|
||||
$order->amount = $amount;
|
||||
$order->status = 2; // 已支付
|
||||
$order->payment_method = 'wechat';
|
||||
$order->create_type = 'wechat_work';
|
||||
$order->payment_time = date('Y-m-d H:i:s');
|
||||
$order->trade_no = $tradeNo;
|
||||
$order->remark = '企业微信直接收款,待关联患者';
|
||||
@@ -536,6 +578,13 @@ class OrderLogic
|
||||
$n->creator_id = $order->creator_id;
|
||||
$n->order_type = (int) $typeList[$i];
|
||||
$n->amount = $amt;
|
||||
$n->create_type = self::normalizeCreateType(
|
||||
(string) ($order->create_type ?? ''),
|
||||
(string) ($order->payment_method ?? ''),
|
||||
(string) ($order->payee_userid ?? ''),
|
||||
(string) ($order->payer_external_userid ?? ''),
|
||||
(string) ($order->remark ?? '')
|
||||
);
|
||||
if ($st === 5) {
|
||||
$n->payment_method = 'fubei';
|
||||
$n->status = 5;
|
||||
@@ -1213,7 +1262,7 @@ class OrderLogic
|
||||
}
|
||||
|
||||
$rows = $q
|
||||
->field(['id', 'order_no', 'order_type', 'amount', 'status', 'create_time', 'creator_id', 'remark', 'is_exempt'])
|
||||
->field(['id', 'order_no', 'order_type', 'amount', 'status', 'create_time', 'creator_id', 'remark', 'is_exempt', 'payment_method', 'create_type'])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
@@ -696,6 +696,8 @@ class PrescriptionOrderLogic
|
||||
{
|
||||
PrescriptionOrderPayOrder::where('prescription_order_id', (int) $order->id)->delete();
|
||||
$order->linked_pay_order_id = null;
|
||||
// 解除关联后刷新「需代收」固定快照(已付归零 → 需代收=总金额)
|
||||
self::refreshAgencyCollectSnapshot((int) $order->id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -768,7 +770,7 @@ class PrescriptionOrderLogic
|
||||
return [];
|
||||
}
|
||||
$rows = Order::whereIn('id', $ids)->whereNull('delete_time')
|
||||
->field(['id', 'order_no', 'order_type', 'amount', 'status', 'create_time', 'creator_id', 'remark', 'is_exempt'])
|
||||
->field(['id', 'order_no', 'order_type', 'amount', 'status', 'create_time', 'creator_id', 'remark', 'is_exempt', 'payment_method', 'create_type'])
|
||||
->order('id', 'asc')
|
||||
->whereIn('status', [2, 4, 5])
|
||||
->select()
|
||||
@@ -837,6 +839,35 @@ class PrescriptionOrderLogic
|
||||
$arr['deposit_min_amount'] = self::depositMinAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新「需代收」固定快照:按当前 总金额 − 关联已付总额(支付单 status ∈ {2 已支付, 5 待审核})写入 agency_collect_amount。
|
||||
* 在关联/新增支付单、建单、改总金额、解除关联等写操作末尾调用;之后退款/审核状态变化不再影响该值。
|
||||
*/
|
||||
private static function refreshAgencyCollectSnapshot(int $id): void
|
||||
{
|
||||
if ($id <= 0) {
|
||||
return;
|
||||
}
|
||||
$order = PrescriptionOrder::where('id', $id)->whereNull('delete_time')->find();
|
||||
if (!$order) {
|
||||
return;
|
||||
}
|
||||
$amount = round((float) $order->amount, 2);
|
||||
$paid = 0.0;
|
||||
$ids = self::linkedPayOrderIdList($id);
|
||||
if ($ids !== []) {
|
||||
$payOrders = Order::whereIn('id', $ids)->whereNull('delete_time')->field(['amount', 'status'])->select();
|
||||
foreach ($payOrders as $po) {
|
||||
$st = (int) $po->status;
|
||||
if ($st === 2 || $st === 5) {
|
||||
$paid += (float) $po->amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
$order->agency_collect_amount = round($amount - $paid, 2);
|
||||
$order->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $params
|
||||
* @return array<string,mixed>|false
|
||||
@@ -969,7 +1000,9 @@ class PrescriptionOrderLogic
|
||||
self::replacePayOrderLinks((int) $order->id, $payOrderIds);
|
||||
}
|
||||
|
||||
$out = $order->toArray();
|
||||
self::refreshAgencyCollectSnapshot((int) $order->id);
|
||||
|
||||
$out = PrescriptionOrder::where('id', (int) $order->id)->find()->toArray();
|
||||
self::maskInternalCostIfNeeded($out, $adminInfo);
|
||||
self::maskRemarkExtraIfNeeded($out, $adminInfo);
|
||||
self::attachLinkedPayOrders($out);
|
||||
@@ -1737,7 +1770,9 @@ class PrescriptionOrderLogic
|
||||
|
||||
self::writeLog((int) $order->id, $adminId, $adminInfo, 'edit', '编辑了业务订单及相关信息');
|
||||
|
||||
$out = $order->toArray();
|
||||
self::refreshAgencyCollectSnapshot((int) $order->id);
|
||||
|
||||
$out = PrescriptionOrder::where('id', (int) $order->id)->find()->toArray();
|
||||
self::maskInternalCostIfNeeded($out, $adminInfo);
|
||||
self::maskRemarkExtraIfNeeded($out, $adminInfo);
|
||||
self::attachLinkedPayOrders($out);
|
||||
@@ -2281,12 +2316,16 @@ class PrescriptionOrderLogic
|
||||
$order->payment_slip_audit_remark = '';
|
||||
self::syncFulfillmentStatus($order);
|
||||
|
||||
// 将关联的已支付支付单(status=2,且payment_method='manual')恢复为待审核(status=5)
|
||||
// 将关联的已支付补齐支付单恢复为待审核:兼容旧 manual 与新 fubei/create_type=fubei 两种标记
|
||||
$payOrderIds = self::linkedPayOrderIdList($id);
|
||||
if (!empty($payOrderIds)) {
|
||||
Order::whereIn('id', $payOrderIds)
|
||||
->where('status', 2) // 只恢复已支付状态的
|
||||
->where('payment_method', 'manual') // 只恢复手动创建的
|
||||
->where(function ($query) {
|
||||
$query->where('payment_method', 'manual')
|
||||
->whereOr('payment_method', 'fubei')
|
||||
->whereOr('create_type', 'fubei');
|
||||
})
|
||||
->update([
|
||||
'status' => 5, // 待审核
|
||||
'payment_time' => null
|
||||
@@ -2378,7 +2417,8 @@ class PrescriptionOrderLogic
|
||||
$payOrder->order_type = $orderType;
|
||||
$payOrder->amount = $amount;
|
||||
$payOrder->status = 5; // 待审核
|
||||
$payOrder->payment_method = 'manual';
|
||||
$payOrder->payment_method = 'fubei'; // 补齐支付单按「付呗」记账
|
||||
$payOrder->create_type = 'fubei';
|
||||
$payOrder->payment_time = null; // 审核通过后再设置支付时间
|
||||
$payOrder->remark = $remark;
|
||||
|
||||
@@ -2420,7 +2460,9 @@ class PrescriptionOrderLogic
|
||||
}
|
||||
self::writeLog($id, $adminId, $adminInfo, 'add_pay_order', $logMsg);
|
||||
|
||||
$out = $order->toArray();
|
||||
self::refreshAgencyCollectSnapshot($id);
|
||||
|
||||
$out = PrescriptionOrder::where('id', $id)->find()->toArray();
|
||||
self::maskInternalCostIfNeeded($out, $adminInfo);
|
||||
self::maskRemarkExtraIfNeeded($out, $adminInfo);
|
||||
self::attachLinkedPayOrders($out);
|
||||
@@ -2531,7 +2573,9 @@ class PrescriptionOrderLogic
|
||||
}
|
||||
self::writeLog($id, $adminId, $adminInfo, 'link_pay_order', $logMsg);
|
||||
|
||||
$out = $order->toArray();
|
||||
self::refreshAgencyCollectSnapshot($id);
|
||||
|
||||
$out = PrescriptionOrder::where('id', $id)->find()->toArray();
|
||||
self::maskInternalCostIfNeeded($out, $adminInfo);
|
||||
self::maskRemarkExtraIfNeeded($out, $adminInfo);
|
||||
self::attachLinkedPayOrders($out);
|
||||
@@ -3415,7 +3459,11 @@ class PrescriptionOrderLogic
|
||||
$item['export_refund_amount'] = $refundStored > 0
|
||||
? number_format($refundStored, 2, '.', '')
|
||||
: '';
|
||||
$item['export_agency_collect'] = number_format(round($amt - $paid, 2), 2, '.', '');
|
||||
// 需代收:优先用固定快照值 agency_collect_amount;历史单为 NULL 时回退实时 amt − paid
|
||||
$agencySnap = $item['agency_collect_amount'] ?? null;
|
||||
$item['export_agency_collect'] = ($agencySnap !== null && $agencySnap !== '')
|
||||
? number_format(round((float) $agencySnap, 2), 2, '.', '')
|
||||
: number_format(round($amt - $paid, 2), 2, '.', '');
|
||||
|
||||
$item['export_tracking_number'] = (string) ($item['tracking_number'] ?? '');
|
||||
$signTs = $poId > 0 ? (int) ($signTsByPoId[$poId] ?? 0) : 0;
|
||||
@@ -4149,6 +4197,9 @@ class PrescriptionOrderLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
// 总金额变化后刷新「需代收」固定快照,保持与新总额一致
|
||||
self::refreshAgencyCollectSnapshot($id);
|
||||
|
||||
// 记录日志
|
||||
$summary = sprintf('将订单金额从 ¥%.2f 修改为 ¥%.2f', $oldAmount, $newAmount);
|
||||
self::writeLog($id, $adminId, $adminInfo, 'update_amount', $summary);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- 支付单:创建方式(统一为三值,用于支付方式显示)
|
||||
ALTER TABLE `zyt_order`
|
||||
ADD COLUMN `create_type` varchar(20) NOT NULL DEFAULT 'normal' COMMENT '创建方式:normal 普通订单 / wechat_work 企业微信对外收款 / fubei 付呗' AFTER `payment_method`;
|
||||
@@ -0,0 +1,3 @@
|
||||
-- 处方业务订单:需代收固定值(关联支付单/改总金额时快照,NULL 表示按实时计算回退)
|
||||
ALTER TABLE `zyt_tcm_prescription_order`
|
||||
ADD COLUMN `agency_collect_amount` decimal(10,2) DEFAULT NULL COMMENT '需代收固定值(关联/改额时快照,NULL 表示按实时计算回退)' AFTER `refund_amount`;
|
||||
Reference in New Issue
Block a user