作者 王智

修改

... ... @@ -373,13 +373,31 @@ class Question extends Api
}
}
foreach ($DayArray as $k => $v) {
$Day[$k]['date'] = $v[0]['date'];
$Day[$k]['V'] = round((array_sum(array_column($v, 'V'))) / count($v), 1);
$Day[$k]['P'] = round((array_sum(array_column($v, 'P'))) / count($v), 1);
$Day[$k]['K'] = round((array_sum(array_column($v, 'K'))) / count($v), 1);
}
//月
foreach ($DateMonth as $k => $v) {
//指定月起止时间戳
$StarTime = strtotime($v['date']);
$EndTime = mktime(23, 59, 59, date('m', strtotime($v['date']))+1, 00);//指定月份月末时间戳
$map['createtime'] = ['between', [$StarTime, $EndTime]];
$List = Db::name('sleep')->where('user_id', $UserId)->where('type', 1)->where($map)->select();
foreach ($List as $key => $value) {
$MonthArray[$k][$key]['date'] = date('Y-m', $value['createtime']);
$MonthArray[$k][$key]['V'] = $value['v'];
$MonthArray[$k][$key]['P'] = $value['p'];
$MonthArray[$k][$key]['K'] = $value['k'];
}
}
foreach ($MonthArray as $k => $v) {
$Month[$k]['V'] = round((array_sum(array_column($v, 'V'))) / count($v), 1);
$Month[$k]['P'] = round((array_sum(array_column($v, 'P'))) / count($v), 1);
$Month[$k]['K'] = round((array_sum(array_column($v, 'K'))) / count($v), 1);
}
dump($Day);
dump($Month;
} else {
$Day = [];
$Month = [];
... ...