Party.php 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\controller\Common;
  4. use app\common\model\PartyJoin;
  5. use fast\Random;
  6. use app\common\controller\RedisLeaderboard;
  7. use Redis;
  8. use think\Db;
  9. use think\Exception;
  10. use think\exception\PDOException;
  11. use think\exception\ValidateException;
  12. use think\Request;
  13. use app\common\service\RoomService;
  14. /**
  15. * 派对信息接口
  16. */
  17. class Party extends Common
  18. {
  19. protected $noNeedLogin = ['updatePartyInfo','getPatyType','addUserPositionToParty', 'clearMoney','clearCharm','getPartyRankList','getDefaultBackground','getPartGifList','getPartHeadgifList','isNotalk','getMusicList','updateTops','handleParty'];
  20. protected $noNeedRight = ['*'];
  21. public function __construct(Request $request = null)
  22. {
  23. $this->roomTypeArr = [1=>"party",2=>"live"];
  24. parent::__construct($request);
  25. }
  26. /**
  27. * 创建/进入派对
  28. */
  29. public function createParty() {
  30. $room_type = $this->request->request('room_type',2); // 房间类型:1=派对,2=直播
  31. $partyModel = new \app\common\model\Party();
  32. $user_id = $this->auth->id;
  33. // 开直播时,判断当前用户是否为主播
  34. $anchorInfo = [];
  35. if($room_type == 2) {
  36. $anchorInfo = \app\common\model\UserAnchor::where(["user_id"=>$user_id])->find();
  37. $anchorInfo || $this->error("您还未申请主播!");
  38. $anchorInfo->status == 0 && $this->error("您的主播申请信息还未受理,请耐心等待!");
  39. $anchorInfo->status == 2 && $this->error("您的主播申请未通过,请重新提交!");
  40. }
  41. // 1。实名认证
  42. $userAuthInfo = \app\common\model\UserAuth::where(["user_id"=>$user_id])->find();
  43. if($userAuthInfo) {
  44. if($userAuthInfo->status == 0) {
  45. $this->error("您的实名认证还在这审核中...,请耐心等待!");
  46. } elseif($userAuthInfo->status == 2) {
  47. $this->error("您的实名认证审核未通过,请重新审核!");
  48. }
  49. } else {
  50. $this->error("请先申请实名认证!");
  51. }
  52. if($room_type == 1) {
  53. // 2。开厅申请
  54. $authInfo = \app\common\model\GuildApply::where(["user_id"=>$user_id])->find();
  55. if($authInfo) {
  56. if($authInfo->status == 0) {
  57. $this->error("您的开厅申请还在这审核中...,请耐心等待!");
  58. } elseif($authInfo->status == -1) {
  59. $this->error("您的开厅申请审核未通过,请重新审核!");
  60. }
  61. } else {
  62. $this->error("请先申请开厅资质!");
  63. }
  64. }
  65. // 判断派对是否存在
  66. $redis = new Redis();
  67. $redisconfig = config("redis");
  68. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  69. if ($redisconfig['redis_pwd']) {
  70. $redis->auth($redisconfig['redis_pwd']);
  71. }
  72. if($redisconfig['redis_selectdb'] > 0){
  73. $redis->select($redisconfig['redis_selectdb']);
  74. }
  75. $where = [];
  76. $where["user_id"] = $user_id;
  77. $where["room_type"] = $room_type;
  78. $sqlPartyInfo = $partyModel->where($where)->find();
  79. if(!$sqlPartyInfo) { // sql中不存在派对信息
  80. $partylimit = config("site.roomLimit");
  81. $partycount = $partyModel->count("id");
  82. if($partycount >= $partylimit && $partylimit != -1) {
  83. $this->error("房间数量已达上线,请联系客服!");
  84. }
  85. $party_name = $this->auth->u_id."的房间"; // 派对名称
  86. $party_logo = "/assets/api/party_logo.png"; // 派对logo
  87. $party_type = isset($anchorInfo['party_type_id']) ? $anchorInfo['party_type_id'] : 0; // 派对类型(情感互动,心动点单 等)
  88. $party_notice = "请编辑房间公告"; // 派对公告
  89. $party_notice_detail = "请编辑房间公告内容!"; // 派对公告详情
  90. if (!$party_name || !$party_logo || !$party_notice) {
  91. $this->error(__('Invalid parameters'));
  92. }
  93. $party_ids = $partyModel->column("party_id");
  94. // 创建派对ID (临时ID四位,派对数不超过8999)
  95. $party_id = $this->auth->getUinqueId(4,$party_ids);
  96. if($party_id > 9999) {
  97. $this->error("派对超限,请联系客服");
  98. }
  99. $data = [];
  100. $data["user_id"] = $this->auth->id;
  101. $data["room_type"] = $room_type;
  102. $data["party_id"] = $party_id;
  103. $data["party_hot"] = 0;
  104. $data["party_name"] = $party_name;
  105. $data["party_logo"] = $party_logo;
  106. $data["party_type"] = $party_type;
  107. $data["party_notice"] = $party_notice;
  108. $data["party_notice_detail"] = $party_notice_detail;
  109. $data["is_online"] = 1;
  110. $data["status"] = 1;
  111. $data["is_recommend"] = 0;
  112. $data["createtime"] = time();
  113. $id = $partyModel->insertGetId($data);
  114. if(!$id) {
  115. $this->error("派对创建失败,请稍后重试!");
  116. }
  117. $data["id"] = $id;
  118. if($room_type == 2) {
  119. \app\common\model\User::update(["is_live"=>1],["id"=>$user_id]);
  120. }
  121. $partyInfo = $partyModel->where(["id"=>$id])->find();
  122. $partyInfo["is_new"] = 1;
  123. // 冠名
  124. $userInfo = [];
  125. if($partyInfo["naming"]) {
  126. $userInfo = \app\common\model\User::field("id,nickname,avatar")->where(["id"=>$partyInfo["naming"]])->find();
  127. }
  128. // 头像
  129. if($partyInfo["user_id"] > 0 && $room_type == 2) {
  130. $partyInfo["avatar"] = \app\common\model\User::where(["id"=>$partyInfo["user_id"]])->value("avatar");
  131. }
  132. // 派对类型
  133. $partyTypeName = "普通房";
  134. if($partyInfo["party_type"]) {
  135. $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name");
  136. }
  137. $partyInfo["naming"] = $userInfo;
  138. $partyInfo["type_name"] = $partyTypeName;
  139. // 加入缓存排序
  140. $redis->zAdd($this->roomTypeArr[$room_type]."Rank", $partyInfo['party_hot'], $partyInfo["id"]);
  141. // 加入缓存
  142. $redis->set($this->roomTypeArr[$room_type]."_".$partyInfo["id"],json_encode($partyInfo));
  143. if($room_type != 2) {
  144. // 创建公会
  145. /*\app\common\model\Guild::createGuild($partyInfo["id"], $partyInfo["party_name"], $user_id);
  146. \app\common\model\User::update(["is_guild" => 3,'guild_id'], ["id" => $user_id]);*/
  147. //更新家族 party_id
  148. $guildWhere['id'] = $user_id;
  149. $guildWhere['status'] = ['in',[0,1]];
  150. $guild = model('Guild')->where($guildWhere)->find();
  151. if (!empty($guild)) {
  152. model('Guild')->where($guildWhere)->update(['party_id'=>$partyInfo['id']]);
  153. }
  154. }
  155. } else {
  156. if($sqlPartyInfo["is_close"] == 1) $this->error("该房间已被关闭!");
  157. if($sqlPartyInfo["status"] == 0){
  158. // 清楚对应的记录
  159. $redis->del($this->roomTypeArr[$room_type]."_".$sqlPartyInfo["id"]);
  160. // 删除派对记录
  161. \app\common\model\Party::where('id',$sqlPartyInfo["id"])->delete();
  162. $this->error("创建失败,请重试");
  163. }
  164. // if($sqlPartyInfo["status"] != 1) $this->error("该房间为预创建房间,请联系管理员正式开通!");
  165. // 如果是房主并且房间处于离线状态下激活
  166. if ($sqlPartyInfo['user_id'] != $user_id) {
  167. $this->error("当前直播已结束!");
  168. }
  169. $partyInfo = $sqlPartyInfo;
  170. $partyInfo["is_new"] = 0;
  171. }
  172. $this->success("获取成功!",$partyInfo);
  173. }
  174. /**
  175. * 更新房间状态为正常
  176. */
  177. public function savePartyStatus() {
  178. $party_id = $this->request->request('party_id'); // 派对ID
  179. $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
  180. if (!$party_id || !in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
  181. $user_id = $this->auth->id;
  182. $partyInfo = \app\common\model\Party::get($party_id);
  183. if($partyInfo->status < 0) $this->error("当前状态不支持变更!");
  184. if($partyInfo->user_id !== $user_id) $this->error("当前账号异常,非工会长禁止操作!");
  185. $partyInfo->status = 1;
  186. $res = $partyInfo->save();
  187. if($res) {
  188. // 更新redis 加入缓存排序
  189. $redis = new Redis();
  190. $redisconfig = config("redis");
  191. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  192. if ($redisconfig['redis_pwd']) {
  193. $redis->auth($redisconfig['redis_pwd']);
  194. }
  195. if($redisconfig['redis_selectdb'] > 0){
  196. $redis->select($redisconfig['redis_selectdb']);
  197. }
  198. // 更新redis 加入缓存
  199. $redPartyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$partyInfo["id"]);
  200. if($redPartyInfo) {
  201. $redPartyInfo = json_decode($redPartyInfo,true);
  202. $redPartyInfo["status"] = 1;
  203. $redis->set($this->roomTypeArr[$room_type]."_".$partyInfo["id"],json_encode($redPartyInfo));
  204. }
  205. $this->success("更新公会状态成功!");
  206. } else {
  207. $this->error("网络错误,请稍后重试!");
  208. }
  209. }
  210. /**
  211. * 删除派对(群解散)
  212. */
  213. public function closeParty() {
  214. $party_id = $this->request->request('party_id'); // 派对ID
  215. $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
  216. if (!$party_id || !in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
  217. $partyInfo = \app\common\model\Party::where(["id"=>$party_id])->find();
  218. if(!$partyInfo) $this->error(__('派对不存在!'));
  219. $res = $partyInfo->delete();
  220. if($res !== false) {
  221. // redis 删除
  222. $redis = new Redis();
  223. $redisconfig = config("redis");
  224. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  225. if ($redisconfig['redis_pwd']) {
  226. $redis->auth($redisconfig['redis_pwd']);
  227. }
  228. if($redisconfig['redis_selectdb'] > 0){
  229. $redis->select($redisconfig['redis_selectdb']);
  230. }
  231. $redis->zRem($this->roomTypeArr[$room_type]."Rank",$party_id);
  232. $redis->del($this->roomTypeArr[$room_type]."_".$party_id);
  233. $this->success("删除成功!");
  234. } else {
  235. $this->error("删除失败!");
  236. }
  237. }
  238. /**
  239. * 获取派对列表排序
  240. */
  241. public function getPartyRankList() {
  242. $thispage = $this->request->request('thispage',1,"intval"); // 当前页数
  243. $pagenum = $this->request->request('pagenum',10,"intval"); // 每页显示条数0=不做分页
  244. $type_id = $this->request->request('type_id'); // 派对类型
  245. $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
  246. $is_recommend = $this->request->request('is_recommend'); // 推荐0=否1=是
  247. $all = $this->request->request('all'); // 全部分类0=否1=是
  248. $index = $this->request->request('index',0); // 全部分类0=否1=是
  249. $start = ($thispage-1)*$pagenum;
  250. $end = $start+($pagenum-1);
  251. // 获取排序
  252. $redis = new Redis();
  253. $redisconfig = config("redis");
  254. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  255. if ($redisconfig['redis_pwd']) {
  256. $redis->auth($redisconfig['redis_pwd']);
  257. }
  258. if($redisconfig['redis_selectdb'] > 0){
  259. $redis->select($redisconfig['redis_selectdb']);
  260. }
  261. $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
  262. $partyModel = new \app\common\model\Party();
  263. if(!$redisPartyRankList) {
  264. $userModel = new \app\common\model\User();
  265. // 直接从数据库获取所有数据
  266. $where = [];
  267. $where["a.status"] = 1;
  268. $where["a.is_online"] = 1;
  269. $where["a.room_type"] = $room_type;
  270. $sqlPartyList = $partyModel->alias("a")->field("a.*,b.name as type_name")
  271. ->join("hx_party_type b","a.party_type = b.id","left")->where($where)->select();
  272. $userList = $userModel->field("id,nickname,avatar")->where(["status"=>"normal"])->select();
  273. $userInfoArr = [];
  274. if($userList) foreach($userList as $k => $v) $userInfoArr[$v["id"]] = $v;
  275. if($sqlPartyList) {
  276. foreach($sqlPartyList as $k => $v) {
  277. // 加入缓存排序
  278. $redis->zAdd($this->roomTypeArr[$room_type]."Rank", $v['party_hot'], $v["id"]);
  279. // 设置冠名
  280. $sqlPartyList[$k]["naming"] = isset($userInfoArr[$v["naming"]])?$userInfoArr[$v["naming"]]:[];
  281. // 设置房主头像
  282. $sqlPartyList[$k]["avatar"] = isset($userInfoArr[$v["user_id"]])?$userInfoArr[$v["user_id"]]["avatar"]:[];
  283. // 加入缓存
  284. $redis->set($this->roomTypeArr[$room_type]."_".$v["id"],json_encode($v));
  285. }
  286. $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
  287. }
  288. }
  289. if($redisPartyRankList) {
  290. $resultInfo = $partyModel->getPatyInfoByPartyId($redisPartyRankList,$this->roomTypeArr[$room_type],$type_id,$is_recommend,$all,$start,$end,$index);
  291. $this->success("获取成功!",$resultInfo);
  292. }else{
  293. $this->success("获取成功!",[]);
  294. }
  295. }
  296. /**
  297. * 获取派对列表排序
  298. */
  299. public function getPartyList() {
  300. try {
  301. $thispage = $this->request->request('thispage',1,"intval"); // 当前页数
  302. $pagenum = $this->request->request('pagenum',10,"intval"); // 每页显示条数0=不做分页
  303. $type_id = $this->request->request('type_id'); // 派对类型
  304. $is_recommend = $this->request->request('is_recommend'); // 推荐0=否1=是
  305. $all = $this->request->request('all'); // 全部分类0=否1=是
  306. $index = $this->request->request('index',0); // 全部分类0=否1=是
  307. $start = ($thispage-1)*$pagenum;
  308. $end = $start+($pagenum-1);
  309. // 获取排序
  310. $redis = new Redis();
  311. $redisconfig = config("redis");
  312. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  313. if ($redisconfig['redis_pwd']) {
  314. $redis->auth($redisconfig['redis_pwd']);
  315. }
  316. if($redisconfig['redis_selectdb'] > 0){
  317. $redis->select($redisconfig['redis_selectdb']);
  318. }
  319. $redisPartyRankList = $redis->zRevRange("partyRank",0,-1,true);
  320. $redisLiveRankList = $redis->zRevRange("liveRank",0,-1,true);
  321. $roomService = new RoomService();
  322. if(!$redisPartyRankList) {//party
  323. $roomParams = ['room_type' => 1];
  324. $roomPartyRes = $roomService->roomRedis($roomParams);
  325. $redisPartyRankList = $roomPartyRes['data'];
  326. }
  327. if(!$redisLiveRankList) {//live
  328. $roomParams = ['room_type' => 2];
  329. $roomLiveRes = $roomService->roomRedis($roomParams);
  330. $redisLiveRankList = $roomLiveRes['data'];
  331. }
  332. $redisRoomListIds = [];
  333. $partyIds = !empty($redisPartyRankList) ? array_keys($redisPartyRankList) : [];
  334. $liveIds = !empty($redisLiveRankList) ? array_keys($redisLiveRankList) : [];
  335. $redisRoomListIds = array_merge($redisRoomListIds,$partyIds,$liveIds);
  336. if(!empty($redisRoomListIds)) {
  337. $roomListParams = [
  338. 'ids' => $redisRoomListIds,
  339. 'type_id' => $type_id,
  340. 'is_recommend' => $is_recommend,
  341. 'all' => $all,
  342. 'start' => $start,
  343. 'end' => $end,
  344. 'index' => $index,
  345. ];
  346. $resultInfo = $roomService->getRoomList($roomListParams);
  347. if (!$resultInfo['status']) {
  348. throw new Exception($resultInfo['msg']);
  349. }
  350. }
  351. $this->success("获取成功!",$resultInfo['data']);
  352. } catch (Exception $e) {;
  353. $this->error($e->getMessage());
  354. }
  355. }
  356. /**
  357. * 获取派对用户排序
  358. */
  359. public function getPartyUserRank() {
  360. $room_type = $this->request->request('room_type',1); // 房间类型
  361. $party_id = $this->request->request("party_id");// 派对ID
  362. if (!$party_id) $this->error(__('Invalid parameters'));
  363. $redis = new Redis();
  364. $redisconfig = config("redis");
  365. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  366. if ($redisconfig['redis_pwd']) {
  367. $redis->auth($redisconfig['redis_pwd']);
  368. }
  369. if($redisconfig['redis_selectdb'] > 0){
  370. $redis->select($redisconfig['redis_selectdb']);
  371. }
  372. $res = [];
  373. // 获取今天
  374. $day = date("Ymd");
  375. // 获取本周第一天
  376. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  377. // 获取本月第一天
  378. $monthday = date("Ym01");
  379. $userModel = new \app\common\model\User();
  380. // 获取条数
  381. $num = 50;
  382. // 获取50条财富排行日记录
  383. $getday = $redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_get_".$party_id.":".$day."d",0,$num-1,true);
  384. $res['getRankListDay'] = $userModel->rankList($getday);
  385. // 获取50条财富排行日记录
  386. $today = $redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_to_".$party_id.":".$day."d",0,$num-1,true);
  387. $res['toRankListDay'] = $userModel->rankList($today);
  388. // 获取50条财富排行周记录
  389. $getweek = $redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_get_".$party_id.":".$weekday."w",0,$num-1,true);
  390. $res['getRankListWeek'] = $userModel->rankList($getweek);
  391. // 获取50条贡献排行周记录
  392. $toweek = $redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_to_".$party_id.":".$weekday."w",0,$num-1,true);
  393. $res['toRankListWeek'] = $userModel->rankList($toweek);
  394. // 获取50条财富排行月记录
  395. $toweek = $redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_get_".$party_id.":".$monthday."m",0,$num-1,true);
  396. $res['getRankListMonth'] = $userModel->rankList($toweek);
  397. // 获取50条贡献排行周记录
  398. $toweek = $redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_to_".$party_id.":".$monthday."m",0,$num-1,true);
  399. $res['toRankListMonth'] = $userModel->rankList($toweek);
  400. return $this->success("获取成功!",$res);
  401. }
  402. /**
  403. * 派对热度更新(已废弃)
  404. */
  405. public function changeUserPartyhot() {
  406. $party_id = $this->request->request('party_id',0,"intval"); // 派对ID
  407. $room_type = $this->request->request('room_type',1); // 房间类型
  408. $party_hot = $this->request->request('party_hot'); // 房间热度(正数表示提高的热度值,负数表示降低的热度值)
  409. if (!$party_id || !$party_hot) {
  410. $this->error(__('Invalid parameters'));
  411. }
  412. $redis = new Redis();
  413. $redisconfig = config("redis");
  414. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  415. if ($redisconfig['redis_pwd']) {
  416. $redis->auth($redisconfig['redis_pwd']);
  417. }
  418. if($redisconfig['redis_selectdb'] > 0){
  419. $redis->select($redisconfig['redis_selectdb']);
  420. }
  421. // 更新热度
  422. $redis->zIncrBy($this->roomTypeArr[$room_type]."Rank", $party_hot, $party_id);
  423. return $this->success("更新成功!");
  424. }
  425. /**
  426. * 更新主持人和麦位前四位至首页房间排行
  427. */
  428. public function addUserPositionToParty() {
  429. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  430. $user_id = $this->request->request('user_id',0,"intval"); // 用户ID
  431. $upOrdown = $this->request->request('upordown'); // 上下麦:1=上麦-1=下麦
  432. $room_type = $this->request->request('room_type',1); // 房间类型
  433. $avatar = $this->request->request('avatar'); // 用户头像 (upOrdown参数为-1时可以不传)
  434. $position = $this->request->request('position'); // 麦位置:0=支持人,1=1号麦,2=2号麦,3=3号麦,4=4号麦
  435. if (!$party_id || !$user_id || !in_array($position,[0,1,2,3,4,5,6,7,8]) || !in_array($upOrdown,[1,-1])) {
  436. $this->error(__('Invalid parameters'));
  437. }
  438. if($upOrdown == 1) {
  439. // 先完成所有麦上记录
  440. \app\common\model\UserOnsiteTime::update(["status"=>2],["user_id"=>$user_id]);
  441. // 保存上麦记录
  442. $data = [];
  443. $data["user_id"] = $user_id;
  444. $data["party_id"] = $party_id;
  445. $data["onsite_time"] = time();
  446. \app\common\model\UserOnsiteTime::insert($data);
  447. }
  448. if($upOrdown == -1) {
  449. // 更新下麦时间
  450. $update = [];
  451. $update["offsite_time"] = time();
  452. $update["status"] = 2;
  453. \app\common\model\UserOnsiteTime::update($update,["user_id"=>$user_id,"status"=>1]);
  454. }
  455. if(in_array($position,[5,6,7,8])) return $this->success("设置成功!");
  456. $redis = new Redis();
  457. $redisconfig = config("redis");
  458. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  459. if ($redisconfig['redis_pwd']) {
  460. $redis->auth($redisconfig['redis_pwd']);
  461. }
  462. if($redisconfig['redis_selectdb'] > 0){
  463. $redis->select($redisconfig['redis_selectdb']);
  464. }
  465. $redisData = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  466. if($redisData) {
  467. $partyInfo = json_decode($redisData,true);
  468. if($upOrdown == 1) {
  469. // 删掉已有头像,防止重复
  470. $partyuser = isset($partyInfo["party_user"])?$partyInfo["party_user"]:"";
  471. if(is_array($partyuser)) foreach($partyuser as $k => $v) if($v === $avatar) unset($partyInfo["party_user"][$k]);
  472. $partyInfo["party_user"][$position] = $avatar;
  473. } else {
  474. if(isset($partyInfo["party_user"])) unset($partyInfo["party_user"][$position]);
  475. }
  476. // sort($partyInfo["party_user"]);
  477. $redis->set($this->roomTypeArr[$room_type]."_".$party_id,json_encode($partyInfo));
  478. }
  479. return $this->success("设置成功!");
  480. }
  481. /**
  482. * 获取派对在线人数列表
  483. */
  484. public function getOnlieList() {
  485. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID 逻辑ID
  486. $page = $this->request->request('page',1); // 分页
  487. $pageNum = $this->request->request('pageNum',10); // 分页
  488. // 分页搜索构建
  489. $pageStart = ($page-1)*$pageNum;
  490. if (!$party_id) {
  491. $this->error(__('Invalid parameters'));
  492. }
  493. $redis = new Redis();
  494. $redisconfig = config("redis");
  495. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  496. if ($redisconfig['redis_pwd']) {
  497. $redis->auth($redisconfig['redis_pwd']);
  498. }
  499. if($redisconfig['redis_selectdb'] > 0){
  500. $redis->select($redisconfig['redis_selectdb']);
  501. }
  502. $res = $redis->hGetAll("online_".$party_id);
  503. $user_ids = [];$userList = [];
  504. if($res) $user_ids = array_values($res);
  505. // 获取用户列表信息
  506. $user_ids && $userList = \app\common\model\User::field("id,avatar,nickname,level,gender")->where(["id"=>["in",$user_ids]])->limit($pageStart,$pageNum)->select();
  507. $this->success("获取成功!",$userList);
  508. }
  509. /**
  510. * 加入派对
  511. */
  512. public function joinParty() {
  513. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID 逻辑ID
  514. $room_type = $this->request->request("room_type",1);//
  515. $party_pass = $this->request->request("party_pass");//
  516. if (!$party_id || !in_array($room_type,[1,2])) {
  517. $this->error(__('Invalid parameters'));
  518. }
  519. $user_id = $this->auth->id;
  520. $redis = new Redis();
  521. $redisconfig = config("redis");
  522. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  523. if ($redisconfig['redis_pwd']) {
  524. $redis->auth($redisconfig['redis_pwd']);
  525. }
  526. if($redisconfig['redis_selectdb'] > 0){
  527. $redis->select($redisconfig['redis_selectdb']);
  528. }
  529. $redis->zAdd("party_user_".$party_id,$this->auth->u_id,$user_id);
  530. // 判断当前用户是否存在在直播间通过切换过来的
  531. $livingUserPartyId = $redis->hGet("livingUser", $user_id);
  532. if ($livingUserPartyId) {
  533. if($livingUserPartyId != $party_id){
  534. // 扣除房间在线人数
  535. $redis->HDel("online_" . $livingUserPartyId, $user_id);
  536. // 扣除在线用户在房间情况
  537. $redis->hDel("livingUser", $user_id);
  538. }
  539. }
  540. // 记录在线用户在房间情况
  541. $redis->hSet("livingUser", $user_id, $party_id);
  542. // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
  543. $lsetList = [];
  544. for($i=1;$i<=4;$i++) {
  545. $hgetlist = $redis->hGet("party_manage_".$party_id,$user_id."-".$i);
  546. $hgetlist = unserialize($hgetlist);
  547. $restime = time() - intval($hgetlist["createtime"]);
  548. // 房管
  549. if($hgetlist && $i == 1) $lsetList["manage_restime"] = "";
  550. // 禁言
  551. if($hgetlist && $i == 2 && $restime < $hgetlist["time"]) $lsetList["manage_notalk"] = $restime;
  552. // 拉黑
  553. if($hgetlist && $i == 3 && $restime < $hgetlist["time"]) {
  554. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  555. $this->error(__('您已被该房间拉黑,解除时间:'.$restime));
  556. break;
  557. }
  558. // 踢出
  559. if($hgetlist && $i == 4 && $restime < $hgetlist["time"]) {
  560. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  561. $this->error(__('您已被该房间踢出,解除时间:'.$restime));
  562. break;
  563. }
  564. }
  565. // 判断派对密码
  566. $partyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  567. if($partyInfo) {
  568. $partyInfo = json_decode($partyInfo,true);
  569. if($partyInfo["is_close"] == 1) $this->error("该房间已被关闭!");
  570. if($partyInfo["status"] != 1) $this->error("该房间为预创建房间,请联系管理员正式开通!");
  571. if(isset($partyInfo["party_pass"]) && $partyInfo["party_pass"] && $partyInfo["user_id"] != $user_id) {
  572. if(($party_pass != $partyInfo["party_pass"] || strlen($party_pass) != 4) && $this->auth->id != 4) {
  573. $this->error("派对密码不正确!");
  574. }
  575. }
  576. // 公会管理员和工会长激活派对厅
  577. $guildInfo = \app\common\model\Guild::where(['user_id' => $partyInfo['user_id'], 'status' => 1])->find();
  578. if ($guildInfo) {
  579. // 获取公会管理员
  580. $guildMemberInfo = \app\common\model\GuildMember::where(["user_id" => $user_id, "guild_id" => $guildInfo['id'], 'status' => 1])->find();
  581. if ($guildMemberInfo && $guildMemberInfo['role'] == 0) {
  582. $this->error("当前直播已结束!");
  583. }
  584. }
  585. // // 如果是房主自己进入房间,则更新用户 为在线状态
  586. // if ($partyInfo["user_id"] == $user_id) {
  587. // if ($room_type == 2)
  588. // \app\common\model\User::update(["is_live" => 1], ["id" => $partyInfo["user_id"]]);
  589. // }
  590. } else {
  591. $this->error("派对信息获取失败!");
  592. }
  593. // 获取用户魅力值
  594. $users = $redis->zRange("hourCharm_".$party_id,0,-1,true);
  595. $u = [];
  596. if($users) {
  597. foreach($users as $k => $v) $u[] = [
  598. "user_id"=>$k,
  599. "charm"=>$this->changeW($v)
  600. ];
  601. }
  602. $lsetList["userCharm"] = $u;
  603. // 获取用户排行榜前三名头像
  604. $heads = $redis->hGet("user_jewel_top3",$party_id);
  605. $lsetList["userJewelTop3"] = $heads?json_decode($heads,true):[];
  606. // 判断当前用户是否收藏了此房间
  607. $cellection = $redis->hGet("room_cellection",$user_id."-".$party_id);
  608. $lsetList["is_cellection"] = $cellection?1:0;
  609. if(isset($partyInfo["type_name"]) && $partyInfo["type_name"]) {
  610. // $partyInfo["type_name"] = $partyInfo["type_name"];
  611. } else {
  612. $partyInfo["type_name"] = "普通房";
  613. }
  614. $partyInfo["party_hot"] = $this->changeW($partyInfo["party_hot"]);
  615. $lsetList["partyInfo"] = $partyInfo;
  616. return $this->success("加入成功!",$lsetList);
  617. }
  618. /**
  619. * 判断是否被禁言
  620. */
  621. public function isNotalk() {
  622. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID 逻辑ID
  623. $user_id = $this->request->request('user_id',0,"intval"); // 用户ID 逻辑ID
  624. if (!$user_id || !$party_id) {
  625. $this->error(__('Invalid parameters'));
  626. }
  627. $redis = new Redis();
  628. $redisconfig = config("redis");
  629. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  630. if ($redisconfig['redis_pwd']) {
  631. $redis->auth($redisconfig['redis_pwd']);
  632. }
  633. if($redisconfig['redis_selectdb'] > 0){
  634. $redis->select($redisconfig['redis_selectdb']);
  635. }
  636. // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
  637. $lsetList = [];
  638. $lsetList["is_notalk"] = 0;
  639. $lsetList["notalk_time"] = 0;
  640. $hgetlist = $redis->hGet("party_manage_".$party_id,$user_id."-2");
  641. $hgetlist = unserialize($hgetlist);
  642. $restime = time() - intval($hgetlist["createtime"]);
  643. // 禁言
  644. if($hgetlist && $restime < $hgetlist["time"]) {
  645. $lsetList["is_notalk"] = 1;
  646. $lsetList["notalk_time"] = $restime;
  647. }
  648. return $this->success("获取成功!",$lsetList);
  649. }
  650. /**
  651. * 退出派对
  652. */
  653. public function outParty() {
  654. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  655. if (!$party_id) {
  656. $this->error(__('Invalid parameters'));
  657. }
  658. $user_u_id = $this->auth->u_id;
  659. $redis = new Redis();
  660. $redisconfig = config("redis");
  661. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  662. if ($redisconfig['redis_pwd']) {
  663. $redis->auth($redisconfig['redis_pwd']);
  664. }
  665. if($redisconfig['redis_selectdb'] > 0){
  666. $redis->select($redisconfig['redis_selectdb']);
  667. }
  668. $redis->zRem("party_user_".$party_id,$user_u_id);
  669. // 处理online_party_id
  670. //$redis->connect($redisconfig["host"], $redisconfig["port"]);
  671. $redis->HDel("online_" . $party_id, $this->auth->id);
  672. // 扣除在线用户在房间情况
  673. $redis->hDel("livingUser", $this->auth->id);
  674. // 更新房间在线状态
  675. $partyInfo = $redis->get("party_" . $party_id);
  676. if ($partyInfo) {
  677. $partyInfo = json_decode($partyInfo, true);
  678. $memCount = count($redis->hGetAll("online_" . $party_id));
  679. if ($memCount <= 0) {
  680. $partyInfo["is_online"] = 0;
  681. $redis->set("party_" . $party_id, json_encode($partyInfo));
  682. \app\common\model\Party::update(["is_online" => 0], ["id" => $party_id]);
  683. }
  684. }
  685. $liveInfo = $redis->get("live_" . $party_id);
  686. if ($liveInfo) {
  687. $liveInfo = json_decode($liveInfo, true);
  688. $memCount = count($redis->hGetAll("online_" . $party_id));
  689. if ($memCount <= 0) {
  690. $liveInfo["is_online"] = 0;
  691. $redis->set("live_" . $party_id, json_encode($liveInfo));
  692. \app\common\model\Party::update(["is_online" => 0], ["id" => $party_id]);
  693. }
  694. }
  695. return $this->success("退出成功!",[]);
  696. }
  697. /**
  698. * 派对内搜索用户
  699. */
  700. public function searchUserParty() {
  701. $u_id = $this->request->request('u_id',0,"intval"); // 用户u_id
  702. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  703. // $redis = new Redis();
  704. // $redisconfig = config("redis");
  705. // $redis->connect($redisconfig["host"], $redisconfig["port"]);
  706. /*if ($redisconfig['redis_pwd']) {
  707. $redis->auth($redisconfig['redis_pwd']);
  708. }
  709. if($redisconfig['redis_selectdb'] > 0){
  710. $redis->select($redisconfig['redis_selectdb']);
  711. }*/
  712. // $userids = $redis->zRange("party_user_".$party_id,0,-1,true);
  713. // $useridArr = [];
  714. // if($userids)foreach($userids as $k => $v) $useridArr[$v] = $k; // 因为array_slip 不能交换数字啊
  715. // $userid = isset($useridArr[$u_id])?$useridArr[$u_id]:0;
  716. $userModel = new \app\common\model\User();
  717. $where = [];
  718. $where["u_id"] = $u_id;
  719. $userInfo = $userModel->field("id,u_id,avatar,nickname,level,gender")->where($where)->select();
  720. return $this->success("查询成功!",$userInfo);
  721. }
  722. /**
  723. * 设置冠名
  724. */
  725. public function setNaming() {
  726. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  727. $user_id = $this->request->request('user_id',0,"intval"); // 用户ID
  728. $type = $this->request->request('type',1); // 1:设置 0:取消设置
  729. if (!$party_id || !$user_id || ($type != 1 && $type != 0)) {
  730. $this->error(__('Invalid parameters'));
  731. }
  732. $redis = new Redis();
  733. $redisconfig = config("redis");
  734. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  735. if ($redisconfig['redis_pwd']) {
  736. $redis->auth($redisconfig['redis_pwd']);
  737. }
  738. if($redisconfig['redis_selectdb'] > 0){
  739. $redis->select($redisconfig['redis_selectdb']);
  740. }
  741. $partyModel = new \app\common\model\Party();
  742. $data = [];
  743. $where = [];
  744. $where["id"] = $party_id;
  745. $partyInfo = $partyModel->where(["id"=>$party_id])->find();
  746. $getredisPartyInfo = $redis->get($this->roomTypeArr[$partyInfo->room_type].'_'.$party_id);
  747. $redisPartyInfo = json_decode($getredisPartyInfo,true);
  748. if($type == 1) {
  749. $data["naming"] = $user_id;
  750. // 冠名
  751. $userInfo = \app\common\model\User::field("id,nickname,avatar")->where(["id"=>$user_id])->find($user_id);
  752. $redisPartyInfo["naming"] = $userInfo;
  753. } else {
  754. $data["naming"] = 0;
  755. $redisPartyInfo["naming"] = [];
  756. }
  757. $redis->set($this->roomTypeArr[$partyInfo->room_type].'_'.$party_id,json_encode($redisPartyInfo));
  758. $res = $partyModel->update($data,$where);
  759. if($res !== false) {
  760. $this->success("操作成功!");
  761. } else {
  762. $this->error("网络错误,请稍后重试!");
  763. }
  764. }
  765. /**
  766. * 派对收藏
  767. */
  768. public function cellectionParty() {
  769. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  770. if (!$party_id) {
  771. $this->error(__('Invalid parameters'));
  772. }
  773. $user_id = $this->auth->id;
  774. $redis = new Redis();
  775. $redisconfig = config("redis");
  776. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  777. if ($redisconfig['redis_pwd']) {
  778. $redis->auth($redisconfig['redis_pwd']);
  779. }
  780. if($redisconfig['redis_selectdb'] > 0){
  781. $redis->select($redisconfig['redis_selectdb']);
  782. }
  783. $partycellectionModel = new \app\common\model\PartyCellection();
  784. // 添加记录
  785. $data = [];
  786. $data["user_id"] = $user_id;
  787. $data["party_id"] = $party_id;
  788. if($partycellectionModel->where($data)->find()) {
  789. $res = $partycellectionModel->where($data)->delete();
  790. $redis->hDel("room_cellection",$user_id."-".$party_id);
  791. return $this->success("取消收藏成功!",$res);
  792. }
  793. $data["createtime"] = time();
  794. $res = $partycellectionModel->insert($data);
  795. $redis->hSet("room_cellection",$user_id."-".$party_id,1);
  796. return $this->success("收藏成功!",$res);
  797. }
  798. /**
  799. * 派对收藏列表
  800. */
  801. public function cellectionPartyList() {
  802. $page = $this->request->request('page',1); // 分页
  803. $pageNum = $this->request->request('pageNum',10); // 分页
  804. // 分页搜索构建
  805. $pageStart = ($page-1)*$pageNum;
  806. $partycellectionModel = new \app\common\model\PartyCellection();
  807. $userModel = new \app\common\model\User();
  808. $where = [];
  809. $where["a.user_id"] = $this->auth->id;
  810. $where["r.room_type"] = 1;
  811. $list = $partycellectionModel->alias("a")
  812. ->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")
  813. ->where($where)
  814. ->join("hx_party r","a.party_id = r.id")
  815. ->join("hx_party_type t","t.id = r.party_type","left")
  816. ->limit($pageStart,$pageNum)
  817. ->select();
  818. if($list) {
  819. // $redis = new Redis();
  820. // $redisconfig = config("redis");
  821. // $redis->connect($redisconfig["host"], $redisconfig["port"]);
  822. /*if ($redisconfig['redis_pwd']) {
  823. $redis->auth($redisconfig['redis_pwd']);
  824. }
  825. if($redisconfig['redis_selectdb'] > 0){
  826. $redis->select($redisconfig['redis_selectdb']);
  827. }*/
  828. // // 获取本周第一天
  829. // $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  830. // // 获取redis 中 用户排行榜前五名
  831. // foreach($list as $k => $v) {
  832. // $getweek = $redis->zRevRange("party_jewel_get_".$v["r_id"].":".$weekday,0,4,true);
  833. // $userlist = $userModel->rankList($getweek);
  834. // if($userlist) {
  835. // $users = [];
  836. // foreach($userlist as $m => $n) {
  837. // $users[] = $n["avatar"];
  838. // }
  839. // $list[$k]["users"] = $users;
  840. // } else {
  841. // $list[$k]["users"] = [];
  842. // }
  843. //
  844. // $mod = isset($v["party_type_id"])?intval($v["party_type_id"])%5:1;
  845. // $list[$k]["party_type_color"] = $mod == 0?5:$mod;
  846. // }
  847. $users = [];
  848. foreach($list as $k => $v) {
  849. $users[$v["party_id"]] = $v["party_hot"];
  850. }
  851. $partyModel = new \app\common\model\Party();
  852. $resultInfo = $partyModel->getPatyInfoByPartyId($users,"party",0,0,1,0,20,0);
  853. $this->success("获取成功!",$resultInfo);
  854. }
  855. return $this->success("获取成功!",$list);
  856. }
  857. /**
  858. * 获取派对信息
  859. */
  860. public function getPartyInfo() {
  861. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  862. if (!$party_id) {
  863. $this->error(__('Invalid parameters'));
  864. }
  865. $user_id = $this->auth->id;
  866. $partyModel = new \app\common\model\Party();
  867. $partycellectionModel = new \app\common\model\PartyCellection();
  868. $userModel = new \app\common\model\User();
  869. // 获取主体信息
  870. $where = [];
  871. $where["a.id"] = $party_id;
  872. $partyInfo = $partyModel->alias("a")
  873. ->field("a.id,a.user_id,a.party_id,a.party_name,a.party_hot,a.party_logo,rt.id as party_type,rt.name as type_name,a.party_notice,a.party_notice_detail")
  874. ->join("hx_party_type rt","rt.id = a.party_type", "left")
  875. ->where($where)
  876. ->find();
  877. if($partyInfo) {
  878. $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1;
  879. $partyInfo["party_type_color"] = $mod == 0?5:$mod;
  880. if(isset($partyInfo["type_name"]) && $partyInfo["type_name"]) {
  881. // $partyInfo["type_name"] = $partyInfo["type_name"];
  882. } else {
  883. $partyInfo["type_name"] = "普通房";
  884. }
  885. // 获取是否被当前用户收藏
  886. $partyInfo["is_sellection"] = 0;
  887. $where = [];
  888. $where["user_id"] = $user_id;
  889. $where["party_id"] = $party_id;
  890. if($partycellectionModel->where($where)->find()) {
  891. $partyInfo["is_sellection"] = 1;
  892. }
  893. // 获取房主信息
  894. $where = [];
  895. $where["id"] = $partyInfo["user_id"];
  896. $userInfo = $userModel->field("avatar,nickname")->where($where)->find();
  897. // 获取技能信息
  898. $skillList = Model("ViewUserSkill")->getSkillInfo($partyInfo["user_id"]);
  899. $userInfo["skill"] = implode("/",$skillList);
  900. $partyInfo["userInfo"] = $userInfo;
  901. $partyInfo["party_hot"] = $this->changeW($partyInfo["party_hot"]);
  902. }
  903. $this->success("获取成功!",$partyInfo);
  904. }
  905. /**
  906. * 派对设置
  907. */
  908. public function setParty() {
  909. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  910. $party_name = $this->request->request('party_name'); // 派对名称
  911. $party_logo = $this->request->request('party_logo'); // 派对logo/封面
  912. $party_pass = $this->request->request('party_pass'); // 派对密码
  913. $party_type = $this->request->request('party_type'); // 使用场景
  914. $is_screen = $this->request->request('is_screen'); // 是否关闭公屏:1=是,0=否
  915. $on_model = $this->request->request('on_model'); // 上麦模式:1=自由模式,2=麦序模式
  916. $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
  917. $background = $this->request->request('background'); // 派对背景
  918. if (!$party_id || (!$party_name && !$party_logo && !$party_pass && !$party_type && !$is_screen && !$on_model && !$background)) {
  919. $this->error(__('Invalid parameters'));
  920. }
  921. if($party_pass && strlen($party_pass) != 4) {
  922. $this->error("房间密码必须为四位!");
  923. }
  924. $partyModel = new \app\common\model\Party();
  925. $data = [];
  926. $party_name && $data["party_name"] = $party_name;
  927. $party_logo && $data["party_logo"] = $party_logo;
  928. $data["party_pass"] = $party_pass;
  929. $party_type && $data["party_type"] = $party_type;
  930. $is_screen && $data["is_screen"] = $is_screen;
  931. $on_model && $data["on_model"] = $on_model;
  932. $background && $data["background"] = $background;
  933. $where = [];
  934. $where["id"] = $party_id;
  935. $res = $partyModel->update($data,$where);
  936. if($res) {
  937. // 获取派对类型
  938. if($party_type) $data["type_name"] = \app\common\model\PartyType::where(["id"=>$party_type])->value("name");
  939. // 存redis 房间信息
  940. $redis = new Redis();
  941. $redisconfig = config("redis");
  942. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  943. if ($redisconfig['redis_pwd']) {
  944. $redis->auth($redisconfig['redis_pwd']);
  945. }
  946. if($redisconfig['redis_selectdb'] > 0){
  947. $redis->select($redisconfig['redis_selectdb']);
  948. }
  949. $partyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  950. if($partyInfo) {
  951. $partyInfo = json_decode($partyInfo,true);
  952. $partyInfo = array_replace($partyInfo,$data);
  953. $redis->set($this->roomTypeArr[$room_type]."_".$party_id,json_encode($partyInfo));
  954. }
  955. $this->success("房间设置成功!",$data);
  956. } else {
  957. $this->error("网络错误,请稍后重试!");
  958. }
  959. }
  960. /**
  961. * 获取派对背景
  962. */
  963. public function getDefaultBackground() {
  964. $room_type = $this->request->request('room_type',1); // 房间类型
  965. if (!in_array($room_type,[1,2])) {
  966. $this->error(__('Invalid parameters'));
  967. }
  968. $this->success("获取成功!",\app\common\model\PartyBackground::where(["room_type"=>$room_type])->select());
  969. }
  970. /**
  971. * 派对管理设置
  972. */
  973. public function partyManageSet() {
  974. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  975. $user_id = $this->request->request('user_id',0,"intval"); // 用户ID
  976. $item = $this->request->request('item'); // 项目:1=房管,2=禁言,3=拉黑,4=踢出
  977. $time = $this->request->request('time'); // 限制时间(单位:秒):0=永久
  978. if (!$party_id || !$user_id || !in_array($item,[1,2,3,4])) {
  979. $this->error(__('Invalid parameters'));
  980. }
  981. if($item>1 && $time<=0) {
  982. $this->error(__('时间设置有误'));
  983. }
  984. $partyUserId = \app\common\model\Party::where('id', $party_id)->value('user_id');
  985. if ($partyUserId == $user_id && in_array($item, [2, 3, 4])) {
  986. $this->error("您当前无权限操作!");
  987. }
  988. // 获取用户信息
  989. $userInfo = \app\common\model\User::field("noble,avatar,nickname,gender,level")->where(["id"=>$user_id])->find();
  990. if(!$userInfo) $this->error("用户信息获取失败!");
  991. // 国王防踢。
  992. $noble_no = \app\common\model\NobleLevel::where(["id"=>$userInfo->noble])->value("level_no");
  993. if(($item == 3 || $item == 4) && $noble_no == "p08PCcNB") {
  994. $this->error("对方已开通国王贵族,踢出房间失败!");
  995. }
  996. $redis = new Redis();
  997. $redisconfig = config("redis");
  998. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  999. if ($redisconfig['redis_pwd']) {
  1000. $redis->auth($redisconfig['redis_pwd']);
  1001. }
  1002. if($redisconfig['redis_selectdb'] > 0){
  1003. $redis->select($redisconfig['redis_selectdb']);
  1004. }
  1005. $data = [];
  1006. $data["user_id"] = $user_id;
  1007. $data["avatar"] = $userInfo->avatar;
  1008. $data["nickname"] = $userInfo->nickname;
  1009. $data["gender"] = $userInfo->gender;
  1010. $data["level"] = $userInfo->level;
  1011. $data["item"] = $item;
  1012. $data["time"] = $time;
  1013. $data["createtime"] = time();
  1014. $res = $redis->hSet("party_manage_".$party_id,$user_id."-".$item,serialize($data));
  1015. if($res !== false) {
  1016. $this->success("设置成功!",$data);
  1017. } else {
  1018. $this->error("网络错误,请稍后重试!");
  1019. }
  1020. }
  1021. /**
  1022. * 派对管理设置列表
  1023. */
  1024. public function partyManageSetList() {
  1025. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  1026. $item = $this->request->request('item',1,"intval"); // 项目:1=房管,2=禁言,3=拉黑,4=踢出
  1027. if (!$party_id || !in_array($item,[1,2,3,4])) {
  1028. $this->error(__('Invalid parameters'));
  1029. }
  1030. $time = time();
  1031. $redis = new Redis();
  1032. $redisconfig = config("redis");
  1033. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1034. if ($redisconfig['redis_pwd']) {
  1035. $redis->auth($redisconfig['redis_pwd']);
  1036. }
  1037. if($redisconfig['redis_selectdb'] > 0){
  1038. $redis->select($redisconfig['redis_selectdb']);
  1039. }
  1040. $hget=$redis->hGetAll("party_manage_".$party_id);
  1041. $list=array();
  1042. foreach($hget as $key=>$val) {
  1043. if(substr($key,-2) == "-".$item){
  1044. array_push($list,unserialize($val));
  1045. }
  1046. }
  1047. if($list) {
  1048. foreach($list as $k => $v) if(bcadd($v["createtime"],$v["time"]) <= $time && $v["item"] > 1) unset($list[$k]);
  1049. if($list) $list = array_values($list);
  1050. }
  1051. $this->success("获取成功!",$list);
  1052. }
  1053. /**
  1054. * 派对管理设置移除
  1055. */
  1056. public function partyManageSetDel() {
  1057. $id = $this->request->request('user_id',0,"intval"); // userid
  1058. $party_id = $this->request->request('party_id',0,"intval"); // 房间ID
  1059. $item = $this->request->request('item',1,"intval"); // 项目:1=房管,2=禁言,3=拉黑,4=踢出
  1060. if (!$id || !in_array($item,[1,2,3,4])) {
  1061. $this->error(__('Invalid parameters'));
  1062. }
  1063. $redis = new Redis();
  1064. $redisconfig = config("redis");
  1065. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1066. if ($redisconfig['redis_pwd']) {
  1067. $redis->auth($redisconfig['redis_pwd']);
  1068. }
  1069. if($redisconfig['redis_selectdb'] > 0){
  1070. $redis->select($redisconfig['redis_selectdb']);
  1071. }
  1072. $res = $redis->hDel("party_manage_".$party_id,$id."-".$item);
  1073. if($res !== false) {
  1074. $this->success("移除成功!",$res);
  1075. } else {
  1076. $this->error("网络错误,请稍后重试!");
  1077. }
  1078. }
  1079. /**
  1080. * 更新派对公告
  1081. */
  1082. public function savePartyNotice() {
  1083. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  1084. $room_type = $this->request->request('room_type',1); // 房间类型:1=派对2=直播
  1085. $party_notice = $this->request->request('party_notice'); // 公告标题
  1086. $party_notice_detail = $this->request->request('party_notice_detail'); // 公告内容
  1087. if (!$party_id || !$party_notice || !$party_notice_detail) {
  1088. $this->error(__('Invalid parameters'));
  1089. }
  1090. $partyModel = new \app\common\model\Party();
  1091. $where = [];
  1092. $where["id"] = $party_id;
  1093. $data = [];
  1094. $data["party_notice"] = $party_notice;
  1095. $data["party_notice_detail"] = $party_notice_detail;
  1096. $res = $partyModel->update($data,$where);
  1097. if($res) {
  1098. // 存redis 房间信息
  1099. $redis = new Redis();
  1100. $redisconfig = config("redis");
  1101. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1102. if ($redisconfig['redis_pwd']) {
  1103. $redis->auth($redisconfig['redis_pwd']);
  1104. }
  1105. if($redisconfig['redis_selectdb'] > 0){
  1106. $redis->select($redisconfig['redis_selectdb']);
  1107. }
  1108. $partyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  1109. if($partyInfo) {
  1110. $partyInfo = json_decode($partyInfo,true);
  1111. $partyInfo = array_replace($partyInfo,$data);
  1112. $redis->set($this->roomTypeArr[$room_type]."_".$party_id,json_encode($partyInfo));
  1113. }
  1114. $this->success("更新成功!",$res);
  1115. } else {
  1116. $this->error("网络错误,请稍后重试!");
  1117. }
  1118. }
  1119. /**
  1120. * 开始排麦
  1121. */
  1122. public function addLineUp() {
  1123. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  1124. $mai_id = $this->request->request('mai_id',"1"); // 麦位置
  1125. if (!$party_id) {
  1126. $this->error(__('Invalid parameters'));
  1127. }
  1128. $userInfo = $this->auth->getUserinfo();
  1129. $userid = $userInfo['id'];
  1130. // 获取 房间信息
  1131. $partyUser = \app\common\model\Party::where(['id'=>$party_id])->value("user_id");
  1132. if(!$partyUser) $this->error(__('房间信息未找到!'));
  1133. // $is_home = $partyUser == $userInfo->id?1:0;
  1134. $redis = new Redis();
  1135. $redisconfig = config("redis");
  1136. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1137. if ($redisconfig['redis_pwd']) {
  1138. $redis->auth($redisconfig['redis_pwd']);
  1139. }
  1140. if($redisconfig['redis_selectdb'] > 0){
  1141. $redis->select($redisconfig['redis_selectdb']);
  1142. }
  1143. $data = unserialize($redis->hGet("party_lineup",$party_id));
  1144. $data[$userid]["user_id"] = $userInfo['id'];
  1145. $data[$userid]["avatar"] = $userInfo['avatar'];
  1146. $data[$userid]["mai_id"] = $mai_id;
  1147. $data[$userid]["nickname"] = $userInfo['nickname'];
  1148. // $data["is_home"] = $is_home;
  1149. $data[$userid]["level"] = $userInfo['level'];
  1150. $data[$userid]["gender"] = $userInfo['gender'];
  1151. $res = false;
  1152. $data && $res = $redis->hSet("party_lineup",$party_id,serialize($data));
  1153. $data = array_values($data);
  1154. if($res !== false) {
  1155. $this->success("设置成功!",$data);
  1156. } else {
  1157. $this->error("网络错误,请稍后重试!");
  1158. }
  1159. }
  1160. /**
  1161. * 取消排麦
  1162. */
  1163. public function cancelLineUp() {
  1164. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  1165. $user_id = $this->request->request('user_id',0); // 直播间ID
  1166. $is_empty = $this->request->request('is_empty',0,"intval"); // 是否清空排麦列表 1=清空,0=不清空
  1167. if (!$party_id) {
  1168. $this->error(__('Invalid parameters'));
  1169. }
  1170. $userid = $this->auth->id;
  1171. $redis = new Redis();
  1172. $redisconfig = config("redis");
  1173. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1174. if ($redisconfig['redis_pwd']) {
  1175. $redis->auth($redisconfig['redis_pwd']);
  1176. }
  1177. if($redisconfig['redis_selectdb'] > 0){
  1178. $redis->select($redisconfig['redis_selectdb']);
  1179. }
  1180. $data=unserialize($redis->hGet("party_lineup",$party_id));
  1181. if($data && $is_empty != 1) {
  1182. foreach($data as $k => $v) {
  1183. if($v["user_id"] == $user_id) {
  1184. unset($data[$k]);
  1185. break;
  1186. }
  1187. }
  1188. }
  1189. // unset($data[$userid]);
  1190. if($is_empty == 1) $data = [];
  1191. $redis->hSet("party_lineup",$party_id,serialize($data));
  1192. $this->success("移除成功!");
  1193. }
  1194. /**
  1195. * 排麦列表
  1196. */
  1197. public function lineUpList() {
  1198. $party_id = $this->request->request('party_id',0,"intval"); // 直播间ID
  1199. if (!$party_id) {
  1200. $this->error(__('Invalid parameters'));
  1201. }
  1202. $redis = new Redis();
  1203. $redisconfig = config("redis");
  1204. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1205. if ($redisconfig['redis_pwd']) {
  1206. $redis->auth($redisconfig['redis_pwd']);
  1207. }
  1208. if($redisconfig['redis_selectdb'] > 0){
  1209. $redis->select($redisconfig['redis_selectdb']);
  1210. }
  1211. $data = $redis->hGet("party_lineup",$party_id);
  1212. $dataArr = unserialize($data);
  1213. $datas = [];
  1214. is_array($dataArr) && $datas=array_values($dataArr);
  1215. if($datas) {
  1216. $this->success("获取成功!",$datas);
  1217. } else {
  1218. $this->success("获取成功!",[]);
  1219. }
  1220. }
  1221. /**
  1222. * 获取派对类型
  1223. */
  1224. public function getPatyType() {
  1225. $room_type = $this->request->request("room_type",1);//
  1226. if (!in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
  1227. $partytypeModel = new \app\common\model\PartyType();
  1228. $partytypeList = $partytypeModel->where(["room_type"=>$room_type])->select();
  1229. $this->success("获取成功!",$partytypeList);
  1230. }
  1231. /**
  1232. * 判断派对是否设置过密码
  1233. */
  1234. public function getPatyIspass() {
  1235. $party_id = $this->request->request("party_id");// 派对ID
  1236. $room_type = $this->request->request("room_type",1);//
  1237. $is_miniprogram = $this->request->request("is_miniprogram",0);//
  1238. if (!$party_id) $this->error(__('Invalid parameters'));
  1239. $user_id = $this->auth->id;
  1240. // 存redis 房间信息
  1241. $redis = new Redis();
  1242. $redisconfig = config("redis");
  1243. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1244. if ($redisconfig['redis_pwd']) {
  1245. $redis->auth($redisconfig['redis_pwd']);
  1246. }
  1247. if($redisconfig['redis_selectdb'] > 0){
  1248. $redis->select($redisconfig['redis_selectdb']);
  1249. }
  1250. $partyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
  1251. if($partyInfo) {
  1252. $partyInfo = json_decode($partyInfo,true);
  1253. } else {
  1254. $partyModel = new \app\common\model\Party();
  1255. $partyInfo = $partyModel->field("id,user_id,party_pass")->where(["id"=>$party_id])->find();
  1256. if(!$partyInfo) {
  1257. $this->error(__('房间信息获取失败!'));
  1258. }
  1259. }
  1260. $data = [];
  1261. $data["status"] = 0;
  1262. $data["is_pass"] = $partyInfo["party_pass"]?1:0;
  1263. if($partyInfo["user_id"] == $user_id || $this->auth->mobile == '17353993050') $data["is_pass"] = 0;
  1264. if($is_miniprogram == 1) { // 小程序单独处理
  1265. // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
  1266. $lsetList = [];
  1267. for($i=1;$i<=4;$i++) {
  1268. $hgetlist = $redis->hGet("party_manage_".$party_id,$user_id."-".$i);
  1269. $hgetlist = unserialize($hgetlist);
  1270. $restime = time() - intval($hgetlist["createtime"]);
  1271. // 房管
  1272. if($hgetlist && $i == 1) $lsetList["manage_restime"] = "";
  1273. // 禁言
  1274. if($hgetlist && $i == 2 && $restime < $hgetlist["time"]) $lsetList["manage_notalk"] = $restime;
  1275. // 拉黑
  1276. if($hgetlist && $i == 3 && $restime < $hgetlist["time"]) {
  1277. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  1278. $lsetList["manage_black"] = $restime;
  1279. $lsetList["tips"] = '您已被该房间拉黑,解除时间:'.$restime;
  1280. // $this->error(__('您已被该房间拉黑,解除时间:'.$restime));
  1281. break;
  1282. }
  1283. // 踢出
  1284. if($hgetlist && $i == 4 && $restime < $hgetlist["time"]) {
  1285. $restime = date("Y-m-d H:i:s",($hgetlist["time"]+$hgetlist["createtime"]));
  1286. $lsetList["manage_takeout"] = $restime;
  1287. $lsetList["tips"] = '您已被该房间踢出,解除时间:'.$restime;
  1288. // $this->error(__('您已被该房间踢出,解除时间:'.$restime));
  1289. break;
  1290. }
  1291. }
  1292. if($lsetList) {
  1293. $data["status"] = 1;
  1294. $data["hgetlist"] = $lsetList;
  1295. }
  1296. }
  1297. $this->success("获取成功!",$data);
  1298. }
  1299. /**
  1300. * 获取房间gif表情列表
  1301. */
  1302. public function getPartGifList() {
  1303. $this->success("获取成功!",\app\common\model\PartyGif::field("id,gif_image")->order("weight","asc")->select());
  1304. }
  1305. /**
  1306. * 获取房间头像gif表情列表
  1307. */
  1308. public function getPartHeadgifList() {
  1309. $this->success("获取成功!",\app\common\model\PartyHeadgif::field("id,name,gif_image")->order("weight","asc")->select());
  1310. }
  1311. /**
  1312. * 随机获取礼物盒礼物
  1313. */
  1314. private function getBoxGift($gift_box_type) {
  1315. // 查询本奖池内礼物是否还有可抽礼物
  1316. $where = [];
  1317. $where["Jackpot_id"] = $gift_box_type;
  1318. $where["is_use"] = 0;
  1319. $boxhasgift = \app\common\model\GiftBox::where($where)->select();
  1320. $giftcount = count($boxhasgift);
  1321. $giftArr = [];
  1322. foreach($boxhasgift as $k => $v) $giftArr[$v["id"]] = $v;
  1323. if($giftcount > 1) {
  1324. // 随机抽取$num个礼物
  1325. $giftids = array_rand($giftArr,1);
  1326. \app\common\model\GiftBox::update(["is_use"=>1],["id"=>$giftids]);
  1327. }
  1328. if($giftcount == 1) {
  1329. $giftids = $boxhasgift[0]["id"];
  1330. // 更新宝箱奖池全部礼物为未使用
  1331. \app\common\model\GiftBox::update(["is_use"=>0],["Jackpot_id"=>$gift_box_type]);
  1332. }
  1333. $giftInfo = $giftArr[$giftids];
  1334. return $giftInfo;
  1335. }
  1336. /**
  1337. * 全麦/单独赠送礼物
  1338. */
  1339. public function giveGiftToYou() {
  1340. // 接口防并发
  1341. if (!$this->apiLimit(1, 1000)) {
  1342. $this->error(__('Operation frequently'));
  1343. }
  1344. $user_ids = $this->request->request("user_id");// 赠送对象
  1345. $gift_id = $this->request->request("gift_id");// 礼物ID
  1346. $party_id = $this->request->request("party_id",0);// 派对ID
  1347. $room_type = $this->request->request('room_type',1); // 房间类型
  1348. $number = $this->request->request("number");// 赠送数量
  1349. $is_back = $this->request->request("is_back",0);// 是否背包赠送: 1=是,0=否
  1350. if (!$user_ids || !in_array($is_back,[0,1]) || !$gift_id || !$number || !in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
  1351. $user_id_arr = explode(",",$user_ids);
  1352. $userCount = count($user_id_arr);
  1353. $userauthid = $this->auth->id;
  1354. $soundCoinRate = config("site.giftCoin"); // 声币兑换比例
  1355. $userModel = new \app\common\model\User();
  1356. $backGiftId = 0;
  1357. $boxgiftInfo = [];
  1358. if($is_back == 1) {
  1359. // 获取背包礼物信息
  1360. $giftInfo = \app\common\model\GiftBack::get($gift_id);
  1361. if(!$giftInfo) $this->error("背包礼物获取失败");
  1362. $backGiftId = $giftInfo->gift_id;
  1363. // 随机获取一个礼物
  1364. $allCount = $number*$userCount;
  1365. $giftbackList = \app\common\model\GiftBack::where(["name"=>$giftInfo->name,"user_id"=>$userauthid,'is_use'=>0])->limit($allCount)->select();
  1366. $giftInfo = isset($giftbackList[0])?$giftbackList[0]:[];
  1367. $giftcount = 0;
  1368. $giftList = [];
  1369. if($giftbackList) foreach($giftbackList as $k => $v) {
  1370. $giftcount = $giftcount + $v["number"];
  1371. $giftList[$k] = $v;
  1372. if($giftcount >= $allCount) {
  1373. break;
  1374. }
  1375. }
  1376. if($giftcount < $allCount) $this->error("背包数量不足");
  1377. $giftValue = $giftInfo["value"] * $number;
  1378. $getValue = $giftInfo["value"] * $number;
  1379. } else {
  1380. // // 不可以赠送给自己
  1381. // if(in_array($userauthid,$user_id_arr)) $this->error("不可以赠送给自己!");
  1382. // 获取礼物信息
  1383. $giftModel = new \app\common\model\Gift();
  1384. $where = [];
  1385. $where["id"] = $gift_id;
  1386. $giftInfo = $giftModel->where($where)->find();
  1387. if (!$giftInfo) $this->error("请选择礼物!");
  1388. $giftValue = $giftInfo["value"] * $number;
  1389. $giftCountValue = $giftInfo["value"] * $number * $userCount;
  1390. $getValue = $giftValue;
  1391. // 判断如果是礼物盒则随机开礼物盒礼物
  1392. if($giftInfo->box_type > 0) {
  1393. $boxgiftInfo = $this->getBoxGift($giftInfo->box_type);
  1394. $getValue = $boxgiftInfo["price"];
  1395. }
  1396. // 判断当前用户余额
  1397. $where = [];
  1398. $where["id"] = $userauthid;
  1399. $userInfo = $userModel->where($where)->lock(true)->find();
  1400. if (!$userInfo) $this->error("用户信息查询失败!");
  1401. if($userInfo["jewel"] < $giftCountValue) $this->error("您的钻石余额不足!");
  1402. }
  1403. $hotValue = $getValue;
  1404. $getValue = round($getValue * ($soundCoinRate/100));
  1405. // 转换统计
  1406. $progetValue = $hotValue - $getValue;
  1407. if($progetValue >0) {
  1408. $data = [];
  1409. $data["user_id"] = $user_ids;
  1410. $data["party_id"] = $party_id?$party_id:0;
  1411. $data["gift_value"] = $hotValue;
  1412. $data["plat_value"] = $hotValue - $getValue;
  1413. $data["createtime"] = time();
  1414. \app\common\model\UserChangeLog::insert($data);
  1415. }
  1416. // 转换声币后 再进行抽点设置
  1417. if(!$party_id) {
  1418. $platRate = 10;
  1419. $guilderRate = 30;
  1420. } else {
  1421. $partyInfo = \app\common\model\Party::field("user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
  1422. // 获取系统配置信息
  1423. $platRate = $partyInfo->platRate; // 平台抽成百分比
  1424. $guilderRate = $partyInfo->guilderRate; // 工会长抽成百分比
  1425. }
  1426. $platValue = bcmul($platRate/100,$getValue,2);
  1427. $guilderValue = bcmul($guilderRate/100,$getValue,2);
  1428. $getValue = bcsub(bcsub($getValue,$platValue),$guilderValue);
  1429. // $gif_image = $is_back==1?$giftInfo["gif_image"]:$giftInfo["special"];
  1430. $returnData = [];
  1431. Db::startTrans();
  1432. try {
  1433. $redis = new Redis();
  1434. $redisconfig = config("redis");
  1435. $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
  1436. if ($redisconfig['redis_pwd']) {
  1437. $redis->auth($redisconfig['redis_pwd']);
  1438. }
  1439. if($redisconfig['redis_selectdb'] > 0){
  1440. $redis->select($redisconfig['redis_selectdb']);
  1441. }
  1442. // 事务处理余额与记录信息
  1443. $userjewellogModel = new \app\common\model\UserJewelLog();
  1444. //$usersoundcoinlogModel = new \app\common\model\UserSoundcoinLog();
  1445. // 获取当天零点
  1446. $day = date("Ymd");
  1447. // 获取本周第一天
  1448. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  1449. // 获取本月第一天
  1450. $monthday = date("Ym01");
  1451. $allVal = 0;
  1452. $i = 0;
  1453. foreach($user_id_arr as $user_id) {
  1454. // 获取赠送用户信息
  1455. $where = [];
  1456. $where["id"] = $user_id;
  1457. $touserInfo = $userModel->where($where)->find();
  1458. if($is_back == 1) {
  1459. $b=0;
  1460. foreach($giftList as $k => $v) {
  1461. for($a=1;$a<=$v["number"];$a++) {
  1462. $b++;
  1463. $num = $v["number"] - $a;
  1464. if($num > 0) {
  1465. $res1 = \app\common\model\GiftBack::where(["id"=>$v["id"]])->setDec("number");
  1466. } else {
  1467. $res1 = \app\common\model\GiftBack::update(["is_use"=>1,"use_time"=>time()],["id"=>$v["id"]]);
  1468. }
  1469. if($b == $number) break;
  1470. }
  1471. }
  1472. $res2 = true;
  1473. } else {
  1474. // 扣除当前用户钻石余额
  1475. $where = [];
  1476. $where["id"] = $userauthid;
  1477. $res1 = $userModel->where($where)->setDec("jewel", $giftValue);
  1478. // 添加当前用户钻石流水记录
  1479. $res2 = $userjewellogModel->addUserJewelLog($userauthid, $giftValue, "-", $userInfo["jewel"], "赠送礼物:'" . $giftInfo["name"] . "',扣除" . $giftValue . "钻石!", 3);
  1480. }
  1481. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  1482. // 添加礼物赠送记录表
  1483. $data = [];
  1484. $data["user_id"] = $userauthid;
  1485. $data["user_to_id"] = $user_id;
  1486. $data["party_id"] = $party_id;
  1487. if($boxgiftInfo){
  1488. $data["gift_id"] = $boxgiftInfo['gift_id'];
  1489. $data["gift_give_type"] = 2;
  1490. $data["gift_name"] = $boxgiftInfo["gift_name"];
  1491. $data["gift_gif_image"] = $boxgiftInfo["image"];
  1492. $data["number"] = $number;
  1493. $data["price"] = $boxgiftInfo["price"];
  1494. $data["value"] = $boxgiftInfo["price"] * $number;
  1495. }else{
  1496. $data["gift_id"] = $backGiftId > 0 ? $backGiftId : $gift_id;
  1497. $data["gift_give_type"] = $is_back ? 1 : 2;
  1498. $data["gift_name"] = $giftInfo["name"];
  1499. $data["gift_gif_image"] = $giftInfo["image"];
  1500. $data["number"] = $number;
  1501. $data["price"] = $giftInfo["value"];
  1502. $data["value"] = $giftValue;
  1503. }
  1504. $data["createtime"] = time();
  1505. $res5 = $giftuserpartyModel->allowField(true)->save($data);
  1506. // 添加赠送用户声币余额
  1507. /* $where = [];
  1508. $where["id"] = $user_id;
  1509. $res3 = $userModel->where($where)->setInc("sound_coin", $getValue);
  1510. $getValue == 0 && $res3 = true;*/
  1511. // 添加赠送用户声币流水记录soundCoin
  1512. // xxx送你
  1513. //$res4 = $usersoundcoinlogModel->addUserSoundcoinLog($user_id, $getValue, "+", $touserInfo["sound_coin"], "{$this->auth->nickname}送你{$giftInfo['name']}x{$number}", 1, $giftuserpartyModel->id);
  1514. /*if ($partyInfo && $guilderValue > 0) {
  1515. // 增加房主抽成
  1516. $where = [];
  1517. $where["id"] = $partyInfo->user_id;
  1518. $userModel->where($where)->setInc("sound_coin", $guilderValue);
  1519. // 添加赠送用户声币流水记录soundCoin
  1520. // xxx送礼物给xxx,房间礼物抽成
  1521. $usersoundcoinlogModel->addUserSoundcoinLog($partyInfo->user_id, $guilderValue, "+", $touserInfo["sound_coin"], "{$this->auth->nickname}送礼物{$giftInfo['name']}x{$number}给{$touserInfo['nickname']},房间礼物抽成", 4, $giftuserpartyModel->id);
  1522. }*/
  1523. if ($res1 && $res2 && $res5) {
  1524. $i++;
  1525. if($party_id > 0) {
  1526. // 添加redis记录做财富排行榜日榜用
  1527. $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $day . "d", $hotValue, $user_id);
  1528. // 添加redis记录做财富排行榜周榜用
  1529. $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $weekday . "w", $hotValue, $user_id);
  1530. // 添加redis记录做财富排行榜月榜用
  1531. $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $monthday . "m", $hotValue, $user_id);
  1532. // 添加redis记录做贡献排行榜日榜用
  1533. $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $day . "d", $giftValue, $userauthid);
  1534. // 添加redis记录做贡献排行榜周榜用
  1535. $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $weekday . "w", $giftValue, $userauthid);
  1536. // 添加redis记录做贡献排行榜月榜用
  1537. $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $monthday . "m", $giftValue, $userauthid);
  1538. // tcp 更新用户魅力值
  1539. $this->updateUserCharm($party_id, $user_id, $hotValue);
  1540. // 如果是主播,则添加魅力值记录做榜单统计
  1541. if($room_type == 2) {
  1542. $data = [];
  1543. $data["user_id"] = $user_id;
  1544. $data["party_id"] = $party_id;
  1545. $data["charm"] = $hotValue;
  1546. $data["createtime"] = time();
  1547. \app\common\model\UserCharmRank::insert($data);
  1548. }
  1549. }
  1550. $getempirical = config("site.getempirical");
  1551. $getempirical = $getempirical * $hotValue;
  1552. // 获取用户贵族信息
  1553. $noble = \app\common\model\User::getUserNoble($this->auth->id);
  1554. if(isset($noble["noble_on"]) && $noble["noble_on"] == 1) {
  1555. $getempirical = $getempirical + $getempirical * ($noble["explain"]/100);
  1556. }
  1557. // 增加用户经验值
  1558. \app\common\model\User::addEmpirical($this->auth->id,$getempirical);
  1559. // +exp
  1560. \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
  1561. // +message
  1562. \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number);
  1563. $allVal = $allVal + $hotValue;
  1564. // // 剪掉背包礼物
  1565. // if($is_back == 1) {
  1566. // \app\common\model\GiftBack::update(["is_use"=>1],["id"=>$gift_id]);
  1567. // }
  1568. }
  1569. }
  1570. // 获取用户魅力值
  1571. $users = $redis->zRange("hourCharm_".$party_id,0,-1,true);
  1572. $u = [];
  1573. if($users) {
  1574. foreach($users as $k => $v) $u[] = [
  1575. "user_id"=>$k,
  1576. "charm"=>$this->changeW($v)
  1577. ];
  1578. }
  1579. $userCharm = $u;
  1580. // tcp 更新房间热度
  1581. $partyHot = $this->updatePartyHot($party_id, $allVal, $room_type);
  1582. // 如果是派对,则添加派对热度值记录做榜单统计
  1583. if($room_type == 1) {
  1584. $data = [];
  1585. $data["party_id"] = $party_id;
  1586. $data["hot"] = $allVal;
  1587. $data["createtime"] = time();
  1588. \app\common\model\PartyHot::insert($data);
  1589. }
  1590. // tcp 获取房间用户周前三名
  1591. $partyUserTop = $this->getPartyUserTop($party_id, $room_type);
  1592. if($i == $userCount) {
  1593. $returnData["userCharm"] = $userCharm;
  1594. $returnData["partyHot"] = $this->changeW($partyHot);
  1595. $returnData["partyUserTop"] = $partyUserTop;
  1596. if($is_back != 1) {
  1597. if($giftInfo->box_type > 0) { // 不是背包,宝箱中赠送
  1598. $returnData["box_type"] = $giftInfo->box_type;
  1599. $returnData["box_image"] = $giftInfo->image;
  1600. $returnData["image"] = $boxgiftInfo["image"];
  1601. $returnData["name"] = $boxgiftInfo["gift_name"];
  1602. $returnData["gif_image"] = $boxgiftInfo["special"];
  1603. } else {
  1604. $returnData["image"] = $giftInfo["image"];
  1605. $returnData["gif_image"] = $giftInfo["special"];
  1606. }
  1607. } else {
  1608. $returnData["image"] = $giftInfo["image"];
  1609. $returnData["gif_image"] = $giftInfo["gif_image"];
  1610. }
  1611. // 增加抽点记录
  1612. $data = [];
  1613. $data["user_id"] = $user_ids;
  1614. $data["party_id"] = $party_id?$party_id:0;
  1615. $data["gift_value"] = $getValue;
  1616. $data["plat_value"] = $platValue;
  1617. $data["guilder_value"] = $guilderValue;
  1618. $data["createtime"] = time();
  1619. \app\common\model\UserProfitLog::insert($data);
  1620. Db::commit();
  1621. $this->success("赠送成功!",$returnData);
  1622. } else {
  1623. $this->success("赠送失败!");
  1624. }
  1625. } catch (ValidateException $e) {
  1626. Db::rollback();
  1627. $this->error($e->getMessage());
  1628. } catch (PDOException $e) {
  1629. Db::rollback();
  1630. $this->error($e->getMessage());
  1631. } catch (Exception $e) {
  1632. Db::rollback();
  1633. $this->error($e->getMessage());
  1634. }
  1635. }
  1636. // /**
  1637. // * 播放动效
  1638. // */
  1639. // public function play($party_id,$type,$value,$number) {
  1640. // // 发送tcp
  1641. // $tcpArr = [];
  1642. // $tcpArr['type'] = "play";
  1643. // $tcpArr['data'] = [
  1644. // 'party_id' => $party_id,
  1645. // 'type' => $type,
  1646. // 'value' => $value,
  1647. // 'number' => $number,
  1648. // ];
  1649. // $tcpJson = json_encode($tcpArr);
  1650. // $client = stream_socket_client(config("tcp"));
  1651. // $buffer2 = base64_encode($tcpJson)."****";
  1652. // fwrite($client, $buffer2);
  1653. // }
  1654. /**
  1655. * 更新派对信息(热度等)
  1656. */
  1657. private function updatePartyHot($party_id,$hotValue,$room_type) {
  1658. $partyInfo = \app\common\model\Party::where(['id'=>$party_id])->find();
  1659. if(!$partyInfo) return $hotValue;
  1660. $party_hot = $partyInfo->party_hot > 0 ? $partyInfo->party_hot:0;
  1661. $party_hot_value = $party_hot + $hotValue;
  1662. $party_hot_value = $party_hot_value > 0 ? $party_hot_value : 0;
  1663. if($party_hot_value != $party_hot) {
  1664. // 保存数据
  1665. $partyInfo->party_hot = $party_hot_value;
  1666. $partyInfo->save();
  1667. // 更新redis 加入缓存排序
  1668. $redis = new Redis();
  1669. $redisconfig = config("redis");
  1670. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1671. if ($redisconfig['redis_pwd']) {
  1672. $redis->auth($redisconfig['redis_pwd']);
  1673. }
  1674. if($redisconfig['redis_selectdb'] > 0){
  1675. $redis->select($redisconfig['redis_selectdb']);
  1676. }
  1677. $redis->zAdd($this->roomTypeArr[$room_type]."Rank", $partyInfo['party_hot'], $partyInfo["id"]);
  1678. // 更新redis 加入缓存
  1679. $redPartyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$partyInfo["id"]);
  1680. if($redPartyInfo) {
  1681. $redPartyInfo = json_decode($redPartyInfo,true);
  1682. $redPartyInfo["party_hot"] = $party_hot_value;
  1683. $redis->set($this->roomTypeArr[$room_type]."_".$partyInfo["id"],json_encode($redPartyInfo));
  1684. }
  1685. // // 发送tcp
  1686. // $tcpArr = [];
  1687. // $tcpArr['type'] = "changeRoomHot";
  1688. // $tcpArr['data'] = [
  1689. // 'room_id' => $party_id,
  1690. // 'value' => $party_hot_value,
  1691. // ];
  1692. // $tcpJson = json_encode($tcpArr);
  1693. // $client = stream_socket_client(config("tcp"));
  1694. // $buffer2 = base64_encode($tcpJson)."****";
  1695. // fwrite($client, $buffer2);
  1696. }
  1697. return $party_hot_value;
  1698. }
  1699. /**
  1700. * 用户赠送礼物后房间内用户排行,贡献榜前三名
  1701. */
  1702. private function getPartyUserTop($party_id,$room_type) {
  1703. $redis = new Redis();
  1704. $redisconfig = config("redis");
  1705. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1706. if ($redisconfig['redis_pwd']) {
  1707. $redis->auth($redisconfig['redis_pwd']);
  1708. }
  1709. if($redisconfig['redis_selectdb'] > 0){
  1710. $redis->select($redisconfig['redis_selectdb']);
  1711. }
  1712. // 获取本周第一天
  1713. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  1714. // 获取当天零点
  1715. $day = date("Ymd");
  1716. $userModel = new \app\common\model\User();
  1717. // 获取条数
  1718. $num = 3;
  1719. // 获取3条财富排行周记录
  1720. $getweek = $redis->zRevRange($this->roomTypeArr[$room_type]."_jewel_to_".$party_id.":".$day."d",0,$num-1,true);
  1721. $userList = $userModel->rankList($getweek);
  1722. $avatarArr = [];
  1723. if($userList) {
  1724. foreach($userList as $k => $v) {
  1725. $v["jewel"] > 0 && $avatarArr[] = $v["avatar"];
  1726. }
  1727. // 加入缓存做备份
  1728. $redis->hSet("user_jewel_top3",$party_id,json_encode($avatarArr));
  1729. // // 发送tcp
  1730. // $tcpArr = [];
  1731. // $tcpArr['type'] = "changeRoomUserTop";
  1732. // $tcpArr['data'] = [
  1733. // 'room_id' => $party_id,
  1734. // 'user_avatar' => $avatarArr,
  1735. // ];
  1736. // $tcpJson = json_encode($tcpArr);
  1737. // $client = stream_socket_client(config("tcp"));
  1738. // $buffer2 = base64_encode($tcpJson)."****";
  1739. // fwrite($client, $buffer2);
  1740. }
  1741. return $avatarArr;
  1742. }
  1743. /**
  1744. * 用户赠送礼物后房间内用户魅力值增加
  1745. */
  1746. private function updateUserCharm($party_id,$user_id,$giftValue) {
  1747. $redis = new Redis();
  1748. $redisconfig = config("redis");
  1749. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1750. if ($redisconfig['redis_pwd']) {
  1751. $redis->auth($redisconfig['redis_pwd']);
  1752. }
  1753. if($redisconfig['redis_selectdb'] > 0){
  1754. $redis->select($redisconfig['redis_selectdb']);
  1755. }
  1756. // 获取用户魅力值
  1757. $users = $redis->zRange("hourCharm_".$party_id,0,-1,true);
  1758. if(!$users) $users[$user_id] = 0;
  1759. if(isset($users[$user_id])) {
  1760. $value = $users[$user_id] + $giftValue;
  1761. } else {
  1762. $value = $giftValue;
  1763. }
  1764. $redis->zAdd("hourCharm_".$party_id,$value,$user_id);
  1765. return true;
  1766. }
  1767. /**
  1768. * 单个房间魅力值清零
  1769. */
  1770. public function partyClearCharm() {
  1771. $party_id = $this->request->request("party_id");// 派对ID
  1772. $userId = $this->request->request("user_id", 0);// 用户ID
  1773. if($party_id <= 0) {
  1774. $this->error("请输入派对ID");
  1775. }
  1776. $redis = new Redis();
  1777. $redisconfig = config("redis");
  1778. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1779. if ($redisconfig['redis_pwd']) {
  1780. $redis->auth($redisconfig['redis_pwd']);
  1781. }
  1782. if($redisconfig['redis_selectdb'] > 0){
  1783. $redis->select($redisconfig['redis_selectdb']);
  1784. }
  1785. if ($userId) {
  1786. $redis->zRem("hourCharm_" . $party_id, $userId);
  1787. } else {
  1788. $redis->del("hourCharm_" . $party_id);
  1789. }
  1790. $this->success("操作成功!");
  1791. }
  1792. /**
  1793. * 获取音乐列表
  1794. */
  1795. public function getMusicList() {
  1796. $this->success("获取成功!",\app\common\model\Music::select());
  1797. }
  1798. //============================定时任务==========================//
  1799. /**
  1800. * redis清理排行榜 并数据库备份
  1801. */
  1802. public function updateTops() {
  1803. // 前一天日期
  1804. $yestaday = date("Ymd",bcsub(time(),86400));
  1805. // 上个周一
  1806. $preweek = $this->firstOfWeek(date("Y-m-d H:i:s",bcsub(time(),604800)));
  1807. // 上个月一号
  1808. $monty = bcsub(date("m"),1);
  1809. if($monty < 10) $monty = "0".$monty;
  1810. $premonth = date("Y").$monty."01";
  1811. $redis = new Redis();
  1812. $redisconfig = config("redis");
  1813. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1814. if ($redisconfig['redis_pwd']) {
  1815. $redis->auth($redisconfig['redis_pwd']);
  1816. }
  1817. if($redisconfig['redis_selectdb'] > 0){
  1818. $redis->select($redisconfig['redis_selectdb']);
  1819. }
  1820. // 获取所有派对ID
  1821. $party_ids = \app\common\model\Party::where(["status"=>1])->column("id");
  1822. // 获取数据
  1823. $time = time();
  1824. if($party_ids) foreach($party_ids as $k => $v) {
  1825. $keys = [
  1826. "party_jewel_get_".$v.":".$yestaday."d",
  1827. "party_jewel_to_".$v.":".$yestaday."d",
  1828. "party_jewel_get_".$v.":".$preweek."w",
  1829. "party_jewel_to_".$v.":".$preweek."w",
  1830. "party_jewel_get_".$v.":".$premonth."m",
  1831. "party_jewel_to_".$v.":".$premonth."m",
  1832. ];
  1833. foreach($keys as $key) {
  1834. // 备份数据
  1835. $redisData = $redis->zRevRange($key,0,-1,true);
  1836. if($redisData) {
  1837. $keyInfo = \app\common\model\RedisTops::where(["key"=>$key])->find();
  1838. $data = ["party_id"=>$v,"key"=>$key,"value"=>json_encode($redisData),"createtime" => $time];
  1839. if(!$keyInfo) {
  1840. $res = \app\common\model\RedisTops::insert($data);
  1841. // 清理数据
  1842. $res && $redis->zRemRangeByRank($key,0,-1);
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. public function handleParty() {
  1849. return false;
  1850. $partyList = \app\common\model\Party::where('is_online',1)->select();
  1851. $redis = new Redis();
  1852. $redisconfig = config("redis");
  1853. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1854. if ($redisconfig['redis_pwd']) {
  1855. $redis->auth($redisconfig['redis_pwd']);
  1856. }
  1857. if($redisconfig['redis_selectdb'] > 0){
  1858. $redis->select($redisconfig['redis_selectdb']);
  1859. }
  1860. // $redis->del("online_" . 3);die;
  1861. // $redis->hSet("online_" . 3, 4, 4);die;
  1862. foreach ($partyList as $party){
  1863. $userId = $party['user_id'];
  1864. $roomId = $party['id'];
  1865. $redis->HDel("online_" . $roomId, $userId);
  1866. // 扣除在线用户在房间情况
  1867. $redis->hDel("livingUser",$userId);
  1868. // // 更新房间在线状态
  1869. $partyInfo = $redis->get("party_" . $roomId);
  1870. if ($partyInfo) {
  1871. $partyInfo = json_decode($partyInfo, true);
  1872. $memCount = count($redis->hGetAll("online_" . $roomId));
  1873. if ($memCount <= 0) {
  1874. dump($roomId.'--1---');
  1875. $partyInfo["is_online"] = 0;
  1876. $redis->set("party_" . $roomId, json_encode($partyInfo));
  1877. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  1878. }
  1879. }
  1880. $liveInfo = $redis->get("live_" . $roomId);
  1881. if ($liveInfo) {
  1882. $liveInfo = json_decode($liveInfo, true);
  1883. $memCount = count($redis->hGetAll("online_" . $roomId));
  1884. if ($memCount <= 0) {
  1885. dump($roomId.'---2--');
  1886. $liveInfo["is_online"] = 0;
  1887. $redis->set("live_" . $roomId, json_encode($liveInfo));
  1888. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  1889. }else{
  1890. dump($roomId.'---3--');
  1891. $redis->del("online_" . $roomId);
  1892. $liveInfo["is_online"] = 0;
  1893. $redis->set("live_" . $roomId, json_encode($liveInfo));
  1894. \app\common\model\Party::update(["is_online" => 0], ["id" => $roomId]);
  1895. }
  1896. }
  1897. }
  1898. $this->success("获取成功!");
  1899. }
  1900. }