Group_model.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. if (!defined('BASEPATH'))exit('No direct script access allowed');
  3. include_once(FCPATH . 'application/models/Base_model.php');
  4. class Group_model extends Base_model {
  5. protected $table = 'lamp_group';
  6. public function __construct() {
  7. parent::__construct();
  8. }
  9. // 通过条件获取分组列表
  10. public function get_list_by_fiter($filter){
  11. foreach ($filter as $key => $value) {
  12. if (is_array($value)) {
  13. if (!empty($value)) {
  14. $this->db->where_in($key,$value);
  15. }
  16. }else{
  17. $this->db->where($key,$value);
  18. }
  19. }
  20. $data = $this->db->get($this->table)->result_array();
  21. foreach ($data as $k=>$v) {
  22. if (empty($v['lampid'])) {
  23. $data[$k]['count'] = 0;
  24. }else{
  25. $ids = explode(',', $v['lampid']);
  26. $data[$k]['count'] = count($ids);
  27. }
  28. }
  29. return $data;
  30. }
  31. public function get_count_by_filter($filter){
  32. $this->db->select('count(*) as total');
  33. foreach ($filter as $key => $value) {
  34. if (is_array($value)) {
  35. if (!empty($value)) {
  36. $this->db->where_in($key,$value);
  37. }
  38. }else{
  39. $this->db->where($key,$value);
  40. }
  41. }
  42. $data = $this->db->get($this->table)->row_array();
  43. return $data['total'];
  44. }
  45. public function getData($filter){
  46. if (!empty($filter)) {
  47. foreach ($filter as $key => $value) {
  48. if (is_array($value)) {
  49. if (!empty($value)) {
  50. $this->db->where($key,$value);
  51. }else{
  52. $this->db->where($key,array(0));
  53. }
  54. }else{
  55. $this->db->where($key,$value);
  56. }
  57. }
  58. }else{
  59. return array();
  60. }
  61. return $this->db->get($this->table)->row_array();
  62. }
  63. public function getDataCount($condition, $id = 0) {
  64. if (!empty($condition)){
  65. foreach ($condition as $k => $v) {
  66. $this->db->where($k,$v);
  67. }
  68. }
  69. if (!empty($id)) {
  70. $this->db->where('id !=',$id);
  71. }
  72. $query = $this->db->get($this->table);
  73. $data = $query->row_array();
  74. if (empty($data)) {
  75. return 0;
  76. } else {
  77. return $id == $data['id'] ? 0 : 1;
  78. }
  79. }
  80. }
  81. ?>