Example #1
0
 /**
  * 获取列表
  * @param array $options
  * array(
  * 	'cid'		=> $cid,// 分类ID
  * 	'keyword'	=> $keyword,// 关键字
  * 	'create_time'	=> $create_time,// 发布日期
  * 	'create_time2'=> $create_time2,// 发布日期截止时间
  * 	'status'	=> $status,// 状态
  * 	'order'		=> $order,// 排序字段
  * 	'limit'		=> $limit,// 获取记录数
  * 	'has_page'	=> $has_page,// 是否分页
  *  'fields'	=> $fields//字段列表
  * )
  */
 public function getList($options = array())
 {
     extract($options);
     if (!isset($fields)) {
         $fields = 'id,title,title_image,create_time';
     }
     // 按状态查询,默认全部
     if (isset($status) && !is_null($status) && ctype_digit((string) $status)) {
         $where = 'status=' . $status;
     }
     // 指定日期,则按发布时间属于指定日期查询
     if (isset($create_time)) {
         if (ctype_digit((string) $create_time)) {
             $day = strtotime(date('Y-m-d', $create_time));
         } else {
             $day = strtotime($create_time);
         }
     }
     if (isset($create_time2)) {
         if (ctype_digit((string) $create_time2)) {
             $endDay = strtotime(date('Y-m-d', $create_time2));
         } else {
             $endDay = strtotime($create_time2);
         }
     }
     // 同时指定查询起止时间
     if (isset($create_time) && isset($create_time2)) {
         $w = 'create_time>=' . $day . ' and create_time<' . $endDay;
         $where = isset($where) ? $where . ' and ' . $w : $w;
     } else {
         if (isset($create_time)) {
             $w = 'create_time>=' . $day;
             $where = isset($where) ? $where . ' and ' . $w : $w;
         } else {
             if (isset($create_time2)) {
                 $w = 'create_time<' . ($endDay + 86400);
                 $where = isset($where) ? $where . ' and ' . $w : $w;
             }
         }
     }
     // 分类查询
     if (isset($cid) && ctype_digit((string) $cid)) {
         $where = isset($where) ? $where . ' and cid=' . $cid : 'cid=' . $cid;
     }
     // 关键字查询
     if (isset($keyword)) {
         $w = 'FIND_IN_SET(:keyword, `keywords`)';
         $where = isset($where) ? $where . ' and ' . $w : $w;
         $params = array('keyword' => $keyword);
     } else {
         $params = null;
     }
     if (!isset($where)) {
         $where = null;
     }
     if (!isset($limit)) {
         $limit = $this->pageSize;
     }
     if (!isset($order)) {
         $order = 'order_score desc';
     }
     // 是否有分页
     if (isset($has_page) && $has_page) {
         $rows = $this->where($where)->params($params)->count();
         Page::init($limit, $rows);
         $this->pagePanel = Page::generateBarCode();
         $start = Page::$from;
         $limit = Page::$to;
     } else {
         $start = 0;
     }
     $list = $this->field($fields)->where($where)->params($params)->order($order)->limit($limit, $start)->select();
     return $list;
 }
Example #2
0
 /**
  * 选择列表数据
  * @param array $options
  */
 public function select($options = null)
 {
     if (is_null($options)) {
         $options = $this->options;
     }
     $options['multi'] = true;
     // 是否有分页
     if (isset($options['has_page']) && $options['has_page']) {
         $rows = $this->count();
         Page::init($this->pageSize, $rows);
         $this->pagePanel = Page::generateBarCode();
         $options['limit'] = array(Page::$from, Page::$to);
     } else {
         $options['limit'] = $this->pageSize;
     }
     $list = Db::fetches($this->tbl, $options);
     return $list;
 }