Company.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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,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. if (empty($id)) { // 添加
  38. if ($this->Company_model->getDataCount(array('name'=>$name)) > 0) {
  39. exit(json_result('1003', $this->response['1003']));
  40. }
  41. $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId,'createTime'=>date('Y-m-d H:i:s',time()));
  42. $this->Company_model->add($data);
  43. }else { // 编辑
  44. if ($this->Company_model->getDataCount(array('name'=>$name),$id) > 0) {
  45. exit(json_result('1003', $this->response['1003']));
  46. }
  47. $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId);
  48. $this->Company_model->update($data,['id'=>$id]);
  49. }
  50. exit(json_result('0000',$this->response['0000']));
  51. }
  52. // 删除公司
  53. public function del(){
  54. $role = $this->get_user_info('role');
  55. if ($role != SYSTEM_ADMIN) exit(json_result('0013',$this->response['0013']));
  56. $id = intval($this->input->post('id',true));
  57. if (empty($id)) exit(json_result('0007',$this->response['0007']));
  58. $res = $this->Project_model->get_one(['company'=>$id],'id');
  59. if (!empty($res) && !empty($res['id'])) exit(json_result('',$this->response['']));
  60. $this->Company_model->delete(['id'=>$id]);
  61. exit(json_result('0000',$this->response['0000']));
  62. }
  63. // 公司下拉
  64. public function nav(){
  65. $where = array();
  66. $type = intval($this->input->post('type',true));
  67. if (!empty($type)) $where['type'] = $type;
  68. $list = $this->Company_model->get_list($where, 'id,name',null, null, 'name asc,id desc', NUll);
  69. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  70. }
  71. }