* @version : HUOSDK 8.0 */ namespace web\pc\logic; use huo\model\common\CommonModel; use huo\model\posts\PostsModel; class PostLogic extends CommonModel { public function getList($where = [], $page = '1,10', $order = '') { $_rdata = [ 'count' => 0, 'list' => [] ]; $_map = []; if (!empty($where['gameid'])) { $_map['app_id'] = $where['gameid']; } if (!empty($where['catalog'])) { $_map['post_type'] = $where['catalog']; } $_param['where'] = $_map; $_param['page'] = $page; $_param['order'] = $order; $_posts = new PostsModel(); $_rdata['count'] = $_posts->where($_map)->count(); if (empty($_rdata['count'])) { return $_rdata; } $_field= 'id,post_title,app_id,published_time,more,user_id,comment_count,post_like,post_type,post_content'; $_datas = $_posts->field($_field)->where($_map)->order($order)->page($page)->select(); // $_param['field'] = 'id,post_title,app_id,published_time,more,user_id,comment_count,post_like,post_type,post_content'; // $_datas = $_posts->getDatas($_param); $_list = []; foreach ($_datas as $_data) { $_post = []; $_post['id'] = $_data['id']; $_post['title'] = $_data['post_title']; $_post['gameid'] = $_data['app_id']; $_post['pubdate'] = $_data['published_time']; $_post['img'] = isset($_data['more']['thumbnail']) ? $_data['more']['thumbnail'] : ''; $_post['author'] = $_data['user_id']; $_post['commentcnt'] = $_data['comment_count']; $_post['likecnt'] = $_data['post_like']; $_post['type'] = $_data['post_type']; $_post['post_content'] = strip_tags($_data['post_content']); $_list[] = $_post; } $_rdata['list'] = $_list; return $_rdata; } /** * @param int $post_id * * @return int */ public function getDetail($post_id = 0) { if (empty($post_id)) { return 2000; } $_param['field'] = 'id,post_title,post_content,app_id,post_excerpt,published_time,more,user_id,comment_count,post_like,post_type'; $_param['id'] = $post_id; $_posts = new PostsModel(); $_data = $_posts->getDatas($_param); if (empty($_data)) { return 2000; } $_post['id'] = $_data['id']; $_post['title'] = $_data['post_title']; $_post['gameid'] = $_data['app_id']; $_post['pubdate'] = $_data['published_time']; $_post['img'] = isset($_data['more']['thumbnail']) ? $_data['more']['thumbnail'] : ''; $_post['author'] = $_data['user_id']; $_post['type'] = $_data['post_type']; $_post['excerpt'] = $_data['post_excerpt']; $_post['content'] = $_data['post_content']; return $_post; } }