瀏覽代碼

公司管理

wzh 5 年之前
父節點
當前提交
9296b2ec9b
共有 3 個文件被更改,包括 103 次插入87 次删除
  1. 10 4
      api/application/config/response.php
  2. 93 0
      api/application/controllers/Company.php
  3. 0 83
      api/application/models/Company_model.php

+ 10 - 4
api/application/config/response.php

@@ -158,7 +158,11 @@ $config['response']['0911'] = "请选择分组";
 $config['response']['0912'] = "请选择操作类型";
 $config['response']['0913'] = "请选择策略";
 $config['response']['0914'] = "请选择要删除的分组";
-
+//公司管理 1000-1099
+$config['response']['1000'] = "公司名称不能为空";
+$config['response']['1001'] = "公司ID不能为空";
+$config['response']['1002'] = "请选择公司类型";
+$config['response']['1003'] = "公司名称已经存在";
 
 
 // 英文版
@@ -319,8 +323,10 @@ $config['response_en']['0911'] = "Please select a group";
 $config['response_en']['0912'] = "Please select operation type";
 $config['response_en']['0913'] = "Please select a policy";
 $config['response_en']['0914'] = "Please select the group to delete";
-
-
-
+//公司管理 1000-1099
+$config['response_en']['1000'] = "Company name cannot be empty";
+$config['response_en']['1001'] = "Company ID cannot be empty";
+$config['response_en']['1002'] = "Please select company type";
+$config['response_en']['1003'] = "Company name already exists";
 
 

+ 93 - 0
api/application/controllers/Company.php

@@ -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)));
+	}
+}

+ 0 - 83
api/application/models/Company_model.php

@@ -7,88 +7,5 @@ class Company_model extends Base_model {
 	public function __construct() {
 		parent::__construct();
 	}
-    // 获取所有公司的id跟名称
-    public function get_all_company($filter = array()) {
-        $this->db->select('id, name');
-        $this->db->order_by("convert(name using gbk)","ASC");
-        if (isset($filter['keyword'])) {
-            if (!empty($filter['keyword'])) {
-                $this->db->like('name',$filter['keyword']);
-            }
-        }
-        unset($filter['keyword']);
-        foreach ($filter as $key => $value) {
-            if (is_array($value)) {
-                if (!empty($value)) {
-                    $this->db->where_in($key,$value);
-                }else{
-                    $this->db->where_in($key,array(0));
-                }
-            }else{
-                $this->db->where($key,$value);
-            }
-        }
-        // $this->db->order_by('name','ASC');
-        $query = $this->db->get($this->table);
-        return $query->result_array();
-    }
-
-    public function get_zone_by_filter($filter,$role=null,$companyid=null){
-        if ($role == SYSTEM_ADMIN) {
-            if (isset($filter['id'])) {
-                unset($filter['id']);
-            }
-        } else {                
-            $filter['id'] = $companyid;
-        }
-
-        foreach ($filter as $k => $v){
-            if (is_array($v)) {
-                if (!empty($v)) {
-                    $this->db->where_in($k,$v);
-                }else{
-                    $this->db->where_in($k,array(0));
-                }
-            }else{
-                $this->db->where($k,$v);
-            }
-        }
-    
-        $this->db->order_by("name","ASC");
-        $query = $this->db->get($this->table);
-        return $query->result_array();
-    }
     
-    public function get_data_by_id($id, $field = '*',$keyword = ''){
-        $this->db->where('id',$id);
-        if (!empty($keyword)) {
-            $this->db->like('name',$keyword);
-        }
-        $query = $this->db->get($this->table);
-        $row = $query->row_array();
-        if ($field == '*') {
-            return $row;
-        } else {
-            return !empty($row) ? $row[$field] : '';   
-        }
-    }
-
-    public function getDataCount($condition, $id = 0) {
-        if (!empty($condition)){
-            foreach ($condition as $k => $v) {
-                $this->db->where($k,$v);
-            }
-        }
-        if (!empty($id)) {
-            $this->db->where('id !=',$id); 
-        }  
-        $query = $this->db->get($this->table);
-        $company = $query->row_array();
-        if (empty($company)) {
-            return 0;
-        } else { 
-            return $id == $company['id'] ? 0 : 1;
-        }
-    }
-
 }