admin_model.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. class Admin_model extends MY_Model
  3. {
  4. /**
  5. * 操作表名
  6. * @access private
  7. * @author leefouce
  8. */
  9. private $table_name = 'admin';
  10. public function __construct() {
  11. parent::__construct();
  12. }
  13. public function insert($parm) {
  14. $this->db->insert($this->table_name, $parm);
  15. return $this->db->insert_id();
  16. }
  17. public function update($id, $parm) {
  18. $this->db->where('id', $id);
  19. $this->db->update($this->table_name, $parm);
  20. return $this->db->affected_rows();
  21. }
  22. /**
  23. * 删除功能,set adStatus = 1
  24. */
  25. public function delete($id) {
  26. $this->db->where('id', $id);
  27. $parm['adStatus'] = 1;
  28. $this->db->update($this->table_name, $parm);
  29. return $this->db->affected_rows();
  30. }
  31. public function getDetailById($id){
  32. $this->db->select('*');
  33. $this->db->from($this->table_name);
  34. $this->db->where('id', $id);
  35. $this->db->where('adStatus', '0');
  36. $query = $this->db->get();
  37. return $query->num_rows() > 0 ? $query->result_array() : false;
  38. }
  39. public function getDetailByLogin($adLogin){
  40. $this->db->select('*');
  41. $this->db->from($this->table_name);
  42. $this->db->where('adLogin', $adLogin);
  43. $this->db->where('adStatus', '0');
  44. $query = $this->db->get();
  45. return $query->num_rows() > 0 ? $query->result_array() : false;
  46. }
  47. public function login($adLogin,$adPass){
  48. $this->db->select('*');
  49. $this->db->from($this->table_name);
  50. $this->db->where('adLogin', $adLogin);
  51. $this->db->where('adPass', $adPass);
  52. $this->db->where('adStatus', '0');
  53. $query = $this->db->get();
  54. return $query->num_rows() > 0 ? $query->result_array() : false;
  55. }
  56. public function isExistByAdLogin($adLogin){
  57. $this->db->from($this->table_name);
  58. $this->db->where('adLogin', $adLogin);
  59. $query = $this->db->get();
  60. return $query->num_rows() > 0 ? true : false;
  61. }
  62. public function getCount(){
  63. $this->db->select('count(id) as count');
  64. $this->db->where('adStatus', '0');
  65. $query = $this->db->get($this->table_name);
  66. $ret = $query->row_array();
  67. return $ret['count'];
  68. }
  69. public function getAll($offset,$rows){
  70. $this->db->where('adStatus','0');
  71. $this->db->limit($rows, $offset);
  72. $query = $this->db->get($this->table_name);
  73. return $query->num_rows() > 0 ? $query->result_array() : false;
  74. }
  75. }