diff --git a/application/api/controller/Cron.php b/application/api/controller/Cron.php index 9f0a7712..83b187cc 100644 --- a/application/api/controller/Cron.php +++ b/application/api/controller/Cron.php @@ -14,7 +14,6 @@ class Cron * pk发起10秒后无应答拒绝 * 提现云账号订单状态查询 * 签约房时间结束处理 - * 系统降身价 * 签约到期处理 */ public function PerformPerSecond() @@ -52,6 +51,7 @@ class Cron /* * 清除房间热度值 * 清除房间离线超24小时的用户 + * 系统降身价 */ public function DaySeconds() { diff --git a/application/api/model/RoomPit.php b/application/api/model/RoomPit.php index ba8041d8..21c4655d 100644 --- a/application/api/model/RoomPit.php +++ b/application/api/model/RoomPit.php @@ -624,7 +624,7 @@ class RoomPit extends Model } //同意上麦 - public function agree_pit($user_id,$room_id,$apply_id) + public function agree_pit($user_id,$room_id,$apply_id,$tpe = 0) { if(!$room_id){ return ['code' => 0, 'msg' => '请选择房间', 'data' => null]; @@ -712,11 +712,14 @@ class RoomPit extends Model //结束循环 break; } - //删除他的申请上麦 - $reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete(); - if (!$reslut) { - continue; + if($tpe == 0){ + //删除他的申请上麦 + $reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete(); + if (!$reslut) { + continue; + } } + $ompit = db::name('vs_room_pit_simulate')->insert( [ 'room_id' => $room_id, @@ -1048,6 +1051,14 @@ class RoomPit extends Model if($room_type == 7 && ($pit_number == 7 || $pit_number == 8)){ return ['code' => 0, 'msg' => '互娱房 不能上7、8号麦位', 'data' => null]; } + $room_label = db::name('vs_room')->where(['id' => $room_id])->value('label_id'); + if($room_type == 1 && $room_label == 2 && !$pit_number){ + $res = model('RoomPit')->agree_pit($user_id, $room_id, $accept_user_id,1); + if($res['code'] == 0){ + return ['code' => 0, 'msg' => $res['msg'], 'data' => null]; + } + return ['code' => 1, 'msg' => '操作成功', 'data' => null]; + } if($room_type == 10){ if($pit_number == 1){ //查询主持邀请列表是否是有数据 diff --git a/application/cron/controller/DaySeconds.php b/application/cron/controller/DaySeconds.php index 083bae33..baf1dfca 100644 --- a/application/cron/controller/DaySeconds.php +++ b/application/cron/controller/DaySeconds.php @@ -22,6 +22,10 @@ class DaySeconds echo "清除房间离线超24小时的用户:\n"; $this->clear_room_offline_user();//0点以后清除房间离线超24小时用户 echo "\n"; + + echo "系统降身价:\n"; + $this->system_downgrade(); + echo "\n"; } @@ -62,4 +66,76 @@ class DaySeconds echo date('Y-m-d H:i:s').' 完成'."\n"; } + + //系统降身价 + public function system_downgrade(){ + //获取系统信息 + $down_market_value = explode(',',get_system_config_value('down_market_value')); + if($down_market_value){ + $day = $down_market_value[0]; + $market_value = $down_market_value[1]; + }else{ + $day = 0; + $market_value = 0; + } + + $num = 0; + if($day && $market_value){ + //查询每个用户的身价 + $user_market_value = db::name('user')->field('id,market_value')->select(); + if($user_market_value){ + foreach ($user_market_value as $value){ + if($value['market_value'] > 1){ + //获取他的降级时间 + $down_time = db::name('vs_user_market_value_log')->where(['user_id' => $value['id'],'type' =>1]) + ->order('id desc')->value('createtime'); + + //如果没有降级记录,则使用当前时间作为起始时间 + if(empty($down_time)){ + $down_time = 0; + } + + //检查是否到了降级时间 + if(time() - $down_time >= $day*86400){ + //开始降身价 + db::startTrans(); + try { + $market_values = max($value['market_value'] - $market_value, 1); + $update_result = db::name('user')->where('id', $value['id'])->update(['market_value' => $market_values]); + + if($update_result) { + $data = [ + 'user_id' => $value['id'], + 'before' => $value['market_value'], + 'change_value' => $market_value, + 'afterwards' => $market_values, + 'type' => 1, + 'createtime' => time() + ]; + $res = db::name('vs_user_market_value_log')->insert($data); + + if($res){ + $num += 1; + db::commit(); + }else{ + db::rollback(); + \think\Log::error("系统降身价失败: 插入日志失败 user_id={$value['id']}"); + } + } else { + db::rollback(); + \think\Log::error("系统降身价失败: 更新用户身价失败 user_id={$value['id']}"); + } + } catch (\Exception $e) { + db::rollback(); + \think\Log::error("系统降身价异常: " . $e->getMessage() . " user_id={$value['id']}"); + } + } + } + } + } + } + echo "系统降身价完成:".$num."\n"; + } + + } \ No newline at end of file diff --git a/application/cron/controller/PerformPerSecond.php b/application/cron/controller/PerformPerSecond.php index 4ec7988d..cfbd1c9a 100644 --- a/application/cron/controller/PerformPerSecond.php +++ b/application/cron/controller/PerformPerSecond.php @@ -51,10 +51,6 @@ class PerformPerSecond $this->sign_room_time_end(); echo "\n"; - echo "系统降身价:\n"; - $this->system_downgrade(); - echo "\n"; - echo "公会会员结算比例申请过期处理:\n"; $this->user_ratio_up_apply_timeout(); echo "\n"; @@ -374,72 +370,7 @@ class PerformPerSecond } } - //系统降身价 - public function system_downgrade(){ - //获取系统信息 - $down_market_value = explode(',',get_system_config_value('down_market_value')); - if($down_market_value){ - $day = $down_market_value[0]; - $market_value = $down_market_value[1]; - }else{ - $day = 0; - $market_value = 0; - } - if($day && $market_value){ - //查询每个用户的身价 - $user_market_value = db::name('user')->field('id,market_value')->select(); - if($user_market_value){ - foreach ($user_market_value as $value){ - if($value['market_value'] > 1){ - //获取他的降级时间 - $down_time = db::name('vs_user_market_value_log')->where(['user_id' => $value['id'],'type' =>1]) - ->order('id desc')->value('createtime'); - - //如果没有降级记录,则使用当前时间作为起始时间 - if(empty($down_time)){ - $down_time = time(); - } - - //检查是否到了降级时间 - if(time() - $down_time >= $day*86400){ - //开始降身价 - db::startTrans(); - try { - $market_values = max($value['market_value'] - $market_value, 1); - $update_result = db::name('user')->where('id', $value['id'])->update(['market_value' => $market_values]); - - if($update_result) { - $data = [ - 'user_id' => $value['id'], - 'before' => $value['market_value'], - 'change_value' => $market_value, - 'afterwards' => $market_values, - 'type' => 1, - 'createtime' => time() - ]; - $res = db::name('vs_user_market_value_log')->insert($data); - - if($res){ - db::commit(); - }else{ - db::rollback(); - \think\Log::error("系统降身价失败: 插入日志失败 user_id={$value['id']}"); - } - } else { - db::rollback(); - \think\Log::error("系统降身价失败: 更新用户身价失败 user_id={$value['id']}"); - } - } catch (\Exception $e) { - db::rollback(); - \think\Log::error("系统降身价异常: " . $e->getMessage() . " user_id={$value['id']}"); - } - } - } - } - } - } - } //公会会员结算比例申请过期处理 public function user_ratio_up_apply_timeout(){ //超过24小时的数据