更新初级版本
This commit is contained in:
@@ -1048,4 +1048,153 @@ class DiagnosisLogic extends BaseLogic
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取诊单详情并记录查看
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
*/
|
||||
public static function diagnosisDetailWithRecord(array $params)
|
||||
{
|
||||
try {
|
||||
$diagnosisId = $params['id'];
|
||||
$userId = $params['user_id'] ?? 0;
|
||||
$shareUserId = $params['share_user_id'] ?? 0;
|
||||
|
||||
// 获取诊单详情
|
||||
$diagnosis = self::detail(['id' => $diagnosisId]);
|
||||
|
||||
if (!$diagnosis) {
|
||||
throw new \Exception('诊单不存在');
|
||||
}
|
||||
|
||||
// 记录查看行为
|
||||
self::recordDiagnosisView([
|
||||
'user_id' => $userId,
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'patient_id' => $diagnosis['patient_id'] ?? 0,
|
||||
'share_user_id' => $shareUserId
|
||||
]);
|
||||
|
||||
return $diagnosis;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 记录诊单查看
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
private static function recordDiagnosisView(array $params)
|
||||
{
|
||||
try {
|
||||
$userId = $params['user_id'];
|
||||
$diagnosisId = $params['diagnosis_id'];
|
||||
$patientId = $params['patient_id'];
|
||||
$shareUserId = $params['share_user_id'];
|
||||
|
||||
// 查找是否已有记录
|
||||
$record = \app\common\model\DiagnosisViewRecord::where([
|
||||
'user_id' => $userId,
|
||||
'diagnosis_id' => $diagnosisId
|
||||
])->find();
|
||||
|
||||
$now = time();
|
||||
|
||||
if ($record) {
|
||||
// 更新记录
|
||||
$record->view_count = $record->view_count + 1;
|
||||
$record->last_view_time = $now;
|
||||
$record->update_time = $now;
|
||||
$record->save();
|
||||
} else {
|
||||
// 创建新记录
|
||||
\app\common\model\DiagnosisViewRecord::create([
|
||||
'user_id' => $userId,
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'patient_id' => $patientId,
|
||||
'share_user_id' => $shareUserId,
|
||||
'view_count' => 1,
|
||||
'first_view_time' => $now,
|
||||
'last_view_time' => $now,
|
||||
'is_confirmed' => 0,
|
||||
'create_time' => $now,
|
||||
'update_time' => $now
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
\think\facade\Log::error('记录诊单查看失败: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 确认诊单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
public static function confirmDiagnosisRecord(array $params)
|
||||
{
|
||||
try {
|
||||
$userId = $params['user_id'] ?? 0;
|
||||
$diagnosisId = $params['id'];
|
||||
$shareUserId = $params['share_user_id'] ?? 0;
|
||||
if(!$userId){
|
||||
throw new \Exception('请重新登录!');
|
||||
}
|
||||
// 查找查看记录
|
||||
$record = \app\common\model\DiagnosisViewRecord::where([
|
||||
'user_id' => $userId,
|
||||
'diagnosis_id' => $diagnosisId
|
||||
])->find();
|
||||
|
||||
$now = time();
|
||||
|
||||
if ($record) {
|
||||
// 更新确认状态
|
||||
$record->is_confirmed = 1;
|
||||
$record->confirmed_time = $now;
|
||||
$record->update_time = $now;
|
||||
$record->save();
|
||||
} else {
|
||||
// 如果没有查看记录,创建一条已确认的记录
|
||||
$diagnosis = Diagnosis::find($diagnosisId);
|
||||
if (!$diagnosis) {
|
||||
throw new \Exception('诊单不存在');
|
||||
}
|
||||
|
||||
// 再次检查是否存在记录,防止并发创建重复记录
|
||||
$existingRecord = \app\common\model\DiagnosisViewRecord::where([
|
||||
'user_id' => $userId,
|
||||
'diagnosis_id' => $diagnosisId
|
||||
])->find();
|
||||
|
||||
if (!$existingRecord) {
|
||||
\app\common\model\DiagnosisViewRecord::create([
|
||||
'user_id' => $userId,
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'patient_id' => $diagnosis->patient_id ?? 0,
|
||||
'share_user_id' => $shareUserId,
|
||||
'view_count' => 1,
|
||||
'first_view_time' => $now,
|
||||
'last_view_time' => $now,
|
||||
'is_confirmed' => 1,
|
||||
'confirmed_time' => $now,
|
||||
'create_time' => $now,
|
||||
'update_time' => $now
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user