News.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class News extends Model
  5. {
  6. public $page_info;
  7. /**
  8. * 新增用户
  9. */
  10. public function addNews($data)
  11. {
  12. return db('news')->insertGetId($data);
  13. }
  14. /**
  15. * 编辑
  16. */
  17. public function editNews($condition, $data)
  18. {
  19. return db('news')->where($condition)->update($data);
  20. }
  21. /**
  22. * 删除
  23. */
  24. public function delNews($condition)
  25. {
  26. return db('news')->where($condition)->delete();
  27. }
  28. /**
  29. * 取列表
  30. */
  31. public function getNewsList($condition = array(),$limit='', $field = '*', $page = '', $order = 'news_order desc,news_id desc')
  32. {
  33. if ($page) {
  34. $res = db('news')->where($condition)->field($field)->order($order)->paginate($page);
  35. $this->page_info = $res;
  36. return $res->items();
  37. } else {
  38. return db('news')->where($condition)->field($field)->order($order)->limit($limit)->select();
  39. }
  40. }
  41. /**
  42. * 取单个新闻
  43. */
  44. public function getOneNews($condition, $field = '*')
  45. {
  46. return db('news')->field($field)->where($condition)->find();
  47. }
  48. }