浏览代码

first commit

git 6 年之前
父节点
当前提交
57ea5fcce5

+ 2 - 0
Home/Common/common.php

@@ -0,0 +1,2 @@
+<?php
+require_once(COMMON_PATH . 'func.php');

+ 102 - 0
Home/Common/func.php

@@ -0,0 +1,102 @@
+<?php
+	/*
+	参数说明:
+		username: 
+
+	*/
+	function checkMobileUsername($username){
+		if(!$username){//用户名参数为空
+			$this->errorMsg(\Zndp\Api\ResponseCode::EMPTY_USERNAME);
+		}
+		$where = array(
+				'UserName'=>$username,
+				'RoleId' => ['neq',\Zndp\User\RoleEnum::FARM_OPERATOR],
+				);
+		$userinfo = MM('uc_user')->where($where)->find();
+		if(!$userinfo){//用户名不存在
+			$this->errorMsg(\Zndp\Api\ResponseCode::USERNAME_NOT_EXISTS);
+		}
+		return $userinfo;
+	}
+
+	/*
+	参数说明:
+		channel_number:通道号 
+
+	*/
+	function MapChannelNumberToZk($channel_number){
+		switch($channel_number){
+			case '1' :
+			return array(
+				'ChNumber' => 7,
+				'DisplayName' => '风口左',
+				'ChNumberText' => 'column_7',
+			);
+			break;
+			case '2' :
+			return array(
+				'ChNumber' => 3,
+				'DisplayName' => '气温',
+				'ChNumberText' => 'column_3',
+			);
+			break;
+			case '3' :
+			return array(
+				'ChNumber' => 4,
+				'DisplayName' => '湿度',
+				'ChNumberText' => 'column_4',
+			);
+			break;
+			case '4' :
+			return array(
+				'ChNumber' => 1,
+				'DisplayName' => '光照',
+				'ChNumberText' => 'column_1',
+			);
+			break;
+			case '5' :
+			return array(
+				'ChNumber' => 8,
+				'DisplayName' => '风口左',
+				'ChNumberText' => 'column_8',
+			);
+			break;
+			default :
+		
+			break;
+		
+		}
+	}
+
+	/*
+	参数说明:
+		channel_number:通道号 
+
+	*/
+	function MapChannelNumber($channel_number){
+		if(!$channel_number){ 
+			return false;
+		}
+		if($channel_number == 1){  //中科光照通道号
+			return 4;	//光照1
+		}
+		if($channel_number == 3){  //中科气温通道号
+			return 2;	//气温1
+		}
+		if($channel_number == 4){  //中科湿度通道号
+			return 3;	//湿度1
+		}
+		if($channel_number == 6){	//中科保温被通道号
+			return false;
+		}
+		if($channel_number == 7){	//中科风口左通道号
+			return 1;	//卷膜1左
+		}
+		if($channel_number == 8){	//中科风口右通道号
+			return 5;	//卷膜1右
+		}
+		return false;
+		
+	}
+
+

+ 10 - 0
Home/Lib/Action/DpjkApiAction.class.php

@@ -0,0 +1,10 @@
+<?php
+class DpjkApiAction extends Action {
+	/*
+
+	*/
+	public function getSessionKey(){
+		
+	}
+
+}

+ 99 - 0
Home/Lib/Action/DpjkControlAction.class.php

@@ -0,0 +1,99 @@
+<?php
+class DpjkControlAction extends Action {
+	/*
+
+	*/
+	public function start(){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		$addr = I("post.addr");
+		$ch_number = I("post.channel");
+		if(!$addr){
+			json_fail('参数配置错误:地址码不存在');
+		}
+		if(!$ch_number){
+			json_fail('参数配置错误:通道号不存在');
+		}
+		$host = '127.0.0.1';
+		$port = 10240;
+		$socket = new Jms\Network\TcpClient($host,$port);
+		$cmd = array(
+			"method" => "apiSendControl", 
+			"Addr" => $addr,     //设备addr
+			"channelNumber" => $ch_number,   //通道编号
+			"status" => 1,
+		);
+		$res = $socket->send(json_encode($cmd)); 
+		if($res['success']){
+			json_success('下发成功');
+		}else{
+			json_fail($res['message']);
+		}
+		
+	}
+	/*
+
+	*/
+	public function stop(){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		$addr = I("post.addr");
+		$ch_number = I("post.channel");
+		if(!$addr){
+			json_fail('参数配置错误:地址码不存在');
+		}
+		if(!$ch_number){
+			json_fail('参数配置错误:通道号不存在');
+		}
+		$host = '127.0.0.1';
+		$port = 10240;
+		$socket = new Jms\Network\TcpClient($host,$port);
+		$cmd = array(
+			"method" => "apiSendControl", 
+			"Addr" => $addr,     //设备addr
+			"channelNumber" => $ch_number,   //通道编号
+			"status" => 0,
+		);
+		$res = $socket->send(json_encode($cmd)); 
+		if($res['success']){
+			json_success('下发成功');
+		}else{
+			json_fail($res['message']);
+		}
+		
+		
+	}
+	/*
+
+	*/
+	public function close(){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		$addr = I("post.addr");
+		$ch_number = I("post.channel");
+		if(!$addr){
+			json_fail('参数配置错误:地址码不存在');
+		}
+		if(!$ch_number){
+			json_fail('参数配置错误:通道号不存在');
+		}
+		$host = '127.0.0.1';
+		$port = 10240;
+		$socket = new Jms\Network\TcpClient($host,$port);
+		$cmd = array(
+			"method" => "apiSendControl", 
+			"Addr" => $addr,     //设备addr
+			"channelNumber" => $ch_number,   //通道编号
+			"status" => 2,
+		);
+		$res = $socket->send(json_encode($cmd)); 
+		if($res['success']){
+			json_success('下发成功');
+		}else{
+			json_fail($res['message']);
+		}
+		
+		
+	}
+
+}

文件差异内容过多而无法显示
+ 1672 - 0
Home/Lib/Action/DpjkIndexAction.class.php


+ 492 - 0
Home/Lib/Action/DpjkMobileAction.class.php

@@ -0,0 +1,492 @@
+<?php
+
+
+
+class DpjkMobileAction extends Action {
+			
+
+
+ 
+	public  function getDeivceRealDataTest(  ){
+		$device_info = MM('dpsb_device')->where(array('ID'=>$device_id))->find();
+		if(!$device_info)
+			return false;
+		$data = array(
+			"id" => $device_id,
+			"title" => $device_info['WorkUnitName'],
+			"addr" => $device_info['DeviceAddr'],
+		   "time" => $device_info['GatherTime'],
+			"channels" => array(),
+			"rollfilm" => array(),
+		);
+		for($i=0;$i<3;$i++){
+			$channel_data = array();
+		   //气温
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::TEMPERATURE,
+				'ChGroup' => $i,
+			);
+			$qw_info = MM('dpsb_channel')->where($where)->find();
+			if(!$qw_info){
+				continue;
+			}
+			//湿度
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::HUMIDITY,
+				'ChGroup' => $i,
+			);
+			$sd_info = MM('dpsb_channel')->where($where)->find();
+			if(!$sd_info){
+				continue;
+			}
+			//光照
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::ILLINATIONUM,
+				'ChGroup' => $i,
+			);
+			$gz_info = MM('dpsb_channel')->where($where)->find();
+			if(!$gz_info){
+				continue;
+			}
+			//卷膜1
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::FILM_CONTROL,
+				'ChGroup' => $i,
+			);
+			$jm_left_info = MM('dpsb_channel')->where($where)->order('ChNumber asc')->find();
+			if(!$jm_left_info){
+				continue;
+			}
+			//卷膜5
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::FILM_CONTROL,
+				'ChGroup' => $i,
+			);
+			$jm_right_info = MM('dpsb_channel')->where($where)->order('ChNumber desc')->find();
+			if(!$jm_right_info){
+				continue;
+			}
+			$channel_data = array(
+				'qw' => $qw_info['ChValue'],
+				'sd' => $sd_info['ChValue'],
+				'gz' => $gz_info['ChValue'],
+				'group' => $i+1,
+			);	
+			array_push($data['channels'],$channel_data);
+			$roll_left_film_data = array(
+				'jm' => $jm_left_info['ChNumber'],
+				'name' => $jm_left_info['DisplayName'],
+				'group' => $i+1,
+			);
+			array_push($data['rollfilm'],$roll_left_film_data);
+			$roll_right_film_data = array(
+				'jm' => $jm_right_info['ChNumber'],
+				'name' => $jm_left_info['DisplayName'],
+				'group' => $i+1,
+			);
+			array_push($data['rollfilm'],$roll_right_film_data);
+		
+		}
+		return $data;
+		
+	}
+	
+ 
+	public  function login(  ){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		//用户信息
+		$username = I('post.Username');
+		$password = I('post.Password');
+		//检查是否是操作员
+		$where = array(
+				'UserName'=>$username
+				);
+		$userinfo = MM('uc_user')->where($where)->find();
+		if(!$userinfo){
+			json_fail('该用户不存在');
+		}
+		/*
+		//用户是否有权限
+		if($userinfo['RoleId'] != \Zndp\User\RoleEnum::FARM_OPERATOR){
+			json_fail('当前用户没有操作权限');
+		}*/
+		$login_list = array(
+							\Zndp\User\RoleEnum::BASE_ADMINISTRATOR,//基地管理员
+							\Zndp\User\RoleEnum::BASE_LEADER,//基地负责人
+		);
+		if( !in_array($userinfo['RoleId'],$login_list) ){
+			json_fail('当前用户没有登录权限');
+		}
+		//密码错误
+		$password = (new \Zndp\User\Util)->encPwd($password);
+		if($password != $userinfo['Password']){
+			json_fail('用户名或者密码不正确');
+		}
+		//保存用户cid
+		$cid = I('post.cid');
+		if($cid){
+			$result = MM('uc_user')->where($where)->setField('ClientId',$cid);
+			if($result === false){
+				json_fail('CID有误');
+			}
+		}
+		//登录成功
+		json_success('登陆成功',$userinfo['ID']);
+	}
+	
+ 
+	public  function allDevicesRealTimeData(  ){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		$userid = I('get.userid');
+		if(!$userid){
+			json_fail('用户信息不存在');
+		}
+		/*$farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
+		if(!$farmid){
+			json_fail('用户下没有农场');	
+		}*/
+		// 新流程
+		$depart_id = MM('uc_user')->where(array('ID'=>$userid))->getField('OrganizationId');
+		if(!$depart_id){
+			json_fail('账号部门信息有误,请联系负责人');	
+		}
+		//获取部门下所有基地
+		$base_ids = \Zndp\User\Util::get_depart_farm($depart_id);
+		$where = array('FarmId'=>array('IN',$base_ids));
+		$group_list = MM('dpsb_group')->where($where)->select();
+		if(!$group_list){
+			json_fail('设备组不存在');
+		}
+		$device_data_list = array();
+		foreach($group_list as $row){
+			$device_list = MM('dpsb_device')->where(array('DeviceGroupId'=>$row['ID']))->select();
+			foreach($device_list as $device){
+				$device_data = $this->getDeivceRealData($device['ID']);
+				array_push($device_data_list,$device_data);
+			}
+		}
+		json_success('',$device_data_list);
+		
+	}
+	
+ 
+	private  function getDeivceRealData( $device_id ){
+		$device_info = MM('dpsb_device')->where(array('ID'=>$device_id))->find();
+		if(!$device_info)
+			return false;
+		$data = array(
+			"id" => $device_id,
+			"title" => $device_info['WorkUnitName'],
+			"addr" => $device_info['DeviceAddr'],
+		   "time" => $device_info['GatherTime'],
+			"channels" => array(),
+			"rollfilm" => array(),
+		);
+		for($i=0;$i<3;$i++){
+			$channel_data = array();
+		   //气温
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::TEMPERATURE,
+				'ChGroup' => $i,
+			);
+			$qw_info = MM('dpsb_channel')->where($where)->find();
+			if(!$qw_info){
+				continue;
+			}
+			//湿度
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::HUMIDITY,
+				'ChGroup' => $i,
+			);
+			$sd_info = MM('dpsb_channel')->where($where)->find();
+			if(!$sd_info){
+				continue;
+			}
+			//光照
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::ILLINATIONUM,
+				'ChGroup' => $i,
+			);
+			$gz_info = MM('dpsb_channel')->where($where)->find();
+			if(!$gz_info){
+				continue;
+			}
+			//卷膜1
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::FILM_CONTROL,
+				'ChGroup' => $i,
+			);
+			$jm_left_info = MM('dpsb_channel')->where($where)->order('ChNumber asc')->find();
+			if(!$jm_left_info){
+				continue;
+			}
+			//卷膜5
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType'=> \Zndp\Device\ChannelType::FILM_CONTROL,
+				'ChGroup' => $i,
+			);
+			$jm_right_info = MM('dpsb_channel')->where($where)->order('ChNumber desc')->find();
+			if(!$jm_right_info){
+				continue;
+			}
+			$channel_data = array(
+				'qw' => $qw_info['ChValue'],
+				'sd' => $sd_info['ChValue'],
+				'gz' => $gz_info['ChValue'],
+				'group' => $i+1,
+			);	
+			array_push($data['channels'],$channel_data);
+			$roll_left_film_data = array(
+				'jm' => $jm_left_info['ChNumber'],
+				'name' => $jm_left_info['DisplayName'],
+				'group' => $i+1,
+			);
+			array_push($data['rollfilm'],$roll_left_film_data);
+			$roll_right_film_data = array(
+				'jm' => $jm_right_info['ChNumber'],
+				'name' => $jm_right_info['DisplayName'],
+				'group' => $i+1,
+			);
+			array_push($data['rollfilm'],$roll_right_film_data);
+		
+		}
+		return $data;
+		
+	}
+	
+ 
+	public  function oneDeviceRealTimeData(  ){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		$userid = I('get.userid');
+		$deviceid = I('get.deviceid');
+		if(!$deviceid)
+			json_fail('设备id不存在');
+		if(!$userid)
+			json_fail('用户信息不存在');
+		$farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
+		if(!$farmid)
+			json_fail('用户下没有农场');
+		$group_list = MM('dpsb_group')->where(array('FarmId'=>$farmid))->select();
+		if(!$group_list)
+			json_fail('设备组不存在');
+		$device_data = $this->getDeivceRealData($deviceid);
+		json_success('',$device_data);
+		
+	}
+	
+ 
+	public  function getAlarmData(  ){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		//获取登录用户部门id
+		$userid = I('get.userid');
+		$where = array('ID'=>$userid);
+		$user_info = MM('uc_user')->field('RoleId,OrganizationId')->where($where)->find();
+		//组装查询条件
+		if( $user_info['RoleId'] == \Zndp\User\RoleEnum::BASE_ADMINISTRATOR){//基地管理员只查看自己的大棚
+			$where = array( 'ManagerId' => $userid );
+		}else{//否则查出该部门下所有基地
+			$base_ids = \Zndp\User\Util::get_depart_farm($user_info['OrganizationId']);
+			$where = array('FarmId'=>array('IN',$base_ids));
+		}
+		//查出大棚告警日志
+		$farmland_ids = MM('dpyh_farmland')->field('ID')->where($where)->select();	
+		$farmland_ids = array_column($farmland_ids,'ID');
+		$where = array( 'FarmlandId' => array('IN',$farmland_ids) );	
+		$alarm_list = MM('dpsj_alarm_log')->where($where)->order('SendTime desc')->limit(100)->select();
+		if( $alarm_list ){
+			$alarm_list = array(
+				'success' => true,
+				'message' => '获取成功',
+				'data' => $alarm_list
+			);
+		}else{
+			$alarm_list = array(
+				'success' => false,
+				'message' => '没有数据',
+				'data' => $alarm_list
+			);
+		}
+		echo json_encode($alarm_list,JSON_UNESCAPED_UNICODE);
+	}
+	
+ 
+	public  function allFarmlandRealTimeData(  ){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		$userid = I('get.userid');
+		if(!$userid){
+			json_fail('用户信息不存在');
+		}
+		// 新流程
+		$user_info = MM('uc_user')->field('ID,RoleId,OrganizationId')->where(array('ID'=>$userid))->find();
+		if(!$user_info['OrganizationId']){
+			json_fail('账号部门信息有误,请联系负责人');	
+		}
+		if($user_info['RoleId'] == \Zndp\User\RoleEnum::BASE_ADMINISTRATOR ){ //基地管理员只能查看自己管理的大棚
+			$where = array('ManagerId'=>$user_info['ID']);
+			$farmland_list = MM('dpyh_farmland')->field('ID,FarmlandName')->where($where)->select();
+		}else{
+			//获取部门下所有基地
+			$base_ids = \Zndp\User\Util::get_depart_farm($user_info['OrganizationId']);
+			$where = array('FarmId'=>array('IN',$base_ids));
+			$farmland_list = MM('dpyh_farmland')->field('ID,FarmlandName')->where($where)->select();
+		}
+		if(!$farmland_list){
+			json_fail('没有大棚存在');
+		}
+		$farmland_data_list = array();
+		foreach($farmland_list as $farmland){
+			$where = array('FarmlandId'=>$farmland['ID']);
+			$chgroup_list = MM('dpsb_chgroup')->field('DeviceId,ChGroup')->where($where)->select();
+			foreach($chgroup_list as $chgroup){ //传设备id和通道组用于获取通道
+				$channel_data = $this->getChgroupRealData($chgroup['DeviceId'],$chgroup['ChGroup'],$farmland);
+				array_push($farmland_data_list,$channel_data);
+			}
+		}
+		json_success('',$farmland_data_list);
+		
+	}
+	
+ 
+	private  function getChgroupRealData( $device_id, $chgroup, $farmland_info ){
+		$where = array('DeviceId'=>$device_id,'ChGroup'=>$chgroup);
+		//查找通道组下所有通道
+		$channel_list = MM('dpsb_channel')->field('ChNumber,DisplayName,ChType,ChValue,GatherTime')->where($where)->order('ChNumber asc')->select();
+		if(!$channel_list || !$farmland_info){
+			return false;
+		}
+		//拼接数据
+		$device_addr = MM('dpsb_device')->where(array('ID'=>$device_id))->getField('DeviceAddr');
+		$farmland_data = array(
+			'id' => $farmland_info['ID'], //用于传给详情页面
+			'title' => $farmland_info['FarmlandName'],//显示标题
+			'addr' => $device_addr,//设备序列号
+			//'time' => $channel_list['GatherTime'],//最新上报数据时间
+			"channels" => array(),//光照、温度、湿度传感器数据
+			"rollfilm" => array(),//卷膜机数据
+		);
+		$channel_data = array(); //初始化传感器数据
+		$jm_data = array();     //初始化卷膜机数据
+		foreach($channel_list as $channel){
+			$channel_unit = (new \Zndp\Device\ChannelType())->getTypeUnit($channel['ChType']);//传感器单位
+			if($channel['ChType'] == \Zndp\Device\ChannelType::TEMPERATURE ){ //气温+
+				$farmland_data['time'] = $channel['GatherTime'];//最新上报数据时间
+				$data = array(
+					'name' => $channel['DisplayName'], //名称
+					'value'=> $channel['ChValue'],	//值
+					'unit' => $channel_unit,	//单位
+					'icon' => 'icon_qw.png',	//图标
+				);
+				array_push($channel_data,$data);
+				//$channel_data[$channel['DisplayName']] = $channel['ChValue'] .' '.$channel_unit;
+			}elseif($channel['ChType'] == \Zndp\Device\ChannelType::HUMIDITY){ //湿度
+				if( $farmland_data['time'] < $channel['GatherTime'] ){
+					$farmland_data['time'] = $channel['GatherTime'];//最新上报数据时间
+				}
+				$data = array(
+					'name' => $channel['DisplayName'], //名称
+					'value'=> $channel['ChValue'],	//值
+					'unit' => $channel_unit,	//单位
+					'icon' => 'icon_sd.png',	//图标
+				);
+				array_push($channel_data,$data);
+				//$channel_data[$channel['DisplayName']] = $channel['ChValue'] .' '.$channel_unit;
+			}elseif($channel['ChType'] == \Zndp\Device\ChannelType::ILLINATIONUM){ //光照
+				if( $farmland_data['time'] < $channel['GatherTime'] ){
+					$farmland_data['time'] = $channel['GatherTime'];//最新上报数据时间
+				}
+				$data = array(
+					'name' => $channel['DisplayName'], //名称
+					'value'=> $channel['ChValue'],	//值
+					'unit' => $channel_unit,	//单位
+					'icon' => 'icon_gz.png',	//图标
+				);
+				array_push($channel_data,$data);
+				//$channel_data[$channel['DisplayName']] = $channel['ChValue'] .' '.$channel_unit;
+			}elseif($channel['ChType'] == \Zndp\Device\ChannelType::FILM_CONTROL){ //卷膜机
+				$jm_name = \Zndp\Device\ChannelType::getDisplayName($channel['ChType'],$chgroup,$channel['ChNumber']);
+				$jm_data[] = array(
+								'jm' => $channel['ChNumber'],//通道号
+								'name' => $jm_name,   //卷膜机名称
+								'group' => $chgroup   //通道组
+								);
+			}else{
+				
+			}
+		}
+		$farmland_data['channels'] = $channel_data;
+		$farmland_data['rollfilm'] = $jm_data;
+		return $farmland_data;
+	}
+	
+ 
+	public  function oneFarmlandRealTimeData(  ){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		$userid = I('get.userid');
+		$farmland_id = I('get.farmland_id');
+		if(!$farmland_id || !$userid){
+			json_fail('用户或大棚id不存在');
+		}
+		$where = array('ID'=>$farmland_id);
+		$farmland_info = MM('dpyh_farmland')->field('ID,FarmlandName')->where($where)->find();
+		$where = array('FarmlandId'=>$farmland_id);
+		$chgroup_info = MM('dpsb_chgroup')->field('DeviceId,ChGroup')->where($where)->find();
+		$channel_data = $this->getChgroupRealData($chgroup_info['DeviceId'],$chgroup_info['ChGroup'],$farmland_info);
+		
+		json_success('',$channel_data);
+		
+	}
+	
+ 
+	public  function getAppAlarmData(  ){
+		//允许所有域名跨域访问
+		header('Access-Control-Allow-Origin: *');
+		//获取登录用户部门id
+		$userid = I('get.userid');
+		$where = array('ID'=>$userid);
+		$user_info = MM('uc_user')->field('RoleId,OrganizationId')->where($where)->find();
+		//组装查询条件
+		if( $user_info['RoleId'] == \Zndp\User\RoleEnum::BASE_ADMINISTRATOR){//基地管理员只查看自己的大棚
+			$where = array( 'ManagerId' => $userid );
+		}else{//否则查出该部门下所有基地
+			$base_ids = \Zndp\User\Util::get_depart_farm($user_info['OrganizationId']);
+			$where = array('FarmId'=>array('IN',$base_ids));
+		}
+		//查出大棚告警日志
+		$farmland_ids = MM('dpyh_farmland')->field('ID')->where($where)->select();	
+		$farmland_ids = array_column($farmland_ids,'ID');
+		$where = array( 'FarmlandId' => array('IN',$farmland_ids), 'Platform'=>1 );	
+		$alarm_list = MM('dpsj_alarm_log')->where($where)->order('SendTime desc')->limit(100)->select();
+		if( $alarm_list ){
+			$alarm_list = array(
+				'success' => true,
+				'message' => '获取成功',
+				'data' => $alarm_list
+			);
+		}else{
+			$alarm_list = array(
+				'success' => false,
+				'message' => '没有数据',
+				'data' => $alarm_list
+			);
+		}
+		echo json_encode($alarm_list,JSON_UNESCAPED_UNICODE);
+	}
+	
+
+}

+ 29 - 0
Home/Lib/Action/IndexAction.class.php

@@ -0,0 +1,29 @@
+<?php
+class IndexAction extends Action {
+	/*
+
+	*/
+	public function index(){
+		echo 4567;
+	}
+	/*
+
+	*/
+	public function test(){
+		$where = array('DeviceId'=>34);
+		$channel_list = MM('dpsb_channel')->where ($where)->select();
+		$channel_arr = array();
+		foreach($channel_list as $channel){
+			//转换为中科通道
+			$zk_channel_info = \Zndp\Device\Util::MapChannelNumberToZk($channel['ChNumber']);
+			$channel['ChNumber'] = $zk_channel_info['ChNumber'];
+			$channel['ChNumberText'] = $zk_channel_info['ChNumberText'];
+			$channel['DisplayName'] = $zk_channel_info['DisplayName'];
+			array_push($channel_arr,$channel);
+		}
+		echo "<pre>";
+		//print_r($channel_arr);
+		var_dump(\Zndp\Device\Util::MapChannelNumber(9));
+	}
+
+}

+ 19 - 0
dp_index.php

@@ -0,0 +1,19 @@
+<?php
+$plugins = array(
+	'dpjk' => 'dpjk',
+);
+if(! isset($_GET['s']))
+	$_GET['s'] = 'dpjk_index/index';
+
+$s = $_GET['s'];
+$prefix = substr($s,0,strpos($s,'_'));
+if(!isset($plugins[$prefix]))
+	die('unknown plugin prefix - ' . $prefix);
+
+$path = __DIR__ . '/' . $plugins[$prefix] . '/stub.php';
+if(! file_exists($path) )
+	die('invalid plugin path - ' . $path);
+
+define('SCRIPT_FILENAME', $path);
+require $path;
+require( __DIR__ . '/jrtp/stub.php');

+ 6 - 0
index.php

@@ -0,0 +1,6 @@
+<?php
+define('SCRIPT_FILENAME', __FILE__);
+//插件信息
+require 'stub.php';
+//TP入口
+require( dirname(__DIR__) . '/jrtp/stub.php');

+ 28 - 0
install.php

@@ -0,0 +1,28 @@
+<?php
+//error_reporting(E_ALL);
+//检测必须是命令行执行
+if(php_sapi_name() != 'cli'){
+	echo 'intall.php must be executed under cli mode';
+	exit;
+}
+
+//检查命令行参数是否正确
+if($_SERVER['argc'] <= 1){
+	echo 'intall.php must be executed with 1 paramter';
+	exit;	
+}
+
+//获取命令行参数 (构件部署配置文件)
+$assembly_json = $_SERVER['argv'][1];
+if(!file_exists($assembly_json)){
+	echo 'intall.php must be existing json file';
+	exit;
+}
+
+$indexfile = __DIR__ .'/dp_index.php';
+//拷贝index.php
+copy($indexfile, dirname(__DIR__) .'/index.php');
+
+echo 'success';
+
+?>

+ 35 - 0
plugin.json

@@ -0,0 +1,35 @@
+{
+  "id": "b4b2a3beabced5e63b90cacac4ab0aa3",
+  "name": "dpjk",
+  "title": "大棚API",
+  "prefix": "dpjk",
+  "version": "1.0.2",
+  "icon": "",
+  "description": "大棚API",
+  "homepage": "",
+  "license": "",
+  "repository": {
+    "type": "git",
+    "url": ""
+  },
+  "author": {
+    "name": "elviss",
+	"mobile": "", 
+    "email": "elvisszhang@icloud.com",
+	"company": ""
+  },
+  "dependencies": {
+
+  },
+  "devDependencies": {
+    "thinkphp": "3.1.3"
+  },
+  "environment":[
+    {
+        "name":"DB_DSN",
+        "title":"MySQL数据库配置",
+        "description":"",
+        "type":"text"
+    }
+  ]
+}

+ 9 - 0
stub.php

@@ -0,0 +1,9 @@
+<?php
+//插件或者工程ID
+define('APP_ID','b4b2a3beabced5e63b90cacac4ab0aa3');
+//插件前缀
+define('APP_PREFIX','dpjk');
+//插件版本
+define('APP_VERSION','1.0.2');
+//入口文件路径
+define('APP_FILENAME', __FILE__);