fetch(); } public function datas(){ $request = Request::instance(); $params = $request->param(); if(isset($params['search']) && !empty($params['search'])){ $search = str_replace('-', '', $params['search']); $where = $search; }else{ $where = date('Ymd',strtotime('-1 day')); } $date = array(); $date['studydate'] = $where; $time['date'] = $where; $info = DB::table('every_studies')->where($time)->select(); if($info){ $count = DB::table('every_studies')->where($time)->count(); $data["total"] = $count; $data["rows"] = $info; echo json_encode($data); }else{ $institution = DB::table('institution')->where('is_test',0)->field('id,name as institution_name')->select(); $count = DB::table('institution')->count(); $every = array(); foreach ($institution as $k => $v) { $institution[$k]['count'] = DB::table('studies')->where($date)->where('institution_id',$v['id'])->group('institution_id')->count(); $every[$k]['id'] = UUIDs::uuid16(); $every[$k]['date'] = $where; $every[$k]['institution_id'] = $v['id']; $every[$k]['institution_name'] = $v['institution_name']; $every[$k]['count'] = $institution[$k]['count']; } DB::table('every_studies')->insertAll($every); $data["total"] = $count; $data["rows"] = $institution; echo json_encode($data); } } }