Quellcode durchsuchen

推广数据-客户群发更新

zhaozhen vor 2 Jahren
Ursprung
Commit
34abba9bd2
2 geänderte Dateien mit 59 neuen und 25 gelöschten Zeilen
  1. 9 2
      app/Models/MassMsg.php
  2. 50 23
      app/Service/PopularizService.php

+ 9 - 2
app/Models/MassMsg.php

@@ -148,8 +148,15 @@ class MassMsg extends Model
148 148
         }
149 149
 
150 150
         $popu_data = array();
151
-        $pids = $data->pluck('pid')->all();
152
-        $pids = array_filter($pids);
151
+        $pidVals = $data->pluck('pid')->all();
152
+        $pids = [];
153
+        foreach ($pidVals as $pidVal) {
154
+            if (empty($pidVal)) continue;
155
+
156
+            $itemPids = json_decode($pidVal, true);
157
+            $pids = array_merge($pids, $itemPids);
158
+        }
159
+
153 160
         if( !empty($pids) ){
154 161
             $popu_data = MassPopularizData::selectRaw('sum(viewUv) as viewUv, sum(payPv) as payPv, sum(payUv) as payUv, sum(payMoney) as payMoney')->whereIn('pid', $pids)->first();
155 162
 

+ 50 - 23
app/Service/PopularizService.php

@@ -44,8 +44,15 @@ class PopularizService
44 44
                 ->whereIn('rule_id', $ruleIds)->groupBy(['rule_id'])->get();
45 45
 
46 46
             #统计回收信息
47
-            $pids = $list->pluck('pid')->all();
48
-            $pids = array_filter($pids);
47
+            $pids = [];
48
+            $pidVals = $list->pluck('pid')->all();
49
+            foreach ($pidVals as $pidVal) {
50
+                if (empty($pidVal)) continue;
51
+
52
+                $itemPids = json_decode($pidVal, true);
53
+                $pids = array_merge($pids, $itemPids);
54
+            }
55
+
49 56
             if( !empty($pids) ){
50 57
                 $popu_data = MassPopularizData::select('viewPv', 'viewUv', 'payPv', 'payUv', 'payMoney', 'pid', 'playletActivityId')
51 58
                     ->whereIn('pid', $pids)
@@ -102,35 +109,55 @@ class PopularizService
102 109
                 $datum->send_total = isset($sendStatInfo->send_total) ? $sendStatInfo->send_total : 0;
103 110
                 unset($datum->admin_id);
104 111
 
105
-                $pid = $datum->pid;
112
+                $datumPids = json_decode($datum->pid, true);
106 113
                 #统计 总播放人数(:总uv)  充值人数 充值次数(今日) 充值金额(今日)   付费率 点击率
107
-                if($pid){
108
-                    $popu_info = $popu_data->where('pid', $pid)->first();
109
-
110
-                    $datum->viewUv = $popu_info->viewUv ?? null;
111
-                    $datum->payUv = $popu_info->payUv ?? null;
112
-                    $datum->payPv = $popu_info->payPv ?? null;
113
-                    $datum->payMoney = $popu_info->payMoney ?? null;
114
+                if($datumPids){
114 115
                     $datum->payAvg = $datum->payUv>0 ? round($datum->payPv/$datum->payUv, 2) : null;
115 116
                     $datum->payRate = $datum->viewUv>0 ? round($datum->payUv/$datum->viewUv*100, 2) .'%' : null;
116 117
                     $datum->clickRate = $datum->send_success>0 ? round($datum->viewUv/$datum->send_success*100, 2) .'%' : null;
117 118
 
118
-                    if(isset($popu_info->playletActivityId)) {
119
-                        $datum->newPayUv = $orderData[$popu_info->playletActivityId]['newPayUv'] ?? null;
120
-                        $datum->newPayPv = $orderData[$popu_info->playletActivityId]['newPayPv'] ?? null;
121
-                        $datum->newPayAmount = isset($orderData[$popu_info->playletActivityId]['newPayAmount']) ? round($orderData[$popu_info->playletActivityId]['newPayAmount']/10000, 2) : null;
122
-                        $datum->oldPayAmount = isset($orderData[$popu_info->playletActivityId]['oldPayAmount']) ? round($orderData[$popu_info->playletActivityId]['oldPayAmount']/10000, 2) : null;
123
-                        $datum->otherPayAmount = isset($otherOrderData[$popu_info->playletActivityId]['otherPayAmount']) ? round($otherOrderData[$popu_info->playletActivityId]['otherPayAmount']/10000, 2) : null;
119
+                    $popu_list = MassPopularizData::select('viewPv', 'viewUv', 'payPv', 'payUv', 'payMoney', 'pid', 'playletActivityId')
120
+                        ->whereIn('pid', $datumPids)
121
+                        ->get();
122
+                    if ($popu_list->isNotEmpty()) {
123
+                        $datum->viewUv         = 0;
124
+                        $datum->payUv          = 0;
125
+                        $datum->payPv          = 0;
126
+                        $datum->payMoney       = 0;
127
+                        $datum->newPayAmount   = 0;
128
+                        $datum->oldPayAmount   = 0;
129
+                        $datum->otherPayAmount = 0;
130
+                        foreach ($popu_list as $popu_info) {
131
+                            $datum->viewUv   += ($popu_info->viewUv ?? 0);
132
+                            $datum->payUv    += ($popu_info->payUv ?? 0);
133
+                            $datum->payPv    += ($popu_info->payPv ?? 0);
134
+                            $datum->payMoney += ($popu_info->payMoney ?? 0);
135
+
136
+                            if(isset($popu_info->playletActivityId)) {
137
+                                $datum->newPayUv       += ($orderData[$popu_info->playletActivityId]['newPayUv'] ?? 0);
138
+                                $datum->newPayPv       += ($orderData[$popu_info->playletActivityId]['newPayPv'] ?? 0);
139
+                                $datum->newPayAmount   += ($orderData[$popu_info->playletActivityId]['newPayAmount'] ?? 0);
140
+                                $datum->oldPayAmount   += ($orderData[$popu_info->playletActivityId]['oldPayAmount'] ?? 0);
141
+                                $datum->otherPayAmount += ($otherOrderData[$popu_info->playletActivityId]['otherPayAmount'] ?? 0);
142
+                            }
143
+                        }
144
+
145
+                        $datum->newPayAmount   = round($orderData[$popu_info->playletActivityId]['newPayAmount']/10000, 2);
146
+                        $datum->oldPayAmount   = round($orderData[$popu_info->playletActivityId]['oldPayAmount']/10000, 2);
147
+                        $datum->otherPayAmount = round($otherOrderData[$popu_info->playletActivityId]['otherPayAmount']/10000, 2);
148
+                        $datum->newPayAvg      = $datum->newPayUv>0 ? round($datum->newPayPv/$datum->newPayUv, 2) : null;
124 149
                     } else {
125
-                        $datum->newPayUv = null;
126
-                        $datum->newPayPv = null;
127
-                        $datum->newPayAmount = null;
128
-                        $datum->oldPayAmount = null;
150
+                        $datum->viewUv         = null;
151
+                        $datum->payUv          = null;
152
+                        $datum->payPv          = null;
153
+                        $datum->payMoney       = null;
154
+                        $datum->newPayUv       = null;
155
+                        $datum->newPayPv       = null;
156
+                        $datum->newPayAmount   = null;
157
+                        $datum->oldPayAmount   = null;
129 158
                         $datum->otherPayAmount = null;
159
+                        $datum->newPayAvg      = null;
130 160
                     }
131
-
132
-                    $datum->newPayAvg = $datum->newPayUv>0 ? round($datum->newPayPv/$datum->newPayUv, 2) : null;
133
-
134 161
                 } else {
135 162
                     $datum->viewUv = null;
136 163
                     $datum->payUv = null;