对数据篮的数据提交过程进行了模块化改造

This commit is contained in:
Li Jianxuan 2013-08-28 09:50:08 +00:00
parent f66616d0dc
commit 6152c36246
8 changed files with 212 additions and 88 deletions

View File

@ -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');
}
@ -1870,23 +1834,25 @@ class DataController extends Zend_Controller_Action
$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";

View File

@ -97,7 +97,22 @@
<div class="control-group">
<label class="control-label" name="project_title">项目名称</label>
<div class="controls">
<input type="text" name="project_title" id="project_title" value="<?= empty($this->formData['project_title']) ? "":$this->formData['project_title']?>" helper="formText" class="input-block-level"> </div>
<input type="text" name="project_title" id="project_title" value="<?= empty($this->formData['project_title']) ? "":$this->formData['project_title']?>" helper="formText" class="input-block-level">
</div>
</div>
<div class="control-group">
<label class="control-label" name="leader">项目负责人</label>
<div class="controls">
<input type="text" name="leader" id="leader" value="<?= empty($this->formData['leader']) ? "":$this->formData['leader']?>" helper="formText" class="input">
</div>
</div>
<div class="control-group">
<label class="control-label" name="leadertitle">项目负责人职称</label>
<div class="controls">
<input type="text" name="leadertitle" id="leadertitle" value="<?= empty($this->formData['leadertitle']) ? "":$this->formData['leadertitle']?>" helper="formText" class="input">
</div>
</div>
<div class="control-group">

View File

@ -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;
}
}
}

View File

@ -1,7 +1,7 @@
<?php
namespace Mail;
use helper\dbh;
use Helpers\dbh;
class Mail
{
@ -47,18 +47,17 @@ class Mail
$this->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

View File

@ -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的信息

View File

@ -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);
}
}

View File

@ -6,4 +6,7 @@ interface PdfEvents
//检查该填写的字段
public function updateUserInfo(\Zend_EventManager_Event $e);
//提交成功后
public function orderSubmited(\Zend_EventManager_Event $e);
}

View File

@ -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();
}
}