DpqdIndexAction.class.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. class DpqdIndexAction extends Action {
  3. const tableName = 'dpqd_index';
  4. /*
  5. */
  6. public function index(){
  7. $this->display();
  8. }
  9. /*
  10. */
  11. public function header(){
  12. $this->display();
  13. }
  14. /*
  15. */
  16. public function jk_left(){
  17. $userid = get_userid();
  18. $farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
  19. $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
  20. $group_list = MM('dpsb_group')->where(array('FarmId'=>$farmid))->select();
  21. $device_list = array();
  22. foreach($group_list as $row){
  23. $device_list[$row['OrgName']] = MM('dpsb_device')->where(array('DeviceGroupId'=>$row['ID']))->select();
  24. }
  25. $this->assign('farmname',$farmname);
  26. $this->assign('device_list',$device_list);
  27. $this->display();
  28. }
  29. /*
  30. */
  31. public function jk_right(){
  32. $deviceid = I('get.id');
  33. if(!$deviceid){
  34. $userid = get_userid();
  35. $farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
  36. $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
  37. $group = MM('dpsb_group')->where(array('FarmId'=>$farmid))->order('ID asc')->find();
  38. $deviceid = MM('dpsb_device')->where(array('DeviceGroupId'=>$group['ID']))->order('ID asc')->getField('ID');
  39. }
  40. $groupid = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceGroupId');
  41. if(!$groupid){
  42. json_fail('设备组不存在');
  43. }
  44. $farmid = MM('dpsb_group')->where(array('ID'=>$groupid))->getField('FarmId');
  45. if(!$farmid){
  46. json_fail('农场不存在');
  47. }
  48. $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
  49. if(!$farmname){
  50. json_fail('农场名称不存在');
  51. }
  52. $where = array(
  53. 'DeviceId'=>$deviceid,
  54. 'ChType' => array('IN',\Zndp\Device\ChannelType::SENSOR_TYPES),
  55. );
  56. $channel_list = MM('dpsb_channel')->where($where)->order('ID asc')->select();
  57. $type = new \Zndp\Device\ChannelType;
  58. foreach($channel_list as $key=>$row){
  59. $channel_list[$key]['Unit1'] = $type->getTypeUnit($row['ChType']);
  60. $channel_list[$key]['channelname'] = $type->getDisplayName($row['ChType']) . ($row['ChGroup']+1);
  61. }
  62. $where = array(
  63. 'DeviceId'=>$deviceid,
  64. 'ChType' => array('IN',\Zndp\Device\ChannelType::CONTROL_SENSOR),
  65. );
  66. $control_list = MM('dpsb_channel')->where($where)->order('ID asc')->select();
  67. foreach($control_list as $key=>$value){
  68. $control_list[$key]['policyid'] = MM('dpsb_policy')->where(array('DeviceId'=>$deviceid,'Channel'=>$value['ChNumber']))->getField('ID');
  69. }
  70. $addr = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceAddr');
  71. $imei = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('DeviceImei');
  72. $gathertime = MM('dpsb_device')->where(array('ID'=>$deviceid))->getField('GatherTime');
  73. $year = date('Y');
  74. $month = date('m');
  75. $day = date('d');
  76. $this->assign('gathertime',$gathertime);
  77. $this->assign('channel_list',$channel_list);
  78. $this->assign('control_list',$control_list);
  79. $this->assign('farmname',$farmname);
  80. $this->assign('addr',$addr);
  81. $this->assign('imei',$imei);
  82. $this->assign('policyid',$policyid);
  83. $this->assign('deviceid',$deviceid);
  84. $this->assign('year',$year);
  85. $this->assign('month',$month);
  86. $this->assign('day',$day);
  87. $this->display();
  88. }
  89. /*
  90. */
  91. public function login(){
  92. if($this->isAjax()){
  93. $account = I('post.account');
  94. $password = I('post.password');
  95. if($account=='' || $password==''){
  96. json_fail('参数错误');
  97. }
  98. $cond = array(
  99. 'UserName' => $account,
  100. 'Password' => \Zndp\User\Util::encPwd($password),
  101. );
  102. $user_info = MM('uc_user')->where($cond)->find();
  103. if(!$user_info){
  104. $this->login_advice($user_info,'登录失败!用户不存在或密码错误.');
  105. exit;
  106. }
  107. if($user_info['IsDisabled']){
  108. $this->login_advice($user_info,'用户已禁用,不可以登录');
  109. exit;
  110. }
  111. //检测是否有后台登录权限
  112. if($user_info['RoleId'] != \Zndp\User\RoleEnum::FARM_OPERATOR){
  113. $this->login_advice($user_info,'无登陆权限!');
  114. exit;
  115. }
  116. //登录成功切点
  117. $this->login_advice($user_info,'');
  118. //登录成功
  119. \Jiaruan\UcCookie::set($user_info['ID']);
  120. $data = array('redirect_url' => '?s=dpqd_index/index');
  121. json_success('登陆成功',$data);
  122. }else{
  123. $this->display();
  124. }
  125. }
  126. /*
  127. 参数说明:
  128. user_info:
  129. message:
  130. */
  131. private function login_advice($user_info, $message){
  132. $result = $message? false:true;
  133. $password = I('post.password');
  134. if($result)
  135. $password = "******";
  136. $param = array(
  137. 'account' => I('post.account'),
  138. 'password' => $password,
  139. );
  140. $options = array(
  141. 'user_info' => $user_info,
  142. 'result' => $result,
  143. 'message' => $message
  144. );
  145. PB('uc_after_login',$param,$options);
  146. if(!$result){
  147. json_fail($message);
  148. }
  149. }
  150. /*
  151. */
  152. public function sj_left(){
  153. $this->display();
  154. }
  155. /*
  156. */
  157. public function sj_right(){
  158. $userid = get_userid();
  159. if(!$userid){
  160. json_fail('用户id不存在,请重新登录');
  161. }
  162. $type =10;
  163. $farmid = MM('uc_user')->where(array('ID'=>$userid))->getField('FarmId');
  164. if(!$farmid)
  165. json_fail('用户下没有农场');
  166. $farmname = MM('dpyh_farm')->where(array('ID'=>$farmid))->getField('FarmName');
  167. $group_list = MM('dpsb_group')->where(array('FarmId'=>$farmid))->select();
  168. if(!$group_list)
  169. json_fail('农场下没有设备组');
  170. $channel_list_data = array();
  171. foreach($group_list as $row){
  172. $device_list = MM('dpsb_device')->where(array('DeviceGroupId'=>$row['ID']))->select();
  173. foreach($device_list as $key=>$device){
  174. $channel_data = $this->get_channel_info($device['ID']);
  175. array_push($channel_list_data,$channel_data);
  176. }
  177. }
  178. $this->assign('channel_list_data',$channel_list_data);
  179. $this->display();
  180. }
  181. /*
  182. 参数说明:
  183. device_id:
  184. */
  185. private function get_channel_info($device_id){
  186. $device_name = MM('dpsb_device')->where(array('ID'=>$device_id))->getField('WorkUnitName');
  187. if(!$device_name)
  188. return false;
  189. $data = array(
  190. "title" => $device_name,
  191. "channels" => array(),
  192. );
  193. $chtype = new \Zndp\Device\ChannelType;
  194. for($i=0;$i<3;$i++){
  195. //温度数据
  196. $where = array(
  197. 'DeviceId'=>$device_id,
  198. 'ChType' => \Zndp\Device\ChannelType::TEMPERATURE,
  199. 'ChGroup' => $i,
  200. );
  201. $temperature_info = MM('dpsb_channel')->where($where)->find();
  202. if(!$temperature_info){
  203. continue;
  204. }
  205. $temperature_info['unit'] = $chtype->getTypeUnit($temperature_info['ChType']);
  206. array_push($data['channels'],$temperature_info);
  207. //湿度数据
  208. $where = array(
  209. 'DeviceId'=>$device_id,
  210. 'ChType' => \Zndp\Device\ChannelType::HUMIDITY,
  211. 'ChGroup' => $i,
  212. );
  213. $humidity_info = MM('dpsb_channel')->where($where)->find();
  214. if(!$humidity_info){
  215. continue;
  216. }
  217. $humidity_info['unit'] = $chtype->getTypeUnit($humidity_info['ChType']);
  218. array_push($data['channels'],$humidity_info);
  219. //光照数据
  220. $where = array(
  221. 'DeviceId'=>$device_id,
  222. 'ChType' => \Zndp\Device\ChannelType::ILLINATIONUM,
  223. 'ChGroup' => $i,
  224. );
  225. $illumination_info = MM('dpsb_channel')->where($where)->find();
  226. if(!$illumination_info){
  227. continue;
  228. }
  229. $illumination_info['unit'] = $chtype->getTypeUnit($illumination_info['ChType']);
  230. array_push($data['channels'],$illumination_info);
  231. }
  232. return $data;
  233. }
  234. }