Sfoglia il codice sorgente

1、邮件支持群发
2、记录用户使用的域名

Tree 6 giorni fa
parent
commit
bf4e1aa587

+ 31 - 11
app/Http/Controllers/Admin/MailController.php

@@ -117,6 +117,16 @@ class MailController extends Controller
         }
 
         $params['type']  = 2;
+        $game_ids = [];
+        if ($params['type'] == 2) {
+            $game_id_string = str_replace([',', ';', ';'], ',', $params['game_id'] ?? '');
+            $game_ids = preg_split('/\s*,\s*/', trim($game_id_string), -1, PREG_SPLIT_NO_EMPTY);
+            $game_ids = array_values(array_unique(array_map('trim', $game_ids)));
+
+            if (empty($game_ids)) {
+                return $this->json(500, '私人邮件缺少发件人');
+            }
+        }
 
         $type = 0;
         $amount = 0;
@@ -150,6 +160,9 @@ class MailController extends Controller
                 if ($lottery_amount < $value['number']) {
                     return $this->json(500, '彩金额度不足');
                 }
+                if ($params['type'] == 2 && $value['id'] === "30000" && $lottery_amount < $value['number'] * count($game_ids)) {
+                    return $this->json(500, '彩金额度不足');
+                }
                 $change_score = $value['number'];
 
                 $value['number'] = $value['number'] * 100;
@@ -165,20 +178,27 @@ class MailController extends Controller
 
         //个人公告
         if ($params['type'] == 2) {
-            $uids = [];
-            if(strstr($params['game_id'],';')){
-                $uids = explode(';',$params['game_id']);
-            }else{
-                $uids = [trim($params['game_id'])];
+            $user_info_list = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')
+                ->whereIn('GameID', $game_ids)
+                ->select('UserID','Channel','GameID')
+                ->get();
+            $user_info_map = [];
+            foreach ($user_info_list as $item) {
+                $user_info_map[(string)$item->GameID] = $item;
             }
-            foreach ($uids as $game_id){
-                $UserInfo = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->where('GameID', $game_id)
-                    ->select('UserID','Channel')
-                    ->first();
 
-                if (!$UserInfo) {
-                    return $this->json(500, '未查询到该用户');
+            $missing_game_ids = [];
+            foreach ($game_ids as $game_id) {
+                if (!isset($user_info_map[(string)$game_id])) {
+                    $missing_game_ids[] = $game_id;
                 }
+            }
+            if (!empty($missing_game_ids)) {
+                return $this->json(500, '未查询到该用户:' . implode(',', $missing_game_ids));
+            }
+
+            foreach ($game_ids as $game_id){
+                $UserInfo = $user_info_map[(string)$game_id];
                 $user_id = $UserInfo->UserID;
                 $Channel = $UserInfo->Channel;
                 $data = [

+ 19 - 0
app/Http/Controllers/Game/WebRouteController.php

@@ -25,6 +25,7 @@ use App\Http\Controllers\Controller;
 use App\Http\helper\NumConfig;
 use App\IpLocation;
 use App\Models\AccountsInfo;
+use App\Models\AccountLoginDomain;
 use App\Models\SystemStatusInfo;
 use App\Jobs\IpRiskDetection;
 use App\Services\ApkService;
@@ -47,6 +48,23 @@ class WebRouteController extends Controller
         $this->routeService = $routeService;
     }
 
+    private function recordLoginDomain(Request $request, $userId)
+    {
+        $origin = $request
+            ? ($request->server('HTTP_ORIGIN') ?? $request->server('HTTP_REFERER') ?? '*')
+            : ($_SERVER['HTTP_ORIGIN'] ?? $_SERVER['HTTP_REFERER'] ?? '*');
+
+        try {
+            AccountLoginDomain::record($userId, $origin);
+        } catch (\Throwable $exception) {
+            \Log::warning('record_login_origin_failed', [
+                'UserID' => $userId,
+                'origin' => $origin,
+                'message' => $exception->getMessage(),
+            ]);
+        }
+    }
+
     public function Routes(Request $request)
     {
 
@@ -78,6 +96,7 @@ class WebRouteController extends Controller
         }
         $user = GlobalUserInfo::$me;//LoginController::checkLogin($request);
         if ($user) {
+            $this->recordLoginDomain($request, $user->UserID ?? 0);
             $ua = $request->userAgent();
             if (stripos($ua, 'iPhone') !== false) {
                 $mobileBand = 'iPhone';

+ 44 - 0
app/Models/AccountLoginDomain.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+
+class AccountLoginDomain extends Model
+{
+    const TABLE = 'QPAccountsDB.dbo.AccountLoginDomain';
+
+    protected $table = self::TABLE;
+
+    public $timestamps = false;
+
+    protected $fillable = [
+        'UserID',
+        'Domain',
+        'Scheme',
+        'UpdatedAt',
+        'CreatedAt',
+    ];
+
+    public static function record($userId, $origin)
+    {
+        $userId = (int) $userId;
+        $origin = trim((string) $origin);
+
+        if ($userId <= 0 || $origin === '') {
+            return false;
+        }
+
+        $now = date('Y-m-d H:i:s');
+
+        return DB::connection('write')->table(self::TABLE)->updateOrInsert(
+            ['UserID' => $userId],
+            [
+                'Domain' => $origin,
+                'Scheme' => '',
+                'UpdatedAt' => $now,
+            ]
+        );
+    }
+}

+ 5 - 5
resources/views/admin/mail/mail_add.blade.php

@@ -26,8 +26,8 @@
                                 </div>
                                 <div class="form-inline" style="margin-top: 5px">
                                     <label for="exampleInputName1">*收件人ID:</label>&nbsp;&nbsp;
-                                    <input v-model="game_id" type="text" style="color: black;width: 500px;"
-                                           class="form-control" name="game_id" placeholder="{{ __('auto.玩家游戏') }}ID">
+                                    <textarea v-model="game_id" style="color: black;width: 700px;height: 90px;" class="form-control"
+                                              name="game_id" rows="3" placeholder="{{ __('auto.玩家游戏') }}ID1,ID2,ID3"></textarea>
                                 </div>
                                 <div class="form-inline" style="margin-top: 5px">
                                     <label for="exampleInputName1">*邮件标题:</label>&nbsp;&nbsp;
@@ -83,7 +83,7 @@
                         id: "30000",
                         number: ""
                     }],
-                    typeList : {'1':'{{ __('auto.全部玩家') }}','2':'{{ __('auto.单个玩家') }}'},
+                    typeList : {'1':'{{ __('auto.全部玩家') }}','2':'单个/群发玩家'},
                     type: 2,
                     title: '',
                     game_id: '',
@@ -128,12 +128,12 @@
                 },
                 send: function () {
 
-                    if (this.type == 1 && this.game_id != '') {
+                    if (this.type == 1 && $.trim(this.game_id) != '') {
                         layer.msg('{{ __('auto.全部玩家时,玩家游戏ID不允许有值!') }}')
                         return false;
                     }
 
-                    if (this.type == 2 && this.game_id == ''){
+                    if (this.type == 2 && $.trim(this.game_id) == ''){
                         layer.msg('{{ __('auto.私人邮件缺少发件人') }}')
                         return false;
                     }