sunhao 5 years ago
parent
commit
80f319779b
1 changed files with 18 additions and 19 deletions
  1. 18 19
      app/Http/Controllers/Admin/StatisticsController.php

+ 18 - 19
app/Http/Controllers/Admin/StatisticsController.php

@@ -4390,18 +4390,17 @@ class StatisticsController extends Controller
4390 4390
             $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 . '%' : '';
4391 4391
             $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 . '%' : '';
4392 4392
             //下单数据统计
4393
-            $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount'))->where('admin_id', $admin_id)->where('is_del', 0)->first();
4393
+            $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount,count(distinct(receiverMobile)) as cust_count'))->where('admin_id', $admin_id)->where('is_able', 1)->where('is_del', 0)->first();
4394 4394
             $result[$k]['order_count'] = $order->order_count;
4395 4395
             $result[$k]['order_amount'] = $order->order_amount;
4396 4396
             //下单用户数
4397
-            $phones = DB::table('customers')->where('admin_id', $admin_id)->lists('phone');
4398
-            //过滤无效单用户
4399
-            $phones = DB::table('order')->whereIn('receiverMobile', $phones)->where('is_del', 0)->lists('receiverMobile');
4400
-            $customer_count = DB::table('customers')->where('admin_id', $admin_id)->whereIn('phone', $phones)->count();
4401
-            $customer_fugou_count = DB::table('customers')->where('is_fugou', 1)->whereIn('phone', $phones)->where('admin_id', $admin_id)->count();
4402
-
4403
-            //复购单
4404
-            $fugou_count = Order::where('is_fugou', 1)->where('admin_id', $admin_id)->where('is_del', 0)->count();
4397
+            $customer_count = $order->cust_count;
4398
+            //复购用户数 = 下单超过一单的用户数
4399
+            $order_cust_fugou = Order::select(DB::raw('count(1) as counts,receiverMobile'))->where('admin_id', $admin_id)->where('is_able', 1)->where('is_del', 0)->groupBy('receiverMobile')->having('counts', '>', 1)->get();
4400
+            $customer_fugou_count = count($order_cust_fugou);
4401
+
4402
+            //复购单= 总单-用户数
4403
+            $fugou_count = $order->order_count - $order->cust_count;
4405 4404
             $no_fugou_count = $order->order_count - $fugou_count;
4406 4405
             //复购率
4407 4406
             $fugou_rate = $no_fugou_count>0 ? round( $fugou_count / $no_fugou_count, 4 ) * 100 . '%' : '';
@@ -4480,7 +4479,7 @@ class StatisticsController extends Controller
4480 4479
             if(!empty($custDetail)){
4481 4480
                 $result[$k]['fan_add'] = $custDetail->fan_add;             
4482 4481
             }else{
4483
-                $result[$k]['fan_add'] = '';                             
4482
+                $result[$k]['fan_add'] = '';             
4484 4483
             }
4485 4484
             $result[$k]['admin_name'] = $name_arr[$admin_id];
4486 4485
             $result[$k]['long_count'] = $result[$k]['tcount'] - $result[$k]['pv_count'];
@@ -4489,17 +4488,17 @@ class StatisticsController extends Controller
4489 4488
             $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 . '%' : '';
4490 4489
             $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 . '%' : '';
4491 4490
             //下单数据统计
4492
-            $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount'))->where('is_del', 0)->where('admin_id', $admin_id)->first();
4491
+            $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount,count(distinct(receiverMobile)) as cust_count'))->where('admin_id', $admin_id)->where('is_able', 1)->where('is_del', 0)->first();
4493 4492
             $result[$k]['order_count'] = $order->order_count;
4494 4493
             $result[$k]['order_amount'] = $order->order_amount;
4495 4494
             //下单用户数
4496
-            $phones = DB::table('customers')->where('admin_id', $admin_id)->lists('phone');
4497
-            //过滤无效单用户
4498
-            $phones = DB::table('order')->whereIn('receiverMobile', $phones)->where('is_del', 0)->lists('receiverMobile');
4499
-            $customer_count = DB::table('customers')->where('admin_id', $admin_id)->whereIn('phone', $phones)->count();
4500
-            $customer_fugou_count = DB::table('customers')->where('is_fugou', 1)->whereIn('phone', $phones)->where('admin_id', $admin_id)->count();
4501
-            //复购单
4502
-            $fugou_count = Order::where('is_fugou', 1)->where('admin_id', $admin_id)->where('is_del', 0)->count();
4495
+            $customer_count = $order->cust_count;
4496
+            //复购用户数 = 下单超过一单的用户数
4497
+            $order_cust_fugou = Order::select(DB::raw('count(1) as counts,receiverMobile'))->where('admin_id', $admin_id)->where('is_able', 1)->where('is_del', 0)->groupBy('receiverMobile')->having('counts', '>', 1)->get();
4498
+            $customer_fugou_count = count($order_cust_fugou);
4499
+
4500
+            //复购单= 总单-用户数
4501
+            $fugou_count = $order->order_count - $order->cust_count;
4503 4502
             $no_fugou_count = $order->order_count - $fugou_count;
4504 4503
             //复购率
4505 4504
             $fugou_rate = $no_fugou_count>0 ? round( $fugou_count / $no_fugou_count, 4 ) * 100 . '%' : '';
@@ -4508,8 +4507,8 @@ class StatisticsController extends Controller
4508 4507
             $result[$k]['customer_count'] = $customer_count;
4509 4508
             $result[$k]['customer_fugou_count'] = $customer_fugou_count;
4510 4509
             $result[$k]['fugou_rate'] = $fugou_rate;
4511
-            $result[$k]['cust_fugou_rate'] = $cust_fugou_rate;
4512 4510
             $result[$k]['fugou_count'] = $fugou_count;
4511
+            $result[$k]['cust_fugou_rate'] = $cust_fugou_rate;
4513 4512
             $result[$k]['fugou_rate_sort'] = $no_fugou_count>0 ? round( $fugou_count / $no_fugou_count, 4 ) * 10000 : 0;
4514 4513
             //用户转化率
4515 4514
             $result[$k]['cust_order_rate'] = $result[$k]['fan_add']>0 ? round( $customer_count / $result[$k]['fan_add'], 4 ) * 100 . '%' : '';