Browse Source

解决冲突

sunhao 5 years ago
parent
commit
50fc5828e4

+ 83 - 3
app/Http/Controllers/Admin/StatisticsController.php

@@ -1482,7 +1482,7 @@ class StatisticsController extends Controller
1482 1482
         $ret = AdCost::select('id')->where(function($query) use($stime, $etime, $city){    
1483 1483
             if($stime) $query->where('ad_time', '>=', $stime);
1484 1484
             if($etime) $query->where('ad_time', '<=', $etime);
1485
-            if($city) $query->where('city', '=', $city);
1485
+            if($city) $query->where('city', 'like', '%'.$city.'%');
1486 1486
         })->groupBy('ad_time')->groupBy('city')->get();
1487 1487
         $ret = json_decode(json_encode($ret), true);
1488 1488
 
@@ -1536,6 +1536,9 @@ class StatisticsController extends Controller
1536 1536
             'order_amount' => 0,
1537 1537
             'roi' => 0,
1538 1538
             'conversion_times' => 0,
1539
+            'new_order_count' => 0,
1540
+            'new_order_amount' => 0,
1541
+            'new_roi' => 0,
1539 1542
         ];
1540 1543
 
1541 1544
         //投入
@@ -1558,6 +1561,11 @@ class StatisticsController extends Controller
1558 1561
         $total_data['order_count'] = $order->order_count;
1559 1562
         $total_data['order_amount'] = $order->order_amount;
1560 1563
         $total_data['roi'] = $total_data['cost']>0 ? round($total_data['order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1564
+        #总新粉成单:            
1565
+        $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->whereIn('receiverMobile', $phones)->first();
1566
+        $total_data['new_order_count'] = $new_order->order_count;
1567
+        $total_data['new_order_amount'] = $new_order->order_amount;
1568
+        $total_data['new_roi'] = $total_data['cost']>0 ? round($total_data['new_order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1561 1569
 
1562 1570
         return view('statistics/districtRoi', ['result' =>$result,
1563 1571
             'page'              =>$page,
@@ -1623,6 +1631,9 @@ class StatisticsController extends Controller
1623 1631
             'order_amount' => 0,
1624 1632
             'roi' => 0,
1625 1633
             'conversion_times' => 0,
1634
+            'new_order_count' => 0,
1635
+            'new_order_amount' => 0,
1636
+            'new_roi' => 0,
1626 1637
         ];
1627 1638
 
1628 1639
         //投入
@@ -1646,13 +1657,18 @@ class StatisticsController extends Controller
1646 1657
         $total_data['order_amount'] = $order->order_amount;
1647 1658
         $total_data['roi'] = $total_data['cost']>0 ? round($total_data['order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1648 1659
 
1660
+        #总新粉成单:            
1661
+        $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->whereIn('receiverMobile', $phones)->first();
1662
+        $total_data['new_order_count'] = $new_order->order_count;
1663
+        $total_data['new_order_amount'] = $new_order->order_amount;
1664
+        $total_data['new_roi'] = $total_data['cost']>0 ? round($total_data['new_order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
1665
+
1649 1666
         $indexKey = ['ad_time','city','total_cost','conversion_times','new_fan_count','new_order_count','new_order_amount','new_roi','order_count','order_amount','total_roi'];
1650 1667
         $title = ['日期', '城市', '投放成本', '加粉数', '新粉数量', '新粉成单数', '新粉收入', '新粉ROI', '累计成单数', '累计收入', '累计ROI'];
1651 1668
         $filename = 'district_roi_'.date('Y-m-d_H').'.xlsx';
1652 1669
         return Order::export_excel($result, $filename, $indexKey, $title);
1653 1670
     }
1654 1671
 
1655
-
1656 1672
     /**
1657 1673
      * 团队订单财务明细
1658 1674
      */
@@ -1660,11 +1676,13 @@ class StatisticsController extends Controller
1660 1676
         $team_id = (int)$request->input('team_id');
1661 1677
         $stime = $request->input('stime');
1662 1678
         $etime = $request->input('etime');
1679
+
1663 1680
         $page = (int)$request->input('page');
1664 1681
         $pageSize = 20;
1665 1682
         if($page<=0){
1666 1683
             $page = 1;
1667 1684
         }
1685
+
1668 1686
         $offset = ($page-1) * $pageSize;
1669 1687
 
1670 1688
         $count = Order::where(function($query) use($team_id, $stime, $etime){
@@ -1727,6 +1745,7 @@ class StatisticsController extends Controller
1727 1745
             if($etime) $query->where('createTime', '<=', $etime.' 23:59:59');
1728 1746
         })->where('is_del', 0)->groupBy('team_id')->groupBy('ctime')->get();
1729 1747
         $count = count($count);
1748
+
1730 1749
         if ($count > 1) {
1731 1750
             // 总页数
1732 1751
             $pages = ceil($count/$pageSize);
@@ -1789,7 +1808,7 @@ class StatisticsController extends Controller
1789 1808
     }
1790 1809
 
1791 1810
     /**
1792
-     * 团队财务明细导出
1811
+     * 团队财务汇总导出
1793 1812
      */
1794 1813
     public function teamFinanceTotal_export(Request $request){
1795 1814
         $team_id = (int)$request->input('team_id');
@@ -1812,6 +1831,67 @@ class StatisticsController extends Controller
1812 1831
         $title = ['团队', '时间', '总单数', '成交金额', '售后', '退补差价', '实际金额', '供应商成本', '物流成本'];
1813 1832
         $filename = 'teamFinanceTotal_'.date('Y-m-d_H').'.xlsx';
1814 1833
         return Order::export_excel($result, $filename, $indexKey, $title);
1834
+
1835
+    }
1836
+
1837
+    /**
1838
+     * 地区汇总roi
1839
+     */
1840
+    public function districtTotalRoi(Request $request){
1841
+
1842
+        $offset = ($page-1) * $pageSize;
1843
+        $city = $request->input('city');
1844
+
1845
+        if($city !== null){
1846
+            $city = str_replace('市', '', $city);
1847
+        }       
1848
+
1849
+        $ret = AdCost::select('id')->where(function($query) use($city){    
1850
+            if($city) $query->where('city', 'like', '%'.$city.'%');
1851
+        })->groupBy('city')->get();
1852
+        $ret = json_decode(json_encode($ret), true);
1853
+
1854
+        $count = count($ret);
1855
+
1856
+        $result = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times, city'))->where(function($query) use($city){    
1857
+            if($city) $query->where('city', 'like', '%'.$city.'%');
1858
+        })->groupBy('city')->offset($offset)->limit($pageSize)->get();
1859
+
1860
+        $result = json_decode(json_encode($result), true);
1861
+
1862
+        foreach($result as $k=>&$v){
1863
+            //新粉收入
1864
+            //加粉
1865
+            $city_name = str_replace('市', '', $v['city']);
1866
+            $phones = DB::table('customers')->where('receiverCity','like', '%'.$city_name.'%')->lists('phone');
1867
+            #订单总计:
1868
+            $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->whereIn('receiverMobile', $phones)->where('is_del', 0)->first();
1869
+            
1870
+            #汇总新粉成单:            
1871
+            $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->leftJoin('customers as cu','cu.phone', '=', 'order.receiverMobile')->whereRaw('left(order.createTime, 10) = cu.fanTime')->where('order.is_del', 0)->whereIn('receiverMobile', $phones)->first();
1872
+            // 1.新粉成单数
1873
+            $v['new_order_count'] = $new_order->order_count;
1874
+            // 2.新粉成交额 
1875
+            $v['new_order_amount'] = $new_order->order_amount;
1876
+            // 3.粉丝总成交额
1877
+            $v['order_amount'] = $order->order_amount;
1878
+            // 总单数
1879
+            $v['order_count'] = $order->order_count;
1880
+            //新粉roi
1881
+            $v['new_roi'] = $v['total_cost']>0 ? round($v['new_order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
1882
+            //累计roi
1883
+            $v['total_roi'] = $v['total_cost']>0 ? round($v['order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
1884
+            $v['new_fan_count'] = count($phones);
1885
+
1886
+        }
1887
+
1888
+        return view('statistics/districtTotalRoi', ['result' =>$result,
1889
+            'page'              =>$page,
1890
+            'count'             =>$count,
1891
+            'pages'             =>$pages,                                    
1892
+            'city'             =>$city,                    
1893
+            ]);
1894
+
1815 1895
     }
1816 1896
 }
1817 1897
 

+ 3 - 0
resources/views/statistics/districtRoi.blade.php

@@ -26,6 +26,9 @@
26 26
                     <li>总投放成本:&yen;{{$total_data['cost']}}&nbsp;&nbsp;&nbsp;&nbsp;
27 27
                     总加粉数:{{$total_data['conversion_times']}}&nbsp;&nbsp;&nbsp;&nbsp;
28 28
                     总新粉数量:{{$total_data['fan_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
29
+                    新粉成单数:{{$total_data['new_order_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
30
+                    新粉收入:&yen;{{$total_data['new_order_amount']}}&nbsp;&nbsp;&nbsp;&nbsp;
31
+                    新粉ROI:{{$total_data['new_roi']}}&nbsp;&nbsp;&nbsp;&nbsp;
29 32
                     总成单数:{{$total_data['order_count']}}&nbsp;&nbsp;&nbsp;&nbsp;
30 33
                     总收入:&yen;{{$total_data['order_amount']}}&nbsp;&nbsp;&nbsp;&nbsp;
31 34
                     总计ROI:{{$total_data['roi']}}</li>