product_model.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. class Product_model extends MY_Model
  3. {
  4. private $table_name = 'product';
  5. private $orderby = 'addtime';
  6. public function insert($parm)
  7. {
  8. $this->db->insert($this->table_name, $parm);
  9. return $this->db->insert_id();
  10. }
  11. public function delete($id) {
  12. $this->db->where('id', $id);
  13. $this->db->delete($this->table_name);
  14. return $this->db->affected_rows();
  15. }
  16. public function update($id, $parm) {
  17. $this->db->where('id', $id);
  18. $this->db->update($this->table_name, $parm);
  19. return $this->db->affected_rows();
  20. }
  21. public function get($id)
  22. {
  23. $this->db->select('*');
  24. $this->db->from($this->table_name);
  25. $this->db->where('id', $id);
  26. $query = $this->db->get();
  27. return $query->num_rows() > 0 ? $query->row_array() : false;
  28. }
  29. public function all()
  30. {
  31. $this->db->order_by($this->orderby, 'desc');
  32. $query = $this->db->get($this->table_name);
  33. return $query->num_rows() > 0 ? $query->result_array() : false;
  34. }
  35. public function max_ord()
  36. {
  37. $this->db->select('max(ord) as max_ord');
  38. $query = $this->db->get($this->table_name);
  39. $ret = $query->row_array();
  40. return $ret['max_ord'];
  41. }
  42. public function count()
  43. {
  44. $this->db->select('count(*) as count');
  45. $query = $this->db->get($this->table_name);
  46. $ret = $query->row_array();
  47. return $ret['count'];
  48. }
  49. public function get_list_by_type($type=0)
  50. {
  51. $this->db->where('type', $type);
  52. $this->db->order_by('addtime', 'desc');
  53. $query = $this->db->get($this->table_name);
  54. return $query->num_rows() > 0 ? $query->result_array() : false;
  55. }
  56. public function all_order_time()
  57. {
  58. $this->db->order_by('addtime', 'desc');
  59. $query = $this->db->get($this->table_name);
  60. return $query->num_rows() > 0 ? $query->result_array() : false;
  61. }
  62. }