Company.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/controllers/Base_Controller.php');
  3. class Company extends Base_Controller {
  4. public function __construct() {
  5. parent::__construct();
  6. $this->load->model('Company_model');
  7. $this->load->model('Project_model');
  8. }
  9. // 公司列表
  10. public function get_list(){
  11. $where = array();
  12. $keyword = $this->input->post('keyword',true);
  13. $type = $this->input->post('type',true);
  14. if ($keyword !== '' && $keyword !== null) $where['name|'] = $keyword;
  15. if ($type !== '' && $type !== null && !empty($type)) $where['type'] = $type;
  16. // 分页数据
  17. $page = intval($this->input->post('page',true));
  18. $page = empty($page) ? 1 : $page;
  19. $count = intval($this->input->post('count',true));
  20. $limit = empty($count) ? 10 : $count;
  21. $offset = ($page - 1)*$count;
  22. $list = $this->Company_model->get_list($where, 'id,name,type,no,companyId',$limit, $offset, 'name asc,id desc', NUll);
  23. $total = $this->Company_model->get_count($where);
  24. exit(json_result('0000',$this->response['0000'],array('list'=>$list,'total'=>$total)));
  25. }
  26. // 添加编辑公司
  27. public function save(){
  28. $role = $this->get_user_info('role');
  29. if ($role != SYSTEM_ADMIN) exit(json_result('0013',$this->response['0013']));
  30. $id = intval($this->input->post('id',true));
  31. $name = $this->input->post('name',true);
  32. if ($name === '' || $name === null) exit(json_result('1000',$this->response['1000']));
  33. $companyId = $this->input->post('companyId',true);
  34. if ($companyId === '' || $companyId === null) exit(json_result('1001',$this->response['1001']));
  35. $type = intval($this->input->post('type',true));
  36. if ($type === '' || $type === null) exit(json_result('1002',$this->response['1002']));
  37. $no = trim($this->input->post('no',true));
  38. if (empty($id)) { // 添加
  39. if ($this->Company_model->getDataCount(array('name'=>$name)) > 0) {
  40. exit(json_result('1003', $this->response['1003']));
  41. }
  42. if ($no !== '' && $no !== null && $this->Company_model->getDataCount(array('no'=>$no)) > 0) {
  43. exit(json_result('1004', $this->response['1004']));
  44. }
  45. $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId,'createTime'=>date('Y-m-d H:i:s',time()));
  46. if ($no !== '' && $no !== null) $data['no'] = $no;
  47. $this->Company_model->add($data);
  48. }else { // 编辑
  49. if ($this->Company_model->getDataCount(array('name'=>$name),$id) > 0) {
  50. exit(json_result('1003', $this->response['1003']));
  51. }
  52. if ($no !== '' && $no !== null && $this->Company_model->getDataCount(array('no'=>$no),$id) > 0) {
  53. exit(json_result('1004', $this->response['1004']));
  54. }
  55. $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId);
  56. $data['no'] = $no;
  57. $this->Company_model->update($data,['id'=>$id]);
  58. }
  59. exit(json_result('0000',$this->response['0000']));
  60. }
  61. // 删除公司
  62. public function del(){
  63. $role = $this->get_user_info('role');
  64. if ($role != SYSTEM_ADMIN) exit(json_result('0013',$this->response['0013']));
  65. $id = intval($this->input->post('id',true));
  66. if (empty($id)) exit(json_result('0007',$this->response['0007']));
  67. $res = $this->Project_model->get_one(['company'=>$id],'id');
  68. if (!empty($res) && !empty($res['id'])) exit(json_result('',$this->response['']));
  69. $this->Company_model->delete(['id'=>$id]);
  70. exit(json_result('0000',$this->response['0000']));
  71. }
  72. // 公司下拉
  73. public function nav(){
  74. $where = array();
  75. $company = $this->get_user_info('company');
  76. $role = $this->get_user_info('role');
  77. $type = intval($this->input->post('type',true));
  78. if (!empty($type)) $where['type'] = $type;
  79. // if ($role != SYSTEM_ADMIN) $where['id'] = $company;
  80. $list = $this->Company_model->get_list($where, 'id,name',null, null, 'name asc,id desc', NUll);
  81. foreach ($list as $key => $value) {
  82. if (!empty($value['no'])) $list[$key]['name'] = $value['no'];
  83. }
  84. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  85. }
  86. }