|
@@ -590,6 +590,31 @@ class StatisticsController extends Controller
|
590
|
590
|
})->first();
|
591
|
591
|
$v['order_count'] = $order->order_count;
|
592
|
592
|
$v['order_amount'] = $order->order_amount;
|
|
593
|
+
|
|
594
|
+ //当日加粉
|
|
595
|
+ $phones = DB::table('customers')->where('fanTime', $v['dtime'])->lists('phone');
|
|
596
|
+ #当日加粉订单总计:
|
|
597
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost, sum(freight_cost) as freight_cost'))->whereIn('receiverMobile', $phones)->where('is_del', 0)->where(function($query) use($team_id){
|
|
598
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
599
|
+ })->first();
|
|
600
|
+ #当日新粉成单:
|
|
601
|
+ $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where(function($query) use($team_id){
|
|
602
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
603
|
+ })->first();
|
|
604
|
+ // 1.当日新粉成单数
|
|
605
|
+ $v['new_order_count'] = $new_order->order_count;
|
|
606
|
+ // 2.当日新粉成交额
|
|
607
|
+ $v['new_order_amount'] = $new_order->order_amount;
|
|
608
|
+ // 1.当日粉累计成单数
|
|
609
|
+ $v['order_count'] = $order->order_count;
|
|
610
|
+ // 2.当日粉累计成交额
|
|
611
|
+ $v['order_amount'] = $order->order_amount;
|
|
612
|
+ #当日新粉roi=当日新增粉丝成交销售额/当日投放消耗额*100%
|
|
613
|
+ $v['new_roi'] = $v['total_cost']>0? round($v['new_order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
|
|
614
|
+ # 综合ROI=当日加粉累计成交额/当日投放消耗额*100%
|
|
615
|
+ $v['roi'] = $v['total_cost']>0? round($v['order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
|
|
616
|
+ # 导粉率=当日个人微信号粉丝数/当日公众号粉丝数*100%
|
|
617
|
+ $v['fan_rate'] = $v['total_fan_add']>0? round($v['wx_fan_add'] / $v['total_fan_add'], 4) * 100 .'%' : '';
|
593
|
618
|
|
594
|
619
|
}
|
595
|
620
|
|
|
@@ -625,80 +650,62 @@ class StatisticsController extends Controller
|
625
|
650
|
if($etime) $query->where('dtime', '<=', $etime);
|
626
|
651
|
})->where('is_del',0)->groupBy('dtime')->orderBy('dtime', 'desc')->get();
|
627
|
652
|
$result = json_decode(json_encode($result),true);
|
628
|
|
-
|
629
|
|
- $filename="当日数据统计.xls";
|
630
|
|
- header("Content-type:application/vnd.ms-excel");
|
631
|
|
- Header("Accept-Ranges:bytes");
|
632
|
|
- Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名
|
633
|
|
- header("Pragma: no-cache");
|
634
|
|
- header("Expires: 0");
|
635
|
|
- $data_str = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
636
|
|
- xmlns:x="urn:schemas-microsoft-com:office:excel"
|
637
|
|
- xmlns="http://www.w3.org/TR/REC-html40">
|
638
|
|
- <head>
|
639
|
|
- <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
|
640
|
|
- <meta http-equiv=Content-Type content="text/html; charset=gb2312">
|
641
|
|
- <!--[if gte mso 9]><xml>
|
642
|
|
- <x:ExcelWorkbook>
|
643
|
|
- <x:ExcelWorksheets>
|
644
|
|
- <x:ExcelWorksheet>
|
645
|
|
- <x:Name></x:Name>
|
646
|
|
- <x:WorksheetOptions>
|
647
|
|
- <x:DisplayGridlines/>
|
648
|
|
- </x:WorksheetOptions>
|
649
|
|
- </x:ExcelWorksheet>
|
650
|
|
- </x:ExcelWorksheets>
|
651
|
|
- </x:ExcelWorkbook>
|
652
|
|
- </xml><![endif]-->
|
653
|
|
- </head>';
|
654
|
|
- $data_str .= "
|
655
|
|
- <table>
|
656
|
|
- <tr>
|
657
|
|
- <th>".iconv("UTF-8", "GB2312//IGNORE","日期")."</th>
|
658
|
|
- <th>".iconv("UTF-8", "GB2312//IGNORE","当日投放金额")."</th>
|
659
|
|
- <th>".iconv("UTF-8", "GB2312//IGNORE","当日公众号进粉")."</th>
|
660
|
|
- <th>".iconv("UTF-8", "GB2312//IGNORE","当日进粉成本")."</th>
|
661
|
|
- <th>".iconv("UTF-8", "GB2312//IGNORE","当日微信粉")."</th>
|
662
|
|
- <th>".iconv("UTF-8", "GB2312//IGNORE","当日微信粉成本")."</th>
|
663
|
|
-
|
664
|
|
- </tr>";
|
665
|
|
- foreach ($result as $k => $v)
|
666
|
|
- {
|
667
|
|
- #进粉成本
|
668
|
|
- $v['cost_fan'] = $v['total_fan_add']>0 ? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
|
669
|
|
- #当日微信粉
|
670
|
|
- $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add, sum(new_reply) as total_new_reply, sum(old_consult) as total_old_consult'))->where('dtime', $v['dtime'])->where('is_del', 0)->where(function($query) use ($team_id, $sale_ids){
|
|
653
|
+ foreach($result as $k=>&$v){
|
|
654
|
+ #进粉成本
|
|
655
|
+ $v['cost_fan'] = $v['total_fan_add']>0? round($v['total_cost'] / $v['total_fan_add'], 2) : '';
|
|
656
|
+ #当日微信粉
|
|
657
|
+ $custDetail = CustDetail::select(DB::raw('sum(fan_add) as wx_fan_add, sum(new_reply) as total_new_reply, sum(old_consult) as total_old_consult'))->where('dtime', $v['dtime'])->where('is_del', 0)->where(function($query) use ($team_id, $sale_ids){
|
671
|
658
|
if($team_id>0 && isset($sale_ids)) $query->whereIn('admin_id', $sale_ids);
|
672
|
659
|
})->first();
|
673
|
|
- $v['wx_fan_add'] = $custDetail->wx_fan_add; //当日微信粉数
|
674
|
|
- $v['total_new_reply'] = $custDetail->total_new_reply; //当日微信新粉回复
|
675
|
|
- $v['total_old_consult'] = $custDetail->total_old_consult; //当日微信老粉询价
|
676
|
|
- $v['new_reply_rate'] = $v['wx_fan_add']>0 ? round($v['total_new_reply'] / $v['wx_fan_add'], 4) * 100 .'%' : ''; //当日新粉回复率
|
|
660
|
+ $v['wx_fan_add'] = $custDetail->wx_fan_add; //当日微信粉数
|
|
661
|
+ $v['total_new_reply'] = $custDetail->total_new_reply; //当日微信新粉回复
|
|
662
|
+ $v['total_old_consult'] = $custDetail->total_old_consult; //当日微信老粉询价
|
|
663
|
+ $v['new_reply_rate'] = $v['wx_fan_add']>0? round($v['total_new_reply'] / $v['wx_fan_add'], 4) * 100 .'%' : ''; //当日新粉回复率
|
677
|
664
|
|
678
|
|
- #当日微信粉成本
|
679
|
|
- $v['cost_wx_fan'] = $v['wx_fan_add']>0 ? round($v['total_cost'] / $v['wx_fan_add'], 2) : '';
|
680
|
|
- #当日订单数、销售额
|
681
|
|
- $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
|
|
665
|
+ #当日微信粉成本
|
|
666
|
+ $v['cost_wx_fan'] = $v['wx_fan_add']>0? round($v['total_cost'] / $v['wx_fan_add'], 2) : '';
|
|
667
|
+ #当日订单数、销售额
|
|
668
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->where(function($query) use($team_id){
|
682
|
669
|
if($team_id>0) $query->where('team_id', $team_id);
|
683
|
670
|
})->first();
|
684
|
|
- $v['order_count'] = $order->order_count;
|
685
|
|
- $v['order_amount'] = $order->order_amount;
|
|
671
|
+ $v['order_count'] = $order->order_count;
|
|
672
|
+ $v['order_amount'] = $order->order_amount;
|
686
|
673
|
|
687
|
|
- $data_str .= "<tr>";
|
688
|
|
- $data_str .= "<td>".$v['dtime']."</td>";
|
689
|
|
- $data_str .= "<td>".$v['total_cost']."</td>";
|
690
|
|
- $data_str .= "<td>".$v['total_fan_add']."</td>";
|
691
|
|
- $data_str .= "<td>".$v['cost_fan']."</td>";
|
692
|
|
- $data_str .= "<td>".$v['wx_fan_add']."</td>";
|
693
|
|
- $data_str .= "<td>".$v['cost_wx_fan']."</td>";
|
694
|
|
- $data_str .= "</tr>";
|
695
|
|
- }
|
|
674
|
+ //当日加粉
|
|
675
|
+ $phones = DB::table('customers')->where('fanTime', $v['dtime'])->lists('phone');
|
|
676
|
+ #当日加粉订单总计:
|
|
677
|
+ $order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count, sum(cost) as order_cost, sum(freight_cost) as freight_cost'))->whereIn('receiverMobile', $phones)->where('is_del', 0)->where(function($query) use($team_id){
|
|
678
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
679
|
+ })->first();
|
|
680
|
+ #当日新粉成单:
|
|
681
|
+ $new_order = DB::table('order')->select(DB::raw('sum(receivedAmount) as order_amount, count(1) as order_count'))->where('createTime','>=', $v['dtime'])->where('createTime','<', $v['dtime'].' 23:59:59')->where('is_del', 0)->whereIn('receiverMobile', $phones)->where(function($query) use($team_id){
|
|
682
|
+ if($team_id>0) $query->where('team_id', $team_id);
|
|
683
|
+ })->first();
|
|
684
|
+ // 1.当日新粉成单数
|
|
685
|
+ $v['new_order_count'] = $new_order->order_count;
|
|
686
|
+ // 2.当日新粉成交额
|
|
687
|
+ $v['new_order_amount'] = $new_order->order_amount;
|
|
688
|
+ // 1.当日粉累计成单数
|
|
689
|
+ $v['order_count'] = $order->order_count;
|
|
690
|
+ // 2.当日粉累计成交额
|
|
691
|
+ $v['order_amount'] = $order->order_amount;
|
|
692
|
+ #当日新粉roi=当日新增粉丝成交销售额/当日投放消耗额*100%
|
|
693
|
+ $v['new_roi'] = $v['total_cost']>0? round($v['new_order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
|
|
694
|
+ # 综合ROI=当日加粉累计成交额/当日投放消耗额*100%
|
|
695
|
+ $v['roi'] = $v['total_cost']>0? round($v['order_amount'] / $v['total_cost'], 4) * 100 .'%' : '';
|
|
696
|
+ # 导粉率=当日个人微信号粉丝数/当日公众号粉丝数*100%
|
|
697
|
+ $v['fan_rate'] = $v['total_fan_add']>0? round($v['wx_fan_add'] / $v['total_fan_add'], 4) * 100 .'%' : '';
|
|
698
|
+
|
|
699
|
+ }
|
696
|
700
|
|
697
|
|
- $data_str .= "</table>";
|
698
|
|
- echo $data_str;
|
699
|
|
- exit;
|
|
701
|
+ $indexKey = ['dtime','total_cost','total_fan_add','cost_fan','wx_fan_add','cost_wx_fan','new_roi','roi','fan_rate'];
|
|
702
|
+ $title = ['日期', '当日投放金额', '当日公众号进粉', '当日进粉成本', '当日微信粉','当日微信粉成本', '当日新粉ROI', '综合ROI', '导粉率'];
|
|
703
|
+
|
|
704
|
+ $filename = 'toufang_'.date('Y-m-d_H').'.xlsx';
|
|
705
|
+ return Order::export_excel($result, $filename, $indexKey, $title);
|
|
706
|
+
|
700
|
707
|
}
|
701
|
|
-
|
|
708
|
+
|
702
|
709
|
/**
|
703
|
710
|
* 销售可看当日数据表
|
704
|
711
|
*
|