更新
This commit is contained in:
@@ -13,6 +13,7 @@ use app\common\model\ExpressStateLog;
|
||||
use app\common\model\ExpressQueryLog;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\DiagnosisAssignLog;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderLog;
|
||||
use think\facade\Db;
|
||||
@@ -250,6 +251,7 @@ class ExpressTrackingService
|
||||
* 快递 100 定时拉轨迹、甘草路由、甘草回调与履约核对共用同一规则。
|
||||
* 例外:指派日志中若存在「从某医助改派到另一医助」(原、新医助 ID 均大于 0)的记录,视为人工指派链,自动释放跳过。
|
||||
* 例外:患者当前医助在「二中心」及其全部子部门(与后台部门树一致)下任职时,不自动清空医助(按 admin_dept 与 dept 树判定)。
|
||||
* 非二中心且已自动释放:诊单写入 shipped_non_er_assistant_cleared_at,assistant_id 已为 0 时后续履约核对不再重复扫描(重新指派医助后可再次处理)。
|
||||
*
|
||||
* @param array{tracking_id?:int,tracking_number?:string,source?:string} $meta
|
||||
* @return array{
|
||||
@@ -288,7 +290,26 @@ class ExpressTrackingService
|
||||
if (!$diag) {
|
||||
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;
|
||||
}
|
||||
// 诊单 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 ($fromAssistantId <= 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -328,7 +349,10 @@ class ExpressTrackingService
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
Diagnosis::where('id', $diagnosisId)->whereNull('delete_time')->update(['assistant_id' => 0]);
|
||||
Diagnosis::where('id', $diagnosisId)->whereNull('delete_time')->update([
|
||||
'assistant_id' => 0,
|
||||
'shipped_non_er_assistant_cleared_at' => time(),
|
||||
]);
|
||||
|
||||
DiagnosisAssignLog::create([
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
@@ -624,19 +648,29 @@ class ExpressTrackingService
|
||||
/**
|
||||
* 按处方订单履约核对:已发货(5)/已签收(6) 时诊单仍挂在医助的,一律释放并写指派日志。
|
||||
* 与快递 100 / 甘草来自哪个物流渠道无关,保障「已发货」后患者侧医助被清掉。
|
||||
* 已对非二中心医助做过发货/签收释放且 assistant_id=0 的诊单(shipped_non_er_assistant_cleared_at>0)不再纳入本扫描,避免重复命中 creator 分支。
|
||||
*
|
||||
* @return array{scanned: int, cleared: int, lines: list<string>}
|
||||
*/
|
||||
public static function reconcileAssistantReleaseForShippedPrescriptionOrders(int $limit = 200): array
|
||||
{
|
||||
$dTable = (new Diagnosis())->getTable();
|
||||
$rxTable = (new Prescription())->getTable();
|
||||
$orders = PrescriptionOrder::alias('po')
|
||||
->join($dTable . ' d', 'd.id = po.diagnosis_id')
|
||||
->leftJoin($rxTable . ' rx', 'rx.id = po.prescription_id AND rx.delete_time IS NULL')
|
||||
->whereNull('po.delete_time')
|
||||
->whereNull('d.delete_time')
|
||||
->whereRaw('(IFNULL(d.shipped_non_er_assistant_cleared_at, 0) = 0 OR d.assistant_id > 0)')
|
||||
->whereIn('po.fulfillment_status', [5, 6])
|
||||
->where('po.diagnosis_id', '>', 0)
|
||||
->where('d.assistant_id', '>', 0)
|
||||
->where(function ($w) {
|
||||
$w->where('d.assistant_id', '>', 0)
|
||||
->whereOr(function ($w2) {
|
||||
$w2->where('po.creator_id', '>', 0)
|
||||
->whereRaw('(rx.id IS NULL OR po.creator_id <> rx.creator_id)');
|
||||
});
|
||||
})
|
||||
->order('po.id', 'asc')
|
||||
->limit($limit)
|
||||
->field('po.*')
|
||||
|
||||
Reference in New Issue
Block a user