文件类中添加了申请表上传的操作,完善Mail、View、dbh助手,完善Order中相关功能,添加Open模块
This commit is contained in:
parent
48ea533412
commit
b062e86e04
|
@ -47,6 +47,11 @@ class Files{
|
|||
return array("error"=>"文件上传失败,请重新上传");
|
||||
}
|
||||
|
||||
if($file['size'] > 20 * 1024 * 1024)
|
||||
{
|
||||
return array('error'=>"文件大小超出限制");
|
||||
}
|
||||
|
||||
$ext = $this->getFileTextExt($file['name']);
|
||||
$filename = $orderid.".".$ext;
|
||||
|
||||
|
|
|
@ -130,4 +130,10 @@ class View extends \Zend_Controller_Plugin_Abstract
|
|||
}
|
||||
return $protocol."://".$_SERVER['SERVER_NAME'];
|
||||
}
|
||||
|
||||
static function isXmlHttpRequest()
|
||||
{
|
||||
$zfhttp = new \Zend_Controller_Request_Http();
|
||||
return $zfhttp->isXmlHttpRequest();
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ class dbh
|
|||
$sth = $this->db->prepare($sql);
|
||||
if($sth->execute())
|
||||
{
|
||||
$temp = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$temp = $sth->fetch(\PDO::FETCH_ASSOC);
|
||||
return $temp['id'];
|
||||
}else{
|
||||
return false;
|
||||
|
|
|
@ -82,6 +82,12 @@ class Mail
|
|||
$this->mail->setFrom($this->conf->username,$this->conf->name);
|
||||
}
|
||||
|
||||
//设置默认收件人
|
||||
public function setDefaultTo()
|
||||
{
|
||||
$this->mail->addTo($this->conf->username,$this->conf->name);
|
||||
}
|
||||
|
||||
//加载模板
|
||||
public function loadTemplate($id,$data){
|
||||
if(is_numeric($id))
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
namespace Open;
|
||||
|
||||
use Open\Open as open;
|
||||
|
||||
class app extends open implements openbase
|
||||
{
|
||||
public $tbl_oauth_clients = "oauth_clients"; //oauth 客户端表
|
||||
|
||||
public function __construct($db = NULL,$auth = NULL)
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
//获得用户创建的app
|
||||
public function getUserApp($uid = 0)
|
||||
{
|
||||
if(empty($uid))
|
||||
{
|
||||
$uid = $this->user->id;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE user_id=".$this->user->id;
|
||||
$rs = $this->db->query($sql);
|
||||
$rows = $rs->fetchAll();
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
//获得某个App的信息
|
||||
public function getAppInfo($id)
|
||||
{
|
||||
if(empty($id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE id=".$id;
|
||||
$rs = $this->db->query($sql);
|
||||
$rows = $rs->fetch();
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
namespace open;
|
||||
|
||||
interface openbase
|
||||
{
|
||||
public function __construct($db = NULL,$auth = NULL);
|
||||
}
|
||||
|
||||
interface openextend extends openbase
|
||||
{
|
||||
public function load();
|
||||
}
|
||||
|
||||
abstract class open extends \Zend_Controller_Plugin_Abstract implements openextend
|
||||
{
|
||||
public $db;
|
||||
public $auth = NULL;
|
||||
public $user;
|
||||
|
||||
public $checkFiled = array('phone','realname','unit','address');
|
||||
|
||||
public function load($db = NULL,$auth = NULL){
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
if(empty($db))
|
||||
{
|
||||
$this->db = \Zend_Registry::get('db');
|
||||
}else{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
if(empty($auth))
|
||||
{
|
||||
$this->auth = \Zend_Auth::getInstance();
|
||||
if($this->auth->hasIdentity())
|
||||
{
|
||||
$this->user = $this->auth->getIdentity();
|
||||
}
|
||||
}else{
|
||||
$this->auth = false;
|
||||
}
|
||||
}
|
||||
|
||||
//检查用户资料完整性
|
||||
public function checkinfo()
|
||||
{
|
||||
if($this->auth === false)
|
||||
{
|
||||
return "未登陆";
|
||||
}
|
||||
|
||||
include_once("Users.php");
|
||||
$user = new \Users($this->db);
|
||||
$info = $user->getUserInfo($this->user->id);
|
||||
|
||||
foreach($this->checkFiled as $v)
|
||||
{
|
||||
if(empty($info[$v]))
|
||||
{
|
||||
return "请完善个人信息";
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
namespace Open;
|
||||
|
||||
class Server extends \Zend_Controller_Plugin_Abstract
|
||||
{
|
||||
public $db;
|
||||
public $auth = NULL;
|
||||
public $user;
|
||||
private $config;
|
||||
|
||||
public function __construct($db = NULL,$auth = NULL){
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
if(empty($db))
|
||||
{
|
||||
$this->db = \Zend_Registry::get('db');
|
||||
}else{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
if(empty($auth))
|
||||
{
|
||||
$this->auth = \Zend_Auth::getInstance();
|
||||
if($this->auth->hasIdentity())
|
||||
{
|
||||
$this->user = $this->auth->getIdentity();
|
||||
}
|
||||
}else{
|
||||
$this->auth = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function bootstrap()
|
||||
{
|
||||
$dsn = "pgsql:dbname={$this->config->db->params->dbname};host={$this->config->db->params->host}";
|
||||
|
||||
$storage = new \OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $this->config->db->params->username, 'password' => $this->config->db->params->password));
|
||||
|
||||
$server = new \OAuth2\Server($storage);
|
||||
|
||||
$server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage));
|
||||
|
||||
$server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage));
|
||||
|
||||
//应用授权
|
||||
//$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ namespace Order\Manager;
|
|||
|
||||
use Helpers\View as view;
|
||||
use Helpers\dbh;
|
||||
use Order\listener\ManagerListener;
|
||||
|
||||
class Offlineapp
|
||||
{
|
||||
|
@ -16,6 +17,9 @@ class Offlineapp
|
|||
{
|
||||
$this->db = \Zend_Registry::get('db');
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
|
||||
$Listener = new ManagerListener();
|
||||
@$this->events()->attachAggregate($Listener);
|
||||
}
|
||||
|
||||
public function events(\Zend_EventManager_EventCollection $events = NULL)
|
||||
|
@ -50,25 +54,73 @@ class Offlineapp
|
|||
return "参数错误";
|
||||
}
|
||||
|
||||
$data = array(
|
||||
|
||||
);
|
||||
$sql="update dataorder set status=4,ts_received=now() where id=?";
|
||||
$rs = $this->db->query($sql,array($id));
|
||||
$row = $rs->fetch();
|
||||
$sql="update dataorder set status=4,ts_received=now() where offlineappid=$id";
|
||||
|
||||
if($this->db->exec($sql) > 0)
|
||||
{
|
||||
@$this->db->exec("UPDATE offlineapp SET status=4,ts_received=now() WHERE id=$id");
|
||||
@$this->events()->trigger('offlineapp.received', $this, compact('id'));
|
||||
return true;
|
||||
}else{
|
||||
return "接收失败,请重试";
|
||||
}
|
||||
}
|
||||
|
||||
//获取一个申请的详细信息
|
||||
public function getOneAppInfo($id)
|
||||
{
|
||||
$sql = "SELECT off.*,o.status,o.applicationform FROM offlineapp off
|
||||
LEFT JOIN dataorder o ON off.id=o.offlineappid
|
||||
WHERE off.id = $id
|
||||
";
|
||||
$rs = $this->db->query($sql);
|
||||
return $rs->fetchAll();
|
||||
}//
|
||||
|
||||
//重置申请表
|
||||
public function resetAppForm($id)
|
||||
{
|
||||
$sql = "SELECT * FROM dataorder WHERE offlineappid=$id";
|
||||
$rs = $this->db->query($sql);
|
||||
$rows = $rs->fetchAll();
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach($rows as $v)
|
||||
{
|
||||
$ids[] = $v['id'];
|
||||
}
|
||||
|
||||
if(file_exists($rows[0]['applicationform']))
|
||||
{
|
||||
@unlink($rows[0]['applicationform']);
|
||||
}
|
||||
|
||||
if($this->db->exec("UPDATE dataorder SET applicationform=NULL WHERE offlineappid=$id")>0)
|
||||
{
|
||||
@$this->events()->trigger('offlineapp.AppFormReseted', $this, compact('id'));
|
||||
return true;
|
||||
}else{
|
||||
return "重置遇到问题,请重试";
|
||||
}
|
||||
}
|
||||
|
||||
//提交给作者的时候需要处理的内容
|
||||
public function sendToAuthor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
public function offLineAppMakeQuery($opt)
|
||||
{
|
||||
$def = array(
|
||||
'field' => ' o.id as orderid,o.status,o.applicationform,off.*,u.realname,u.username ',
|
||||
'field' => ' off.*,o.id as orderid,o.status,o.applicationform,u.realname,u.username,md.title ',
|
||||
'table' => ' dataorder o ',
|
||||
'join' => ' LEFT JOIN offlineapp off ON off.id=o.offlineappid
|
||||
LEFT JOIN users u ON u.id = off.userid',
|
||||
'order' => ' o.id ASC '
|
||||
LEFT JOIN users u ON u.id = off.userid
|
||||
LEFT JOIN metadata md ON md.uuid=o.uuid',
|
||||
'order' => ' o.id DESC '
|
||||
);
|
||||
return array_merge($def,$opt);
|
||||
}
|
||||
|
@ -76,9 +128,29 @@ class Offlineapp
|
|||
public function fetchNotReceived()
|
||||
{
|
||||
$opt = $this->offLineAppMakeQuery(array(
|
||||
'where' => ' o.offlineappid != -1 AND o.status=1'
|
||||
'where' => ' o.offlineappid != -1 AND o.status=3'
|
||||
));
|
||||
$dbh = new dbh();
|
||||
//echo $dbh->select($opt,true);exit();
|
||||
return $dbh->select($opt);
|
||||
}//未接受的
|
||||
|
||||
public function fetchNoPdf()
|
||||
{
|
||||
$opt = $this->offLineAppMakeQuery(array(
|
||||
'where' => ' o.offlineappid != -1 AND o.status=4 AND (o.applicationform IS NULL OR o.applicationform=\'\') '
|
||||
));
|
||||
$dbh = new dbh();
|
||||
//echo $dbh->select($opt,true);exit();
|
||||
return $dbh->select($opt);
|
||||
}//没有pdf的
|
||||
|
||||
public function fetchNotApprove()
|
||||
{
|
||||
$opt = $this->offLineAppMakeQuery(array(
|
||||
'where' => ' o.offlineappid != -1 AND o.status=4 AND (o.applicationform IS NOT NULL || o.applicationform!=\'\') '
|
||||
));
|
||||
$dbh = new dbh();
|
||||
return $dbh->select($opt);
|
||||
}
|
||||
}//待审核
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
namespace Order;
|
||||
|
||||
use Helpers\View as view;
|
||||
use Mail\Mail;
|
||||
use Order\listener\OrderListener;
|
||||
|
||||
class Order
|
||||
{
|
||||
|
@ -33,6 +35,9 @@ class Order
|
|||
}
|
||||
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
|
||||
$Listener = new OrderListener();
|
||||
@$this->events()->attachAggregate($Listener);
|
||||
}
|
||||
|
||||
public function events(\Zend_EventManager_EventCollection $events = NULL)
|
||||
|
@ -319,10 +324,11 @@ class Order
|
|||
//header("Content-Length: " . strlen($pdfstring));
|
||||
echo $pdf->Output('westdc-data-apply.pdf','S');
|
||||
}else{
|
||||
$fn = $formData['realname'].date('YmdHis').".pdf";
|
||||
//$fn = date('YmdHis').".pdf";
|
||||
//$fn = $formData['realname'].date('YmdHis').".pdf";
|
||||
$fn = date('YmdHis').".pdf";
|
||||
$path = realpath($this->config->offline->savepath);
|
||||
$pdf->Output($path.DIRECTORY_SEPARATOR.$fn, 'F');
|
||||
$pdf->pdflink = $fn;
|
||||
@$pdf->Output($path.DIRECTORY_SEPARATOR.$fn, 'F');
|
||||
}
|
||||
|
||||
if($returnpdf === true)
|
||||
|
@ -332,7 +338,7 @@ class Order
|
|||
}
|
||||
|
||||
//获得要生成pdf的信息
|
||||
public function getOrderItemForPdf($uid = 0)
|
||||
public function getOrderItemForPdf($uid = 0 , $statu = 2)
|
||||
{
|
||||
if(empty($uid))
|
||||
{
|
||||
|
@ -348,13 +354,34 @@ class Order
|
|||
from fund left join mdfund on fund.id=mdfund.fid where mdfund.uuid=d.uuid order by mdfund.place),'\n'::text) as fund,
|
||||
doi.doi as datadoi,doi.authors,doi.publisher,doi.title as doititle,doi.author_en,doi.publisher_en,doi.title_en
|
||||
from dataorder d left join metadata m on d.uuid=m.uuid left join datadoi doi on doi.uuid=d.uuid
|
||||
where d.status=2 and d.userid=? order by d.ts_created desc
|
||||
where d.status=$statu and d.userid=? order by d.ts_created desc
|
||||
";
|
||||
$rows = $this->db->fetchAll($sql,array($uid));
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
//确认申请
|
||||
public function commitApplicationForm($offlineappid)
|
||||
{
|
||||
$user = view::User();
|
||||
|
||||
if($user === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
"user" => empty($user->realname) ? $user->username : $user->realname,
|
||||
"link"=> view::getHostLink() . '/admin/down/offlineapps/ac/view/offlineappid/'.$offlineappid
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
$mail->loadTemplate("offline-pdf-commited",$data);
|
||||
$mail->setDefaultTo();
|
||||
$mail->send();
|
||||
}//确认申请
|
||||
|
||||
//service_type 选择
|
||||
public function serviceTypeTest($type)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
namespace Order\listener;
|
||||
//接口 ,需要实现的Listener中的方法
|
||||
interface ManagerEvents
|
||||
{
|
||||
|
||||
public function received(\Zend_EventManager_Event $e);
|
||||
public function appFormReseted(\Zend_EventManager_Event $e);
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
namespace Order\listener;
|
||||
|
||||
use Order\mount\ManagerOperate;
|
||||
|
||||
//侦听
|
||||
class ManagerListener implements \Zend_EventManager_ListenerAggregate
|
||||
{
|
||||
private $db;
|
||||
|
||||
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 attach(\Zend_EventManager_EventCollection $events)
|
||||
{
|
||||
$this->attachOnOfflineapp($events);
|
||||
}
|
||||
|
||||
public function detach(\Zend_EventManager_EventCollection $events)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function attachOnOfflineapp(\Zend_EventManager_EventCollection $events)
|
||||
{
|
||||
$mountedClass = new ManagerOperate();
|
||||
$events->attach('offlineapp.received', array($mountedClass, 'received'), 100);
|
||||
$events->attach('offlineapp.AppFormReseted',array($mountedClass, 'appFormReseted'), 100);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
namespace Order\mount;
|
||||
|
||||
use Helpers\View as view;
|
||||
use Helpers\dbh;
|
||||
use Mail\Mail;
|
||||
use Order\Manager\Offlineapp;
|
||||
|
||||
//事件中存在的操作
|
||||
class ManagerOperate implements \Order\listener\ManagerEvents
|
||||
{
|
||||
private $db;
|
||||
private $config;
|
||||
|
||||
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 received(\Zend_EventManager_Event $e)
|
||||
{
|
||||
$id = $e->getParam('id');
|
||||
|
||||
try{
|
||||
|
||||
$OM = new Offlineapp();
|
||||
|
||||
$data = $OM->getOneAppInfo($id);
|
||||
|
||||
$emailkeys = array(
|
||||
"user"=>$data[0]['username'],
|
||||
"datalist"=>str_replace(";","\n",$data[0]['datalist']),
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
$mail->loadTemplate("offline-start",$emailkeys);
|
||||
$mail->addTo($data[0]['email'],$data[0]['username']);
|
||||
$mail->send();
|
||||
|
||||
}catch(Exception $e)
|
||||
{
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//申请表重置
|
||||
public function appFormReseted(\Zend_EventManager_Event $e)
|
||||
{
|
||||
$id = $e->getParam('id');
|
||||
|
||||
try{
|
||||
|
||||
$OM = new Offlineapp();
|
||||
|
||||
$data = $OM->getOneAppInfo($id);
|
||||
|
||||
$emailkeys = array(
|
||||
"user"=>$data[0]['username'],
|
||||
"link"=> view::getHostLink() . '/data/order/ac/offline3'
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
$mail->loadTemplate("offline-appformreseted",$emailkeys);
|
||||
$mail->addTo($data[0]['email'],$data[0]['username']);
|
||||
$mail->send();
|
||||
|
||||
}catch(Exception $e)
|
||||
{
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
//专题数据集
|
||||
public function checkDataSource()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -101,6 +101,12 @@ class PdfOperate implements \Order\listener\PdfEvents
|
|||
return "数据篮状态更新失败,请重试";
|
||||
}
|
||||
|
||||
$sql = "UPDATE offlineapp SET pdflink='".$pdf->pdflink."' WHERE id=$oid ";
|
||||
if($this->db->exec($sql) < 0)
|
||||
{
|
||||
return "数据篮状态更新有误,请联系管理员";
|
||||
}
|
||||
|
||||
$this->sendEmail($formData,$pdf);
|
||||
|
||||
}catch(Exception $e)
|
||||
|
@ -116,7 +122,8 @@ class PdfOperate implements \Order\listener\PdfEvents
|
|||
{
|
||||
$data = array(
|
||||
"user"=>$formData['realname'],
|
||||
"datalist"=>str_replace(";","\n",$formData['datalist'])
|
||||
"datalist"=>str_replace(";","\n",$formData['datalist']),
|
||||
"orderlink"=> view::getHostLink() . '/data/order/ac/offline3'
|
||||
);
|
||||
|
||||
$mail = new Mail();
|
||||
|
|
Loading…
Reference in New Issue