Party.php 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Redis;
  5. use think\Db;
  6. use think\Exception;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. use app\common\service\RoomService;
  10. use app\common\library\Easemob;
  11. require_once EXTEND_PATH . 'shengwang/src/RtcTokenBuilder2.php';
  12. require_once EXTEND_PATH . 'shengwang/src/RtmTokenBuilder2.php';
  13. /**
  14. *
  15. * 派对信息接口
  16. */
  17. class Party extends Api
  18. {
  19. protected $noNeedLogin = ['test_party_attr','updatePartyInfo','getPatyType','shengwang_token','addUserPositionToParty', 'clearMoney','clearCharm','getPartyRankList','getDefaultBackground','getPartGifList','getPartHeadgifList','isNotalk','getMusicList','updateTops','handleParty'];
  20. protected $noNeedRight = ['*'];
  21. protected $redis;
  22. public function __construct()
  23. {
  24. $this->roomTypeArr = [1=>"party",2=>"live"];
  25. //redis
  26. $redis = new Redis();
  27. $redisconfig = config("redis");
  28. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  29. if ($redisconfig['redis_pwd']) {
  30. $redis->auth($redisconfig['redis_pwd']);
  31. }
  32. if($redisconfig['redis_selectdb'] > 0){
  33. $redis->select($redisconfig['redis_selectdb']);
  34. }
  35. $this->redis = $redis;
  36. parent::__construct();
  37. }
  38. /**
  39. * 创建/进入派对
  40. */
  41. public function createParty() {
  42. if(!$this->apiLimit()){
  43. $this->error('访问频繁,请稍后重试');
  44. }
  45. $party_logo = input('party_logo');
  46. $party_name = input('party_name');
  47. $seatnum = input('seatnum');
  48. $is_public = input('is_public',1); //是否公开:1=是,0=否
  49. //$room_type = input('room_type',2); // 房间类型:1=公会房,2=K歌房
  50. $room_type = 2; // 房间类型:1=公会房,2=K歌房
  51. $partyModel = new \app\common\model\Party();
  52. $user_id = $this->auth->id;
  53. // 开直播时,判断当前用户是否为主播
  54. $anchorInfo = [];
  55. if($room_type == 2) {
  56. /*$anchorInfo = \app\common\model\UserAnchor::where(["user_id"=>$user_id])->find();
  57. $anchorInfo || $this->error("您还未申请主播!");
  58. $anchorInfo->status == 0 && $this->error("您的主播申请信息还未受理,请耐心等待!");
  59. $anchorInfo->status == 2 && $this->error("您的主播申请未通过,请重新提交!");*/
  60. }
  61. // 1。实名认证
  62. $userAuthInfo = \app\common\model\UserAuth::where(["user_id"=>$user_id])->find();
  63. if($userAuthInfo) {
  64. if($userAuthInfo->status == 0) {
  65. $this->error("您的实名认证还在这审核中...,请耐心等待!");
  66. } elseif($userAuthInfo->status == 2) {
  67. $this->error("您的实名认证审核未通过,请重新审核!");
  68. }
  69. } else {
  70. $this->error("请先申请实名认证!");
  71. }
  72. if($room_type == 1) {
  73. // 2。开厅申请
  74. $authInfo = model('Guild')->where(["user_id"=>$user_id])->order('id desc')->find();
  75. if($authInfo) {
  76. if($authInfo->status == 0) {
  77. $this->error("您的公会申请还在这审核中...,请耐心等待!");
  78. } elseif($authInfo->status == -1) {
  79. $this->error("您的公会申请已解散,请重新申请!");
  80. }
  81. } else {
  82. $this->error("请先申请公会!");
  83. }
  84. }
  85. // 判断派对是否存在
  86. $where = [];
  87. $where["user_id"] = $user_id;
  88. $where["room_type"] = $room_type;
  89. $sqlPartyInfo = $partyModel->where($where)->find();
  90. if(!$sqlPartyInfo) { // sql中不存在派对信息
  91. $party_type = 8; // 派对类型(情感互动,心动点单 等)
  92. $party_notice = "请编辑房间公告"; // 派对公告
  93. $party_notice_detail = "请编辑房间公告内容!"; // 派对公告详情
  94. $party_ids = $partyModel->column("party_id");
  95. // 创建派对ID (临时ID四位,派对数不超过8999)
  96. $party_id = $this->auth->getUinqueId(4,$party_ids);
  97. if($party_id > 9999) {
  98. $this->error("房间超限,请联系客服");
  99. }
  100. if ($room_type == 1) {//公会房间获取家族信息
  101. $guildWhere['user_id'] = $user_id;
  102. $guildWhere['status'] = 1;
  103. $guild = model('Guild')->where($guildWhere)->order('id desc')->find();
  104. if (!empty($guild)) {
  105. $party_name = $guild['name'].'的房间';
  106. $party_logo = $guild['image'];
  107. $party_notice = $guild['desc'];
  108. $party_notice_detail = $guild['notice'];
  109. }
  110. $party_type = 7;
  111. }
  112. //创建房间,初始化环信
  113. $easemob_room_id = $this->easemob_createroom($party_name,$party_logo,$seatnum,$is_public,$room_type);
  114. //写入派对
  115. Db::startTrans();
  116. $data = [];
  117. $data["user_id"] = $this->auth->id;
  118. $data["room_type"] = $room_type;
  119. $data["party_id"] = $party_id;
  120. $data["party_hot"] = 0;
  121. $data["party_name"] = $party_name;
  122. $data["party_logo"] = $party_logo;
  123. $data["party_type"] = $party_type;
  124. $data["party_notice"] = $party_notice;
  125. $data["party_notice_detail"] = $party_notice_detail;
  126. $data["is_online"] = 1;
  127. $data["status"] = 1;//直接正常状态
  128. $data["is_recommend"] = 0;
  129. $data["createtime"] = time();
  130. $data["easemob_room_id"] = $easemob_room_id;
  131. if($room_type == 1){
  132. $data["platRate"] = config('site.party_party_platrate');
  133. $data["guilderRate"] = config('site.party_party_guilderrate');
  134. }else{
  135. $data["platRate"] = config('site.party_live_platrate');
  136. $data["guilderRate"] = config('site.party_live_guilderrate');
  137. }
  138. $id = $partyModel->insertGetId($data);
  139. if(!$id) {
  140. Db::rollback();
  141. $this->error("房间创建失败,请稍后重试!");
  142. }
  143. $data["id"] = $id;
  144. if($room_type == 2) {
  145. \app\common\model\User::update(["is_live"=>1],["id"=>$user_id]);
  146. }
  147. $partyInfo = $partyModel->where(["id"=>$id])->find();
  148. $partyInfo["is_new"] = 1;
  149. // 冠名
  150. $userInfo = [];
  151. if($partyInfo["naming"]) {
  152. $userInfo = \app\common\model\User::field("id,nickname,avatar")->where(["id"=>$partyInfo["naming"]])->find();
  153. }
  154. // 头像
  155. if($partyInfo["user_id"] > 0 && $room_type == 2) {
  156. $partyInfo["avatar"] = \app\common\model\User::where(["id"=>$partyInfo["user_id"]])->value("avatar");
  157. }
  158. // 派对类型
  159. $partyTypeName = "普通房";
  160. if($partyInfo["party_type"]) {
  161. $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name");
  162. }
  163. $partyInfo["naming"] = $userInfo;
  164. $partyInfo["type_name"] = $partyTypeName;
  165. // 加入缓存排序,rediskey:派对热度
  166. $this->redis->zAdd($this->roomTypeArr[$room_type]."Rank", $partyInfo['party_hot'], $partyInfo["id"]);
  167. // 加入缓存,rediskey:派对详情
  168. $this->redis->set($this->roomTypeArr[$room_type]."_".$partyInfo["id"],json_encode($partyInfo));
  169. if($room_type != 2) {
  170. //更新家族 party_id
  171. $guildWhere['user_id'] = $user_id;
  172. $guildWhere['status'] = 1;
  173. $guild = model('Guild')->where($guildWhere)->order('id desc')->find();
  174. if (!empty($guild)) {
  175. $rs_guild = model('Guild')->where($guildWhere)->update(['party_id'=>$partyInfo['id']]);
  176. if($rs_guild === false){
  177. Db::rollback();
  178. $this->error('创建房间失败');
  179. }
  180. }
  181. }
  182. Db::commit();
  183. } else {
  184. $partyInfo = $sqlPartyInfo;
  185. $partyInfo["is_new"] = 0;
  186. $partyInfo["status"] = 1;
  187. //修改状态
  188. $update = [
  189. 'status' => 1,
  190. ];
  191. //没有房间号的给创建一个
  192. if(empty($partyInfo['easemob_room_id'])){
  193. $easemob_room_id = $this->easemob_createroom($party_name,$party_logo,$seatnum,$is_public,$room_type);
  194. $update['easemob_room_id'] = $easemob_room_id;
  195. $partyInfo['easemob_room_id'] = $easemob_room_id;
  196. }else{
  197. $easemob_room_id = $partyInfo['easemob_room_id'];
  198. }
  199. Db::name('party')->where('id',$partyInfo['id'])->update($update);
  200. //修改状态
  201. $redispartyInfo = $this->redis->get($this->roomTypeArr[$room_type]."_".$partyInfo['id']);
  202. if($redispartyInfo) {
  203. $redispartyInfo = json_decode($redispartyInfo,true);
  204. $redispartyInfo = array_replace($redispartyInfo,$update);
  205. $this->redis->set($this->roomTypeArr[$room_type]."_".$partyInfo['id'],json_encode($redispartyInfo));
  206. }
  207. }
  208. //声网三个token
  209. $partyInfo['shengwang_token'] = $this->shengwang_token_private($easemob_room_id);
  210. //帮房主走一次joinparty
  211. $this->creater_joinParty($partyInfo['id'],$easemob_room_id,$partyInfo['user_id']);
  212. $this->success("获取成功!",$partyInfo);
  213. }
  214. //创建房间,初始化环信
  215. private function easemob_createroom($party_name,$party_logo,$seatnum,$is_public,$room_type){
  216. //[环信]创建聊天室
  217. $easemob = new Easemob();
  218. $easemob_room_id = $easemob->room_createRoom($party_name,$party_name,$this->auth->id);
  219. if(empty($easemob_room_id)){
  220. $this->error('创建房间失败');
  221. }
  222. //[环信]初始化房间,初始化自定义属性
  223. $matedata = [
  224. 'seatnum'=> $seatnum,//麦位数量
  225. 'waitsing_list' => json_encode([]),//已点歌曲列表
  226. 'party_name' => $party_name,//房名字
  227. 'party_logo' => $party_logo,//logo
  228. 'is_public' => $is_public,//是否公开
  229. 'room_type' => $room_type,//房间类型
  230. 'online_user_num' => 0,//当前房间在线的人
  231. 'wealth_top3_userlist' => json_encode([]),//财富榜前3个人列表
  232. 'background' => '', //房间背景
  233. ];
  234. $rs = $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$this->auth->id,$matedata);
  235. //[环信]初始化N个麦位
  236. $seatdata = [];
  237. for($i=0;$i<$seatnum;$i++){
  238. $seat = [
  239. 'charm' => 0, //红心,魅力值
  240. 'isMaster' => false, // 是否是房主
  241. 'headUrl' => '', // 头像
  242. 'userNo' => '', // 座位上用户no
  243. 'rtcUid' => '', // 座位上用户id,与rtc的userId一致
  244. 'name' => '', // 座位上用户昵称
  245. 'seatIndex' => -1, // 座位编号
  246. 'chorusSongCode' => '', // 是否合唱
  247. 'isAudioMuted' => 1, // 是否静音
  248. 'isVideoMuted' => 0, // 是否开启视频
  249. 'checked' => false, // 用于送礼物选择用户
  250. 'isUsed' => true, // 用于送礼物选择用户
  251. 'gender' => 1, //性别
  252. ];
  253. //创建完房间就进入,所以房主直接在麦位0
  254. /*if($i == 0){
  255. $seat['isMaster'] = true;
  256. $seat['headUrl'] = localpath_to_netpath($this->auth->avatar);
  257. $seat['userNo'] = $this->auth->id;
  258. $seat['rtcUid'] = $this->auth->id;
  259. $seat['name'] = $this->auth->nickname;
  260. $seat['seatIndex'] = $i;
  261. }*/
  262. $seatdata['seat'.$i] = json_encode($seat);
  263. }
  264. $rs = $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$this->auth->id,$seatdata);
  265. return $easemob_room_id;
  266. }
  267. //声网3个token
  268. public function shengwang_token(){
  269. $party_id = input('party_id'); // 派对ID
  270. $partyInfo = \app\common\model\Party::where(["id"=>$party_id])->find();
  271. if(!$partyInfo) {
  272. $this->error(__('派对不存在!'));
  273. }
  274. $rs = $this->shengwang_token_private($partyInfo['easemob_room_id']);
  275. $this->success(1,$rs);
  276. }
  277. //声网3个token
  278. private function shengwang_token_private($easemob_room_id){
  279. $config = config('shengwang');
  280. $appId = $config['app_id'];
  281. $appCertificate = $config['app_zhengshu'];;
  282. $channelName = $easemob_room_id;
  283. $uid = 0; //任何人都可进入
  284. $uidStr = '0';//任何人都可进入
  285. $tokenExpirationInSeconds = 86400;
  286. $privilegeExpirationInSeconds = 86400;
  287. //rtc token
  288. $rtc_token = \RtcTokenBuilder2::buildTokenWithUid($appId, $appCertificate, $channelName, $uid, \RtcTokenBuilder2::ROLE_PUBLISHER, $tokenExpirationInSeconds, $privilegeExpirationInSeconds);
  289. //chorus token
  290. $chorus_token = \RtcTokenBuilder2::buildTokenWithUid($appId, $appCertificate, $channelName.'_ex', $uid, \RtcTokenBuilder2::ROLE_PUBLISHER, $tokenExpirationInSeconds, $privilegeExpirationInSeconds);
  291. //rtm token
  292. $user = '0';
  293. $expireTimeInSeconds = 86400;
  294. $rtm_token = \RtmTokenBuilder2::buildToken($appId, $appCertificate, $user, $expireTimeInSeconds);
  295. $result = [
  296. 'rtc_token' => $rtc_token,
  297. 'chorus_token' => $chorus_token,
  298. 'rtm_token' => $rtm_token,
  299. ];
  300. //dump($result);
  301. return $result;
  302. }
  303. /**
  304. * 解散房间
  305. */
  306. public function closeParty() {
  307. $party_id = input('party_id'); // 派对ID
  308. $room_type = input('room_type',1); // 房间类型:1=派对,2=直播
  309. if (!$party_id || !in_array($room_type,[1,2])) {
  310. $this->error(__('Invalid parameters'));
  311. }
  312. $partyInfo = \app\common\model\Party::where(["id"=>$party_id])->find();
  313. if(!$partyInfo) {
  314. $this->error(__('派对不存在!'));
  315. }
  316. $room_type = $partyInfo['room_type'];
  317. if($partyInfo['user_id'] != $this->auth->id){
  318. $this->error('房主才能解散');
  319. }
  320. //房间从首页列表消失
  321. $update = [
  322. 'status' => 3,
  323. ];
  324. Db::name('party')->where('id',$party_id)->update($update);
  325. // 存redis 房间信息
  326. $redispartyInfo = $this->redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  327. if($redispartyInfo) {
  328. $redispartyInfo = json_decode($redispartyInfo,true);
  329. $redispartyInfo = array_replace($redispartyInfo,$update);
  330. $this->redis->set($this->roomTypeArr[$room_type]."_".$party_id,json_encode($redispartyInfo));
  331. }
  332. //用户魅力榜,清空
  333. $this->redis->zRemRangeByRank("hourCharm_".$party_id, 0,-1);
  334. //用户贡献榜,清空
  335. $this->redis->zRemRangeByRank("hourWealth_".$party_id, 0,-1);
  336. //贡献榜前三,设置为空
  337. $this->redis->hSet("user_jewel_top3",$party_id,json_encode([]));
  338. //排麦列表,清空
  339. $this->redis->hSet("party_lineup",$party_id,serialize([]));
  340. //清空房间
  341. $user_ids = $this->redis->hGetAll("online_".$party_id);
  342. if(!empty($user_ids)){
  343. foreach($user_ids as $key => $userId){
  344. $this->redis->HDel("online_" . $party_id, $userId);
  345. $this->redis->zRem("party_user_".$party_id,$userId); //新加的
  346. $this->redis->hDel("livingUser", $userId);
  347. }
  348. }
  349. //环信操作
  350. $easemob_room_id = $partyInfo['easemob_room_id'];
  351. if(!empty($easemob_room_id)){
  352. ///初始化房间信息,重置自定义属性
  353. $matedata = [
  354. 'waitsing_list' => json_encode([]), //清空房间待唱列表
  355. 'online_user_num' => 0, //当前房间在线的人
  356. 'wealth_top3_userlist' => json_encode([]),//财富榜前3个人列表
  357. ];
  358. $easemob = new Easemob();
  359. $easemob->room_setRoomCustomAttributeForced($partyInfo['easemob_room_id'],$partyInfo['user_id'],$matedata);
  360. //重置麦位
  361. $seatnum = $partyInfo['seatnum'];
  362. $seatdata = [];
  363. for($i=0;$i<$seatnum;$i++){
  364. $seat = [
  365. 'charm' => 0, //红心,魅力值
  366. 'isMaster' => false, // 是否是房主
  367. 'headUrl' => '', // 头像
  368. 'userNo' => '', // 座位上用户no
  369. 'rtcUid' => '', // 座位上用户id,与rtc的userId一致
  370. 'name' => '', // 座位上用户昵称
  371. 'seatIndex' => -1, // 座位编号
  372. 'chorusSongCode' => '', // 是否合唱
  373. 'isAudioMuted' => 1, // 是否静音
  374. 'isVideoMuted' => 0, // 是否开启视频
  375. 'checked' => false, // 用于送礼物选择用户
  376. 'isUsed' => true, // 用于送礼物选择用户
  377. 'gender' => 1, //性别
  378. ];
  379. $seatdata['seat'.$i] = json_encode($seat);
  380. }
  381. $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$partyInfo['user_id'],$seatdata);
  382. //清空房间人,聊天室
  383. //分页获取聊天室成员列表
  384. $usernames = $easemob->room_listRoomMembers($easemob_room_id,0);
  385. //批量移除聊天室成员
  386. $user_ids = [];
  387. if(!empty($usernames)){
  388. foreach($usernames as $username){
  389. foreach($username as $key => $val)
  390. {
  391. $user_ids[] = $val;
  392. }
  393. }
  394. }
  395. if(!empty($user_ids)){
  396. $easemob->room_removeRoomMembers($easemob_room_id,$user_ids);
  397. }
  398. }
  399. $this->success();
  400. }
  401. /**
  402. * 获取派对列表排序
  403. */
  404. public function getPartyList() {
  405. $order = input('orderby','new');
  406. $this->reset_all_party();
  407. //
  408. $orderby = 'party.party_hot desc, party.id desc';
  409. $where = [];
  410. if($order == 'recommend'){
  411. $where['party.is_recommend'] = 1;
  412. }
  413. if($order == 'follow'){
  414. $follow_party_ids = Db::name('party_follow')->where('user_id',$this->auth->id)->column('party_id');
  415. $where['party.id'] = ['IN',$follow_party_ids];
  416. }
  417. $where['party.status'] = 1; //正常
  418. //$where['party.is_online'] = 1; //在线
  419. $where['party.is_close'] = 0; //未关闭
  420. $where['party.is_public'] = 1; //是否公开:1=是,0=否
  421. $field = 'party.id,party.user_id,party.room_type,party.party_id,party.party_name,party.party_hot,
  422. party.party_logo,party.party_pass,party.party_type,party.easemob_room_id,type.name as type_name';
  423. $list = Db::name('party')->alias('party')
  424. ->join('party_type type','party.party_type = type.id','LEFT')
  425. ->field($field)->where($where)->order($orderby)->autopage()->select();
  426. $list = list_domain_image($list,['party_logo']);
  427. $resdata = [];
  428. if (!empty($list)) {
  429. $roomService = new RoomService();
  430. foreach($list as $k => $v) {
  431. $mod = isset($v["party_type"]) ? intval($v["party_type"])%5 : 1;
  432. //房间用户列表
  433. $userDataResult = $roomService->getPartyUserList(['party_id'=>$v['id']]);
  434. $userDataRes = isset($userDataResult['data']) ? $userDataResult['data'] : [];
  435. $partyUserList = [
  436. 'user_list' => isset($userDataRes['member_list']) ? $userDataRes['member_list'] : [],
  437. 'online_num' => isset($userDataRes['online_num']) ? $userDataRes['online_num'] : 0,
  438. ];
  439. $resdata[] = [
  440. "id" => $v["id"],
  441. "user_id" => $v["user_id"],
  442. "room_type" => $v['room_type'],
  443. "party_id" => $v["party_id"],
  444. "r_id" => $v["party_id"],
  445. "party_name" => $v["party_name"],
  446. "party_hot" => $v['party_hot'],
  447. "party_logo" => $v["party_logo"],
  448. "party_pass" => $v["party_pass"] ? $v["party_pass"]:"",
  449. "party_type" => $v['type_name'],
  450. "party_type_color" => $mod == 0?5:$mod,
  451. "easemob_room_id" => $v['easemob_room_id'],
  452. "party_user" => $partyUserList,
  453. ];
  454. }
  455. }
  456. $this->success("获取成功!",$resdata);
  457. }
  458. //把所有房间的信息,都放到redis里去
  459. private function reset_all_party(){
  460. //rediskey:派对热度
  461. $redisPartyRankList = $this->redis->zRevRange("partyRank",0,-1,true);
  462. //rediskey:派对热度
  463. $redisLiveRankList = $this->redis->zRevRange("liveRank",0,-1,true);
  464. $roomService = new RoomService();
  465. if(!$redisPartyRankList) {//party
  466. $roomParams = ['room_type' => 1];
  467. $roomPartyRes = $roomService->roomRedis($roomParams);
  468. $redisPartyRankList = $roomPartyRes['data'];
  469. }
  470. if(!$redisLiveRankList) {//live
  471. $roomParams = ['room_type' => 2];
  472. $roomLiveRes = $roomService->roomRedis($roomParams);
  473. $redisLiveRankList = $roomLiveRes['data'];
  474. }
  475. }
  476. /**
  477. * 获取派对用户排序,(日榜,周榜,月榜) X (魅力榜,财富榜)
  478. */
  479. /*public function getPartyUserRank_old() {
  480. $room_type = input('room_type',1); // 房间类型
  481. $party_id = input("party_id");// 派对ID
  482. if (!$party_id) $this->error(__('Invalid parameters'));
  483. $res = [];
  484. // 获取今天
  485. $day = date("Ymd");
  486. // 获取本周第一天
  487. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  488. // 获取本月第一天
  489. $monthday = date("Ym01");
  490. $userModel = new \app\common\model\User();
  491. // 获取条数
  492. $num = 50;
  493. // 获取50条魅力排行日记录
  494. $getday = $this->redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_get_".$party_id.":".$day."d",0,$num-1,true);
  495. $res['getRankListDay'] = $userModel->rankList($getday);
  496. // 获取50条财富排行日记录
  497. $today = $this->redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_to_".$party_id.":".$day."d",0,$num-1,true);
  498. $res['toRankListDay'] = $userModel->rankList($today);
  499. // 获取50条魅力排行周记录
  500. $getweek = $this->redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_get_".$party_id.":".$weekday."w",0,$num-1,true);
  501. $res['getRankListWeek'] = $userModel->rankList($getweek);
  502. // 获取50条财富排行周记录
  503. $toweek = $this->redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_to_".$party_id.":".$weekday."w",0,$num-1,true);
  504. $res['toRankListWeek'] = $userModel->rankList($toweek);
  505. // 获取50条魅力排行月记录
  506. $toweek = $this->redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_get_".$party_id.":".$monthday."m",0,$num-1,true);
  507. $res['getRankListMonth'] = $userModel->rankList($toweek);
  508. // 获取50条财富排行月记录
  509. $toweek = $this->redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_to_".$party_id.":".$monthday."m",0,$num-1,true);
  510. $res['toRankListMonth'] = $userModel->rankList($toweek);
  511. return $this->success("获取成功!",$res);
  512. }*/
  513. //获取派对用户排序(魅力榜,财富榜),有数值的在上,0的在下
  514. public function getPartyUserRank() {
  515. $party_id = input("party_id");// 派对ID
  516. if (!$party_id) $this->error(__('Invalid parameters'));
  517. $userModel = new \app\common\model\User();
  518. // 获取所有魅力排行
  519. $getday = $this->redis->zRevRange("hourCharm_".$party_id,0,-1,true);
  520. $res['getRankListDay'] = $userModel->rankList($getday);
  521. // 获取所有财富排行
  522. $today = $this->redis->zRevRange("hourWealth_".$party_id,0,-1,true);
  523. $res['toRankListDay'] = $userModel->rankList($today);
  524. return $this->success("获取成功!",$res);
  525. }
  526. /**
  527. * 派对热度更新(已废弃)
  528. */
  529. /*public function changeUserPartyhot() {
  530. $party_id = input('party_id',0,"intval"); // 派对ID
  531. $room_type = input('room_type',1); // 房间类型
  532. $party_hot = input('party_hot'); // 房间热度(正数表示提高的热度值,负数表示降低的热度值)
  533. if (!$party_id || !$party_hot) {
  534. $this->error(__('Invalid parameters'));
  535. }
  536. // 更新热度
  537. $this->redis->zIncrBy($this->roomTypeArr[$room_type]."Rank", $party_hot, $party_id);
  538. return $this->success("更新成功!");
  539. }*/
  540. /**
  541. * 更新主持人和麦位前四位至首页房间排行
  542. */
  543. public function addUserPositionToParty() {
  544. $party_id = input('party_id',0,"intval"); // 直播间ID
  545. $user_id = input('user_id',0,"intval"); // 用户ID
  546. $upOrdown = input('upordown'); // 上下麦:1=上麦-1=下麦
  547. $room_type = input('room_type',1); // 房间类型
  548. $avatar = input('avatar'); // 用户头像 (upOrdown参数为-1时可以不传)
  549. $position = input('position'); // 麦位置:0=支持人,1=1号麦,2=2号麦,3=3号麦,4=4号麦
  550. if (!$party_id || !$user_id || !in_array($position,[0,1,2,3,4,5,6,7,8]) || !in_array($upOrdown,[1,-1])) {
  551. $this->error(__('Invalid parameters'));
  552. }
  553. if($upOrdown == 1) {
  554. // 先完成所有麦上记录
  555. \app\common\model\UserOnsiteTime::update(["status"=>2],["user_id"=>$user_id]);
  556. // 保存上麦记录
  557. $data = [];
  558. $data["user_id"] = $user_id;
  559. $data["party_id"] = $party_id;
  560. $data["onsite_time"] = time();
  561. \app\common\model\UserOnsiteTime::insert($data);
  562. }
  563. if($upOrdown == -1) {
  564. // 更新下麦时间
  565. $update = [];
  566. $update["offsite_time"] = time();
  567. $update["status"] = 2;
  568. \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
  569. }
  570. if(in_array($position,[5,6,7,8])) return $this->success("设置成功!");
  571. $redisData = $this->redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  572. if($redisData) {
  573. $partyInfo = json_decode($redisData,true);
  574. if($upOrdown == 1) {
  575. // 删掉已有头像,防止重复
  576. $partyuser = isset($partyInfo["party_user"])?$partyInfo["party_user"]:"";
  577. if(is_array($partyuser)) foreach($partyuser as $k => $v) if($v === $avatar) unset($partyInfo["party_user"][$k]);
  578. $partyInfo["party_user"][$position] = $avatar;
  579. } else {
  580. if(isset($partyInfo["party_user"])) unset($partyInfo["party_user"][$position]);
  581. }
  582. // sort($partyInfo["party_user"]);
  583. $this->redis->set($this->roomTypeArr[$room_type]."_".$party_id,json_encode($partyInfo));
  584. }
  585. return $this->success("设置成功!");
  586. }
  587. /**
  588. * 获取派对在线人数列表
  589. */
  590. public function getOnlieList() {
  591. $party_id = input('party_id',0,"intval"); // 直播间ID 逻辑ID
  592. if (!$party_id) {
  593. $this->error(__('Invalid parameters'));
  594. }
  595. $res = $this->redis->hGetAll("online_".$party_id);
  596. $user_ids = [];$userList = [];
  597. if($res) $user_ids = array_values($res);
  598. // 获取用户列表信息
  599. if($user_ids){
  600. $userList = Db::name('user')->alias('user')->field("user.id,user.avatar,user.nickname,user.level,user.gender,user.charm_level,user.wealth_level,charm.image as charm_image,charm.color as charm_color,wealth.image as wealth_image,wealth.color as wealth_color")
  601. ->join('user_config_charm charm','user.charm_level = charm.level','LEFT')
  602. ->join('user_config_wealth wealth','user.wealth_level = wealth.level','LEFT')
  603. ->where(["user.id"=>["in",$user_ids],'user.is_stealth'=>0])
  604. ->autopage()->select();
  605. $userList = list_domain_image($userList,['avatar','charm_image','wealth_image']);
  606. }
  607. $this->success("获取成功!",$userList);
  608. }
  609. /** 连续进房提示
  610. * @param $user_id
  611. * @param $party_id
  612. * @return int
  613. */
  614. private function getUserJoinPartyDays($user_id, $party_id)
  615. {
  616. $days = 1;
  617. $joinPartyDays = $this->redis->hGet("joinParty_days",$user_id."-".$party_id);
  618. if ($joinPartyDays){
  619. $joinPartyDaysArr = explode('-',$joinPartyDays);
  620. $oldTime = (int)$joinPartyDaysArr[0];
  621. $todayStartTime = strtotime(date('Y-m-d'));//今天0点
  622. $yesterdayStartTime = strtotime(date("Y-m-d",strtotime("-1 day")));//昨天开始时间戳
  623. $todayEndTime = $todayStartTime+24 * 60 * 60-1;//今天结束时间戳
  624. //昨天登录过,+1
  625. if ($yesterdayStartTime <= $oldTime && $oldTime < $todayStartTime){
  626. $days = (int)$joinPartyDaysArr[1];
  627. $days++;
  628. $this->redis->hSet("joinParty_days", $user_id . "-" . $party_id, time().'-'. $days);
  629. }elseif($todayStartTime <= $oldTime && $oldTime <= $todayEndTime){
  630. //今天登录过 days
  631. $days = (int)$joinPartyDaysArr[1];
  632. } else {
  633. $this->redis->hSet("joinParty_days", $user_id . "-" . $party_id, time().'-1');
  634. }
  635. }else{
  636. $this->redis->hSet("joinParty_days", $user_id . "-" . $party_id, time().'-1');
  637. }
  638. return $days;
  639. }
  640. /**
  641. * 加入派对
  642. */
  643. public function joinParty() {
  644. $party_id = input('party_id',0,"intval"); // 直播间ID 逻辑ID
  645. $room_type = input("room_type",1);//
  646. $party_pass = input("party_pass");//
  647. if (!$party_id || !in_array($room_type,[1,2])) {
  648. $this->error(__('Invalid parameters'));
  649. }
  650. $user_id = $this->auth->id;
  651. // 判断派对密码
  652. $partyInfo = Db::name('party')->where('id',$party_id)->find();
  653. if($partyInfo) {
  654. if($partyInfo["status"] != 1) $this->error("该房间已被解散!");
  655. // if($partyInfo["is_close"] == 1) $this->error("该房间已被关闭!");
  656. //if($partyInfo["status"] != 1) $this->error("该房间为预创建房间,请联系管理员正式开通!");
  657. $partyManage = $this->redis->hGet("party_manage_".$party_id,$user_id."-1");
  658. if(isset($partyInfo["party_pass"]) && $partyInfo["party_pass"] && $partyInfo["user_id"] != $user_id && empty($partyManage)) {
  659. if(($party_pass != $partyInfo["party_pass"] || strlen($party_pass) != 4) && $this->auth->is_manager == 0) {
  660. $this->error("派对密码不正确!");
  661. }
  662. }
  663. // 公会管理员和公会长激活派对厅
  664. /* $guildInfo = \app\common\model\Guild::where(['user_id' => $partyInfo['user_id'], 'status' => 1])->find();
  665. if ($guildInfo) {
  666. // 获取公会管理员
  667. $guildMemberInfo = \app\common\model\GuildMember::where(["user_id" => $user_id, "guild_id" => $guildInfo['id'], 'status' => 1])->find();
  668. if ($guildMemberInfo && $guildMemberInfo['role'] == 0 && $partyInfo['is_online'] == 0) {
  669. //$this->error("当前直播已结束!");//这种情况理论上不存在
  670. }
  671. }*/
  672. // // 如果是房主自己进入房间,则更新用户 为在线状态
  673. // if ($partyInfo["user_id"] == $user_id) {
  674. // if ($room_type == 2)
  675. // \app\common\model\User::update(["is_live" => 1], ["id" => $partyInfo["user_id"]]);
  676. // }
  677. } else {
  678. $this->error("派对信息获取失败!");
  679. }
  680. // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
  681. $lsetList = [];
  682. for($i=1;$i<=4;$i++) {
  683. $hgetlist = $this->redis->hGet("party_manage_".$party_id,$user_id."-".$i);
  684. $hgetlist = unserialize($hgetlist);
  685. if($hgetlist){
  686. $restime = time() - intval($hgetlist["createtime"]);
  687. }else{
  688. $restime = 0;
  689. }
  690. // 房管
  691. if($hgetlist && $i == 1) {
  692. $lsetList["manage_restime"] = "";
  693. //重新设置成管理员
  694. $this->setGroupAdmin($partyInfo['easemob_room_id'],$user_id,1);
  695. }
  696. // 禁言
  697. if($hgetlist && $i == 2 && $restime < $hgetlist["time"]) {
  698. $lsetList["manage_notalk"] = $restime;
  699. }
  700. // 拉黑,管理员不能被拉黑
  701. if($hgetlist && $i == 3 && $restime < $hgetlist["time"] && $this->auth->is_manager == 0) {
  702. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  703. $this->error(__('您已被该房间拉黑,解除时间:'.$restime));
  704. break;
  705. }
  706. // 踢出,管理员不能被踢出
  707. if($hgetlist && $i == 4 && $restime < $hgetlist["time"] && $this->auth->is_manager == 0) {
  708. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  709. $this->error(__('您已被该房间踢出,解除时间:'.$restime));
  710. break;
  711. }
  712. }
  713. //下移
  714. $this->redis->zAdd("party_user_".$party_id,$user_id,$user_id);
  715. $this->redis->hSet("online_".$party_id,$user_id,$user_id); //新增的
  716. // 判断当前用户是否存在在直播间通过切换过来的
  717. $livingUserPartyId = $this->redis->hGet("livingUser", $user_id);
  718. if ($livingUserPartyId) {
  719. if($livingUserPartyId != $party_id){
  720. // 扣除房间在线人数
  721. $this->redis->HDel("online_" . $livingUserPartyId, $user_id);
  722. //首页用户头像
  723. $this->redis->zRem("party_user_".$livingUserPartyId, $user_id);
  724. // 扣除在线用户在房间情况
  725. $this->redis->hDel("livingUser", $user_id);
  726. }
  727. }
  728. // 记录在线用户在房间情况
  729. $this->redis->hSet("livingUser", $user_id, $party_id);
  730. //下移
  731. // 获取用户魅力值。大概率没用了
  732. // 获取用户排行榜前三名头像。大概率没用了
  733. // 获取是否被当前用户关注
  734. $lsetList["is_follow"] = 0;
  735. $where = [];
  736. $where["user_id"] = $user_id;
  737. $where["party_id"] = $party_id;
  738. if(Db::name('party_follow')->where($where)->find()) {
  739. $lsetList["is_follow"] = 1;
  740. }
  741. if(isset($partyInfo["type_name"]) && $partyInfo["type_name"]) {
  742. // $partyInfo["type_name"] = $partyInfo["type_name"];
  743. } else {
  744. $partyInfo["type_name"] = "普通房";
  745. }
  746. $partyInfo["party_hot"] = changeW($partyInfo["party_hot"]);
  747. $partyInfo['is_new'] = $partyInfo["status"] == 0 ? 1 : 0;
  748. $partyInfo['join_days'] = $this->getUserJoinPartyDays($user_id,$party_id);
  749. $lsetList["partyInfo"] = $partyInfo;
  750. //声网三个token
  751. $lsetList['shengwang_token'] = $this->shengwang_token_private($partyInfo['easemob_room_id']);
  752. //[环信] 更新聊天室自定义属性 在线用户人数
  753. $easemob = new Easemob();
  754. $matedata = [
  755. 'online_user_num' => count($this->redis->hGetAll("online_".$party_id)),
  756. ];
  757. $easemob->room_setRoomCustomAttributeForced($partyInfo['easemob_room_id'],$partyInfo['user_id'],$matedata);
  758. return $this->success("加入成功!",$lsetList);
  759. }
  760. private function creater_joinParty($party_id,$easemob_room_id,$party_user_id) {
  761. $user_id = $this->auth->id;
  762. // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
  763. $lsetList = [];
  764. for($i=1;$i<=4;$i++) {
  765. $hgetlist = $this->redis->hGet("party_manage_".$party_id,$user_id."-".$i);
  766. $hgetlist = unserialize($hgetlist);
  767. // 房管
  768. if($hgetlist && $i == 1) {
  769. $lsetList["manage_restime"] = "";
  770. //重新设置成管理员
  771. $this->setGroupAdmin($easemob_room_id,$user_id,1);
  772. }
  773. }
  774. //下移
  775. $this->redis->zAdd("party_user_".$party_id,$user_id,$user_id);
  776. $this->redis->hSet("online_".$party_id,$user_id,$user_id); //新增的
  777. // 判断当前用户是否存在在直播间通过切换过来的
  778. $livingUserPartyId = $this->redis->hGet("livingUser", $user_id);
  779. if ($livingUserPartyId) {
  780. if($livingUserPartyId != $party_id){
  781. // 扣除房间在线人数
  782. $this->redis->HDel("online_" . $livingUserPartyId, $user_id);
  783. //首页用户头像
  784. $this->redis->zRem("party_user_".$livingUserPartyId, $user_id);
  785. // 扣除在线用户在房间情况
  786. $this->redis->hDel("livingUser", $user_id);
  787. }
  788. }
  789. // 记录在线用户在房间情况
  790. $this->redis->hSet("livingUser", $user_id, $party_id);
  791. //下移
  792. //[环信] 更新聊天室自定义属性 在线用户人数
  793. $easemob = new Easemob();
  794. $matedata = [
  795. 'online_user_num' => count($this->redis->hGetAll("online_".$party_id)),
  796. ];
  797. $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_user_id,$matedata);
  798. return true;
  799. }
  800. /**
  801. * 判断是否被禁言
  802. */
  803. public function isNotalk() {
  804. $party_id = input('party_id',0,"intval"); // 直播间ID 逻辑ID
  805. $user_id = input('user_id',0,"intval"); // 用户ID 逻辑ID
  806. if (!$user_id || !$party_id) {
  807. $this->error(__('Invalid parameters'));
  808. }
  809. // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
  810. $lsetList = [];
  811. $lsetList["is_notalk"] = 0;
  812. $lsetList["notalk_time"] = 0;
  813. $hgetlist = $this->redis->hGet("party_manage_".$party_id,$user_id."-2");
  814. if(!$hgetlist){
  815. return $this->success("获取成功!",$lsetList);
  816. }
  817. $hgetlist = unserialize($hgetlist);
  818. $restime = time() - intval($hgetlist["createtime"]);
  819. // 禁言
  820. if($hgetlist && $restime < $hgetlist["time"]) {
  821. $lsetList["is_notalk"] = 1;
  822. $lsetList["notalk_time"] = $restime;//已经禁了N秒
  823. }
  824. return $this->success("获取成功!",$lsetList);
  825. }
  826. /**
  827. * 退出派对
  828. */
  829. public function outParty() {
  830. $party_id = input('party_id',0,"intval"); // 直播间ID
  831. $room_type = input("room_type",1);//
  832. if (!$party_id) {
  833. $this->error(__('Invalid parameters'));
  834. }
  835. $userId = $this->auth->id;
  836. $this->redis->zRem("party_user_".$party_id,$userId);
  837. // 处理online_party_id
  838. $this->redis->HDel("online_" . $party_id, $this->auth->id);
  839. // 扣除在线用户在房间情况
  840. $this->redis->hDel("livingUser", $this->auth->id);
  841. //下麦
  842. $key = "party_seat_".$party_id;
  843. $seats = $this->redis->hGetAll($key);
  844. foreach($seats as $seat_num => $seatuserid){
  845. if($seatuserid == $userId){
  846. $this->redis->HDel($key, $seat_num);
  847. }
  848. }
  849. // 更新房间在线状态
  850. $partyInfo = $this->redis->get($this->roomTypeArr[$room_type].'_'.$party_id);
  851. if ($partyInfo) {
  852. $partyInfo = json_decode($partyInfo, true);
  853. $memCount = count($this->redis->hGetAll("online_" . $party_id));
  854. if ($memCount <= 0) {
  855. $partyInfo["is_online"] = 0;
  856. $this->redis->set($this->roomTypeArr[$room_type].'_'.$party_id,json_encode($partyInfo));
  857. \app\common\model\Party::update(["is_online" => 0], ["id" => $party_id]);
  858. }
  859. //[环信] 更新聊天室自定义属性 在线用户人数
  860. $easemob = new Easemob();
  861. $matedata = [
  862. 'online_user_num' => count($this->redis->hGetAll("online_".$party_id)),
  863. ];
  864. $easemob->room_setRoomCustomAttributeForced($partyInfo['easemob_room_id'],$partyInfo['user_id'],$matedata);
  865. //清除这个人点的歌,前台自己处理了
  866. /*$easemob_room_id = $partyInfo['easemob_room_id'];
  867. $singlist = $easemob->room_getRoomCustomAttribute($easemob_room_id,['waitsing_list']);
  868. $singlist = json_decode($singlist['waitsing_list'],true);
  869. if(!empty($singlist)){
  870. foreach($singlist as $key => $sing){
  871. if($sing['userNo'] == $userId){
  872. unset($singlist[$key]);
  873. }
  874. }
  875. //重新排序
  876. $singlist = $this->waitsing_array_column_sort($singlist);
  877. //重新设置
  878. $matedata = [
  879. 'waitsing_list' => json_encode($singlist),
  880. ];
  881. $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$partyInfo['user_id'],$matedata);
  882. }*/
  883. }
  884. $this->success("退出成功!",[]);
  885. }
  886. /**
  887. * 派对内搜索用户
  888. */
  889. public function searchUserParty() {
  890. $u_id = input('u_id',0,"intval"); // 用户u_id
  891. $party_id = input('party_id',0,"intval"); // 直播间ID
  892. // $userids = $this->redis->zRange("party_user_".$party_id,0,-1,true);
  893. // $useridArr = [];
  894. // if($userids)foreach($userids as $k => $v) $useridArr[$v] = $k; // 因为array_slip 不能交换数字啊
  895. // $userid = isset($useridArr[$u_id])?$useridArr[$u_id]:0;
  896. $userModel = new \app\common\model\User();
  897. $where = [];
  898. $where["u_id"] = $u_id;
  899. $userInfo = $userModel->field("id,u_id,avatar,nickname,level,gender")->where($where)->select();
  900. return $this->success("查询成功!",$userInfo);
  901. }
  902. /**
  903. * 设置冠名
  904. */
  905. public function setNaming() {
  906. $party_id = input('party_id',0,"intval"); // 直播间ID
  907. $user_id = input('user_id',0,"intval"); // 用户ID
  908. $type = input('type',1); // 1:设置 0:取消设置
  909. if (!$party_id || !$user_id || ($type != 1 && $type != 0)) {
  910. $this->error(__('Invalid parameters'));
  911. }
  912. $partyModel = new \app\common\model\Party();
  913. $data = [];
  914. $where = [];
  915. $where["id"] = $party_id;
  916. $partyInfo = $partyModel->where(["id"=>$party_id])->find();
  917. $getredisPartyInfo = $this->redis->get($this->roomTypeArr[$partyInfo->room_type].'_'.$party_id);
  918. $redisPartyInfo = json_decode($getredisPartyInfo,true);
  919. if($type == 1) {
  920. $data["naming"] = $user_id;
  921. // 冠名
  922. $userInfo = \app\common\model\User::field("id,nickname,avatar")->where(["id"=>$user_id])->find($user_id);
  923. $redisPartyInfo["naming"] = $userInfo;
  924. } else {
  925. $data["naming"] = 0;
  926. $redisPartyInfo["naming"] = [];
  927. }
  928. $this->redis->set($this->roomTypeArr[$partyInfo->room_type].'_'.$party_id,json_encode($redisPartyInfo));
  929. $res = $partyModel->update($data,$where);
  930. if($res !== false) {
  931. $this->success("操作成功!");
  932. } else {
  933. $this->error("网络错误,请稍后重试!");
  934. }
  935. }
  936. /**
  937. * 派对关注
  938. */
  939. public function followparty() {
  940. $party_id = input('party_id',0,"intval"); // 直播间ID
  941. if (!$party_id) {
  942. $this->error(__('Invalid parameters'));
  943. }
  944. $user_id = $this->auth->id;
  945. // 添加记录
  946. $data = [];
  947. $data["user_id"] = $user_id;
  948. $data["party_id"] = $party_id;
  949. if(Db::name('party_follow')->where($data)->find()) {
  950. $res = Db::name('party_follow')->where($data)->delete();
  951. $this->success("已取消关注");
  952. }
  953. $data["createtime"] = time();
  954. $res = Db::name('party_follow')->insert($data);
  955. $this->success("已关注");
  956. }
  957. /**
  958. * 派对收藏列表
  959. */
  960. public function cellectionPartyList() {
  961. $page = input('page',1); // 分页
  962. $pageNum = input('pageNum',10); // 分页
  963. // 分页搜索构建
  964. $pageStart = ($page-1)*$pageNum;
  965. $partycellectionModel = new \app\common\model\PartyCellection();
  966. $where = [];
  967. $where["a.user_id"] = $this->auth->id;
  968. $where["r.room_type"] = 1;
  969. $list = $partycellectionModel->alias("a")
  970. ->field("a.party_id,r.party_logo,r.party_hot,r.party_id as r_id,r.party_name,t.id as party_type_id,t.name as party_type")
  971. ->where($where)
  972. ->join("hx_party r","a.party_id = r.id")
  973. ->join("hx_party_type t","t.id = r.party_type","left")
  974. ->limit($pageStart,$pageNum)
  975. ->select();
  976. if($list) {
  977. $users = [];
  978. foreach($list as $k => $v) {
  979. $users[$v["party_id"]] = $v["party_hot"];
  980. }
  981. $partyModel = new \app\common\model\Party();
  982. $resultInfo = $partyModel->getPatyInfoByPartyId($users,"party",0,0,1,0,20,0);
  983. $this->success("获取成功!",$resultInfo);
  984. }
  985. return $this->success("获取成功!",$list);
  986. }
  987. /**
  988. * 获取派对信息
  989. */
  990. public function getPartyInfo() {
  991. $party_id = input('party_id',0,"intval"); // 直播间ID
  992. if (!$party_id) {
  993. $this->error(__('Invalid parameters'));
  994. }
  995. $user_id = $this->auth->id;
  996. $partyModel = new \app\common\model\Party();
  997. $userModel = new \app\common\model\User();
  998. // 获取主体信息
  999. $where = [];
  1000. $where["a.id"] = $party_id;
  1001. $partyInfo = $partyModel->alias("a")
  1002. ->field("a.id,a.user_id,a.party_id,a.party_name,a.party_hot,a.party_logo,a.party_notice,a.party_notice_detail,a.on_model,a.background,a.is_public,
  1003. rt.id as party_type,rt.name as type_name")
  1004. ->join("hx_party_type rt","rt.id = a.party_type", "left")
  1005. ->where($where)
  1006. ->find();
  1007. if($partyInfo) {
  1008. $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1;
  1009. $partyInfo["party_type_color"] = $mod == 0?5:$mod;
  1010. if(isset($partyInfo["type_name"]) && $partyInfo["type_name"]) {
  1011. // $partyInfo["type_name"] = $partyInfo["type_name"];
  1012. } else {
  1013. $partyInfo["type_name"] = "普通房";
  1014. }
  1015. // 获取是否被当前用户关注
  1016. $partyInfo["is_follow"] = 0;
  1017. $where = [];
  1018. $where["user_id"] = $user_id;
  1019. $where["party_id"] = $party_id;
  1020. if(Db::name('party_follow')->where($where)->find()) {
  1021. $partyInfo["is_follow"] = 1;
  1022. }
  1023. // 获取房主信息
  1024. $where = [];
  1025. $where["id"] = $partyInfo["user_id"];
  1026. $userInfo = $userModel->field("avatar,nickname")->where($where)->find();
  1027. // 获取技能信息
  1028. $partyInfo["userInfo"] = $userInfo;
  1029. $partyInfo["party_hot"] = changeW($partyInfo["party_hot"]);
  1030. }
  1031. $this->success("获取成功!",$partyInfo);
  1032. }
  1033. /**
  1034. * 派对设置
  1035. */
  1036. public function setParty() {
  1037. $party_id = input('party_id',0,"intval"); // 直播间ID
  1038. $room_type = input('room_type',1); // 房间类型:1=公会,2=个人k歌
  1039. if (!$party_id || !$room_type) {
  1040. $this->error(__('Invalid parameters'));
  1041. }
  1042. // 派对名称
  1043. // 派对logo/封面
  1044. // 派对密码
  1045. // 使用场景
  1046. // 是否关闭公屏:1=是,0=否
  1047. // 上麦模式:1=自由模式,2=麦序模式
  1048. // 派对背景
  1049. // 是否公开:1=是,0=否
  1050. $field_array = ['party_name','party_logo','party_pass'/*,'party_type'*/,'is_screen','on_model','background','is_public','party_notice'];
  1051. $data = [];
  1052. foreach($field_array as $key => $field){
  1053. //前端传不了post,改了
  1054. if(!request()->has($field,'post')){
  1055. continue;
  1056. }
  1057. /*if(!input('?'.$field)){
  1058. continue;
  1059. }*/
  1060. $newone = input($field);
  1061. $data[$field] = $newone;
  1062. }
  1063. if(isset($data['party_pass'])){
  1064. if(empty($data['party_pass'])){
  1065. $data['party_pass'] = '';
  1066. }
  1067. if(!empty($data['party_pass']) && strlen($data['party_pass']) != 4) {
  1068. $this->error("房间密码必须为四位!");
  1069. }
  1070. }
  1071. $partyModel = new \app\common\model\Party();
  1072. $where = [];
  1073. $where["id"] = $party_id;
  1074. $res = $partyModel->update($data,$where);
  1075. if($res) {
  1076. // 获取派对类型
  1077. //if($party_type) $data["type_name"] = \app\common\model\PartyType::where(["id"=>$party_type])->value("name");
  1078. // 存redis 房间信息
  1079. $partyInfo = $this->redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  1080. if($partyInfo) {
  1081. $partyInfo = json_decode($partyInfo,true);
  1082. $partyInfo = array_replace($partyInfo,$data);
  1083. $this->redis->set($this->roomTypeArr[$room_type]."_".$party_id,json_encode($partyInfo));
  1084. }
  1085. //[环信]初始化房间,初始化自定义属性
  1086. $matedata = [];
  1087. if(isset($data['party_name'])){
  1088. $matedata['party_name'] = $data['party_name'];
  1089. }
  1090. if(isset($data['party_logo'])){
  1091. $matedata['party_logo'] = $data['party_logo'];
  1092. }
  1093. if(isset($data['is_public'])){
  1094. $matedata['is_public'] = $data['is_public'];
  1095. }
  1096. if(isset($data['background'])){
  1097. $matedata['background'] = $data['background'];
  1098. }
  1099. if(isset($data['party_notice'])){
  1100. $matedata['party_notice'] = $data['party_notice'];
  1101. }
  1102. if(!empty($matedata)){
  1103. $easemob = new Easemob();
  1104. $rs = $easemob->room_setRoomCustomAttributeForced($partyInfo['easemob_room_id'],$partyInfo['user_id'],$matedata);
  1105. }
  1106. $this->success("房间设置成功!",$data);
  1107. } else {
  1108. $this->error("网络错误,请稍后重试!");
  1109. }
  1110. }
  1111. /**
  1112. * 获取派对背景
  1113. */
  1114. public function getDefaultBackground() {
  1115. $room_type = input('room_type',1); // 房间类型
  1116. if (!in_array($room_type,[1,2])) {
  1117. $this->error(__('Invalid parameters'));
  1118. }
  1119. $this->success("获取成功!",\app\common\model\PartyBackground::where(["room_type"=>$room_type])->select());
  1120. }
  1121. //环信聊天室设置管理员,type=1设置,type=0移除
  1122. private function setGroupAdmin($easemob_room_id,$user_id,$type = 1)
  1123. {
  1124. $easemob = new Easemob();
  1125. if($type == 1){
  1126. $easemob->room_promoteRoomAdmin($easemob_room_id,$user_id);
  1127. }else{
  1128. $easemob->room_demoteRoomAdmin($easemob_room_id,$user_id);
  1129. }
  1130. }
  1131. /**
  1132. * 派对管理设置
  1133. */
  1134. public function partyManageSet() {
  1135. $party_id = input('party_id',0,"intval"); // 直播间ID
  1136. $user_id = input('user_id',0,"intval"); // 用户ID
  1137. $item = input('item'); // 项目:1=房管,2=禁言,3=拉黑,4=踢出
  1138. $time = input('time'); // 限制时间(单位:秒):0=永久
  1139. if (!$party_id || !$user_id || !in_array($item,[1,2,3,4])) {
  1140. $this->error(__('Invalid parameters'));
  1141. }
  1142. //2=禁言,3=拉黑,4=踢出 ,都要有时间
  1143. if($item>1 && $time<=0) {
  1144. $this->error(__('时间设置有误'));
  1145. }
  1146. //不能对房主恶意操作
  1147. $partyinfo = \app\common\model\Party::where('id', $party_id)->field('user_id,easemob_room_id')->find();
  1148. if ($partyinfo['user_id'] == $user_id && in_array($item, [2, 3, 4])) {
  1149. $this->error("您当前无权限操作!");
  1150. }
  1151. //只有房主才能加管理员
  1152. if($item == 1 && $this->auth->id != $partyinfo['user_id']){
  1153. $this->error('只有房主才能设置管理员');
  1154. }
  1155. // 获取用户信息
  1156. $userInfo = \app\common\model\User::field("avatar,nickname,gender")->where(["id"=>$user_id])->find();
  1157. if(!$userInfo) $this->error("用户信息获取失败!");
  1158. $data = [];
  1159. $data["user_id"] = $user_id;
  1160. $data["avatar"] = $userInfo->avatar;
  1161. $data["nickname"] = $userInfo->nickname;
  1162. $data["gender"] = $userInfo->gender;
  1163. $data["item"] = $item;
  1164. $data["time"] = $time;
  1165. $data["createtime"] = time();
  1166. $res = $this->redis->hSet("party_manage_".$party_id,$user_id."-".$item,serialize($data));
  1167. if ($item==1) {
  1168. $this->setGroupAdmin($partyinfo['easemob_room_id'],$user_id,1);
  1169. }
  1170. if($res !== false) {
  1171. $this->success("设置成功!",$data);
  1172. } else {
  1173. $this->error("网络错误,请稍后重试!");
  1174. }
  1175. }
  1176. /**
  1177. * 派对管理设置列表
  1178. * 仅用来给前端展示,禁言的鉴权在isNotalk接口,拉黑与提出的鉴权在joinparty接口
  1179. */
  1180. public function partyManageSetList() {
  1181. $party_id = input('party_id',0,"intval"); // 直播间ID
  1182. $item = input('item',1,"intval"); // 项目:1=房管,2=禁言,3=拉黑,4=踢出
  1183. if (!$party_id || !in_array($item,[1,2,3,4])) {
  1184. $this->error(__('Invalid parameters'));
  1185. }
  1186. $time = time();
  1187. $hget=$this->redis->hGetAll("party_manage_".$party_id);
  1188. $list=array();
  1189. foreach($hget as $key=>$val) {
  1190. if(substr($key,-2) == "-".$item){
  1191. array_push($list,unserialize($val));
  1192. }
  1193. }
  1194. if($list) {
  1195. foreach($list as $k => $v) if(bcadd($v["createtime"],$v["time"]) <= $time && $v["item"] > 1) unset($list[$k]);
  1196. if($list) $list = array_values($list);
  1197. }
  1198. $this->success("获取成功!",$list);
  1199. }
  1200. /**
  1201. * 派对管理设置移除
  1202. */
  1203. public function partyManageSetDel() {
  1204. $id = input('user_id',0,"intval"); // userid
  1205. $party_id = input('party_id',0,"intval"); // 房间ID
  1206. $item = input('item',1,"intval"); // 项目:1=房管,2=禁言,3=拉黑,4=踢出
  1207. if (!$id || !in_array($item,[1,2,3,4])) {
  1208. $this->error(__('Invalid parameters'));
  1209. }
  1210. $partyinfo = \app\common\model\Party::where('id', $party_id)->field('user_id,easemob_room_id')->find();
  1211. //只有房主才能加管理员
  1212. if($item == 1 && $this->auth->id != $partyinfo['user_id']){
  1213. $this->error('只有房主才能免除管理员');
  1214. }
  1215. $res = $this->redis->hDel("party_manage_".$party_id,$id."-".$item);
  1216. if ($item==1) {
  1217. $this->setGroupAdmin($partyinfo['easemob_room_id'],$id,0);
  1218. }
  1219. if($res !== false) {
  1220. $this->success("移除成功!",$res);
  1221. } else {
  1222. $this->error("网络错误,请稍后重试!");
  1223. }
  1224. }
  1225. /**
  1226. * 更新派对公告
  1227. */
  1228. public function savePartyNotice() {
  1229. $party_id = input('party_id',0,"intval"); // 直播间ID
  1230. $room_type = input('room_type',1); // 房间类型:1=派对2=直播
  1231. $party_notice = input('party_notice'); // 公告标题
  1232. $party_notice_detail = input('party_notice_detail'); // 公告内容
  1233. if (!$party_id || !$party_notice || !$party_notice_detail) {
  1234. $this->error(__('Invalid parameters'));
  1235. }
  1236. $partyModel = new \app\common\model\Party();
  1237. $where = [];
  1238. $where["id"] = $party_id;
  1239. $data = [];
  1240. $data["party_notice"] = $party_notice;
  1241. $data["party_notice_detail"] = $party_notice_detail;
  1242. $res = $partyModel->update($data,$where);
  1243. if($res) {
  1244. // 存redis 房间信息
  1245. $partyInfo = $this->redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  1246. if($partyInfo) {
  1247. $partyInfo = json_decode($partyInfo,true);
  1248. $partyInfo = array_replace($partyInfo,$data);
  1249. $this->redis->set($this->roomTypeArr[$room_type]."_".$party_id,json_encode($partyInfo));
  1250. }
  1251. $this->success("更新成功!",$res);
  1252. } else {
  1253. $this->error("网络错误,请稍后重试!");
  1254. }
  1255. }
  1256. /**
  1257. * 开始排麦
  1258. */
  1259. public function addLineUp() {
  1260. $party_id = input('party_id',0,"intval"); // 直播间ID
  1261. $mai_id = input('mai_id',"1"); // 麦位置
  1262. if (!$party_id) {
  1263. $this->error(__('Invalid parameters'));
  1264. }
  1265. $userInfo = $this->auth->getUserinfo();
  1266. $userid = $userInfo['id'];
  1267. // 获取 房间信息
  1268. $partyUser = \app\common\model\Party::where(['id'=>$party_id])->value("user_id");
  1269. if(!$partyUser) $this->error(__('房间信息未找到!'));
  1270. // $is_home = $partyUser == $userInfo->id?1:0;
  1271. $data = unserialize($this->redis->hGet("party_lineup",$party_id));
  1272. $data[$userid]["user_id"] = $userInfo['id'];
  1273. $data[$userid]["avatar"] = $userInfo['avatar'];
  1274. $data[$userid]["mai_id"] = $mai_id;
  1275. $data[$userid]["nickname"] = $userInfo['nickname'];
  1276. // $data["is_home"] = $is_home;
  1277. // $data[$userid]["level"] = $userInfo['level'];
  1278. $data[$userid]["gender"] = $userInfo['gender'];
  1279. $res = false;
  1280. $data && $res = $this->redis->hSet("party_lineup",$party_id,serialize($data));
  1281. $data = array_values($data);
  1282. if($res !== false) {
  1283. $this->success("设置成功!",$data);
  1284. } else {
  1285. $this->error("网络错误,请稍后重试!");
  1286. }
  1287. }
  1288. /**
  1289. * 取消排麦
  1290. */
  1291. public function cancelLineUp() {
  1292. $party_id = input('party_id',0,"intval"); // 直播间ID
  1293. $user_id = input('user_id',0); // 直播间ID
  1294. $is_empty = input('is_empty',0,"intval"); // 是否清空排麦列表 1=清空,0=不清空
  1295. $is_baomai = input('is_baomai',0,'intval'); //是否抱麦
  1296. if (!$party_id) {
  1297. $this->error(__('Invalid parameters'));
  1298. }
  1299. $data=unserialize($this->redis->hGet("party_lineup",$party_id));
  1300. $baomai_user = [];
  1301. if($data && $is_empty != 1) {
  1302. foreach($data as $k => $v) {
  1303. if($v["user_id"] == $user_id) {
  1304. $baomai_user = $v;
  1305. unset($data[$k]);
  1306. break;
  1307. }
  1308. }
  1309. }
  1310. // unset($data[$userid]);
  1311. if($is_empty == 1) $data = [];
  1312. $this->redis->hSet("party_lineup",$party_id,serialize($data));
  1313. //抱麦
  1314. if($is_empty != 1 && $is_baomai == 1 && !empty($baomai_user)){
  1315. $this->baomai($party_id,$user_id,$baomai_user);
  1316. }
  1317. //
  1318. $datas = [];
  1319. is_array($data) && $datas=array_values($data);
  1320. if($datas) {
  1321. $this->success("移除成功!",$datas);
  1322. } else {
  1323. $this->success("移除成功!",[]);
  1324. }
  1325. }
  1326. private function baomai($party_id,$user_id,$baomai_user){
  1327. $partyinfo = \app\common\model\Party::where('id', $party_id)->field('user_id,easemob_room_id')->find();
  1328. if(empty($partyinfo)){
  1329. return false;
  1330. }
  1331. //获取所有麦位,假设8个
  1332. $easemob = new Easemob();
  1333. $seatlist = $easemob->room_getRoomCustomAttribute($partyinfo['easemob_room_id'],['seat0','seat1','seat2','seat3','seat4','seat5','seat6','seat7']);
  1334. $newseat = [
  1335. 'charm' => 0, //红心,魅力值
  1336. 'isMaster' => false, // 是否是房主
  1337. 'headUrl' => $baomai_user['avatar'], // 头像
  1338. 'userNo' => $baomai_user['user_id'], // 座位上用户no
  1339. 'rtcUid' => $baomai_user['user_id'], // 座位上用户id,与rtc的userId一致
  1340. 'name' => $baomai_user['nickname'], // 座位上用户昵称
  1341. 'seatIndex' => -1, // 座位编号
  1342. 'chorusSongCode' => '', // 是否合唱
  1343. 'isAudioMuted' => 1, // 是否静音
  1344. 'isVideoMuted' => 0, // 是否开启视频
  1345. 'checked' => false, // 用于送礼物选择用户
  1346. 'isUsed' => true, // 用于送礼物选择用户
  1347. 'gender' => $baomai_user['gender'], //性别
  1348. ];
  1349. if(empty($seatlist)){
  1350. $newseat['seatIndex'] = 0;
  1351. $matedata['seat0'] = $newseat;
  1352. }else{
  1353. //第一遍轮询麦位,尝试找到这个人,如果找到在任何一个麦位,立刻return
  1354. foreach($seatlist as $k => $seat){
  1355. $seat = json_decode($seat,true);
  1356. //找到当前用户所在的麦位
  1357. if(isset($seat['rtcUid']) && !empty($seat['rtcUid']) && $seat['rtcUid'] == $user_id){
  1358. return true;
  1359. }
  1360. }
  1361. //第二遍轮询麦位,找一个空麦位,放进去
  1362. $matedata = [];
  1363. foreach($seatlist as $k => $seat){
  1364. $seat = json_decode($seat,true);
  1365. //找到当前用户所在的麦位
  1366. if(isset($seat['rtcUid']) && empty($seat['rtcUid'])){
  1367. //dump(substr($k,-1));
  1368. $newseat['seatIndex'] = substr($k,-1);
  1369. //初始化这个麦位
  1370. $matedata = [
  1371. $k => json_encode($newseat),
  1372. ];
  1373. }
  1374. }
  1375. }
  1376. //重置房间在线人数
  1377. if(!empty($matedata)){
  1378. $easemob->room_setRoomCustomAttributeForced($partyinfo['easemob_room_id'],$partyinfo['user_id'],$matedata);
  1379. }
  1380. return true;
  1381. }
  1382. /**
  1383. * 排麦列表
  1384. */
  1385. public function lineUpList() {
  1386. $party_id = input('party_id',0,"intval"); // 直播间ID
  1387. if (!$party_id) {
  1388. $this->error(__('Invalid parameters'));
  1389. }
  1390. $data = $this->redis->hGet("party_lineup",$party_id);
  1391. $dataArr = unserialize($data);
  1392. $datas = [];
  1393. is_array($dataArr) && $datas=array_values($dataArr);
  1394. if($datas) {
  1395. $this->success("获取成功!",$datas);
  1396. } else {
  1397. $this->success("获取成功!",[]);
  1398. }
  1399. }
  1400. /**
  1401. * 获取派对类型
  1402. */
  1403. public function getPatyType() {
  1404. $room_type = input("room_type",1);//
  1405. if (!in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
  1406. $partytypeModel = new \app\common\model\PartyType();
  1407. $partytypeList = $partytypeModel->where(["room_type"=>$room_type])->select();
  1408. $this->success("获取成功!",$partytypeList);
  1409. }
  1410. /**
  1411. * 判断派对是否设置过密码
  1412. */
  1413. public function getPatyIspass() {
  1414. $party_id = input("party_id");// 派对ID
  1415. $room_type = input("room_type",1);//
  1416. $is_miniprogram = input("is_miniprogram",0);//
  1417. if (!$party_id) $this->error(__('Invalid parameters'));
  1418. $user_id = $this->auth->id;
  1419. // 存redis 房间信息
  1420. $partyInfo = $this->redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  1421. if($partyInfo) {
  1422. $partyInfo = json_decode($partyInfo,true);
  1423. } else {
  1424. $partyModel = new \app\common\model\Party();
  1425. $partyInfo = $partyModel->field("id,user_id,party_pass")->where(["id"=>$party_id])->find();
  1426. if(!$partyInfo) {
  1427. $this->error(__('房间信息获取失败!'));
  1428. }
  1429. }
  1430. $data = [];
  1431. $data["status"] = 0;
  1432. $data["is_pass"] = $partyInfo["party_pass"]?1:0;
  1433. $partyManage = $this->redis->hGet("party_manage_".$party_id,$user_id."-1");
  1434. if($partyInfo["user_id"] == $user_id || $this->auth->is_manager == 1 || !empty($partyManage)){ $data["is_pass"] = 0;}
  1435. if($is_miniprogram == 1) { // 小程序单独处理
  1436. // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
  1437. $lsetList = [];
  1438. for($i=1;$i<=4;$i++) {
  1439. $hgetlist = $this->redis->hGet("party_manage_".$party_id,$user_id."-".$i);
  1440. $hgetlist = unserialize($hgetlist);
  1441. $restime = time() - intval($hgetlist["createtime"]);
  1442. // 房管
  1443. if($hgetlist && $i == 1) $lsetList["manage_restime"] = "";
  1444. // 禁言
  1445. if($hgetlist && $i == 2 && $restime < $hgetlist["time"]) $lsetList["manage_notalk"] = $restime;
  1446. // 拉黑
  1447. if($hgetlist && $i == 3 && $restime < $hgetlist["time"]) {
  1448. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  1449. $lsetList["manage_black"] = $restime;
  1450. $lsetList["tips"] = '您已被该房间拉黑,解除时间:'.$restime;
  1451. // $this->error(__('您已被该房间拉黑,解除时间:'.$restime));
  1452. break;
  1453. }
  1454. // 踢出
  1455. if($hgetlist && $i == 4 && $restime < $hgetlist["time"]) {
  1456. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  1457. $lsetList["manage_takeout"] = $restime;
  1458. $lsetList["tips"] = '您已被该房间踢出,解除时间:'.$restime;
  1459. // $this->error(__('您已被该房间踢出,解除时间:'.$restime));
  1460. break;
  1461. }
  1462. }
  1463. if($lsetList) {
  1464. $data["status"] = 1;
  1465. $data["hgetlist"] = $lsetList;
  1466. }
  1467. }
  1468. $this->success("获取成功!",$data);
  1469. }
  1470. /**
  1471. * 获取房间gif表情分类
  1472. */
  1473. public function getPartyGifType()
  1474. {
  1475. $list = \app\common\model\PartyGifType::field("id,name,image")->order("weigh", "asc")->select();
  1476. $this->success("获取成功!", $list);
  1477. }
  1478. /**
  1479. * 获取房间gif表情列表
  1480. */
  1481. public function getPartGifList() {
  1482. $this->success("获取成功!",\app\common\model\PartyGif::field("id,gif_image")->order("weight","asc")->select());
  1483. }
  1484. /**
  1485. * 获取房间头像gif表情列表
  1486. */
  1487. public function getPartHeadgifList() {
  1488. $this->success("获取成功!",\app\common\model\PartyHeadgif::field("id,name,gif_image")->order("weight","asc")->select());
  1489. }
  1490. /**
  1491. * 全麦/单独赠送礼物
  1492. */
  1493. public function giveGiftToYou() {
  1494. // 是否背包赠送: 1=是,0=否
  1495. $is_back = input("is_back",0);
  1496. // 接口防并发
  1497. if($is_back){
  1498. if (!$this->apiLimit(50, 1000)) {
  1499. //1000毫秒50次
  1500. $this->error('休息一下吧');
  1501. }
  1502. }else{
  1503. if (!$this->apiLimit(10, 1000)) {
  1504. //1000毫秒10次
  1505. $this->error('休息一下吧');
  1506. }
  1507. }
  1508. //送礼物权限
  1509. /*if($this->auth->power['give_gift'] == 1){
  1510. $this->error('您已被限制:赠送礼物,请联系管理员');
  1511. }*/
  1512. //接收参数
  1513. $user_ids = input("user_id");// 赠送对象用户id
  1514. $seat_ids = input("seat_id");// 赠送对象麦位id
  1515. $gift_id = input("gift_id",0,'intval');// 礼物ID。如果是背包赠送,则是gift_back表的id,这样不合理,但是已经不好改了
  1516. $party_id = input("party_id",0,'intval');// 派对ID
  1517. $room_type = input('room_type',1,'intval'); // 房间类型
  1518. $number = input("number",1,'intval');// 赠送数量
  1519. if (!$user_ids || $seat_ids == '' || !in_array($is_back,[0,1]) || !$gift_id || !$number || !in_array($room_type,[1,2]))
  1520. {
  1521. $this->error(__('Invalid parameters'));
  1522. }
  1523. if(!$party_id){
  1524. $this->error('只有房间内能送礼物');
  1525. }
  1526. //处理参数
  1527. $user_id_arr = explode(",",$user_ids);
  1528. $seat_id_arr = explode(",",$seat_ids);
  1529. $userCount = count($user_id_arr);
  1530. $seatCount = count($seat_id_arr);
  1531. if($userCount != $seatCount){
  1532. $this->error();
  1533. }
  1534. $userauthid = $this->auth->id;
  1535. $money_to_jewel = config('site.money_to_jewel') ?: 10000; //余额兑换金币
  1536. // 不可以赠送给自己
  1537. if(in_array($userauthid,$user_id_arr)) $this->error("不可以赠送给自己!");
  1538. $backGiftId = 0; //背包礼物表的 gift_id
  1539. $boxgiftInfo = [];
  1540. //每个人都能得到的礼物价值
  1541. $giftValue = 0;
  1542. //每个人都能得到的礼物价值
  1543. $getValue = 0;
  1544. //热度值
  1545. $hotValue = 0;
  1546. if($is_back == 1) {
  1547. // 获取背包礼物信息
  1548. $giftbackInfo = Db::name('gift_back')->field('gift_id')->where('id',$gift_id)->find();
  1549. if(!$giftbackInfo){
  1550. $this->error("背包礼物获取失败");
  1551. }
  1552. $backGiftId = $giftbackInfo['gift_id'];
  1553. // 随机获取一个礼物
  1554. $allCount = $number*$userCount;
  1555. $giftbackList = Db::name('gift_back')->field('id,value,name,image,gif_image,number')->where(["gift_id"=>$backGiftId,"user_id"=>$userauthid,'is_use'=>0])->limit($allCount)->order('id asc')->select();
  1556. $giftInfo = isset($giftbackList[0]) ? $giftbackList[0] : [];
  1557. $gift_realinfo = Db::name('gift')->field('is_baobi')->where('id',$backGiftId)->find();
  1558. $giftInfo['is_baobi'] = $gift_realinfo ? $gift_realinfo['is_baobi'] : 0;
  1559. $giftcount = 0;
  1560. $giftList = [];
  1561. if(!empty($giftbackList)) {
  1562. foreach($giftbackList as $k => $v) {
  1563. $giftList[$k] = $v;
  1564. $giftcount += $v["number"];
  1565. if($giftcount >= $allCount) {
  1566. break;
  1567. }
  1568. }
  1569. }
  1570. if($giftcount < $allCount)
  1571. {
  1572. $this->error("背包数量不足");
  1573. }
  1574. $giftValue = $giftInfo["value"] * $number;
  1575. $getValue = $giftValue;
  1576. $giftCountValue = $giftInfo["value"] * $number * $userCount;
  1577. } else {
  1578. // 获取礼物信息
  1579. $giftInfo = Db::name('gift')->field('id,value,name,image,special as gif_image,is_baobi')->where('id',$gift_id)->find();
  1580. if (!$giftInfo) {
  1581. $this->error("请选择礼物!");
  1582. }
  1583. $giftValue = $giftInfo["value"] * $number;
  1584. $getValue = $giftValue;
  1585. // 判断当前用户余额,这里不需要锁表,钱包操作会锁
  1586. $giftCountValue = $giftInfo["value"] * $number * $userCount;
  1587. $user_jewel = model('wallet')->getWallet($this->auth->id,'jewel');
  1588. if($user_jewel < $giftCountValue){
  1589. $this->error("您的金币余额不足!");
  1590. }
  1591. }
  1592. //此时 $giftValue,$getValue,$hotValue是相等的(除了盒子礼物特殊)
  1593. $hotValue = $getValue;
  1594. //进行抽点设置
  1595. $partyInfo = null;
  1596. $partyInfo = \app\common\model\Party::field("id,room_type,party_name,party_hot,user_id,platRate,guilderRate,easemob_room_id")->where(["id"=>$party_id])->find();
  1597. // 获取系统配置信息
  1598. $platRate = $partyInfo->platRate; // 平台抽成百分比
  1599. $guilderRate = $partyInfo->guilderRate; // 房主抽成百分比,包括公会房主,普通房房主
  1600. //爆币礼物单独比例
  1601. if($is_back != 1){
  1602. if(isset($giftInfo['is_baobi']) && $giftInfo['is_baobi'] == 1){
  1603. $platRate = config('site.baobi_gift_platrate');
  1604. $guilderRate = config('site.baobi_gift_guilderrate');
  1605. }
  1606. }
  1607. //getValue削减
  1608. //
  1609. $returnData = [];
  1610. Db::startTrans();
  1611. try {
  1612. // 获取当天零点
  1613. $day = date("Ymd");
  1614. // 获取本周第一天
  1615. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  1616. // 获取本月第一天
  1617. $monthday = date("Ym01");
  1618. $allVal = 0;
  1619. $i = 0;
  1620. //用户大循环
  1621. foreach($user_id_arr as $user_id_key => $user_id) {
  1622. if($is_back == 1) {
  1623. $b=0;
  1624. foreach($giftList as $k => $v) {
  1625. for($a=1;$a<=$v["number"];$a++) {
  1626. $b++;
  1627. $num = $v["number"] - $a;
  1628. if($num > 0) {
  1629. $res1 = Db::name('gift_back')->where(["id"=>$v["id"]])->setDec("number");
  1630. } else {
  1631. $res1 = Db::name('gift_back')->where(["id"=>$v["id"]])->delete();
  1632. }
  1633. if($b == $number) break;
  1634. }
  1635. }
  1636. } else {
  1637. $res1 = true;
  1638. // 扣除当前用户金币余额
  1639. $rs_wallet = model('wallet')->lockChangeAccountRemain($userauthid, $giftValue, '-', 0, "赠送礼物:'" . $giftInfo["name"] . "',扣除" . $giftValue . "金币!", 3,'jewel');
  1640. if($rs_wallet['status'] == false){
  1641. Db::rollback();
  1642. $this->error($rs_wallet['msg']);
  1643. }
  1644. }
  1645. // 添加礼物赠送记录表
  1646. $data = [];
  1647. $data["user_id"] = $userauthid;
  1648. $data["user_to_id"] = $user_id;
  1649. $data["seat_num"] = $seat_id_arr[$user_id_key];
  1650. $data["party_id"] = $party_id;
  1651. $data["gift_id"] = $backGiftId > 0 ? $backGiftId : $gift_id;
  1652. $data["gift_give_type"] = $is_back ? 1 : 2;
  1653. $data["gift_name"] = $giftInfo["name"];
  1654. $data["gift_gif_image"] = $giftInfo["image"];
  1655. $data["number"] = $number;
  1656. $data["price"] = $giftInfo["value"];
  1657. $data["value"] = $giftValue;
  1658. //每个礼物都要计算平台抽成和房主抽成
  1659. $data['platvalue'] = bcmul($platRate/100 ,$data["value"],2);//平台抽成
  1660. $data['guildervalue'] = bcmul($guilderRate/100 ,$data["value"],2);// 房主抽成
  1661. $data['guildermoney'] = bcdiv($data['guildervalue'],$money_to_jewel,2);
  1662. $data['getvalue'] = bcsub(bcsub($data["value"] ,$data['platvalue'],2),$data['guildervalue'],2);//减去抽成剩余价值
  1663. $data['task_status'] = 0;
  1664. $data["createtime"] = time();
  1665. $res5 = Db::name('gift_user_party')->insertGetId($data);
  1666. //大礼物飘屏
  1667. //$this->bigGiftNotice($this->auth->nickname,$touserInfo['nickname'],$partyInfo,$data);
  1668. // 添加获赠用户余额
  1669. if($data['getvalue'] > 0){
  1670. $getMoney = bcdiv($data['getvalue'],$money_to_jewel,2);
  1671. if($getMoney > 0){
  1672. $rs_wallet = model('wallet')->lockChangeAccountRemain($user_id,$getMoney,'+',0,"{$this->auth->nickname}送你{$giftInfo['name']}x{$number}",101,'money');
  1673. if($rs_wallet['status'] == false){
  1674. Db::rollback();
  1675. $this->error($rs_wallet['msg']);
  1676. }
  1677. }
  1678. }
  1679. // 增加房主抽成
  1680. if ($partyInfo && $data['guildervalue'] > 0) {
  1681. $guilderMoney = bcdiv($data['guildervalue'],$money_to_jewel,2);
  1682. if($guilderMoney > 0){
  1683. $touserInfo = Db::name('user')->field('nickname')->where('id',$user_id)->find();
  1684. $rs_wallet = model('wallet')->lockChangeAccountRemain($partyInfo->user_id,$guilderMoney,'+',0,"{$this->auth->nickname}送礼物{$giftInfo['name']}x{$number}给{$touserInfo['nickname']},房间礼物抽成",102,'money');
  1685. if($rs_wallet['status'] == false){
  1686. Db::rollback();
  1687. $this->error($rs_wallet['msg']);
  1688. }
  1689. }
  1690. }
  1691. if ($res1 && $res5) {
  1692. $i++;
  1693. if($party_id > 0) {
  1694. // 添加redis记录做魅力排行榜日榜用
  1695. // $this->redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $day . "d", $hotValue, $user_id);
  1696. // 添加redis记录做魅力排行榜周榜用
  1697. // $this->redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $weekday . "w", $hotValue, $user_id);
  1698. // 添加redis记录做魅力排行榜月榜用
  1699. // $this->redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $monthday . "m", $hotValue, $user_id);
  1700. // 添加redis记录做财富排行榜日榜用
  1701. // $this->redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $day . "d", $giftValue, $userauthid);
  1702. // 添加redis记录做财富排行榜周榜用
  1703. // $this->redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $weekday . "w", $giftValue, $userauthid);
  1704. // 添加redis记录做财富排行榜月榜用
  1705. // $this->redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $monthday . "m", $giftValue, $userauthid);
  1706. // tcp 更新用户魅力值
  1707. $this->redis->zIncrBy("hourCharm_".$party_id, $hotValue, $user_id);
  1708. // tcp 更新用户贡献值
  1709. $this->redis->zIncrBy("hourWealth_".$party_id, $hotValue, $userauthid);
  1710. //更新麦位魅力值
  1711. //$this->updateSeatCharm($partyInfo['easemob_room_id'],$seat_id_arr[$user_id_key],$hotValue,$partyInfo);
  1712. // 如果是主播,则添加魅力值记录做榜单统计
  1713. /*if($room_type == 2) {
  1714. $data = [];
  1715. $data["user_id"] = $user_id;
  1716. $data["party_id"] = $party_id;
  1717. $data["charm"] = $hotValue;
  1718. $data["createtime"] = time();
  1719. \app\common\model\UserCharmRank::insert($data);
  1720. }*/
  1721. }
  1722. //用户经验升级
  1723. /*$getempirical = config("site.getempirical");
  1724. $getempirical = $getempirical * $hotValue;
  1725. // 获取用户贵族信息
  1726. $noble = \app\common\model\User::getUserNoble($this->auth->id);
  1727. if(isset($noble["noble_on"]) && $noble["noble_on"] == 1) {
  1728. $getempirical = $getempirical + $getempirical * ($noble["explain"]/100);
  1729. }
  1730. // 增加用户经验值
  1731. $res = \app\common\model\User::addEmpirical($this->auth->id,$getempirical);
  1732. if ($res){
  1733. $this->auth->level = $res->level;
  1734. }
  1735. //增加被送礼物用户的魅力等级
  1736. $res_charm = \app\common\model\User::add_charm_level($user_id,$giftValue);
  1737. // +exp
  1738. \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
  1739. */
  1740. // +message
  1741. \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number." 价值 ".$giftValue ." 金币");
  1742. //增加送礼用户的财富等级
  1743. $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$giftValue);
  1744. $allVal = $allVal + $hotValue;
  1745. }
  1746. }
  1747. //爆币,背包不爆币
  1748. if($is_back != 1){
  1749. if(isset($giftInfo['is_baobi']) && $giftInfo['is_baobi'] == 1){
  1750. $res_baobi = $this->baobi($this->auth->id,$data["gift_id"],$giftCountValue,$giftInfo["value"]);
  1751. if($res_baobi === false){
  1752. Db::rollback();
  1753. $this->error('爆币失败');
  1754. }elseif($res_baobi === true){
  1755. $returnData['baobi_total'] = 0;
  1756. $returnData['baobi_beilv'] = 0;
  1757. }else{
  1758. //爆币了
  1759. $returnData['baobi_total'] = $res_baobi['baobi_total'];
  1760. $returnData['baobi_beilv'] = $res_baobi['baobi_beilv'];
  1761. }
  1762. }
  1763. }
  1764. // 获取用户魅力值。大概率没用了
  1765. // tcp 更新房间热度
  1766. //$partyHot = $this->updatePartyHot($partyInfo, $allVal, $room_type);
  1767. // 如果是派对,则添加派对热度值记录做榜单统计
  1768. /*if($room_type == 1) {
  1769. $data = [];
  1770. $data["party_id"] = $party_id;
  1771. $data["hot"] = $allVal;
  1772. $data["createtime"] = time();
  1773. \app\common\model\PartyHot::insert($data);
  1774. }*/
  1775. //增加送礼用户的财富等级
  1776. // $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$allVal);
  1777. // tcp 获取房间用户周前三名
  1778. $this->getPartyUserTop($partyInfo, $room_type);
  1779. if($i == $userCount) {
  1780. $returnData["image"] = $giftInfo["image"];
  1781. $returnData["gif_image"] = $giftInfo["gif_image"];
  1782. // 增加抽点记录
  1783. Db::commit();
  1784. $this->success("赠送成功!",$returnData);
  1785. } else {
  1786. $this->success("赠送失败!");
  1787. }
  1788. } catch (ValidateException $e) {
  1789. Db::rollback();
  1790. $this->error($e->getMessage());
  1791. } catch (PDOException $e) {
  1792. Db::rollback();
  1793. $this->error($e->getMessage());
  1794. } catch (Exception $e) {
  1795. Db::rollback();
  1796. $this->error($e->getMessage());
  1797. }
  1798. }
  1799. //gift_id必须是爆币礼物才可以
  1800. public function baobi($user_id,$gift_id,$pay_total,$giftInfo_value){
  1801. //奖项参数
  1802. $conf_arr = Db::name('gift_baobi_config')->where('gift_id',$gift_id)->select();
  1803. if(empty($conf_arr)){
  1804. return true;
  1805. }
  1806. //用户今天的爆币情况,与消费情况,不用区分具体哪个爆币礼物
  1807. $today_start = strtotime(date('Y-m-d'));
  1808. $today_end = $today_start + 86399;
  1809. $map = [
  1810. 'user_id' => $user_id,
  1811. 'createtime' => ['BETWEEN',[$today_start,$today_end]],
  1812. ];
  1813. $today_data = Db::name('gift_baobi_log')->field('IFNULL(sum(pay_total),0) as today_pay_total,IFNULL(sum(baobi_total),0) as today_baobi_total')->where($map)->find();
  1814. //dump($today_data);
  1815. $baobi_zhisun_bili = config('site.baobi_zhisun_bili');
  1816. if($today_data['today_baobi_total'] >= bcdiv(bcmul($today_data['today_pay_total'],$baobi_zhisun_bili,2),100,2)){
  1817. //爆币比消费还高了,不用抽奖了,记录个日志,返回。这里的日志仅用来记录今日消费 sum(pay_total)
  1818. $data = [];
  1819. $data['user_id'] = $user_id;
  1820. $data['gift_id'] = $gift_id;
  1821. $data['baobi_id'] = 0;
  1822. $data['beilv'] = 0;
  1823. $data['rate'] = 0;
  1824. $data['pay_total'] = $pay_total;
  1825. $data['baobi_total'] = 0;
  1826. $data['createtime'] = time();
  1827. $log_id = Db::name('gift_baobi_log')->insertGetId($data);
  1828. if(!$log_id){
  1829. return false;
  1830. }
  1831. return true;
  1832. }
  1833. //概率新数组
  1834. $gailv = [];
  1835. $bei = 100; //小数变整数
  1836. foreach ($conf_arr as $key=>$value)
  1837. {
  1838. $gailv[$value['id']] = $value['rate']*$bei;
  1839. }
  1840. //dump($gailv);
  1841. //奖项新数组
  1842. $conf_column = [];
  1843. foreach ($conf_arr as $key=>$value)
  1844. {
  1845. $conf_column[$value['id']] = $value;
  1846. }
  1847. //dump($conf_column);
  1848. //抽
  1849. $rid = $this->getRand($gailv); //根据概率获取奖项id
  1850. //dump($rid);
  1851. //返回中奖结果
  1852. $result = $conf_column[$rid];
  1853. //爆币金额
  1854. $baobi_total = bcmul($giftInfo_value,$result['beilv'],0);
  1855. //写入爆币记录,不论有没有钱。全都写入其实是为了方便查日志,比在money_log里找范围更小,而且可删除
  1856. $data = [];
  1857. $data['user_id'] = $user_id;
  1858. $data['gift_id'] = $gift_id;
  1859. $data['baobi_id'] = $result['id'];
  1860. $data['beilv'] = $result['beilv'];
  1861. $data['rate'] = $result['rate'];
  1862. $data['pay_total'] = $pay_total;
  1863. $data['baobi_total'] = $baobi_total;
  1864. $data['createtime'] = time();
  1865. $log_id = Db::name('gift_baobi_log')->insertGetId($data);
  1866. if(!$log_id){
  1867. return false;
  1868. }
  1869. //直接给用户钱
  1870. if($baobi_total > 0){
  1871. $rs_wallet = model('wallet')->lockChangeAccountRemain($user_id,$baobi_total,'+',0,'送礼物爆币'.$result['beilv'].'倍',21,'jewel');
  1872. if($rs_wallet['status'] === false){
  1873. return false;
  1874. }
  1875. //返回爆币金额
  1876. return [
  1877. 'baobi_total' => $baobi_total,
  1878. 'baobi_beilv' => $result['beilv'],
  1879. ];
  1880. }
  1881. //默认成功
  1882. return true;
  1883. }
  1884. //概率获得算法
  1885. private function getRand($proArr) {
  1886. //概率数组的总概率精度
  1887. $proSum = array_sum($proArr);
  1888. $key = rand(1, $proSum);
  1889. // echo $key;
  1890. $result = 0;
  1891. $now = 0;
  1892. foreach ($proArr as $k=>$v)
  1893. {
  1894. $now = $now + $v;
  1895. if($key<=$now)
  1896. {
  1897. $result = $k;
  1898. break;
  1899. }
  1900. }
  1901. unset ($proArr);
  1902. return $result;
  1903. }
  1904. //某房间内礼物列表
  1905. public function getPartyGiftLog(){
  1906. $party_id = input('party_id',0);
  1907. $list = Db::name('gift_user_party')->alias('log')
  1908. ->field('log.gift_name,log.gift_gif_image,log.number,log.value,log.guildermoney,log.createtime,user.nickname as give_nickname,b.nickname as get_nickname')
  1909. ->join('user','log.user_id = user.id','LEFT')
  1910. ->join('user b','log.user_to_id = b.id','LEFT')
  1911. ->where('log.party_id',$party_id)->order('log.id desc')->autopage()->select();
  1912. $list = list_domain_image($list,['gift_gif_image']);
  1913. foreach($list as $key => &$val){
  1914. $val['createtime'] = get_last_time($val['createtime']);
  1915. }
  1916. $this->success('success',$list);
  1917. }
  1918. // /**
  1919. // * 播放动效
  1920. // */
  1921. // public function play($party_id,$type,$value,$number) {
  1922. // // 发送tcp
  1923. // $tcpArr = [];
  1924. // $tcpArr['type'] = "play";
  1925. // $tcpArr['data'] = [
  1926. // 'party_id' => $party_id,
  1927. // 'type' => $type,
  1928. // 'value' => $value,
  1929. // 'number' => $number,
  1930. // ];
  1931. // $tcpJson = json_encode($tcpArr);
  1932. // $client = stream_socket_client(config("tcp"));
  1933. // $buffer2 = base64_encode($tcpJson)."****";
  1934. // fwrite($client, $buffer2);
  1935. // }
  1936. /**
  1937. * 更新派对信息(热度等)
  1938. */
  1939. private function updatePartyHot($partyInfo,$hotValue,$room_type) {
  1940. // $partyInfo = \app\common\model\Party::where(['id'=>$party_id])->find();
  1941. if(!$partyInfo) return $hotValue;
  1942. $party_hot = $partyInfo->party_hot > 0 ? $partyInfo->party_hot:0;
  1943. $party_hot_value = $party_hot + $hotValue;
  1944. $party_hot_value = $party_hot_value > 0 ? $party_hot_value : 0;
  1945. if($party_hot_value != $party_hot) {
  1946. // 保存数据
  1947. $partyInfo->party_hot = $party_hot_value;
  1948. $partyInfo->save();
  1949. // 更新redis 加入缓存排序
  1950. $this->redis->zAdd($this->roomTypeArr[$room_type]."Rank", $partyInfo['party_hot'], $partyInfo["id"]);
  1951. // 更新redis 加入缓存
  1952. $redPartyInfo = $this->redis->get($this->roomTypeArr[$room_type]."_".$partyInfo["id"]);
  1953. if($redPartyInfo) {
  1954. $redPartyInfo = json_decode($redPartyInfo,true);
  1955. $redPartyInfo["party_hot"] = $party_hot_value;
  1956. $this->redis->set($this->roomTypeArr[$room_type]."_".$partyInfo["id"],json_encode($redPartyInfo));
  1957. }
  1958. }
  1959. return $party_hot_value;
  1960. }
  1961. /**
  1962. * 用户赠送礼物后房间内用户排行,财富榜前三名
  1963. */
  1964. private function getPartyUserTop($party_info,$room_type) {
  1965. // 获取当天零点
  1966. $userModel = new \app\common\model\User();
  1967. // 获取条数
  1968. $num = 3;
  1969. // 获取3条财富排行记录
  1970. $getweek = $this->redis->zRevRange("hourWealth_".$party_info['id'],0,$num-1,true);
  1971. $userList = $userModel->rankList($getweek);
  1972. $avatarArr = [];
  1973. if($userList) {
  1974. foreach($userList as $k => $v) {
  1975. $v["jewel"] > 0 && $avatarArr[] = $v;
  1976. }
  1977. // 加入缓存做备份
  1978. $this->redis->hSet("user_jewel_top3",$party_info['id'],json_encode($avatarArr));
  1979. }
  1980. return $avatarArr;
  1981. //[环信]更新财富榜前3。放到异步了
  1982. }
  1983. /**
  1984. * 单个房间魅力值清零
  1985. */
  1986. public function partyClearCharm() {
  1987. $party_id = input("party_id");// 派对ID
  1988. $userId = input("user_id", 0);// 用户ID
  1989. if($party_id <= 0) {
  1990. $this->error("请输入派对ID");
  1991. }
  1992. if ($userId) {
  1993. $this->redis->zRem("hourCharm_" . $party_id, $userId);
  1994. } else {
  1995. $this->redis->del("hourCharm_" . $party_id);
  1996. }
  1997. $this->success("操作成功!");
  1998. }
  1999. //获取某房间内某个用户的魅力值
  2000. //上麦时候初始化小红心用的
  2001. public function getPartyUserCharm(){
  2002. $party_id = input("party_id");// 派对ID
  2003. $userId = input("user_id", 0);// 用户ID
  2004. $seat_num = input('seat_num',0);//麦位数字0-7
  2005. $key = "party_seat_".$party_id;
  2006. $seat_userid = $this->redis->hGet($key,$seat_num);
  2007. if($seat_userid){
  2008. $this->error('麦上有人了');
  2009. }
  2010. //轮询下麦
  2011. $key = "party_seat_".$party_id;
  2012. $seats = $this->redis->hGetAll($key);
  2013. foreach($seats as $seatnum => $seatuserid){
  2014. if($seatuserid == $userId){
  2015. $this->redis->HDel($key, $seatnum);
  2016. }
  2017. }
  2018. //上麦
  2019. $this->redis->hSet($key,$seat_num,$userId);
  2020. //获取魅力值
  2021. $users = $this->redis->zRevRange("hourCharm_".$party_id,0,-1,true);
  2022. $charm = 0;
  2023. if($users) {
  2024. foreach($users as $k => $v){
  2025. if($userId == $k){
  2026. $charm = changeW($v);
  2027. }
  2028. }
  2029. }
  2030. $this->success(1,$charm);
  2031. }
  2032. //下麦
  2033. public function seat_down(){
  2034. $party_id = input("party_id");// 派对ID
  2035. $userId = input("user_id", 0);// 用户ID
  2036. /*$seat_num = input('seat_num',0);//麦位数字0-7
  2037. $key = "party_seat_".$party_id;
  2038. $this->redis->HDel($key, $seat_num);*/
  2039. //轮询下麦
  2040. $key = "party_seat_".$party_id;
  2041. $seats = $this->redis->hGetAll($key);
  2042. foreach($seats as $seat_num => $seatuserid){
  2043. if($seatuserid == $userId){
  2044. $this->redis->HDel($key, $seat_num);
  2045. }
  2046. }
  2047. $this->success(1);
  2048. }
  2049. /**
  2050. * 获取音乐列表
  2051. */
  2052. public function getMusicList() {
  2053. $this->success("获取成功!",\app\common\model\Music::select());
  2054. }
  2055. //派对举报
  2056. public function report_party() {
  2057. $type = input('type');// 类型描述
  2058. $content = input('content');// 内容
  2059. $images = input('images');// 图片
  2060. $party_id = input('party_id');//
  2061. if (!$type || !$content || !$images || !$party_id) {
  2062. $this->error("请完成举报内容!");
  2063. }
  2064. $data = [];
  2065. $data["user_id"] = $this->auth->id;
  2066. $data["party_id"] = $party_id;
  2067. $data["type"] = $type;
  2068. $data["content"] = $content;
  2069. $data["images"] = $images;
  2070. $data["createtime"] = time();
  2071. $res = Db::name('party_report')->insertGetId($data);
  2072. if ($res) {
  2073. $this->success("举报内容提交成功!");
  2074. } else {
  2075. $this->error("网络错误,请稍后重试!");
  2076. }
  2077. }
  2078. //=============待唱歌曲操作=================
  2079. //待唱,列表
  2080. public function waitsing_list(){
  2081. $party_id = input('party_id');
  2082. $party_info = Db::name('party')->where('id',$party_id)->find();
  2083. if(empty($party_info)){
  2084. $this->error();
  2085. }
  2086. $easemob_room_id = $party_info['easemob_room_id'];
  2087. $easemob = new Easemob();
  2088. $singlist = $easemob->room_getRoomCustomAttribute($easemob_room_id,['waitsing_list']);
  2089. if(empty($singlist)){
  2090. //默认为空
  2091. $singlist['waitsing_list'] = '[]';
  2092. }
  2093. $singlist = json_decode($singlist['waitsing_list'],true);
  2094. //重新排序
  2095. $singlist = $this->waitsing_array_column_sort($singlist);
  2096. $this->success(1,$singlist);
  2097. }
  2098. //待唱,增加
  2099. public function waitsing_add(){
  2100. //查找派对
  2101. $party_id = input('party_id');
  2102. $party_info = Db::name('party')->where('id',$party_id)->find();
  2103. if(empty($party_info)){
  2104. $this->error();
  2105. }
  2106. $easemob_room_id = $party_info['easemob_room_id'];
  2107. //接收新歌
  2108. $sing_json = input('sing_json','','htmlspecialchars_decode');
  2109. $sing_json = json_decode($sing_json,true);
  2110. $sing_json['sing_no'] = createUniqueNo('s');//附加新参数:歌曲编号
  2111. $sing_json['sort'] = time();//附加新参数:排序
  2112. //获取已有列表
  2113. $easemob = new Easemob();
  2114. $singlist = $easemob->room_getRoomCustomAttribute($easemob_room_id,['waitsing_list']);
  2115. if(empty($singlist)){
  2116. //默认为空
  2117. $singlist['waitsing_list'] = '[]';
  2118. }
  2119. $singlist = json_decode($singlist['waitsing_list'],true);
  2120. //加入新歌
  2121. $singlist[] = $sing_json;
  2122. //重新排序
  2123. $singlist = $this->waitsing_array_column_sort($singlist);
  2124. //重新设置
  2125. $matedata = [
  2126. 'waitsing_list' => json_encode($singlist),
  2127. ];
  2128. $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_info['user_id'],$matedata);
  2129. //返回最新歌曲列表
  2130. $this->success(1,$singlist);
  2131. }
  2132. //根据歌曲sort字段,正序排列
  2133. private function waitsing_array_column_sort($data){
  2134. if(empty($data)){
  2135. return $data;
  2136. }
  2137. //dump($data);
  2138. $sort = array_column($data,'sort');
  2139. $sing_no = array_column($data,'sing_no');
  2140. $a = array_multisort($sort,SORT_ASC,$sing_no,$data);
  2141. //dump($data);exit;
  2142. return $data;
  2143. }
  2144. //待唱,删除
  2145. public function waitsing_delete(){
  2146. //查找派对
  2147. $party_id = input('party_id');
  2148. $party_info = Db::name('party')->where('id',$party_id)->find();
  2149. if(empty($party_info)){
  2150. $this->error();
  2151. }
  2152. $easemob_room_id = $party_info['easemob_room_id'];
  2153. //需要删除的编号
  2154. $sing_no = input('sing_no','');
  2155. //获取已有列表
  2156. $easemob = new Easemob();
  2157. $singlist = $easemob->room_getRoomCustomAttribute($easemob_room_id,['waitsing_list']);
  2158. if(empty($singlist)){
  2159. //默认为空
  2160. $singlist['waitsing_list'] = '[]';
  2161. }
  2162. $singlist = json_decode($singlist['waitsing_list'],true);
  2163. //轮询,找到,删除
  2164. foreach($singlist as $key => $sing){
  2165. if($sing['sing_no'] == $sing_no){
  2166. unset($singlist[$key]);
  2167. }
  2168. }
  2169. //重新排序
  2170. $singlist = $this->waitsing_array_column_sort($singlist);
  2171. //重新设置
  2172. $matedata = [
  2173. 'waitsing_list' => json_encode($singlist),
  2174. ];
  2175. $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_info['user_id'],$matedata);
  2176. //返回最新歌曲列表
  2177. $this->success(1,$singlist);
  2178. }
  2179. //待唱,置顶
  2180. public function waitsing_top(){
  2181. //查找派对
  2182. $party_id = input('party_id');
  2183. $party_info = Db::name('party')->where('id',$party_id)->find();
  2184. if(empty($party_info)){
  2185. $this->error();
  2186. }
  2187. $easemob_room_id = $party_info['easemob_room_id'];
  2188. //需要置顶的编号
  2189. $sing_no = input('sing_no','');
  2190. //获取已有列表
  2191. $easemob = new Easemob();
  2192. $singlist = $easemob->room_getRoomCustomAttribute($easemob_room_id,['waitsing_list']);
  2193. if(empty($singlist)){
  2194. //默认为空
  2195. $singlist['waitsing_list'] = '[]';
  2196. }
  2197. $singlist = json_decode($singlist['waitsing_list'],true);
  2198. //轮询,找到,改排序
  2199. if(!empty($singlist)){
  2200. //拿到所有排序字段,排列,取第0个
  2201. $sort = array_column($singlist,'sort');
  2202. ksort($sort);
  2203. foreach($singlist as $key => &$sing){
  2204. if($sing['sing_no'] == $sing_no){
  2205. $sing['sort'] = $sort[0] - 1;
  2206. }
  2207. }
  2208. }
  2209. //重新排序
  2210. $singlist = $this->waitsing_array_column_sort($singlist);
  2211. //重新设置
  2212. $matedata = [
  2213. 'waitsing_list' => json_encode($singlist),
  2214. ];
  2215. $easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_info['user_id'],$matedata);
  2216. //返回最新歌曲列表
  2217. $this->success(1,$singlist);
  2218. }
  2219. //轮询所有房间,挨个初始化自定义属性
  2220. public function room_task(){
  2221. $ids = Db::name('party')->select();
  2222. $easemob = new Easemob();
  2223. foreach($ids as $key => $party){
  2224. //[环信]初始化房间
  2225. $matedata = [
  2226. 'seatnum'=> $party['seatnum'],//麦位数量
  2227. 'waitsing_list' => json_encode([]),//已点歌曲列表
  2228. 'party_name' => $party['party_name'],//房名字
  2229. 'party_logo' => localpath_to_netpath($party['party_logo']),//logo
  2230. 'is_public' => $party['is_public'],//是否公开
  2231. 'room_type' => $party['room_type'],//房间类型
  2232. 'online_user_num' => 0,//当前房间在线的人
  2233. 'wealth_top3_userlist' => json_encode([]),//财富榜前3个人列表
  2234. 'background' => '',//背景图
  2235. ];
  2236. $rs = $easemob->room_setRoomCustomAttributeForced($party['easemob_room_id'],$party['user_id'],$matedata);
  2237. //[环信]初始化N个麦位
  2238. $seatdata = [];
  2239. for($i=0;$i<$party['seatnum'];$i++){
  2240. $seat = [
  2241. 'charm' => 0, //红心,魅力值
  2242. 'isMaster' => false, // 是否是房主
  2243. 'headUrl' => '', // 头像
  2244. 'userNo' => '', // 座位上用户no
  2245. 'rtcUid' => '', // 座位上用户id,与rtc的userId一致
  2246. 'name' => '', // 座位上用户昵称
  2247. 'seatIndex' => -1, // 座位编号
  2248. 'chorusSongCode' => '', // 是否合唱
  2249. 'isAudioMuted' => 1, // 是否静音
  2250. 'isVideoMuted' => 0, // 是否开启视频
  2251. 'checked' => false, // 用于送礼物选择用户
  2252. 'isUsed' => true, // 用于送礼物选择用户
  2253. 'gender' => 1, //性别
  2254. ];
  2255. //创建完房间就进入,所以房主直接在麦位1
  2256. $owner = Db::name('user')->where('id',$party['user_id'])->find();
  2257. if($i == 0){
  2258. $seat['isMaster'] = true;
  2259. $seat['headUrl'] = localpath_to_netpath($owner['avatar']);
  2260. $seat['userNo'] = $owner['id'];
  2261. $seat['rtcUid'] = $owner['id'];
  2262. $seat['name'] = $owner['nickname'];
  2263. $seat['seatIndex']= $i;
  2264. }
  2265. $seatdata['seat'.$i] = json_encode($seat);
  2266. }
  2267. $rs = $easemob->room_setRoomCustomAttributeForced($party['easemob_room_id'],$party['user_id'],$seatdata);
  2268. }
  2269. }
  2270. //显示聊天室所有自定义属性,自用工具
  2271. public function test_party_attr(){
  2272. $party_id = input('party_id',0);
  2273. $party_info = Db::name('party')->where('id',$party_id)->find();
  2274. $easemob = new Easemob();
  2275. $field = [
  2276. 'seatnum',
  2277. 'waitsing_list',
  2278. 'party_name',
  2279. 'party_logo',
  2280. 'is_public',
  2281. 'room_type',
  2282. 'online_user_num',
  2283. 'wealth_top3_userlist',
  2284. 'background',
  2285. ];
  2286. for($i=0;$i<$party_info['seatnum'];$i++){
  2287. $field[] = 'seat'.$i;
  2288. }
  2289. $all_attr = $easemob->room_getRoomCustomAttribute($party_info['easemob_room_id'],$field);
  2290. dump($all_attr);
  2291. echo '<hr>';
  2292. foreach($all_attr as $key => $val){
  2293. echo $key;
  2294. echo '<br>';
  2295. $val = json_decode($val,true);
  2296. dump($val);
  2297. echo '<hr>';
  2298. }
  2299. //
  2300. /*$matedata = [
  2301. 'background' => '1.jpg',
  2302. ];
  2303. $rs = $easemob->room_setRoomCustomAttributeForced($party_info['easemob_room_id'],$party_info['user_id'],$matedata);
  2304. dump($rs);*/
  2305. }
  2306. //============================定时任务==========================//
  2307. /**
  2308. * redis清理排行榜 并数据库备份
  2309. */
  2310. /*public function updateTops() {
  2311. // 前一天日期
  2312. $yestaday = date("Ymd",bcsub(time(),86400));
  2313. // 上个周一
  2314. $preweek = $this->firstOfWeek(date("Y-m-d H:i:s",bcsub(time(),604800)));
  2315. // 上个月一号
  2316. $monty = bcsub(date("m"),1);
  2317. if($monty < 10) $monty = "0".$monty;
  2318. $premonth = date("Y").$monty."01";
  2319. // 获取所有派对ID
  2320. $party_ids = \app\common\model\Party::where(["status"=>1])->column("id");
  2321. // 获取数据
  2322. $time = time();
  2323. if($party_ids) foreach($party_ids as $k => $v) {
  2324. $keys = [
  2325. "party_jewel_get_".$v.":".$yestaday."d",
  2326. "party_jewel_to_".$v.":".$yestaday."d",
  2327. "party_jewel_get_".$v.":".$preweek."w",
  2328. "party_jewel_to_".$v.":".$preweek."w",
  2329. "party_jewel_get_".$v.":".$premonth."m",
  2330. "party_jewel_to_".$v.":".$premonth."m",
  2331. ];
  2332. foreach($keys as $key) {
  2333. // 备份数据
  2334. $redisData = $this->redis->zRevRange($key,0,-1,true);
  2335. if($redisData) {
  2336. $keyInfo = \app\common\model\RedisTops::where(["key"=>$key])->find();
  2337. $data = ["party_id"=>$v,"key"=>$key,"value"=>json_encode($redisData),"createtime" => $time];
  2338. if(!$keyInfo) {
  2339. $res = \app\common\model\RedisTops::insert($data);
  2340. // 清理数据
  2341. $res && $this->redis->zRemRangeByRank($key,0,-1);
  2342. }
  2343. }
  2344. }
  2345. }
  2346. }*/
  2347. public function handleParty() {
  2348. return false;
  2349. $partyList = \app\common\model\Party::where('is_online',1)->select();
  2350. // $this->redis->del("online_" . 3);die;
  2351. // $this->redis->hSet("online_" . 3, 4, 4);die;
  2352. foreach ($partyList as $party){
  2353. $userId = $party['user_id'];
  2354. $roomId = $party['id'];
  2355. $this->redis->HDel("online_" . $roomId, $userId);
  2356. $this->redis->zRem("party_user_".$roomId, $userId);
  2357. // 扣除在线用户在房间情况
  2358. $this->redis->hDel("livingUser",$userId);
  2359. // // 更新房间在线状态
  2360. $partyInfo = $this->redis->get("party_" . $roomId);
  2361. if ($partyInfo) {
  2362. $partyInfo = json_decode($partyInfo, true);
  2363. $memCount = count($this->redis->hGetAll("online_" . $roomId));
  2364. if ($memCount <= 0) {
  2365. dump($roomId.'--1---');
  2366. $partyInfo["is_online"] = 0;
  2367. $this->redis->set("party_" . $roomId, json_encode($partyInfo));
  2368. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  2369. }
  2370. }
  2371. $liveInfo = $this->redis->get("live_" . $roomId);
  2372. if ($liveInfo) {
  2373. $liveInfo = json_decode($liveInfo, true);
  2374. $memCount = count($this->redis->hGetAll("online_" . $roomId));
  2375. if ($memCount <= 0) {
  2376. dump($roomId.'---2--');
  2377. $liveInfo["is_online"] = 0;
  2378. $this->redis->set("live_" . $roomId, json_encode($liveInfo));
  2379. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  2380. }else{
  2381. dump($roomId.'---3--');
  2382. $this->redis->del("online_" . $roomId);
  2383. $liveInfo["is_online"] = 0;
  2384. $this->redis->set("live_" . $roomId, json_encode($liveInfo));
  2385. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  2386. }
  2387. }
  2388. }
  2389. $this->success("获取成功!");
  2390. }
  2391. }