更新
This commit is contained in:
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\adminapi\logic\dept\DeptLogic;
|
||||
use app\common\model\auth\AdminDept;
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\model\ExpressTracking;
|
||||
use app\common\model\ExpressTrace;
|
||||
use app\common\model\ExpressStateLog;
|
||||
@@ -246,6 +249,7 @@ class ExpressTrackingService
|
||||
* 处方业务订单履约「已发货(5) / 已签收(6)」时:清空关联诊单(患者)医助,并写入 tcm_diagnosis_assign_log。
|
||||
* 快递 100 定时拉轨迹、甘草路由、甘草回调与履约核对共用同一规则。
|
||||
* 例外:指派日志中若存在「从某医助改派到另一医助」(原、新医助 ID 均大于 0)的记录,视为人工指派链,自动释放跳过。
|
||||
* 例外:患者当前医助在「二中心」及其全部子部门(与后台部门树一致)下任职时,不自动清空医助(按 admin_dept 与 dept 树判定)。
|
||||
*
|
||||
* @param array{tracking_id?:int,tracking_number?:string,source?:string} $meta
|
||||
* @return array{
|
||||
@@ -300,6 +304,17 @@ class ExpressTrackingService
|
||||
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,
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$operatorName = match ($source) {
|
||||
'express_auto_update' => '系统·物流自动同步',
|
||||
'gancao_route', 'gancao_route_sync' => '系统·甘草路由同步',
|
||||
@@ -358,6 +373,54 @@ class ExpressTrackingService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门名称为「二中心」的根节点 id(启用、未删除的首条),无则 0。
|
||||
* 与后台 adminapi 部门数据源一致(表 zyt_dept,树由 pid 构成)。
|
||||
*/
|
||||
private static function getErzhongxinRootDeptId(): int
|
||||
{
|
||||
static $cached = null;
|
||||
if ($cached !== null) {
|
||||
return $cached;
|
||||
}
|
||||
$id = (int) Dept::where('name', '二中心')
|
||||
->where('status', 1)
|
||||
->whereNull('delete_time')
|
||||
->order('id', 'asc')
|
||||
->value('id');
|
||||
$cached = $id > 0 ? $id : 0;
|
||||
|
||||
return $cached;
|
||||
}
|
||||
|
||||
/**
|
||||
* 诊单当前医助(管理员)是否归属「二中心」或其任意下级部门(admin_dept.dept_id 落在该子树内)。
|
||||
* 与 DeptLogic::getSelfAndDescendantIds 行为对齐于部门列表接口的树展开。
|
||||
*/
|
||||
private static function currentAssistantBelongsToErzhongxinDeptTree(int $assistantAdminId): bool
|
||||
{
|
||||
if ($assistantAdminId <= 0) {
|
||||
return false;
|
||||
}
|
||||
$rootId = self::getErzhongxinRootDeptId();
|
||||
if ($rootId <= 0) {
|
||||
return false;
|
||||
}
|
||||
$treeIds = DeptLogic::getSelfAndDescendantIds($rootId);
|
||||
if ($treeIds === []) {
|
||||
return false;
|
||||
}
|
||||
$allowed = array_flip(array_map('intval', $treeIds));
|
||||
$deptIds = AdminDept::where('admin_id', $assistantAdminId)->column('dept_id');
|
||||
foreach ($deptIds as $did) {
|
||||
if (isset($allowed[(int) $did])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在「由原医助改派到新医助」的指派记录(两端 admin 均大于 0)。有此记录则已发货自动释放医助不执行。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user