소스 검색

付费用户局数统计

Tree 1 일 전
부모
커밋
9eeaf8f96b

+ 3 - 0
app/Console/Commands/RecordPlatformData.php

@@ -105,6 +105,9 @@ class RecordPlatformData extends Command
 
         // 分渠道修改
         $this->affixation($date, $dateID);
+
+        // 老付费用户平均游戏局数
+        $service->oldPayUserAvgGameCountStat($dateID, $date);
     }
 
 

+ 48 - 0
app/Services/RecordPlatformData.php

@@ -217,6 +217,54 @@ class RecordPlatformData
 
     }
 
+    /**
+     * 统计老付费用户(非当日注册)当日有/无充值的平均游戏局数,写入 RecordPlatformData
+     *
+     * @param string $dateID Ymd
+     * @param \Carbon\Carbon $date
+     * @return bool
+     */
+    public function oldPayUserAvgGameCountStat($dateID, $date)
+    {
+        $dao = new \App\dao\RecordPlatformData\RecordPlatformData();
+        $stats = $dao->oldPayUserAvgGameCountStatBundle($dateID, $date);
+
+        $withRecharge = $stats['withRecharge'];
+        $withoutRecharge = $stats['withoutRecharge'];
+        $withRechargeAll = $stats['withRechargeAll'];
+        $withoutRechargeAll = $stats['withoutRechargeAll'];
+
+        $withoutRechargeByChannel = $withoutRecharge->keyBy('Channel');
+
+        foreach ($withRecharge as $item) {
+            $paySecond = $withoutRechargeByChannel->get($item->Channel);
+            $dao->Update([
+                'DateID' => $dateID,
+                'PayGameCount' => round($item->PayGameCount ?? 0, 2),
+                'PaySecond' => round($paySecond->PaySecond ?? 0, 2),
+            ], $item->Channel, $item->Channel, $dateID);
+        }
+
+        foreach ($withoutRecharge as $item) {
+            if ($withRecharge->firstWhere('Channel', $item->Channel)) {
+                continue;
+            }
+            $dao->Update([
+                'DateID' => $dateID,
+                'PayGameCount' => 0,
+                'PaySecond' => round($item->PaySecond ?? 0, 2),
+            ], $item->Channel, $item->Channel, $dateID);
+        }
+
+        $dao->Update([
+            'DateID' => $dateID,
+            'PayGameCount' => round($withRechargeAll->PayGameCount ?? 0, 2),
+            'PaySecond' => round($withoutRechargeAll->PaySecond ?? 0, 2),
+        ], -1, -1, $dateID);
+
+        return true;
+    }
+
     /**
      * Build SQL Server table expression with NOLOCK hint for read-heavy statistics queries.
      *

+ 137 - 0
app/dao/RecordPlatformData/RecordPlatformData.php

@@ -164,4 +164,141 @@ class RecordPlatformData
             ->groupBy('Channel')
             ->get();
     }
+
+    /**
+     * 老付费用户当日有充值:先锁定用户集,再按 UserID+DateID 关联局数(避免全表聚合)
+     */
+    private function perUserGameCountForRechargedOldPayers($dateID, $registerBefore)
+    {
+        return DB::connection('sqlsrv')
+            ->table(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as rn WITH (NOLOCK)'))
+            ->join(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'), 'rn.UserID', '=', 'ai.UserID')
+            ->join(DB::raw(TableName::QPAccountsDB() . 'YN_VIPAccount as va WITH (NOLOCK)'), 'rn.UserID', '=', 'va.UserID')
+            ->leftJoin(DB::raw(TableName::QPRecordDB() . 'RecordUserGameDayCount as rd WITH (NOLOCK)'), function ($join) use ($dateID) {
+                $join->on('rn.UserID', '=', 'rd.UserID')->where('rd.DateID', '=', $dateID);
+            })
+            ->where('rn.DateID', $dateID)
+            ->where('rn.Recharge', '>', 0)
+            ->where('ai.RegisterDate', '<', $registerBefore)
+            ->where('va.Recharge', '>', 0)
+            ->groupBy('ai.Channel', 'rn.UserID')
+            ->selectRaw('ai.Channel, ISNULL(SUM(rd.Cnt), 0) as TotalCnt');
+    }
+
+    /**
+     * 老付费用户当日无充值且当日有玩游戏:从当日 rd 出发,只扫描 DateID 分区后再过滤用户
+     */
+    private function perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore)
+    {
+        return DB::connection('sqlsrv')
+            ->table(DB::raw(TableName::QPRecordDB() . 'RecordUserGameDayCount as rd WITH (NOLOCK)'))
+            ->join(DB::raw(TableName::QPAccountsDB() . 'YN_VIPAccount as va WITH (NOLOCK)'), function ($join) {
+                $join->on('rd.UserID', '=', 'va.UserID')->where('va.Recharge', '>', 0);
+            })
+            ->join(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'), 'rd.UserID', '=', 'ai.UserID')
+            ->leftJoin(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as rn WITH (NOLOCK)'), function ($join) use ($dateID) {
+                $join->on('rd.UserID', '=', 'rn.UserID')->where('rn.DateID', '=', $dateID);
+            })
+            ->where('rd.DateID', $dateID)
+            ->where('ai.RegisterDate', '<', $registerBefore)
+            ->where(function ($query) {
+                $query->whereNull('rn.Recharge')->orWhere('rn.Recharge', '<=', 0);
+            })
+            ->groupBy('ai.Channel', 'rd.UserID')
+            ->selectRaw('ai.Channel, SUM(rd.Cnt) as TotalCnt');
+    }
+
+    private function avgGameCountByChannel($perUserQuery, $fieldAlias)
+    {
+        return $this->avgFromSubSql($perUserQuery->toSql(), $perUserQuery->getBindings(), true, $fieldAlias);
+    }
+
+    private function avgGameCountAll($perUserQuery, $fieldAlias)
+    {
+        return $this->avgFromSubSql($perUserQuery->toSql(), $perUserQuery->getBindings(), false, $fieldAlias);
+    }
+
+    private function avgFromSubSql($sql, array $bindings, $byChannel, $fieldAlias)
+    {
+        $query = DB::connection('sqlsrv')->table(DB::raw("({$sql}) as u"));
+        foreach ($bindings as $binding) {
+            $query->addBinding($binding, 'select');
+        }
+
+        if ($byChannel) {
+            return $query
+                ->selectRaw("u.Channel, AVG(CAST(u.TotalCnt AS FLOAT)) as {$fieldAlias}")
+                ->groupBy('u.Channel')
+                ->get();
+        }
+
+        return $query->selectRaw("AVG(CAST(u.TotalCnt AS FLOAT)) as {$fieldAlias}")->first();
+    }
+
+    /**
+     * 一次返回 PayGameCount / PaySecond 的分渠道与全渠道结果(共 2 次 DB 查询)
+     */
+    public function oldPayUserAvgGameCountStatBundle($dateID, $date)
+    {
+        $registerBefore = $date->format('Y-m-d');
+
+        $rechargedPerUser = $this->perUserGameCountForRechargedOldPayers($dateID, $registerBefore);
+        $rechargedSql = $rechargedPerUser->toSql();
+        $rechargedBindings = $rechargedPerUser->getBindings();
+
+        $nonRechargedPerUser = $this->perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore);
+        $nonRechargedSql = $nonRechargedPerUser->toSql();
+        $nonRechargedBindings = $nonRechargedPerUser->getBindings();
+
+        return [
+            'withRecharge' => $this->avgFromSubSql($rechargedSql, $rechargedBindings, true, 'PayGameCount'),
+            'withRechargeAll' => $this->avgFromSubSql($rechargedSql, $rechargedBindings, false, 'PayGameCount'),
+            'withoutRecharge' => $this->avgFromSubSql($nonRechargedSql, $nonRechargedBindings, true, 'PaySecond'),
+            'withoutRechargeAll' => $this->avgFromSubSql($nonRechargedSql, $nonRechargedBindings, false, 'PaySecond'),
+        ];
+    }
+
+    /**
+     * 老付费用户(非当日注册)当日有充值的平均游戏局数,按渠道
+     */
+    public function oldPayUserAvgGameCountWithRecharge($dateID, $date)
+    {
+        $registerBefore = $date->format('Y-m-d');
+        $perUserQuery = $this->perUserGameCountForRechargedOldPayers($dateID, $registerBefore);
+
+        return $this->avgGameCountByChannel($perUserQuery, 'PayGameCount');
+    }
+
+    /**
+     * 老付费用户(非当日注册)当日有充值的平均游戏局数,全渠道
+     */
+    public function oldPayUserAvgGameCountWithRechargeAll($dateID, $date)
+    {
+        $registerBefore = $date->format('Y-m-d');
+        $perUserQuery = $this->perUserGameCountForRechargedOldPayers($dateID, $registerBefore);
+
+        return $this->avgGameCountAll($perUserQuery, 'PayGameCount');
+    }
+
+    /**
+     * 老付费用户(非当日注册)当日没有充值且当日有玩游戏的平均游戏局数,按渠道
+     */
+    public function oldPayUserAvgGameCountWithoutRecharge($dateID, $date)
+    {
+        $registerBefore = $date->format('Y-m-d');
+        $perUserQuery = $this->perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore);
+
+        return $this->avgGameCountByChannel($perUserQuery, 'PaySecond');
+    }
+
+    /**
+     * 老付费用户(非当日注册)当日没有充值且当日有玩游戏的平均游戏局数,全渠道
+     */
+    public function oldPayUserAvgGameCountWithoutRechargeAll($dateID, $date)
+    {
+        $registerBefore = $date->format('Y-m-d');
+        $perUserQuery = $this->perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore);
+
+        return $this->avgGameCountAll($perUserQuery, 'PaySecond');
+    }
 }

+ 1 - 1
resources/views/admin/Withdrawal/verify_finish.blade.php

@@ -293,7 +293,7 @@
                                                 </a>
                                             @endif
 
-                                            @if($item->State == 5 || ($item->State == 6 && (!empty($isSuperAdmin) || $item->WithDraw < 40)))
+                                            @if(($item->State == 6 && (!empty($isSuperAdmin) || $item->WithDraw < 40)))
                                                 <br>
                                                 <a class="layer-switch"
                                                    data-remind="{{ __('auto.你确定要重制茶叶状态么?') }}"