Article.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Article extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 获取文章列表
  16. * @access public
  17. * @author csdeshang
  18. * @param type $condition
  19. * @param type $pagesize
  20. * @param type $order
  21. * @return type
  22. */
  23. public function getArticleList($condition, $pagesize = '', $order = 'article_sort asc,article_time desc')
  24. {
  25. if ($pagesize) {
  26. $result = Db::name('article')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  27. $this->page_info = $result;
  28. return $result->items();
  29. } else {
  30. return Db::name('article')->where($condition)->order($order)->limit(10)->select()->toArray();
  31. }
  32. }
  33. /**
  34. * 连接查询列表
  35. * @access public
  36. * @author csdeshang
  37. * @param type $where
  38. * @param type $limit
  39. * @param type $field
  40. * @param type $order
  41. * @return type
  42. */
  43. public function getJoinArticleList($where, $limit = 0, $field = '*', $order = 'article.article_sort')
  44. {
  45. $result = Db::name('article')->alias('article')->join('articleclass article_class', 'article.ac_id=article_class.ac_id', 'LEFT')->field($field)->where($where)->limit($limit)->order($order)->select()->toArray();
  46. return $result;
  47. }
  48. /**
  49. * 取单个内容
  50. * @access public
  51. * @author csdeshang
  52. * @param int $condition
  53. * @return array 数组类型的返回结果
  54. */
  55. public function getOneArticle($condition)
  56. {
  57. $result = Db::name('article')->where($condition)->find();
  58. return $result;
  59. }
  60. /**
  61. * 新增
  62. * @access public
  63. * @author csdeshang
  64. * @param array $data 参数内容
  65. * @return bool 布尔类型的返回结果
  66. */
  67. public function addArticle($data)
  68. {
  69. $result = Db::name('article')->insertGetId($data);
  70. return $result;
  71. }
  72. /**
  73. * 更新信息
  74. * @access public
  75. * @author csdeshang
  76. * @param array $data 更新数据
  77. * @return bool 布尔类型的返回结果
  78. */
  79. public function editArticle($data, $article_id)
  80. {
  81. $result = Db::name('article')->where(array('article_id' => $article_id))->update($data);
  82. return $result;
  83. }
  84. /**
  85. * 删除
  86. * @access public
  87. * @author csdeshang
  88. * @param int $id 记录ID
  89. * @return bool 布尔类型的返回结果
  90. */
  91. public function delArticle($id)
  92. {
  93. return Db::name('article')->where(array('article_id' => $id))->delete();
  94. }
  95. }