9 Commits 5a234c543b ... 06aaaad698

Autore SHA1 Messaggio Data
  zhaozhen 06aaaad698 Merge branch 'zz/dev001' 2 anni fa
  zhaozhen 2bbf5aa087 提取pid-更新 2 anni fa
  zhaozhen 771e34fa11 提取pid更新 2 anni fa
  zhaozhen 78200c53da 提取pid更新 2 anni fa
  zhaozhen b8259ee674 提取pid更新 2 anni fa
  zhaozhen f2ae70ad87 提取pid更新 2 anni fa
  zhaozhen 1b5e3b85ff 提取pid更新 2 anni fa
  zhaozhen 2db683ab4c 推广数据-朋友圈群发更新 2 anni fa
  zhaozhen 34abba9bd2 推广数据-客户群发更新 2 anni fa

+ 51 - 25
app/Console/Commands/ReferralLinkPidDraw.php

@@ -64,7 +64,7 @@ class ReferralLinkPidDraw extends Command
64 64
                     continue;
65 65
                 }
66 66
 
67
-                $res = MassMsgService::drawPid($data, $pid, 'ReferralLinkPidDraw');
67
+                $res = $this->drawPid($data, $pid, 'ReferralLinkPidDraw');
68 68
             } catch (\Throwable $e) {
69 69
                 Log::logError('提取推广链接PID异常', [
70 70
                     'type'  => $type,
@@ -85,19 +85,19 @@ class ReferralLinkPidDraw extends Command
85 85
 
86 86
             if ($res) {
87 87
                 $upDb = ['is_draw' => 1];
88
-                if (!is_null($pid)) $upDb['pid'] = $pid;
88
+                if (!is_null($pid)) $upDb['pids'] = $pid;
89 89
 
90 90
                 $item->update($upDb);
91 91
             }
92 92
         }
93 93
     }
94 94
 
95
-    public function drawPid($data, &$pid)
95
+    public function drawPid($attachments, &$pid, $logName)
96 96
     {
97
-        Log::logInfo('提取开始', $data, 'ReferralLinkPidDraw');
97
+        Log::logInfo('提取开始', $attachments, $logName);
98 98
 
99
-        $drawPids     = [];
100
-        foreach ($data as $datum) {
99
+        $drawPids = [];
100
+        foreach ($attachments as $datum) {
101 101
             if (isset($datum['msgtype'])) {
102 102
                 $url = null;
103 103
                 // 小程序
@@ -133,71 +133,97 @@ class ReferralLinkPidDraw extends Command
133 133
                     $url = $datum['promote']['jump_url'];
134 134
                 }
135 135
 
136
+                // 欢迎语中的H5推广会被转换成普通链接方式
137
+                if (
138
+                    ($datum['msgtype'] == 'link')
139
+                    &&
140
+                    isset($datum['link']['jump_url'])
141
+                    &&
142
+                    !empty($datum['link']['jump_url'])
143
+                ) {
144
+                    $url = $datum['link']['jump_url'];
145
+                }
146
+
136 147
                 // 属于其他类型
137 148
                 if (is_null($url)) continue;
138 149
 
139
-                Log::logInfo('处理url', ['url' => $url], 'ReferralLinkPidDraw');
150
+                Log::logInfo('提取URL', [
151
+                    'url'       => $url
152
+                ], $logName);
140 153
 
141 154
                 // 处理url
142
-                $fildExistNum = 0;
143
-                $this->dealUrl($url, $fildExistNum, $drawPids);
155
+                $filedExistNum = 0;
156
+                $this->dealUrl($url, $filedExistNum, $drawPids, $logName);
144 157
 
145
-                if ($fildExistNum > 1) {
146
-                    Log::logError('提取推广链接PID存在多个字段', $datum, 'ReferralLinkPidDraw');
158
+                if ($filedExistNum > 1) {
159
+                    Log::logError('提取推广链接PID存在多个字段', $datum, $logName);
147 160
                     return false;
148 161
                 }
149 162
             }
150 163
 
151
-            if (count($drawPids) > 1) {
152
-                Log::logError('提取推广链接PID存在多个值', $datum, 'ReferralLinkPidDraw');
153
-                return false;
154
-            }
164
+//            if (count($drawPids) > 1) {
165
+//                Log::logError('提取推广链接PID存在多个值', $datum, $logName);
166
+//                return false;
167
+//            }
155 168
 
156
-            if (!empty($drawPids)) $pid = current($drawPids);
169
+            if (!empty($drawPids)) $pid = json_encode(array_filter($drawPids));
157 170
 
158
-            Log::logInfo('提取结束', $data, 'ReferralLinkPidDraw');
171
+            Log::logInfo('提取结束', $attachments, $logName);
159 172
         }
160 173
 
161 174
         return true;
162 175
     }
163 176
 
164
-    public function dealUrl($url, &$fildExistNum, &$drawPids)
177
+    public function dealUrl($url, &$filedExistNum, &$drawPids, $logName)
165 178
     {
179
+        $url = str_replace("%25", "%", $url);
180
+        $url = str_replace("&", "&", $url);
181
+
182
+        $url = urldecode($url);
166 183
         $urlArr = parse_url($url);
184
+
167 185
         if (!isset($urlArr['query']) && empty($urlArr['query'])) return false;
168 186
 
169
-        Log::logInfo('提取url', ['url' => $url, 'fildExistNum' => $fildExistNum, 'drawPids' => $drawPids], 'ReferralLinkPidDraw');
187
+        Log::logInfo('提取url', [
188
+            'url'           => $url,
189
+            'filedExistNum' => $filedExistNum,
190
+            'drawPids'      => $drawPids
191
+        ], $logName);
170 192
 
171 193
         parse_str($urlArr['query'], $query);
172 194
 
173 195
         // 柚子 pathId
174 196
         if (isset($query['pathId']) && !empty($query['pathId'])) {
175
-            $fildExistNum ++;
197
+            $filedExistNum ++;
176 198
             $drawPids[] = $query['pathId'];
177 199
         }
178 200
 
179 201
         // 嘉书 article
180 202
         if (isset($query['article']) && !empty($query['article'])) {
181
-            $fildExistNum ++;
203
+            $filedExistNum ++;
182 204
             $drawPids[] = $query['article'];
183 205
         }
184 206
 
185 207
         // 迈步 pid
186 208
         if (isset($query['pid']) && !empty($query['pid'])) {
187
-            $fildExistNum ++;
209
+            $filedExistNum ++;
188 210
             $drawPids[] = $query['pid'];
189 211
         }
190 212
 
191 213
         // 点众阳光 referral_id
192 214
         if (isset($query['referral_id']) && !empty($query['referral_id'])) {
193
-            $fildExistNum ++;
215
+            $filedExistNum ++;
194 216
             $drawPids[] = $query['referral_id'];
195 217
         }
196 218
 
197 219
         foreach ($query as $urlVal) {
198
-            $this->dealUrl($urlVal, $fildExistNum, $drawPids);
220
+            $this->dealUrl($urlVal, $filedExistNum, $drawPids, $logName);
199 221
         }
200 222
 
201
-        Log::logInfo('提取url结果', ['url' => $url, 'fildExistNum' => $fildExistNum, 'drawPids' => $drawPids], 'ReferralLinkPidDraw');
223
+        Log::logInfo('提取url结果', [
224
+            'url'           => $url,
225
+            'filedExistNum' => $filedExistNum,
226
+            'drawPids'      => $drawPids
227
+        ], $logName);
202 228
     }
203 229
 }

+ 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('pids')->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
 

+ 9 - 1
app/Models/MomentTask.php

@@ -131,7 +131,15 @@ class MomentTask extends Model
131 131
 //        }
132 132
 
133 133
         $popu_data = null;
134
-        $pids = $data->pluck('pid')->all();
134
+        $pids = [];
135
+        $pidVals = $data->pluck('pids')->all();
136
+        foreach ($pidVals as $pidVal) {
137
+            if (empty($pidVal)) continue;
138
+
139
+            $itemPids = json_decode($pidVal, true);
140
+            $pids = array_merge($pids, $itemPids);
141
+        }
142
+
135 143
         $pids = array_filter($pids);
136 144
         if( !empty($pids) ){
137 145
             $popu_data = MassPopularizData::selectRaw('sum(viewUv) as viewUv, sum(payPv) as payPv, sum(payUv) as payUv, sum(payMoney) as payMoney')->whereIn('pid', $pids)->first();

+ 103 - 47
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('pids')->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,57 @@ 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->pids, 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->newPayUv       = 0;
128
+                        $datum->newPayPv       = 0;
129
+                        $datum->newPayAmount   = 0;
130
+                        $datum->oldPayAmount   = 0;
131
+                        $datum->otherPayAmount = 0;
132
+                        foreach ($popu_list as $popu_info) {
133
+                            $datum->viewUv   += ($popu_info->viewUv ?? 0);
134
+                            $datum->payUv    += ($popu_info->payUv ?? 0);
135
+                            $datum->payPv    += ($popu_info->payPv ?? 0);
136
+                            $datum->payMoney += ($popu_info->payMoney ?? 0);
137
+
138
+                            if(isset($popu_info->playletActivityId)) {
139
+                                $datum->newPayUv       += ($orderData[$popu_info->playletActivityId]['newPayUv'] ?? 0);
140
+                                $datum->newPayPv       += ($orderData[$popu_info->playletActivityId]['newPayPv'] ?? 0);
141
+                                $datum->newPayAmount   += ($orderData[$popu_info->playletActivityId]['newPayAmount'] ?? 0);
142
+                                $datum->oldPayAmount   += ($orderData[$popu_info->playletActivityId]['oldPayAmount'] ?? 0);
143
+                                $datum->otherPayAmount += ($otherOrderData[$popu_info->playletActivityId]['otherPayAmount'] ?? 0);
144
+                            }
145
+                        }
146
+
147
+                        $datum->newPayAmount   = round($orderData[$popu_info->playletActivityId]['newPayAmount']/10000, 2);
148
+                        $datum->oldPayAmount   = round($orderData[$popu_info->playletActivityId]['oldPayAmount']/10000, 2);
149
+                        $datum->otherPayAmount = round($otherOrderData[$popu_info->playletActivityId]['otherPayAmount']/10000, 2);
150
+                        $datum->newPayAvg      = $datum->newPayUv>0 ? round($datum->newPayPv/$datum->newPayUv, 2) : null;
124 151
                     } else {
125
-                        $datum->newPayUv = null;
126
-                        $datum->newPayPv = null;
127
-                        $datum->newPayAmount = null;
128
-                        $datum->oldPayAmount = null;
152
+                        $datum->viewUv         = null;
153
+                        $datum->payUv          = null;
154
+                        $datum->payPv          = null;
155
+                        $datum->payMoney       = null;
156
+                        $datum->newPayUv       = null;
157
+                        $datum->newPayPv       = null;
158
+                        $datum->newPayAmount   = null;
159
+                        $datum->oldPayAmount   = null;
129 160
                         $datum->otherPayAmount = null;
161
+                        $datum->newPayAvg      = null;
130 162
                     }
131
-
132
-                    $datum->newPayAvg = $datum->newPayUv>0 ? round($datum->newPayPv/$datum->newPayUv, 2) : null;
133
-
134 163
                 } else {
135 164
                     $datum->viewUv = null;
136 165
                     $datum->payUv = null;
@@ -205,8 +234,15 @@ class PopularizService
205 234
                 ->whereIn('rule_id', $ruleIds)->groupBy(['rule_id'])->get();
206 235
 
207 236
             #统计回收信息
208
-            $pids = $list->pluck('pid')->all();
209
-            $pids = array_filter($pids);
237
+            $pids = [];
238
+            $pidVals = $list->pluck('pids')->all();
239
+            foreach ($pidVals as $pidVal) {
240
+                if (empty($pidVal)) continue;
241
+
242
+                $itemPids = json_decode($pidVal, true);
243
+                $pids = array_merge($pids, $itemPids);
244
+            }
245
+
210 246
             if( !empty($pids) ){
211 247
                 $popu_data = MassPopularizData::select('viewPv', 'viewUv', 'payPv', 'payUv', 'payMoney', 'pid', 'playletActivityId')
212 248
                     ->whereIn('pid', $pids)
@@ -259,35 +295,55 @@ class PopularizService
259 295
 
260 296
                 unset($datum->admin_id);
261 297
 
262
-                $pid = $datum->pid;
298
+                $datumPids = json_decode($datum->pids, true);
263 299
                 #统计 总播放人数(:总uv)  充值人数 充值次数(今日) 充值金额(今日)   付费率 点击率
264
-                if($pid){
265
-                    $popu_info = $popu_data->where('pid', $pid)->first();
266
-
267
-                    $datum->viewUv = $popu_info->viewUv ?? null;
268
-                    $datum->payUv = $popu_info->payUv ?? null;
269
-                    $datum->payPv = $popu_info->payPv ?? null;
270
-                    $datum->payMoney = $popu_info->payMoney ?? null;
300
+                if($datumPids){
271 301
                     $datum->payAvg = $datum->payUv>0 ? round($datum->payPv/$datum->payUv, 2) : null;
272 302
                     $datum->payRate = $datum->viewUv>0 ? round($datum->payUv/$datum->viewUv*100, 2) .'%' : null;
273 303
                     $datum->clickRate = $datum->published_count>0 ? round($datum->viewUv/$datum->published_count*100, 2) .'%' : null;
274 304
 
275
-                    if(isset($popu_info->playletActivityId)) {
276
-                        $datum->newPayUv = $orderData[$popu_info->playletActivityId]['newPayUv'] ?? null;
277
-                        $datum->newPayPv = $orderData[$popu_info->playletActivityId]['newPayPv'] ?? null;
278
-                        $datum->newPayAmount = isset($orderData[$popu_info->playletActivityId]['newPayAmount']) ? round($orderData[$popu_info->playletActivityId]['newPayAmount']/10000, 2) : null;
279
-                        $datum->oldPayAmount = isset($orderData[$popu_info->playletActivityId]['oldPayAmount']) ? round($orderData[$popu_info->playletActivityId]['oldPayAmount']/10000, 2) : null;
280
-                        $datum->otherPayAmount = isset($otherOrderData[$popu_info->playletActivityId]['otherPayAmount']) ? round($otherOrderData[$popu_info->playletActivityId]['otherPayAmount']/10000, 2) : null;
305
+                    $popu_list = MassPopularizData::select('viewPv', 'viewUv', 'payPv', 'payUv', 'payMoney', 'pid', 'playletActivityId')
306
+                        ->whereIn('pid', $datumPids)
307
+                        ->get();
308
+                    if ($popu_list->isNotEmpty()) {
309
+                        $datum->viewUv         = 0;
310
+                        $datum->payUv          = 0;
311
+                        $datum->payPv          = 0;
312
+                        $datum->payMoney       = 0;
313
+                        $datum->newPayUv       = 0;
314
+                        $datum->newPayPv       = 0;
315
+                        $datum->newPayAmount   = 0;
316
+                        $datum->oldPayAmount   = 0;
317
+                        $datum->otherPayAmount = 0;
318
+                        foreach ($popu_list as $popu_info) {
319
+                            $datum->viewUv   += ($popu_info->viewUv ?? 0);
320
+                            $datum->payUv    += ($popu_info->payUv ?? 0);
321
+                            $datum->payPv    += ($popu_info->payPv ?? 0);
322
+                            $datum->payMoney += ($popu_info->payMoney ?? 0);
323
+                            if(isset($popu_info->playletActivityId)) {
324
+                                $datum->newPayUv       += ($orderData[$popu_info->playletActivityId]['newPayUv'] ?? 0);
325
+                                $datum->newPayPv       += ($orderData[$popu_info->playletActivityId]['newPayPv'] ?? 0);
326
+                                $datum->newPayAmount   += ($orderData[$popu_info->playletActivityId]['newPayAmount'] ?? 0);
327
+                                $datum->oldPayAmount   += ($orderData[$popu_info->playletActivityId]['oldPayAmount'] ?? 0);
328
+                                $datum->otherPayAmount += ($otherOrderData[$popu_info->playletActivityId]['otherPayAmount'] ?? 0);
329
+                            }
330
+                        }
331
+                        $datum->newPayAmount   = round($orderData[$popu_info->playletActivityId]['newPayAmount']/10000, 2);
332
+                        $datum->oldPayAmount   = round($orderData[$popu_info->playletActivityId]['oldPayAmount']/10000, 2);
333
+                        $datum->otherPayAmount = round($otherOrderData[$popu_info->playletActivityId]['otherPayAmount']/10000, 2);
334
+                        $datum->newPayAvg      = $datum->newPayUv>0 ? round($datum->newPayPv/$datum->newPayUv, 2) : null;
281 335
                     } else {
282
-                        $datum->newPayUv = null;
283
-                        $datum->newPayPv = null;
284
-                        $datum->newPayAmount = null;
285
-                        $datum->oldPayAmount = null;
286
-                        $datum->otherPayAmount = null;
336
+                        $datum->viewUv         = 0;
337
+                        $datum->payUv          = 0;
338
+                        $datum->payPv          = 0;
339
+                        $datum->payMoney       = 0;
340
+                        $datum->newPayUv       = 0;
341
+                        $datum->newPayPv       = 0;
342
+                        $datum->newPayAmount   = 0;
343
+                        $datum->oldPayAmount   = 0;
344
+                        $datum->otherPayAmount = 0;
345
+                        $datum->newPayAvg      = 0;
287 346
                     }
288
-
289
-                    $datum->newPayAvg = $datum->newPayUv>0 ? round($datum->newPayPv/$datum->newPayUv, 2) : null;
290
-
291 347
                 } else {
292 348
                     $datum->viewUv = null;
293 349
                     $datum->payUv = null;