|
@@ -4956,6 +4956,111 @@ class StatisticsController extends Controller
|
4956
|
4956
|
}
|
4957
|
4957
|
return '';
|
4958
|
4958
|
}
|
|
4959
|
+
|
|
4960
|
+ /**
|
|
4961
|
+ * 分团队每日roi汇总数据
|
|
4962
|
+ */
|
|
4963
|
+ public function dayGrandSalerTotal(Request $request){
|
|
4964
|
+ $team_id = (int)$request->input('team_id');
|
|
4965
|
+ $admin_id = (int)$request->input('admin_id');
|
|
4966
|
+ $stime = $request->input('stime');
|
|
4967
|
+ $etime = $request->input('etime');
|
|
4968
|
+ $page = (int)$request->input('page');
|
|
4969
|
+ $pageSize = 20;
|
|
4970
|
+ if($page<=0){
|
|
4971
|
+ $page = 1;
|
|
4972
|
+ }
|
|
4973
|
+
|
|
4974
|
+ $offset = ($page-1) * $pageSize;
|
|
4975
|
+
|
|
4976
|
+ //查询历史数据
|
|
4977
|
+ $count = DB::table('day_grand_saler_total')->where(function($query) use($team_id, $stime, $etime, $admin_id){
|
|
4978
|
+ if($team_id) $query->where('team_id', $team_id);
|
|
4979
|
+ if($admin_id) $query->where('admin_id', $admin_id);
|
|
4980
|
+ if($stime) $query->where('idate', '>=', $stime);
|
|
4981
|
+ if($etime) $query->where('idate', '<=', $etime);
|
|
4982
|
+ })->count();
|
|
4983
|
+ $teamArr = DB::table('teams')->lists('name', 'id');
|
|
4984
|
+ $adminArr = DB::table('admin')->lists('realname', 'id');
|
|
4985
|
+ $result = DB::table('day_grand_saler_total')->where(function($query) use($team_id, $stime, $etime, $admin_id){
|
|
4986
|
+ if($team_id) $query->where('team_id', $team_id);
|
|
4987
|
+ if($admin_id) $query->where('admin_id', $admin_id);
|
|
4988
|
+ if($stime) $query->where('idate', '>=', $stime);
|
|
4989
|
+ if($etime) $query->where('idate', '<=', $etime);
|
|
4990
|
+ })->orderBy('idate', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
4991
|
+ $result = json_decode(json_encode($result), true);
|
|
4992
|
+ foreach($result as $k=>&$v){
|
|
4993
|
+ $v['roi'] = $v['throw_cost']>0 ? round($v['order_amount'] / $v['throw_cost'], 4) * 100 .'%' : '';
|
|
4994
|
+ $v['fugou_rate'] = $v['cust_count']>0 ? round($v['fugou_order_count'] / $v['cust_count'], 4) : '';
|
|
4995
|
+ $v['roi7'] = $v['cost7']>0? round($v['order_amount7'] / $v['cost7'], 4) * 100 .'%' : '';
|
|
4996
|
+ $v['roi15'] = $v['cost15']>0? round($v['order_amount15'] / $v['cost15'], 4) * 100 .'%' : '';
|
|
4997
|
+ $v['roi30'] = $v['cost30']>0? round($v['order_amount30'] / $v['cost30'], 4) * 100 .'%' : '';
|
|
4998
|
+ $v['roi45'] = $v['cost45']>0? round($v['order_amount45'] / $v['cost45'], 4) * 100 .'%' : '';
|
|
4999
|
+ $v['roi60'] = $v['cost60']>0? round($v['order_amount60'] / $v['cost60'], 4) * 100 .'%' : '';
|
|
5000
|
+ $v['team_name'] = $teamArr[$v['team_id']];
|
|
5001
|
+ $v['admin_name'] = $adminArr[$v['admin_id']];
|
|
5002
|
+ }
|
|
5003
|
+
|
|
5004
|
+ if ($count > 1) {
|
|
5005
|
+ // 总页数
|
|
5006
|
+ $pages = ceil($count/20);
|
|
5007
|
+ }else{
|
|
5008
|
+ // 总页数
|
|
5009
|
+ $pages = 1;
|
|
5010
|
+ }
|
|
5011
|
+
|
|
5012
|
+ $teamList = DB::table('teams')->select('id', 'name')->get();
|
|
5013
|
+ $teamList = json_decode(json_encode($teamList), true);
|
|
5014
|
+ $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
|
|
5015
|
+ $adminList = json_decode(json_encode($adminList), true);
|
|
5016
|
+ return view('statistics/dayGrandSalerTotal', ['result' =>$result,
|
|
5017
|
+ 'page' =>$page,
|
|
5018
|
+ 'count' =>$count,
|
|
5019
|
+ 'pages' =>$pages,
|
|
5020
|
+ 'teamlist' =>$teamList,
|
|
5021
|
+ 'adminlist' =>$adminList,
|
|
5022
|
+ 'team_id' =>$team_id,
|
|
5023
|
+ 'admin_id' =>$admin_id,
|
|
5024
|
+ 'stime' =>$stime,
|
|
5025
|
+ 'etime' =>$etime,
|
|
5026
|
+ ]);
|
|
5027
|
+ }
|
|
5028
|
+
|
|
5029
|
+ /**
|
|
5030
|
+ * 每日累计汇总数据导出
|
|
5031
|
+ */
|
|
5032
|
+ public function dayGrandSalerTotal_export(Request $request){
|
|
5033
|
+ $team_id = (int)$request->input('team_id');
|
|
5034
|
+ $admin_id = (int)$request->input('admin_id');
|
|
5035
|
+ $stime = $request->input('stime');
|
|
5036
|
+ $etime = $request->input('etime');
|
|
5037
|
+
|
|
5038
|
+ $teamArr = DB::table('teams')->lists('name', 'id');
|
|
5039
|
+ $adminArr = DB::table('admin')->lists('realname', 'id');
|
|
5040
|
+ $result = DB::table('day_grand_saler_total')->where(function($query) use($team_id, $stime, $etime, $admin_id){
|
|
5041
|
+ if($team_id) $query->where('team_id', $team_id);
|
|
5042
|
+ if($admin_id) $query->where('admin_id', $admin_id);
|
|
5043
|
+ if($stime) $query->where('idate', '>=', $stime);
|
|
5044
|
+ if($etime) $query->where('idate', '<=', $etime);
|
|
5045
|
+ })->orderBy('idate', 'desc')->get();
|
|
5046
|
+ $result = json_decode(json_encode($result), true);
|
|
5047
|
+ foreach($result as $k=>&$v){
|
|
5048
|
+ $v['roi'] = $v['throw_cost']>0 ? round($v['order_amount'] / $v['throw_cost'], 4) * 100 .'%' : '';
|
|
5049
|
+ $v['fugou_rate'] = $v['cust_count']>0 ? round($v['fugou_order_count'] / $v['cust_count'], 4) : '';
|
|
5050
|
+ $v['roi7'] = $v['cost7']>0? round($v['order_amount7'] / $v['cost7'], 4) * 100 .'%' : '';
|
|
5051
|
+ $v['roi15'] = $v['cost15']>0? round($v['order_amount15'] / $v['cost15'], 4) * 100 .'%' : '';
|
|
5052
|
+ $v['roi30'] = $v['cost30']>0? round($v['order_amount30'] / $v['cost30'], 4) * 100 .'%' : '';
|
|
5053
|
+ $v['roi45'] = $v['cost45']>0? round($v['order_amount45'] / $v['cost45'], 4) * 100 .'%' : '';
|
|
5054
|
+ $v['roi60'] = $v['cost60']>0? round($v['order_amount60'] / $v['cost60'], 4) * 100 .'%' : '';
|
|
5055
|
+ $v['team_name'] = $teamArr[$v['team_id']];
|
|
5056
|
+ $v['admin_name'] = $adminArr[$v['admin_id']];
|
|
5057
|
+ }
|
|
5058
|
+
|
|
5059
|
+ $indexKey = ['idate','admin_name','team_name','throw_cost','cust_count','order_count','order_amount','goods_cost', 'freight_cost', 'aftersale_cost', 'refund_fee', 'profit', 'roi', 'fan_count', 'new_order_count', 'old_order_count', 'fugou_order_count', 'fugou_rate', 'roi7', 'roi15', 'roi30', 'roi45', 'roi60'];
|
|
5060
|
+ $title = ['汇总日期','销售', '所属团队', '总投放', '总客户数', '总下单数', '总销售额', '总货品成本', '总运费成本', '总售后', '总退补', '总毛利', '累计ROI', '总加粉数', '总新粉单数', '总老粉单数', '总复购单数', '总复购率', '累计7日roi', '累计15日roi', '累计30日roi', '累计45日roi', '累计60日roi'];
|
|
5061
|
+ $filename = 'salerRoi_'.date('Y-m-d_H').'.xlsx';
|
|
5062
|
+ return Order::export_excel($result, $filename, $indexKey, $title);
|
|
5063
|
+ }
|
4959
|
5064
|
|
4960
|
5065
|
}
|
4961
|
5066
|
|