123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- /**
- * PostLogic.php UTF-8
- * 文章逻辑
- *
- * @date : 2017/11/23 21:22
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huomp\logic\posts;
- use huo\model\common\CommonModel;
- use huo\model\posts\PostsModel;
- use huolib\constant\CommonConst;
- use huolib\tool\StrUtils;
- class PostsLogic extends CommonModel {
- protected $base_field
- = [
- 'id' => 'id',
- 'post_title' => 'title',
- 'post_excerpt' => 'excerpt',
- 'post_content' => 'content',
- ];
- /**
- * 获取问答列表
- *
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array|int
- */
- public function getList($where = [], $page = '1,10', $order = '') {
- $_map = [];
- if (!empty($where['post_type'])) {
- $_map['post_type'] = $where['post_type'];
- }
- $_posts_model = new PostsModel();
- $_count = $_posts_model->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- $_field = $this->base_field;
- $_order = $this->orderFilter($order);
- $_datas = $_posts_model->field($_field)->where($_map)->page($page)->order($_order)->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_datas;
- return $_rdata;
- }
- /**
- * 后台猎人平台列表
- *
- * @param array $where
- * @param string $page
- * @param string $order
- *
- * @return array
- */
- public function getHunterList($where = [], $page = '1,10', $order = '-published_time') {
- $_map = [];
- if (!empty($param['start_time']) && !empty($param['start_time'])) {
- $_map['published_time'] = ['between', [strtotime($param['start_time']),
- CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])]];
- } else if (!empty($param['start_time'])) {
- $_map['published_time'] = ['gt', strtotime($param['start_time'])];
- } else if (!empty($param['end_time'])) {
- $_map['published_time'] = ['lt', CommonConst::CONST_DAY_SECONDS + strtotime($param['end_time'])];
- }
- if (!empty($where['post_type'])) {
- $_map['post_type'] = $where['post_type'];
- }
- if (!empty($where['keyword'])) {
- $_map['post_title'] = ['like', $where['keyword'].'%'];
- }
- $_map['delete_time'] = 0;
- $_posts_model = new PostsModel();
- $_count = $_posts_model->useGlobalScope(false)->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- $_order = $this->orderFilter($order);
- $_datas = $_posts_model->useGlobalScope(false)
- ->with('user')
- ->where($_map)
- ->page($page)
- ->order($_order)
- ->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_datas;
- return $_rdata;
- }
- /**
- * 获取列表用于生成静态页面
- *
- * @param string $post_type
- * @param string $order
- *
- * @return array
- */
- public function getHtmlList($post_type, $order = '-published_time') {
- $_map = [];
- $_map['post_type'] = $post_type;
- $_posts_model = new PostsModel();
- $_count = $_posts_model->where($_map)->count();
- if (empty($_count)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- $_field = 'id,is_top,post_like,url,post_title,post_keywords,post_source,post_excerpt,more,update_time';
- $_order = $this->orderFilter($order);
- $_datas = $_posts_model->field($_field)->where($_map)->order($_order)->select();
- if (is_object($_datas)) {
- $_datas = $_datas->toArray();
- }
- if (empty($_datas)) {
- return [
- 'count' => 0,
- 'list' => []
- ];
- }
- foreach ($_datas as $_k => $_v) {
- $_datas[$_k]['id'] = $_v['id'];
- $_datas[$_k]['title'] = $_v['post_title'];
- $_datas[$_k]['img'] = empty($_v['more']['thumbnail']) ? '' : $_v['more']['thumbnail'];
- $_datas[$_k]['down_cnt'] = StrUtils::formatNumber($_v['post_like'] / 1000);
- $_datas[$_k]['size'] = $_v['post_source'];
- $_datas[$_k]['post_excerpt'] = $_v['post_excerpt'];
- $_datas[$_k]['url'] = $_v['url'];
- $_datas[$_k]['update_time'] = $_v['update_time'];
- $_datas[$_k]['tags'] = empty($_v['post_keywords']) ? [] : explode(',', $_v['post_keywords']);
- }
- $_rdata['count'] = $_count;
- $_rdata['list'] = $_datas;
- return $_rdata;
- }
- /**
- * 获取所有可显示的id
- *
- * @param array $post_type
- *
- * @return array
- */
- public function getAllIds($post_type = []) {
- $_map = [
- 'post_type' => ['in', $post_type],
- ];
- $_ids = (new PostsModel())->where($_map)->column('id');
- return $_ids;
- }
- }
|