Browse Source

first commit

git 6 years ago
parent
commit
c4caabe4c0

+ 9 - 0
.gitignore

@@ -0,0 +1,9 @@
+# ---> Linux
+*~
+
+# KDE directory preferences
+.directory
+
+# Linux trash folder which might appear on any partition or disk
+.Trash-*
+

+ 2 - 0
Home/Common/common.php

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

+ 29 - 0
Home/Common/fuc.php

@@ -0,0 +1,29 @@
+<?php
+	/*
+
+	*/
+	function get_userid(){
+		//return $_SESSION[C('SESSION_USER')];//用户ID保存到session时使用
+		$userid = \Jiaruan\UcCookie::get();
+		if($userid){
+			return $userid;
+		}
+		return fd_get_session($_COOKIE['PHPSESSID']);//用户session保存到数据库时使用
+	}
+
+	/*
+
+	*/
+	function get_username(){
+		//$id = $_SESSION[C('SESSION_USER')];
+		$id = get_userid();
+		if(!$id){
+			json_fail('没有获取到用户id');
+		}
+		$userName = MM('uc_user','uc')->where(array('ID'=>$id))->getField('UserName');
+		
+		
+		return $userName;
+	}
+
+

+ 122 - 0
Home/Conf/db_structure.php

@@ -0,0 +1,122 @@
+<?php
+return array (
+  'dpqd_index' => 
+  array (
+    'model_type' => 'virtual',
+    'parent_model' => '',
+    'field_list' => 
+    array (
+      'ID' => 
+      array (
+        'ID' => '11693',
+        'AppID' => 'b4b2a5b1aec0d783a1e0b923cf348c59',
+        'Model' => '2095',
+        'FieldName' => 'ID',
+        'FieldTitle' => 'ID',
+        'FieldType' => 'auto_guid',
+        'FieldLength' => NULL,
+        'FieldDefault' => NULL,
+        'FieldComment' => NULL,
+        'IsRequired' => NULL,
+        'IsReadonly' => NULL,
+        'IsTextField' => '0',
+        'RelationModel' => '',
+        'RelationField' => '',
+        'IsSearchable' => NULL,
+        'IsFormOnly' => NULL,
+        'IsPrimaryKey' => '0',
+        'IsUniqueKey' => NULL,
+        'OrderNum' => '9999',
+      ),
+      'UserName' => 
+      array (
+        'ID' => '11694',
+        'AppID' => 'b4b2a5b1aec0d783a1e0b923cf348c59',
+        'Model' => '2095',
+        'FieldName' => 'UserName',
+        'FieldTitle' => '用户姓名',
+        'FieldType' => 'string',
+        'FieldLength' => '50',
+        'FieldDefault' => NULL,
+        'FieldComment' => NULL,
+        'IsRequired' => NULL,
+        'IsReadonly' => NULL,
+        'IsTextField' => '0',
+        'RelationModel' => '',
+        'RelationField' => '',
+        'IsSearchable' => NULL,
+        'IsFormOnly' => NULL,
+        'IsPrimaryKey' => '0',
+        'IsUniqueKey' => NULL,
+        'OrderNum' => '9999',
+      ),
+      'PassWord' => 
+      array (
+        'ID' => '11695',
+        'AppID' => 'b4b2a5b1aec0d783a1e0b923cf348c59',
+        'Model' => '2095',
+        'FieldName' => 'PassWord',
+        'FieldTitle' => '密码',
+        'FieldType' => 'string',
+        'FieldLength' => '50',
+        'FieldDefault' => NULL,
+        'FieldComment' => NULL,
+        'IsRequired' => NULL,
+        'IsReadonly' => NULL,
+        'IsTextField' => '0',
+        'RelationModel' => NULL,
+        'RelationField' => NULL,
+        'IsSearchable' => NULL,
+        'IsFormOnly' => NULL,
+        'IsPrimaryKey' => '0',
+        'IsUniqueKey' => NULL,
+        'OrderNum' => '9999',
+      ),
+      'Remarks' => 
+      array (
+        'ID' => '11696',
+        'AppID' => 'b4b2a5b1aec0d783a1e0b923cf348c59',
+        'Model' => '2095',
+        'FieldName' => 'Remarks',
+        'FieldTitle' => '备注',
+        'FieldType' => 'string',
+        'FieldLength' => '50',
+        'FieldDefault' => NULL,
+        'FieldComment' => NULL,
+        'IsRequired' => NULL,
+        'IsReadonly' => NULL,
+        'IsTextField' => '0',
+        'RelationModel' => NULL,
+        'RelationField' => NULL,
+        'IsSearchable' => NULL,
+        'IsFormOnly' => NULL,
+        'IsPrimaryKey' => '0',
+        'IsUniqueKey' => NULL,
+        'OrderNum' => '9999',
+      ),
+    ),
+    'many2one_list' => NULL,
+    'one2many_list' => NULL,
+  ),
+  'fuc' => 
+  array (
+    'model_type' => 'funclib',
+    'parent_model' => NULL,
+    'field_list' => 
+    array (
+    ),
+    'many2one_list' => NULL,
+    'one2many_list' => NULL,
+  ),
+  'Common' => 
+  array (
+    'model_type' => 'controller',
+    'parent_model' => NULL,
+    'field_list' => 
+    array (
+    ),
+    'many2one_list' => NULL,
+    'one2many_list' => NULL,
+  ),
+);
+?>

+ 38 - 0
Home/Lib/Action/CommonAction.class.php

@@ -0,0 +1,38 @@
+<?php
+class CommonAction extends Action {
+	/*
+
+	*/
+	public function _initialize(){
+		//项目信息
+		$this->project_id = C('CC_PROJECT_ID');
+		if(!$this->project_id){
+			echo 'project_id empty';
+			return;
+		}
+		$this->site_title = C('SITE_TITLE') ? : '用户中心';
+		$this->site_copyright = C('SITE_COPYRIGHT') ? : '版权所有';
+		
+		//跳过检查登录的操作
+		if(in_array(ACTION_NAME,array('login','login2','register','init') ))
+			return;	
+		if(strpos(ACTION_NAME,'api_')===0)
+			return;
+		
+		//获取用户信息
+		$this->userid = \Jiaruan\UcCookie::get();
+		if(!$this->userid){
+			header('Location: ?s=dpqd_index/login');
+			exit;
+		}
+		$cond = array('ID'=>$this->userid);
+		$this->userinfo = M('uc_user')->where($cond)->find();
+		
+		//跳转到登录页面
+		if(!$this->userinfo){
+			header('Location: ?s=dpqd_index/login');
+			exit;
+		}
+	}
+
+}

+ 93 - 0
Home/Lib/Action/DpqdControlAction.class.php

@@ -0,0 +1,93 @@
+<?php
+class DpqdControlAction extends Action {
+	/*
+
+	*/
+	public function start(){
+		$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(){
+		$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(){
+		$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']);
+		}
+		
+		
+	}
+
+}

+ 249 - 0
Home/Lib/Action/DpqdIndexAction.class.php

@@ -0,0 +1,249 @@
+<?php
+class DpqdIndexAction extends Action {
+	const tableName =  'dpqd_index';
+	/*
+
+	*/
+	public function index(){
+		$this->display();
+	}
+	/*
+
+	*/
+	public function header(){
+		$this->display();
+	}
+	/*
+
+	*/
+	public function jk_left(){
+		$userid = get_userid();
+		$farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
+		$farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
+		$group_list = MM('dpsb_group')->where(array('FarmId'=>$farmid))->select();
+		$device_list = array();
+		foreach($group_list as $row){
+			$device_list[$row['OrgName']] = MM('dpsb_device')->where(array('DeviceGroupId'=>$row['ID']))->select();
+		}
+		$this->assign('farmname',$farmname);
+		$this->assign('device_list',$device_list);
+		$this->display();
+	}
+	/*
+
+	*/
+	public function jk_right(){
+		$deviceid = I('get.id');
+		if(!$deviceid){
+			$userid = get_userid();
+			$farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
+			$farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
+			$group = MM('dpsb_group')->where(array('FarmId'=>$farmid))->order('ID asc')->find();
+			$deviceid = MM('dpsb_device')->where(array('DeviceGroupId'=>$group['ID']))->order('ID asc')->getField('ID');
+		}
+		
+		$groupid = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceGroupId');
+		if(!$groupid){
+			json_fail('设备组不存在');
+		}
+		$farmid = MM('dpsb_group')->where(array('ID'=>$groupid))->getField('FarmId');
+		if(!$farmid){
+			json_fail('农场不存在');
+		}
+		$farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
+		if(!$farmname){
+			json_fail('农场名称不存在');
+		}
+		$where = array(
+			'DeviceId'=>$deviceid,
+			'ChType' => array('IN',\Zndp\Device\ChannelType::SENSOR_TYPES),
+		);
+		$channel_list = MM('dpsb_channel')->where($where)->order('ID asc')->select();
+		$type = new \Zndp\Device\ChannelType;
+		foreach($channel_list as $key=>$row){
+			$channel_list[$key]['Unit1'] = $type->getTypeUnit($row['ChType']);
+			$channel_list[$key]['channelname'] = $type->getDisplayName($row['ChType']) . ($row['ChGroup']+1);
+		}
+		$where = array(
+			'DeviceId'=>$deviceid,
+			'ChType' => array('IN',\Zndp\Device\ChannelType::CONTROL_SENSOR),
+		);
+		$control_list = MM('dpsb_channel')->where($where)->order('ID asc')->select();
+		foreach($control_list as $key=>$value){
+			$control_list[$key]['policyid'] = MM('dpsb_policy')->where(array('DeviceId'=>$deviceid,'Channel'=>$value['ChNumber']))->getField('ID');
+		}
+		$addr = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceAddr');
+		$imei = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceImei');
+		$gathertime = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('GatherTime');
+		$year = date('Y');
+		$month = date('m');
+		$day = date('d');
+		$this->assign('gathertime',$gathertime);
+		$this->assign('channel_list',$channel_list);
+		$this->assign('control_list',$control_list);
+		$this->assign('farmname',$farmname);
+		$this->assign('addr',$addr);
+		$this->assign('imei',$imei);
+		$this->assign('policyid',$policyid);
+		$this->assign('deviceid',$deviceid);
+		$this->assign('year',$year);
+		$this->assign('month',$month);
+		$this->assign('day',$day);
+		$this->display();
+	}
+	/*
+
+	*/
+	public function login(){
+		if($this->isAjax()){
+		  $account = I('post.account');
+		  $password = I('post.password');
+		  if($account=='' || $password==''){
+		    json_fail('参数错误');
+		  }
+		  $cond = array(
+		    'UserName' => $account,
+		    'Password' => \Zndp\User\Util::encPwd($password),
+		  );
+		  $user_info = MM('uc_user')->where($cond)->find();
+		 if(!$user_info){
+			 $this->login_advice($user_info,'登录失败!用户不存在或密码错误.');
+		    exit;
+		  }
+		 if($user_info['IsDisabled']){
+			 $this->login_advice($user_info,'用户已禁用,不可以登录');
+			 exit;
+		  }
+			//检测是否有后台登录权限
+			if($user_info['RoleId'] != \Zndp\User\RoleEnum::FARM_OPERATOR){
+				$this->login_advice($user_info,'无登陆权限!');
+				exit;
+			}
+			//登录成功切点
+			$this->login_advice($user_info,'');
+		
+			//登录成功
+			\Jiaruan\UcCookie::set($user_info['ID']);
+		   $data = array('redirect_url' => '?s=dpqd_index/index');
+			json_success('登陆成功',$data);
+		  
+		}else{
+			$this->display();
+		}
+	}
+	/*
+	参数说明:
+		user_info: 
+		message: 
+
+	*/
+	private function login_advice($user_info, $message){
+		$result = $message? false:true;
+		$password = I('post.password');
+		if($result)
+			$password = "******";
+		
+		$param = array(
+			'account' => I('post.account'),
+			'password' => $password,
+		);
+		
+		$options = array(
+		    'user_info' => $user_info,
+		    'result' => $result,
+			 'message' => $message
+		);
+		PB('uc_after_login',$param,$options);
+		if(!$result){
+			json_fail($message);
+		}
+	}
+	/*
+
+	*/
+	public function sj_left(){
+		$this->display();
+	}
+	/*
+
+	*/
+	public function sj_right(){
+		$userid = get_userid();
+		if(!$userid){
+			json_fail('用户id不存在,请重新登录');
+		}
+		$type =10;
+		$farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
+		if(!$farmid)
+			json_fail('用户下没有农场');
+		$farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
+		$group_list = MM('dpsb_group')->where(array('FarmId'=>$farmid))->select();
+		if(!$group_list)
+			json_fail('农场下没有设备组');
+		$channel_list_data = array();
+		foreach($group_list as $row){
+			$device_list = MM('dpsb_device')->where(array('DeviceGroupId'=>$row['ID']))->select();
+			foreach($device_list as $key=>$device){
+				$channel_data = $this->get_channel_info($device['ID']);
+				array_push($channel_list_data,$channel_data);
+			}
+		}
+		$this->assign('channel_list_data',$channel_list_data);
+		$this->display();
+	}
+	/*
+	参数说明:
+		device_id: 
+
+	*/
+	private function get_channel_info($device_id){
+		$device_name = MM('dpsb_device')->where(array('ID'=>$device_id))->getField('WorkUnitName');
+		if(!$device_name)
+			return false;
+		$data = array(
+			"title" => $device_name,
+			"channels" => array(),
+		);
+		$chtype = new \Zndp\Device\ChannelType;
+		for($i=0;$i<3;$i++){
+			//温度数据
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType' => \Zndp\Device\ChannelType::TEMPERATURE,
+				'ChGroup' => $i,
+				);
+			$temperature_info = MM('dpsb_channel')->where($where)->find();
+			if(!$temperature_info){
+				continue;
+			}
+			$temperature_info['unit'] = $chtype->getTypeUnit($temperature_info['ChType']);
+			array_push($data['channels'],$temperature_info);
+			//湿度数据
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType' => \Zndp\Device\ChannelType::HUMIDITY,
+				'ChGroup' => $i,
+				);
+			$humidity_info = MM('dpsb_channel')->where($where)->find();
+			if(!$humidity_info){
+				continue;
+			}
+			$humidity_info['unit'] = $chtype->getTypeUnit($humidity_info['ChType']);
+			array_push($data['channels'],$humidity_info);
+			//光照数据
+			$where = array(
+				'DeviceId'=>$device_id,
+				'ChType' => \Zndp\Device\ChannelType::ILLINATIONUM,
+				'ChGroup' => $i,
+				);
+			$illumination_info = MM('dpsb_channel')->where($where)->find();
+			if(!$illumination_info){
+				continue;
+			}
+			$illumination_info['unit'] = $chtype->getTypeUnit($illumination_info['ChType']);
+			array_push($data['channels'],$illumination_info);
+		}
+		return $data;
+	}
+
+}

+ 1 - 0
Home/Tpl/DpqdIndex/header.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:cust@zndp@header@1.0.0'}>

+ 1 - 0
Home/Tpl/DpqdIndex/index.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:cust@zndp@index@1.0.0'}>

+ 1 - 0
Home/Tpl/DpqdIndex/jk_left.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:cust@zndp@jk_left@1.0.0'}>

+ 1 - 0
Home/Tpl/DpqdIndex/jk_right.html

@@ -0,0 +1 @@
+<{extends file='jiaruandev:cust@zndp@jk_right@1.0.0'}>

+ 1 - 0
Home/Tpl/DpqdIndex/login.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:login@liger@0.2.0'}>

+ 1 - 0
Home/Tpl/DpqdIndex/sj_left.html

@@ -0,0 +1 @@
+<{extends file='jiaruandev:cust@zndp@sj_left@1.0.0'}>

+ 1 - 0
Home/Tpl/DpqdIndex/sj_right.html

@@ -0,0 +1 @@
+<{extends file='jiaruandev:cust@zndp@sj_right@1.0.0'}>

+ 1 - 0
Home/Tpl/Index/header.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:cust@zndp@index@1.0.0'}>

+ 1 - 0
Home/Tpl/Index/index.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:cust@zndp@header@1.0.0'}>

+ 1 - 0
Home/Tpl/Index/jk_left.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:cust@zndp@jk_left@1.0.0'}>

+ 1 - 0
Home/Tpl/Index/jk_right.html

@@ -0,0 +1 @@
+<{extends file='jiaruan:cust@zndp@jk_right@1.0.0'}>

+ 0 - 3
README.md

@@ -1,3 +0,0 @@
-# dpqd
-
-大棚前端网站,控制柜远端操作

+ 1 - 0
database.json

@@ -0,0 +1 @@
+{"table":[]}

+ 6 - 0
index.php

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

+ 35 - 0
plugin.json

@@ -0,0 +1,35 @@
+{
+  "id": "b4b2a5b1aec0d783a1e0b923cf348c59",
+  "name": "dpqd",
+  "title": "大棚前端",
+  "prefix": "dpqd",
+  "version": "1.0.1",
+  "icon": "",
+  "description": "大棚前端",
+  "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','b4b2a5b1aec0d783a1e0b923cf348c59');
+//插件前缀
+define('APP_PREFIX','dpqd');
+//插件版本
+define('APP_VERSION','1.0.1');
+//入口文件路径
+define('APP_FILENAME', __FILE__);