|
@@ -0,0 +1,93 @@
|
|
|
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
+
|
|
|
+include_once(FCPATH . 'application/controllers/Base_Controller.php');
|
|
|
+class Company extends Base_Controller {
|
|
|
+
|
|
|
+ public function __construct() {
|
|
|
+ parent::__construct();
|
|
|
+ $this->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) $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,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(){
|
|
|
+ $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']));
|
|
|
+
|
|
|
+ if (empty($id)) { // 添加
|
|
|
+ if ($this->Company_model->getDataCount(array('name'=>$name)) > 0) {
|
|
|
+ exit(json_result('1003', $this->response['1003']));
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId,'createTime'=>date('Y-m-d H:i:s',time()));
|
|
|
+ $this->Company_model->add($data);
|
|
|
+ }else { // 编辑
|
|
|
+ if ($this->Company_model->getDataCount(array('name'=>$name),$id) > 0) {
|
|
|
+ exit(json_result('1003', $this->response['1003']));
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = array('type'=>$type,'name'=>$name,'companyId'=>$companyId);
|
|
|
+ $this->Company_model->update($data,['id'=>$id]);
|
|
|
+ }
|
|
|
+
|
|
|
+ exit(json_result('0000',$this->response['0000']));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除公司
|
|
|
+ public function del(){
|
|
|
+ $id = intval($this->input->post('id',true));
|
|
|
+ if (empty($id)) exit(json_result('0007',$this->response['0007']));
|
|
|
+
|
|
|
+ $res = $this->Project_model->get_one(['companyId'=>$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();
|
|
|
+
|
|
|
+ $type = intval($this->input->post('type',true));
|
|
|
+ if (empty($type)) exit(json_result('0007',$this->response['0007']));
|
|
|
+
|
|
|
+ $where['type'] = $type;
|
|
|
+
|
|
|
+ $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)));
|
|
|
+ }
|
|
|
+}
|