Party.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use Redis;
  5. /**
  6. * 模型
  7. */
  8. class Party extends Model
  9. {
  10. // 开启自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. /**
  16. * 根据partyid 获取 party 信息
  17. */
  18. public function getPatyInfoByPartyId($party_id,$room_type,$type_id,$is_recommend,$all,$start = 0,$end = 9,$index) {
  19. if(!$party_id) return false;
  20. // 判断派对是否存在
  21. $redis = new Redis();
  22. $redisconfig = config("redis");
  23. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  24. if(!is_array($party_id)) {
  25. return [];
  26. }
  27. $redisPartyInfo = [];
  28. foreach($party_id as $k => $v) {
  29. $getredisPartyInfo = $redis->get($room_type.'_'.$k);
  30. $foreachData = json_decode($getredisPartyInfo,true);
  31. if(!$foreachData || $foreachData["is_close"] == 1) continue;
  32. if(!$foreachData || $foreachData["is_online"] == 0) continue;
  33. if(!$foreachData || $foreachData["party_pass"] != '') continue;
  34. $mod = isset($foreachData["party_type"])?intval($foreachData["party_type"])%5:1;
  35. if(isset($foreachData["type_name"]) && $foreachData["type_name"]) {
  36. $type_name = $foreachData["type_name"];
  37. } else {
  38. $type_name = "普通房";
  39. }
  40. $hasdata = false;
  41. if($all == 1) {
  42. if($is_recommend == 1) {
  43. if($foreachData["is_recommend"] == 1) $hasdata = true;
  44. } else {
  45. $hasdata = true;
  46. }
  47. } elseif($type_id > 0) {
  48. if($type_id == $foreachData["party_type"]) $hasdata = true;
  49. }
  50. if($foreachData["status"] != 1) $hasdata = false;
  51. $hasdata && $redisPartyInfo[] = [
  52. "id" => $foreachData["id"],
  53. "party_id" => $foreachData["party_id"],
  54. "r_id" => $foreachData["party_id"],
  55. "party_name" => $foreachData["party_name"],
  56. "party_pass" => $foreachData["party_pass"]?$foreachData["party_pass"]:"",
  57. "party_hot" => $v,
  58. "party_logo" => $this->httpurl($foreachData["party_logo"]),
  59. "party_type" => $type_name,
  60. "avatar" => $room_type == 2 ? $foreachData["avatar"]:"",
  61. "party_type_color" => $mod == 0?5:$mod,
  62. "party_user" => isset($foreachData["party_user"]) ? array_values($foreachData["party_user"]) : [] // 当前麦位人头像
  63. ];
  64. }
  65. $resdata = [];
  66. if($index == 1) {
  67. $num = $end - $start + 1;
  68. $countData = count($redisPartyInfo);
  69. if($num > $countData) $num = $countData;
  70. if($redisPartyInfo) {
  71. $dataRand = array_rand($redisPartyInfo,$num);
  72. $dataRand = is_array($dataRand)?$dataRand:[$dataRand];
  73. if($redisPartyInfo) foreach($redisPartyInfo as $k => $v) if(in_array($k,$dataRand)) $resdata[] = $v;
  74. }
  75. } else {
  76. if($redisPartyInfo) foreach($redisPartyInfo as $k => $v) if($k >= $start && $k <= $end) $resdata[] = $v;
  77. }
  78. return $resdata;
  79. }
  80. /**
  81. * 判断当前url是否为全路径,并返回全路径
  82. */
  83. protected function httpurl($path) {
  84. // 获取当前域名
  85. if(strpos($path,'http://') === false && strpos($path,'https://') === false && strpos($path,'uploads') !== false) {
  86. $host = config("cos")['url'];
  87. $url = $host.$path;
  88. } else {
  89. $url = $path;
  90. }
  91. return $url;
  92. }
  93. }