Example #1
0
 /**
  * 学生考试报名
  * @author FuRongxin
  * @date    2016-02-22
  * @version 2.0
  * @param   \Illuminate\Http\Request $request 报名请求
  * @param   string $kslx 考试类型代码
  * @return  \Illuminate\Http\Response 报名列表
  */
 public function update(Request $request, $kslx)
 {
     $exam = Extype::find($kslx);
     $registered = Exregister::whereNd($exam->nd)->whereXh(Auth::user()->xh)->whereKslx($kslx)->exists();
     // 检测是否已经报过名
     if (!$registered) {
         // 检测是否CET4
         if (in_array($exam->kslx, Helper::getCet4())) {
             // 检测是否允许新生报考CET4
             if (config('constants.status.enable') == Setting::find('KS_CET4_XS')) {
                 // 不允许新生报考CET4
                 if (Profile::isFresh(Auth::user())->exists()) {
                     abort(403, '不允许新生报考CET4');
                 }
             }
         }
         // 检测是否CET6
         if (config('constants.exam.type.cet6') == $exam->kslx) {
             // 检测是否允许新生报考CET6
             if (config('constants.status.enable') == Setting::find('KS_CET6_XS')) {
                 // 不允许新生报考CET6
                 if (Profile::isFresh(Auth::user())->exists()) {
                     abort(403, '不允许新生报考CET6');
                 }
             }
             // 检测CET6是否具有过往成绩或者CET4是否及格
             if (!Exscore::whereC_xh(Auth::user()->xh)->whereC_kslx(config('constants.exam.type.cet6'))->exists() && !Exscore::isPassed(Auth::user(), Helper::getCet4())->exists()) {
                 abort(403, '四级成绩不达标,不能参加CET6考试');
             }
         }
         // 检测是否已经报过CET考试
         if (config('constants.exam.type.cet') == $exam->ksdl) {
             $registered = Exregister::with('type')->whereNd($exam->nd)->whereXh(Auth::user()->xh);
             foreach ($registered as $cet) {
                 if (config('constants.exam.type.cet') == $cet->type->ksdl) {
                     abort(403, '已经报名本次' . $cet . '考试,' . $cet . '和' . $exam->ksmc . '不能同时报名');
                 }
             }
         }
     }
     $register = new Exregister();
     $register->xh = Auth::user()->xh;
     $register->xq = Auth::user()->profile->college->pivot->xq;
     $register->kslx = $kslx;
     $register->bklb = '00';
     $register->kssj = $exam->sj;
     $register->clbz = config('constants.exam.status.register');
     $register->bmsj = date('Y-m-d H:i:s');
     $register->nd = $exam->nd;
     $register->save();
     return redirect('exam')->withStatus('考试报名成功,请交费!');
 }