|
@@ -1274,6 +1274,19 @@ class StatisticsController extends Controller
|
1274
|
1274
|
public function orderRateList(Request $request){
|
1275
|
1275
|
$stime = $request->input('stime');
|
1276
|
1276
|
$etime = $request->input('etime');
|
|
1277
|
+
|
|
1278
|
+ $self_role = session('role_name');
|
|
1279
|
+ $team_id = $request->input('team_id');
|
|
1280
|
+ #只能看自己团队的
|
|
1281
|
+ if($self_role != '超级管理员' && $self_role != '售后管理员'){
|
|
1282
|
+ $self_id = session('admin_id');
|
|
1283
|
+ $team_id = DB::table('admin')->where('id', $self_id)->pluck('team_id');
|
|
1284
|
+ }
|
|
1285
|
+ if($team_id>0){
|
|
1286
|
+ $result = $this->orderTeamRateList($stime, $etime, $team_id);
|
|
1287
|
+ return view('statistics/orderRateList', $result);
|
|
1288
|
+ }
|
|
1289
|
+
|
1277
|
1290
|
$_day = 30;
|
1278
|
1291
|
if($stime == '' && $etime == ''){
|
1279
|
1292
|
$stime = date("Y-m-d", strtotime('-32 day'));
|
|
@@ -1336,9 +1349,91 @@ class StatisticsController extends Controller
|
1336
|
1349
|
$new_data[$k]['rate'][] = isset($v[$n]['rate']) ? $v[$n]['rate'].'%' : '';
|
1337
|
1350
|
}
|
1338
|
1351
|
}
|
|
1352
|
+
|
|
1353
|
+ $teamList = DB::table('teams')->select('id', 'name')->where(function($query) use($self_role, $team_id){
|
|
1354
|
+ if($team_id>0 && $self_role != '超级管理员' && $self_role != '售后管理员') $query->where('id', $team_id);
|
|
1355
|
+ })->get();
|
|
1356
|
+ $teamList = json_decode(json_encode($teamList), true);
|
1339
|
1357
|
//echo '<pre>';
|
1340
|
1358
|
//print_r($new_data);print_r($columns);exit;
|
1341
|
|
- return view('statistics/orderRateList', ['result' =>$new_data, 'columns'=>$columns, 'stime'=>$stime, 'etime'=>$etime]);
|
|
1359
|
+ return view('statistics/orderRateList', ['result' =>$new_data, 'columns'=>$columns, 'stime'=>$stime, 'etime'=>$etime, 'team_id'=>$team_id, 'teamlist'=>$teamList]);
|
|
1360
|
+
|
|
1361
|
+ }
|
|
1362
|
+
|
|
1363
|
+ /**
|
|
1364
|
+ * 团队成单率梯形图
|
|
1365
|
+ */
|
|
1366
|
+ public function orderTeamRateList($stime, $etime, $team_id){
|
|
1367
|
+ $_day = 30;
|
|
1368
|
+ if($stime == '' && $etime == ''){
|
|
1369
|
+ $stime = date("Y-m-d", strtotime('-32 day'));
|
|
1370
|
+ $etime = date("Y-m-d", strtotime('-2 day'));
|
|
1371
|
+ }else{
|
|
1372
|
+ if($stime){
|
|
1373
|
+ $_day = floor( (time() - strtotime($stime)) / 86400) - 2; //距昨天天数
|
|
1374
|
+ }
|
|
1375
|
+ }
|
|
1376
|
+ #统计天数
|
|
1377
|
+ $month = date('d')<=2 ? date('Y-m', strtotime('-1 month')) : date('Y-m'); //当前月
|
|
1378
|
+ $day_count = DB::table('team_cust_day_remain')->where('team_id', $team_id)->where('month_time', $month)->where(function($query) use($stime, $etime){
|
|
1379
|
+ if($stime) $query->where('idate','>=', $stime);
|
|
1380
|
+ if($etime) $query->where('idate','<=', $etime);
|
|
1381
|
+ })->count();
|
|
1382
|
+
|
|
1383
|
+ $result = DB::table('team_cust_day_remain')->where('team_id', $team_id)->where(function($query) use($stime, $etime){
|
|
1384
|
+ if($stime) $query->where('idate','>=', $stime);
|
|
1385
|
+ if($etime) $query->where('idate','<=', $etime);
|
|
1386
|
+ })->orderBy('idate', 'asc')->orderBy('month_time', 'asc')->get();
|
|
1387
|
+
|
|
1388
|
+ if($stime)
|
|
1389
|
+ #获取列
|
|
1390
|
+ $columns = array();
|
|
1391
|
+ $i_max = 31;
|
|
1392
|
+ for($i=0; $i<$i_max; $i++){
|
|
1393
|
+ $columns[] = $i;
|
|
1394
|
+ }
|
|
1395
|
+
|
|
1396
|
+ if($_day >= 45){
|
|
1397
|
+ $columns[] = 45;
|
|
1398
|
+ }
|
|
1399
|
+ if($_day >= 60){
|
|
1400
|
+ $columns[] = 60;
|
|
1401
|
+ }
|
|
1402
|
+ if($_day >= 75){
|
|
1403
|
+ $columns[] = 75;
|
|
1404
|
+ }
|
|
1405
|
+ if($_day >= 90){
|
|
1406
|
+ $columns[] = 90;
|
|
1407
|
+ }
|
|
1408
|
+
|
|
1409
|
+
|
|
1410
|
+ #数据整合
|
|
1411
|
+ $data = array();
|
|
1412
|
+ foreach($result as $k=>$v){
|
|
1413
|
+ $key = $v->idate;
|
|
1414
|
+ $rate_data = json_decode($v->order_rate_data, true);
|
|
1415
|
+ $data[$key] = isset($data[$key]) ? array_merge($data[$key], $rate_data) : $rate_data;
|
|
1416
|
+ }
|
|
1417
|
+
|
|
1418
|
+ #数据格式化
|
|
1419
|
+ $new_data = array();
|
|
1420
|
+ foreach($data as $k=>$v){
|
|
1421
|
+ //当日加粉数
|
|
1422
|
+ $fan_add = DB::table('cust_day_detail')->where('dtime', $k)->where('is_del',0)->sum('fan_add');
|
|
1423
|
+ $new_data[$k]['fan_add'] = $fan_add;
|
|
1424
|
+ foreach($columns as $val){
|
|
1425
|
+ $n = $val;
|
|
1426
|
+ $new_data[$k]['rate'][] = isset($v[$n]['rate']) ? $v[$n]['rate'].'%' : '';
|
|
1427
|
+ }
|
|
1428
|
+ }
|
|
1429
|
+ //echo '<pre>';
|
|
1430
|
+ //print_r($new_data);print_r($columns);exit;
|
|
1431
|
+ $self_role = session('role_name');
|
|
1432
|
+ $teamList = DB::table('teams')->select('id', 'name')->where(function($query) use($self_role, $team_id){
|
|
1433
|
+ if($self_role != '超级管理员' && $self_role != '售后管理员') $query->where('id', $team_id);
|
|
1434
|
+ })->get();
|
|
1435
|
+ $teamList = json_decode(json_encode($teamList), true);
|
|
1436
|
+ return ['result' =>$new_data, 'columns'=>$columns, 'stime'=>$stime, 'etime'=>$etime, 'team_id'=>$team_id, 'teamlist'=>$teamList];
|
1342
|
1437
|
|
1343
|
1438
|
}
|
1344
|
1439
|
|