更新
This commit is contained in:
@@ -82,6 +82,22 @@ class AppointmentController extends BaseAdminController
|
||||
return $this->success('保存成功');
|
||||
}
|
||||
|
||||
/** 批量修改挂号渠道来源(消费者处方-挂号列表) */
|
||||
public function batchEditChannel()
|
||||
{
|
||||
$params = (new AppointmentValidate())->post()->goCheck('batchEditChannel');
|
||||
$post = $this->request->post();
|
||||
if (\array_key_exists('channel_source_detail', $post)) {
|
||||
$params['channel_source_detail'] = $post['channel_source_detail'];
|
||||
}
|
||||
$result = AppointmentLogic::adminBatchEditChannel($params, $this->adminId, $this->adminInfo);
|
||||
if ($result === false) {
|
||||
return $this->fail(AppointmentLogic::getError());
|
||||
}
|
||||
|
||||
return $this->success((string) ($result['msg'] ?? '操作成功'), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 预约详情
|
||||
* @return \think\response\Json
|
||||
|
||||
@@ -126,6 +126,12 @@ class AuthMiddleware
|
||||
return true;
|
||||
}
|
||||
|
||||
// 挂号列表批量改渠道:与单条编辑同一数据域,复用 doctor.appointment/edit
|
||||
if ($accessUri === 'doctor.appointment/batcheditchannel'
|
||||
&& in_array('doctor.appointment/edit', $adminUris, true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use app\common\model\dict\DictData;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\lists\Traits\HasDataScopeFilter;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 医生预约列表
|
||||
@@ -74,6 +75,46 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 渠道筛选:与 AppointmentLogic 一致,兼容仅有 channel_source、仅有 channels、或两者皆有的表结构
|
||||
*
|
||||
* @param mixed $query
|
||||
*/
|
||||
private function applyChannelSourceFilter($query, string $chFilter): void
|
||||
{
|
||||
if ($chFilter === '') {
|
||||
return;
|
||||
}
|
||||
$tblFields = Db::name('doctor_appointment')->getTableFields();
|
||||
$cols = \is_array($tblFields) ? $tblFields : [];
|
||||
$hasChannelSource = \in_array('channel_source', $cols, true);
|
||||
$hasChannels = \in_array('channels', $cols, true);
|
||||
if (!$hasChannelSource && !$hasChannels) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where(function ($q) use ($chFilter, $hasChannelSource, $hasChannels): void {
|
||||
if ($hasChannelSource && $hasChannels) {
|
||||
$q->where('a.channel_source', '=', $chFilter)
|
||||
->whereOr('a.channels', '=', $chFilter);
|
||||
if (is_numeric($chFilter)) {
|
||||
$q->whereOr('a.channels', '=', (int) $chFilter);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if ($hasChannelSource) {
|
||||
$q->where('a.channel_source', '=', $chFilter);
|
||||
|
||||
return;
|
||||
}
|
||||
$q->where('a.channels', '=', $chFilter);
|
||||
if (is_numeric($chFilter)) {
|
||||
$q->whereOr('a.channels', '=', (int) $chFilter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return array
|
||||
@@ -107,6 +148,9 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
$this->searchWhere[] = ['a.status', '=', $this->params['status']];
|
||||
}
|
||||
|
||||
// 渠道字典 value(命中 channel_source 或 legacy channels)
|
||||
$chFilter = isset($this->params['channel_source']) ? trim((string) $this->params['channel_source']) : '';
|
||||
|
||||
// 处理日期范围搜索
|
||||
if (!empty($this->params['start_date']) && !empty($this->params['end_date'])) {
|
||||
$this->searchWhere[] = ['a.appointment_date', 'between', [$this->params['start_date'], $this->params['end_date']]];
|
||||
@@ -147,6 +191,8 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
|
||||
$this->applyAssistantIdFilter($query);
|
||||
|
||||
$this->applyChannelSourceFilter($query, $chFilter);
|
||||
|
||||
// 是否确认诊单:1=已确认 0=未确认
|
||||
if (isset($this->params['diagnosis_confirmed']) && $this->params['diagnosis_confirmed'] !== '') {
|
||||
$confirmed = (int)$this->params['diagnosis_confirmed'];
|
||||
@@ -308,6 +354,7 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
if ($applyStatusFilter && isset($this->params['status']) && $this->params['status'] !== '') {
|
||||
$query->where('a.status', '=', $this->params['status']);
|
||||
}
|
||||
$chFilter = isset($this->params['channel_source']) ? trim((string) $this->params['channel_source']) : '';
|
||||
if (!empty($this->params['start_date']) && !empty($this->params['end_date'])) {
|
||||
$query->whereBetween('a.appointment_date', [$this->params['start_date'], $this->params['end_date']]);
|
||||
} elseif (!empty($this->params['start_date'])) {
|
||||
@@ -326,6 +373,8 @@ class AppointmentLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
|
||||
$this->applyAssistantIdFilter($query);
|
||||
|
||||
$this->applyChannelSourceFilter($query, $chFilter);
|
||||
|
||||
if ((int) ($this->params['exclude_cancelled'] ?? 0) === 1) {
|
||||
$sf = $this->params['status'] ?? '';
|
||||
if ($sf === '' || (int) $sf !== 2) {
|
||||
|
||||
@@ -104,6 +104,7 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$this->applyPatientIdFilter($query);
|
||||
$this->applyExpressCompanyFilter($query);
|
||||
$this->applyExpressKeywordFilter($query);
|
||||
$this->applyServiceChannelFilter($query);
|
||||
$this->applySupplyModeFilter($query);
|
||||
if (!$this->shouldBypassListVisibilityForDiagnosisEdit()) {
|
||||
$this->applyCreatorOrOwnPrescriptionVisibility($query);
|
||||
@@ -200,6 +201,24 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$query->whereRaw("(($po) OR ($et))");
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务渠道:未指派传 service_channel=0 时命中「空串」或「0」(varchar)
|
||||
*/
|
||||
private function applyServiceChannelFilter(Query $query): void
|
||||
{
|
||||
$raw = $this->params['service_channel'] ?? '';
|
||||
if ($raw === '' || $raw === null) {
|
||||
return;
|
||||
}
|
||||
$v = trim((string) $raw);
|
||||
if ($v === '0') {
|
||||
$query->whereRaw("(TRIM(IFNULL(`service_channel`,'')) = '' OR `service_channel` = '0')");
|
||||
|
||||
return;
|
||||
}
|
||||
$query->where('service_channel', '=', $v);
|
||||
}
|
||||
|
||||
/**
|
||||
* 供货方式:甘草(已上传甘草药方单号)/ 自营(无甘草单号,走药房直发等)
|
||||
*
|
||||
|
||||
@@ -1106,6 +1106,130 @@ class AppointmentLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台批量修改挂号渠道(仅渠道号与可选补充)
|
||||
*
|
||||
* @param array<string, mixed> $params
|
||||
* @return array{updated:int}|false
|
||||
*/
|
||||
public static function adminBatchEditChannel(array $params, int $adminId, array $adminInfo)
|
||||
{
|
||||
try {
|
||||
$idsRaw = $params['ids'] ?? [];
|
||||
if (!\is_array($idsRaw) || $idsRaw === []) {
|
||||
self::setError('请选择要修改的挂号记录');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
foreach ($idsRaw as $raw) {
|
||||
$id = (int) $raw;
|
||||
if ($id > 0) {
|
||||
$ids[$id] = $id;
|
||||
}
|
||||
}
|
||||
$ids = array_values($ids);
|
||||
$maxBatch = 300;
|
||||
if (\count($ids) === 0) {
|
||||
self::setError('预约ID无效');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (\count($ids) > $maxBatch) {
|
||||
self::setError('单次最多修改 ' . $maxBatch . ' 条挂号');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$chSrc = trim((string) ($params['channel_source'] ?? ''));
|
||||
if ($chSrc === '') {
|
||||
self::setError('请选择渠道来源');
|
||||
|
||||
return false;
|
||||
}
|
||||
$chDetail = isset($params['channel_source_detail']) ? trim((string) $params['channel_source_detail']) : '';
|
||||
$channelDictName = trim((string) (DictData::where('type_value', 'channels')
|
||||
->where('value', $chSrc)
|
||||
->value('name') ?? ''));
|
||||
if ($channelDictName !== '' && self::channelDictNameRequiresSourceDetail($channelDictName)) {
|
||||
if ($chDetail === '') {
|
||||
self::setError('请填写自媒体渠道补充信息');
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (mb_strlen($chDetail) > 128) {
|
||||
self::setError('渠道补充说明过长');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$tblFields = Db::name('doctor_appointment')->getTableFields();
|
||||
$cols = \is_array($tblFields) ? $tblFields : [];
|
||||
$channelErr = self::assertAppointmentChannelWritable($cols, $chSrc);
|
||||
if ($channelErr !== null) {
|
||||
self::setError($channelErr);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
|
||||
$updated = 0;
|
||||
foreach ($ids as $id) {
|
||||
$appointment = Appointment::findOrEmpty((int) $id);
|
||||
if ($appointment->isEmpty()) {
|
||||
Db::rollback();
|
||||
self::setError('预约记录不存在(ID ' . $id . ')');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$diag = Diagnosis::where('id', (int) $appointment->patient_id)->whereNull('delete_time')->find();
|
||||
|
||||
if (!self::appointmentRowManageableByAdmin($appointment, $diag ?: null, $adminId, $adminInfo)) {
|
||||
Db::rollback();
|
||||
self::setError('无权限修改挂号 #' . $id);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$saveData = [
|
||||
'update_time' => time(),
|
||||
];
|
||||
self::mergeAppointmentChannelIntoRow($saveData, $cols, $chSrc, $chDetail);
|
||||
|
||||
$saveData = self::filterAppointmentRowByExistingColumns($saveData, $cols);
|
||||
|
||||
Db::name('doctor_appointment')->where('id', $id)->update($saveData);
|
||||
|
||||
$patientId = (int) $appointment->patient_id;
|
||||
self::appendDiagnosisGuahaoLog(
|
||||
$patientId,
|
||||
(int) $id,
|
||||
$adminId,
|
||||
$adminInfo,
|
||||
'admin_batch_channel',
|
||||
sprintf('批量修改挂号 #%d:渠道设为 %s', $id, $chSrc !== '' ? $chSrc : '—')
|
||||
);
|
||||
++$updated;
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return [
|
||||
'updated' => $updated,
|
||||
'msg' => sprintf('已更新 %d 条挂号渠道', $updated),
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 诊单列表维度:记录谁在后台发起挂号 / 取消挂号(写入失败不影响主流程)
|
||||
*/
|
||||
|
||||
@@ -28,6 +28,7 @@ class AppointmentValidate extends BaseValidate
|
||||
'remark' => 'max:500',
|
||||
'channel_source' => 'require',
|
||||
'channel_source_detail' => 'max:128',
|
||||
'ids' => 'require|array',
|
||||
'note_id' => 'require|integer',
|
||||
'image_type' => 'require|in:tongue_images,report_files',
|
||||
'image_path' => 'require',
|
||||
@@ -51,6 +52,7 @@ class AppointmentValidate extends BaseValidate
|
||||
'assistant_id' => '医助',
|
||||
'channel_source' => '渠道来源',
|
||||
'channel_source_detail' => '渠道补充说明',
|
||||
'ids' => '预约ID列表',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -148,4 +150,10 @@ class AppointmentValidate extends BaseValidate
|
||||
'channel_source_detail',
|
||||
]);
|
||||
}
|
||||
|
||||
/** 批量修改挂号渠道(权限同 doctor.appointment/edit) */
|
||||
public function sceneBatchEditChannel()
|
||||
{
|
||||
return $this->only(['ids', 'channel_source', 'channel_source_detail']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user