ScaleController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Http\Controllers\Api\V1\Mentality;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\V1\BaseController;
  5. use App\Facades\ScaleFacade;
  6. class ScaleController extends BaseController
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return \Illuminate\Http\Response
  12. */
  13. public function index()
  14. {
  15. $commentTag = request('comment_tag');
  16. if ($commentTag){
  17. $commentTag = json_decode($commentTag);
  18. }
  19. $conditions = [
  20. 'category_id' => request('category_id'),
  21. 'search' => request('search'),
  22. 'comment_tag' => $commentTag
  23. ];
  24. // var_dump($conditions);exit;
  25. $fields = ['*'];
  26. switch (request('sort')) {
  27. case 1: // 最新上架
  28. $sort = '`id` desc';
  29. break;
  30. case 2: // 最受欢迎
  31. $sort = '`number_of_test` desc';
  32. break;
  33. default:
  34. $sort = '`rank` desc, `id` desc';
  35. }
  36. $page = request('page', 1);
  37. $limit = request('limit', 20);
  38. return ScaleFacade::getList($conditions, $fields, $sort, $page, $limit);
  39. }
  40. /**
  41. * Store a newly created resource in storage.
  42. *
  43. * @param \Illuminate\Http\Request $request
  44. * @return \Illuminate\Http\Response
  45. */
  46. public function store(Request $request)
  47. {
  48. //
  49. }
  50. /**
  51. * Display the specified resource.
  52. *
  53. * @param int $id
  54. * @return \Illuminate\Http\Response
  55. */
  56. public function show($id)
  57. {
  58. $conditions = ['id' => $id, 'uid'=>$this->auth()];
  59. $fields = ['*'];
  60. return ScaleFacade::findBy($conditions, $fields);
  61. }
  62. /**
  63. * Update the specified resource in storage.
  64. *
  65. * @param \Illuminate\Http\Request $request
  66. * @param int $id
  67. * @return \Illuminate\Http\Response
  68. */
  69. public function update(Request $request, $id)
  70. {
  71. //
  72. }
  73. /**
  74. * Remove the specified resource from storage.
  75. *
  76. * @param int $id
  77. * @return \Illuminate\Http\Response
  78. */
  79. public function destroy($id)
  80. {
  81. //
  82. }
  83. public function startTest(Request $request){
  84. // return ScaleFacade::createThirdScale(0, 100, '异性');
  85. return ScaleFacade::startTest($this->auth(), intval($request->scale_id));
  86. }
  87. }