117 lines
2.6 KiB
PHP
117 lines
2.6 KiB
PHP
|
<?php
|
||
|
namespace order\mount;
|
||
|
include_once("helper/view.php");
|
||
|
|
||
|
//事件中存在的操作
|
||
|
class OrderOperate implements \order\listener\OrderEvents
|
||
|
{
|
||
|
private $db;
|
||
|
private $config;
|
||
|
|
||
|
//!!!!!!important!!!!!
|
||
|
//不同项目使用时是否要修改此项??
|
||
|
public $tbl_metadata = "heihemetadata";
|
||
|
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');
|
||
|
}
|
||
|
|
||
|
//提交申请
|
||
|
public function submit($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));
|
||
|
|
||
|
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
|
||
|
|
||
|
|
||
|
|
||
|
}
|