2013-07-17 09:53:44 +00:00
|
|
|
<?php
|
2013-11-05 03:57:01 +00:00
|
|
|
namespace Order\Mount;
|
2013-08-26 02:33:44 +00:00
|
|
|
|
2013-11-05 03:57:01 +00:00
|
|
|
use \Helpers\View as view;
|
2013-07-17 09:53:44 +00:00
|
|
|
|
|
|
|
//事件中存在的操作
|
2013-11-05 03:57:01 +00:00
|
|
|
class OrderOperate implements \Order\Listener\OrderEvents
|
2013-07-17 09:53:44 +00:00
|
|
|
{
|
|
|
|
private $db;
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
//!!!!!!important!!!!!
|
|
|
|
//不同项目使用时是否要修改此项??
|
2013-11-20 09:53:33 +00:00
|
|
|
public $tbl_metadata = "normalmetadata";
|
2013-07-17 09:53:44 +00:00
|
|
|
public $tbl_dataorder = "dataorder";
|
|
|
|
|
|
|
|
function __construct($db = NULL)
|
|
|
|
{
|
|
|
|
if(empty($db))
|
|
|
|
{
|
|
|
|
$this->db = \Zend_Registry::get('db');
|
|
|
|
}else{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->config = \Zend_Registry::get('config');
|
|
|
|
}
|
|
|
|
|
|
|
|
//提交申请
|
2013-07-19 10:19:59 +00:00
|
|
|
public function submit(\Zend_EventManager_Event $e)
|
2013-07-17 09:53:44 +00:00
|
|
|
{
|
|
|
|
$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)
|
|
|
|
{
|
2013-11-05 03:57:01 +00:00
|
|
|
view::Dump($e->getMessage());
|
2013-07-17 09:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-17 09:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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)";
|
2013-07-25 09:13:57 +00:00
|
|
|
$rs = $this->db->fetchRow($this->db->quoteInto($sql,$uuid),\PDO::FETCH_BOTH);
|
2013-07-17 09:53:44 +00:00
|
|
|
|
|
|
|
if($rs['datacount']>=1)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}//CheckOrderHas()
|
|
|
|
|
|
|
|
//检查用户已经在数据篮中的申请的数量
|
|
|
|
// 已经超过返回 true
|
|
|
|
public function checkOrderNum($bool = true,$uid = 0)
|
|
|
|
{
|
|
|
|
if(empty($uid))
|
|
|
|
{
|
2013-08-26 02:33:44 +00:00
|
|
|
$uid = view::User('id');
|
2013-07-17 09:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
2013-07-19 10:19:59 +00:00
|
|
|
//检查数据来源
|
|
|
|
public function checksource(\Zend_EventManager_Event $e)
|
|
|
|
{
|
|
|
|
$uuid = $e->getParam('uuid');
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
return $this->getDataService($uuid);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//获得数据服务类型
|
|
|
|
public function getDataService($uuid){
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM dataservice WHERE uuid='$uuid'";
|
2013-07-19 10:19:59 +00:00
|
|
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
|
2013-07-25 09:13:57 +00:00
|
|
|
$row = $rs->fetch(\PDO::FETCH_BOTH);
|
2013-07-19 10:19:59 +00:00
|
|
|
|
|
|
|
if(isset($row['uuid']) && !empty($row['uuid']))
|
|
|
|
{
|
2013-07-24 10:11:14 +00:00
|
|
|
return $row;
|
2013-07-19 10:19:59 +00:00
|
|
|
}else{
|
2013-07-24 10:11:14 +00:00
|
|
|
return NULL;
|
2013-07-19 10:19:59 +00:00
|
|
|
}
|
2013-07-24 10:11:14 +00:00
|
|
|
|
2013-07-19 10:19:59 +00:00
|
|
|
}
|
2013-07-17 09:53:44 +00:00
|
|
|
|
|
|
|
}
|