作者 王智

修改

@@ -373,13 +373,31 @@ class Question extends Api @@ -373,13 +373,31 @@ class Question extends Api
373 } 373 }
374 } 374 }
375 foreach ($DayArray as $k => $v) { 375 foreach ($DayArray as $k => $v) {
376 - $Day[$k]['date'] = $v[0]['date'];  
377 $Day[$k]['V'] = round((array_sum(array_column($v, 'V'))) / count($v), 1); 376 $Day[$k]['V'] = round((array_sum(array_column($v, 'V'))) / count($v), 1);
378 $Day[$k]['P'] = round((array_sum(array_column($v, 'P'))) / count($v), 1); 377 $Day[$k]['P'] = round((array_sum(array_column($v, 'P'))) / count($v), 1);
379 $Day[$k]['K'] = round((array_sum(array_column($v, 'K'))) / count($v), 1); 378 $Day[$k]['K'] = round((array_sum(array_column($v, 'K'))) / count($v), 1);
380 - 379 + }
  380 + //月
  381 + foreach ($DateMonth as $k => $v) {
  382 + //指定月起止时间戳
  383 + $StarTime = strtotime($v['date']);
  384 + $EndTime = mktime(23, 59, 59, date('m', strtotime($v['date']))+1, 00);//指定月份月末时间戳
  385 + $map['createtime'] = ['between', [$StarTime, $EndTime]];
  386 + $List = Db::name('sleep')->where('user_id', $UserId)->where('type', 1)->where($map)->select();
  387 + foreach ($List as $key => $value) {
  388 + $MonthArray[$k][$key]['date'] = date('Y-m', $value['createtime']);
  389 + $MonthArray[$k][$key]['V'] = $value['v'];
  390 + $MonthArray[$k][$key]['P'] = $value['p'];
  391 + $MonthArray[$k][$key]['K'] = $value['k'];
  392 + }
  393 + }
  394 + foreach ($MonthArray as $k => $v) {
  395 + $Month[$k]['V'] = round((array_sum(array_column($v, 'V'))) / count($v), 1);
  396 + $Month[$k]['P'] = round((array_sum(array_column($v, 'P'))) / count($v), 1);
  397 + $Month[$k]['K'] = round((array_sum(array_column($v, 'K'))) / count($v), 1);
381 } 398 }
382 dump($Day); 399 dump($Day);
  400 + dump($Month;
383 } else { 401 } else {
384 $Day = []; 402 $Day = [];
385 $Month = []; 403 $Month = [];