Author: FuRongxin
Inheritance: extends BaseModel
Esempio n. 1
0
 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();
     });
 }
Esempio n. 2
0
 public function getDataAttribute()
 {
     $data = [];
     $startOffset = Count::currentRankStart() + 1;
     $end = $startOffset + 89;
     for ($i = $startOffset; $i < $end; $i++) {
         $column = 'r' . strval($i % 90);
         $data[] = intval($this->{$column});
     }
     return $data;
 }
Esempio n. 3
0
 public function index()
 {
     $host = Request::getHttpHost();
     $subdomain = substr($host, 0, strpos($host, '.'));
     if ($subdomain === 'store') {
         return ujs_redirect(route('store.products.index'));
     }
     if (Auth::check()) {
         return ujs_redirect(route('forum.forums.index'));
     }
     $stats = BanchoStats::whereRaw('banchostats_id mod 10 = 0')->orderBy('banchostats_id', 'DESC')->limit(24 * 60 / 10)->get();
     $totalUsers = Count::totalUsers();
     $currentOnline = $stats->isEmpty() ? 0 : $stats->last()->users_osu;
     return view('home.landing', compact('stats', 'totalUsers', 'currentOnline'));
 }
Esempio n. 4
0
 /**
  * 按校区列出可选课程
  * 2016-05-12:应教务处要求,添加公体选课类别名称
  * 2016-09-01:应教务处要求,添加公体选课人数
  * @author FuRongxin
  * @date    2016-09-01
  * @version 2.1.2
  * @param   string $type 课程类型
  * @param   string $campus 校区号
  * @return  JSON 可选课程列表
  */
 public function listing($type, $campus)
 {
     $courses = Mjcourse::ofType($type)->selectable($campus)->get();
     $datatable = Datatables::of($courses)->addColumn('action', function ($course) use($type) {
         $same = Selcourse::whereXh(Auth::user()->xh)->whereNd(session('year'))->whereXq(session('term'))->whereKch($course->kch)->where('kcxh', '<>', $course->kcxh)->exists();
         $exists = Selcourse::whereXh(Auth::user()->xh)->whereNd(session('year'))->whereXq(session('term'))->whereKcxh($course->kcxh)->exists();
         if ($exists) {
             return '<form name="deleteForm" action="' . route('selcourse.destroy', $course->kcxh) . '" method="post" role="form" data-id="' . $course->kcxh . '" data-name="' . $course->kcmc . '">' . method_field('delete') . csrf_field() . '<button type="submit" class="btn btn-danger">退课</button></form>';
         } elseif ($same) {
             return '<div class="text-danger">已选同号课程</div>';
         } elseif (Prior::failed($course->kch, Auth::user())->exists()) {
             return '<div class="text-danger">前修课未修读</div>';
         } elseif ($course->rs >= $course->zrs) {
             return '<div class="text-danger">人数已满</div>';
         } else {
             return '<form name="createForm" action="' . route('selcourse.store') . '" method="post" role="form" data-id="' . $course->kcxh . '" data-name="' . $course->kcmc . '">' . csrf_field() . '<button type="submit" class="btn btn-primary">选课</button><input type="hidden" name="kcxh" value="' . $course->kcxh . '"><input type="hidden" name="type" value="' . $type . '"></form>';
         }
     })->editColumn('kcmc', function ($course) use($type) {
         // 列出公体项目名称
         if ('pubsport' == $type) {
             $sport = Pubsport::whereNd(session('year'))->whereXq(session('term'))->whereKcxh($course->kcxh)->first();
             if (is_object($sport)) {
                 return $course->kcmc . '-' . $sport->xm;
             }
         }
         return $course->kcmc;
     })->editColumn('rs', function ($course) use($type) {
         // 显示公体已选人数
         if ('pubsport' == $type) {
             $count = Count::whereKcxh($course->kcxh)->first();
             if (is_object($count)) {
                 return $count->rs;
             }
         }
         return $course->rs;
     });
     for ($i = 1; $i <= 7; ++$i) {
         $datatable = $datatable->addColumn($this->_weeks[$i], function ($course) use($i) {
             $info = '';
             foreach (array_keys(explode(',', $course->zcs), $i) as $pos) {
                 $ksz = array_get(explode(',', $course->kszs), $pos);
                 $jsz = array_get(explode(',', $course->jszs), $pos);
                 $ksj = array_get(explode(',', $course->ksjs), $pos);
                 $jsj = array_get(explode(',', $course->jsjs), $pos);
                 $jsxm = array_get(explode(',', $course->jsxms), $pos);
                 $info .= '<p><div>第 ';
                 $info .= $ksz === $jsz ? $ksz : $ksz . ' ~ ' . $jsz;
                 $info .= ' 周</div><div class="text-danger">第 ';
                 $info .= $ksj === $jsj ? $ksj : $ksj . ' ~ ' . $jsj;
                 $info .= ' 节</div><div class="text-info">';
                 $info .= empty($jsxm) ? '未知老师' : $jsxm;
                 $info .= '</div></p>';
             }
             return $info;
         });
     }
     return $datatable->make(true);
 }