DictStatisticController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. $query = "SELECT count(*) from (SELECT parent from user_dicts ud group by parent) as t;";
  22. $allParent = DB::select($query);
  23. $items[] = ['key'=>'all','title'=>'all','count'=>$all,'vocabulary'=>$allVocabulary[0]->count,'parent'=>$allParent[0]->count];
  24. $dictName = ['robot_compound','system_regular','community_extract','community'];
  25. foreach ($dictName as $key => $name) {
  26. $dict = DictInfo::where('name',$name)->first();
  27. $all = UserDict::where('dict_id',$dict->id)->count();
  28. $query = "SELECT count(*) from (SELECT word from user_dicts ud where dict_id = ? group by word) as t;";
  29. $vocabulary = DB::select($query,[$dict->id]);
  30. $query = "SELECT count(*) from (SELECT parent from user_dicts ud where dict_id = ? group by parent) as t;";
  31. $parent = DB::select($query,[$dict->id]);
  32. $items[] = ['key'=>$dict->shortname,'title'=>$dict->shortname,'count'=>$all,'vocabulary'=>$vocabulary[0]->count,'parent'=>$parent[0]->count];
  33. }
  34. return $this->ok($items);
  35. }
  36. /**
  37. * Store a newly created resource in storage.
  38. *
  39. * @param \Illuminate\Http\Request $request
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function store(Request $request)
  43. {
  44. //
  45. }
  46. /**
  47. * Display the specified resource.
  48. *
  49. * @param int $id
  50. * @return \Illuminate\Http\Response
  51. */
  52. public function show($id)
  53. {
  54. //
  55. }
  56. /**
  57. * Update the specified resource in storage.
  58. *
  59. * @param \Illuminate\Http\Request $request
  60. * @param int $id
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function update(Request $request, $id)
  64. {
  65. //
  66. }
  67. /**
  68. * Remove the specified resource from storage.
  69. *
  70. * @param int $id
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function destroy($id)
  74. {
  75. //
  76. }
  77. }