westdc-zf1/application/models/data/DataService.php

118 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2013-10-28 14:54:21 +00:00
<?php
namespace data;
use Helpers\View as view;
use Helpers\Curl;
class DataService
{
private $db; //传入PDO对象.
//使用到的公共变量
public $tbl_dataservice = "dataservice";
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
}
function Fetch()
{
$sql = "SELECT * FROM ".$this->tbl_dataservice."";
$rs = $this->db->query($sql);
return $rs->fetchAll();
}
function get($uuid)
{
$sql = "SELECT * FROM ".$this->tbl_dataservice." WHERE uuid='$uuid' LIMIT 1";
$rs = $this->db->query($sql);
return $rs->fetch();
}
public function getWsnData($type,$uuid = "",$param = ""){
$info = $this->get($uuid);
$curl = new Curl();
$uid = view::User('id');
if(!is_numeric($uid) || $uid <1)
{
return "请先登录";
}
if($type == 'site')
{
$param = array(
'uuid'=>$uuid,
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
'uid'=> view::User('id')
);
$data = $curl->request($info['service_url']."site/",$param,"POST");
$data = json_decode($data['response'],TRUE);
}//site
if($type == 'var')
{
$param_temp = array(
'uuid'=>$uuid,
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
'uid'=> view::User('id'),
);
$param = array_merge($param,$param_temp);
$data = $curl->request($info['service_url']."var/",$param,"POST");
$data = json_decode($data['response'],TRUE);
}
if($type == 'submit')
{
$param_temp = array(
'uuid'=>$uuid,
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
'uid'=> view::User('id'),
);
$param = array_merge($param,$param_temp);
$data = $curl->request($info['service_url']."insert/",$param,"POST");
$data = json_decode($data['response'],TRUE);
}
if($data['status'] == 0)
{
return $data['error'];
}
else if($data['status'] == 1)
{
return $data['data'];
}
else
{
return NULL;
}
}//获取Wsn数据
//访问wsn端生成数据的webservice
public function makeWsnData($param)
{
$param_temp = array(
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
);
$param = array_merge($param,$param_temp);
$url = "http://ftp2.westgis.ac.cn/wsndata.php";
$curl = new Curl();
$data = $curl->request($url,$param);
$data = json_decode($data['response'],TRUE);
}
}