zz vor 5 Jahren
Ursprung
Commit
f5062c971f
3 geänderte Dateien mit 108 neuen und 3 gelöschten Zeilen
  1. 104 0
      app/Console/Commands/InnerOuterWeixinStats.php
  2. 2 1
      app/Console/Kernel.php
  3. 2 2
      config/app.php

+ 104 - 0
app/Console/Commands/InnerOuterWeixinStats.php

@@ -0,0 +1,104 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use DB;
+use Redis;
+
+class InnerOuterWeixinStats extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'InnerOuterWeixinStats {--day=}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $day = $this->option('day');
+        if($day){
+            $day = date('Y-m-d',time()-86400);
+        }
+        $this->getByDay($day);
+    }
+
+    private function getByDay($day)
+    {
+        $keys = Redis::SMEMBERS('InnerOuterWeixinStats:'.$day);
+        if (!$keys) {
+            return ;
+        }
+        $data = [];
+        $i = 0;
+        foreach ($keys as $k){
+
+            list($from,$distribution_channel_id) = explode(':',$k);
+            if(!$from || !$distribution_channel_id) continue;
+            $pv_key = sprintf('InnerOuterWeixinStats:pv:%s:%s',$from,$distribution_channel_id);
+            $uv_key = sprintf('InnerOuterWeixinStats:uv:%s:%s:%s',$from,$distribution_channel_id,$day);
+            $pv = Redis::hget($pv_key,$day);
+            $uv = Redis::scard($uv_key);
+            $type = '';
+            $param = '';
+            if(is_numeric($from)){
+                $type = 'send_order';
+                $param = $from;
+            }
+
+            if(str_contains($from,['custom','template'])){
+                return ;
+            }
+            if(str_contains($from,['template'])){
+                $type = 'template';
+                list($temp,$param) = explode('_',$from);
+            }
+
+            if(str_contains($from,['custom'])){
+                $type = 'custom';
+                list($temp,$param) = explode('_',$from);
+            }
+
+            if(!$type || !$param || !is_numeric($param)) continue;
+
+            $data[] = [
+                'type'=>$type,
+                'param'=>$param,
+                'pv'=>$pv,
+                'uv'=>$uv,
+                'day'=>$day,
+                'charge'=>0,
+                'updated_at'=>date('Y-m-d H:i:s'),
+                'created_at'=>date('Y-m-d H:i:s')
+            ];
+            if($i++ % 100 == 0){
+                DB::table('inner_outer_weixin_stats')->insert($data);
+                $data = [];
+            }
+        }
+        if($data){DB::table('inner_outer_weixin_stats')->insert($data);}
+    }
+}

+ 2 - 1
app/Console/Kernel.php

@@ -23,7 +23,8 @@ class Kernel extends ConsoleKernel
         Commands\BookAttr::class,
         Commands\YqBook::class,
         Commands\channelCpcCode::class,
-        Commands\updateFromNewYunqi::class
+        Commands\updateFromNewYunqi::class,
+        Commands\InnerOuterWeixinStats::class
     ];
 
     /**

+ 2 - 2
config/app.php

@@ -159,7 +159,7 @@ return [
         App\Providers\SQLServiceProvider::class,
         Vinkla\Hashids\HashidsServiceProvider::class,
         Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,
-        Mews\Captcha\CaptchaServiceProvider::class,
+        //Mews\Captcha\CaptchaServiceProvider::class,
         //VladimirYuldashev\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider::class,
     ],
 
@@ -208,7 +208,7 @@ return [
         'View' => Illuminate\Support\Facades\View::class,
          'Hashids' => Vinkla\Hashids\Facades\Hashids::class,
         'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class ,
-        'Captcha' => Mews\Captcha\Facades\Captcha::class,
+        //'Captcha' => Mews\Captcha\Facades\Captcha::class,
     ],
 
 ];