修复bug
This commit is contained in:
@@ -552,6 +552,8 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
}
|
||||
unset($item);
|
||||
|
||||
$this->appendPrescriptionOrderAssignSnapshotErCenterFlags($lists);
|
||||
|
||||
if ((int) ($this->params['yeji_order_drawer'] ?? 0) === 1) {
|
||||
PrescriptionOrderLogic::appendLinkedAppointmentsToListRows($lists, $this->params);
|
||||
}
|
||||
@@ -1069,4 +1071,118 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
. ")"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表行标注:指派日志快照(related_po_creator_id + related_po_create_time)是否指向本业务单,
|
||||
* 以及该次操作的新医助(to_assistant_id)是否归属「二中心」部门子树(与 DeptLogic / 业绩看板一致)。
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $lists
|
||||
*/
|
||||
private function appendPrescriptionOrderAssignSnapshotErCenterFlags(array &$lists): void
|
||||
{
|
||||
if ($lists === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$diagIds = [];
|
||||
foreach ($lists as $row) {
|
||||
$d = (int) ($row['diagnosis_id'] ?? 0);
|
||||
if ($d > 0) {
|
||||
$diagIds[$d] = true;
|
||||
}
|
||||
}
|
||||
$diagIdList = array_keys($diagIds);
|
||||
$latestSnapLogByTriple = [];
|
||||
if ($diagIdList !== []) {
|
||||
$logRows = Db::name('tcm_diagnosis_assign_log')
|
||||
->whereIn('diagnosis_id', $diagIdList)
|
||||
->field(['id', 'diagnosis_id', 'to_assistant_id', 'related_po_creator_id', 'related_po_create_time'])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($logRows as $log) {
|
||||
$d = (int) ($log['diagnosis_id'] ?? 0);
|
||||
$rcp = (int) ($log['related_po_creator_id'] ?? 0);
|
||||
$rpct = (int) ($log['related_po_create_time'] ?? 0);
|
||||
if ($d <= 0 || $rcp <= 0 || $rpct <= 0) {
|
||||
continue;
|
||||
}
|
||||
$tripleKey = $d . ':' . $rcp . ':' . $rpct;
|
||||
if (!isset($latestSnapLogByTriple[$tripleKey])) {
|
||||
$latestSnapLogByTriple[$tripleKey] = $log;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$toAssistantIdsHit = [];
|
||||
foreach ($lists as $item) {
|
||||
$diagId = (int) ($item['diagnosis_id'] ?? 0);
|
||||
$creatorId = (int) ($item['creator_id'] ?? 0);
|
||||
$poCt = (int) ($item['create_time'] ?? 0);
|
||||
$tripleKey = $diagId . ':' . $creatorId . ':' . $poCt;
|
||||
$log = $latestSnapLogByTriple[$tripleKey] ?? null;
|
||||
if (\is_array($log)) {
|
||||
$tid = (int) ($log['to_assistant_id'] ?? 0);
|
||||
if ($tid > 0) {
|
||||
$toAssistantIdsHit[$tid] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$toAssistantIdList = array_keys($toAssistantIdsHit);
|
||||
|
||||
$erDeptSet = DeptLogic::getErCenterSubtreeDeptIdSet();
|
||||
$adminErCenter = [];
|
||||
if ($toAssistantIdList !== [] && $erDeptSet !== []) {
|
||||
$adRows = AdminDept::whereIn('admin_id', $toAssistantIdList)
|
||||
->field(['admin_id', 'dept_id'])
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($adRows as $ad) {
|
||||
$aid = (int) ($ad['admin_id'] ?? 0);
|
||||
$did = (int) ($ad['dept_id'] ?? 0);
|
||||
if ($aid > 0 && $did > 0 && isset($erDeptSet[$did])) {
|
||||
$adminErCenter[$aid] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nameMap = [];
|
||||
if ($toAssistantIdList !== []) {
|
||||
$nameMap = \app\common\model\auth\Admin::whereIn('id', $toAssistantIdList)->column('name', 'id');
|
||||
}
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$diagId = (int) ($item['diagnosis_id'] ?? 0);
|
||||
$creatorId = (int) ($item['creator_id'] ?? 0);
|
||||
$poCt = (int) ($item['create_time'] ?? 0);
|
||||
|
||||
$item['po_assign_snapshot_hit'] = 0;
|
||||
$item['po_assign_to_assistant_id'] = 0;
|
||||
$item['po_assign_to_assistant_name'] = '';
|
||||
$item['po_assign_to_er_center'] = 0;
|
||||
$item['po_assign_is_release'] = 0;
|
||||
|
||||
if ($diagId <= 0 || $creatorId <= 0 || $poCt <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tripleKey = $diagId . ':' . $creatorId . ':' . $poCt;
|
||||
$log = $latestSnapLogByTriple[$tripleKey] ?? null;
|
||||
if (!\is_array($log)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item['po_assign_snapshot_hit'] = 1;
|
||||
$toId = (int) ($log['to_assistant_id'] ?? 0);
|
||||
$item['po_assign_to_assistant_id'] = $toId;
|
||||
if ($toId <= 0) {
|
||||
$item['po_assign_is_release'] = 1;
|
||||
continue;
|
||||
}
|
||||
$item['po_assign_to_assistant_name'] = (string) ($nameMap[$toId] ?? '');
|
||||
$item['po_assign_to_er_center'] = isset($adminErCenter[$toId]) ? 1 : 0;
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ use think\console\Output;
|
||||
* 配置 crontab(每 10 分钟):拉快递 100 + 按履约「已发货/已签收」核对释放诊单医助(与是否甘草单无关)
|
||||
* 0,10,20,30,40,50 * * * * cd /path/to/server && php think express:auto-update >> /dev/null 2>&1
|
||||
*
|
||||
* 已对非二中心医助执行发货/签收自动释放的诊单会写入 tcm_diagnosis.shipped_non_er_assistant_cleared_at,
|
||||
* 已对「业务订单创建人非二中心」(或创建人为开方医生时按待释放身份判定)执行发货/签收自动释放的诊单会写入 tcm_diagnosis.shipped_non_er_assistant_cleared_at,
|
||||
* 后续履约核对不再重复扫描(需先执行 sql/1.9.20260507/add_diagnosis_shipped_non_er_assistant_cleared_at.sql)。
|
||||
*/
|
||||
class ExpressAutoUpdate extends Command
|
||||
|
||||
@@ -29,7 +29,7 @@ use think\console\Output;
|
||||
* 建议 crontab(每 30 分钟执行一次):
|
||||
* 0,30 * * * * cd /path/to/server && php think gancao:sync-logistics --limit=200 >> runtime/log/gancao_sync.log 2>&1
|
||||
*
|
||||
* 已对非二中心医助执行发货/签收自动释放的诊单会写入 tcm_diagnosis.shipped_non_er_assistant_cleared_at,
|
||||
* 已对「业务订单创建人非二中心」(发货/签收自动释放规则见 ExpressTrackingService)的诊单会写入 tcm_diagnosis.shipped_non_er_assistant_cleared_at,
|
||||
* 后续履约核对不再重复扫描(需先执行 sql/1.9.20260507/add_diagnosis_shipped_non_er_assistant_cleared_at.sql)。
|
||||
*/
|
||||
class GancaoSyncLogisticsRoute extends Command
|
||||
|
||||
@@ -249,7 +249,7 @@ class ExpressTrackingService
|
||||
/**
|
||||
* 处方业务订单履约「已发货(5) / 已签收(6)」时:清空关联诊单(患者)医助,并写入 tcm_diagnosis_assign_log(含关联业务订单 creator_id / create_time 快照,便于核对医助创建订单时间)。
|
||||
* 快递 100 定时拉轨迹、甘草路由、甘草回调与履约核对共用同一规则。
|
||||
* 不自动清空的情形仅两种:(1)患者当前医助在「二中心」及其全部子部门(与后台部门树一致)下任职;(2)诊单已有 shipped_non_er_assistant_cleared_at 且 assistant_id 已为 0(视为已处理过,重新指派医助后可再次处理)。
|
||||
* 不自动清空的情形:(1)按业务订单 creator_id(代建场景)或回退身份判断是否在「二中心」部门子树;(2)诊单已有 shipped_non_er_assistant_cleared_at 且 assistant_id 已为 0(视为已处理);(3)指派日志存在后台人工指派:`operator_admin_id>0` 且 `to_assistant_id>0`(系统任务为 operator_admin_id=0);或 related_po_creator_id=from_assistant_id 且 to>0 的旧数据兼容。避免「系统·已发货履约核对」覆盖人工指派链。
|
||||
*
|
||||
* @param array{tracking_id?:int,tracking_number?:string,source?:string} $meta
|
||||
* @return array{
|
||||
@@ -288,36 +288,55 @@ class ExpressTrackingService
|
||||
if (!$diag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 后台曾人工指派到新医助(operator_admin_id>0 且 to>0,与系统写入的 operator=0 区分)时不再自动清空;另保留快照 related_po=from 的旧数据兼容
|
||||
if (self::diagnosisShouldSkipAutoAssistantReleaseDueToManualAssignLog($diagnosisId)) {
|
||||
Log::info('Skipped auto assistant release (shipped/signed): manual assign history exists (human operator + to_assistant_id>0, or snapshot-tied pattern)', [
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'prescription_order_id' => $orderId,
|
||||
'source' => $source,
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$shippedClearedAt = (int) ($diag->getAttr('shipped_non_er_assistant_cleared_at') ?? 0);
|
||||
$diagAssistantIdNow = (int) ($diag->getAttr('assistant_id') ?? 0);
|
||||
if ($shippedClearedAt > 0 && $diagAssistantIdNow === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$poCreatorId = (int) ($order->getAttr('creator_id') ?? 0);
|
||||
$rxId = (int) ($order->getAttr('prescription_id') ?? 0);
|
||||
$rxCreator = 0;
|
||||
if ($rxId > 0) {
|
||||
$rxCreator = (int) Prescription::where('id', $rxId)->whereNull('delete_time')->value('creator_id');
|
||||
}
|
||||
|
||||
// 诊单 assistant_id 与列表「医助」筛选一致:医助常代建单但诊单未写 assistant_id,此时用创建人作为待释放身份(创建人即开方医生时不采用,避免误记指派日志)
|
||||
$fromAssistantId = (int) ($diag->getAttr('assistant_id') ?? 0);
|
||||
if ($fromAssistantId <= 0) {
|
||||
$creatorId = (int) ($order->getAttr('creator_id') ?? 0);
|
||||
if ($creatorId > 0) {
|
||||
$rxId = (int) ($order->getAttr('prescription_id') ?? 0);
|
||||
$rxCreator = 0;
|
||||
if ($rxId > 0) {
|
||||
$rxCreator = (int) Prescription::where('id', $rxId)->whereNull('delete_time')->value('creator_id');
|
||||
}
|
||||
if ($rxId <= 0 || $creatorId !== $rxCreator) {
|
||||
$fromAssistantId = $creatorId;
|
||||
}
|
||||
if ($poCreatorId > 0 && ($rxId <= 0 || $poCreatorId !== $rxCreator)) {
|
||||
$fromAssistantId = $poCreatorId;
|
||||
}
|
||||
}
|
||||
if ($fromAssistantId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (self::currentAssistantBelongsToErzhongxinDeptTree($fromAssistantId)) {
|
||||
Log::info('Skipped auto assistant release (shipped/signed): assistant under 二中心 dept tree', [
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'prescription_order_id' => $orderId,
|
||||
'source' => $source,
|
||||
'current_assistant_id' => $fromAssistantId,
|
||||
/** 是否因「二中心」跳过释放:优先看业务订单创建人 creator_id(代建场景);创建人即开方医生时用 fromAssistantId */
|
||||
$erZhongxinCheckAdminId = ($poCreatorId > 0 && ($rxId <= 0 || $poCreatorId !== $rxCreator))
|
||||
? $poCreatorId
|
||||
: $fromAssistantId;
|
||||
|
||||
if ($erZhongxinCheckAdminId > 0 && self::currentAssistantBelongsToErzhongxinDeptTree($erZhongxinCheckAdminId)) {
|
||||
Log::info('Skipped auto assistant release (shipped/signed): order creator (or fallback from-id) under 二中心 dept tree', [
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'prescription_order_id' => $orderId,
|
||||
'source' => $source,
|
||||
'er_zhongxin_check_admin_id' => $erZhongxinCheckAdminId,
|
||||
'prescription_order_creator_id' => $poCreatorId,
|
||||
'from_assistant_id_for_log' => $fromAssistantId,
|
||||
]);
|
||||
|
||||
return null;
|
||||
@@ -440,6 +459,39 @@ class ExpressTrackingService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 若诊单曾被后台人工指派到具体医助,则不再执行发运/签收自动清空(避免「系统·已发货履约核对」覆盖人工链)。
|
||||
* 判定:operator_admin_id>0 且 to_assistant_id>0(人工);系统写入的释放/同步为 operator_admin_id=0。
|
||||
* 另保留 related_po_creator_id=from_assistant_id 且 to>0 的窄条件,兼容早期数据。
|
||||
*/
|
||||
private static function diagnosisShouldSkipAutoAssistantReleaseDueToManualAssignLog(int $diagnosisId): bool
|
||||
{
|
||||
if ($diagnosisId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tbl = 'tcm_diagnosis_assign_log';
|
||||
|
||||
$humanReassign = (int) Db::name($tbl)
|
||||
->where('diagnosis_id', $diagnosisId)
|
||||
->where('to_assistant_id', '>', 0)
|
||||
->where('operator_admin_id', '>', 0)
|
||||
->count();
|
||||
if ($humanReassign > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$snapshotTied = (int) Db::name($tbl)
|
||||
->where('diagnosis_id', $diagnosisId)
|
||||
->where('to_assistant_id', '>', 0)
|
||||
->where('from_assistant_id', '>', 0)
|
||||
->where('related_po_creator_id', '>', 0)
|
||||
->whereRaw('`related_po_creator_id` = `from_assistant_id`')
|
||||
->count();
|
||||
|
||||
return $snapshotTied > 0;
|
||||
}
|
||||
|
||||
private static function maybeClearDiagnosisAssistantWhenShippedPrescription(ExpressTracking $tracking): ?array
|
||||
{
|
||||
if ((string) $tracking->order_type !== 'prescription') {
|
||||
@@ -619,7 +671,7 @@ class ExpressTrackingService
|
||||
|
||||
/**
|
||||
* 按处方订单履约核对:已发货(5)/已签收(6) 时符合条件的订单调用 applyAssistantReleaseForShippedPrescriptionOrder。
|
||||
* 与快递 100 / 甘草来自哪个物流渠道无关;是否清空医助以该方法为准(仅二中心不释放;已 shipped 释放且 assistant_id=0 视为已处理)。
|
||||
* 与快递 100 / 甘草来自哪个物流渠道无关;是否清空医助以该方法为准(**二中心豁免看业务单创建人**参见 apply;已 shipped 释放且 assistant_id=0 视为已处理)。
|
||||
*
|
||||
* @return array{scanned: int, cleared: int, lines: list<string>}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user