public function getTest(Request $request)
 {
     $validator = Validator::make($request->all(), ['username' => 'required|exists:mysql_old.member,id']);
     if ($validator->fails()) {
         return response()->json(['success' => false, 'error_message' => $validator->errors()->getMessages()]);
     }
     $userid = $request->input('username');
     $set1 = \DB::connection('mysql_old')->table('data')->where('userid', $userid)->where('heartrate', '!=', 0)->orderBy('time', 'DESC')->select(['heartrate', 'spo2'])->first();
     $set2 = \DB::connection('mysql_old')->table('data')->where('userid', $userid)->orderBy('time', 'DESC')->select(['activity', 'sleep_total_time'])->first();
     $set3 = \DB::connection('mysql_old')->table('data_warn_save')->where('userid', $userid)->where('type', '!=', 5)->orderBy('id', 'DESC')->first();
     $relative = Relative::where('mid', $userid)->where('main', 1)->first();
     $sleep = $set2 ? $set2->sleep_total_time : 0;
     return response()->json(['success' => true, 'result' => ['bloodOxygen' => $set1 ? $set1->spo2 : null, 'heartRate' => $set1 ? $set1->heartrate : null, 'activity' => $set2 ? $set2->activity : null, 'sleep' => $sleep >= 360 ? '良好' : '差', 'lifeWarning' => null, 'ecg' => null, 'emotion' => null, 'temperature' => null]]);
 }
Пример #2
0
 public function postMultipleCreate(Request $request)
 {
     $excel = $request->file('watch');
     $target = $excel->move(storage_path(), 'test.xslt');
     \Excel::load($target, function ($reader) {
         $array = $reader->get()->toArray();
         $result = [];
         foreach ($array as $item) {
             if ($item[0]) {
                 $result[] = $item[0];
             }
         }
         foreach ($result as $item) {
             if ($member = Member::where('pid', intval($item))->first()) {
                 $member->fid = \Auth::user()->id;
                 $member->uname = \Auth::user()->contact_name;
                 $relative = Relative::where('mid', $member->id)->where('main', 1)->first();
                 if (!$relative) {
                     $relative = new Relative();
                 }
                 $relative->name = \Auth::user()->contact_name;
                 $relative->phone = \Auth::user()->contact_phone;
                 $relative->mid = $member->id;
                 $relative->main = 1;
                 $relative->save();
                 $member->save();
             }
         }
     });
     if (\Auth::user()->user_type == 0) {
         $items = Member::paginate(10);
     } else {
         $items = Member::where('fid', '=', \Auth::user()->id)->paginate(10);
     }
     return view('watch.index')->with(['success' => true, 'items' => $items]);
 }