| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\DictInfo;
- use App\Models\UserDict;
- use Illuminate\Http\Request;
- use Illuminate\Http\Response;
- use Illuminate\Support\Facades\DB;
- class DictStatisticController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return Response
- */
- public function index(Request $request)
- {
- //
- $items = [];
- $all = UserDict::count();
- $query = 'SELECT count(*) from (SELECT word from user_dicts ud group by word) as t;';
- $allVocabulary = DB::select($query);
- $query = 'SELECT count(*) from (SELECT parent from user_dicts ud group by parent) as t;';
- $allParent = DB::select($query);
- $items[] = ['key' => 'all', 'title' => 'all', 'count' => $all, 'vocabulary' => $allVocabulary[0]->count, 'parent' => $allParent[0]->count];
- $dictName = ['robot_compound', 'system_regular', 'community_extract', 'community'];
- foreach ($dictName as $key => $name) {
- $dict = DictInfo::where('name', $name)->first();
- $all = UserDict::where('dict_id', $dict->id)->count();
- $query = 'SELECT count(*) from (SELECT word from user_dicts ud where dict_id = ? group by word) as t;';
- $vocabulary = DB::select($query, [$dict->id]);
- $query = 'SELECT count(*) from (SELECT parent from user_dicts ud where dict_id = ? group by parent) as t;';
- $parent = DB::select($query, [$dict->id]);
- $items[] = ['key' => $dict->shortname, 'title' => $dict->shortname, 'count' => $all, 'vocabulary' => $vocabulary[0]->count, 'parent' => $parent[0]->count];
- }
- return $this->ok($items);
- }
- /**
- * Store a newly created resource in storage.
- *
- * @return Response
- */
- public function store(Request $request)
- {
- //
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return Response
- */
- public function show($id)
- {
- //
- }
- /**
- * Update the specified resource in storage.
- *
- * @param int $id
- * @return Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return Response
- */
- public function destroy($id)
- {
- //
- }
- }
|