| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 | 
							- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
- class Common extends CI_Controller {
 
-     
 
-     var $response;
 
-     var $userinfo;
 
-     var $version;
 
-     public function __construct() {
 
-         parent::__construct();
 
-         $this->load->model('User_model');
 
-         $this->response = $this->config->config['response_en'];
 
-         $version = 1;
 
-         $this->session->set_userdata('version', $version);
 
-         $this->version = $version;
 
-     }
 
-     // 系统日志
 
-     protected function add_operation_log($optype, $content, $logtype = 1,$language=0){
 
-         $role = $this->userinfo['role'];
 
-         $companyid = $this->userinfo['company'];
 
-         $this->load->model('Syslog_model');
 
-         $userid = $this->userinfo['id'];
 
-         $data = array(
 
-             'time'     => date('Y-m-d H:i:s',time()),
 
-             'logtype'  => $logtype,
 
-             'optype'   => $optype,
 
-             'userid'   => $userid,
 
-             'content'  => $content,
 
-             'language' => $language
 
-         );
 
-         if ($role != SYSTEM_ADMIN) {
 
-             $data['company'] = $companyid;
 
-         }
 
-         $this->Syslog_model->add($data);
 
-     }
 
-     public function login() {
 
-         $this->load->model('Company_model');
 
-         $username = $this->input->post('username',true);
 
-         $password = $this->input->post('password',true);
 
-         $client_key = $this->input->post('client_key',true);
 
-         $role = $this->input->post('role',true);
 
-         $code = $this->input->post('code',true);
 
-         $os = intval($this->input->post('os',true));
 
-         if(empty($client_key)) exit(json_result('0003', $this->response['0003']));
 
-         if(empty($username) || empty($password)) exit(json_result('0100', $this->response['0100']));
 
-         $password = md5($password);
 
-         if(empty($os) && empty($code)) exit(json_result('0105', $this->response['0105']));
 
-         if (empty($os) && !isset($_SESSION['login_code'])) exit(json_result('0106',$this->response['0106']));
 
-         if (empty($os) && $_SESSION['login_code'] != $code) exit(json_result('0107',$this->response['0107']));
 
-         $user = $this->User_model->get_one(array('username'=>$username,'role'=>$role));
 
-         if(!empty($user)) {
 
-             if ($user['password'] != $password) {
 
-                 exit(json_result('0101', $this->response['0101']));
 
-             }
 
-             $comInfo = $this->Company_model->get_one(['id'=>$user['company']],'name,no');
 
-             $company = !empty($comInfo['no']) ? $comInfo['no'] : $comInfo['name'];
 
-             $data = array(
 
-                 'token' => generate_token($username, $password, $client_key),
 
-                 'username' => $user['username'],
 
-                 'id' => $user['id'],
 
-                 'role' => intval($user['role']),
 
-                 'name' => $user['name'],
 
-                 'privilege' => $user['privilege'],
 
-                 'avatar' => empty($user['avatar']) ? '' : base_url($user['avatar']),
 
-                 'company' => $company
 
-             );
 
-             
 
-             $this->userinfo = $user;
 
-             $this->add_operation_log('login','用户登录',0);
 
-             $this->add_operation_log('login','login',0,1);
 
-             exit(json_result('0000', $this->response['0000'], $data));
 
-         } else {
 
-             exit(json_result('0102', $this->response['0102']));
 
-         }
 
-     }
 
-     // 图片上传
 
-     public function update_file(){
 
-         $type = intval($this->input->post("fileType",true));
 
-         $path = '../upload/image';
 
-         $config['file_name'] = md5(uniqid());   // 设置图片名字
 
-        
 
-         if (!file_exists($path)) {
 
-             mkdir($path);
 
-         }
 
-         $config['upload_path']      = $path.'/';   // 设置图片上传路径
 
-         $config['allowed_types']    = '*';  // 设置图片上传格式
 
-         $config['max_size']     = 10240;   // 设置文件上传大小
 
-         
 
-         $this->load->library('upload', $config);
 
-         if ( ! $this->upload->do_upload('file'))
 
-         {
 
-             $error = array('error' => $this->upload->display_errors('',''));
 
-             // if (empty($this->version)) {
 
-                 // $data = array('error'=>transfer_error_tips($error['error']));
 
-             // }else{
 
-                 $data = array('error'=>$error['error']);
 
-             // }
 
-             exit(json_result('0012',$this->response['0012'],$data));
 
-         }
 
-         else
 
-         {
 
-             $data = $this->upload->data();
 
-             $imagePath = '/upload/image/'.$data['file_name'];
 
-             
 
-             exit(json_result('0000',$this->response['0000'],array('path'=>base_url($imagePath))));
 
-         }
 
-     }
 
-     public function get_country() {
 
-         $this->load->model('Global_location_model');
 
-         $version = $this->session->userdata('version');
 
-         if (empty($version)) {
 
-             $data = $this->Global_location_model->get_list(['level'=>1,'id'=>92], 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }else{
 
-             $data = $this->Global_location_model->get_list(['level'=>1,'id'=>92], 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }
 
-         
 
-         exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
 
-     }
 
-     public function get_province() {
 
-         $country_id = intval($this->input->post('countryId',true));
 
-         $country_id = 92;
 
-         $this->load->model('Global_location_model');
 
-         $version = $this->session->userdata('version');
 
-         if (empty($country_id)) {
 
-             exit(json_result('0000', $this->response['0000'], ['list'=>[]]));
 
-         }else{
 
-             $where = ['level'=>2, 'pid'=>$country_id];
 
-         }
 
-         if (empty($version)) {
 
-             $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }else{
 
-             $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }
 
-         exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
 
-     }
 
-     public function get_city() {
 
-         $province_id = intval($this->input->post('provinceId',true));
 
-         $this->load->model('Global_location_model');
 
-         $version = $this->session->userdata('version');
 
-         if (empty($province_id)) {
 
-             exit(json_result('0000', $this->response['0000'], ['list'=>[]]));
 
-         }else{
 
-             $where = ['level'=>3, 'pid'=>$province_id];
 
-         }
 
-         if (empty($version)) {
 
-             $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }else{
 
-             $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }
 
-         exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
 
-     }
 
-     public function get_area() {
 
-         $cityId = intval($this->input->post('cityId',true));
 
-         $this->load->model('Global_location_model');
 
-         $version = $this->session->userdata('version');
 
-         if (empty($cityId)) {
 
-             exit(json_result('0000', $this->response['0000'], ['list'=>[]]));
 
-         }else{
 
-             $where = ['level'=>4, 'pid'=>$cityId];
 
-         }
 
-         if (empty($version)) {
 
-             $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }else{
 
-             $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
-         }
 
-         exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
 
-     }
 
-     public function get_code_image(){
 
-         $type = intval($this->input->post('type',true));
 
-         $this->load->helper('captcha');
 
-         if (!file_exists('../upload')) mkdir('../upload');
 
-         if (!file_exists('../upload/image')) mkdir('../upload/image');
 
-         if (!file_exists('../upload/image/code')) mkdir('../upload/image/code');
 
-         $url = '/upload/image/code';
 
-         $code = rand(1000,9999);
 
-         $vals = array(
 
-             'word'      => $code,
 
-             'img_path'  => '../upload/image/code/',
 
-             'img_url'   => $url,
 
-             'img_width' => 120,
 
-             'font_path' => '../file/font/PingFangRegular.ttf',
 
-             'img_height'    => 36,
 
-             'expiration'    => 600,
 
-             'word_length'   => 4,
 
-             'font_size' => 20,
 
-             'img_id'    => 'Imageid',
 
-         );
 
-         
 
-         $cap = create_captcha($vals);
 
-         $filename = $cap['filename'];
 
-         $url .= '/'.$filename;
 
-         $this->load->library('session');
 
-         if ($type == 0) {
 
-             $this->session->set_userdata('login_code', $code);
 
-         }else {
 
-             $this->session->set_userdata('password_code', $code);
 
-         }
 
-         exit(json_result('0000',$this->response['0000'],array('path'=>base_url($url))));
 
-     }
 
-     public function model_nav(){
 
-         $supId = intval($this->input->post('supId',true));
 
-         if (empty($supId)) exit(json_result('0007',$this->response['0007']));
 
-         $list = $this->db->query('select id,name from model_info where supId = '.$supId)->result_array();
 
-         exit(json_result('0000',$this->response['0000'],['list'=>$list]));
 
-     }
 
-     // 图片上传
 
-     public function update_firewalld(){
 
-         // var_dump($_FILES);
 
-         // $type = intval($this->input->post("fileType",true));
 
-         $filename = trim($_FILES['file']['name']);
 
-         $path = '../upload/firewalld';
 
-         $config['file_name'] = $filename;
 
-         if (!file_exists('../upload')) mkdir('../upload');
 
-         if (!file_exists('../upload/firewalld')) mkdir('../upload/firewalld');
 
-         $config['upload_path']      = $path.'/';   // 设置图片上传路径
 
-         $config['allowed_types']    = '*';  // 设置图片上传格式
 
-         $config['max_size']     = 10240;   // 设置文件上传大小
 
-         
 
-         $this->load->library('upload', $config);
 
-         if ( ! $this->upload->do_upload('file'))
 
-         {
 
-             $error = array('error' => $this->upload->display_errors('',''));
 
-             // if (empty($this->version)) {
 
-                 // $data = array('error'=>transfer_error_tips($error['error']));
 
-             // }else{
 
-                 $data = array('error'=>$error['error']);
 
-             // }
 
-             exit(json_result('0012',$this->response['0012'],$data));
 
-         }
 
-         else
 
-         {
 
-             $data = $this->upload->data();
 
-             $imagePath = '/upload/firewalld/'.$data['file_name'];
 
-             
 
-             exit(json_result('0000',$this->response['0000'],array('path'=>$imagePath)));
 
-         }
 
-     }
 
-     public function firewalld(){
 
-         $this->load->view('common/index');
 
-     }
 
-     // 获取制造商下拉列表
 
-     public function manu_nav(){
 
-         $list = $this->db->query('select id,name,no from company where type = 2 and companyId != ""')->result_array();
 
-         foreach ($list as $key => $value) {
 
-             if (!empty($value['no'])) {
 
-                 $list[$key]['name'] = $value['no'];
 
-             }
 
-         }
 
-         exit(json_result('0000',$this->response['0000'],['list'=>$list]));
 
-     }
 
-     // 通过设备地址获取制造商id
 
-     public function get_manu_by_address(){
 
-         $address = $this->input->post('address',true);
 
-         $name = '';
 
-         if ($address === '' || $address === null){
 
-             $id = 0;
 
-         }else{
 
-             $companyId = substr($address,0,2);
 
-             $res = $this->db->query('select id,name,no from company where companyId like "'.$companyId.'%" order by id desc')->row_array();
 
-             if (empty($res) || empty($res['id'])) {
 
-                 $id = 0;
 
-             }else{
 
-                 $id = $res['id'];
 
-                 if (!empty($res['no'])) {
 
-                     $name = $res['no'];
 
-                 }else{
 
-                     $name = $res['name'];
 
-                 }
 
-             }
 
-         }
 
-         exit(json_result('0000',$this->response['0000'],array('id'=>$id,'name'=>$name)));
 
-     }
 
-     // 上传固件文件
 
-     public function uploadFilewalld(){
 
-         $body = file_get_contents('php://input');
 
-         $body = json_decode($body,true);
 
-         $path = $body['path'];
 
-         $version = $body['version'];
 
-         $manuId = $body['manuId'];
 
-         $infodata = $this->db->query('select * from firmware_info where manuId = '.$manuId)->row_array();
 
-         $data = ['version'=>$version,'path'=>$path,'manuId'=>$manuId];
 
-         if (empty($infodata)) {
 
-             $this->db->insert('firmware_info', $data);
 
-         }else{
 
-             $this->db->where('id', $infodata['id']);
 
-             $this->db->update('firmware_info', $data);
 
-         }
 
-         exit(json_result('0000',$this->response['0000']));
 
-     }
 
-     public function workmode() {
 
-         $version = $this->session->userdata('version');
 
-         if (empty($version)) {
 
-             $data = (object)array(
 
-                 0 => '纯光控、光控开负载、光控关负载',
 
-                 1 => '光控开负载,延时1小时后关闭负载',
 
-                 2 => '光控开负载,延时2小时后关闭负载',
 
-                 3 => '光控开负载,延时3小时后关闭负载',
 
-                 4 => '光控开负载,延时4小时后关闭负载',
 
-                 5 => '光控开负载,延时5小时后关闭负载',
 
-                 6 => '光控开负载,延时6小时后关闭负载',
 
-                 7 => '光控开负载,延时7小时后关闭负载',
 
-                 8 => '光控开负载,延时8小时后关闭负载',
 
-                 9 => '光控开负载,延时9小时后关闭负载',
 
-                 10 => '光控开负载,延时10小时后关闭负载',
 
-                 11 => '光控开负载,延时11小时后关闭负载',
 
-                 12 => '光控开负载,延时12小时后关闭负载',
 
-                 13 => '光控开负载,延时13小时后关闭负载',
 
-                 14 => '光控开负载,延时14小时后关闭负载',
 
-                 15 => '手动模式',
 
-                 16 => '调试模式',
 
-                 17 => '常开模式'
 
-             );
 
-         }else{
 
-             $data = (object)array(
 
-                 0 => 'Pure light control, light control open load, light control load',
 
-                 1 => 'Light control open load, delay 1 hours to close the load',
 
-                 2 => 'Light control open load, delay 2 hours to close the load',
 
-                 3 => 'Light control open load, delay 3 hours to close the load',
 
-                 4 => 'Light control open load, delay 4 hours to close the load',
 
-                 5 => 'Light control open load, delay 5 hours to close the load',
 
-                 6 => 'Light control open load, delay 6 hours to close the load',
 
-                 7 => 'Light control open load, delay 7 hours to close the load',
 
-                 8 => 'Light control open load, delay 8 hours to close the load',
 
-                 9 => 'Light control open load, delay 9 hours to close the load',
 
-                 10 => 'Light control open load, delay 10 hours to close the load',
 
-                 11 => 'Light control open load, delay 11 hours to close the load',
 
-                 12 => 'Light control open load, delay 12 hours to close the load',
 
-                 13 => 'Light control open load, delay 13 hours to close the load',
 
-                 14 => 'Light control open load, delay 14 hours to close the load',
 
-                 15 => 'Manual mode',
 
-                 16 => 'Debug mode',
 
-                 17 => 'Open mode'
 
-             );
 
-         }
 
-         
 
-         exit(json_result('0000', $this->response['0000'], $data));
 
-     }
 
-     
 
- }
 
 
  |