Example #1
0
 public static function setDay($date)
 {
     $date_now = date("Y-m-d H:i:s");
     $tmp_quantity = HealthLog::find()->where(['date' => $date])->sum("quantity");
     $health_day_info = HealthDay::findOne(['date' => $date]);
     if ($health_day_info) {
         $model_health_day = $health_day_info;
     } else {
         $model_health_day = new HealthDay();
         $model_health_day->date = $date;
         $model_health_day->created_time = $date_now;
     }
     $model_health_day->quantity = $tmp_quantity ? $tmp_quantity : 0;
     $model_health_day->updated_time = $date_now;
     $model_health_day->save(0);
     return true;
 }
Example #2
0
 public function actionStep()
 {
     $type = $this->get("type", "daily");
     $total_step = 0;
     $data_step = [];
     $x_cat = [];
     if ($type == "monthly") {
         $avg = 6000;
         $step = 3;
         $total_days = 0;
         $date_to = date("Ymd");
         $date_from = date("Ymd", strtotime(' -30 day'));
         $step_list = HealthDay::find()->where([">=", "date", $date_from])->andWhere(["<=", "date", $date_to])->orderBy("id asc")->all();
         if ($step_list) {
             foreach ($step_list as $_one_step) {
                 $data_step[] = $_one_step["quantity"];
                 $x_cat[] = (strtotime($_one_step['date']) + 8 * 3600) * 1000;
                 $total_days++;
                 $total_step += $_one_step["quantity"];
             }
         }
         $title = '<span class="sub_title">步数<br/><span>日平均值:' . ceil($total_step / $total_days) . '</span></span>';
         $sub_title = '<span class="sub_title">' . number_format($total_step) . ' 步<br/><span>' . "{$date_from} ~ {$date_to}</span></span>";
     } else {
         $avg = 40;
         $step = 3;
         $date_to = "";
         $date_from = "";
         $step_list = HealthLog::find()->where(["date" => date("Ymd")])->orderBy("id asc")->all();
         if ($step_list) {
             $date_from = date("H:i", strtotime($step_list[0]['time_from']));
             foreach ($step_list as $_one_step) {
                 $data_step[] = $_one_step["quantity"];
                 $total_step += $_one_step["quantity"];
                 $x_cat[] = (strtotime($_one_step['time_from']) + 8 * 3600) * 1000;
                 $date_to = date("H:i", strtotime($_one_step['time_from']));
             }
         }
         $title = '<span class="sub_title">步数<br/><span>小时平均值:' . ceil($total_step / date("H")) . '</span></span>';
         $sub_title = '<span class="sub_title">' . number_format($total_step) . ' 步<br/><span>' . "{$date_from} ~ {$date_to}</span></span>";
     }
     $data = ['data' => $data_step, 'x_cat' => $x_cat, 'avg' => $avg, 'step' => $step, 'title' => $title, 'sub_title' => $sub_title];
     return $this->render("step", ['data' => json_encode($data), 'type' => $type, 'urls' => ["daily" => UrlService::buildUrl("/run/step", ["type" => "daily"]), "monthly" => UrlService::buildUrl("/run/step", ["type" => "monthly"])]]);
 }