DictStatisticController.php 2.1 KB

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