Browse Source

添加上报日志

Tree 17 hours ago
parent
commit
8ba6b6175d

+ 118 - 0
app/Http/Controllers/Admin/ClientLogController.php

@@ -0,0 +1,118 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use App\Http\Controllers\Controller;
+use App\Models\ClientLog;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+
+class ClientLogController extends Controller
+{
+    /**
+     * Client log list query
+     * @param Request $request
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+     */
+    public function index(Request $request)
+    {
+        $logType = $request->input('log_type', '');
+        $logDate = $request->input('log_date', '');
+        $channel = $request->input('Channel', '');
+        $page = $request->input('page', 1);
+
+        $query = DB::table(ClientLog::TABLE);
+
+        // Filter by log_type
+        if (!empty($logType)) {
+            $query->where('log_type', $logType);
+        }
+
+        // Filter by date
+        if (!empty($logDate)) {
+            $query->where('log_date', $logDate);
+        }
+
+        // Filter by channel
+        if (!empty($channel)) {
+            $query->where('Channel', $channel);
+        }
+
+        // Order by created_at desc
+        $query->orderBy('created_at', 'desc');
+
+        // Pagination
+        $perPage = 20;
+        $list = $query->paginate($perPage, ['*'], 'page', $page);
+
+        return view('admin.client_log.index', [
+            'list' => $list,
+            'log_type' => $logType,
+            'log_date' => $logDate,
+            'Channel' => $channel,
+        ]);
+    }
+
+    /**
+     * API: Query client log
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function query(Request $request)
+    {
+        try {
+            $logType = $request->input('log_type', '');
+            $logDate = $request->input('log_date', '');
+            $userID = $request->input('userID', '');
+            $channel = $request->input('Channel', '');
+            $page = $request->input('page', 1);
+            $perPage = $request->input('per_page', 20);
+
+            $query = DB::table(ClientLog::TABLE);
+
+            // Filter by log_type
+            if (!empty($logType)) {
+                $query->where('log_type', $logType);
+            }
+
+            // Filter by date
+            if (!empty($logDate)) {
+                $query->where('log_date', $logDate);
+            }
+
+            // Filter by userID
+            if (!empty($userID)) {
+                $query->where('userID', $userID);
+            }
+
+            // Filter by channel
+            if (!empty($channel)) {
+                $query->where('Channel', $channel);
+            }
+
+            // Order by created_at desc
+            $query->orderBy('created_at', 'desc');
+
+            // Pagination
+            $list = $query->paginate($perPage, ['*'], 'page', $page);
+
+            return response()->json([
+                'code' => 0,
+                'data' => $list->items(),
+                'total' => $list->total(),
+                'per_page' => $list->perPage(),
+                'current_page' => $list->currentPage(),
+                'last_page' => $list->lastPage(),
+            ]);
+        } catch (\Exception $e) {
+            \Log::error('Client log query error: ' . $e->getMessage(), [
+                'request' => $request->all(),
+                'trace' => $e->getTraceAsString()
+            ]);
+            return response()->json([
+                'code' => 1,
+                'message' => 'Query failed: ' . $e->getMessage()
+            ]);
+        }
+    }
+}

+ 52 - 0
app/Http/Controllers/Game/ClientLogController.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Http\Controllers\Game;
+
+use App\Http\Controllers\Controller;
+use App\Models\ClientLog;
+use Illuminate\Http\Request;
+
+class ClientLogController extends Controller
+{
+    /**
+     * Record client log
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function recordLog(Request $request)
+    {
+        try {
+            $logType = $request->input('log_type');
+            
+            // Validate log_type
+            if (empty($logType) || !in_array($logType, ['register', 'pay'])) {
+                return apiReturnFail('Invalid log_type. Must be register or pay');
+            }
+
+            $data = [
+                'log_type' => $logType,
+                'userID' => $request->input('userID'),
+                'Channel' => $request->input('Channel'),
+                'campaign_id' => $request->input('campaign_id'),
+                'ad_id' => $request->input('ad_id'),
+                'pixel' => $request->input('pixel'),
+                'pixelID' => $request->input('pixelID'),
+                'log_date' => $request->input('log_date') ?: date('Y-m-d'),
+            ];
+
+            $result = ClientLog::addLog($data);
+
+            if ($result) {
+                return apiReturnSuc(['message' => 'Log recorded successfully']);
+            } else {
+                return apiReturnFail('Failed to record log');
+            }
+        } catch (\Exception $e) {
+            \Log::error('Client log record error: ' . $e->getMessage(), [
+                'request' => $request->all(),
+                'trace' => $e->getTraceAsString()
+            ]);
+            return apiReturnFail('Error: ' . $e->getMessage());
+        }
+    }
+}

+ 46 - 0
app/Models/ClientLog.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class ClientLog extends Model
+{
+    const TABLE = 'agent.dbo.client_log';
+    protected $table = self::TABLE;
+    public $timestamps = false;
+
+    protected $fillable = [
+        'log_type',
+        'userID',
+        'Channel',
+        'campaign_id',
+        'ad_id',
+        'pixel',
+        'pixelID',
+        'log_date',
+        'created_at'
+    ];
+
+    /**
+     * Add client log
+     * @param array $data
+     * @return bool
+     */
+    public static function addLog(array $data)
+    {
+        $logData = [
+            'log_type' => $data['log_type'] ?? '',
+            'userID' => $data['userID'] ?? null,
+            'Channel' => $data['Channel'] ?? null,
+            'campaign_id' => $data['campaign_id'] ?? null,
+            'ad_id' => $data['ad_id'] ?? null,
+            'pixel' => $data['pixel'] ?? null,
+            'pixelID' => $data['pixelID'] ?? null,
+            'log_date' => $data['log_date'] ?? date('Y-m-d'),
+            'created_at' => date('Y-m-d H:i:s')
+        ];
+
+        return self::insert($logData);
+    }
+}

+ 85 - 0
resources/views/admin/client_log/index.blade.php

@@ -0,0 +1,85 @@
+@extends('base.base')
+@section('base')
+    <!-- Content Area -->
+    <div class="main-panel">
+        <div class="content-wrapper">
+            <div class="page-header">
+                <h3 class="page-title">
+                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
+                        <i class="mdi mdi-file-document"></i>
+                    </span>
+                    Client Log
+                </h3>
+                <nav aria-label="breadcrumb">
+                    <ol class="breadcrumb">
+                        <li class="breadcrumb-item"><a href="#">Log Management</a></li>
+                        <li class="breadcrumb-item active" aria-current="page">Client Log</li>
+                    </ol>
+                </nav>
+            </div>
+            <div class="row">
+                <div class="col-lg-12 grid-margin stretch-card">
+                    <div class="card">
+                        <div class="card-body">
+                            <h4 class="card-title">Client Log List</h4>
+                            <form class="well form-inline margin-top-20" method="get" action='/admin/client_log'>
+                                <div>
+                                    <span style="padding-left: 10px">Log Type:</span>
+                                    <select class="form-control" name="log_type" style="color: black">
+                                        <option value="">All</option>
+                                        <option value="register" @if($log_type == 'register') selected @endif>Register</option>
+                                        <option value="pay" @if($log_type == 'pay') selected @endif>Pay</option>
+                                    </select>
+                                    <span style="padding-left: 10px">Date:</span>
+                                    <input type="date" name="log_date" class="form-control" value="{{$log_date}}" />
+                                    <span style="padding-left: 10px">Channel:</span>
+                                    <input class="form-control" type="text" name="Channel" style="width: 10%;" value="{{$Channel}}" placeholder="Channel">
+                                </div>
+                                <div style="margin-top: 10px;">
+                                    <input type="submit" class="btn btn-sm btn-gradient-dark btn-icon-text" value="Search"/>&nbsp;&nbsp;
+                                    <a href="/admin/client_log" class="btn btn-sm btn-gradient-warning btn-icon-text">Clear</a>
+                                </div>
+                            </form>
+                            <table class="table table-bordered">
+                                <thead>
+                                <tr>
+                                    <th>ID</th>
+                                    <th>Log Type</th>
+                                    <th>UserID</th>
+                                    <th>Channel</th>
+                                    <th>Campaign ID</th>
+                                    <th>Ad ID</th>
+                                    <th>Pixel</th>
+                                    <th>Pixel ID</th>
+                                    <th>Log Date</th>
+                                    <th>Created At</th>
+                                </tr>
+                                </thead>
+                                <tbody>
+                                @foreach($list as $k=>$v)
+                                    <tr>
+                                        <td>{{ $v->id }}</td>
+                                        <td>{{ $v->log_type }}</td>
+                                        <td>{{ $v->userID ?? '-' }}</td>
+                                        <td>{{ $v->Channel ?? '-' }}</td>
+                                        <td>{{ $v->campaign_id ?? '-' }}</td>
+                                        <td>{{ $v->ad_id ?? '-' }}</td>
+                                        <td>{{ $v->pixel ?? '-' }}</td>
+                                        <td>{{ $v->pixelID ?? '-' }}</td>
+                                        <td>{{ $v->log_date }}</td>
+                                        <td>{{ $v->created_at }}</td>
+                                    </tr>
+                                @endforeach
+                                </tbody>
+                            </table>
+                            <div class="box-footer clearfix">
+                                Total <b>{{ $list->appends(['log_type'=>$log_type,'log_date'=>$log_date,'Channel'=>$Channel])->total() }}</b> records, divided into <b>{{ $list->lastPage() }}</b> pages
+                                {!! $list->links() !!}
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+@endsection

+ 2 - 0
routes/game.php

@@ -3,6 +3,8 @@
 use App\Game\Config\GameBasicConfig;
 use Illuminate\Support\Facades\Route;
 
+Route::any('/client_log/record', 'Game\ClientLogController@recordLog');
+
 
 //GlobalUID date
 Route::any('/agent_api/get-players', 'Game\AgentController@getAgentPlayers');

+ 4 - 0
routes/web.php

@@ -94,6 +94,10 @@ Route::group([
 
         $route->get('/game/user/onlines', 'Admin\GameDataController@userOnline');
         $route->get('/createid', 'Admin\GameDataController@makeGameid');
+        
+        // 客户端日志查询
+        $route->get('/client_log', 'Admin\ClientLogController@index')->defaults('name', '客户端日志');
+        $route->any('/client_log/query', 'Admin\ClientLogController@query');
 //        $route->any('/game_data/GateBuyRecord','Admin\GameDataController@GateBuyRecord');
 //        $route->any('/game_data/GateBuyRecord','Admin\GameDataController@GateBuyRecord');