public function initialize()
 {
     parent::initialize();
     $this->tag->prependTitle(' - 家长');
     self::$service = new ParentService($this);
     $this->user = self::$service->getUserInfo($this->user->id, new User());
     $this->assign('user', $this->user);
     //获取他的孩纸
     $this->son_student = self::$service->getStudentForParentId($this->user->id);
     $this->assign('son_student', $this->son_student);
     //当前的孩子
     if (count($this->son_student) > 0) {
         $son_now_id = $this->dispatcher->getParam('sid', 'int');
         if ($son_now_id) {
             foreach ($this->son_student as $std) {
                 if ($std->getId() == $son_now_id) {
                     $this->son_now_id = $std->getId();
                     $this->son_now_student = $std;
                     break;
                 }
             }
         }
         if (!$this->son_now_id) {
             $this->son_now_student = $this->son_student->getFirst();
             $this->son_now_id = $this->son_now_student->getId();
         }
         $this->assign('son_now_student', $this->son_now_student);
         $this->assign('son_now_id', $this->son_now_id);
     } else {
         $this->flash->error('没有孩子');
         $this->forward('error/message', '', '\\ST\\Apps\\Home\\Controllers');
         return false;
     }
 }
 /**
  * 统一更新统计表
  *
  * @param User $user
  * @param int  $now_data
  * @param int  $type
  *
  * @return bool|mixed
  * @author Hunter.<*****@*****.**>
  */
 public function updateStatistics(User $user, $now_data = 0, $type = 0, $other_bind_param = [])
 {
     if (!$user or !$type or !isset(Config('CONFIG_STATISTICS_AB_ID')[$type])) {
         return false;
     }
     $bind = array_merge(['classes_id' => $user->getClassesId(), 'user_id' => $user->getId(), 'type' => $type], $other_bind_param);
     //获取当前此type的值
     $statistics = $this->getCommon(['classes_id=:classes_id: and uid=:user_id: and ab_id=:type:', 'bind' => $bind], 'Statistics', true);
     $old_data = 0;
     if ($statistics) {
         $old_data = $statistics->getVal();
     } else {
         $statistics = 'Statistics';
     }
     /*
             1 => '认知',
             2 => '理解',
             3 => '分析',
             4 => '迁移应用',
     
             30 => '字数',
     
             40 => '本数',
             41 => '已阅读本数',
     
             50 => '笔记',
     
             60 => '平均分',
             61 => '学生已评测次数',
     
             70 => '老师发布阅读次数',
             80 => '老师发布评测次数',
     */
     //这些值都是不断增加
     $add_sum_type = [30, 40, 41, 50, 61, 70, 80];
     //这些值是不断取平均值
     $avg_type = [1, 2, 3, 4, 60];
     //这些值使用给定的值
     $use_now_data_type = [42];
     //insert的数据
     $data['ab_id'] = $type;
     $data['school_id'] = $user->getSchoolId();
     $data['classes_id'] = $user->getClassesId();
     $data['uid'] = $user->getId();
     if (in_array($type, $add_sum_type)) {
         $new_data = $old_data + $now_data;
     } else {
         if (in_array($type, $avg_type)) {
             if ($old_data) {
                 $new_data = ($old_data + $now_data) / 2;
             } else {
                 $new_data = $now_data;
             }
         } else {
             if (in_array($type, $use_now_data_type)) {
                 $new_data = $now_data;
             }
         }
     }
     $data['val'] = $new_data;
     //写入库
     if (is_string($statistics)) {
         return $this->insertCommon($data, $statistics);
     } else {
         return $this->updateCommon($data, $statistics);
     }
 }