load->model('Company_model'); $this->load->model('Project_model'); } // 公司列表 public function get_list(){ $where = array(); $keyword = $this->input->post('keyword',true); $type = $this->input->post('type',true); if ($keyword !== '' && $keyword !== null) $where['name|'] = $keyword; if ($type !== '' && $type !== null && !empty($type)) $where['type'] = $type; // 分页数据 $page = intval($this->input->post('page',true)); $page = empty($page) ? 1 : $page; $count = intval($this->input->post('count',true)); $limit = empty($count) ? 10 : $count; $offset = ($page - 1)*$count; $list = $this->Company_model->get_list($where, 'id,name,type,no,companyId',$limit, $offset, 'name asc,id desc', NUll); $total = $this->Company_model->get_count($where); exit(json_result('0000',$this->response['0000'],array('list'=>$list,'total'=>$total))); } // 添加编辑公司 public function save(){ $role = $this->get_user_info('role'); if ($role != SYSTEM_ADMIN) exit(json_result('0013',$this->response['0013'])); $id = intval($this->input->post('id',true)); $name = $this->input->post('name',true); if ($name === '' || $name === null) exit(json_result('1000',$this->response['1000'])); $companyId = $this->input->post('companyId',true); if ($companyId === '' || $companyId === null) exit(json_result('1001',$this->response['1001'])); $type = intval($this->input->post('type',true)); if ($type === '' || $type === null) exit(json_result('1002',$this->response['1002'])); $no = trim($this->input->post('no',true)); if (empty($id)) { // 添加 if ($this->Company_model->getDataCount(array('name'=>$name)) > 0) { exit(json_result('1003', $this->response['1003'])); } if ($no !== '' && $no !== null && $this->Company_model->getDataCount(array('no'=>$no)) > 0) { exit(json_result('1004', $this->response['1004'])); } $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId,'createTime'=>date('Y-m-d H:i:s',time())); if ($no !== '' && $no !== null) $data['no'] = $no; $this->Company_model->add($data); }else { // 编辑 if ($this->Company_model->getDataCount(array('name'=>$name),$id) > 0) { exit(json_result('1003', $this->response['1003'])); } if ($no !== '' && $no !== null && $this->Company_model->getDataCount(array('no'=>$no),$id) > 0) { exit(json_result('1004', $this->response['1004'])); } $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId); $data['no'] = $no; $this->Company_model->update($data,['id'=>$id]); } exit(json_result('0000',$this->response['0000'])); } // 删除公司 public function del(){ $role = $this->get_user_info('role'); if ($role != SYSTEM_ADMIN) exit(json_result('0013',$this->response['0013'])); $id = intval($this->input->post('id',true)); if (empty($id)) exit(json_result('0007',$this->response['0007'])); $res = $this->Project_model->get_one(['company'=>$id],'id'); if (!empty($res) && !empty($res['id'])) exit(json_result('',$this->response[''])); $this->Company_model->delete(['id'=>$id]); exit(json_result('0000',$this->response['0000'])); } // 公司下拉 public function nav(){ $where = array(); $company = $this->get_user_info('company'); $role = $this->get_user_info('role'); // $type = intval($this->input->post('type',true)); if (!empty($type)) $where['type'] = $type; if ($role != SYSTEM_ADMIN) $where['id'] = $company; $list = $this->Company_model->get_list($where, 'id,name',null, null, 'name asc,id desc', NUll); exit(json_result('0000',$this->response['0000'],array('list'=>$list))); } }