Article.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Article extends BaseModel
  16. {
  17. public $page_info;
  18. /**
  19. * 获取文章列表
  20. * @access public
  21. * @author csdeshang
  22. * @param type $condition
  23. * @param type $pagesize
  24. * @param type $order
  25. * @return type
  26. */
  27. public function getArticleList($condition,$pagesize='',$order='article_sort asc,article_time desc'){
  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. $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();
  48. return $result;
  49. }
  50. /**
  51. * 取单个内容
  52. * @access public
  53. * @author csdeshang
  54. * @param int $condition
  55. * @return array 数组类型的返回结果
  56. */
  57. public function getOneArticle($condition){
  58. $result = Db::name('article')->where($condition)->find();
  59. return $result;
  60. }
  61. /**
  62. * 新增
  63. * @access public
  64. * @author csdeshang
  65. * @param array $data 参数内容
  66. * @return bool 布尔类型的返回结果
  67. */
  68. public function addArticle($data){
  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. $result = Db::name('article')->where(array('article_id'=>$article_id))->update($data);
  81. return $result;
  82. }
  83. /**
  84. * 删除
  85. * @access public
  86. * @author csdeshang
  87. * @param int $id 记录ID
  88. * @return bool 布尔类型的返回结果
  89. */
  90. public function delArticle($id){
  91. return Db::name('article')->where(array('article_id'=>$id))->delete();
  92. }
  93. }