Article.php 3.0 KB

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