|
@@ -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);}
|
|
|
+ }
|
|
|
+}
|