|
@@ -11,58 +11,15 @@ class Base_Controller extends CI_Controller {
|
|
|
|
|
|
parent::__construct();
|
|
|
$this->os = intval($this->input->post('os',true));
|
|
|
- // if ($version === null) {
|
|
|
- // $version = $this->session->userdata('version');
|
|
|
- // }
|
|
|
|
|
|
$this->response = $this->config->config['response_en'];
|
|
|
- $this->load->model('Operation_model');
|
|
|
- $this->load->model('Room_model');
|
|
|
- $this->load->model('Build_model');
|
|
|
- $this->load->model('Hotel_model');
|
|
|
- $this->load->model('Global_location_model');
|
|
|
$this->load->model('User_model');
|
|
|
- $this->load->model('Floor_model');
|
|
|
- $this->load->model('Sensorlog_model');
|
|
|
- $this->load->model('DevInfo_model');
|
|
|
- $this->load->model('TempDevInfo_model');
|
|
|
- $this->load->model('AlarmInfo_model');
|
|
|
- $this->load->model('LampLog_model');
|
|
|
- $this->load->model('AirPurifier_model');
|
|
|
- $this->load->model('Network_model');
|
|
|
$this->check_base_params();
|
|
|
|
|
|
// 判断用户权限
|
|
|
// $this->check_auth();
|
|
|
}
|
|
|
- // 检测用户权限
|
|
|
- // private function check_auth(){
|
|
|
- // if ($this->userinfo['role'] != 1) {
|
|
|
- // $action = uri_string();
|
|
|
- // // 设置基本权限
|
|
|
- // $def = array();
|
|
|
- // if (!in_array($action, $def)) {
|
|
|
- // // 获取用户权限
|
|
|
- // $authid = $this->get_user_info('privilege_list');
|
|
|
- // if (empty($authid)) exit(json_result('0013',$this->response['0013']));
|
|
|
- // $authid = explode(',', $authid);
|
|
|
- // $this->load->model('Privilnode_model');
|
|
|
|
|
|
- // $actions = $this->Privilnode_model->get_list(['id'=>$authid],'action');
|
|
|
- // $actions = explode(',', implode(array_column($actions, 'action'), ','));
|
|
|
-
|
|
|
- // if (!in_array($action, $actions)) {
|
|
|
- // $asy_actions = ['group/inspectionSet','lamp/dimming','lamp/getParam','lamp/setParam','lamp/reset','group/set','lamp/update_lamp_info'];
|
|
|
- // if (in_array($action, $asy_actions)) {
|
|
|
- // $data = ['code'=>'0013','msg'=>$this->response['0013'],'data'=>['status'=>2]];
|
|
|
- // $clientid = $this->input->post('clientid',true);
|
|
|
- // exit(send_websocket($clientid,$data));
|
|
|
- // }
|
|
|
- // exit(json_result('0013',$this->response['0013']));
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
protected function check_base_params() {
|
|
|
$username = $this->input->post('username',true);
|
|
|
$token = $this->input->post('token',true);
|
|
@@ -120,216 +77,7 @@ class Base_Controller extends CI_Controller {
|
|
|
];
|
|
|
$this->Operation_model->add($new);
|
|
|
}
|
|
|
- /**
|
|
|
- * type 0 增加,1 减少
|
|
|
- * deviceType 设备类型(0 lights,1 circadian light,2 sensor,3 purifiers)
|
|
|
- */
|
|
|
- protected function change_room_device_count($roomId,$deviceType,$type,$count = 1){
|
|
|
- if (empty($roomId)) return;
|
|
|
- $roomData = $this->Room_model->get_one(array('id'=>$roomId),'deviceCount,lightCount,cicLightCount,sensorCount,airPurCount');
|
|
|
- if (empty($roomData)) return;
|
|
|
- if ($type == 1) {
|
|
|
- $roomData['deviceCount'] = $roomData['deviceCount'] > $count ? $roomData['deviceCount'] - $count : 0;
|
|
|
- if ($deviceType == 0) {
|
|
|
- $roomData['lightCount'] = $roomData['lightCount'] > $count ? $roomData['lightCount'] - $count : 0;
|
|
|
- }elseif ($deviceType == 1) {
|
|
|
- $roomData['cicLightCount'] = $roomData['cicLightCount'] > $count ? $roomData['cicLightCount'] - $count : 0;
|
|
|
- }elseif ($deviceType == 2) {
|
|
|
- $roomData['sensorCount'] = $roomData['sensorCount'] > $count ? $roomData['sensorCount'] - $count : 0;
|
|
|
- }else{
|
|
|
- $roomData['airPurCount'] = $roomData['airPurCount'] > $count ? $roomData['airPurCount'] - $count : 0;
|
|
|
- }
|
|
|
- }else{
|
|
|
- $roomData['deviceCount'] = $roomData['deviceCount'] + $count;
|
|
|
- if ($deviceType == 0) {
|
|
|
- $roomData['lightCount'] = $roomData['lightCount'] + $count;
|
|
|
- }elseif ($deviceType == 1) {
|
|
|
- $roomData['cicLightCount'] = $roomData['cicLightCount'] + $count;
|
|
|
- }elseif ($deviceType == 2) {
|
|
|
- $roomData['sensorCount'] = $roomData['sensorCount'] + $count;
|
|
|
- }else{
|
|
|
- $roomData['airPurCount'] = $roomData['airPurCount'] + $count;
|
|
|
- }
|
|
|
- }
|
|
|
- $this->Room_model->update($roomData,array('id'=>$roomId));
|
|
|
- }
|
|
|
-
|
|
|
- // 获取时区,可根据房间、楼房、酒店、城市获取时区数据
|
|
|
- protected function get_timezone($id = 0,$type = 0){
|
|
|
- if (empty($id)) return 8;
|
|
|
-
|
|
|
- $join = array(
|
|
|
- ['table'=>'dev_info AS D','cond'=>'D.roomId = R.id','type'=>'left'],
|
|
|
- ['table'=>'floor AS F','cond'=>'F.id = R.floorId','type'=>'left'],
|
|
|
- ['table'=>'build AS B','cond'=>'F.buildId = B.id','type'=>'left'],
|
|
|
- ['table'=>'hotel AS H','cond'=>'B.hotelId = H.id','type'=>'left'],
|
|
|
- ['table'=>'global_location AS G','cond'=>'G.id = H.cityId','type'=>'left']
|
|
|
- );
|
|
|
- $where = array();
|
|
|
- if ($type == ROOM) {
|
|
|
- $where['R.id'] = $id;
|
|
|
- }elseif ($type == HOTEL) {
|
|
|
- $where['H.id'] = $id;
|
|
|
- }elseif ($type == FLOOR) {
|
|
|
- $where['F.id'] = $id;
|
|
|
- }elseif ($type == BUILD) {
|
|
|
- $where['B.id'] = $id;
|
|
|
- }elseif ($type == CITY) {
|
|
|
- $where['G.id'] = $id;
|
|
|
- }elseif ($type == DEVICE) {
|
|
|
- $where['D.id'] = $id;
|
|
|
- }else{
|
|
|
- return 8;
|
|
|
- }
|
|
|
- $res = $this->Room_model->get_list_by_multi_join($where, 'G.timezone',NULL, NULL, $join, NULL, NUll, 'R', true);
|
|
|
- return empty($res) ? 8 : $res['timezone'];
|
|
|
- }
|
|
|
- /**
|
|
|
- * type 0 房间,1 楼房
|
|
|
- */
|
|
|
- protected function update_user_personnel($id,$pid,$type=0){
|
|
|
- if ($type == BUILD) {
|
|
|
- $userList = $this->User_model->get_list(array('buildId|'=>$id),'hotelId,id');
|
|
|
- if (!empty($userList)) {
|
|
|
- foreach ($userList as $user) {
|
|
|
- if (empty($user['hotelId'])) {
|
|
|
- $this->User_model->update(array('hotelId'=>$pid),array('id'=>$user['id']));
|
|
|
- }else{
|
|
|
- $hotelArr = explode(',', $user['hotelId']);
|
|
|
- if (!in_array($pid, $hotelArr)) {
|
|
|
- $hotelArr[] = $pid;
|
|
|
- $ids = implode(',', $hotelArr);
|
|
|
- $this->User_model->update(array('hotelId'=>$ids),array('id'=>$user['id']));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif ($type == ROOM){
|
|
|
- $buildData = $this->Build_model->get_one(array('id'=>$pid),'hotelId');
|
|
|
- if (empty($buildData)) return;
|
|
|
- $userList = $this->User_model->get_list(array('room|'=>$id),'hotelId,buildId,id');
|
|
|
- if (!empty($userList)) {
|
|
|
- foreach ($userList as $user) {
|
|
|
- if (empty($user['buildId'])) {
|
|
|
- $this->User_model->update(array('buildId'=>$pid),array('id'=>$user['id']));
|
|
|
- }else{
|
|
|
- $buildArr = explode(',', $user['buildId']);
|
|
|
- if (!in_array($pid, $buildArr)) {
|
|
|
- $buildArr[] = $pid;
|
|
|
- $ids = implode(',', $buildArr);
|
|
|
- $this->User_model->update(array('buildId'=>$ids),array('id'=>$user['id']));
|
|
|
- }
|
|
|
- }
|
|
|
- if (empty($user['hotelId'])) {
|
|
|
- $this->User_model->update(array('hotelId'=>$buildData['hotelId']),array('id'=>$user['id']));
|
|
|
- }else{
|
|
|
- $hotelArr = explode(',', $user['hotelId']);
|
|
|
- if (!in_array($buildData['hotelId'], $hotelArr)) {
|
|
|
- $hotelArr[] = $buildData['hotelId'];
|
|
|
- $ids = implode(',', $hotelArr);
|
|
|
- $this->User_model->update(array('hotelId'=>$ids),array('id'=>$user['id']));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * type ROOM 房间,BUILD 楼房,HOTEL 酒店,FLOOR 楼层
|
|
|
- */
|
|
|
- protected function del_user_personnel($id,$type=0){
|
|
|
- if ($type == BUILD) {
|
|
|
- $userList = $this->User_model->get_list(array('buildId|'=>$id),'buildId,id');
|
|
|
- if (!empty($userList)) {
|
|
|
- foreach ($userList as $user) {
|
|
|
- if (!empty($user['buildId'])) {
|
|
|
- $buildArr = explode(',', $user['buildId']);
|
|
|
- if (in_array($id, $buildArr)) {
|
|
|
- $temp = array();
|
|
|
- foreach ($buildArr as $bId) {
|
|
|
- if ($id != $bId) $temp[] = $bId;
|
|
|
- }
|
|
|
- $ids = empty($temp) ? '' : implode(',', $temp);
|
|
|
- $this->User_model->update(array('buildId'=>$ids),array('id'=>$user['id']));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif ($type == HOTEL) {
|
|
|
- $userList = $this->User_model->get_list(array('hotelId|'=>$id),'hotelId,id');
|
|
|
- if (!empty($userList)) {
|
|
|
- foreach ($userList as $user) {
|
|
|
- if (!empty($user['hotelId'])) {
|
|
|
- $hotelArr = explode(',', $user['hotelId']);
|
|
|
- if (in_array($id, $hotelArr)) {
|
|
|
- $temp = array();
|
|
|
- foreach ($hotelArr as $bId) {
|
|
|
- if ($id != $bId) $temp[] = $bId;
|
|
|
- }
|
|
|
- $ids = empty($temp) ? '' : implode(',', $temp);
|
|
|
- $this->User_model->update(array('hotelId'=>$ids),array('id'=>$user['id']));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif ($type == ROOM) {
|
|
|
- $userList = $this->User_model->get_list(array('roomId|'=>$id),'roomId,id');
|
|
|
- if (!empty($userList)) {
|
|
|
- foreach ($userList as $user) {
|
|
|
- if (!empty($user['roomId'])) {
|
|
|
- $roomArr = explode(',', $user['roomId']);
|
|
|
- if (in_array($id, $roomArr)) {
|
|
|
- $temp = array();
|
|
|
- foreach ($roomArr as $bId) {
|
|
|
- if ($id != $bId) $temp[] = $bId;
|
|
|
- }
|
|
|
- $ids = empty($temp) ? '' : implode(',', $temp);
|
|
|
- $this->User_model->update(array('roomId'=>$ids),array('id'=>$user['id']));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif ($type == FLOOR) {
|
|
|
- $userList = $this->User_model->get_list(array('floorId|'=>$id),'floorId,id');
|
|
|
- if (!empty($userList)) {
|
|
|
- foreach ($userList as $user) {
|
|
|
- if (!empty($user['floorId'])) {
|
|
|
- $roomArr = explode(',', $user['floorId']);
|
|
|
- if (in_array($id, $roomArr)) {
|
|
|
- $temp = array();
|
|
|
- foreach ($roomArr as $bId) {
|
|
|
- if ($id != $bId) $temp[] = $bId;
|
|
|
- }
|
|
|
- $ids = empty($temp) ? '' : implode(',', $temp);
|
|
|
- $this->User_model->update(array('floorId'=>$ids),array('id'=>$user['id']));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 获取酒店id
|
|
|
- protected function get_hotel_ids(){
|
|
|
- if ($this->get_user_info('role') == SYSTEM_ADMIN) {
|
|
|
- $roomId = $this->get_user_info('roomId');
|
|
|
- if (empty($roomId)) return array();
|
|
|
- $join = array();
|
|
|
- $join[] = ['table'=>'build as B','cond'=>'B.id = R.buildId','type'=>'left'];
|
|
|
- $join[] = ['table'=>'hotel as H','cond'=>'H.id = B.hotelId','type'=>'left'];
|
|
|
- $hotelList = $this->Room_model->get_list_by_join(array('R.id'=>explode(',', $roomId)), 'H.id as id',NULL, NULL, $join, NULL, NUll, 'R');
|
|
|
- }else{
|
|
|
- $hotelList = $this->Hotel_model->get_list(array(),'id');
|
|
|
- }
|
|
|
- $hotelIds = array_column($hotelList, 'id');
|
|
|
- return $hotelIds;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 导出数据
|
|
|
protected function export($fileName = '导出数据', $titles = [], $data= []){
|