DictStatisticController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\DictInfo;
  4. use App\Models\UserDict;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Response;
  7. use Illuminate\Support\Facades\DB;
  8. class DictStatisticController extends Controller
  9. {
  10. /**
  11. * Display a listing of the resource.
  12. *
  13. * @return Response
  14. */
  15. public function index(Request $request)
  16. {
  17. //
  18. $items = [];
  19. $all = UserDict::count();
  20. $query = 'SELECT count(*) from (SELECT word from user_dicts ud group by word) as t;';
  21. $allVocabulary = DB::select($query);
  22. $query = 'SELECT count(*) from (SELECT parent from user_dicts ud group by parent) as t;';
  23. $allParent = DB::select($query);
  24. $items[] = ['key' => 'all', 'title' => 'all', 'count' => $all, 'vocabulary' => $allVocabulary[0]->count, 'parent' => $allParent[0]->count];
  25. $dictName = ['robot_compound', 'system_regular', 'community_extract', 'community'];
  26. foreach ($dictName as $key => $name) {
  27. $dict = DictInfo::where('name', $name)->first();
  28. $all = UserDict::where('dict_id', $dict->id)->count();
  29. $query = 'SELECT count(*) from (SELECT word from user_dicts ud where dict_id = ? group by word) as t;';
  30. $vocabulary = DB::select($query, [$dict->id]);
  31. $query = 'SELECT count(*) from (SELECT parent from user_dicts ud where dict_id = ? group by parent) as t;';
  32. $parent = DB::select($query, [$dict->id]);
  33. $items[] = ['key' => $dict->shortname, 'title' => $dict->shortname, 'count' => $all, 'vocabulary' => $vocabulary[0]->count, 'parent' => $parent[0]->count];
  34. }
  35. return $this->ok($items);
  36. }
  37. /**
  38. * Store a newly created resource in storage.
  39. *
  40. * @return Response
  41. */
  42. public function store(Request $request)
  43. {
  44. //
  45. }
  46. /**
  47. * Display the specified resource.
  48. *
  49. * @param int $id
  50. * @return Response
  51. */
  52. public function show($id)
  53. {
  54. //
  55. }
  56. /**
  57. * Update the specified resource in storage.
  58. *
  59. * @param int $id
  60. * @return Response
  61. */
  62. public function update(Request $request, $id)
  63. {
  64. //
  65. }
  66. /**
  67. * Remove the specified resource from storage.
  68. *
  69. * @param int $id
  70. * @return Response
  71. */
  72. public function destroy($id)
  73. {
  74. //
  75. }
  76. }