Company.php 3.2 KB

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