示例#1
0
 public function download_survey_file(Request $request)
 {
     $survey_id = $request->survey_id;
     $gen_id = $request->gen_id;
     $survey = Survey::find($survey_id);
     $gen = Gen::find($gen_id);
     $survey_users = $gen->survey_users()->where('survey_id', '=', $survey->id)->get();
     $header = array('Biết đến colorME qua', 'facebook', 'Giới tính', 'Ngày sinh', 'Trường học', 'Nơi làm việc', 'Địa chỉ', 'Họ tên', 'email', 'Số điện thoại');
     foreach ($survey->questions as $question) {
         $header[] = $question->content;
     }
     $result_arr = array($header);
     foreach ($survey_users as $survey_user) {
         if ($survey_user->content != null) {
             $row = json_decode($survey_user->content);
             $user = $survey_user->user;
             array_unshift($row, how_know($user->how_know), $user->facebook, gender($user->gender), format_date($user->dob), $user->university, $user->work, $user->address);
             $result_arr[] = $row;
         }
     }
     $name = $survey->name . ' khoá ' . $gen->name;
     Excel::create($name, function ($excel) use($name, $result_arr, $header) {
         $excel->sheet('survey', function ($sheet) use($result_arr, $header) {
             $sheet->fromArray($result_arr);
         });
     })->export('xls');
 }
示例#2
0
 public function download_paid_students(Request $request)
 {
     $genId = $request->genid;
     $gen = Gen::find($genId);
     $registers_id = $gen->registers()->where('status', 1)->get()->pluck('user_id')->toArray();
     $students = User::whereIn('id', $registers_id)->get();
     $students = $students->map(function ($student) use($gen) {
         $student->how_know = how_know($student->how_know);
         $student->gender = gender($student->gender);
         $student->dob = format_date($student->dob);
         $registers = $student->registers()->where('gen_id', $gen->id)->get();
         $student->class = $registers->map(function ($register) {
             $class = $register->studyClass;
             $base = $class->base;
             $className = $class->name . " (" . $base->name . ": " . $base->address . ")";
             return $className;
         })->reduce(function ($carry, $item) {
             return $carry . ", " . $item;
         }, "");
         unset($student->id);
         unset($student->created_at);
         unset($student->updated_at);
         unset($student->role);
         unset($student->code);
         unset($student->avatar_url);
         unset($student->cover_url);
         unset($student->description);
         unset($student->money);
         unset($student->status);
         unset($student->avatar_name);
         unset($student->cover_name);
         unset($student->cover_name);
         unset($student->order);
         unset($student->registers);
         return $student;
     })->toArray();
     return Excel::create('Khoá ' . $gen->name, function ($excel) use($students) {
         $excel->sheet('students', function ($sheet) use($students) {
             $sheet->fromArray($students);
         });
     })->download('xls');
 }