2013-07-24 10:11:14 +00:00
|
|
|
|
<?php
|
2013-11-05 03:57:01 +00:00
|
|
|
|
namespace Order\Mount;
|
2013-08-26 02:33:44 +00:00
|
|
|
|
|
2013-11-05 03:57:01 +00:00
|
|
|
|
use \Helpers\View as view;
|
|
|
|
|
use \Helpers\dbh;
|
|
|
|
|
use \Mail\Mail;
|
2013-07-24 10:11:14 +00:00
|
|
|
|
|
|
|
|
|
//事件中存在的操作
|
2013-11-05 03:57:01 +00:00
|
|
|
|
class PdfOperate implements \Order\Listener\PdfEvents
|
2013-07-24 10:11:14 +00:00
|
|
|
|
{
|
|
|
|
|
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');
|
2013-08-28 09:50:08 +00:00
|
|
|
|
$returnid = $e->getParam('returnid');
|
2013-07-24 10:11:14 +00:00
|
|
|
|
|
|
|
|
|
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));
|
2013-08-26 02:33:44 +00:00
|
|
|
|
|
|
|
|
|
$dbh = new dbh($this->db);
|
2013-07-24 10:11:14 +00:00
|
|
|
|
$formData['username'] = $formData['realname'];
|
2013-08-29 07:53:31 +00:00
|
|
|
|
$formData['userid'] = $uid;
|
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
|
unset($formData['realname']);
|
|
|
|
|
unset($formData['save']);
|
2013-08-28 09:50:08 +00:00
|
|
|
|
unset($formData['submit']);
|
2013-08-29 07:53:31 +00:00
|
|
|
|
unset($formData['id']);
|
2013-08-28 01:41:49 +00:00
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
|
if ($row) {
|
|
|
|
|
$s = $dbh->update($this->tbl_offlineapp,$formData," id={$row['id']} ");
|
2013-09-06 07:05:33 +00:00
|
|
|
|
$this->updateToUserTable($formData,$row['id']);
|
2013-08-28 09:50:08 +00:00
|
|
|
|
if(empty($returnid))
|
|
|
|
|
{
|
|
|
|
|
return $s;
|
|
|
|
|
}else{
|
|
|
|
|
return $row['id'];
|
|
|
|
|
}
|
2013-07-24 10:11:14 +00:00
|
|
|
|
} else {
|
2013-09-06 07:05:33 +00:00
|
|
|
|
$id = $dbh->insert($this->tbl_offlineapp,$formData,true);
|
2013-09-09 08:46:54 +00:00
|
|
|
|
$this->updateToUserTable($formData,$uid);
|
2013-08-28 09:50:08 +00:00
|
|
|
|
if(empty($returnid))
|
2013-08-29 07:53:31 +00:00
|
|
|
|
{
|
2013-09-06 07:05:33 +00:00
|
|
|
|
if($id > 0)
|
2013-08-29 07:53:31 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return "保存失败,请重试";
|
|
|
|
|
}
|
2013-08-28 09:50:08 +00:00
|
|
|
|
}else{
|
|
|
|
|
return $id;
|
|
|
|
|
}
|
2013-07-24 10:11:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}catch(Exception $e)
|
|
|
|
|
{
|
|
|
|
|
return $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 07:05:33 +00:00
|
|
|
|
//将项目信息更新到用户表
|
|
|
|
|
public function updateToUserTable($formData,$id)
|
|
|
|
|
{
|
|
|
|
|
$data = array(
|
|
|
|
|
'address' => $formData['address'],
|
|
|
|
|
'phone' => $formData['phone'],
|
|
|
|
|
'postcode' => $formData['postcode'],
|
|
|
|
|
'unit' => $formData['unit'],
|
|
|
|
|
'project_id' => $formData['project_id'],
|
|
|
|
|
'project_type' => $formData['project_type'],
|
|
|
|
|
'project_title' => $formData['project_title'],
|
|
|
|
|
'project_leader' => $formData['project_leader'],
|
|
|
|
|
'project' => $formData['project']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$dbh = new dbh($this->db);
|
|
|
|
|
@$dbh->update('users',$data," id=$id ");
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 09:50:08 +00:00
|
|
|
|
//申请成功提交之后
|
|
|
|
|
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{
|
|
|
|
|
|
2013-09-09 08:46:54 +00:00
|
|
|
|
$sql="update dataorder set offlineappid=$oid where status=2 and userid=$uid";
|
2013-08-28 09:50:08 +00:00
|
|
|
|
if($this->db->exec($sql) < 0)
|
|
|
|
|
{
|
|
|
|
|
return "数据篮状态更新失败,请重试";
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-09 08:46:54 +00:00
|
|
|
|
$sql = "UPDATE offlineapp SET pdflink='".$pdf->pdflink."',status=2 WHERE id=$oid ";
|
2013-09-05 01:52:27 +00:00
|
|
|
|
if($this->db->exec($sql) < 0)
|
|
|
|
|
{
|
|
|
|
|
return "数据篮状态更新有误,请联系管理员";
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 09:50:08 +00:00
|
|
|
|
$this->sendEmail($formData,$pdf);
|
|
|
|
|
|
|
|
|
|
}catch(Exception $e)
|
|
|
|
|
{
|
|
|
|
|
return $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-09 03:22:27 +00:00
|
|
|
|
//检查生成pdf的数量
|
|
|
|
|
public function checkPdfOrderNum(\Zend_EventManager_Event $e)
|
|
|
|
|
{
|
|
|
|
|
$uid = (int)$e->getParam('uid');
|
|
|
|
|
if(empty($uid))
|
|
|
|
|
{
|
|
|
|
|
$uid = view::User('id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = "select count(*) as datacount from {$this->tbl_dataorder} where (ts_approved is null) and userid=? and status=2 AND offlineappid=-1";
|
|
|
|
|
$rs = $this->db->fetchRow($this->db->quoteInto($sql,$uid));
|
|
|
|
|
$inorder = $rs['datacount'];
|
|
|
|
|
|
2013-10-09 03:46:33 +00:00
|
|
|
|
if($inorder <= $this->config->download->max)
|
2013-10-09 03:22:27 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
2013-10-09 07:58:46 +00:00
|
|
|
|
return "本次订单将使申请数量超过限制,所以无法生成PDF,请在数据篮-待提交订单中移除相应数据,确保待提交的数据申请条数小于等于5条,然后再重新生成。";
|
2013-10-09 03:22:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 09:50:08 +00:00
|
|
|
|
//发送邮件通知
|
|
|
|
|
public function sendEmail($formData,$pdf)
|
|
|
|
|
{
|
|
|
|
|
$data = array(
|
|
|
|
|
"user"=>$formData['realname'],
|
2013-09-05 01:52:27 +00:00
|
|
|
|
"datalist"=>str_replace(";","\n",$formData['datalist']),
|
2013-09-09 08:46:54 +00:00
|
|
|
|
"orderlink"=> view::getHostLink() . '/data/order/ac/offline2'
|
2013-08-28 09:50:08 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 10:11:14 +00:00
|
|
|
|
}
|