PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/user.php

https://gitlab.com/lisit1003/TTPHPServer
PHP | 176 lines | 164 code | 12 blank | 0 comment | 13 complexity | efe9235cc60b155711c25027c3a0f7ea MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(APPPATH."core/TT_Controller.php");
  3. class User extends TT_Controller {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. $this->load->helper('url');
  8. $this->load->model('user_model');
  9. $this->load->model('depart_model');
  10. }
  11. public function index()
  12. {
  13. $this->config->site_url();
  14. $this->load->view('base/header');
  15. $this->load->view('base/user');
  16. $this->load->view('base/footer');
  17. }
  18. public function all()
  19. {
  20. $perpage = 10000;
  21. $departs = $this->depart_model->getList(array('status'=>0,'pid !='=>0), '*', 0, $perpage);
  22. $_departs = array();
  23. foreach ($departs as $key => $value) {
  24. $_departs[$value['id']] = $value;
  25. }
  26. $start = $this->input->get('start');
  27. if(!$start){
  28. $start = 0;
  29. }
  30. $perpage = 10;
  31. $users = $this->user_model->getList(array('status'=>0), '*', $start*$perpage, $perpage);
  32. foreach ($users as $key => $value) {
  33. if($value['sex'] == 0){
  34. $users[$key]['sex'] = '女';
  35. }else{
  36. $users[$key]['sex'] = '男';
  37. }
  38. if(isset($_departs[$value['departId']])){
  39. $users[$key]['depart_value'] = $_departs[$value['departId']]['title'];
  40. }else{
  41. $users[$key]['depart_value'] = '数据错误';
  42. }
  43. if($users[$key]['avatar']){
  44. $users[$key]['avatar_value'] = $this->config->config['msfs_url'].$users[$key]['avatar'];
  45. }
  46. }
  47. $count = $this->user_model->getCount(array('status'=>0));
  48. $result = array(
  49. 'users'=>$users,
  50. 'page'=>$start,
  51. 'count'=>ceil($count/10),
  52. 'departs'=>$_departs
  53. );
  54. echo json_encode($result);
  55. }
  56. public function del()
  57. {
  58. $id = $this->input->post('id');
  59. $result = $this->user_model->update(array('status'=>1), $id);
  60. if($result){
  61. echo 'success';
  62. }
  63. }
  64. public function add()
  65. {
  66. $params = array(
  67. 'title'=>$this->input->post('title'),
  68. 'uname'=>$this->input->post('uname'),
  69. 'pwd'=>md5($this->input->post('title')),
  70. 'avatar'=>$this->input->post('avatar'),
  71. 'nickName'=>$this->input->post('nickName'),
  72. 'departId'=>$this->input->post('departId'),
  73. 'sex'=>$this->input->post('sex'),
  74. 'position'=>$this->input->post('position'),
  75. 'mail'=>$this->input->post('mail'),
  76. 'telphone'=>$this->input->post('telphone'),
  77. 'jobNumber'=>$this->input->post('jobNumber'),
  78. 'created'=>time(),
  79. 'updated'=>time()
  80. );
  81. $result = $this->user_model->insert($params);
  82. if($result){
  83. echo 'success';
  84. }
  85. }
  86. public function edit()
  87. {
  88. $params = array(
  89. 'title'=>$this->input->post('title'),
  90. 'uname'=>$this->input->post('uname'),
  91. 'avatar'=>$this->input->post('avatar'),
  92. 'nickName'=>$this->input->post('nickName'),
  93. 'departId'=>$this->input->post('departId'),
  94. 'sex'=>$this->input->post('sex'),
  95. 'position'=>$this->input->post('position'),
  96. 'mail'=>$this->input->post('mail'),
  97. 'telphone'=>$this->input->post('telphone'),
  98. 'jobNumber'=>$this->input->post('jobNumber'),
  99. 'updated'=>time()
  100. );
  101. $id = $this->input->post('id');
  102. $pwd = $this->input->post('pwd');
  103. if($pwd){
  104. $params['pwd'] = md5($pwd);
  105. }
  106. $result = $this->user_model->update($params,$id);
  107. if($result){
  108. echo 'success';
  109. }
  110. }
  111. public function get()
  112. {
  113. $id = $this->input->post('id');
  114. $result = $this->user_model->getOne(array('id'=>$id));
  115. if($result){
  116. echo json_encode($result);
  117. }
  118. }
  119. public function upload()
  120. {
  121. try{
  122. $filename=$this->input->get('filename');
  123. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  124. $filename = time().".".$ext;
  125. $input = file_get_contents("php://input");
  126. file_put_contents('./download/'.$filename, $input);
  127. $res = $this->_upload('./download/'.$filename);
  128. if($res['error_code'] == 0){
  129. $array = array(
  130. 'status' =>'success',
  131. 'file' =>$res['path'],
  132. 'real_path'=>$this->config->config['msfs_url'].$res['path']
  133. );
  134. }else{
  135. $array = array(
  136. 'status' =>'fail',
  137. 'file' =>'',
  138. 'real_path'=>''
  139. );
  140. }
  141. echo json_encode($array);
  142. }
  143. catch(Exception $e)
  144. {
  145. $array = array(
  146. 'status' =>'fail',
  147. 'file' =>0
  148. );
  149. echo json_encode($array);
  150. }
  151. }
  152. public function _upload($filename)
  153. {
  154. $ch = curl_init();
  155. $data = array('filename'=>'@'.$filename);
  156. curl_setopt($ch,CURLOPT_URL,$this->config->config['msfs_url']);
  157. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  158. curl_setopt($ch,CURLOPT_POST,true);
  159. curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
  160. $result = curl_exec($ch);
  161. curl_close($ch);
  162. return json_decode($result,1);
  163. }
  164. }