You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class BlockService
|
|
{
|
|
/**
|
|
* 检查患者是否允许在指定渠道预约
|
|
*
|
|
* @param int $channelId 渠道ID (channel表的id)
|
|
* @param string $patientIdCardNo 患者身份证号
|
|
* @return array ['status'=>bool, 'msg'=>string]
|
|
*/
|
|
public function checkAppointmentPermission($channelId, $patientIdCardNo)
|
|
{
|
|
// 1. 检查黑名单功能是否启用
|
|
$config = DB::table('sys_config')
|
|
->where('config_key', 'block_list_config')
|
|
->where('deleted', 0)
|
|
->where('status', 1)
|
|
->first();
|
|
|
|
// 如果功能未启用,直接返回允许
|
|
if (!$config) {
|
|
return ['status' => true, 'msg' => ''];
|
|
}
|
|
|
|
// 2. 查询患者的生效中黑名单记录
|
|
$blockList = DB::table('blocklist')
|
|
->where('patient_id_card_no', $patientIdCardNo)
|
|
->where('status', 1)
|
|
->where('deleted', 0)
|
|
->where(function ($query) {
|
|
$query->whereNull('end_time')
|
|
->orWhere('end_time', '>', date('Y-m-d H:i:s'));
|
|
})
|
|
->get();
|
|
|
|
// 如果没有生效中的黑名单记录,允许预约
|
|
if ($blockList->isEmpty()) {
|
|
return ['status' => true, 'msg' => ''];
|
|
}
|
|
|
|
// 3. 解析黑名单配置
|
|
$configValue = json_decode($config->config_value, true);
|
|
|
|
if (!is_array($configValue) || empty($configValue)) {
|
|
// 配置为空,不限制
|
|
return ['status' => true, 'msg' => ''];
|
|
}
|
|
|
|
// 4. 检查每个黑名单类型的渠道限制
|
|
$blockedTypes = [];
|
|
foreach ($blockList as $block) {
|
|
$blockType = $block->block_type;
|
|
|
|
// 查找该黑名单类型的配置
|
|
$typeConfig = null;
|
|
foreach ($configValue as $item) {
|
|
if (isset($item['type']) && $item['type'] == $blockType) {
|
|
$typeConfig = $item;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 如果该类型有配置且包含当前渠道,则被限制
|
|
if ($typeConfig && isset($typeConfig['disabled_channel']) && is_array($typeConfig['disabled_channel'])) {
|
|
if (in_array((string)$channelId, $typeConfig['disabled_channel'])) {
|
|
$blockedTypes[] = $blockType;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 如果有任何类型限制了该渠道,返回不允许
|
|
if (!empty($blockedTypes)) {
|
|
return ['status' => false, 'msg' => '患者被限制在该渠道预约'];
|
|
}
|
|
|
|
// 所有类型都没有限制该渠道,允许预约
|
|
return ['status' => true, 'msg' => ''];
|
|
}
|
|
}
|