2013-08-26 02:33:44 +00:00
< ? php
namespace Order\Manager ;
use Helpers\View as view ;
use Helpers\dbh ;
2013-11-15 02:31:03 +00:00
use Order\Listener\ManagerListener ;
2013-08-26 02:33:44 +00:00
class Offlineapp
{
private $db ;
private $config ;
protected $events = NULL ;
public $pdfData ;
function __construct ()
{
$this -> db = \Zend_Registry :: get ( 'db' );
$this -> config = \Zend_Registry :: get ( 'config' );
2013-09-05 01:52:27 +00:00
$Listener = new ManagerListener ();
@ $this -> events () -> attachAggregate ( $Listener );
2013-08-26 02:33:44 +00:00
}
public function events ( \Zend_EventManager_EventCollection $events = NULL )
{
if ( $events !== NULL ) {
$this -> events = $events ;
} elseif ( $this -> events === NULL ) {
$this -> events = new \Zend_EventManager_EventManager ( __CLASS__ );
}
return $this -> events ;
}
/*************
status :
1 开始进入离线申请申请程序中
2 填写并提交离线申请表
3 邮寄离线申请表
4 收到离线申请表
5 处理离线申请表
10 : 离线申请完成?
- 1 : 取消了在线下载进程
**************/
//接收
public function receive ( $id )
{
2013-08-28 01:41:49 +00:00
if ( empty ( $id ) || ! is_numeric ( $id ))
{
return " 参数错误 " ;
}
2013-09-05 01:52:27 +00:00
$sql = " update dataorder set status=4,ts_received=now() where offlineappid= $id " ;
2013-08-28 01:41:49 +00:00
2013-09-05 01:52:27 +00:00
if ( $this -> db -> exec ( $sql ) > 0 )
{
@ $this -> db -> exec ( " UPDATE offlineapp SET status=4,ts_received=now() WHERE id= $id " );
@ $this -> events () -> trigger ( 'offlineapp.received' , $this , compact ( 'id' ));
return true ;
} else {
return " 接收失败,请重试 " ;
}
}
//获取一个申请的详细信息
public function getOneAppInfo ( $id )
{
2013-09-25 09:44:21 +00:00
$sql = " SELECT off.*,o.status,o.uuid FROM offlineapp off
2013-09-05 01:52:27 +00:00
LEFT JOIN dataorder o ON off . id = o . offlineappid
WHERE off . id = $id
" ;
$rs = $this -> db -> query ( $sql );
return $rs -> fetchAll ();
2013-11-26 09:40:33 +00:00
} //
//判断是否存在wsn数据申请
public function hasWsnData ( $id )
{
$sql = " select count(d.id) as wsn from dataorder d left join dataservice s on d.uuid=s.uuid where d.offlineappid= $id and s.service_type in (1,2) and position('waterwsn' in s.service_url)>0 and d.selection is not null " ;
$rs = $this -> db -> query ( $sql );
$row = $rs -> fetch ();
return $row [ 'wsn' ];
2013-09-26 05:10:30 +00:00
}
2013-09-05 01:52:27 +00:00
//重置申请表
public function resetAppForm ( $id )
{
2013-09-06 08:15:16 +00:00
$sql = " SELECT * FROM offlineapp WHERE id= $id " ;
2013-09-05 01:52:27 +00:00
$rs = $this -> db -> query ( $sql );
2013-09-06 08:15:16 +00:00
$row = $rs -> fetch ();
2013-08-28 01:41:49 +00:00
2013-09-05 01:52:27 +00:00
$ids = array ();
2013-09-06 08:15:16 +00:00
if ( file_exists ( $row [ 'applicationform' ]))
2013-09-05 01:52:27 +00:00
{
2013-09-06 08:15:16 +00:00
@ unlink ( $row [ 'applicationform' ]);
2013-09-05 01:52:27 +00:00
}
2013-11-26 09:40:33 +00:00
if ( $this -> db -> exec ( " UPDATE offlineapp SET applicationform=NULL,status=2 WHERE id= $id " ) > 0 && $this -> db -> exec ( " UPDATE dataorder SET status=2 WHERE offlineappid= $id " ))
2013-09-05 01:52:27 +00:00
{
@ $this -> events () -> trigger ( 'offlineapp.AppFormReseted' , $this , compact ( 'id' ));
return true ;
} else {
return " 重置遇到问题,请重试 " ;
}
}
//提交给作者的时候需要处理的内容
public function sendToAuthor ()
{
2013-08-26 02:33:44 +00:00
}
2013-09-05 01:52:27 +00:00
///////////////////////////////////////////
2013-08-26 02:33:44 +00:00
public function offLineAppMakeQuery ( $opt )
{
$def = array (
2013-09-16 04:13:53 +00:00
'field' => ' off.*,o.id as orderid,o.status,u.realname,u.username,md.title ' ,
2013-08-26 02:33:44 +00:00
'table' => ' dataorder o ' ,
'join' => ' LEFT JOIN offlineapp off ON off . id = o . offlineappid
2013-09-05 01:52:27 +00:00
LEFT JOIN users u ON u . id = off . userid
LEFT JOIN metadata md ON md . uuid = o . uuid ' ,
'order' => ' o.id DESC '
2013-08-26 02:33:44 +00:00
);
return array_merge ( $def , $opt );
}
public function fetchNotReceived ()
{
$opt = $this -> offLineAppMakeQuery ( array (
2013-09-05 01:52:27 +00:00
'where' => ' o.offlineappid != -1 AND o.status=3'
2013-08-26 02:33:44 +00:00
));
$dbh = new dbh ();
2013-09-05 01:52:27 +00:00
//echo $dbh->select($opt,true);exit();
2013-08-26 02:33:44 +00:00
return $dbh -> select ( $opt );
2013-09-05 01:52:27 +00:00
} //未接受的
public function fetchNoPdf ()
{
$opt = $this -> offLineAppMakeQuery ( array (
2013-09-06 08:15:16 +00:00
'where' => ' o.offlineappid != -1 AND o.status=4 AND (off.applicationform IS NULL OR off.applicationform=\'\') '
2013-09-05 01:52:27 +00:00
));
$dbh = new dbh ();
//echo $dbh->select($opt,true);exit();
return $dbh -> select ( $opt );
} //没有pdf的
public function fetchNotApprove ()
{
$opt = $this -> offLineAppMakeQuery ( array (
2013-09-06 08:15:16 +00:00
'where' => ' o.offlineappid != -1 AND o.status=4 AND (off.applicationform IS NOT NULL || off.applicationform!=\'\') '
2013-09-05 01:52:27 +00:00
));
$dbh = new dbh ();
return $dbh -> select ( $opt );
} //待审核
2013-08-26 02:33:44 +00:00
}