Dynamic.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\UserDynamic as UserDynamicModel;
  4. use app\api\service\User as UserService;
  5. /**
  6. * 动态控制器
  7. * Class Dynamic
  8. * @package app\api\controller
  9. */
  10. class Dynamic extends Controller
  11. {
  12. public function list()
  13. {
  14. // 获取列表数据
  15. $model = new UserDynamicModel();
  16. $pageSize = $this->request->param('pageSize', 15);
  17. $params = $this->request->param();
  18. $userInfo = UserService::getCurrentLoginUser(true);
  19. $accessUserId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
  20. $userId = isset($params['user_id'])? intval($params['user_id']) : 0;
  21. $params['access_user_id'] = $accessUserId;
  22. if($userId<=0){
  23. $params['user_id'] = $accessUserId;
  24. }
  25. $list = $model->getList($params, (int)$pageSize);
  26. return $this->renderSuccess(compact('list'));
  27. }
  28. /**
  29. * 推荐动态
  30. * @return \think\response\Json
  31. * @throws \think\db\exception\DbException
  32. */
  33. public function index()
  34. {
  35. // 获取列表数据
  36. $model = new UserDynamicModel();
  37. $pageSize = $this->request->param('pageSize', 15);
  38. $userInfo = UserService::getCurrentLoginUser(true);
  39. $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
  40. $list = $model->getIndexList($userId,$this->request->param(), (int)$pageSize);
  41. return $this->renderSuccess(compact('list'));
  42. }
  43. /**
  44. * 动态发布
  45. * @return \think\response\Json
  46. */
  47. public function publish()
  48. {
  49. $model = new UserDynamicModel();
  50. if(!$model->publish($this->request->param())){
  51. return $this->renderError($model->getError() ?: '动态发布失败');
  52. }
  53. $info = ['dynamic_id'=> $model['id'],'message'=>'发布成功'];
  54. return $this->renderSuccess(compact('info'));
  55. }
  56. /**
  57. * 动态详情
  58. * @return \think\response\Json
  59. */
  60. public function detail()
  61. {
  62. $model = new UserDynamicModel();
  63. $info = $model->getDetail((int)$this->request->param('id'));
  64. return $this->renderSuccess(compact('info'));
  65. }
  66. }