/**
  * 更新处理界面
  *
  * @return void
  */
 public function update_save()
 {
     $post = $this->input->post();
     /** 验证 */
     /** 标题 */
     if (empty($post['title'])) {
         message('标题不能为空!');
     }
     /** 考试期次 */
     if (count($post['exam_id']) < 1) {
         message('请选择考试期次!');
     }
     /** 学科 */
     if (count($post['subject_id']) < 1) {
         message('请选择学科!');
     }
     /** 学科权重 */
     $post['weight'] = array_filter($post['weight']);
     if (empty($post['weight'])) {
         message('请填写学科权重!');
     }
     $tip_subject = array();
     $subject_weight = array();
     $subject_total_percent = 0;
     foreach ($post['subject_id'] as $subject_id) {
         if (empty($post['weight'][$subject_id])) {
             $tip_subject[] = C("subject/{$subject_id}");
         } else {
             $subject_weight[$subject_id] = $post['weight'][$subject_id];
             $subject_total_percent += $post['weight'][$subject_id];
         }
     }
     if ($tip_subject) {
         message("请填写 [" . implode('、', $tip_subject) . "] 学科权重");
     }
     if ($subject_total_percent != 100) {
         message('所有学科的权重占比总和必须等于 100');
     }
     /** 评分项 */
     if (count($post['option_id']) < 1) {
         message('请选择评分项!');
     }
     foreach ($post['subject_id'] as $subject_id) {
         if (empty($post['option_id'][$subject_id])) {
             $tip_subject[] = C("subject/{$subject_id}");
         }
     }
     if ($tip_subject) {
         message("请选择 [" . implode('、', $tip_subject) . "] 学科评分项");
     }
     /* 排序 */
     foreach ($post['sort'] as $subject_id => $option_sort) {
         $sort = array();
         foreach ($option_sort as $key => $k_sort) {
             if (empty($k_sort)) {
                 $sort[0][] = $post['option_id'][$subject_id][$key];
             } else {
                 $sort[$k_sort][] = $post['option_id'][$subject_id][$key];
             }
         }
         ksort($sort);
         $options = array();
         foreach ($sort as $index => $val) {
             if (is_array($val)) {
                 foreach ($val as $k => $v) {
                     $options[] = $v;
                 }
             }
         }
         $post['option_id'][$subject_id] = $options;
     }
     /** 等级及等级所占比例  */
     if (empty($post['level'])) {
         message("请输入等级名称");
     }
     if (empty($post['level_percent'])) {
         message("请输入等级所占百分比");
     }
     $tips = array();
     $levels = array();
     foreach ($post['level'] as $key => $level) {
         if (!$level) {
             $tips[1] = '请输入等级名称';
         }
         if (empty($post['level_percent'][$key])) {
             $tips[2] = '请输入等级所占百分比';
         }
         if (!$tips) {
             $levels[$level] = $post['level_percent'][$key];
         }
     }
     if ($tips) {
         message(implode("<br>", $tips));
     }
     $data = array();
     /** 格式转换 */
     $data['title'] = trim($post['title']);
     $data['subject_id'] = implode(',', $post['subject_id']);
     $data['weight'] = json_encode($post['weight']);
     $data['options'] = json_encode($post['option_id']);
     $data['level'] = json_encode($levels);
     $data['status'] = $post['status'];
     /** 写入评分标准 */
     $result = EvaluationStandardModel::update($post['id'], $data);
     if (!$result) {
         message('评分标准修改失败!');
     }
     /** 清楚原本关联并从新写入评分标准与考试期次关联 */
     $result_one = EvaluationStandardExamModel::delete($post['id']);
     $result_two = EvaluationStandardExamModel::add($post['id'], $post['exam_id']);
     if ($result_one && $result_two) {
         message('评分标准修改成功', 'admin/evaluation_standard/index');
     } else {
         message('评分标准修改失败!请重新尝试!', 'admin/evaluation_standard/index');
     }
 }