97 lines
3.2 KiB
PHP
97 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Db;
|
|
use think\Model;
|
|
|
|
class RoomMicroGift extends Model
|
|
{
|
|
|
|
//麦位礼物变更
|
|
public function update_room_micro_gift($uid, $user_id, $rid, $gid, $position){
|
|
//当前用户是否在麦位上
|
|
$room_info = db::name('room')->find($rid);
|
|
$room_micro_arr = db::name('room_micro')->where('rid', $rid)->column('uid');
|
|
|
|
if($position == 1){
|
|
$gift_position = 'frame_gid';
|
|
}else if($position == 2){
|
|
$gift_position = 'centre_gid';
|
|
}else if($position == 3){
|
|
$gift_position = 'above_gid';
|
|
}else if($position == 4){
|
|
$gift_position = 'below_gid';
|
|
}else if($position == 5){
|
|
$gift_position = 'left_gid';
|
|
}else if($position == 6){
|
|
$gift_position = 'right_gid';
|
|
}
|
|
|
|
|
|
if($user_id == $room_info['room_host_uid']){
|
|
$update = [];
|
|
$update[$gift_position] = $gid;
|
|
$update['update_time'] = time();
|
|
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
|
if(!$reslut){
|
|
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
|
}
|
|
}else if(in_array($user_id, $room_micro_arr)){
|
|
|
|
$update = [];
|
|
$update[$gift_position] = $gid;
|
|
$update['update_time'] = time();
|
|
$reslut = db::name('room_micro')->where('rid', $rid)->where('uid', $user_id)->update($update);
|
|
|
|
if(!$reslut){
|
|
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
|
|
|
}
|
|
|
|
//下麦删除麦位礼物
|
|
public function down_micro_del_position_gift($uid, $rid){
|
|
//当前用户是否在麦位上
|
|
$room_info = db::name('room')->find($rid);
|
|
$room_micro_arr = db::name('room_micro')->where('rid', $rid)->column('uid');
|
|
|
|
if($uid == $room_info['room_host_uid']){
|
|
$update = [];
|
|
$update['frame_gid'] = 0;
|
|
$update['centre_gid'] = 0;
|
|
$update['above_gid'] = 0;
|
|
$update['below_gid'] = 0;
|
|
$update['left_gid'] = 0;
|
|
$update['right_gid'] = 0;
|
|
$update['update_time'] = time();
|
|
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
|
if(!$reslut){
|
|
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
|
}
|
|
}else if(in_array($uid, $room_micro_arr)){
|
|
$update = [];
|
|
$update['frame_gid'] = 0;
|
|
$update['centre_gid'] = 0;
|
|
$update['above_gid'] = 0;
|
|
$update['below_gid'] = 0;
|
|
$update['left_gid'] = 0;
|
|
$update['right_gid'] = 0;
|
|
$update['update_time'] = time();
|
|
$reslut = db::name('room_micro')->where('rid', $rid)->where('uid', $uid)->update($update);
|
|
if(!$reslut){
|
|
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
|
}
|
|
}
|
|
|
|
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|