<?php namespace App\Service\Stats; use Illuminate\Support\Facades\Redis; /** * 短剧统计 */ class MiniprogramStatService{ public static function getOneItem(int $video_id,int $user_id,string $day){ $playNumkey = 'VideoStat:palyNum:'.$day; $field = sprintf('UserId:%s:MinId:%s',$user_id,$video_id); $play_count = Redis::hget($playNumkey,$field); $amountKey = 'VideoStat:chargeAmount:'.$day; //充值金额 $amount = Redis::hget($amountKey,$field); $chargeCountkey = 'VideoStat:chargeCount:'.$day; $charge_count = Redis::hget($chargeCountkey,$field); //充值人数 $chargeUserNumKey = 'VideoStat:chargeUserNum:'.$day.':'; $charge_user_num = Redis::scard($chargeUserNumKey.$field); return compact('amount','play_count','charge_count','charge_user_num'); } public static function deleteCache(int $video_id,int $user_id,string $day){ $field = sprintf('UserId:%s:MinId:%s',$user_id,$video_id); $playNumkey = 'VideoStat:palyNum:'.$day; $amountKey = 'VideoStat:chargeAmount:'.$day; $chargeCountkey = 'VideoStat:chargeCount:'.$day; $chargeUserNumKey = 'VideoStat:chargeUserNum:'.$day.':'.$field; Redis::hdel( $playNumkey,$field); Redis::hdel( $amountKey,$field); Redis::hdel( $chargeCountkey,$field); Redis::del($chargeUserNumKey); } public static function deleteAll(string $day){ $playNumkey = 'VideoStat:palyNum:'.$day; $amountKey = 'VideoStat:chargeAmount:'.$day; $chargeCountkey = 'VideoStat:chargeCount:'.$day; Redis::del($playNumkey,$amountKey,$chargeCountkey); } }