|
@@ -13,6 +13,7 @@ use App\CustTotal;
|
13
|
13
|
use App\CustDetail;
|
14
|
14
|
use App\AdCost;
|
15
|
15
|
use App\Order;
|
|
16
|
+use App\DistrictRoi7;
|
16
|
17
|
use Illuminate\Http\Request;
|
17
|
18
|
use Illuminate\Support\Facades\DB;
|
18
|
19
|
|
|
@@ -1838,6 +1839,11 @@ class StatisticsController extends Controller
|
1838
|
1839
|
* 地区汇总roi
|
1839
|
1840
|
*/
|
1840
|
1841
|
public function districtTotalRoi(Request $request){
|
|
1842
|
+ $page = (int)$request->input('page');
|
|
1843
|
+ $pageSize = 20;
|
|
1844
|
+ if($page<=0){
|
|
1845
|
+ $page = 1;
|
|
1846
|
+ }
|
1841
|
1847
|
|
1842
|
1848
|
$offset = ($page-1) * $pageSize;
|
1843
|
1849
|
$city = $request->input('city');
|
|
@@ -1850,8 +1856,14 @@ class StatisticsController extends Controller
|
1850
|
1856
|
if($city) $query->where('city', 'like', '%'.$city.'%');
|
1851
|
1857
|
})->groupBy('city')->get();
|
1852
|
1858
|
$ret = json_decode(json_encode($ret), true);
|
1853
|
|
-
|
1854
|
1859
|
$count = count($ret);
|
|
1860
|
+ if ($count > 1) {
|
|
1861
|
+ // 总页数
|
|
1862
|
+ $pages = ceil($count/$pageSize);
|
|
1863
|
+ }else{
|
|
1864
|
+ // 总页数
|
|
1865
|
+ $pages = 1;
|
|
1866
|
+ }
|
1855
|
1867
|
|
1856
|
1868
|
$result = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times, city'))->where(function($query) use($city){
|
1857
|
1869
|
if($city) $query->where('city', 'like', '%'.$city.'%');
|
|
@@ -1893,7 +1905,98 @@ class StatisticsController extends Controller
|
1893
|
1905
|
]);
|
1894
|
1906
|
|
1895
|
1907
|
}
|
1896
|
|
-}
|
1897
|
1908
|
|
|
1909
|
+ /**
|
|
1910
|
+ * 地域roi7日
|
|
1911
|
+ */
|
|
1912
|
+ public function districtRoi7day(Request $request){
|
|
1913
|
+ $page = (int)$request->input('page');
|
|
1914
|
+ $pageSize = 20;
|
|
1915
|
+ if($page<=0){
|
|
1916
|
+ $page = 1;
|
|
1917
|
+ }
|
|
1918
|
+
|
|
1919
|
+ $offset = ($page-1) * $pageSize;
|
|
1920
|
+ $stime = $request->input('stime');
|
|
1921
|
+ $etime = $request->input('etime');
|
|
1922
|
+ $city = $request->input('city');
|
|
1923
|
+
|
|
1924
|
+ if($city !== null){
|
|
1925
|
+ $city = str_replace('市', '', $city);
|
|
1926
|
+ }
|
|
1927
|
+
|
|
1928
|
+ $count = DistrictRoi7::where(function($query) use($stime, $etime, $city){
|
|
1929
|
+ if($stime) $query->where('ad_time', '>=', $stime);
|
|
1930
|
+ if($etime) $query->where('ad_time', '<=', $etime);
|
|
1931
|
+ if($city) $query->where('city', 'like', '%'.$city.'%');
|
|
1932
|
+ })->count();
|
|
1933
|
+
|
|
1934
|
+ if ($count > 1) {
|
|
1935
|
+ // 总页数
|
|
1936
|
+ $pages = ceil($count/$pageSize);
|
|
1937
|
+ }else{
|
|
1938
|
+ // 总页数
|
|
1939
|
+ $pages = 1;
|
|
1940
|
+ }
|
|
1941
|
+
|
|
1942
|
+ $result = DistrictRoi7::where(function($query) use($stime, $etime, $city){
|
|
1943
|
+ if($stime) $query->where('ad_time', '>=', $stime);
|
|
1944
|
+ if($etime) $query->where('ad_time', '<=', $etime);
|
|
1945
|
+ if($city) $query->where('city', 'like', '%'.$city.'%');
|
|
1946
|
+ })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
1947
|
+
|
|
1948
|
+ $result = json_decode(json_encode($result), true);
|
|
1949
|
+ foreach($result as $k=>&$v){
|
|
1950
|
+ //新粉roi
|
|
1951
|
+ $v['new_roi'] = $v['cost']>0 ? round($v['new_fan_order_amount'] / $v['cost'], 4) * 100 .'%' : '';
|
|
1952
|
+ //累计roi
|
|
1953
|
+ $v['total_roi'] = $v['cost']>0 ? round($v['order_amount'] / $v['cost'], 4) * 100 .'%' : '';
|
|
1954
|
+ }
|
|
1955
|
+
|
|
1956
|
+ return view('statistics/districtRoi7day', ['result' =>$result,
|
|
1957
|
+ 'page' =>$page,
|
|
1958
|
+ 'count' =>$count,
|
|
1959
|
+ 'pages' =>$pages,
|
|
1960
|
+ 'city' =>$city,
|
|
1961
|
+ 'stime' =>$stime,
|
|
1962
|
+ 'etime' =>$etime,
|
|
1963
|
+ ]);
|
|
1964
|
+
|
|
1965
|
+ }
|
|
1966
|
+
|
|
1967
|
+ /**
|
|
1968
|
+ * 地域roi7日
|
|
1969
|
+ */
|
|
1970
|
+ public function districtRoi7day_export(Request $request){
|
|
1971
|
+
|
|
1972
|
+ $stime = $request->input('stime');
|
|
1973
|
+ $etime = $request->input('etime');
|
|
1974
|
+ $city = $request->input('city');
|
|
1975
|
+
|
|
1976
|
+ if($city !== null){
|
|
1977
|
+ $city = str_replace('市', '', $city);
|
|
1978
|
+ }
|
|
1979
|
+
|
|
1980
|
+ $result = DistrictRoi7::where(function($query) use($stime, $etime, $city){
|
|
1981
|
+ if($stime) $query->where('ad_time', '>=', $stime);
|
|
1982
|
+ if($etime) $query->where('ad_time', '<=', $etime);
|
|
1983
|
+ if($city) $query->where('city', 'like', '%'.$city.'%');
|
|
1984
|
+ })->orderBy('id', 'desc')->get();
|
|
1985
|
+
|
|
1986
|
+ $result = json_decode(json_encode($result), true);
|
|
1987
|
+ foreach($result as $k=>&$v){
|
|
1988
|
+ //新粉roi
|
|
1989
|
+ $v['new_roi'] = $v['cost']>0 ? round($v['new_fan_order_amount'] / $v['cost'], 4) * 100 .'%' : '';
|
|
1990
|
+ //累计roi
|
|
1991
|
+ $v['total_roi'] = $v['cost']>0 ? round($v['order_amount'] / $v['cost'], 4) * 100 .'%' : '';
|
|
1992
|
+ }
|
|
1993
|
+
|
|
1994
|
+ $indexKey = ['ad_time','city','cost','gzh_count','fan_count','new_fan_order_count','new_fan_order_amount','new_roi','order_count','order_amount','total_roi'];
|
|
1995
|
+ $title = ['日期', '城市', '投放成本', '加粉数', '新粉数量', '新粉成单数', '新粉收入', '新粉ROI', '7日累计成单数', '7日累计收入', '7日累计ROI'];
|
|
1996
|
+ $filename = 'districtRoi7day_'.date('Y-m-d_H').'.xlsx';
|
|
1997
|
+ return Order::export_excel($result, $filename, $indexKey, $title);
|
|
1998
|
+ }
|
|
1999
|
+}
|
|
2000
|
+
|
1898
|
2001
|
|
1899
|
2002
|
|