westdc-zf1/application/module/Order/Manager/Offlineapp.php

170 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Order\Manager;
use Helpers\View as view;
use Helpers\dbh;
use Order\Listener\ManagerListener;
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');
$Listener = new ManagerListener();
@$this->events()->attachAggregate($Listener);
}
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)
{
if(empty($id) || !is_numeric($id))
{
return "参数错误";
}
$sql="update dataorder set status=4,ts_received=now() where offlineappid=$id";
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)
{
$sql = "SELECT off.*,o.status,o.uuid FROM offlineapp off
LEFT JOIN dataorder o ON off.id=o.offlineappid
WHERE off.id = $id
";
$rs = $this->db->query($sql);
return $rs->fetchAll();
}//
//判断是否存在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'];
}
//重置申请表
public function resetAppForm($id)
{
$sql = "SELECT * FROM offlineapp WHERE id=$id";
$rs = $this->db->query($sql);
$row = $rs->fetch();
$ids = array();
if(file_exists($row['applicationform']))
{
@unlink($row['applicationform']);
}
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"))
{
@$this->events()->trigger('offlineapp.AppFormReseted', $this, compact('id'));
return true;
}else{
return "重置遇到问题,请重试";
}
}
//提交给作者的时候需要处理的内容
public function sendToAuthor()
{
}
///////////////////////////////////////////
public function offLineAppMakeQuery($opt)
{
$def = array(
'field' => ' off.*,o.id as orderid,o.status,u.realname,u.username,md.title ',
'table' => ' dataorder o ',
'join' => ' LEFT JOIN offlineapp off ON off.id=o.offlineappid
LEFT JOIN users u ON u.id = off.userid
LEFT JOIN metadata md ON md.uuid=o.uuid',
'order' => ' o.id DESC '
);
return array_merge($def,$opt);
}
public function fetchNotReceived()
{
$opt = $this->offLineAppMakeQuery(array(
'where' => ' o.offlineappid != -1 AND o.status=3'
));
$dbh = new dbh();
//echo $dbh->select($opt,true);exit();
return $dbh->select($opt);
}//未接受的
public function fetchNotSubmitted()
{
$opt = $this->offLineAppMakeQuery(array(
'where' => ' o.offlineappid != -1 AND o.status=2 and off.pdflink is not null'
));
$dbh = new dbh();
//echo $dbh->select($opt,true);exit();
return $dbh->select($opt);
}//未提交pdf的数据申请用于替用户重置后重新上传pdf
public function fetchNoPdf()
{
$opt = $this->offLineAppMakeQuery(array(
'where' => ' o.offlineappid != -1 AND o.status=4 AND (off.applicationform IS NULL OR off.applicationform=\'\') '
));
$dbh = new dbh();
//echo $dbh->select($opt,true);exit();
return $dbh->select($opt);
}//没有pdf的
public function fetchNotApprove()
{
$opt = $this->offLineAppMakeQuery(array(
'where' => ' o.offlineappid != -1 AND o.status=4 AND (off.applicationform IS NOT NULL || off.applicationform!=\'\') '
));
$dbh = new dbh();
return $dbh->select($opt);
}//待审核
}