Company_model.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/models/Base_model.php');
  3. class Company_model extends Base_model {
  4. protected $table = 'company';
  5. public function __construct() {
  6. parent::__construct();
  7. }
  8. // 获取所有公司的id跟名称
  9. public function get_all_company($filter = array()) {
  10. $this->db->select('id, name');
  11. $this->db->order_by("convert(name using gbk)","ASC");
  12. if (isset($filter['keyword'])) {
  13. if (!empty($filter['keyword'])) {
  14. $this->db->like('name',$filter['keyword']);
  15. }
  16. }
  17. unset($filter['keyword']);
  18. foreach ($filter as $key => $value) {
  19. if (is_array($value)) {
  20. if (!empty($value)) {
  21. $this->db->where_in($key,$value);
  22. }else{
  23. $this->db->where_in($key,array(0));
  24. }
  25. }else{
  26. $this->db->where($key,$value);
  27. }
  28. }
  29. // $this->db->order_by('name','ASC');
  30. $query = $this->db->get($this->table);
  31. return $query->result_array();
  32. }
  33. public function get_zone_by_filter($filter,$role=null,$companyid=null){
  34. if ($role == SYSTEM_ADMIN) {
  35. if (isset($filter['id'])) {
  36. unset($filter['id']);
  37. }
  38. } else {
  39. $filter['id'] = $companyid;
  40. }
  41. foreach ($filter as $k => $v){
  42. if (is_array($v)) {
  43. if (!empty($v)) {
  44. $this->db->where_in($k,$v);
  45. }else{
  46. $this->db->where_in($k,array(0));
  47. }
  48. }else{
  49. $this->db->where($k,$v);
  50. }
  51. }
  52. $this->db->order_by("name","ASC");
  53. $query = $this->db->get($this->table);
  54. return $query->result_array();
  55. }
  56. public function get_data_by_id($id, $field = '*',$keyword = ''){
  57. $this->db->where('id',$id);
  58. if (!empty($keyword)) {
  59. $this->db->like('name',$keyword);
  60. }
  61. $query = $this->db->get($this->table);
  62. $row = $query->row_array();
  63. if ($field == '*') {
  64. return $row;
  65. } else {
  66. return !empty($row) ? $row[$field] : '';
  67. }
  68. }
  69. public function getDataCount($condition, $id = 0) {
  70. if (!empty($condition)){
  71. foreach ($condition as $k => $v) {
  72. $this->db->where($k,$v);
  73. }
  74. }
  75. if (!empty($id)) {
  76. $this->db->where('id !=',$id);
  77. }
  78. $query = $this->db->get($this->table);
  79. $company = $query->row_array();
  80. if (empty($company)) {
  81. return 0;
  82. } else {
  83. return $id == $company['id'] ? 0 : 1;
  84. }
  85. }
  86. }