From b062e86e04cfcb0f9516341b7287b06ffe601d0d Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 5 Sep 2013 01:52:27 +0000 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=B1=BB=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E7=94=B3=E8=AF=B7=E8=A1=A8=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=9A=84=E6=93=8D=E4=BD=9C=EF=BC=8C=E5=AE=8C=E5=96=84Mail?= =?UTF-8?q?=E3=80=81View=E3=80=81dbh=E5=8A=A9=E6=89=8B=EF=BC=8C=E5=AE=8C?= =?UTF-8?q?=E5=96=84Order=E4=B8=AD=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0Open=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Files/Files.php | 5 + application/module/Helpers/View.php | 6 ++ application/module/Helpers/dbh.php | 2 +- application/module/Mail/Mail.php | 6 ++ application/module/Open/app.php | 45 +++++++++ application/module/Open/open.php | 66 +++++++++++++ application/module/Open/server.php | 50 ++++++++++ .../module/Order/Manager/Offlineapp.php | 94 ++++++++++++++++--- application/module/Order/Order.php | 37 +++++++- .../module/Order/listener/ManagerEvents.php | 10 ++ .../module/Order/listener/ManagerListener.php | 40 ++++++++ .../module/Order/mount/ManagerOperate.php | 92 ++++++++++++++++++ application/module/Order/mount/PdfOperate.php | 9 +- 13 files changed, 444 insertions(+), 18 deletions(-) create mode 100644 application/module/Open/app.php create mode 100644 application/module/Open/open.php create mode 100644 application/module/Open/server.php create mode 100644 application/module/Order/listener/ManagerEvents.php create mode 100644 application/module/Order/listener/ManagerListener.php create mode 100644 application/module/Order/mount/ManagerOperate.php diff --git a/application/module/Files/Files.php b/application/module/Files/Files.php index 44b19014..7be0fd5c 100644 --- a/application/module/Files/Files.php +++ b/application/module/Files/Files.php @@ -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; diff --git a/application/module/Helpers/View.php b/application/module/Helpers/View.php index 4643f6c9..703b189b 100644 --- a/application/module/Helpers/View.php +++ b/application/module/Helpers/View.php @@ -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(); + } } \ No newline at end of file diff --git a/application/module/Helpers/dbh.php b/application/module/Helpers/dbh.php index 0a434f16..83791cd1 100644 --- a/application/module/Helpers/dbh.php +++ b/application/module/Helpers/dbh.php @@ -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; diff --git a/application/module/Mail/Mail.php b/application/module/Mail/Mail.php index c8e3656e..8736bffb 100644 --- a/application/module/Mail/Mail.php +++ b/application/module/Mail/Mail.php @@ -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)) diff --git a/application/module/Open/app.php b/application/module/Open/app.php new file mode 100644 index 00000000..23d3b377 --- /dev/null +++ b/application/module/Open/app.php @@ -0,0 +1,45 @@ +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; + } + + +} \ No newline at end of file diff --git a/application/module/Open/open.php b/application/module/Open/open.php new file mode 100644 index 00000000..8a6445df --- /dev/null +++ b/application/module/Open/open.php @@ -0,0 +1,66 @@ +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; + } + +} \ No newline at end of file diff --git a/application/module/Open/server.php b/application/module/Open/server.php new file mode 100644 index 00000000..ee0b7408 --- /dev/null +++ b/application/module/Open/server.php @@ -0,0 +1,50 @@ +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; + } + +} \ No newline at end of file diff --git a/application/module/Order/Manager/Offlineapp.php b/application/module/Order/Manager/Offlineapp.php index 3b01191d..dedf7f27 100644 --- a/application/module/Order/Manager/Offlineapp.php +++ b/application/module/Order/Manager/Offlineapp.php @@ -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); - } + }//待审核 } \ No newline at end of file diff --git a/application/module/Order/Order.php b/application/module/Order/Order.php index 40f358cd..ef7cc4de 100644 --- a/application/module/Order/Order.php +++ b/application/module/Order/Order.php @@ -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) { diff --git a/application/module/Order/listener/ManagerEvents.php b/application/module/Order/listener/ManagerEvents.php new file mode 100644 index 00000000..2fedd65f --- /dev/null +++ b/application/module/Order/listener/ManagerEvents.php @@ -0,0 +1,10 @@ +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); + } + + +} \ No newline at end of file diff --git a/application/module/Order/mount/ManagerOperate.php b/application/module/Order/mount/ManagerOperate.php new file mode 100644 index 00000000..8929337b --- /dev/null +++ b/application/module/Order/mount/ManagerOperate.php @@ -0,0 +1,92 @@ +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() + { + + } + +} \ No newline at end of file diff --git a/application/module/Order/mount/PdfOperate.php b/application/module/Order/mount/PdfOperate.php index d091cb2c..7639142d 100644 --- a/application/module/Order/mount/PdfOperate.php +++ b/application/module/Order/mount/PdfOperate.php @@ -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();