Prechádzať zdrojové kódy

充值成功率统计1

laowu 4 dní pred
rodič
commit
9d61192140

+ 21 - 46
app/Http/Controllers/Admin/RechargeController.php

@@ -780,7 +780,7 @@ class RechargeController extends Controller
             } elseif ($i == 1) {
                 $dateLabels[] = '昨日';
             } else {
-                $dateLabels[] = $d->format('Y-m-d') . '(今日-' . $i . '天)';
+                $dateLabels[] = $d->format('Y-m-d');
             }
         }
 
@@ -804,54 +804,29 @@ class RechargeController extends Controller
             ->orderBy('o.order_title')
             ->get();
 
-        // 从 admin_configs 取所有支付渠道(type=pay),config_key 即为 payment_code
-        $paymentCodes = DB::connection('write')
-            ->table(DB::raw('agent.dbo.admin_configs WITH (NOLOCK)'))
-            ->where('type', 'pay')
-            ->where('config_key', '<>', '')
-            ->pluck('config_key')
-            ->unique()
-            ->values()
-            ->toArray();
-
-        // 将订单数据按 [payment_code][order_title] 索引
-        $dataIndex = [];
-        foreach ($rows as $row) {
-            $code = $row->payment_code;
-            $title = (int)$row->order_title;
-            $dataIndex[$code][$title] = $row;
-        }
-
         $list = [];
-        foreach ($paymentCodes as $code) {
-            foreach ($payMethodsMap as $title => $name) {
-                $row = $dataIndex[$code][$title] ?? null;
-                $channelName = $code . ' ' . $name;
-
-                $days = [];
-                for ($i = 0; $i < 4; $i++) {
-                    if ($row) {
-                        $total = (int)$row->{'d' . $i . '_total'};
-                        $success = (int)$row->{'d' . $i . '_success'};
-                    } else {
-                        $total = 0;
-                        $success = 0;
-                    }
-                    $rate = $total > 0 ? round($success / $total * 100, 1) : 0;
-                    $days[] = [
-                        'total' => $total,
-                        'success' => $success,
-                        'rate' => $rate,
-                    ];
-                }
-
-                $list[] = [
-                    'payment_code' => $code,
-                    'order_title' => $title,
-                    'channel_name' => $channelName,
-                    'days' => $days,
+        foreach ($rows as $row) {
+            $methodName = $payMethodsMap[(int)$row->order_title] ?? '其他(' . $row->order_title . ')';
+            $channelName = $row->payment_code . ' ' . $methodName;
+
+            $days = [];
+            for ($i = 0; $i < 4; $i++) {
+                $total = (int)$row->{'d' . $i . '_total'};
+                $success = (int)$row->{'d' . $i . '_success'};
+                $rate = $total > 0 ? round($success / $total * 100, 1) : 0;
+                $days[] = [
+                    'total' => $total,
+                    'success' => $success,
+                    'rate' => $rate,
                 ];
             }
+
+            $list[] = [
+                'payment_code' => $row->payment_code,
+                'order_title' => $row->order_title,
+                'channel_name' => $channelName,
+                'days' => $days,
+            ];
         }
 
         return view('admin.recharge.pay_channel_rate', [