137 lines
3.3 KiB
PHP
137 lines
3.3 KiB
PHP
<?php
|
||
namespace Order\mount;
|
||
|
||
use Helpers\View as view;
|
||
use Helpers\dbh;
|
||
use Mail\Mail;
|
||
|
||
//事件中存在的操作
|
||
class PdfOperate implements \Order\listener\PdfEvents
|
||
{
|
||
private $db;
|
||
private $config;
|
||
|
||
//!!!!!!important!!!!!
|
||
//不同项目使用时是否要修改此项??
|
||
public $tbl_metadata = "heihemetadata";
|
||
public $tbl_dataorder = "dataorder";
|
||
public $tbl_offlineapp = "offlineapp";
|
||
|
||
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 updateUserInfo(\Zend_EventManager_Event $e)
|
||
{
|
||
//根据pdflink字段,以判断是否已经提交
|
||
//在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息
|
||
$formData = $e->getParam('formData');
|
||
$uid = $e->getParam('uid');
|
||
$returnid = $e->getParam('returnid');
|
||
|
||
try{
|
||
|
||
$sql="SELECT id FROM ".$this->tbl_offlineapp."
|
||
WHERE userid=? AND (pdflink IS null OR pdflink='') AND (ts_approved IS null)";
|
||
$row = $this->db->fetchRow($sql,array($uid));
|
||
|
||
$dbh = new dbh($this->db);
|
||
$formData['username'] = $formData['realname'];
|
||
$formData['userid'] = $uid;
|
||
|
||
unset($formData['realname']);
|
||
unset($formData['save']);
|
||
unset($formData['submit']);
|
||
unset($formData['id']);
|
||
|
||
if ($row) {
|
||
$s = $dbh->update($this->tbl_offlineapp,$formData," id={$row['id']} ");
|
||
if(empty($returnid))
|
||
{
|
||
return $s;
|
||
}else{
|
||
return $row['id'];
|
||
}
|
||
} else {
|
||
if(empty($returnid))
|
||
{
|
||
$s = $dbh->insert($this->tbl_offlineapp,$formData);
|
||
if($s > 0)
|
||
{
|
||
return true;
|
||
}else{
|
||
return "保存失败,请重试";
|
||
}
|
||
}else{
|
||
$id = $dbh->insert($this->tbl_offlineapp,$formData,true);
|
||
return $id;
|
||
}
|
||
}
|
||
|
||
}catch(Exception $e)
|
||
{
|
||
return $e->getMessage();
|
||
}
|
||
|
||
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 "数据篮状态更新失败,请重试";
|
||
}
|
||
|
||
$sql = "UPDATE offlineapp SET pdflink='".$pdf->pdflink."' WHERE id=$oid ";
|
||
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']),
|
||
"orderlink"=> view::getHostLink() . '/data/order/ac/offline3'
|
||
);
|
||
|
||
$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();
|
||
}
|
||
|
||
} |