Common.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Common extends CI_Controller {
  3. var $response;
  4. var $userinfo;
  5. var $version;
  6. public function __construct() {
  7. parent::__construct();
  8. $this->load->model('User_model');
  9. $this->load->model('Hotel_model');
  10. $this->load->model('Build_model');
  11. $this->load->model('Floor_model');
  12. $this->load->model('Room_model');
  13. $this->response = $this->config->config['response_en'];
  14. }
  15. public function login() {
  16. $username = $this->input->post('username',true);
  17. $password = $this->input->post('password',true);
  18. $client_key = $this->input->post('client_key',true);
  19. $code = $this->input->post('code',true);
  20. $os = intval($this->input->post('os',true));
  21. if(empty($client_key)) exit(json_result('0003', $this->response['0003']));
  22. if(empty($username) || empty($password)) exit(json_result('0100', $this->response['0100']));
  23. $password = md5($password);
  24. $user = $this->User_model->get_one(array('username'=>$username));
  25. if(!empty($user)) {
  26. if ($user['password'] != $password) {
  27. exit(json_result('0101', $this->response['0101']));
  28. }
  29. $data = array(
  30. 'token' => generate_token($username, $password, $client_key),
  31. 'username' => $user['username'],
  32. 'id' => $user['id'],
  33. 'role' => intval($user['role']),
  34. 'name' => $user['name'],
  35. );
  36. $this->userinfo = $user;
  37. exit(json_result('0000', $this->response['0000'], $data));
  38. } else {
  39. exit(json_result('0102', $this->response['0102']));
  40. }
  41. }
  42. // 图片上传
  43. public function update_file(){
  44. $type = intval($this->input->post("fileType",true));
  45. if ($type == 0) {
  46. $path = '../upload/image';
  47. $config['file_name'] = md5(uniqid()); // 设置图片名字
  48. }else{
  49. $config['overwrite'] = true;
  50. $filename = trim($_FILES['file']['name']);
  51. if (strpos($filename, 'LampControl_') !== false) {
  52. $path = '../upload/firewalld';
  53. $config['file_name'] = $filename;
  54. }else{
  55. $path = '../upload/firewalld';
  56. $config['file_name'] = 'openwrt-'.md5(uniqid());
  57. }
  58. }
  59. if (!file_exists($path)) {
  60. mkdir($path);
  61. }
  62. $config['upload_path'] = $path.'/'; // 设置图片上传路径
  63. $config['allowed_types'] = '*'; // 设置图片上传格式
  64. $config['max_size'] = 10240; // 设置文件上传大小
  65. $this->load->library('upload', $config);
  66. if ( ! $this->upload->do_upload('file'))
  67. {
  68. $error = array('error' => $this->upload->display_errors('',''));
  69. // if (empty($this->version)) {
  70. // $data = array('error'=>transfer_error_tips($error['error']));
  71. // }else{
  72. $data = array('error'=>$error['error']);
  73. // }
  74. exit(json_result('0012',$this->response['0012'],$data));
  75. }
  76. else
  77. {
  78. $data = $this->upload->data();
  79. if ($type == 0) {
  80. $imagePath = '/upload/image/'.$data['file_name'];
  81. }else{
  82. $imagePath = '/upload/firewalld/'.$data['file_name'];
  83. }
  84. exit(json_result('0000',$this->response['0000'],array('path'=>base_url($imagePath))));
  85. }
  86. }
  87. public function get_country() {
  88. $this->load->model('Global_location_model');
  89. $version = $this->session->userdata('version');
  90. if (empty($version)) {
  91. $data = $this->Global_location_model->get_list(['level'=>1], 'id, chinese_name as name',null,null,'convert(chinese_name using gbk) ASC,id DESC');
  92. }else{
  93. $data = $this->Global_location_model->get_list(['level'=>1], 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  94. }
  95. exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
  96. }
  97. public function get_province() {
  98. $country_id = intval($this->input->post('countryId',true));
  99. $this->load->model('Global_location_model');
  100. $version = $this->session->userdata('version');
  101. if (empty($country_id)) {
  102. exit(json_result('0000', $this->response['0000'], ['list'=>[]]));
  103. }else{
  104. $where = ['level'=>2, 'pid'=>$country_id];
  105. }
  106. if (empty($version)) {
  107. $data = $this->Global_location_model->get_list($where, 'id, chinese_name as name',null,null,'convert(chinese_name using gbk) ASC,id DESC');
  108. }else{
  109. $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  110. }
  111. exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
  112. }
  113. public function get_city() {
  114. $province_id = intval($this->input->post('provinceId',true));
  115. $this->load->model('Global_location_model');
  116. $version = $this->session->userdata('version');
  117. if (empty($province_id)) {
  118. exit(json_result('0000', $this->response['0000'], ['list'=>[]]));
  119. }else{
  120. $where = ['level'=>3, 'pid'=>$province_id];
  121. }
  122. if (empty($version)) {
  123. $data = $this->Global_location_model->get_list($where, 'id, chinese_name as name',null,null,'convert(chinese_name using gbk) ASC,id DESC');
  124. }else{
  125. $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  126. }
  127. exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
  128. }
  129. public function get_area() {
  130. $cityId = intval($this->input->post('cityId',true));
  131. $this->load->model('Global_location_model');
  132. $version = $this->session->userdata('version');
  133. if (empty($cityId)) {
  134. exit(json_result('0000', $this->response['0000'], ['list'=>[]]));
  135. }else{
  136. $where = ['level'=>4, 'pid'=>$cityId];
  137. }
  138. if (empty($version)) {
  139. $data = $this->Global_location_model->get_list($where, 'id, chinese_name as name',null,null,'convert(chinese_name using gbk) ASC,id DESC');
  140. }else{
  141. $data = $this->Global_location_model->get_list($where, 'id, english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  142. }
  143. exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
  144. }
  145. }