更新
This commit is contained in:
@@ -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