|
@@ -19,6 +19,7 @@ use App\DistrictRoi15;
|
19
|
19
|
use App\DistrictRoi45;
|
20
|
20
|
use App\DistrictRoi60;
|
21
|
21
|
use App\SalerTargets;
|
|
22
|
+use App\TemplatesLog;
|
22
|
23
|
use App\RedisModel as Redis;
|
23
|
24
|
use Illuminate\Http\Request;
|
24
|
25
|
use Illuminate\Support\Facades\DB;
|
|
@@ -4330,9 +4331,157 @@ class StatisticsController extends Controller
|
4330
|
4331
|
$filename = 'districtRoiAll_'.date('Y-m-d_H').'.xlsx';
|
4331
|
4332
|
return Order::export_excel($result, $filename, $indexKey, $title);
|
4332
|
4333
|
}
|
|
4334
|
+
|
|
4335
|
+ /**
|
|
4336
|
+ * 销售粉丝复购率
|
|
4337
|
+ */
|
|
4338
|
+ public function salerOrderFugou(Request $request){
|
|
4339
|
+ //获取销售
|
|
4340
|
+ $saler_id = (int)$request->input('admin_id');
|
|
4341
|
+ $team_id = (int)$request->input('team_id');
|
|
4342
|
+
|
|
4343
|
+ //假如有团队筛选,检索销售队员
|
|
4344
|
+ $saler_ids = null;
|
|
4345
|
+ if($saler_id>0){
|
|
4346
|
+ $saler_ids = [$saler_id];
|
|
4347
|
+ }elseif($team_id>0){
|
|
4348
|
+ $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
4349
|
+ }else{
|
|
4350
|
+ $saler_ids = DB::table('admin')->whereIn('team_id', [1,3,5])->lists('id');
|
|
4351
|
+ }
|
|
4352
|
+
|
|
4353
|
+ $page = (int)$request->input('page');
|
|
4354
|
+ $pageSize = 20;
|
|
4355
|
+ if($page<=0){
|
|
4356
|
+ $page = 1;
|
|
4357
|
+ }
|
|
4358
|
+
|
|
4359
|
+ $offset = ($page-1) * $pageSize;
|
|
4360
|
+ $count = count($saler_ids);
|
|
4361
|
+ $saler_ids = array_slice($saler_ids, $offset, $pageSize);
|
|
4362
|
+
|
|
4363
|
+ $result = array();
|
|
4364
|
+ foreach($saler_ids as $k=>$admin_id){
|
|
4365
|
+ $result[$k]['admin_id'] = $admin_id;
|
|
4366
|
+ //pv
|
|
4367
|
+ $temp = TemplatesLog::select(DB::raw('count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('admin_id',$admin_id)->first();
|
|
4368
|
+ $result[$k]['tcount'] = $temp->tcount;
|
|
4369
|
+ $result[$k]['pv_count'] = $temp->pv_count;
|
|
4370
|
+ //加粉
|
|
4371
|
+ $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add, admin_name'))->where('admin_id', $admin_id)->where('is_del', 0)->first();
|
|
4372
|
+ if(!empty($custDetail)){
|
|
4373
|
+ $result[$k]['fan_add'] = $custDetail->fan_add;
|
|
4374
|
+ $result[$k]['admin_name'] = $custDetail->admin_name;
|
|
4375
|
+ }else{
|
|
4376
|
+ $result[$k]['fan_add'] = '';
|
|
4377
|
+ $result[$k]['admin_name'] = DB::table('admin')->where('id', $admin_id)->pluck('realname');
|
|
4378
|
+ }
|
|
4379
|
+ $result[$k]['long_count'] = $result[$k]['tcount'] - $result[$k]['pv_count'];
|
|
4380
|
+
|
|
4381
|
+ //点击率
|
|
4382
|
+ $result[$k]['click_rate'] = $result[$k]['pv_count']>0 && $result[$k]['long_count']>0 ? round( $result[$k]['long_count'] / $result[$k]['pv_count'], 4 ) * 100 . '%' : '';
|
|
4383
|
+ $result[$k]['change_rate'] = $result[$k]['long_count']>0 && $result[$k]['fan_add']>0 ? round( $result[$k]['fan_add'] / $result[$k]['long_count'], 4 ) * 100 . '%' : '';
|
|
4384
|
+ //下单数据统计
|
|
4385
|
+ $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount'))->where('admin_id', $admin_id)->first();
|
|
4386
|
+ $result[$k]['order_count'] = $order->order_count;
|
|
4387
|
+ $result[$k]['order_amount'] = $order->order_amount;
|
|
4388
|
+ //下单用户数
|
|
4389
|
+ $customer_count = DB::table('customers')->where('admin_id', $admin_id)->count();
|
|
4390
|
+ $customer_fugou_count = DB::table('customers')->where('is_fugou', 1)->where('admin_id', $admin_id)->count();
|
|
4391
|
+ //复购率
|
|
4392
|
+ $fugou_rate = $customer_count>0 ? round( $customer_fugou_count / $customer_count, 4 ) * 100 . '%' : '';
|
|
4393
|
+
|
|
4394
|
+ $result[$k]['customer_count'] = $customer_count;
|
|
4395
|
+ $result[$k]['fugou_rate'] = $fugou_rate;
|
|
4396
|
+
|
|
4397
|
+ }
|
|
4398
|
+
|
|
4399
|
+ if ($count > 1) {
|
|
4400
|
+ // 总页数
|
|
4401
|
+ $pages = ceil($count/$pageSize);
|
|
4402
|
+ }else{
|
|
4403
|
+ // 总页数
|
|
4404
|
+ $pages = 1;
|
|
4405
|
+ }
|
|
4406
|
+
|
|
4407
|
+ $teamList = DB::table('teams')->select('id', 'name')->get();
|
|
4408
|
+ $teamList = json_decode(json_encode($teamList), true);
|
|
4409
|
+ $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
|
|
4410
|
+ $adminList = json_decode(json_encode($adminList), true);
|
|
4411
|
+
|
|
4412
|
+ return view('statistics/salerOrderFugou', ['result' =>$result,
|
|
4413
|
+ 'page' =>$page,
|
|
4414
|
+ 'count' =>$count,
|
|
4415
|
+ 'pages' =>$pages,
|
|
4416
|
+ 'admin_id' =>$saler_id,
|
|
4417
|
+ 'team_id' =>$team_id,
|
|
4418
|
+ 'teamlist' =>$teamList,
|
|
4419
|
+ 'adminlist' =>$adminList,
|
|
4420
|
+ ]);
|
|
4421
|
+
|
|
4422
|
+ }
|
|
4423
|
+
|
|
4424
|
+ /**
|
|
4425
|
+ * 销售粉丝复购率导出
|
|
4426
|
+ */
|
|
4427
|
+ public function salerOrderFugou_export(Request $request){
|
|
4428
|
+ //获取销售
|
|
4429
|
+ $saler_id = (int)$request->input('admin_id');
|
|
4430
|
+ $team_id = (int)$request->input('team_id');
|
|
4431
|
+
|
|
4432
|
+ //假如有团队筛选,检索销售队员
|
|
4433
|
+ $saler_ids = null;
|
|
4434
|
+ if($saler_id>0){
|
|
4435
|
+ $saler_ids = [$saler_id];
|
|
4436
|
+ }elseif($team_id>0){
|
|
4437
|
+ $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
|
|
4438
|
+ }else{
|
|
4439
|
+ $saler_ids = DB::table('admin')->whereIn('team_id', [1,3,5])->lists('id');
|
|
4440
|
+ }
|
|
4441
|
+
|
|
4442
|
+ $result = array();
|
|
4443
|
+ foreach($saler_ids as $k=>$admin_id){
|
|
4444
|
+ $result[$k]['admin_id'] = $admin_id;
|
|
4445
|
+ //pv
|
|
4446
|
+ $temp = TemplatesLog::select(DB::raw('count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('admin_id',$admin_id)->first();
|
|
4447
|
+ $result[$k]['tcount'] = $temp->tcount;
|
|
4448
|
+ $result[$k]['pv_count'] = $temp->pv_count;
|
|
4449
|
+ //加粉
|
|
4450
|
+ $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add, admin_name'))->where('admin_id', $admin_id)->where('is_del', 0)->first();
|
|
4451
|
+ if(!empty($custDetail)){
|
|
4452
|
+ $result[$k]['fan_add'] = $custDetail->fan_add;
|
|
4453
|
+ $result[$k]['admin_name'] = $custDetail->admin_name;
|
|
4454
|
+ }else{
|
|
4455
|
+ $result[$k]['fan_add'] = '';
|
|
4456
|
+ $result[$k]['admin_name'] = DB::table('admin')->where('id', $admin_id)->pluck('realname');
|
|
4457
|
+ }
|
|
4458
|
+ $result[$k]['long_count'] = $result[$k]['tcount'] - $result[$k]['pv_count'];
|
|
4459
|
+
|
|
4460
|
+ //点击率
|
|
4461
|
+ $result[$k]['click_rate'] = $result[$k]['pv_count']>0 && $result[$k]['long_count']>0 ? round( $result[$k]['long_count'] / $result[$k]['pv_count'], 4 ) * 100 . '%' : '';
|
|
4462
|
+ $result[$k]['change_rate'] = $result[$k]['long_count']>0 && $result[$k]['fan_add']>0 ? round( $result[$k]['fan_add'] / $result[$k]['long_count'], 4 ) * 100 . '%' : '';
|
|
4463
|
+ //下单数据统计
|
|
4464
|
+ $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount'))->where('admin_id', $admin_id)->first();
|
|
4465
|
+ $result[$k]['order_count'] = $order->order_count;
|
|
4466
|
+ $result[$k]['order_amount'] = $order->order_amount;
|
|
4467
|
+ //下单用户数
|
|
4468
|
+ $customer_count = DB::table('customers')->where('admin_id', $admin_id)->count();
|
|
4469
|
+ $customer_fugou_count = DB::table('customers')->where('is_fugou', 1)->where('admin_id', $admin_id)->count();
|
|
4470
|
+ //复购率
|
|
4471
|
+ $fugou_rate = $customer_count>0 ? round( $customer_fugou_count / $customer_count, 4 ) * 100 . '%' : '';
|
|
4472
|
+
|
|
4473
|
+ $result[$k]['customer_count'] = $customer_count;
|
|
4474
|
+ $result[$k]['fugou_rate'] = $fugou_rate;
|
|
4475
|
+ }
|
|
4476
|
+
|
|
4477
|
+ $indexKey = ['admin_name','pv_count','long_count','fan_add','change_rate','customer_count','order_count','order_amount','fugou_rate'];
|
|
4478
|
+ $title = ['销售', 'PV量', '累计预估加粉数', '累计加粉数', '加粉转化率', '下单用户数', '累计下单数', '累计销售额', '复购率'];
|
|
4479
|
+ $filename = 'xiaoshoufugou_'.date('Y-m-d_H').'.xlsx';
|
|
4480
|
+ return Order::export_excel($result, $filename, $indexKey, $title);
|
|
4481
|
+ }
|
4333
|
4482
|
|
4334
|
4483
|
}
|
4335
|
|
-
|
|
4484
|
+
|
4336
|
4485
|
|
4337
|
4486
|
|
4338
|
4487
|
|