DynamicController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\BaseController;
  4. use App\Http\Validator\DynamicValidator;
  5. use App\Services\DynamicCommentService;
  6. use App\Services\DynamicService;
  7. use Illuminate\Http\Request;
  8. /**
  9. * 动态控制器类
  10. * @author wesmiler
  11. * @since 2020/11/10
  12. * Class DynamicController
  13. * @package App\Http\Controllers
  14. */
  15. class DynamicController extends BaseController
  16. {
  17. /**
  18. * 构造函数
  19. * @author wesmiler
  20. * @since 2020/11/11
  21. * ArticleController constructor.
  22. */
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. $this->service = new DynamicService();
  27. $this->commentService = new DynamicCommentService();
  28. }
  29. /**
  30. * 列表
  31. * @return array
  32. */
  33. public function index(){
  34. $params = request()->all();
  35. $type = isset($params['type'])? $params['type'] : 0;
  36. if($type==1){
  37. $params['user_id'] = $this->userId;
  38. return $this->service->getCollectList($params);
  39. }else{
  40. return $this->service->getDataList($params);
  41. }
  42. }
  43. /**
  44. * 动态评论
  45. * @return mixed
  46. */
  47. public function commentList(){
  48. $params = request()->all();
  49. return $this->commentService->getDataList($params);
  50. }
  51. /**
  52. * 发布动态评论
  53. * @param Request $request
  54. * @param DynamicValidator $validate
  55. * @return array
  56. */
  57. public function comment(Request $request, DynamicValidator $validate){
  58. $params = $validate->check($request->all(),'publish');
  59. if(!is_array($params)){
  60. return message($params, false);
  61. }
  62. return $this->commentService->comment($this->userId);
  63. }
  64. /**
  65. * 我的动态
  66. * @return array
  67. */
  68. public function myList(){
  69. $params = request()->all();
  70. $params['user_id'] = $this->userId;
  71. return $this->service->getDataList($params);
  72. }
  73. /**
  74. * 详情
  75. * @return array|mixed
  76. */
  77. public function info(){
  78. $id = request()->get('id',0);
  79. if($id<=0){
  80. return message(1006, false);
  81. }
  82. $info = $this->service->getDetail($id, $this->userId);
  83. return message(1005, true, $info);
  84. }
  85. /**
  86. * 发布动态
  87. * @param Request $request
  88. * @param DynamicValidator $validate
  89. * @return array
  90. */
  91. public function publish(Request $request, DynamicValidator $validate){
  92. $params = $validate->check($request->all(),'publish');
  93. if(!is_array($params)){
  94. return message($params, false);
  95. }
  96. return $this->service->publish($this->userId);
  97. }
  98. /**
  99. * 动态通知
  100. * @return mixed
  101. */
  102. public function notice(){
  103. return $this->service->notice($this->userId);
  104. }
  105. }