db = \Zend_Registry::get('db'); }else{ $this->db = $db; } $this->config = \Zend_Registry::get('config'); } //提交申请 public function submit(\Zend_EventManager_Event $e) { $uuid = $e->getParam('uuid'); $uid = $e->getParam('uid'); try{ if($this->checkOrderUUID($uuid) !== false) { return "此数据尚未正式发布,还不能申请"; } if($this->checkOrderNum(true,$uid) === false) { return "您的数据篮中存放的数据已达到可申请的数量"; } if($this->checkOrderHas($uuid,$uid)) { return "此数据已经在数据篮中"; } }catch(Exception $e) { view::Dump($e->getMessage()); } return true; } //检查元数据是否已发布(存在于metadata表中) public function checkOrderUUID($uuid) { $sql = "select count(*) as mdcount from {$this->tbl_metadata} where uuid=?"; $rs = $this->db->fetchRow($this->db->quoteInto($sql,$uuid)); if($rs['mdcount'] == 0) { return true; }else{ return false; } } //检查用户是否已经提交了该数据的申请 public function checkOrderHas($uuid,$uid = 0) { if(empty($uid)) { $uid = view::User('id'); } $sql = "select count(*) as datacount from {$this->tbl_dataorder} where (ts_approved is null) and userid=$uid and uuid=? and status in (1,2,3,4)"; $rs = $this->db->fetchRow($this->db->quoteInto($sql,$uuid),\PDO::FETCH_BOTH); if($rs['datacount']>=1) { return true; }else{ return false; } }//CheckOrderHas() //检查用户已经在数据篮中的申请的数量 // 已经超过返回 true public function checkOrderNum($bool = true,$uid = 0) { if(empty($uid)) { $uid = view::User('id'); } $sql = "select count(*) as datacount from {$this->tbl_dataorder} where (ts_approved is null) and userid=? and status>0 and status<3"; $rs = $this->db->fetchRow($this->db->quoteInto($sql,$uid)); if($bool === true) { if($rs['datacount'] <= $this->config->download->max - 1) { return true; }else{ return false; } }else{ return $rs['datacount']; } }//checkOrderNum //检查数据来源 public function checksource(\Zend_EventManager_Event $e) { $uuid = $e->getParam('uuid'); return $this->getDataService($uuid); } //获得数据服务类型 public function getDataService($uuid){ $sql = "SELECT * FROM dataservice WHERE uuid='$uuid'"; $rs = $this->db->query($sql); $row = $rs->fetch(\PDO::FETCH_BOTH); if(isset($row['uuid']) && !empty($row['uuid'])) { return $row; }else{ return NULL; } } }