对数据篮的数据提交过程进行了模块化改造
This commit is contained in:
parent
f66616d0dc
commit
6152c36246
|
@ -1646,7 +1646,7 @@ class DataController extends Zend_Controller_Action
|
||||||
$service_type = $order->serviceTypeTest($state['service_type']);
|
$service_type = $order->serviceTypeTest($state['service_type']);
|
||||||
if($service_type !== false)
|
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{
|
}else{
|
||||||
$this->view->msg = view::Msg('alert-error',"无法申请:此元数据的数据类型未知");
|
$this->view->msg = view::Msg('alert-error',"无法申请:此元数据的数据类型未知");
|
||||||
}
|
}
|
||||||
|
@ -1797,56 +1797,20 @@ class DataController extends Zend_Controller_Action
|
||||||
} elseif ($formData['submit']) {
|
} elseif ($formData['submit']) {
|
||||||
//提交
|
//提交
|
||||||
//生成PDF
|
//生成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');
|
|
||||||
|
|
||||||
//保存到数据库
|
$orderListener = new OrderListener();
|
||||||
$sql="select id from offlineapp where userid=? and pdflink is null and (ts_approved is null)";
|
|
||||||
$row=$this->db->fetchRow($sql,array($userid));
|
@$order->events()->attachAggregate($orderListener);
|
||||||
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=?";
|
$order->setPdfData($rows);
|
||||||
$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 {
|
$s = $order->SubmitOrder($formData);
|
||||||
$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']));
|
if($s !== true)
|
||||||
$sql="select id from offlineapp where userid=? and pdflink=?";
|
{
|
||||||
$row=$this->db->fetchRow($sql,array($userid,$fn));
|
$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
|
//跳转到/data/order,并提示帮助信息,告知用户已经发送EMAIL
|
||||||
$this->view->msg = view::Msg('alert-success',"提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表、签字后扫描为pdf并email给数据中心服务组(仍可以采用邮寄方式),具体信息请参考邮件说明。",0);
|
$this->view->msg = view::Msg('alert-success',"提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表、签字后扫描为pdf并email给数据中心服务组(仍可以采用邮寄方式),具体信息请参考邮件说明。",0);
|
||||||
|
@ -1870,6 +1834,8 @@ class DataController extends Zend_Controller_Action
|
||||||
$this->view->msg=view::Msg('alert-error',"错误:您还没有提交任何离线申请的数据,或您的数据申请已经提交(等待处理过程中)!",0);
|
$this->view->msg=view::Msg('alert-error',"错误:您还没有提交任何离线申请的数据,或您的数据申请已经提交(等待处理过程中)!",0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//index
|
||||||
|
|
||||||
if ($ac=='' || $ac=='online')
|
if ($ac=='' || $ac=='online')
|
||||||
{
|
{
|
||||||
$status='d.status=0 and d.ts_approved is not null';
|
$status='d.status=0 and d.ts_approved is not null';
|
||||||
|
|
|
@ -97,7 +97,22 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" name="project_title">项目名称</label>
|
<label class="control-label" name="project_title">项目名称</label>
|
||||||
<div class="controls">
|
<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>
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
|
|
|
@ -6,10 +6,15 @@ class dbh
|
||||||
private $db; //传入PDO对象.
|
private $db; //传入PDO对象.
|
||||||
private $product = 0; //产品环境
|
private $product = 0; //产品环境
|
||||||
|
|
||||||
function __construct($db)
|
function __construct($db = NULL)
|
||||||
{
|
{
|
||||||
|
if(empty($db))
|
||||||
|
{
|
||||||
|
$this->db = \Zend_Registry::get('db');
|
||||||
|
}else{
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function insert($table,$data,$return=false)
|
function insert($table,$data,$return=false)
|
||||||
{
|
{
|
||||||
|
@ -136,4 +141,38 @@ class dbh
|
||||||
|
|
||||||
}//update
|
}//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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Mail;
|
namespace Mail;
|
||||||
|
|
||||||
use helper\dbh;
|
use Helpers\dbh;
|
||||||
|
|
||||||
class Mail
|
class Mail
|
||||||
{
|
{
|
||||||
|
@ -47,18 +47,17 @@ class Mail
|
||||||
$this->conf->host = $this->config->smtp->host;
|
$this->conf->host = $this->config->smtp->host;
|
||||||
$this->conf->username = $this->config->smtp->username;
|
$this->conf->username = $this->config->smtp->username;
|
||||||
$this->conf->password = $this->config->smtp->password;
|
$this->conf->password = $this->config->smtp->password;
|
||||||
$this->conf->port = 465;
|
$this->conf->port = 994;
|
||||||
$this->conf->ssl = $this->config->smtp->ssl;
|
$this->conf->ssl = $this->config->smtp->ssl;
|
||||||
$this->conf->auth = $this->config->smtp->auth;
|
$this->conf->auth = $this->config->smtp->auth;
|
||||||
|
$this->conf->name = $this->config->smtp->name;
|
||||||
$this->conf->name = $this->config->title->site;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function smtp()
|
private function smtp()
|
||||||
{
|
{
|
||||||
$mail_config = array(
|
$mail_config = array(
|
||||||
'ssl' => $this->conf->ssl,
|
'ssl' => $this->conf->ssl,
|
||||||
'port' => $this->conf->port,
|
//'port' => $this->conf->port,
|
||||||
'auth' => $this->conf->auth,
|
'auth' => $this->conf->auth,
|
||||||
'username' => $this->conf->username,
|
'username' => $this->conf->username,
|
||||||
'password' => $this->conf->password
|
'password' => $this->conf->password
|
||||||
|
|
|
@ -237,13 +237,46 @@ class Order
|
||||||
|
|
||||||
}//SaveOrder
|
}//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
|
//生成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
|
$sql="SELECT m.title||'('||m.filesize::text||'MB)' as title FROM dataorder d
|
||||||
RIGHT JOIN heihemetadata m ON d.uuid=m.uuid
|
RIGHT JOIN heihemetadata m ON d.uuid=m.uuid
|
||||||
|
@ -278,11 +311,23 @@ class Order
|
||||||
|
|
||||||
$pdf->addSecurity($this->config->offline->security);
|
$pdf->addSecurity($this->config->offline->security);
|
||||||
|
|
||||||
|
if($save === false)
|
||||||
|
{
|
||||||
header("Content-Disposition: inline; filename=westdc-data-apply.pdf");
|
header("Content-Disposition: inline; filename=westdc-data-apply.pdf");
|
||||||
header("Content-Type:application/pdf");
|
header("Content-Type:application/pdf");
|
||||||
|
|
||||||
//header("Content-Length: " . strlen($pdfstring));
|
//header("Content-Length: " . strlen($pdfstring));
|
||||||
echo $pdf->Output('westdc-data-apply.pdf','S');
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
if($returnpdf === true)
|
||||||
|
{
|
||||||
|
return $pdf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//获得要生成pdf的信息
|
//获得要生成pdf的信息
|
||||||
|
|
|
@ -46,6 +46,7 @@ class OrderListener implements \Zend_EventManager_ListenerAggregate
|
||||||
|
|
||||||
$PdfClass = new PdfOperate();
|
$PdfClass = new PdfOperate();
|
||||||
$events->attach('order.onUpdate', array($PdfClass, 'updateUserInfo'), 100);
|
$events->attach('order.onUpdate', array($PdfClass, 'updateUserInfo'), 100);
|
||||||
|
$events->attach('order.onSubmited', array($PdfClass, 'orderSubmited'), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,4 +6,7 @@ interface PdfEvents
|
||||||
//检查该填写的字段
|
//检查该填写的字段
|
||||||
public function updateUserInfo(\Zend_EventManager_Event $e);
|
public function updateUserInfo(\Zend_EventManager_Event $e);
|
||||||
|
|
||||||
|
//提交成功后
|
||||||
|
public function orderSubmited(\Zend_EventManager_Event $e);
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ namespace Order\mount;
|
||||||
|
|
||||||
use Helpers\View as view;
|
use Helpers\View as view;
|
||||||
use Helpers\dbh;
|
use Helpers\dbh;
|
||||||
|
use Mail\Mail;
|
||||||
|
|
||||||
//事件中存在的操作
|
//事件中存在的操作
|
||||||
class PdfOperate implements \Order\listener\PdfEvents
|
class PdfOperate implements \Order\listener\PdfEvents
|
||||||
|
@ -35,6 +36,7 @@ class PdfOperate implements \Order\listener\PdfEvents
|
||||||
//在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息
|
//在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息
|
||||||
$formData = $e->getParam('formData');
|
$formData = $e->getParam('formData');
|
||||||
$uid = $e->getParam('uid');
|
$uid = $e->getParam('uid');
|
||||||
|
$returnid = $e->getParam('returnid');
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
|
@ -46,13 +48,25 @@ class PdfOperate implements \Order\listener\PdfEvents
|
||||||
$formData['username'] = $formData['realname'];
|
$formData['username'] = $formData['realname'];
|
||||||
unset($formData['realname']);
|
unset($formData['realname']);
|
||||||
unset($formData['save']);
|
unset($formData['save']);
|
||||||
|
unset($formData['submit']);
|
||||||
|
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$s = $dbh->update($this->tbl_offlineapp,$formData," id={$row['id']} ");
|
$s = $dbh->update($this->tbl_offlineapp,$formData," id={$row['id']} ");
|
||||||
|
if(empty($returnid))
|
||||||
|
{
|
||||||
return $s;
|
return $s;
|
||||||
}else{
|
}else{
|
||||||
|
return $row['id'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(empty($returnid))
|
||||||
|
{
|
||||||
$s = $dbh->insert($this->tbl_offlineapp,$formData);
|
$s = $dbh->insert($this->tbl_offlineapp,$formData);
|
||||||
return $s;
|
return $s;
|
||||||
|
}else{
|
||||||
|
$id = $dbh->insert($this->tbl_offlineapp,$formData,true);
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Exception $e)
|
}catch(Exception $e)
|
||||||
|
@ -63,4 +77,46 @@ class PdfOperate implements \Order\listener\PdfEvents
|
||||||
return true;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue