MiniprogramStatService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Service\Stats;
  3. use Illuminate\Support\Facades\Redis;
  4. /**
  5. * 短剧统计
  6. */
  7. class MiniprogramStatService{
  8. public static function getOneItem(int $video_id,int $user_id,string $day){
  9. $playNumkey = 'VideoStat:palyNum:'.$day;
  10. $field = sprintf('UserId:%s:MinId:%s',$user_id,$video_id);
  11. $play_count = Redis::hget($playNumkey,$field);
  12. $amountKey = 'VideoStat:chargeAmount:'.$day; //充值金额
  13. $amount = Redis::hget($amountKey,$field);
  14. $chargeCountkey = 'VideoStat:chargeCount:'.$day;
  15. $charge_count = Redis::hget($chargeCountkey,$field);
  16. //充值人数
  17. $chargeUserNumKey = 'VideoStat:chargeUserNum:'.$day.':';
  18. $charge_user_num = Redis::scard($chargeUserNumKey.$field);
  19. return compact('amount','play_count','charge_count','charge_user_num');
  20. }
  21. public static function deleteCache(int $video_id,int $user_id,string $day){
  22. $field = sprintf('UserId:%s:MinId:%s',$user_id,$video_id);
  23. $playNumkey = 'VideoStat:palyNum:'.$day;
  24. $amountKey = 'VideoStat:chargeAmount:'.$day;
  25. $chargeCountkey = 'VideoStat:chargeCount:'.$day;
  26. $chargeUserNumKey = 'VideoStat:chargeUserNum:'.$day.':'.$field;
  27. Redis::hdel( $playNumkey,$field);
  28. Redis::hdel( $amountKey,$field);
  29. Redis::hdel( $chargeCountkey,$field);
  30. Redis::del($chargeUserNumKey);
  31. }
  32. public static function deleteAll(string $day){
  33. $playNumkey = 'VideoStat:palyNum:'.$day;
  34. $amountKey = 'VideoStat:chargeAmount:'.$day;
  35. $chargeCountkey = 'VideoStat:chargeCount:'.$day;
  36. Redis::del($playNumkey,$amountKey,$chargeCountkey);
  37. }
  38. }