Browse Source

销售模板数据导出

sunhao 5 years ago
parent
commit
d600d22f11

+ 55 - 1
app/Http/Controllers/Admin/TemplateController.php

@@ -14,6 +14,7 @@ use App\TemplatesSalers;
14 14
 use App\AdminRole;
15 15
 use App\TemplatesLog;
16 16
 use App\CustDetail;
17
+use App\Order;
17 18
 use App\Services\OssServices as oss;
18 19
 use Illuminate\Support\Facades\DB;
19 20
 
@@ -347,5 +348,58 @@ class TemplateController extends Controller
347 348
         ]);
348 349
     }
349 350
 
351
+    /**
352
+     * 销售引流模板分配日志报表
353
+     */
354
+    public function templateLogReport_export(Request $request){
355
+        $admin_id = (int)$request->input('admin_id');
356
+        $team_id = (int)$request->input('team_id');
357
+        $stime = $request->input('stime');
358
+        $etime = $request->input('etime');
359
+
360
+        //假如有团队筛选,检索销售队员
361
+        $sale_ids = null;
362
+        if($team_id>0){
363
+            $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
364
+        }
365
+
366
+        $result = TemplatesLog::select(DB::raw('left(create_time,10) as day,admin_id,count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where(function($query) use($admin_id, $stime, $etime, $sale_ids){
367
+            if($admin_id>0) $query->where('admin_id', $admin_id);
368
+            if($stime) $query->where('create_time', '>=', $stime);
369
+            if($etime) $query->where('create_time', '<=', $etime. ' 23:59:59');
370
+            if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
371
+        })->groupBy('day')->groupBy('admin_id')->orderBy('day', 'desc')->get();
372
+        $result = json_decode(json_encode($result), true);
373
+        foreach($result as $k=>&$v){
374
+            //获取销售当天加粉情况
375
+            $custDetail = CustDetail::select('fan_add', 'new_reply', 'new_consult', 'old_consult', 'admin_name')->where('dtime', $v['day'])->where('admin_id', $v['admin_id'])->where('is_del', 0)->first();
376
+            if(!empty($custDetail)){
377
+                $v['fan_add'] = $custDetail->fan_add;
378
+                $v['new_reply'] = $custDetail->new_reply;
379
+                $v['old_consult'] = $custDetail->old_consult;
380
+                $v['new_consult'] = $custDetail->new_consult;
381
+                $v['admin_name'] = $custDetail->admin_name;
382
+            }else{
383
+                $v['fan_add'] = '';
384
+                $v['new_reply'] = '';
385
+                $v['old_consult'] = '';
386
+                $v['new_consult'] = '';
387
+                $v['admin_name'] = DB::table('admin')->where('id', $v['admin_id'])->pluck('realname');
388
+            }
389
+            $v['long_count'] = $v['tcount'] - $v['pv_count'];
390
+
391
+            //点击率
392
+            $v['click_rate'] = $v['pv_count']>0 && $v['long_count']>0 ? round( $v['long_count'] / $v['pv_count'], 4 ) * 100 . '%' : '';
393
+            $v['change_rate'] = $v['long_count']>0 && $v['fan_add']>0 ? round( $v['fan_add'] / $v['long_count'], 4 ) * 100 . '%' : '';
394
+        }
395
+
396
+        $indexKey = ['day','admin_name','pv_count','long_count','fan_add','click_rate','change_rate','new_reply','new_consult','old_consult'];
397
+        $title = ['日期', '销售名', 'PV量', '长按次数', '加粉数', '点击率', '转化率', '新粉回复数', '新粉询价数', '老粉询价数'];
398
+        $filename = 'xiaoshoudaofen_'.date('Y-m-d_H').'.xlsx';
399
+        return Order::export_excel($result, $filename, $indexKey, $title);
400
+       
401
+    }
402
+
350 403
 
351
-}
404
+}
405
+ 

+ 1 - 0
app/Http/routes.php

@@ -200,6 +200,7 @@ Route::group(['prefix' => 'admin'], function(){
200 200
         Route::get('template/logindex',   'Admin\TemplateController@logindex');
201 201
         //销售模板引流每日报表
202 202
         Route::get('template/templateLogReport',   'Admin\TemplateController@templateLogReport');
203
+        Route::get('template/templateLogReport_export',   'Admin\TemplateController@templateLogReport_export');
203 204
     });
204 205
     
205 206
 });

+ 1 - 1
resources/views/template/templateLogReport.blade.php

@@ -25,7 +25,7 @@
25 25
                
26 26
                 
27 27
                 <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>   
28
-                <!--a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a-->
28
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
29 29
                 
30 30
             </div>
31 31
         </div>