123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace Common\Model;
- use Common\Model\BaseModel;
- /**
- * 官网新闻
- * @author: linch
- * Class HomeNewModel
- * @package Common\Model
- */
- class HomeNewModel extends BaseModel
- {
- //软删状态
- const status_del = 0; //删除
- const status_on = 1; //正常
- const status_off = 2; //下架
- //推荐状态
- const recommend_off = 0; //不推荐
- const recommend_on = 1; //推荐
- //类型
- const type_industry = 1; //行业动态
- const type_company = 2; //公司动态
- const type_join = 3; //加盟动态
- //顶部banner
- const banner_off = 0; //关闭
- const banner_on = 1; //开启
- protected $mod;
- public function __construct() {
- parent::__construct();
- $this->mod = M('home_new');
- }
- /**
- * 获取类型列表
- * @author: linch
- * @return array
- */
- public function get_type_list() {
- return array(
- self::type_industry => '行业动态',
- self::type_company => '公司动态',
- self::type_join => '加盟动态',
- );
- }
- /**
- * 获取数据
- * @author: linch
- * @param $search
- * @param $page_num
- * @param $page_size
- * @return array
- */
- public function get_data($search, $page_num, $page_size) {
- $where = array(
- 'status' => self::status_on,
- );
- if (!empty($search['type'])) {
- $where['type'] = $search['type'];
- }
- if (!empty($search['store_id'])) {
- $where['store_id'] = $search['store_id'];
- }
- $order = 'id desc';
- $limit = ($page_num - 1) * $page_size . ' ,' . $page_size;
- $field = '*';
- $list = $this->where($where)->order($order)->field($field)->limit($limit)->select();
- $count = $this->where($where)->count();
- $Page = new \Common\Common\util\PageO($count, $page_size);
- $pager = $Page->show();
- $data = array(
- 'list' => $list,
- 'count' => $count,
- 'pager' => $pager,
- );
- return $data;
- }
- /**
- * 获取推荐
- * @author: linch
- */
- public function get_recommend() {
- $where = array('status' => self::status_on, 'is_recommend' => self::recommend_on);
- $order = 'id desc';
- $limit = '3';
- $recommend = $this->where($where)->order($order)->limit($limit)->select();
- return $recommend;
- }
- /**
- * 获取banner新闻
- * @author: linch
- * @return array
- */
- public function get_banner_data() {
- $where = array('status' => self::status_on, 'is_banner' => self::banner_on);
- $order = array('id desc');
- $data = $this->where($where)->order($order)->find();
- return $data;
- }
- /**
- * 获取下一篇文章,循环制,只有一篇时终止
- * @author: linch
- * @param $id
- * @param $type
- * @return array
- */
- public function get_next_data($id, $type = 0) {
- $where = array('id' => array('lt', $id), 'status' => self::status_on);
- if (!empty($type)) {
- $where['type'] = $type;
- }
- $order = 'id desc';
- $data = $this->where($where)->order($order)->find();
- if (empty($data)) {
- unset($where['id']);
- $data = $this->where($where)->order($order)->find();
- }
- if (intval($data['id']) == $id) { //只有一篇时没有下一篇
- $data = array();
- }
- return $data;
- }
- /**
- * 获取上一篇文章,循环制,只有一篇时终止
- * @author: linch
- * @param $id
- * @param $type
- * @return array
- */
- public function get_pre_data($id, $type = 0) {
- $where = array('id' => array('gt', $id), 'status' => self::status_on);
- if (!empty($type)) {
- $where['type'] = $type;
- }
- $order = 'id asc';
- $data = $this->where($where)->order($order)->find();
- if (empty($data)) {
- unset($where['id']);
- $data = $this->where($where)->order($order)->find();
- }
- if (intval($data['id']) == $id) { //只有一篇时没有下一篇
- $data = array();
- }
- return $data;
- }
- }
|