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; } }