Browse Source

销售上报导出

sunhao 5 years ago
parent
commit
87d1535efb

+ 36 - 76
app/Http/Controllers/Admin/CustReportController.php

@@ -13,6 +13,7 @@ use App\CustTotal;
13 13
 use App\CustDetail;
14 14
 use App\AdCost;
15 15
 use App\Oplog;
16
+use App\Order;
16 17
 use Illuminate\Http\Request;
17 18
 use Illuminate\Support\Facades\DB;
18 19
 
@@ -578,89 +579,48 @@ class custReportController extends Controller
578 579
         }
579 580
     }
580 581
 
581
-    public function detail_export(Request $request){
582
-        
582
+    public function detail_export(Request $request){       
583
+       
584
+        $team_id = (int)$request->input('team_id');
585
+        $admin_id = (int)$request->input('admin_id');
586
+        $search_admin = 1;
587
+        #只能看自己团队的
583 588
         $self_role = session('role_name');
584
-        if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '运营投放'  || $self_role == '售后管理员'){
585
-            $admin_id = $request->input('admin_id');
586
-        }else{
587
-            $admin_id = session('admin_id');
589
+        if($self_role != '超级管理员' && $self_role != '售后管理员'){
590
+            $self_id = session('admin_id');
591
+            $team_id = DB::table('admin')->where('id', $self_id)->pluck('team_id');                  
588 592
         }
589
-        $stime = $request->input('stime');
590
-        $etime = $request->input('etime');
591
-
592
-        $result = CustDetail::where(function($query) use($admin_id, $stime, $etime){
593
-            if($admin_id) $query->where('admin_id',  $admin_id);
594
-            if($stime) $query->where('createTime', '>=', $stime);
595
-            if($etime) $query->where('createTime', '<=', $etime);
596
-        })->where('is_del',0)->orderBy('id', 'desc')->get();
597
-        $result = json_decode(json_encode($result),true);
598
-
599
-
600
-        $filename="粉丝数据分日统计.xls";
601
-        header("Content-type:application/vnd.ms-excel");
602
-        Header("Accept-Ranges:bytes");
603
-        Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名
604
-        header("Pragma: no-cache");
605
-        header("Expires: 0");
606 593
 
607
-        $data_str = "
608
-            <table>
609
-            <tr>
610
-                <th>".iconv("UTF-8", "GB2312//IGNORE","销售微信号")."</th>
611
-                <th>".iconv("UTF-8", "GB2312//IGNORE","销售团队")."</th>
612
-                <th>".iconv("UTF-8", "GB2312//IGNORE","销售")."</th>
613
-                <th>".iconv("UTF-8", "GB2312//IGNORE","订单时间")."</th>
614
-                <th>".iconv("UTF-8", "GB2312//IGNORE","加粉时间")."</th>
615
-                <th>".iconv("UTF-8", "GB2312//IGNORE","是否复购")."</th>
616
-                <th>".iconv("UTF-8", "GB2312//IGNORE","订单金额")."</th>
617
-                <th>".iconv("UTF-8", "GB2312//IGNORE","订单商品")."</th>
618
-                <th>".iconv("UTF-8", "GB2312//IGNORE","是否退补单")."</th>
619
-                <th>".iconv("UTF-8", "GB2312//IGNORE","配送地址")."</th>
620
-                <th>".iconv("UTF-8", "GB2312//IGNORE","配送姓名")."</th>
621
-                <th>".iconv("UTF-8", "GB2312//IGNORE","配送电话")."</th>
622
-                <th>".iconv("UTF-8", "GB2312//IGNORE","供应商成本")."</th>
623
-                <th>".iconv("UTF-8", "GB2312//IGNORE","顺丰单号")."</th>                
594
+        if($admin_id>0 && !$team_id){
595
+            $team_id = DB::table('admin')->where('id', $admin_id)->pluck('team_id');
596
+        }
624 597
 
625
-            </tr>";
626
-            foreach ($result as $k => $v)
627
-            {
628
-                #销售
629
-                $admin = DB::table('admin')->where('id', $v['admin_id'])->first();
630
-                $v['wx_id'] = isset($admin->wx_id) ? $admin->wx_id : '';
631
-                #team
632
-                $team = DB::table('teams')->where('id', $v['team_id'])->first();
633
-                $v['team_name'] = isset($team->name) ? $team->name : '';
634
-                #加粉时间
635
-                $customr = DB::table('customers')->where('phone', $v['receiverMobile'])->first();
636
-                $v['fanTime'] = isset($customr->fanTime) ? $customr->fanTime : '';
598
+        if($self_role == '销售'){
599
+            $search_admin = 0;
600
+            $admin_id = $self_id;
601
+        }
637 602
 
638
-                $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
603
+        //假如有团队筛选,检索销售队员
604
+        $sale_ids = null;
605
+        if($team_id>0 && !$admin_id){
606
+            $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
607
+        }
639 608
 
640
-                $fugou = $v['is_fugou']==1? '是' : '否';
641
-                $is_refund = $v['is_refund']==1? '是' : '否';
642
-                $address = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverAddress'];
643
-                $data_str .= "<tr>";
644
-                $data_str .= "<td>".$v['wx_id']."</td>";
645
-                $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["team_name"])."</td>";
646
-                $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["admin_name"])."</td>";
647
-                $data_str .= "<td>".$v['createTime']."</td>";
648
-                $data_str .= "<td>".$v['fanTime']."</td>";
649
-                $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $fugou)."</td>";
650
-                $data_str .= "<td>".$v['receivedAmount']."</td>";
651
-                $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["goods_note"])."</td>";
652
-                $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $is_refund)."</td>";
653
-                $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $address)."</td>";
654
-                $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["receiverName"])."</td>";
655
-                $data_str .= "<td>".$v['receiverMobile']."</td>";
656
-                $data_str .= "<td>".$v['cost']."</td>";
657
-                $data_str .= "<td style='vnd.ms-excel.numberformat:@'>".$v["logistics_id"]."</td>";
658
-                $data_str .= "</tr>";
659
-            }
609
+        $stime = $request->input('stime');
610
+        $etime = $request->input('etime');
611
+        $result = CustDetail::where(function($query) use($admin_id, $stime, $etime, $sale_ids){
612
+            if($admin_id) $query->where('admin_id', $admin_id);
613
+            if($stime) $query->where('dtime', '>=', $stime);
614
+            if($etime) $query->where('dtime', '<=', $etime);
615
+            if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
616
+        })->where('is_del',0)->orderBy('id', 'desc')->get();
617
+        $result = json_decode(json_encode($result),true);  
660 618
 
661
-        $data_str .= "</table>";
662
-        echo $data_str;
663
-        exit;       
619
+        $indexKey = ['dtime','fan_add','new_reply','old_consult','new_consult','admin_name'];
620
+        $title = ['日期', '加粉数', '新粉回复数', '老粉询价数', '新粉询价数','所属销售'];
621
+        
622
+        $filename = 'xiaoshoushangbao_'.date('Y-m-d_H').'.xlsx';
623
+        return Order::export_excel($result, $filename, $indexKey, $title);        
664 624
     }
665 625
 
666 626
     /**

+ 1 - 1
resources/views/custreport/detaillist.blade.php

@@ -29,7 +29,7 @@
29 29
                 
30 30
                     <a style="margin-left: 5px" class="btn btn-primary radius" onclick="user_search()" href="javascript:;">搜索</a>
31 31
                     <a style="margin-left: 5px" class="btn btn-danger radius" onclick="look_noreport()" href="javascript:;">查看未上报数据销售</a>
32
-                    <!--a class="btn btn-primary radius" onclick="custreport_export()" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 导出订单</a-->
32
+                    <a class="btn btn-primary radius" onclick="custreport_export()" href="javascript:;"> 导出</a>
33 33
                 
34 34
             </div>
35 35
         </div>