示例#1
0
 /**
  * 批量更新成绩
  * @author FuRongxin
  * @date    2016-05-06
  * @version 2.1
  * @param   \Illuminate\Http\Request $request 更新成绩请求
  * @param   string $kcxh 12位课程序号
  * @return  \Illuminate\Http\Response 学生成绩
  */
 public function batchUpdate(Request $request, $kcxh)
 {
     if ($request->isMethod('put')) {
         $inputs = $request->all();
         $snos = array_unique(array_map(function ($val) {
             return Str::substr($val, 0, 12);
         }, array_filter(array_keys($inputs), function ($val) {
             return is_numeric($val);
         })));
         $task = Task::whereKcxh($kcxh)->whereNd(session('year'))->whereXq(session('term'))->whereJsgh(Auth::user()->jsgh)->firstOrFail();
         $ratios = [];
         $items = Ratio::whereFs($task->cjfs)->orderBy('id')->get();
         foreach ($items as $ratio) {
             $ratios[] = ['id' => $ratio->id, 'name' => $ratio->idm, 'value' => $ratio->bl / $ratio->mf, 'allow_failed' => $ratio->jg];
         }
         foreach ($snos as $sno) {
             $student = Score::whereNd(session('year'))->whereXq(session('term'))->whereKcxh($kcxh)->whereXh($sno)->firstOrFail();
             $rules = [];
             foreach ($items as $item) {
                 $rules[$student->xh . $item->id] = 'numeric|min:0|max:100';
             }
             $rules[$student->xh . 'kszt'] = 'numeric';
             $this->validate($request, $rules);
             foreach ($items as $item) {
                 $student->{'cj' . $item->id} = isset($inputs[$student->xh . $item->id]) ? $inputs[$student->xh . $item->id] : 0;
             }
             if (isset($inputs[$student->xh . 'kszt'])) {
                 $student->kszt = $inputs[$student->xh . 'kszt'];
             }
             $total = 0;
             $fails = [];
             foreach ($ratios as $ratio) {
                 if (config('constants.score.passline') > $student->{'cj' . $ratio['id']} && config('constants.status.enable') == $ratio['allow_failed']) {
                     $fails[] = $student->{'cj' . $ratio['id']};
                 } else {
                     $total += $student->{'cj' . $ratio['id']} * $ratio['value'];
                 }
             }
             $student->zpcj = round(empty($fails) ? $total : min($fails));
             $student->save();
         }
     }
     return redirect()->route('score.edit', $kcxh)->withStatus('保存成绩成功');
 }
示例#2
0
 /**
  * 将成绩转换成按成绩比例方式排列
  * @author FuRongxin
  * @date    2016-01-27
  * @version 2.0
  * @param   array $scores 学生成绩
  * @return  array 按成绩比例方式排列的成绩
  */
 private function _arrangeScores($scores)
 {
     $ratios = [];
     foreach ($scores as $score) {
         if (count($score->task)) {
             if (!array_key_exists($score->task->cjfs, $ratios)) {
                 $items = Ratio::whereFs($score->task->cjfs)->orderBy('id')->get();
                 foreach ($items as $ratio) {
                     $ratios[$ratio->fs][] = ['id' => $ratio->id, 'name' => $ratio->idm, 'value' => $ratio->bl];
                 }
             }
             $ratios[$score->task->cjfs]['score'][] = $score;
         } else {
             $ratios['000'] = [['id' => '1', 'name' => '成绩1'], ['id' => '2', 'name' => '成绩2'], ['id' => '3', 'name' => '成绩3'], ['id' => '4', 'name' => '成绩4'], ['id' => '5', 'name' => '成绩5'], ['id' => '6', 'name' => '成绩6']];
             $ratios['000']['score'][] = $score;
         }
     }
     ksort($ratios);
     return $ratios;
 }