From 6152c36246be0c07b32838b614ad81387e2fedf2 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 28 Aug 2013 09:50:08 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=95=B0=E6=8D=AE=E7=AF=AE=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8F=90=E4=BA=A4=E8=BF=87=E7=A8=8B=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BA=86=E6=A8=A1=E5=9D=97=E5=8C=96=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/DataController.php | 104 ++++++------------ .../default/views/scripts/data/pdf.phtml | 17 ++- application/module/Helpers/dbh.php | 43 +++++++- application/module/Mail/Mail.php | 9 +- application/module/Order/Order.php | 61 ++++++++-- .../module/Order/listener/OrderListener.php | 1 + .../module/Order/listener/PdfEvents.php | 3 + application/module/Order/mount/PdfOperate.php | 62 ++++++++++- 8 files changed, 212 insertions(+), 88 deletions(-) diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index de672305..8e4c7071 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1646,7 +1646,7 @@ class DataController extends Zend_Controller_Action $service_type = $order->serviceTypeTest($state['service_type']); if($service_type !== false) { - view::Post($this,$service_type,$state['service_url']."?href=".urlencode(\view::getHostLink()."/data/order/")."&uuid=".$state['uuid']."&uid=".$userid); + view::Post($this,$service_type,$state['service_url']."?href=".urlencode(view::getHostLink()."/data/order/")."&uuid=".$state['uuid']."&uid=".$userid); }else{ $this->view->msg = view::Msg('alert-error',"无法申请:此元数据的数据类型未知"); } @@ -1797,59 +1797,23 @@ class DataController extends Zend_Controller_Action } elseif ($formData['submit']) { //提交 //生成PDF - $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join heihemetadata m on d.uuid=m.uuid where d.status=2 and d.userid=?"; - $list=$this->db->fetchAll($sql,array($userid)); - foreach($list as $i=>$row) @$formData['heihelist'].=($i+1).". ".$row['title'].";"; - $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join normalmetadata m on d.uuid=m.uuid where d.uuid not in (select uuid from heihemetadata) and d.status=2 and d.userid=?"; - $list=$this->db->fetchAll($sql,array($userid)); - foreach($list as $i=>$row) @$formData['westdclist'].=($i+1).". ".$row['title'].";"; - $pdf = new ApplicantPDF(); - $pdf->template=$this->view->config->offline->template; - $pdf->heihetemplate=$this->view->config->offline->heihetemplate; - $pdf->data = $formData; - $pdf->data['project'].='['.$formData['project_title'].' | '.$formData['project_type'].' | '.$formData['project_id'].']'; - if (isset($formData['westdclist'])) $pdf->drawWestdc(); - if (isset($formData['heihelist'])) $pdf->drawHeihe(); - $pdf->addRef($rows); - $pdf->addSecurity($this->view->config->offline->security); - $fn=$formData['realname'].date('YmdHis').".pdf"; - $pdf->Output($this->view->config->offline->savepath."/".$fn, 'F'); - - //保存到数据库 - $sql="select id from offlineapp where userid=? and pdflink is null and (ts_approved is null)"; - $row=$this->db->fetchRow($sql,array($userid)); - if ($row) { - $sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now(),pdflink=?,project_type=?,project_id=?,project_title=? where id=?"; - $this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$formData['project_type'],$formData['project_id'],$formData['project_title'],$row['id'])); - } else { - $sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist,pdflink,project_type,project_id,project_title) values(?,?,?,?,?,?,?,?,?,?,?,?,?)"; - $this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$formData['project_type'],$formData['project_id'],$formData['project_title'])); - $sql="select id from offlineapp where userid=? and pdflink=?"; - $row=$this->db->fetchRow($sql,array($userid,$fn)); + + $orderListener = new OrderListener(); + + @$order->events()->attachAggregate($orderListener); + + $order->setPdfData($rows); + + $s = $order->SubmitOrder($formData); + + if($s !== true) + { + $this->view->error = view::Msg('alert-error',$s); + return true; } - $sql="update dataorder set status=3, offlineappid=? where status=2 and userid=?"; - $this->db->query($sql,array($row['id'],$userid)); - - //发送用户邮件进行信息提示和说明 - //$mail = new Zend_Mail('utf-8'); - - $data = array( - "user"=>$formData['realname'], - "datalist"=>str_replace(";","\n",$datalist) - ); - $mailtp=new EmailText($this->db,'offline-email',$data); - $mail = new WestdcMailer($this->view->config->smtp); - $mail->setBodyText($mailtp->getBody()); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - $mail->setSubject($mailtp->getSubject()); - $attach=$mail->createAttachment($pdf->Output('applicant','S')); - $attach->filename='数据申请-'.$formData['realname'].'.pdf'; - $mail->send(); - $this->_helper->viewRenderer('order'); //跳转到/data/order,并提示帮助信息,告知用户已经发送EMAIL - $this->view->msg=view::Msg('alert-success',"提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表、签字后扫描为pdf并email给数据中心服务组(仍可以采用邮寄方式),具体信息请参考邮件说明。",0); + $this->view->msg = view::Msg('alert-success',"提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表、签字后扫描为pdf并email给数据中心服务组(仍可以采用邮寄方式),具体信息请参考邮件说明。",0); if (empty($ac)) $ac='offline3'; //$this->_redirect('/data/order'); } @@ -1869,24 +1833,26 @@ class DataController extends Zend_Controller_Action } else $this->view->msg=view::Msg('alert-error',"错误:您还没有提交任何离线申请的数据,或您的数据申请已经提交(等待处理过程中)!",0); } - - if ($ac=='' || $ac=='online') - { - $status='d.status=0 and d.ts_approved is not null'; - $this->view->tabID='order-online'; - } else if ($ac=='offline1') { - $status='d.status in (1)'; - $this->view->tabID='order-offline1'; - } else if ($ac=='offline2') { - $status='d.status in (2)'; - $this->view->tabID='order-offline2'; - } else if ($ac=='offline3') { - $status='d.status in (3,4)'; - $this->view->tabID='order-offline3'; - } else if ($ac=='offline4') { - $status='d.status in (5)'; - $this->view->tabID='order-offline4'; - } + + //index + + if ($ac=='' || $ac=='online') + { + $status='d.status=0 and d.ts_approved is not null'; + $this->view->tabID='order-online'; + } else if ($ac=='offline1') { + $status='d.status in (1)'; + $this->view->tabID='order-offline1'; + } else if ($ac=='offline2') { + $status='d.status in (2)'; + $this->view->tabID='order-offline2'; + } else if ($ac=='offline3') { + $status='d.status in (3,4)'; + $this->view->tabID='order-offline3'; + } else if ($ac=='offline4') { + $status='d.status in (5)'; + $this->view->tabID='order-offline4'; + } //显示已经申请的数据,包括已经提交的申请和未提交的申请,还有已经处理完成的申请,正在进行的在线数据下载 $sql="select d.*,m.title,m.datatype from dataorder d left join metadata m on d.uuid=m.uuid where $status and d.userid=? order by d.status,d.ts_created desc"; diff --git a/application/default/views/scripts/data/pdf.phtml b/application/default/views/scripts/data/pdf.phtml index 4513968e..908fd5f9 100644 --- a/application/default/views/scripts/data/pdf.phtml +++ b/application/default/views/scripts/data/pdf.phtml @@ -97,7 +97,22 @@
- formData['project_title']?>" helper="formText" class="input-block-level">
+ formData['project_title']?>" helper="formText" class="input-block-level"> +
+ + +
+ +
+ formData['leader']?>" helper="formText" class="input"> +
+
+ +
+ +
+ formData['leadertitle']?>" helper="formText" class="input"> +
diff --git a/application/module/Helpers/dbh.php b/application/module/Helpers/dbh.php index cbadc51e..0a434f16 100644 --- a/application/module/Helpers/dbh.php +++ b/application/module/Helpers/dbh.php @@ -6,9 +6,14 @@ class dbh private $db; //传入PDO对象. private $product = 0; //产品环境 - function __construct($db) + function __construct($db = NULL) { - $this->db = $db; + if(empty($db)) + { + $this->db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } } function insert($table,$data,$return=false) @@ -136,4 +141,38 @@ class dbh }//update + //select + public function select($opt,$debug = false) + { + $field = (isset($opt['field']) && !empty($opt['field'])) ? $opt['field']:"*"; + $tbl = (isset($opt['table']) && !empty($opt['table'])) ? $opt['table'] : ""; + $join = (isset($opt['join']) && !empty($opt['join'])) ? $opt['join'] : ""; + $wheresql = (isset($opt['where']) && !empty($opt['where'])) ? " WHERE ".$opt['where']:" "; + $limit = (isset($opt['limit']) && !empty($opt['limit'])) ? " LIMIT ".$opt['limit']:""; + $offset = (isset($opt['start']) && !empty($opt['start'])) ? " OFFSET ".$opt['start']:""; + $order = (isset($opt['order']) && !empty($opt['order'])) ? " ORDER BY ".$opt['order']:""; + $order .= (isset($opt['sort']) && !empty($opt['sort']) && $order !== '') ? " ".$opt['sort']:""; + $sql = "SELECT $field FROM $tbl + " . $join . " + " . $wheresql . " + " . $order . " + " . $limit . " + " . $offset . " + "; + if($debug) return $sql; + + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } + + public function chk($p) + { + if(!isset($p) || empty($p)) + { + return false; + }else{ + return true; + } + } + } \ No newline at end of file diff --git a/application/module/Mail/Mail.php b/application/module/Mail/Mail.php index b6c0cecc..c8e3656e 100644 --- a/application/module/Mail/Mail.php +++ b/application/module/Mail/Mail.php @@ -1,7 +1,7 @@ conf->host = $this->config->smtp->host; $this->conf->username = $this->config->smtp->username; $this->conf->password = $this->config->smtp->password; - $this->conf->port = 465; + $this->conf->port = 994; $this->conf->ssl = $this->config->smtp->ssl; $this->conf->auth = $this->config->smtp->auth; - - $this->conf->name = $this->config->title->site; + $this->conf->name = $this->config->smtp->name; } private function smtp() { $mail_config = array( 'ssl' => $this->conf->ssl, - 'port' => $this->conf->port, + //'port' => $this->conf->port, 'auth' => $this->conf->auth, 'username' => $this->conf->username, 'password' => $this->conf->password diff --git a/application/module/Order/Order.php b/application/module/Order/Order.php index 8deebf20..abfe5c47 100644 --- a/application/module/Order/Order.php +++ b/application/module/Order/Order.php @@ -237,13 +237,46 @@ class Order }//SaveOrder - //发送邮件 - public function SendOrderEmail(){ + //正式提交 + public function SubmitOrder($formData,$uid = 0) + { + if(empty($uid) || !is_numeric($uid)) + { + $uid = view::User('id'); + } - } + $results = $this->events()->trigger('order.formcheck', $this, compact('formData')); + $data = $results->bottom(); + + if($data !== true) + { + return $data; + } + + $pdf = $this->pdfPrint($formData,$uid,true,true); + + $returnid = true; + $results = $this->events()->trigger('order.onUpdate', $this, compact('formData','uid','returnid')); + $oid = $results->bottom(); + + if(!is_numeric($oid) || $oid<1) + { + return "参数错误"; + } + + $results = $this->events()->trigger('order.onSubmited', $this, compact('formData','uid','oid','pdf')); + $data = $results->bottom(); + + if($data !== true) + { + return $data; + } + + return true; + }//SubmitOrder() //生成pdf - public function pdfPrint($formData,$userid = 0) + public function pdfPrint($formData,$userid = 0,$save = false,$returnpdf = false) { $sql="SELECT m.title||'('||m.filesize::text||'MB)' as title FROM dataorder d RIGHT JOIN heihemetadata m ON d.uuid=m.uuid @@ -278,11 +311,23 @@ class Order $pdf->addSecurity($this->config->offline->security); - header("Content-Disposition: inline; filename=westdc-data-apply.pdf"); - header("Content-Type:application/pdf"); + if($save === false) + { + header("Content-Disposition: inline; filename=westdc-data-apply.pdf"); + header("Content-Type:application/pdf"); + //header("Content-Length: " . strlen($pdfstring)); + echo $pdf->Output('westdc-data-apply.pdf','S'); + }else{ + $fn = $formData['realname'].date('YmdHis').".pdf"; + //$fn = date('YmdHis').".pdf"; + $path = realpath($this->config->offline->savepath); + $pdf->Output($path.DIRECTORY_SEPARATOR.$fn, 'F'); + } - //header("Content-Length: " . strlen($pdfstring)); - echo $pdf->Output('westdc-data-apply.pdf','S'); + if($returnpdf === true) + { + return $pdf; + } } //获得要生成pdf的信息 diff --git a/application/module/Order/listener/OrderListener.php b/application/module/Order/listener/OrderListener.php index c5bb1738..23ccf98c 100644 --- a/application/module/Order/listener/OrderListener.php +++ b/application/module/Order/listener/OrderListener.php @@ -46,6 +46,7 @@ class OrderListener implements \Zend_EventManager_ListenerAggregate $PdfClass = new PdfOperate(); $events->attach('order.onUpdate', array($PdfClass, 'updateUserInfo'), 100); + $events->attach('order.onSubmited', array($PdfClass, 'orderSubmited'), 100); } } \ No newline at end of file diff --git a/application/module/Order/listener/PdfEvents.php b/application/module/Order/listener/PdfEvents.php index c4399978..a72bbe57 100644 --- a/application/module/Order/listener/PdfEvents.php +++ b/application/module/Order/listener/PdfEvents.php @@ -6,4 +6,7 @@ interface PdfEvents //检查该填写的字段 public function updateUserInfo(\Zend_EventManager_Event $e); + //提交成功后 + public function orderSubmited(\Zend_EventManager_Event $e); + } \ No newline at end of file diff --git a/application/module/Order/mount/PdfOperate.php b/application/module/Order/mount/PdfOperate.php index 7d49fdf1..398e59a1 100644 --- a/application/module/Order/mount/PdfOperate.php +++ b/application/module/Order/mount/PdfOperate.php @@ -3,6 +3,7 @@ namespace Order\mount; use Helpers\View as view; use Helpers\dbh; +use Mail\Mail; //事件中存在的操作 class PdfOperate implements \Order\listener\PdfEvents @@ -35,6 +36,7 @@ class PdfOperate implements \Order\listener\PdfEvents //在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息 $formData = $e->getParam('formData'); $uid = $e->getParam('uid'); + $returnid = $e->getParam('returnid'); try{ @@ -46,13 +48,25 @@ class PdfOperate implements \Order\listener\PdfEvents $formData['username'] = $formData['realname']; unset($formData['realname']); unset($formData['save']); + unset($formData['submit']); if ($row) { $s = $dbh->update($this->tbl_offlineapp,$formData," id={$row['id']} "); - return $s; + if(empty($returnid)) + { + return $s; + }else{ + return $row['id']; + } } else { - $s = $dbh->insert($this->tbl_offlineapp,$formData); - return $s; + if(empty($returnid)) + { + $s = $dbh->insert($this->tbl_offlineapp,$formData); + return $s; + }else{ + $id = $dbh->insert($this->tbl_offlineapp,$formData,true); + return $id; + } } }catch(Exception $e) @@ -63,4 +77,46 @@ class PdfOperate implements \Order\listener\PdfEvents return true; } + //申请成功提交之后 + public function orderSubmited(\Zend_EventManager_Event $e) + { + $formData = $e->getParam('formData'); + $uid = (int)$e->getParam('uid'); + $oid = (int)$e->getParam('oid'); + $pdf = $e->getParam('pdf'); + + try{ + + $sql="update dataorder set status=3, offlineappid=$oid where status=2 and userid=$uid"; + if($this->db->exec($sql) < 0) + { + return "数据篮状态更新失败,请重试"; + } + + $this->sendEmail($formData,$pdf); + + }catch(Exception $e) + { + return $e->getMessage(); + } + + return true; + } + + //发送邮件通知 + public function sendEmail($formData,$pdf) + { + $data = array( + "user"=>$formData['realname'], + "datalist"=>str_replace(";","\n",$formData['datalist']) + ); + + $mail = new Mail(); + $mail->loadTemplate("offline-email",$data); + $mail->addTo($formData['email'],$formData['realname']); + $attach = $mail->mail->createAttachment($pdf->Output('applicant','S')); + $attach->filename = '数据申请-'.$formData['realname'].'.pdf'; + $mail->send(); + } + } \ No newline at end of file