Party.php 3.6 KB

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