예제 #1
0
파일: Selcourse.php 프로젝트: rxfu/student
 public static function boot()
 {
     parent::boot();
     static::created(function ($course) {
         // 2016-09-01:应教务处要求添加公体选课统计,修改选课统计方式
         if ($isPubSport = Helper::isCourseType($course->kcxh, 'TB14')) {
             $count = Count::whereKcxh($course->kcxh)->first();
         } else {
             $count = Count::whereKcxh($course->kcxh)->whereZy($course->zy)->first();
         }
         if (count($count)) {
             $count->rs += 1;
         } else {
             $count = new Count();
             $count->kcxh = $course->kcxh;
             $count->zy = $isPubSport ? '' : $course->zy;
             $count->rs = 1;
         }
         $count->save();
         $log = new Slog();
         $log->kcxh = $course->kcxh;
         $log->ip = request()->ip();
         $log->czlx = 'insert';
         $log->save();
     });
     static::deleted(function ($course) {
         // 2016-09-01:应教务处要求添加公体选课统计,修改选课统计方式
         if ($isPubSport = Helper::isCourseType($course->kcxh, 'TB14')) {
             $count = Count::whereKcxh($course->kcxh)->first();
         } else {
             $count = Count::whereKcxh($course->kcxh)->whereZy($course->zy)->first();
         }
         if (count($count)) {
             $count->rs -= 1;
         } else {
             $count = new Count();
             $count->kcxh = $course->kcxh;
             $count->zy = $isPubSport ? '' : $course->zy;
             $count->rs = 0;
         }
         $count->save();
         $log = new Slog();
         $log->kcxh = $course->kcxh;
         $log->ip = request()->ip();
         $log->czlx = 'delete';
         $log->save();
     });
 }
예제 #2
0
 /**
  * 选课门数和人数限制检测
  * 2016-06-16:添加专业号检测
  * 2016-09-01:应教务处要求添加公体选课统计,修改选课统计方式
  * @author FuRongxin
  * @date    2016-09-01
  * @version 2.1.2
  * @param   string $type 课程类型
  * @param   string $kcxh 12位课程序号
  * @param   string $zy 专业号
  * @param   integer $ms 课程门数限制,-1为无限制
  * @param   integer $rs 选课人数限制,-1为无限制
  * @return  array 课程门数和人数限制标志数组,true为超限,false为未超限
  */
 public function checkcourse($type, $kcxh, $zy, $ms = -1, $rs = -1)
 {
     $limits = ['ms' => false, 'rs' => false];
     if (in_array($type, array_keys(config('constants.course.general')))) {
         if (-1 < $ms) {
             $count = Selcourse::ofType($type)->whereNd(session('year'))->whereXq(session('term'))->whereXh(Auth::user()->xh)->count();
             if ($count >= $ms) {
                 $limits['ms'] = true;
             }
         }
         if (-1 < $rs) {
             $course = Count::whereKcxh($kcxh)->whereZy($zy)->first();
             $count = isset($course) ? $course->rs : 0;
             if ($count >= $rs) {
                 $limits['rs'] = true;
             }
         }
     } else {
         // 2016-09-01:应教务处要求添加公体选课统计,修改选课统计方式
         if (Helper::isCourseType($kcxh, config('constants.course.pubsport.type'))) {
             $course = Count::whereKcxh($kcxh)->first();
         } else {
             $course = Count::whereKcxh($kcxh)->whereZy($zy)->first();
         }
         $count = isset($course) ? $course->rs : 0;
         if ($count >= $rs) {
             $limits['rs'] = true;
         }
     }
     return request()->ajax() ? response()->json($limits) : $limits;
 }