12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once(FCPATH . 'application/models/Base_model.php');
- class Company_model extends Base_model {
- protected $table = 'company';
- 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;
- }
- }
- }
|