public function yearAction() { $p = $_REQUEST; $pDate = empty($p['date']) ? '' : trim($p['date']); $pOpt = empty($p['opt']) ? 'left' : Tool_Fnc::safe_string($p['opt']); if (!empty($pDate) && !Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tWhere = ''; $tTime = strtotime($pDate); if ($pOpt == 'left') { if (!empty($pDate)) { $tEnd = date('Y-m-d', $tTime - 86400); } else { $tTime = time(); $tEnd = date('Y-m-d'); } $tStart = date('Y-m-d', $tTime - 86400 * 364); } else { if (!empty($pDate)) { $tStart = date('Y-m-d', $tTime + 86400); } else { $tTime = time(); $tStart = date('Y-m-d'); } $tEnd = date('Y-m-d', $tTime + 86400 * 364); } $tTRMO = new BqetreatmentrecordModel(); $tTRDatas = $tTRMO->field('bodyweight_bef,bodyweight_after,treate_date')->where('uid = ' . $this->tUid . ' and treate_date between \'' . $tStart . '\' and \'' . $tEnd . '\'')->order('treate_date asc')->fList(); $tDWLMO = new DryweightlogModel(); $tDWLDatas = $tDWLMO->field('weight,date')->where('uid = ' . $this->tUid . ' and date between \'' . $tStart . '\' and \'' . $tEnd . '\'')->fList(); //最开始日期 $tSql = 'select treate_date from ' . $tTRMO->table . ' where uid = ' . $this->tUid . ' order by treate_date asc limit 1'; $tTRMOList = $tTRMO->query($tSql); #用户最新干体重 $tUMO = new UserModel(); $tURow = $tUMO->field('dry_weight')->where('id = ' . $this->tUid)->fRow(); //如果没有干体重 初始化 $tDatearr = array(); for ($i = 0; $i < 364; $i++) { $tDatearr[] = date('Y-m-d', strtotime($tStart) + 86400 * $i); } $tDWLDate = array(); foreach ($tDWLDatas as $tRow) { $tDWLDate[] = $tRow['date']; } $tDatediff = array_diff($tDatearr, $tDWLDate); $tDiffarr = array(); foreach ($tDatediff as $tDate) { break; #判断该日期之前的干体重 $tDWLRow = $tDWLMO->field('weight')->where('uid = ' . $this->tUid . ' and date < ' . $tDate)->order('date desc')->limit('1')->fRow(); if (count($tDWLRow)) { $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tDWLRow['weight']); continue; } #判断该日期之后临近的干体重 $tDWLRow = $tDWLMO->field('weight')->where('uid = ' . $this->tUid . ' and date > ' . $tDate)->order('date desc')->limit('1')->fRow(); if (count($tDWLRow)) { $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tDWLRow['weight']); continue; } #当前用户干体重 $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tURow['dry_weight']); } #将没有干体重的天入库 foreach ($tDiffarr as $tRow) { break; if ($tDWLMO->in_weight($this->tUid, $tRow['date'])) { continue; } $tData = array('weight' => $tRow['weight'], 'uid' => $this->tUid, 'created' => $tTime, 'date' => $tRow['date'], 'month' => date('Y-m', strtotime($tRow['date'])), 'year' => date('Y-m', strtotime($tRow['date']))); $tDWLMO->insert($tData); } #排除 只要有体重的 干体重╮(╯▽╰)╭ $tTRDate = array(); foreach ($tTRDatas as $tRow) { $tTRDate[] = $tRow['treate_date']; } foreach ($tDWLDatas as $tKey => $tRow) { if (!in_array($tRow['date'], $tTRDate)) { unset($tDWLDatas[$tKey]); } } $tDWLDatas = Tool_Fnc::arraySort($tDWLDatas, 'date', 'asc'); Tool_Fnc::ajaxMsg('', 1, array('dry_weight' => $tDWLDatas, 'weight' => $tTRDatas, 'start_treate_date' => $tTRMOList[0]['treate_date'])); }