更新
This commit is contained in:
@@ -623,7 +623,42 @@ class TcmController extends BaseApiController
|
||||
];
|
||||
|
||||
if ($existing) {
|
||||
$payload['id'] = $existing['id'];
|
||||
// 分表单项更新时保留未提交字段,避免血糖/血压互相覆盖
|
||||
$keepDecimal = function ($new, string $oldKey) use ($parseDecimal, $existing) {
|
||||
if ($new !== null) {
|
||||
return $new;
|
||||
}
|
||||
return $parseDecimal($existing[$oldKey] ?? null);
|
||||
};
|
||||
$keepInt = function ($new, string $oldKey) use ($parseInt, $existing) {
|
||||
if ($new !== null) {
|
||||
return $new;
|
||||
}
|
||||
return $parseInt($existing[$oldKey] ?? null);
|
||||
};
|
||||
$fasting = $keepDecimal($fasting, 'fasting_blood_sugar');
|
||||
$postprandial = $keepDecimal($postprandial, 'postprandial_blood_sugar');
|
||||
$other = $keepDecimal($other, 'other_blood_sugar');
|
||||
$systolic = $keepInt($systolic, 'systolic_pressure');
|
||||
$diastolic = $keepInt($diastolic, 'diastolic_pressure');
|
||||
if ($remark === '') {
|
||||
$remark = trim((string) ($existing['remark'] ?? ''));
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'diagnosis_id' => $diagnosisId,
|
||||
'patient_id' => (int) $diagnosis['patient_id'],
|
||||
'record_date' => $todayStart,
|
||||
'record_time' => date('H:i'),
|
||||
'fasting_blood_sugar' => $fasting,
|
||||
'postprandial_blood_sugar' => $postprandial,
|
||||
'other_blood_sugar' => $other,
|
||||
'systolic_pressure' => $systolic,
|
||||
'diastolic_pressure' => $diastolic,
|
||||
'remark' => $remark,
|
||||
'source' => 1,
|
||||
'id' => $existing['id'],
|
||||
];
|
||||
BloodRecord::update($payload);
|
||||
return $this->success('已更新今日记录', ['id' => $existing['id']]);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,10 @@ class DailyGamifyLogic
|
||||
|
||||
/** @var array<string,array{name:string,points:int}> */
|
||||
protected static array $taskDefs = [
|
||||
'blood' => ['name' => '测血糖血压', 'points' => 10],
|
||||
'diet' => ['name' => '记今日饮食', 'points' => 10],
|
||||
'exercise' => ['name' => '记今日运动', 'points' => 10],
|
||||
'glucose' => ['name' => '测血糖', 'points' => 10],
|
||||
'bp' => ['name' => '测血压', 'points' => 10],
|
||||
'diet' => ['name' => '饮食', 'points' => 10],
|
||||
'exercise' => ['name' => '运动', 'points' => 10],
|
||||
];
|
||||
|
||||
public static function getError(): string
|
||||
@@ -83,12 +84,13 @@ class DailyGamifyLogic
|
||||
->where('record_date', '<=', $end)
|
||||
->find();
|
||||
|
||||
$bloodDone = false;
|
||||
$glucoseDone = false;
|
||||
$bpDone = false;
|
||||
if ($blood) {
|
||||
$bloodDone = self::hasValue($blood['fasting_blood_sugar'] ?? null)
|
||||
$glucoseDone = self::hasValue($blood['fasting_blood_sugar'] ?? null)
|
||||
|| self::hasValue($blood['postprandial_blood_sugar'] ?? null)
|
||||
|| self::hasValue($blood['other_blood_sugar'] ?? null)
|
||||
|| self::hasValue($blood['systolic_pressure'] ?? null)
|
||||
|| self::hasValue($blood['other_blood_sugar'] ?? null);
|
||||
$bpDone = self::hasValue($blood['systolic_pressure'] ?? null)
|
||||
|| self::hasValue($blood['diastolic_pressure'] ?? null);
|
||||
}
|
||||
|
||||
@@ -118,7 +120,8 @@ class DailyGamifyLogic
|
||||
}
|
||||
|
||||
return [
|
||||
'blood' => $bloodDone,
|
||||
'glucose' => $glucoseDone,
|
||||
'bp' => $bpDone,
|
||||
'diet' => $dietDone,
|
||||
'exercise' => $exerciseDone,
|
||||
];
|
||||
@@ -141,13 +144,36 @@ class DailyGamifyLogic
|
||||
'name' => $def['name'],
|
||||
'points' => $def['points'],
|
||||
'completed' => !empty($completion[$id]),
|
||||
'claimed' => !empty($awards[$id]),
|
||||
'claimed' => self::isTaskClaimed($id, $awards, $completion),
|
||||
];
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务是否已领取(兼容旧版 blood 合并任务)
|
||||
*
|
||||
* @param array<string,bool> $awards
|
||||
* @param array<string,bool> $completion
|
||||
*/
|
||||
protected static function isTaskClaimed(string $id, array $awards, array $completion = []): bool
|
||||
{
|
||||
if (!empty($awards[$id])) {
|
||||
return true;
|
||||
}
|
||||
// 旧版 blood 一次性领取:对应分项当日已有记录则视为已领,避免拆分后重复领奖/轮换引导
|
||||
if (!empty($awards['blood'])) {
|
||||
if ($id === 'glucose' && !empty($completion['glucose'])) {
|
||||
return true;
|
||||
}
|
||||
if ($id === 'bp' && !empty($completion['bp'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 与前端 tongji/utils/treeLevels.js 保持一致 */
|
||||
protected const TREE_MAX_LEVEL = 9;
|
||||
protected const TREE_XP_PER_LEVEL = 50;
|
||||
|
||||
Reference in New Issue
Block a user