BeanDetailController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 beanDetail(Request $request)
  21. {
  22. $validator = Validator::make($request->all(), [
  23. 'type' => ['required',Rule::in([0,1, 2])],
  24. ]);
  25. if ($validator->fails()) {
  26. return $this->jsonError($validator->errors()->first());
  27. }
  28. $beanDetail = $this->beanRepository->beanDetail($request->all());
  29. if ($beanDetail){
  30. return $this->jsonSuccess($beanDetail);
  31. }else{
  32. return $this->jsonError('没有找到对应彩虹豆明细');
  33. }
  34. }
  35. //获取星球-用户彩虹豆相关信息
  36. public function getBean(Request $request)
  37. {
  38. $user_bean = $this->beanRepository->getBean($request->all());
  39. if ($user_bean){
  40. return $this->jsonSuccess($user_bean);
  41. }else{
  42. return $this->jsonError('没有找到星球彩虹豆信息');
  43. }
  44. }
  45. //昨日优秀居民
  46. public function excellentResidents(Request $request)
  47. {
  48. $excellent_residents = $this->beanRepository->excellentResidents($request->all());
  49. if ($excellent_residents){
  50. return $this->jsonSuccess($excellent_residents);
  51. }else{
  52. return $this->jsonError('没有找到昨日优秀居民相关信息');
  53. }
  54. }
  55. //排行榜
  56. public function rankingList(Request $request)
  57. {
  58. $validator = Validator::make($request->all(), [
  59. 'type' => ['required',Rule::in([0,1, 2])],
  60. ]);
  61. if ($validator->fails()) {
  62. return $this->jsonError($validator->errors()->first());
  63. }
  64. $top_most = $this->beanRepository->rankingList($request->all());
  65. if ($top_most){
  66. return $this->jsonSuccess($top_most);
  67. }else{
  68. return $this->jsonError('没有找到排行榜相关信息');
  69. }
  70. }
  71. }