更新
This commit is contained in:
@@ -19,6 +19,7 @@ use app\adminapi\logic\dept\DeptLogic;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\BloodRecord;
|
||||
use app\common\model\DiagnosisViewRecord;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\doctor\Appointment;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\tcm\CallRecord;
|
||||
@@ -130,6 +131,8 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status = 3");
|
||||
}
|
||||
|
||||
$this->applyPendingAssignBusinessOrderMonthFilter($query);
|
||||
|
||||
// 仅已开方(有处方)的诊单:随访列表传 only_has_prescription=1;问诊等页面不传则不过滤
|
||||
if (isset($this->params['only_has_prescription']) && (string) $this->params['only_has_prescription'] === '1') {
|
||||
$rxTbl = (new Prescription())->getTable();
|
||||
@@ -541,7 +544,49 @@ class DiagnosisLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$aptTbl} apt WHERE apt.patient_id = {$diagTbl}.id AND apt.status = 3");
|
||||
}
|
||||
|
||||
$this->applyPendingAssignBusinessOrderMonthFilter($query);
|
||||
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 「待分配医助」Tab:按月份筛选——诊单在指定自然月内需存在业务订单(order.patient_id = 诊单 id)
|
||||
* create_time 兼容整型时间戳与 datetime 字符串
|
||||
*/
|
||||
private function applyPendingAssignBusinessOrderMonthFilter($query): void
|
||||
{
|
||||
$pendingAssign = isset($this->params['pending_assign']) && (string) $this->params['pending_assign'] === '1';
|
||||
if (!$pendingAssign || empty($this->params['pending_assign_order_month'])) {
|
||||
return;
|
||||
}
|
||||
$month = trim((string) $this->params['pending_assign_order_month']);
|
||||
if (!preg_match('/^(\d{4})-(\d{2})$/', $month, $m)) {
|
||||
return;
|
||||
}
|
||||
$y = (int) $m[1];
|
||||
$mo = (int) $m[2];
|
||||
if ($y < 1970 || $y > 2100 || $mo < 1 || $mo > 12) {
|
||||
return;
|
||||
}
|
||||
$tStart = strtotime(sprintf('%04d-%02d-01 00:00:00', $y, $mo));
|
||||
if ($tStart === false) {
|
||||
return;
|
||||
}
|
||||
$tEnd = strtotime(date('Y-m-t 23:59:59', $tStart));
|
||||
if ($tEnd === false) {
|
||||
return;
|
||||
}
|
||||
$dsStart = date('Y-m-d H:i:s', $tStart);
|
||||
$dsEnd = date('Y-m-d H:i:s', $tEnd);
|
||||
|
||||
$orderTbl = (new Order())->getTable();
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$sql = "SELECT 1 FROM `{$orderTbl}` o WHERE o.patient_id = {$diagTbl}.id "
|
||||
. 'AND o.delete_time IS NULL AND ('
|
||||
. "(o.create_time >= {$tStart} AND o.create_time <= {$tEnd}) OR "
|
||||
. "(o.create_time >= '{$dsStart}' AND o.create_time <= '{$dsEnd}')"
|
||||
. ')';
|
||||
$query->whereExists($sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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