HomeNewModel.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace Common\Model;
  3. use Common\Model\BaseModel;
  4. /**
  5. * 官网新闻
  6. * @author: linch
  7. * Class HomeNewModel
  8. * @package Common\Model
  9. */
  10. class HomeNewModel extends BaseModel
  11. {
  12. //软删状态
  13. const status_del = 0; //删除
  14. const status_on = 1; //正常
  15. const status_off = 2; //下架
  16. //推荐状态
  17. const recommend_off = 0; //不推荐
  18. const recommend_on = 1; //推荐
  19. //类型
  20. const type_industry = 1; //行业动态
  21. const type_company = 2; //公司动态
  22. const type_join = 3; //加盟动态
  23. //顶部banner
  24. const banner_off = 0; //关闭
  25. const banner_on = 1; //开启
  26. protected $mod;
  27. public function __construct() {
  28. parent::__construct();
  29. $this->mod = M('home_new');
  30. }
  31. /**
  32. * 获取类型列表
  33. * @author: linch
  34. * @return array
  35. */
  36. public function get_type_list() {
  37. return array(
  38. self::type_industry => '行业动态',
  39. self::type_company => '公司动态',
  40. self::type_join => '加盟动态',
  41. );
  42. }
  43. /**
  44. * 获取数据
  45. * @author: linch
  46. * @param $search
  47. * @param $page_num
  48. * @param $page_size
  49. * @return array
  50. */
  51. public function get_data($search, $page_num, $page_size) {
  52. $where = array(
  53. 'status' => self::status_on,
  54. );
  55. if (!empty($search['type'])) {
  56. $where['type'] = $search['type'];
  57. }
  58. if (!empty($search['store_id'])) {
  59. $where['store_id'] = $search['store_id'];
  60. }
  61. $order = 'id desc';
  62. $limit = ($page_num - 1) * $page_size . ' ,' . $page_size;
  63. $field = '*';
  64. $list = $this->where($where)->order($order)->field($field)->limit($limit)->select();
  65. $count = $this->where($where)->count();
  66. $Page = new \Common\Common\util\PageO($count, $page_size);
  67. $pager = $Page->show();
  68. $data = array(
  69. 'list' => $list,
  70. 'count' => $count,
  71. 'pager' => $pager,
  72. );
  73. return $data;
  74. }
  75. /**
  76. * 获取推荐
  77. * @author: linch
  78. */
  79. public function get_recommend() {
  80. $where = array('status' => self::status_on, 'is_recommend' => self::recommend_on);
  81. $order = 'id desc';
  82. $limit = '3';
  83. $recommend = $this->where($where)->order($order)->limit($limit)->select();
  84. return $recommend;
  85. }
  86. /**
  87. * 获取banner新闻
  88. * @author: linch
  89. * @return array
  90. */
  91. public function get_banner_data() {
  92. $where = array('status' => self::status_on, 'is_banner' => self::banner_on);
  93. $order = array('id desc');
  94. $data = $this->where($where)->order($order)->find();
  95. return $data;
  96. }
  97. /**
  98. * 获取下一篇文章,循环制,只有一篇时终止
  99. * @author: linch
  100. * @param $id
  101. * @param $type
  102. * @return array
  103. */
  104. public function get_next_data($id, $type = 0) {
  105. $where = array('id' => array('lt', $id), 'status' => self::status_on);
  106. if (!empty($type)) {
  107. $where['type'] = $type;
  108. }
  109. $order = 'id desc';
  110. $data = $this->where($where)->order($order)->find();
  111. if (empty($data)) {
  112. unset($where['id']);
  113. $data = $this->where($where)->order($order)->find();
  114. }
  115. if (intval($data['id']) == $id) { //只有一篇时没有下一篇
  116. $data = array();
  117. }
  118. return $data;
  119. }
  120. /**
  121. * 获取上一篇文章,循环制,只有一篇时终止
  122. * @author: linch
  123. * @param $id
  124. * @param $type
  125. * @return array
  126. */
  127. public function get_pre_data($id, $type = 0) {
  128. $where = array('id' => array('gt', $id), 'status' => self::status_on);
  129. if (!empty($type)) {
  130. $where['type'] = $type;
  131. }
  132. $order = 'id asc';
  133. $data = $this->where($where)->order($order)->find();
  134. if (empty($data)) {
  135. unset($where['id']);
  136. $data = $this->where($where)->order($order)->find();
  137. }
  138. if (intval($data['id']) == $id) { //只有一篇时没有下一篇
  139. $data = array();
  140. }
  141. return $data;
  142. }
  143. }