SocialController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\SocialService;
  5. use App\Services\Common\AdService;
  6. /**
  7. * 发圈管理
  8. * @package App\Http\Controllers\Api
  9. */
  10. class SocialController extends webApp
  11. {
  12. /**
  13. * 列表
  14. * @return array
  15. */
  16. public function index()
  17. {
  18. $params =request()->post();
  19. $pageSize = request()->post('pageSize', 15);
  20. $params['user_id'] = $this->userId;
  21. $datas = SocialService::make()->getDataList($params, $pageSize);
  22. return message(1010, true, $datas);
  23. }
  24. /**
  25. * 首页数据
  26. * @return array
  27. */
  28. public function data()
  29. {
  30. try {
  31. $data = [
  32. 'banners' => AdService::make()->getListByPosition(2), // 轮播
  33. ];
  34. return showJson(1010, true, $data);
  35. } catch (\Exception $exception) {
  36. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  37. return showJson(1046, false, $error);
  38. }
  39. }
  40. /**
  41. * 详情
  42. */
  43. public function info()
  44. {
  45. $params = request()->all();
  46. $id = isset($params['id'])? intval($params['id']) : 0;
  47. if(empty($id)){
  48. return message(1036, false);
  49. }
  50. if($info = SocialService::make()->getInfo($id)){
  51. return message(1010, true, $info);
  52. }else{
  53. return message(1009, false);
  54. }
  55. }
  56. /**
  57. * 发布
  58. */
  59. public function submit()
  60. {
  61. $params = request()->post();
  62. try {
  63. if (SocialService::make()->submit($this->userId, $params)) {
  64. return showJson(SocialService::make()->getError(), true);
  65. } else {
  66. return showJson(SocialService::make()->getError(), false);
  67. }
  68. } catch (\Exception $exception) {
  69. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  70. return showJson(1046, false, $error);
  71. }
  72. }
  73. /**
  74. * 点赞
  75. */
  76. public function like()
  77. {
  78. $params = request()->post();
  79. try {
  80. if (SocialService::make()->like($this->userId, $params)) {
  81. return showJson(SocialService::make()->getError(), true);
  82. } else {
  83. return showJson(SocialService::make()->getError(), false);
  84. }
  85. } catch (\Exception $exception) {
  86. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  87. return showJson(1046, false, $error);
  88. }
  89. }
  90. /**
  91. * 评论/回复
  92. */
  93. public function comment()
  94. {
  95. $params = request()->post();
  96. try {
  97. if (SocialService::make()->comment($this->userId, $params)) {
  98. return showJson(SocialService::make()->getError(), true);
  99. } else {
  100. return showJson(SocialService::make()->getError(), false);
  101. }
  102. } catch (\Exception $exception) {
  103. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  104. return showJson(1046, false, $error);
  105. }
  106. }
  107. }