From 4358904f5dc6f394c5ee17b4d040e282426e4dbe Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Sat, 5 Jan 2013 09:20:36 +0000 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E4=B8=93=E5=AE=B6=E9=82=80?= =?UTF-8?q?=E8=AF=B7=E7=A1=AE=E8=AE=A4=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/HeiheController.php | 26 ++-- application/models/Heihe.php | 117 ++++++++++++++++++ 2 files changed, 124 insertions(+), 19 deletions(-) diff --git a/application/default/controllers/HeiheController.php b/application/default/controllers/HeiheController.php index 1573b56c..b031d431 100644 --- a/application/default/controllers/HeiheController.php +++ b/application/default/controllers/HeiheController.php @@ -1017,29 +1017,17 @@ class HeiheController extends DataController return true; } - $sql = "SELECT * FROM $projectTable WHERE id=$pid"; - $sth = $this->db->query($sql); - $row = $sth->fetch(); + $level = $heihe->expertActive($pid,$invite); - if(empty($row['expert_name'])) + if($level>100) { - $this->view->error = "此项目尚未邀请跟踪专家"; + $this->view->error = "数据中心对您的邀请已经确认!感谢您的支持"; + return true; + }else{ + $this->view->error = $heihe->expertActiveError($level); return true; } - - $names = $this->getArray($row['expert_name']); - $emails = $this->getArray($row['expert_email']); - $validations = $this->getArray($row['expert_validation']); - $created = $this->getArray($row['expert_created']); - - if(!in_array($validations)) - { - $this->view->error = "您不在被邀请的专家名单内"; - return true; - } - - - + }//专家邀请链接 diff --git a/application/models/Heihe.php b/application/models/Heihe.php index 1e595cdd..981e1e3e 100644 --- a/application/models/Heihe.php +++ b/application/models/Heihe.php @@ -52,5 +52,122 @@ class Heihe return $rs; } + + //专家激活 + public function expertActive($pid,$code) + { + try{ + $sql = "SELECT * FROM ".$this->tbl_heiheproject." WHERE id=$pid"; + $sth = $this->db->query($sql); + $row = $sth->fetch(); + + //没有邀请专家 + if(empty($row['expert_name'])) + { + return 1; + } + + $validations = $this->getArray($row['expert_validation']); + $status = $this->getArray($row['expert_activated']); + + if(!in_array($code,$validations)) + { + return 2; + } + + $key = $this->getKey($validations,$code); + + if(!empty($status)) + { + if(isset($status[$key])) + { + return 3; + } + + $time = array($code,date("Y-m-d H:i:s",time())); + + $time = array($this->mkArray($time)); + + $new_status = array_splice($status,$key,0,$time); + + $new_status = $this->mkArray($new_status); + + $sql = "UPDATE ".$this->tbl_heiheproject." SET expert_activated=?"; + $sth = $this->db->prepare($sql); + if($sth->execute(array($new_status))) + { + return 200; + } + }else{ + + $time = date("Y-m-d H:i:s",time()); + + $new_status = "{{".$code.",".$time."}}"; + + $sql = "UPDATE ".$this->tbl_heiheproject." SET expert_activated=?"; + $sth = $this->db->prepare($sql); + if($sth->execute(array($new_status))) + { + return 200; + } + } + + }catch(Execaption $e){ + return 50; + } + + } + + public function expertActiveError($level){ + + $errors = array( + 1 => "该汇交计划还没有邀请专家", + 2 => "您没有被邀请,请联系数据中心进行核实", + 3 => "您的邀请已经激活", + 50 => "服务器错误,请刷新页面重试", + 200 => "在已存在的激活时间中插入了新数据", + 300 => "新激活时间写入" + ); + + } + + //从pgsql读取数组并拆分为php数组 + public function getArray($str){ + if(strlen($str)>3) + { + return explode(",",substr($str,1,-1)); + }else{ + return NULL; + } + } + + //将php数组组装成pgsql中的数组 + public function mkArray($array){ + if(!is_array($array)) + { + return "{".$array."}"; + } + if(count($array)==1) + { + $key = max(array_keys($array)); + return "{".$array[$key]."}"; + } + if(count($array)>1) + { + return "{".join(",",$array)."}"; + } + } + + //从数组中获得键名 + public function getKey($array,$needle) + { + foreach($array as $k=>$v) + { + if($v == $needle) + { + return $k; + } + } + } }