更新
This commit is contained in:
@@ -298,7 +298,7 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
if ($diagnosisIds !== []) {
|
||||
$rxAll = Prescription::whereIn('diagnosis_id', $diagnosisIds)
|
||||
->whereNull('delete_time')
|
||||
->field(['id', 'diagnosis_id', 'doctor_name', 'creator_id', 'prescription_date', 'create_time', 'void_status'])
|
||||
->field(['id', 'diagnosis_id', 'doctor_name', 'creator_id', 'prescription_date', 'create_time', 'void_status', 'audit_status'])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
@@ -339,6 +339,8 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
'time_text' => $this->formatPrescriptionFollowupTime($rx),
|
||||
'doctor_name' => $doctorName !== '' ? $doctorName : '—',
|
||||
'voided' => (int) ($rx['void_status'] ?? 0) !== 0,
|
||||
'void_status' => (int) ($rx['void_status'] ?? 0),
|
||||
'audit_status' => (int) ($rx['audit_status'] ?? -1),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -348,6 +350,8 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$item['followup_time_text'] = ($item['has_prescription'] && $fu) ? ($fu['time_text'] ?? '') : '';
|
||||
$item['followup_doctor_name'] = ($item['has_prescription'] && $fu) ? ($fu['doctor_name'] ?? '—') : '';
|
||||
$item['followup_rx_voided'] = ($item['has_prescription'] && $fu && !empty($fu['voided'])) ? 1 : 0;
|
||||
$item['prescription_audit_status'] = ($item['has_prescription'] && $fu) ? (int) ($fu['audit_status'] ?? -1) : -1;
|
||||
$item['prescription_void_status'] = ($item['has_prescription'] && $fu) ? (int) ($fu['void_status'] ?? 0) : 0;
|
||||
// 开方次数即复诊次数:1 张处方 = 第 1 次复诊,以此类推
|
||||
$item['followup_prescription_count'] = (int) ($rxCountByDiag[$did] ?? 0);
|
||||
}
|
||||
|
||||
@@ -809,8 +809,8 @@ class PrescriptionLogic
|
||||
'dose_unit' => '剂',
|
||||
'usage_days' => 7,
|
||||
'times_per_day' => 2,
|
||||
'usage_instruction' => '水煎服,一日二次',
|
||||
'usage_time' => '饭前',
|
||||
'usage_instruction' => '',
|
||||
'usage_time' => '饭后',
|
||||
'usage_way' => '温水送服',
|
||||
'dietary_taboo' => '',
|
||||
'usage_notes' => '',
|
||||
|
||||
@@ -13,11 +13,10 @@ use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderLog;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminDept;
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\service\ExpressTrackService;
|
||||
use app\common\service\gancao\GancaoScmRecipelService;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class PrescriptionOrderLogic
|
||||
@@ -36,6 +35,7 @@ class PrescriptionOrderLogic
|
||||
|
||||
/**
|
||||
* 部门自底向上链式名称,含父级(如:总部 / 华东 / 上海门诊)
|
||||
* 使用 Db 直查 zyt_dept:避免 Dept 软删除全局作用域导致有 dept_id 仍拼不出路径
|
||||
*/
|
||||
private static function buildDeptPath(int $deptId): string
|
||||
{
|
||||
@@ -45,13 +45,13 @@ class PrescriptionOrderLogic
|
||||
$names = [];
|
||||
$id = $deptId;
|
||||
for ($i = 0; $i < 50; $i++) {
|
||||
$row = Dept::where('id', $id)->whereNull('delete_time')->field(['id', 'name', 'pid'])->find();
|
||||
if ($row === null) {
|
||||
$row = Db::name('dept')->where('id', $id)->field(['id', 'name', 'pid'])->find();
|
||||
if (empty($row)) {
|
||||
break;
|
||||
}
|
||||
$data = $row->toArray();
|
||||
array_unshift($names, (string) ($data['name'] ?? ''));
|
||||
$pid = (int) ($data['pid'] ?? 0);
|
||||
$r = is_array($row) ? $row : $row->toArray();
|
||||
array_unshift($names, (string) ($r['name'] ?? ''));
|
||||
$pid = (int) ($r['pid'] ?? 0);
|
||||
if ($pid <= 0) {
|
||||
break;
|
||||
}
|
||||
@@ -66,6 +66,27 @@ class PrescriptionOrderLogic
|
||||
return implode(' / ', $names);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员在 zyt_admin_dept 中的部门路径(多部门用「;」、含父级「 / 」)
|
||||
*/
|
||||
private static function buildAdminDeptPathJoined(int $adminId): string
|
||||
{
|
||||
if ($adminId <= 0) {
|
||||
return '';
|
||||
}
|
||||
$deptIds = Db::name('admin_dept')->where('admin_id', $adminId)->column('dept_id');
|
||||
$pathSegmentsC = [];
|
||||
foreach ($deptIds as $didC) {
|
||||
$pc = self::buildDeptPath((int) $didC);
|
||||
if ($pc !== '') {
|
||||
$pathSegmentsC[] = $pc;
|
||||
}
|
||||
}
|
||||
$pathSegmentsC = array_values(array_unique($pathSegmentsC));
|
||||
|
||||
return $pathSegmentsC === [] ? '' : implode(';', $pathSegmentsC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int[] $allowRoleIds
|
||||
*/
|
||||
@@ -641,7 +662,7 @@ class PrescriptionOrderLogic
|
||||
unset($arr['prescription']['herbs']);
|
||||
}
|
||||
|
||||
// 诊单医助 / 诊单创建人 及部门(多部门、含父级路径用「;」与「 / 」分隔);创建人为 tcm_diagnosis.admin_id
|
||||
// 诊单医助 / 诊单创建人姓名(tcm_diagnosis.admin_id);部门见下方:优先业务订单 creator_id
|
||||
$arr['assistant_id'] = 0;
|
||||
$arr['assistant_name'] = '';
|
||||
$arr['assistant_dept_path'] = '';
|
||||
@@ -659,7 +680,7 @@ class PrescriptionOrderLogic
|
||||
if ($astId > 0) {
|
||||
$an = Admin::where('id', $astId)->whereNull('delete_time')->value('name');
|
||||
$arr['assistant_name'] = $an !== null && (string) $an !== '' ? (string) $an : '';
|
||||
$deptIds = AdminDept::where('admin_id', $astId)->column('dept_id');
|
||||
$deptIds = Db::name('admin_dept')->where('admin_id', $astId)->column('dept_id');
|
||||
$pathSegments = [];
|
||||
foreach ($deptIds as $did) {
|
||||
$p = self::buildDeptPath((int) $did);
|
||||
@@ -675,19 +696,18 @@ class PrescriptionOrderLogic
|
||||
if ($creId > 0) {
|
||||
$cn = Admin::where('id', $creId)->whereNull('delete_time')->value('name');
|
||||
$arr['diagnosis_creator_name'] = $cn !== null && (string) $cn !== '' ? (string) $cn : '';
|
||||
$deptIdsC = AdminDept::where('admin_id', $creId)->column('dept_id');
|
||||
$pathSegmentsC = [];
|
||||
foreach ($deptIdsC as $didC) {
|
||||
$pc = self::buildDeptPath((int) $didC);
|
||||
if ($pc !== '') {
|
||||
$pathSegmentsC[] = $pc;
|
||||
}
|
||||
}
|
||||
$pathSegmentsC = array_values(array_unique($pathSegmentsC));
|
||||
$arr['diagnosis_creator_dept_path'] = $pathSegmentsC === [] ? '' : implode(';', $pathSegmentsC);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 「创建人所属部门」:优先 zyt_tcm_prescription_order.creator_id;无部门时再试诊单 admin_id(非处方开方人)
|
||||
$deptPath = self::buildAdminDeptPathJoined((int) ($arr['creator_id'] ?? 0));
|
||||
if ($deptPath === '') {
|
||||
$dgAdmin = (int) ($arr['diagnosis_creator_id'] ?? 0);
|
||||
if ($dgAdmin > 0) {
|
||||
$deptPath = self::buildAdminDeptPathJoined($dgAdmin);
|
||||
}
|
||||
}
|
||||
$arr['diagnosis_creator_dept_path'] = $deptPath;
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\Order;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderLog;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
use think\facade\Config;
|
||||
use think\facade\Log;
|
||||
use think\Response;
|
||||
@@ -237,11 +239,66 @@ class GancaoCallbackController extends BaseApiController
|
||||
* 11 系统审核通过
|
||||
* 110 订单药房流转制作中(ext: flow_name, supplier)
|
||||
* 20 物流中(ext: shipping_name, nu, supplier)
|
||||
* 30 完成 - 终态(ext: shipping_name, nu, supplier)
|
||||
* 30 完成 - 终态。fulfillment 见 resolveFulfilmentOnGancaoState30(与 zyt_order 已付/关联合计对比业务订单 amount)
|
||||
* 90 拦截 - 可恢复
|
||||
* 91 主动撤单 - 终态(退费)
|
||||
* 92 驳回 - 终态(无法制作并退费)
|
||||
*/
|
||||
/**
|
||||
* 甘草 state=30:返回 fulfillment_status 3=已完成 或 6=已签收
|
||||
* 1) 已支付金额(zyt_order.status=2 的 amount 合计)与业务订单 amount 一致 → 3
|
||||
* 2) 否则已关联订单金额合计(全部关联单 amount)与业务订单 amount 一致 → 3
|
||||
* 3) 否则 → 6(含:已支付与总金额不一致且关联合计也不一致)
|
||||
* 无关联 zyt_order:仅甘草完成则 3
|
||||
*/
|
||||
private function resolveFulfilmentOnGancaoState30(PrescriptionOrder $order): int
|
||||
{
|
||||
$poId = (int) $order->id;
|
||||
if ($poId <= 0) {
|
||||
return 3;
|
||||
}
|
||||
$payIds = PrescriptionOrderPayOrder::where('prescription_order_id', $poId)
|
||||
->column('pay_order_id');
|
||||
$payIds = array_values(array_filter(
|
||||
array_map('intval', is_array($payIds) ? $payIds : []),
|
||||
static fn (int $id): bool => $id > 0
|
||||
));
|
||||
if ($payIds === []) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
$orderAmt = round((float) ($order->amount ?? 0), 2);
|
||||
$sumAll = round(
|
||||
(float) Order::whereIn('id', $payIds)->whereNull('delete_time')->sum('amount'),
|
||||
2
|
||||
);
|
||||
$sumPaid = round(
|
||||
(float) Order::whereIn('id', $payIds)
|
||||
->whereNull('delete_time')
|
||||
->where('status', 2)
|
||||
->sum('amount'),
|
||||
2
|
||||
);
|
||||
|
||||
if (abs($sumPaid - $orderAmt) <= 0.02) {
|
||||
return 3;
|
||||
}
|
||||
if (abs($sumAll - $orderAmt) <= 0.02) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
Log::warning('Gancao 完成回调:已支付(status=2)与关联合计均未与业务订单金额对齐,标已签收(6)', [
|
||||
'prescription_order_id' => $poId,
|
||||
'order_no' => (string) ($order->order_no ?? ''),
|
||||
'tcm_order_amount' => $orderAmt,
|
||||
'sum_paid_status2' => $sumPaid,
|
||||
'sum_linked_all' => $sumAll,
|
||||
'linked_pay_order_ids' => $payIds,
|
||||
]);
|
||||
|
||||
return 6;
|
||||
}
|
||||
|
||||
private function updateOrderStatus(PrescriptionOrder $order, int $state, array $ext): void
|
||||
{
|
||||
$order->gancao_order_state = $state;
|
||||
@@ -262,7 +319,7 @@ class GancaoCallbackController extends BaseApiController
|
||||
case 30:
|
||||
$this->handleShipping($order, $ext);
|
||||
if ((int) $order->fulfillment_status !== 4) {
|
||||
$order->fulfillment_status = 3; // 已完成
|
||||
$order->fulfillment_status = $this->resolveFulfilmentOnGancaoState30($order);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user