VideoRedRedisService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class VideoRedRedisService extends BaseRedisService
  10. {
  11. var $user_red_db; //:red_id list数据 存储 中奖金额列表
  12. var $user_winning_db;//:red_id zset user_id:money
  13. /**
  14. +----------------------------------------------------------
  15. * 架构函数
  16. +----------------------------------------------------------
  17. * @access public
  18. +----------------------------------------------------------
  19. */
  20. public function __construct()
  21. {
  22. parent::__construct();
  23. $this->user_red_db = $this->prefix.'user_red:';
  24. $this->user_winning_db = $this->prefix.'user_winning:';
  25. }
  26. /*
  27. * 抢红包
  28. */
  29. public function push_red($red_id,$money){
  30. return $this->redis->rPush($this->user_red_db.$red_id,$money);
  31. }
  32. public function red_exists($red_id){
  33. return $this->redis->exists($this->user_red_db.$red_id);
  34. }
  35. /*
  36. *
  37. */
  38. public function pop_red($red_id){
  39. return $this->redis->lPop($this->user_red_db.$red_id);
  40. }
  41. /*
  42. * 添加中奖用户
  43. */
  44. public function add_user_winning($red_id,$user_id,$money){
  45. return $this->redis->zIncrBy($this->user_winning_db.$red_id,$money,$user_id);
  46. //return $this->redis->zAdd($this->user_winning_db.$red_id,$money,$user_id);
  47. }
  48. /*
  49. * 获取中奖用户的值
  50. * 未中奖 返回false
  51. */
  52. public function get_user_winning($red_id,$user_id){
  53. return $this->redis->zScore($this->user_winning_db.$red_id,$user_id);
  54. }
  55. /*
  56. * 获取中奖的红包
  57. */
  58. public function get_winnings($red_id){
  59. $user_num_array = $this->redis->zRevRange($this->user_winning_db.$red_id,0,-1,true);
  60. $user_ids = array_keys($user_num_array);
  61. $user_list_array = $this->redis->hMGet($this->user_hash_db,$user_ids);
  62. $user_list = array();
  63. foreach($user_list_array as $k=>$v){
  64. if($v){
  65. $user = json_decode($v,true);
  66. $user['user_id'] = $k;
  67. $user['diamonds'] = $user_num_array[$k];
  68. $user['head_image'] = get_spec_image($user['head_image']);
  69. $user_list[] = $user;
  70. }
  71. }
  72. return $user_list;
  73. }
  74. }//类定义结束
  75. ?>