LogController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Controllers\Miniprogram\Auth;
  4. use Illuminate\Http\Request;
  5. class LogController extends Controller
  6. {
  7. //
  8. public function accessLog(Request $request)
  9. {
  10. try {
  11. $uid = Auth::auth();
  12. } catch (\Exception $e) {
  13. $uid = $request->input('uid', 0);
  14. }
  15. $data = $request->only(['app_id', 'uuid']);
  16. $url = urldecode($request->input('url'));
  17. $data['start_time'] = time();
  18. $data['uid'] = $uid;
  19. $data["url"] = stripos($url, "?") ? substr($url, 0, stripos($url, "?")) : $url;
  20. $data['ip'] = ip2long($_SERVER['REMOTE_ADDR']);
  21. $data['browser'] = $_SERVER['HTTP_USER_AGENT'];
  22. $data['query'] = substr(json_encode($request->input('query')), 0, 256);
  23. \DB::connection('mysql_datalog')->table('page_access_logs_' . date('Ym'))->insert($data);
  24. return response([
  25. 'code' => 200,
  26. 'message' => 'OK'
  27. ]);
  28. }
  29. public function groupLog(Request $request)
  30. {
  31. $group_name = \DB::connection('mysql_datalog')->table("group_logs")->where(
  32. 'group_id',
  33. $request->post('group_id')
  34. )->value('group_name') ?: '';
  35. $data = [
  36. 'uid' => $request->post('uid'),
  37. 'group_id' => $request->post('group_id'),
  38. 'group_name' => $group_name,
  39. 'created_at' => time()
  40. ];
  41. \DB::connection('mysql_datalog')->table("group_logs")->insert($data);
  42. return response([
  43. 'code' => 200,
  44. 'message' => 'OK'
  45. ]);
  46. }
  47. }