Esempio n. 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     if ($request->hasFile('health_file')) {
         // 上传文件
         $xml = $request->file('health_file');
         if ($xml->getClientOriginalExtension() != 'xml') {
             return 'File extension is not xml!';
         }
         $new_name = 'xml_' . date('Y-m-d H:m:s') . Auth::user()->id . '.xml';
         $xml->move(base_path() . '/public/file/health/', $new_name);
         $obj = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . '/file/health/' . $new_name);
         for ($i = 0; $i < count($obj->xpath('healthentry')); ++$i) {
             $e = $obj->xpath('healthentry')[$i];
             $entry = new healthentry();
             $entry->user_id = Auth::user()->id;
             $entry->type = $e->xpath('type')[0];
             $entry->level = $e->xpath('level')[0];
             $entry->value = $e->xpath('value')[0];
             $entry->value2 = $e->xpath('value2')[0];
             $entry->last_time = $e->xpath('last_time')[0];
             $entry->begin_time = $e->xpath('begin_time')[0];
             $entry->end_time = $e->xpath('end_time')[0];
             $entry->description = $e->xpath('description')[0];
             $entry->save();
         }
     } else {
         // 手动输入
         if ($request->input('temp')) {
             $entry = new healthentry();
             $entry->user_id = Auth::user()->id;
             $entry->type = healthentry::TYPE_TEMPERATURE;
             $entry->begin_time = date('Y-m-d H:m:s');
             $entry->value = $request->input('temp');
             $entry->save();
         }
         if ($request->input('height')) {
             $entry = new healthentry();
             $entry->user_id = Auth::user()->id;
             $entry->type = healthentry::TYPE_HEIGHT;
             $entry->begin_time = date('Y-m-d H:m:s');
             $entry->value = $request->input('height');
             $entry->save();
         }
         if ($request->input('weight')) {
             $entry = new healthentry();
             $entry->user_id = Auth::user()->id;
             $entry->type = healthentry::TYPE_WEIGTH;
             $entry->begin_time = date('Y-m-d H:m:s');
             $entry->value = $request->input('weight');
             $entry->save();
         }
         if ($request->input('hr')) {
             $entry = new healthentry();
             $entry->user_id = Auth::user()->id;
             $entry->type = healthentry::TYPE_HEARTRATE;
             $entry->begin_time = date('Y-m-d H:m:s');
             $entry->value = $request->input('hr');
             $entry->save();
         }
         if ($request->input('bph')) {
             $entry = new healthentry();
             $entry->user_id = Auth::user()->id;
             $entry->type = healthentry::TYPE_BLOODPRESSURE;
             $entry->begin_time = date('Y-m-d H:m:s');
             $entry->value = $request->input('bph');
             $entry->value2 = $request->input('bpl');
             $entry->save();
         }
         if ($request->input('dh')) {
             $entry = new healthentry();
             $entry->user_id = Auth::user()->id;
             $entry->type = healthentry::TYPE_SLEEP;
             $entry->level = healthentry::LEVEL_GOOD;
             $entry->begin_time = date('Y-m-d H:m:s');
             $entry->value = $request->input('dh') * 3600 + $request->input('dm') * 60 + $request->input('ds');
             $entry->save();
             $entry2 = new healthentry();
             $entry2->user_id = Auth::user()->id;
             $entry2->type = healthentry::TYPE_SLEEP;
             $entry2->level = healthentry::LEVEL_MID;
             $entry2->begin_time = date('Y-m-d H:m:s');
             $entry2->value = $request->input('mh') * 3600 + $request->input('mm') * 60 + $request->input('ms');
             $entry2->save();
             $entry3 = new healthentry();
             $entry3->user_id = Auth::user()->id;
             $entry3->type = healthentry::TYPE_SLEEP;
             $entry3->level = healthentry::LEVEL_BAD;
             $entry3->begin_time = date('Y-m-d H:m:s');
             $entry3->value = $request->input('bh') * 3600 + $request->input('bm') * 60 + $request->input('bs');
             $entry3->save();
         }
     }
     return Redirect::to('/player/health/data');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     $user = User::find($id);
     if ($request->hasFile('portrait')) {
         $portrait = $request->file('portrait');
         $por_name = 'user_portrait_' . $id . '.' . $portrait->getClientOriginalExtension();
         $portrait->move(base_path() . '/public/img/portrait/', $por_name);
         $user->portrait = '/img/portrait/' . $por_name;
     }
     $user->name = $request->input('name');
     $user->email = $request->input('email');
     if (strlen($request->input('password')) != 0) {
         $user->password = bcrypt($request->input('password'));
     }
     $user->save();
     $height = new healthentry();
     $height->user_id = $id;
     $height->timescale = 1;
     $height->level = 2;
     $height->type = healthentry::TYPE_HEIGHT;
     $height->begin_time = date('Y-m-d H:m:s');
     $height->value = $request->input('height');
     $height->save();
     $weight = new healthentry();
     $weight->user_id = $id;
     $weight->timescale = 1;
     $weight->level = 2;
     $weight->type = healthentry::TYPE_WEIGTH;
     $weight->begin_time = date('Y-m-d H:m:s');
     $weight->value = $request->input('weight');
     $weight->save();
     return Redirect::to('/player');
 }