Posts.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Post.php UTF-8
  4. * 文章处理
  5. *
  6. * @date : 2017/11/23 21:42
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\posts;
  13. use huo\controller\common\Base;
  14. use huo\logic\posts\PostsLogic;
  15. use huolib\status\CommonStatus;
  16. use huolib\status\NewsStatus;
  17. use huolib\utils\NewsUtils;
  18. class Posts extends Base {
  19. protected $post_logic;
  20. public function __construct(PostsLogic $post_logic = null) {
  21. if (null === $post_logic) {
  22. $this->post_logic = new PostsLogic();
  23. } else {
  24. $this->post_logic = $post_logic;
  25. }
  26. }
  27. /**
  28. * 获取文章列表
  29. *
  30. * @param array $param
  31. * @param string $page
  32. *
  33. * @return array
  34. */
  35. public function getList($param = [], $page = '1,10') {
  36. $_order = '-is_top,-published_time';
  37. $_map['app_id'] = $this->getVal($param, 'game_id', 0);
  38. $_map['post_type'] = $this->getVal($param, 'type', 0);
  39. $_rs = NewsUtils::checkNewsType($_map['post_type']);
  40. if (NewsStatus::NO_ERROR != $_rs) {
  41. return $this->huoError($_rs, NewsStatus::getMsg($_rs));
  42. }
  43. $_data = $this->post_logic->getList($_map, $page, $_order);
  44. return $this->retSucMsg(CommonStatus::NO_ERROR, $_data);
  45. }
  46. /**
  47. * @param int $post_id
  48. *
  49. * @param int $type
  50. *
  51. * @return array
  52. */
  53. public function getDetail($post_id, $type = 0) {
  54. if (!is_numeric($post_id) || $post_id < 0) {
  55. return $this->retErrMsg(CommonStatus::INVALID_PARAMS);
  56. }
  57. $_data = $this->post_logic->getDetail($post_id, $type);
  58. return $this->retSucMsg(CommonStatus::NO_ERROR, $_data);
  59. }
  60. }