更新
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 诊单列表维度:记录谁在后台发起挂号 / 取消挂号(写入失败不影响主流程)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user