BeanDetailController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Http\Controllers\V1;
  3. use App\Repositories\BeanRepository;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Validation\Rule;
  7. /**
  8. * Created by PhpStorm.
  9. * User: durong
  10. * Date: 2019/6/19
  11. * Time: 下午12:25
  12. */
  13. class BeanDetailController extends Controller
  14. {
  15. public function __construct(BeanRepository $beanRepository)
  16. {
  17. $this->beanRepository = $beanRepository;
  18. }
  19. //排行榜
  20. public function rankingList(Request $request)
  21. {
  22. $data = $request->all();
  23. $validator = Validator::make($data, [
  24. 'type' => ['required',Rule::in([0,1, 2])],
  25. ]);
  26. if ($validator->fails()) {
  27. return $this->jsonError($validator->errors()->first());
  28. }
  29. $top_most = $this->beanRepository->rankingList($data);
  30. return success(['list'=>$top_most]);
  31. }
  32. //分享/邀请首页
  33. public function starDetail(Request $request)
  34. {
  35. $validator = Validator::make($request->all(), [
  36. 'invite_code' => 'required',
  37. ]);
  38. if ($validator->fails()) {
  39. return $this->jsonError($validator->errors()->first());
  40. }
  41. $star_detail = $this->beanRepository->starDetail($request->all());
  42. if ($star_detail){
  43. return $this->jsonSuccess($star_detail);
  44. }else{
  45. return $this->jsonSuccess();
  46. }
  47. }
  48. //后院首页
  49. public function starHome(Request $request)
  50. {
  51. $star_home = $this->beanRepository->starHome($request->all());
  52. if ($star_home){
  53. return $this->jsonSuccess($star_home);
  54. }else{
  55. return $this->jsonSuccess();
  56. }
  57. }
  58. //不登录单独返回每日新闻、小贴士
  59. public function lists(Request $request)
  60. {
  61. $star_lists = $this->beanRepository->lists($request->all());
  62. if ($star_lists){
  63. return $this->jsonSuccess($star_lists);
  64. }else{
  65. return $this->jsonSuccess();
  66. }
  67. }
  68. }