2
0

UserStatisticController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\UserOperationDaily;
  4. use App\Models\UserOperationLog;
  5. use App\Models\Wbw;
  6. use App\Models\Sentence;
  7. use App\Models\DhammaTerm;
  8. use App\Models\UserDict;
  9. use Illuminate\Http\Request;
  10. use App\Http\Api\AuthApi;
  11. use App\Http\Api\UserApi;
  12. use Illuminate\Support\Facades\Cache;
  13. class UserStatisticController extends Controller
  14. {
  15. /**
  16. * Display a listing of the resource.
  17. *
  18. * @return \Illuminate\Http\Response
  19. */
  20. public function index()
  21. {
  22. //
  23. }
  24. /**
  25. * Show the form for creating a new resource.
  26. *
  27. * @return \Illuminate\Http\Response
  28. */
  29. public function create()
  30. {
  31. //
  32. }
  33. /**
  34. * Store a newly created resource in storage.
  35. *
  36. * @param \Illuminate\Http\Request $request
  37. * @return \Illuminate\Http\Response
  38. */
  39. public function store(Request $request)
  40. {
  41. //
  42. }
  43. /**
  44. * Display the specified resource.
  45. *
  46. * @param \App\Models\UserOperationDaily $userOperationDaily
  47. * @return \Illuminate\Http\Response
  48. */
  49. public function show(string $userName)
  50. {
  51. //
  52. $queryUserId = UserApi::getIntIdByName($userName);
  53. $queryUserUuid = UserApi::getIdByName($userName);
  54. $cacheExpiry = 600;
  55. //总经验值
  56. $expSum = Cache::remember("user/{$userName}/exp/sum",$cacheExpiry,function() use($queryUserId){
  57. return UserOperationDaily::where('user_id',$queryUserId)
  58. ->sum('duration');
  59. });
  60. //逐词解析
  61. $wbwCount = Cache::remember("user/{$userName}/wbw/count",$cacheExpiry,function() use($queryUserId){
  62. return Wbw::where('editor_id',$queryUserId)
  63. ->count();
  64. });
  65. //查字典
  66. $lookupCount = Cache::remember("user/{$userName}/lookup/count",$cacheExpiry,function() use($queryUserId){
  67. return UserOperationDaily::where('user_id',$queryUserId)
  68. ->count();
  69. });
  70. //译文
  71. //TODO 判断是否是译文channel
  72. $translationCount = Cache::remember("user/{$userName}/translation/count",$cacheExpiry,function() use($queryUserUuid){
  73. return Sentence::where('editor_uid',$queryUserUuid)
  74. ->count();
  75. });
  76. $translationCountPub = Cache::remember("user/{$userName}/translation/count-pub",$cacheExpiry,function() use($queryUserUuid){
  77. return Sentence::where('editor_uid',$queryUserUuid)
  78. ->where('status',30)
  79. ->count();
  80. });
  81. //术语
  82. $termCount = Cache::remember("user/{$userName}/term/count",$cacheExpiry,function() use($queryUserId){
  83. return DhammaTerm::where('editor_id',$queryUserId)
  84. ->count();
  85. });
  86. $termCountWithNote = Cache::remember("user/{$userName}/term/count-note",$cacheExpiry,function() use($queryUserId){
  87. return DhammaTerm::where('editor_id',$queryUserId)
  88. ->where('note',"<>","")
  89. ->count();
  90. });
  91. //单词本
  92. $myDictCount = Cache::remember("user/{$userName}/dict/count",$cacheExpiry,function() use($queryUserId){
  93. return UserDict::where('creator_id',$queryUserId)
  94. ->count();
  95. });
  96. return $this->ok([
  97. "exp" => ["sum"=>(int)$expSum],
  98. "wbw" => ["count"=>(int)$wbwCount],
  99. "lookup" => ["count"=>(int)$lookupCount],
  100. "translation" =>["count"=>(int)$translationCount,
  101. "count_pub"=>(int)$translationCountPub],
  102. "term" => ["count"=>(int)$termCount,
  103. "count_with_note"=>(int)$termCountWithNote],
  104. "dict" => ["count"=>(int)$myDictCount],
  105. ]);
  106. }
  107. /**
  108. * Show the form for editing the specified resource.
  109. *
  110. * @param \App\Models\UserOperationDaily $userOperationDaily
  111. * @return \Illuminate\Http\Response
  112. */
  113. public function edit(UserOperationDaily $userOperationDaily)
  114. {
  115. //
  116. }
  117. /**
  118. * Update the specified resource in storage.
  119. *
  120. * @param \Illuminate\Http\Request $request
  121. * @param \App\Models\UserOperationDaily $userOperationDaily
  122. * @return \Illuminate\Http\Response
  123. */
  124. public function update(Request $request, UserOperationDaily $userOperationDaily)
  125. {
  126. //
  127. }
  128. /**
  129. * Remove the specified resource from storage.
  130. *
  131. * @param \App\Models\UserOperationDaily $userOperationDaily
  132. * @return \Illuminate\Http\Response
  133. */
  134. public function destroy(UserOperationDaily $userOperationDaily)
  135. {
  136. //
  137. }
  138. }