* @version : HUOSDK 8.0 */ namespace huo\controller\posts; use huo\controller\common\Base; use huo\logic\posts\PostsLogic; use huolib\status\CommonStatus; use huolib\status\NewsStatus; use huolib\utils\NewsUtils; class Posts extends Base { protected $post_logic; public function __construct(PostsLogic $post_logic = null) { if (null === $post_logic) { $this->post_logic = new PostsLogic(); } else { $this->post_logic = $post_logic; } } /** * 获取文章列表 * * @param array $param * @param string $page * * @return array */ public function getList($param = [], $page = '1,10') { $_order = '-is_top,-published_time'; $_map['app_id'] = $this->getVal($param, 'game_id', 0); $_map['post_type'] = $this->getVal($param, 'type', 0); $_rs = NewsUtils::checkNewsType($_map['post_type']); if (NewsStatus::NO_ERROR != $_rs) { return $this->huoError($_rs, NewsStatus::getMsg($_rs)); } $_data = $this->post_logic->getList($_map, $page, $_order); return $this->retSucMsg(CommonStatus::NO_ERROR, $_data); } /** * @param int $post_id * * @param int $type * * @return array */ public function getDetail($post_id, $type = 0) { if (!is_numeric($post_id) || $post_id < 0) { return $this->retErrMsg(CommonStatus::INVALID_PARAMS); } $_data = $this->post_logic->getDetail($post_id, $type); return $this->retSucMsg(CommonStatus::NO_ERROR, $_data); } }