HomeNewModel.class.php 4.3 KB

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