|
@@ -16,7 +16,8 @@ class Plantask extends Controller
|
|
|
|
|
|
|
|
|
//送礼物(api/party/giveGiftToYou)拆分出来的异步用户升级方法,
|
|
|
- public function auto_user_level_up(){
|
|
|
+
|
|
|
+ public function auto_user_level_up_old(){
|
|
|
Db::startTrans();
|
|
|
$tasklist = Db::name('gift_user_party')->where('task_status',0)->limit(20)->lock(true)->select();
|
|
|
if(empty($tasklist)){
|
|
@@ -140,60 +141,103 @@ class Plantask extends Controller
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //最新方法
|
|
|
+ public function auto_user_level_up(){
|
|
|
+ Db::startTrans();
|
|
|
+
|
|
|
+ $tasklist = Db::name('gift_user_party')->where('task_status',0)->order('id asc')->field('party_id')->select();
|
|
|
+
|
|
|
+ if(empty($tasklist)){
|
|
|
+ Db::rollback();
|
|
|
+ echo 'empty';
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ //redis
|
|
|
+ $redis = new Redis();
|
|
|
+ $redisconfig = config("redis");
|
|
|
+ $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
+ if ($redisconfig['redis_pwd']) {
|
|
|
+ $redis->auth($redisconfig['redis_pwd']);
|
|
|
+ }
|
|
|
+ if($redisconfig['redis_selectdb'] > 0){
|
|
|
+ $redis->select($redisconfig['redis_selectdb']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //开始
|
|
|
+ $party_ids = array_column($tasklist,'party_id');
|
|
|
+ $party_ids = array_flip($party_ids);
|
|
|
+ $party_ids = array_flip($party_ids);
|
|
|
+ //dump($party_ids);
|
|
|
+ $partyInfo_arr = Db::name('party')->where('id','IN',$party_ids)->column('id,user_id,easemob_room_id');
|
|
|
+ //dump($partyInfo_arr);exit;
|
|
|
+ foreach($partyInfo_arr as $party_id => $partyInfo){
|
|
|
+ //更新麦位魅力值
|
|
|
+ $this->updateSeatCharm($partyInfo['easemob_room_id'],$partyInfo,$redis);
|
|
|
+ }
|
|
|
+
|
|
|
+ //结束
|
|
|
+ $rs_up = Db::name('gift_user_party')->where('id','IN',$party_ids)->update(['task_status'=>1]);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ } catch (ValidateException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/////////////////////////////////////////下面都是工具方法////////////////////////////////////////////////
|
|
|
|
|
|
/**
|
|
|
* 用户赠送礼物后房间内麦位魅力值增加,更新到麦位自定义信息
|
|
|
* $seatnum 座位数字 1,不是键名 seat1
|
|
|
*/
|
|
|
- private function updateSeatCharm($easemob_room_id,$seatnum,$giftValue,$party_info,$redis) {
|
|
|
+ private function updateSeatCharm($easemob_room_id,$party_info,$redis) {
|
|
|
//获取已有信息
|
|
|
- $key = 'seat'.$seatnum;
|
|
|
+
|
|
|
$easemob = new Easemob();
|
|
|
- $seatdata = $easemob->room_getRoomCustomAttribute($easemob_room_id,[$key]);
|
|
|
-
|
|
|
- if(empty($seatdata)){
|
|
|
- //默认为空
|
|
|
- $seatdata = [
|
|
|
- 'charm' => 0, //红心,魅力值
|
|
|
-
|
|
|
- 'isMaster' => false, // 是否是房主
|
|
|
- 'headUrl' => '', // 头像
|
|
|
- 'userNo' => '', // 座位上用户no
|
|
|
- 'rtcUid' => '', // 座位上用户id,与rtc的userId一致
|
|
|
- 'name' => '', // 座位上用户昵称
|
|
|
- 'seatIndex' => $seatnum, // 座位编号
|
|
|
- 'chorusSongCode' => '', // 是否合唱
|
|
|
- 'isAudioMuted' => 1, // 是否静音
|
|
|
- 'isVideoMuted' => 0, // 是否开启视频
|
|
|
- 'checked' => false, // 用于送礼物选择用户
|
|
|
- 'isUsed' => true, // 用于送礼物选择用户
|
|
|
- 'gender' => 1, //性别
|
|
|
- ];
|
|
|
- }else{
|
|
|
- $seatdata = json_decode($seatdata[$key],true);
|
|
|
+ $seatlist = $easemob->room_getRoomCustomAttribute($easemob_room_id,['seat0','seat1','seat2','seat3','seat4','seat5','seat6','seat7']);
|
|
|
+
|
|
|
+ if(empty($seatlist)){
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
+ $matedata = [];
|
|
|
|
|
|
// 获取用户魅力值
|
|
|
$users = $redis->zRevRange("hourCharm_".$party_info['id'],0,-1,true);
|
|
|
- $u = [];
|
|
|
- if($users) {
|
|
|
- foreach($users as $k => $v){
|
|
|
- if(isset($seatdata['userNo']) && $seatdata['userNo'] == $k){
|
|
|
- $seatdata['charm'] = changeW($v);
|
|
|
+
|
|
|
+ //轮询麦位
|
|
|
+ foreach($seatlist as $seatnum => $seatdata){
|
|
|
+ $seatdata = json_decode($seatdata,true);
|
|
|
+
|
|
|
+ if($users) {
|
|
|
+ foreach($users as $user_id => $charm){
|
|
|
+ if(isset($seatdata['userNo']) && $seatdata['userNo'] == $user_id){
|
|
|
+ $seatdata['charm'] = changeW($charm);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ $seatdata = json_encode($seatdata);
|
|
|
+
|
|
|
+ $matedata[$seatnum] = $seatdata;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//重新设置麦位小红心
|
|
|
- // tcp 获取房间用户周前三名 getPartyUserTop里面摘出来的一部分
|
|
|
+ //获取房间用户周前三名 getPartyUserTop里面摘出来的一部分
|
|
|
//[环信]更新财富榜前3。
|
|
|
$avatarArr = $redis->hGet("user_jewel_top3",$party_info['id']);
|
|
|
- $matedata = [
|
|
|
- $key => json_encode($seatdata),
|
|
|
- 'wealth_top3_userlist' => $avatarArr,
|
|
|
- ];
|
|
|
+ $matedata['wealth_top3_userlist'] = $avatarArr;
|
|
|
$easemob->room_setRoomCustomAttributeForced($easemob_room_id,$party_info['user_id'],$matedata);
|
|
|
|
|
|
return true;
|