|
@@ -1494,13 +1494,14 @@ class StatisticsController extends Controller
|
1494
|
1494
|
$pages = 1;
|
1495
|
1495
|
}
|
1496
|
1496
|
|
1497
|
|
- $result = AdCost::select(DB::raw('sum(cost) as total_cost, city, ad_time'))->where(function($query) use($stime, $etime, $city){
|
|
1497
|
+ $result = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times, city, ad_time'))->where(function($query) use($stime, $etime, $city){
|
1498
|
1498
|
if($stime) $query->where('ad_time', '>=', $stime);
|
1499
|
1499
|
if($etime) $query->where('ad_time', '<=', $etime);
|
1500
|
1500
|
if($city) $query->where('city', 'like', '%'.$city.'%');
|
1501
|
1501
|
})->groupBy('ad_time')->groupBy('city')->orderBy('ad_time', 'desc')->offset($offset)->limit($pageSize)->get();
|
1502
|
1502
|
|
1503
|
1503
|
$result = json_decode(json_encode($result), true);
|
|
1504
|
+
|
1504
|
1505
|
foreach($result as $k=>&$v){
|
1505
|
1506
|
//新粉收入
|
1506
|
1507
|
//当日加粉
|
|
@@ -1523,8 +1524,40 @@ class StatisticsController extends Controller
|
1523
|
1524
|
//累计roi
|
1524
|
1525
|
$v['total_roi'] = $v['total_cost']>0 ? round($v['order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
|
1525
|
1526
|
$v['new_fan_count'] = count($phones);
|
|
1527
|
+
|
1526
|
1528
|
}
|
1527
|
1529
|
|
|
1530
|
+ //总计
|
|
1531
|
+ $total_data = [
|
|
1532
|
+ 'cost' => 0,
|
|
1533
|
+ 'fan_count' => 0,
|
|
1534
|
+ 'order_count' => 0,
|
|
1535
|
+ 'order_amount' => 0,
|
|
1536
|
+ 'roi' => 0,
|
|
1537
|
+ 'conversion_times' => 0,
|
|
1538
|
+ ];
|
|
1539
|
+
|
|
1540
|
+ //投入
|
|
1541
|
+ $adcost = AdCost::select(DB::raw('sum(cost) as total_cost, sum(conversion_times) as conversion_times'))->where(function($query) use($stime, $etime, $city){
|
|
1542
|
+ if($stime) $query->where('ad_time', '>=', $stime);
|
|
1543
|
+ if($etime) $query->where('ad_time', '<=', $etime);
|
|
1544
|
+ if($city) $query->where('city', 'like', '%'.$city.'%');
|
|
1545
|
+ })->first();
|
|
1546
|
+ $total_data['cost'] = $adcost->total_cost;
|
|
1547
|
+ $total_data['conversion_times'] = $adcost->conversion_times;
|
|
1548
|
+ //总新粉
|
|
1549
|
+ $phones = DB::table('customers')->where('fanTime','>=', '2019-09-01')->where(function($query) use($stime, $etime, $city){
|
|
1550
|
+ if($stime) $query->where('fanTime', '>=', $stime);
|
|
1551
|
+ if($etime) $query->where('fanTime', '<=', $etime);
|
|
1552
|
+ if($city) $query->where('receiverCity', 'like', '%'.$city.'%');
|
|
1553
|
+ })->lists('phone');
|
|
1554
|
+ $total_data['fan_count'] = !empty($phones) ? count($phones) : 0;
|
|
1555
|
+ //总收入
|
|
1556
|
+ $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();
|
|
1557
|
+ $total_data['order_count'] = $order->order_count;
|
|
1558
|
+ $total_data['order_amount'] = $order->order_amount;
|
|
1559
|
+ $total_data['roi'] = $total_data['cost']>0 ? round($total_data['order_amount'] / $total_data['cost'], 4) * 100 .'%' : '';
|
|
1560
|
+
|
1528
|
1561
|
return view('statistics/districtRoi', ['result' =>$result,
|
1529
|
1562
|
'page' =>$page,
|
1530
|
1563
|
'count' =>$count,
|
|
@@ -1532,6 +1565,7 @@ class StatisticsController extends Controller
|
1532
|
1565
|
'stime' =>$stime,
|
1533
|
1566
|
'etime' =>$etime,
|
1534
|
1567
|
'city' =>$city,
|
|
1568
|
+ 'total_data' =>$total_data,
|
1535
|
1569
|
]);
|
1536
|
1570
|
}
|
1537
|
1571
|
}
|