Explorar el Código

增加推广链接每日新增用户的支付人数统计

liuzejian hace 1 año
padre
commit
e69e6c1933
Se han modificado 1 ficheros con 41 adiciones y 10 borrados
  1. 41 10
      app/Console/Commands/Statistic/PromotionDayCharge.php

+ 41 - 10
app/Console/Commands/Statistic/PromotionDayCharge.php

@@ -5,6 +5,7 @@ namespace App\Console\Commands\Statistic;
 use Illuminate\Console\Command;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Redis;
 
 class PromotionDayCharge extends Command
 {
@@ -53,6 +54,7 @@ class PromotionDayCharge extends Command
                     $promotionDayCharge = $this->promotionDayCharge($item->promotion_id, $date);
                     $newUserCharge = $this->newUserCharge($item->promotion_id, $date);
                     $chargeInfo = $this->getPromotionData($promotionDayCharge, $newUserCharge);
+                    $chargeInfo['new_user_num'] = $this->getNewUserNum($item->promotion_id, $date);
                     $promotionData[] = array_merge( $chargeInfo, [
                         'promotion_id' => $item->promotion_id, 'day_at' => $date,
                         'created_at' => $now, 'updated_at' => $now,
@@ -81,13 +83,20 @@ class PromotionDayCharge extends Command
         }
     }
 
-    public function getPromotionData($promotionDayCharge, $newUserCharge, ) {
+    /**
+     * 某个推广链接在某天的新用户数量
+     * @param $promotionId 推广链接id
+     * @param $date  日期
+     * @return mixed
+     */
+    private function getNewUserNum($promotionId, $date) {
+        return intval(Redis::hget(sprintf('promotion:newUserCount:%s', $date), $promotionId));
+    }
+
+    public function getPromotionData($promotionDayCharge, $newUserCharge) {
         return [
             'pay_money' => $promotionDayCharge['pay_money'] ?? 0,
             'pay_count' => $promotionDayCharge['pay_count'] ?? 0,
-            'new_user_pay_money' => $newUserCharge['new_user_pay_money'] ?? 0,
-            'new_user_common_pay_money' => $newUserCharge['new_user_common_pay_money'] ?? 0,
-            'new_user_vip_pay_money' => $newUserCharge['new_user_vip_pay_money'] ?? 0,
             'common_pay_money' => $promotionDayCharge['common_pay_money'] ?? 0,
             'common_pay_uv' => $promotionDayCharge['common_pay_uv'] ?? 0,
             'common_pay_count' => $promotionDayCharge['common_pay_count'] ?? 0,
@@ -96,6 +105,12 @@ class PromotionDayCharge extends Command
             'vip_pay_uv' => $promotionDayCharge['vip_pay_uv'] ?? 0,
             'vip_pay_count' => $promotionDayCharge['vip_pay_count'] ?? 0,
             'vip_unpay_count' => $promotionDayCharge['vip_unpay_count'] ?? 0,
+            'new_user_pay_money' => $newUserCharge['new_user_pay_money'] ?? 0,
+            'new_user_common_pay_money' => $newUserCharge['new_user_common_pay_money'] ?? 0,
+            'new_user_vip_pay_money' => $newUserCharge['new_user_vip_pay_money'] ?? 0,
+            'new_user_pay_uv' => $newUserCharge['new_user_pay_uv'] ?? 0,
+            'new_user_vip_pay_uv' => $newUserCharge['new_user_vip_pay_uv'] ?? 0,
+            'new_user_common_pay_uv' =>$newUserCharge['new_user_common_pay_uv'] ?? 0,
         ];
     }
 
@@ -109,15 +124,27 @@ class PromotionDayCharge extends Command
                 DB::raw("sum(if(status <> 'unpaid', price, 0)) as pay_money"),
                 // 普通支付金额
                 DB::raw("sum(if(status <> 'unpaid' and order_type in ('coin', 'first_coin'), price, 0)) as common_pay_money"),
+                // 累计充值人数
+                DB::raw("count(distinct if(status <> 'unpaid', concat(uid, ranse_created_at), null)) as pay_uv"),
+                // 普通支付人数
+                DB::raw("count(distinct if(order_type in ('coin', 'first_coin') and status <> 'unpaid', concat(uid, ranse_created_at), null)) as common_pay_uv"),
+                // vip支付人数
+                DB::raw("count(distinct if(order_type not in ('coin', 'first_coin') and status <> 'unpaid', concat(uid, ranse_created_at), null)) as vip_pay_uv"),
             )->first();
         if($info) {
             return [
-                // 新用户支付总额
+                // 新用户支付总额
                 'new_user_pay_money' => $info->pay_money,
-                // 新用户普通支付总额
+                // 新用户普通支付总额
                 'new_user_common_pay_money' => $info->common_pay_money,
-                // 新用户会员支付总额
-                'new_user_vip_pay_money' => $info->pay_money - $info->common_pay_money
+                // 新增用户会员支付总额
+                'new_user_vip_pay_money' => $info->pay_money - $info->common_pay_money,
+                // 新增用户在{$date}充值人数
+                'new_user_pay_uv' => $info->pay_uv,
+                // 新增用户在{$date}vip充值支付人数
+                'new_user_vip_pay_uv' => $info->vip_pay_uv,
+                // 新增用户在{$date}普通充值支付人数
+                'new_user_common_pay_uv' => $info->vip_pay_uv,
             ];
         } else {
             return null;
@@ -128,6 +155,7 @@ class PromotionDayCharge extends Command
         $info = DB::table('orders')
             ->where('promotion_id', $promotionId)
             ->whereBetween('created_at', [$date, $date. ' 23:59:59'])
+            ->where('ranse_created_at', '>', '2000-01-01')
             ->select(
                 // 未支付金额
                 DB::raw("sum(if(status = 'unpaid', price, 0)) as unpay_money"),
@@ -143,10 +171,13 @@ class PromotionDayCharge extends Command
                 DB::raw("sum(if(order_type in ('coin', 'first_coin'), 1,  0)) as common_count"),
                 // 普通支付金额
                 DB::raw("sum(if(order_type in ('coin', 'first_coin') and status <> 'unpaid', price, 0)) as common_pay_money"),
+                // NOTE!!!,uid, ranse_created_at 唯一确定一个用户
+                // 累计充值人数
+                DB::raw("count(distinct if(status <> 'unpaid', concat(uid, ranse_created_at), null)) as pay_uv"),
                 // 普通支付人数
-                DB::raw("count(distinct if(order_type in ('coin', 'first_coin') and status <> 'unpaid', uid, null)) as common_pay_uv"),
+                DB::raw("count(distinct if(order_type in ('coin', 'first_coin') and status <> 'unpaid', concat(uid, ranse_created_at), null)) as common_pay_uv"),
                 // vip支付人数
-                DB::raw("count(distinct if(order_type not in ('coin', 'first_coin') and status <> 'unpaid', uid, null)) as vip_pay_uv"),
+                DB::raw("count(distinct if(order_type not in ('coin', 'first_coin') and status <> 'unpaid', concat(uid, ranse_created_at), null)) as vip_pay_uv"),
                 // vip未支付笔数
                 DB::raw("sum(if(order_type not in ('coin', 'first_coin') and status = 'unpaid', 1,  0)) as vip_unpay_count"),
             )->first();