|
@@ -7,7 +7,8 @@ use App\Models\VideoStatByCompany;
|
|
use App\Models\VideoStatByUser;
|
|
use App\Models\VideoStatByUser;
|
|
use App\Service\Stats\MiniprogramStatService;
|
|
use App\Service\Stats\MiniprogramStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Console\Command;
|
|
-use DB;
|
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
class MiniprogramStats extends Command{
|
|
class MiniprogramStats extends Command{
|
|
/**
|
|
/**
|
|
@@ -48,6 +49,45 @@ select '%s' as `date`,puser_id,video_id,video_name,sum(amount),sum(charge_count)
|
|
EDF;
|
|
EDF;
|
|
$sql = sprintf($sql,$this->day,$this->day);
|
|
$sql = sprintf($sql,$this->day,$this->day);
|
|
DB::insert($sql);
|
|
DB::insert($sql);
|
|
|
|
+
|
|
|
|
+ $iterator = 0;
|
|
|
|
+ $match = sprintf('djClickUv.%s.*', $this->day);
|
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
|
+ do {
|
|
|
|
+ list($iterator, $keys) = Redis::scan($iterator, 'match', $match, 'count', 1000);
|
|
|
|
+ foreach ($keys as $key) {
|
|
|
|
+ $arr = explode('.', $key);
|
|
|
|
+ $count = Redis::pfcount($key);
|
|
|
|
+ if(DB::table('video_stat_by_company')
|
|
|
|
+ ->where([
|
|
|
|
+ ['user_id', '=', $arr[3]],
|
|
|
|
+ ['video_id', '=', $arr[2]],
|
|
|
|
+ ['is_delete', '=', 0],
|
|
|
|
+ ['day','=', $this->day]
|
|
|
|
+ ])->exists()) {
|
|
|
|
+ DB::table('video_stat_by_company')
|
|
|
|
+ ->where([
|
|
|
|
+ ['user_id', '=', $arr[3]],
|
|
|
|
+ ['video_id', '=', $arr[2]],
|
|
|
|
+ ['is_delete', '=', 0],
|
|
|
|
+ ['day','=', $this->day]
|
|
|
|
+ ])->update([
|
|
|
|
+ 'click_uv' => $count, 'updated_at' => $now,
|
|
|
|
+ ]);
|
|
|
|
+ } else {
|
|
|
|
+ DB::table('video_stat_by_company')
|
|
|
|
+ ->insert([
|
|
|
|
+ 'user_id' => $arr[3],
|
|
|
|
+ 'video_id' => $arr[2],
|
|
|
|
+ 'day' => $this->day,
|
|
|
|
+ 'click_uv' => $count,
|
|
|
|
+ 'created_at' => $now,
|
|
|
|
+ 'updated_at' => $now,
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }while($iterator > 0);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -90,7 +130,7 @@ EDF;
|
|
* @param integer $user_id
|
|
* @param integer $user_id
|
|
* @param string $video_name
|
|
* @param string $video_name
|
|
* @return void
|
|
* @return void
|
|
- */
|
|
|
|
|
|
+ */
|
|
private function processUserDetail(int $puser_id, int $video_id,int $user_id,string $video_name){
|
|
private function processUserDetail(int $puser_id, int $video_id,int $user_id,string $video_name){
|
|
$day = $this->day;
|
|
$day = $this->day;
|
|
$stat_data = MiniprogramStatService::getOneItem($video_id,$user_id,$day);
|
|
$stat_data = MiniprogramStatService::getOneItem($video_id,$user_id,$day);
|
|
@@ -111,4 +151,4 @@ EDF;
|
|
}
|
|
}
|
|
MiniprogramStatService::deleteCache($video_id,$user_id,$day);
|
|
MiniprogramStatService::deleteCache($video_id,$user_id,$day);
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|