SocialController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, $this->userId)){
  51. return message(1010, true, $info);
  52. }else{
  53. return message(1009, false);
  54. }
  55. }
  56. /**
  57. * 删除
  58. */
  59. public function delete()
  60. {
  61. return SocialService::make()->delete();
  62. }
  63. /**
  64. * 发布
  65. */
  66. public function submit()
  67. {
  68. $params = request()->post();
  69. try {
  70. if (SocialService::make()->submit($this->userId, $params)) {
  71. return showJson(SocialService::make()->getError(), true);
  72. } else {
  73. return showJson(SocialService::make()->getError(), false);
  74. }
  75. } catch (\Exception $exception) {
  76. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  77. return showJson(1046, false, $error);
  78. }
  79. }
  80. }