Party.php 86 KB

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