public function assess()
 {
     $uid = session('uid');
     if (IS_GET) {
         if ($uid == null) {
             $info = authcode(cookie('applyInfo'), 'DECODE', C('AUTH_KEY'));
             $info = unserialize($info);
             if ($info) {
                 $info['name1'] = self::subject($info['csid'])[0]['name'];
                 $info['name2'] = self::subject($info['esid'])[0]['name'];
                 echo json_encode(array('data' => $info));
             } else {
                 echo json_encode(array('data' => array()));
             }
             exit;
         } else {
             $lang = LANG_SET;
             $applyInfoModel = M('apply_info');
             $applyInfo = $applyInfoModel->alias('a')->field('a.*,b.name name1,c.name name2')->join('LEFT JOIN __SUBJECT__ b ON a.csid=b.su_id LEFT JOIN __SUBJECT__ c ON a.esid=c.su_id')->where("a.uid={$uid} and b.lang='{$lang}' and c.lang='{$lang}'")->find();
             if ($applyInfo) {
                 echo json_encode(array('data' => $applyInfo));
             } else {
                 echo json_encode(array('data' => array()));
             }
         }
     }
     if ($_POST) {
         $data = self::getParam($_POST);
         if (!preg_match('/^[1-9](?:\\.[0])?$|^[1-8](?:\\.[1-9])?$/', $data['lscore'])) {
             echo json_encode(array('data' => array()));
             exit;
         }
         if (!preg_match('/^(?:[1-9]?\\d|100)$/', $data['score'])) {
             echo json_encode(array('data' => array()));
             exit;
         }
         $esid = I('post.esid');
         $csid = I('post.csid');
         $subjectRelation = M('subject_relation');
         $count = $subjectRelation->field('*')->where("cn_sub={$csid} and uk_sub={$esid} and type=3")->count();
         if ($count > 0) {
             echo json_encode(array('data' => array('r' => 0)));
             exit;
         }
         $data['uid'] = $uid;
         if ($data['country'] == 'China') {
             $data['country'] = 1;
         } else {
             $data['country'] = 2;
         }
         $applyInfoModel = M('apply_info');
         if ($uid) {
             if ($data['hasAssess'] == 0) {
                 //不存在用户数据
                 //保存用户数据
                 $applyInfoModel->add($data);
             } else {
                 //更新用户数据
                 $applyInfoModel->where("id={$data['hasAssess']}")->save($data);
             }
         } else {
             $applyInfo = authcode(serialize($data), 'ENCODE', C('AUTH_KEY'));
             cookie('applyInfo', $applyInfo);
         }
         //计算匹配度
         $matchModel = new \Home\Model\MatchModel();
         $us_id = (int) $data['us_id'];
         $data = $matchModel->match($us_id);
         echo json_encode(array('data' => $data));
     }
 }
Example #2
0
 public function index()
 {
     $type = false;
     $count = 0;
     $model = new \Home\Model\MatchModel();
     $info = $model->match();
     if ($info['status'] == 1) {
         $count = count($info['data']);
         $type = true;
     }
     $time = date('Y-m', time());
     $timeArr = explode('-', $time);
     if ($timeArr[1] >= 9) {
         $res = array($timeArr[0] + 1, $timeArr[0] + 2);
     } else {
         $res = array($timeArr[0], $timeArr[0] + 1);
     }
     $username = session('username') ?: L('TOURIST');
     $uid = session('uid');
     if ($uid) {
         $infoModel = M('apply_info');
         $info = $infoModel->where("uid={$uid}")->find();
         if (empty($info)) {
             $info = authcode(cookie('applyInfo'), 'DECODE', C('AUTH_KEY'));
             if ($info) {
                 $info = unserialize($info);
             }
         }
         $this->assign('info', $info);
     }
     $this->assign('username', $username);
     $this->assign('count', $count);
     $this->assign('type', $type);
     $this->assign('resTime', $res);
     $cache = self::applyNum();
     $this->assign('APPLY_NUM', $cache['APPLY_NUM']);
     //学校新闻
     $lang = LANG_SET;
     //and a.is_school=1
     $condition = "b.lang='{$lang}' ";
     $newsModel = M('news');
     $join = 'left join __NEWSLANG__ b on a.id=b.fid';
     $schoolNews = $newsModel->alias('a')->field('a.id,a.is_school,a.college_id,
         a.editer,a.visits,a.preview_img,FROM_UNIXTIME(a.create_time,"%b-%d")create_time,b.lang,
         CASE b.title
         WHEN CHAR_LENGTH(b.title)<20 THEN CONCAT(SUBSTRING(b.title,1,20),"...")
         ELSE b.title END title,b.title title1,b.keyword,b.author,b.news_from,b.content')->join($join)->where("{$condition}")->limit(0, 12)->order('a.create_time desc')->select();
     $this->assign('schoolNews', $schoolNews);
     //重要日期
     $condition = "b.lang='{$lang}' and a.is_future=1";
     $newsModel = M('news');
     $join = 'left join __NEWSLANG__ b on a.id=b.fid';
     $futureNews = $newsModel->alias('a')->field('a.id,a.is_school,a.college_id,
         a.editer,a.visits,a.preview_img,FROM_UNIXTIME(a.create_time,"%d/%b/%Y")create_time,DATE_FORMAT(a.future_time,"%d/%b/%Y") create_time1,
         DATE_FORMAT(a.future_time,"%b") m,DATE_FORMAT(a.future_time,"%d") d,b.lang,
         CASE b.title
         WHEN CHAR_LENGTH(b.title)<20 THEN CONCAT(SUBSTRING(b.title,1,20),"...")
         ELSE b.title END title,b.title title1,b.keyword,b.author,b.news_from,b.content')->join($join)->where("{$condition}")->limit(0, 5)->order('a.future_time desc')->select();
     $this->assign('futureNews', $futureNews);
     $this->schoolIMGPic();
     //查询学LOGO
     $subject = M('subject')->field('su_id as id, name')->where(array('lang' => LANG_SET))->order('id asc')->limit(7)->select();
     $this->assign('subject', $subject);
     $this->theme('bootstrap')->display();
 }