仓库初始化
This commit is contained in:
151
application/api/model/Activities.php
Normal file
151
application/api/model/Activities.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
|
||||
class Activities extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
public static function init()
|
||||
{
|
||||
self::beforeWrite(function ($row) {
|
||||
});
|
||||
}
|
||||
/*
|
||||
* 首充好礼发放
|
||||
*/
|
||||
public static function first_charge_gift_send($user_id,$money=0)
|
||||
{
|
||||
//礼包
|
||||
$gift_bag_id = DB::name('vs_gift_bag')->where(['activities_id'=>1,'status'=>1,'money'=>$money])->value('id');
|
||||
if (!$gift_bag_id) {
|
||||
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
||||
}
|
||||
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select();
|
||||
if (!$gift_bag_detail) {
|
||||
return ['code' => 0, 'msg' => '礼包未配置','data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($gift_bag_detail as $k=>$v){
|
||||
switch ($v['type']) {
|
||||
case 1: //金币 方法1:直接添加到用户钱包
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::FIRST_CHARGE,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::FIRST_CHARGE));
|
||||
break;
|
||||
case 2: //礼物 方法2:添加到用户礼物背包
|
||||
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::FIRST_CHARGE,"首充好礼获得礼物");
|
||||
break;
|
||||
case 3: //坐骑 方法3:添加到用户装扮
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
||||
if(empty($decorate_price_info)){
|
||||
continue;
|
||||
}
|
||||
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],5);
|
||||
break;
|
||||
case 4: //道具 方法5:钻石
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::FIRST_CHARGE,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::FIRST_CHARGE));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ($res['code'] != 1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
// 记录日志
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
// 添加活动记录
|
||||
$reslut = Db::name('vs_activities_receive')->insert([
|
||||
'user_id' => $user_id,
|
||||
'activities_id' => 1,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 天降好礼发放
|
||||
*/
|
||||
public static function drop_gift_send($user_id)
|
||||
{
|
||||
$activities_id = 3;
|
||||
//礼包
|
||||
$gift_bag_id = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->value('id');
|
||||
if (!$gift_bag_id) {
|
||||
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
||||
}
|
||||
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select();
|
||||
if (!$gift_bag_detail) {
|
||||
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($gift_bag_detail as $k=>$v){
|
||||
switch ($v['type']) {
|
||||
case 1: //金币 方法1:直接添加到用户钱包
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::DROP_GIFT_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DROP_GIFT_REWARD));
|
||||
break;
|
||||
case 2: //礼物 方法2:添加到用户礼物背包
|
||||
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::DRAW_GIFT,"天降好礼获得礼物");
|
||||
break;
|
||||
case 3: //坐骑 方法3:添加到用户装扮
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
||||
if(empty($decorate_price_info)){
|
||||
continue;
|
||||
}
|
||||
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],6);
|
||||
break;
|
||||
case 4: //道具 方法5:钻石
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::DROP_GIFT_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DROP_GIFT_REWARD));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ($res['code'] != 1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
// 记录日志
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
// 添加活动记录
|
||||
$reslut = Db::name('vs_activities_receive')->insert([
|
||||
'user_id' => $user_id,
|
||||
'activities_id' => $activities_id,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
476
application/api/model/Agora.php
Normal file
476
application/api/model/Agora.php
Normal file
@@ -0,0 +1,476 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Loader;
|
||||
use think\Model;
|
||||
|
||||
Loader::import('shengwang.Shengwang', EXTEND_PATH, '.php');
|
||||
class Agora extends Model
|
||||
{
|
||||
//获取歌曲列表
|
||||
public function agora_song_list($page, $page_limit, $song_code){
|
||||
$config = get_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];//cc71b8df2c254c35bc96fbf591b6801f
|
||||
$requestId = 'df2ce922m28xy80z80i3j7tq2vbooetv';
|
||||
$pageType = $page;
|
||||
$pageCode = $song_code;
|
||||
$size = $page_limit;
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$postUrl = 'https://api.agora.io/cn/v1.0/projects/'.$agora_app_id.'/ktv-service/api/serv/songs?requestId='.$requestId.'&pageType='.$pageType.'&pageCode='.$pageCode.'&size='.$size;
|
||||
$headerArray =array(
|
||||
"Content-type:application/json",
|
||||
"Accept:application/json",
|
||||
"Authorization:Basic ".$AuthorizationHeader,
|
||||
);
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);//设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
// curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);CURLOPT_RETURNTRANSFER
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$data = curl_exec($ch);//运行curl
|
||||
curl_close($ch);
|
||||
$data = json_decode($data, true);
|
||||
if($data['code'] == 0){
|
||||
return ['code' => 200, 'msg' => $data['msg'], 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $data['msg'], 'data' => null];
|
||||
}
|
||||
// dump($data);
|
||||
}
|
||||
|
||||
//获取增量歌曲列表
|
||||
public function agora_new_song_list($page, $page_limit, $lastUpdateTime = 0){
|
||||
$config = get_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];//cc71b8df2c254c35bc96fbf591b6801f
|
||||
$requestId = 'df2ce922m28xy80z80i3j7tq2vbooetv';
|
||||
$pageType = $page;
|
||||
// $pageCode = $song_code;
|
||||
$size = $page_limit;
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$postUrl = 'https://api.agora.io/cn/v1.0/projects/'.$agora_app_id.'/ktv-service/api/serv/songs-incr?requestId='.$requestId.'&lastUpdateTime='.$lastUpdateTime.'&size='.$size.'&pageType='.$pageType;//'&pageType='.$pageType.'&pageCode='.$pageCode.'&size='.$size.
|
||||
$headerArray =array(
|
||||
"Content-type:application/json",
|
||||
"Accept:application/json",
|
||||
"Authorization:Basic ".$AuthorizationHeader,
|
||||
);
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);//设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
// curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);CURLOPT_RETURNTRANSFER
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$data = curl_exec($ch);//运行curl
|
||||
curl_close($ch);
|
||||
$data = json_decode($data, true);
|
||||
|
||||
if($data['code'] == 0){
|
||||
return ['code' => 200, 'msg' => $data['msg'], 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $data['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//获取指定歌曲详情
|
||||
public function agora_song_info($song_code, $lyric_type){
|
||||
$config = get_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];//cc71b8df2c254c35bc96fbf591b6801f
|
||||
$requestId = 'df2ce922m28xy80z80i3j7tq2vbooetv';
|
||||
$songCode = $song_code;
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
$lyric_type = 1;
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$postUrl = 'https://api.agora.io/cn/v1.0/projects/'.$agora_app_id.'/ktv-service/api/serv/song-url?requestId='.$requestId.'&lyricType='.$lyric_type.'&songCode='.$songCode;//'&pageType='.$pageType.'&pageCode='.$pageCode.'&size='.$size.
|
||||
$headerArray =array(
|
||||
"Content-type:application/json",
|
||||
"Accept:application/json",
|
||||
"Authorization:Basic ".$AuthorizationHeader,
|
||||
);
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);//设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
// curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);CURLOPT_RETURNTRANSFER
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$data = curl_exec($ch);//运行curl
|
||||
curl_close($ch);
|
||||
$data = json_decode($data, true);
|
||||
// dump($data);exit;
|
||||
if($data['code'] == 0){
|
||||
return ['code' => 200, 'msg' => $data['msg'], 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $data['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//获取声网token信息
|
||||
public function agora_token_info($uid, $room_id){
|
||||
$config = get_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];
|
||||
$agora_app_certificate = $config['agora_app_certificate'];
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
|
||||
$agora = new \shengwang\Shengwang();
|
||||
$Rtc_token = $agora->RtcTokenBuilder($uid, $room_id, 0, $agora_app_id, $agora_app_certificate);
|
||||
|
||||
return $Rtc_token;
|
||||
}
|
||||
|
||||
//同步热门歌单
|
||||
public function synchro_agora_song_hot($hot_type){
|
||||
$config = get_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];//cc71b8df2c254c35bc96fbf591b6801f
|
||||
$requestId = 'df2ce922m28xy80z80i3j7tq2vbooetv';
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$postUrl = 'https://api.agora.io/cn/v1.0/projects/'.$agora_app_id.'/ktv-service/api/serv/song-hot?requestId='.$requestId.'&hotType='.$hot_type;
|
||||
$headerArray =array(
|
||||
"Content-type:application/json",
|
||||
"Accept:application/json",
|
||||
"Authorization:Basic ".$AuthorizationHeader,
|
||||
);
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 1);//设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
// curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);CURLOPT_RETURNTRANSFER
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$data = curl_exec($ch);//运行curl
|
||||
curl_close($ch);
|
||||
$data = json_decode($data, true);
|
||||
if($data['code'] == 0){
|
||||
return ['code' => 200, 'msg' => $data['msg'], 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $data['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************分 割 线***********************************************************/
|
||||
|
||||
//同步热门歌单
|
||||
public function synchro_hot_song($hot_type){
|
||||
$time = date('Y-m-d').' 5:00:00';
|
||||
$time = strtotime($time);
|
||||
//当天是否已同步
|
||||
$map = [];
|
||||
$map[] = ['add_time', '>=', $time];
|
||||
$hot_song = db::name('agora_song_hot')->where($map)->order('hid desc')->limit(1)->find();
|
||||
if($hot_song){
|
||||
return ['code' => 201, 'msg' => '今日已同步过热门歌单', 'data' => null];
|
||||
}
|
||||
//获取热门歌单
|
||||
$datas = model('Agora')->synchro_agora_song_hot($hot_type);
|
||||
if($datas['code'] == 200){
|
||||
if(empty($datas['data']['list'])){
|
||||
return['code' => 201, 'msg' => '暂无歌曲数据', 'data' => null];
|
||||
}else{
|
||||
$data = [];
|
||||
$data_array = [];
|
||||
foreach ($datas['data']['list'] as $k => $v){
|
||||
$data['song_code'] = $v['songCode'];
|
||||
$data['num'] = $v['num'];
|
||||
$data['add_time'] = time();
|
||||
$data_array[] = $data;
|
||||
}
|
||||
|
||||
$result = db::name('agora_song_hot')->insertAll($data_array);
|
||||
if($result){
|
||||
return ['code' => 200, 'msg' => '同步成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '同步失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $datas['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//热歌榜单
|
||||
public function hot_song_list(){
|
||||
$data = db::name('agora_song_hot')->alias('a')->join('yy_agora_song b','a.song_code = b.song_code')->field('a.hid,a.song_code,a.num,b.song_name,b.poster,b.singer,duration')->order('hid asc')->limit(100)->select();
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//获得歌曲列表
|
||||
public function song_list($name, $page, $page_limit){
|
||||
$map = [];
|
||||
if(!empty($name)){
|
||||
$map[] = ['song_name|singer', 'like', '%'.$name.'%'];
|
||||
}
|
||||
|
||||
$data = db::name('agora_song')->where($map)->order('aid asc')->page($page, $page_limit)->select();
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//点歌
|
||||
public function dot_song($uid, $rid, $song_code, $is_accapella){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '该用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->where('rid', $rid)->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$song = db::name('agora_song')->where('song_code', $song_code)->find();
|
||||
if(!$song){
|
||||
return ['code' => 201, 'msg' => '该歌曲不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['song_code', '=', $song_code];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$song_dot = db::name('agora_song_dot')->where($map)->find();
|
||||
if($song_dot){
|
||||
return ['code' => 201, 'msg' => '该歌曲已点过', 'data' => null];
|
||||
}
|
||||
|
||||
//K歌厅点歌限制
|
||||
if($room_info['cate_id'] == 27){
|
||||
//当前是否已进唱歌模式
|
||||
$auction_info = db::name('room_song_log')->where('rid', $rid)->where('is_delete', 1)->find();
|
||||
if($auction_info){
|
||||
$user_song_dot_arr = explode(',', $auction_info['uid_array']);
|
||||
if(in_array($uid, $auction_info)){
|
||||
$where = [];
|
||||
$where[] = ['uid', '=', $uid];
|
||||
$where[] = ['rsid', '=', $auction_info['id']];
|
||||
$where[] = ['status', '>', 1];
|
||||
$user_song_info = db::name('room_song_user_log')->where($where)->find();
|
||||
if($user_song_info){
|
||||
return ['code' => 201, 'msg' => '您已过了唱歌阶段无法点歌', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '当前活动进行中无法点歌', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//练歌房一个用户只能点一首歌
|
||||
// if($room_info['cate_id'] == 27){
|
||||
// $map = [];
|
||||
// $map[] = ['rid', '=', $rid];
|
||||
// $map[] = ['uid', '=', $uid];
|
||||
// $map[] = ['song_code', '=', $song_code];
|
||||
// $map[] = ['is_delete', '=', 1];
|
||||
// $song_dot = db::name('agora_song_dot')->where($map)->find();
|
||||
// if($song_dot){
|
||||
// return ['code' => 201, 'msg' => '你有点歌的尚未唱完,无法再次点歌', 'data' => null];
|
||||
// }
|
||||
// }
|
||||
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_song_dot = db::name('agora_song_dot')->where($map)->find();
|
||||
if($user_song_dot){
|
||||
$update = [];
|
||||
$update['song_code'] = $song_code;
|
||||
$update['is_accapella'] = $is_accapella;
|
||||
$update['update_time'] = time();
|
||||
$result = db::name('agora_song_dot')->where('did', $user_song_dot['did'])->update($update);
|
||||
}else{
|
||||
$data = [];
|
||||
$data['rid'] = $rid;
|
||||
$data['uid'] = $uid;
|
||||
$data['song_code'] = $song_code;
|
||||
$data['is_accapella'] = $is_accapella;
|
||||
$data['add_time'] = time();
|
||||
$result = db::name('agora_song_dot')->insert($data);
|
||||
}
|
||||
|
||||
if($result){
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$song_data = db::name('agora_song_dot')->alias('a')->join('yy_user b','a.uid = b.uid')->join('yy_agora_song c','c.song_code = a.song_code')->field('a.did,a.rid,a.uid,a.song_code,c.song_name,c.poster,c.singer,c.duration,b.base64_nick_name,a.is_accapella')->where($map)->select();
|
||||
foreach ($song_data as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
// dump($song_data);
|
||||
//socket播报
|
||||
$push_data = [];
|
||||
$push_data['code'] = 401;
|
||||
$push_data['msg'] = "点歌房间播报";
|
||||
$push_data['data'] = $song_data;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
return ['code' => 200, 'msg' => '点歌成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '点歌失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//取消点歌
|
||||
public function dot_song_del($uid, $rid, $song_code){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '该用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->where('rid', $rid)->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($song_code)){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$song_code = explode(',', $song_code);
|
||||
$map = [];
|
||||
$map[] = ['song_code', 'in', $song_code];
|
||||
$song = db::name('agora_song')->where($map)->find();
|
||||
if(!$song){
|
||||
return ['code' => 201, 'msg' => '该歌曲不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['song_code', 'in', $song_code];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
if($room_info['room_owner_uid'] != $uid){
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$song_dot = db::name('agora_song_dot')->where($map)->find();
|
||||
if(!$song_dot){
|
||||
return ['code' => 201, 'msg' => '你尚未点击该首歌曲', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['is_delete'] = 2;
|
||||
$data['delete_time'] = time();
|
||||
$result = db::name('agora_song_dot')->where($map)->update($data);
|
||||
if($result){
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$song_data = db::name('agora_song_dot')->alias('a')->join('yy_user b','a.uid = b.uid')->join('yy_agora_song c','c.song_code = a.song_code')->field('a.did,a.rid,a.uid,a.song_code,c.song_name,c.poster,c.singer,c.duration,b.base64_nick_name')->where($map)->select();
|
||||
foreach ($song_data as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
//socket播报
|
||||
$push_data = [];
|
||||
$push_data['code'] = 401;
|
||||
$push_data['msg'] = "点歌房间播报";
|
||||
$push_data['data'] = $song_data;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
return ['code' => 200, 'msg' => '取消成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '取消失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//点歌列表
|
||||
public function dot_song_list($rid){
|
||||
$room_info = db::name('room')->where('rid', $rid)->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$song_data = db::name('agora_song_dot')->alias('a')->join('yy_user b','a.uid = b.uid')->join('yy_agora_song c','c.song_code = a.song_code')->field('a.did,a.rid,a.uid,a.song_code,c.song_name,c.poster,c.singer,c.duration,b.base64_nick_name')->where($map)->order('did asc')->select();
|
||||
foreach ($song_data as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '点歌成功', 'data' => $song_data];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function agora_rtm_token_info($uid,$room_id)
|
||||
{
|
||||
// require_once Env::get('root_path') . 'extend/shengwang/Shengwang.php';
|
||||
$config = get_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];
|
||||
$agora_app_certificate = $config['agora_app_certificate'];
|
||||
// $agora_app_key = $config['agora_app_key'];
|
||||
// $agora_app_secret = $config['agora_app_secret'];
|
||||
|
||||
|
||||
$agora = new \shengwang\Shengwang();
|
||||
$Rtm_token = $agora->RtmTokenBuilders($uid, $agora_app_id, $agora_app_certificate,$room_id);
|
||||
|
||||
return $Rtm_token;
|
||||
}
|
||||
|
||||
//取消用户点歌
|
||||
public function user_quit_song_del($uid, $rid){
|
||||
//查询当前用户在该房间所点歌曲
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_song_list = db::name('agora_song_dot')->where($map)->select();
|
||||
if($user_song_list){
|
||||
$update_data = [];
|
||||
$update_data['is_delete'] = 2;
|
||||
$update_data['delete_time'] = time();
|
||||
$result = db::name('agora_song_dot')->where($map)->update($update_data);
|
||||
if($result){
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$song_data = db::name('agora_song_dot')->alias('a')->join('yy_user b','a.uid = b.uid')->join('yy_agora_song c','c.song_code = a.song_code')->field('a.did,a.rid,a.uid,a.song_code,a.is_accapella,c.song_name,c.poster,c.singer,c.duration,b.base64_nick_name,b.sex')->where($map)->select();
|
||||
foreach ($song_data as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
//socket播报
|
||||
$push_data = [];
|
||||
$push_data['code'] = 401;
|
||||
$push_data['msg'] = "点歌房间播报";
|
||||
$push_data['data'] = $song_data;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
56
application/api/model/Banner.php
Normal file
56
application/api/model/Banner.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Banner extends Model
|
||||
{
|
||||
protected $table = 'fa_vs_banner';
|
||||
public $ShowType = [
|
||||
// 1 => '引导页',
|
||||
// 2 => '启动页',
|
||||
3 => '首页轮播图',
|
||||
4 => '工会',
|
||||
5 => '帮助反馈'
|
||||
];
|
||||
//1纯展示 2文章 3房间 4个人主页 5外站'
|
||||
public $Type = [
|
||||
1 => '纯展示',
|
||||
2 => '文章',
|
||||
3 => '房间',
|
||||
4 => '个人主页',
|
||||
5 => '外站'
|
||||
];
|
||||
//l轮播广告位
|
||||
public function banner_list($type)
|
||||
{
|
||||
$map = [
|
||||
'show_status' => 1,
|
||||
'delete_time' => 0,
|
||||
'show_type' => $type,
|
||||
];
|
||||
$list = db::name('vs_banner')->where($map)->field('bid,aid,type,show_type,image')->order('sort desc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['url'] ="";
|
||||
if ($v['type'] == 2) {
|
||||
$v['image'] = localpath_to_netpath($v['image']);
|
||||
if($v['url']){
|
||||
$v['url'] = $v['url'];
|
||||
}else{
|
||||
$v['url'] = get_system_config_value('web_site').'/api/Banner/banner_content_show?id='.$v['bid'];
|
||||
}
|
||||
}elseif ($v['type'] == 3) {
|
||||
$room_info = Db::name('vs_room')->where('rid', $v['aid'])->where('delete_time',0)->find();
|
||||
$v['image'] = localpath_to_netpath($room_info['room_cover']);
|
||||
}elseif ($v['type'] == 4) {
|
||||
$v['image'] = localpath_to_netpath($v['image']);
|
||||
}elseif ($v['type'] == 5) {
|
||||
$v['image'] = localpath_to_netpath($v['image']);
|
||||
$v['url'] = $v['url'];
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
132
application/api/model/Chat.php
Normal file
132
application/api/model/Chat.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
|
||||
class Chat extends Model
|
||||
{
|
||||
|
||||
//腾讯IM发送消息
|
||||
public function sendMsg($type,$roomId,$content,$userId = 0)
|
||||
{
|
||||
// /// 系统消息
|
||||
// QXRoomMessageTypeSystem = 1000,
|
||||
// /// 用户进入房间
|
||||
// QXRoomMessageTypeJoin = 1001,
|
||||
// /// 用户退出房间
|
||||
// QXRoomMessageTypeQuit = 1002,
|
||||
// /// 用户上麦
|
||||
// QXRoomMessageTypeUpSeat = 1003,
|
||||
// /// 用户下麦
|
||||
// QXRoomMessageTypeDownSeat = 1004,
|
||||
// /// 房间收到礼物
|
||||
// QXRoomMessageTypeGift = 1005,
|
||||
// /// 设置管理员
|
||||
// QXRoomMessageTypeSetManage = 1006,
|
||||
// /// 设置主持
|
||||
// QXRoomMessageTypeSetCompere = 1007,
|
||||
// /// 禁麦/解禁
|
||||
// QXRoomMessageTypeSeatMute = 1008,
|
||||
// /// 锁麦/解除锁麦
|
||||
// QXRoomMessageTypeSeatLock = 1009,
|
||||
// /// 踢出房间
|
||||
// QXRoomMessageTypeTakeOff = 1011,
|
||||
// /// 房间类型发生变化
|
||||
// QXRoomMessageTypeRoomTypeChanged = 1012,
|
||||
// /// 申请点歌/切歌/同意点歌
|
||||
// QXRoomMessageTypeSwicthSong = 1013,
|
||||
//房间上麦模式改变
|
||||
// UpRoomPItType = 1014,
|
||||
//pk房数值变化
|
||||
// PkRoomVaule = 1015,
|
||||
//禁言,禁麦。解禁
|
||||
// SeatMute = 1016,
|
||||
//删除管理员
|
||||
// DeleteManager = 1017,
|
||||
// 删除主持
|
||||
// DeleteCompere = 1018,
|
||||
//K歌房送礼后魅力变化 排序变化
|
||||
// KRoomGiftChange = 1019,
|
||||
//修改房间信息
|
||||
// ModifyRoomInfo = 1020,
|
||||
//清除房间魅力
|
||||
// ClearRoomCharm = 1021,
|
||||
|
||||
//拍卖者被抱上麦
|
||||
// AuctionerUpSeat = 1022,
|
||||
//拍卖者选完关系(拍卖开始)
|
||||
// AuctionerSelectRelation = 1023,
|
||||
//参与竞拍
|
||||
// RoomAuctionJoin = 1024,
|
||||
//竞拍结束
|
||||
// RoomAuctionEnd = 1025,
|
||||
//拍卖延时
|
||||
// RoomAuctionDelay = 1026,
|
||||
//竞拍类型转换
|
||||
// RoomAuctionTypeChange = 1027,
|
||||
//cp房送礼物推送心动值
|
||||
// KRoomGiftChange = 1028,
|
||||
//PK房发起邀请
|
||||
// RoomAuctionPK = 1029,
|
||||
//房间PK 拒绝和同意
|
||||
// RoomAuctionPK = 1030,
|
||||
//房间PK 开始
|
||||
// RoomAuctionPK = 1031,
|
||||
//房间PK 结束
|
||||
// RoomAuctionPK = 1032,
|
||||
//房间PK 断开
|
||||
// RoomAuctionPK = 1033,
|
||||
//申请上麦
|
||||
// RoomApplyOnPit = 1034,
|
||||
//用户修改信息
|
||||
// ModifyUserInfo = 1035,
|
||||
//房间在线人数
|
||||
// RoomOnlineNumber = 1036,
|
||||
//房间PK 失败者在惩罚阶段提前申请断开链接
|
||||
// RoomAuctionPK = 1037,
|
||||
//送盲盒礼物推送文字消息
|
||||
// RoomGiftBlindBox = 1038,
|
||||
|
||||
|
||||
|
||||
$text = [
|
||||
'MsgType' => $type,
|
||||
'RoomId' => $roomId,
|
||||
'Text' => $content
|
||||
];
|
||||
|
||||
$data = model('api/Tencent')->send_group_system_notification('room'.$roomId,json_encode($text));
|
||||
|
||||
if($data['code'] == 0){
|
||||
Log::record("腾讯发送群消息:".$data['msg'].$type,"info");
|
||||
}else{
|
||||
Log::record("腾讯发送群消息:".$data['msg'].$type,"info");
|
||||
}
|
||||
}
|
||||
|
||||
//指定用户发送给谁单聊消息
|
||||
public function sendMsgToUser($userId,$ToUserId,$content,$type = 2000)
|
||||
{
|
||||
//type 2000 发起PK
|
||||
/*
|
||||
* $text = [
|
||||
'SendUserId' => $create_user_id,//发送者id
|
||||
'SendUserName' => db::name('user')->where('id', $create_user_id)->value('nickname'),//发送者昵称
|
||||
'RoomId' => $room_id_a,//发起者所在房间id
|
||||
'AcceptRoomId' => $room_id_b,//接受者所在房间id
|
||||
'Text' => 'PK邀请',
|
||||
];
|
||||
*/
|
||||
|
||||
$text = [
|
||||
'MsgType' => $type,
|
||||
'ToUserId' => $ToUserId,
|
||||
'Text' => $content
|
||||
];
|
||||
//谁发送给谁,什么消息,是否同步到发送者1是,2否,消息是否只下发给在线用户 1 是,0 否
|
||||
model('Tencent')->user_sendmsg($userId,$ToUserId,json_encode($text),2,1);
|
||||
}
|
||||
}
|
||||
437
application/api/model/DailyTasks.php
Normal file
437
application/api/model/DailyTasks.php
Normal file
@@ -0,0 +1,437 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
use think\Db;
|
||||
|
||||
class DailyTasks extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $table;
|
||||
//每日任务类型枚举
|
||||
public $processing_type_str = [
|
||||
1 => '登录',
|
||||
2 => '去观看',
|
||||
3 => '去完成',
|
||||
4 => '去送礼',
|
||||
5 => '去邀请',
|
||||
6 => '去充值',
|
||||
7 => '去发布',
|
||||
8 => '签到',
|
||||
9 => '自动完成',
|
||||
];
|
||||
public function __construct($data = [])
|
||||
{
|
||||
$prefix = config('database.prefix');
|
||||
$this->table = $prefix . 'vs_daily_tasks';
|
||||
parent::__construct($data);
|
||||
|
||||
}
|
||||
//每日任务列表
|
||||
public function dailyTasksList($user_id=''){
|
||||
$reslut = [];
|
||||
//用户今日充值金币数量
|
||||
$user_gold = Db::name('vs_user_money_log')->where(['user_id'=>$user_id,'change_type'=>2,'money_type'=>1])
|
||||
->whereTime('createtime', 'today')
|
||||
->sum('change_value');
|
||||
$reslut['user_gold'] = $user_gold ? $user_gold : 0;
|
||||
//礼盒列表
|
||||
$gift_box = Db::name('vs_gift_bag')->where('status',1)->where('activities_id',2)->select();
|
||||
$reslut['gift_box_list'] = [];
|
||||
foreach ($gift_box as $key => $val) {
|
||||
$reslut['gift_box_list'][$key]['id'] = $val['id'];
|
||||
$reslut['gift_box_list'][$key]['name'] = $val['name'];
|
||||
$reslut['gift_box_list'][$key]['title'] = $val['title'];
|
||||
$reslut['gift_box_list'][$key]['icon'] = localpath_to_netpath($val['icon']);
|
||||
$ext = json_decode($val['ext'],true);
|
||||
$reslut['gift_box_list'][$key]['highest_gain'] = $ext['highest_gain'];
|
||||
$reslut['gift_box_list'][$key]['meet'] = $ext['meet'] ? $ext['meet'] : 0;
|
||||
//解锁进度
|
||||
if($ext['meet']){
|
||||
if($user_gold > $ext['meet']){
|
||||
$reslut['gift_box_list'][$key]['unlock_progress'] = 1;
|
||||
}else{
|
||||
$reslut['gift_box_list'][$key]['unlock_progress'] = round(( $user_gold / $ext['meet']),2);
|
||||
}
|
||||
}else{
|
||||
$reslut['gift_box_list'][$key]['unlock_progress'] = 0;
|
||||
}
|
||||
//今日可抽奖次数
|
||||
$reslut['gift_box_list'][$key]['all_number'] = $ext['num'] ? $ext['num'] : 0;
|
||||
//今日已抽奖次数
|
||||
$reslut['gift_box_list'][$key]['taday_number'] = Db::name('vs_gift_bag_receive_log')->where('user_id',$user_id)->where('gift_bag_id',$val['id'])->whereTime('createtime', 'today')->count();
|
||||
//今日剩余抽奖次数
|
||||
$reslut['gift_box_list'][$key]['taday_number_left'] = $ext['num'] - $reslut['gift_box_list'][$key]['taday_number'];
|
||||
//状态
|
||||
if ($user_gold < $ext['meet']) {
|
||||
$reslut['gift_box_list'][$key]['status'] = 0;
|
||||
$reslut['gift_box_list'][$key]['status_str'] = '未解锁';
|
||||
} else {
|
||||
$reslut['gift_box_list'][$key]['status'] = 1;
|
||||
$reslut['gift_box_list'][$key]['status_str'] = '已解锁('.$reslut['gift_box_list'][$key]['taday_number'].'/'.$ext['num'].')';
|
||||
}
|
||||
if ($reslut['gift_box_list'][$key]['taday_number']>=$ext['num']) {
|
||||
$reslut['gift_box_list'][$key]['status'] = 2;
|
||||
$reslut['gift_box_list'][$key]['status_str'] = '已用完('.$reslut['gift_box_list'][$key]['taday_number'].'/'.$ext['num'].')';
|
||||
}
|
||||
}
|
||||
//任务列表
|
||||
$reslut['tasks']['daily_tasks'] = [];//每日任务1
|
||||
$reslut['tasks']['daily_tasks_special'] = [];//每日特殊任务2
|
||||
$reslut['tasks']['usual_tasks'] = [];//平台常规任务3
|
||||
$data = db::name('vs_daily_tasks')
|
||||
->field('task_id,icon,task_name,gold_reward,target_quantity,task_type')
|
||||
->where('delete_time',0)
|
||||
->where('is_active',1)
|
||||
->order('sort asc')->select();
|
||||
foreach ($data as $k => $v) {
|
||||
//完成进度
|
||||
if(in_array($v['task_type'],[1,2])){
|
||||
//今日完成进度
|
||||
$user_daily_tasks = Db::name('vs_user_daily_tasks')
|
||||
->where('user_id',$user_id)
|
||||
->where('task_id',$v['task_id'])
|
||||
->whereTime('createtime', 'today')
|
||||
->find();
|
||||
}else{
|
||||
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$v['task_id'])->find();
|
||||
}
|
||||
$progress = isset($user_daily_tasks['current_progress']) ? $user_daily_tasks['current_progress'] : 0;
|
||||
$quantity_str = "";
|
||||
if($v['target_quantity']!=1){
|
||||
$quantity_str= "({$progress}/{$v['target_quantity']})";
|
||||
}
|
||||
$v['task_name'] = $v['task_name'].$quantity_str;
|
||||
//处理状态
|
||||
$v['task_status'] = 1;
|
||||
$v['task_type_str'] = "去完成";
|
||||
if(isset($user_daily_tasks['is_completed']) && $user_daily_tasks['is_completed'] ==1){ //已完成
|
||||
$v['task_status'] = 2;
|
||||
$v['task_type_str'] = "领取金币";
|
||||
}
|
||||
if(isset($user_daily_tasks['is_claimed']) && $user_daily_tasks['is_claimed'] ==1){ //已完成
|
||||
$v['task_status'] = 3;
|
||||
$v['task_type_str'] = "已领取";
|
||||
}
|
||||
if($v['task_id']==1){//每日签到处理
|
||||
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d')])->find();
|
||||
if ($sign_in_info) {
|
||||
$v['task_status'] =3;
|
||||
$v['task_type_str'] = "已签到";
|
||||
}else{
|
||||
$v['task_status'] = 1;
|
||||
$v['task_type_str'] = "去签到";
|
||||
}
|
||||
}
|
||||
$v['from_id'] = 0;
|
||||
$v['is_time'] = 0;
|
||||
if(in_array($v['task_id'],[8,9])){
|
||||
$v['processing_type'] = 2;
|
||||
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
||||
//跳转的房间路径
|
||||
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6]])->orderRaw('rand()')->value('id');
|
||||
$v['target_quantity'] = $v['target_quantity'] * 60;
|
||||
$v['is_time'] = 1;
|
||||
}elseif(in_array($v['task_id'],[10])){
|
||||
$v['processing_type'] = 7;
|
||||
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
||||
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6]])->orderRaw('rand()')->value('id');
|
||||
} else{
|
||||
$v['processing_type'] = 9;
|
||||
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
||||
}
|
||||
|
||||
//分类回显
|
||||
if ($v['task_type']==1) {
|
||||
$reslut['tasks']['daily_tasks'][] = $v;
|
||||
}elseif ($v['task_type']==2) {
|
||||
$reslut['tasks']['daily_tasks_special'][] = $v;
|
||||
}else{
|
||||
$reslut['tasks']['usual_tasks'][] = $v;
|
||||
}
|
||||
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $reslut];
|
||||
}
|
||||
//完成每日任务
|
||||
public function tasks_complete($user_id,$task_id){
|
||||
//查询任务
|
||||
$task_info = Db::name('vs_daily_tasks')->where('task_id',$task_id)->where('delete_time',0)->where('is_active',1)->find();
|
||||
if(empty($task_info)){
|
||||
return ['code' => 0, 'msg' => '任务不存在或已删除','data' => null];
|
||||
}
|
||||
//查询用户每日任务进度表
|
||||
if($task_info['task_type']==3){
|
||||
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->find();
|
||||
}else{
|
||||
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->whereTime('createtime', 'today')->find();
|
||||
}
|
||||
if ($user_daily_tasks && $user_daily_tasks['is_completed'] == 1) {
|
||||
return ['code' => 0, 'msg' => '您已完成该任务','data' => null];
|
||||
}
|
||||
//判断是是否是赠送礼包任务
|
||||
if($task_info['bag_id'] != 0){
|
||||
//暂未开发
|
||||
}
|
||||
if ($user_daily_tasks) {
|
||||
$current_progress = $user_daily_tasks['current_progress'] +1;
|
||||
$is_completed = 0;
|
||||
if($task_info['target_quantity']==$current_progress){
|
||||
$is_completed = 1;
|
||||
}
|
||||
$reslut = Db::name('vs_user_daily_tasks')->where('id',$user_daily_tasks['id'])->update([
|
||||
'current_progress' => $current_progress,
|
||||
'is_completed'=> $is_completed,
|
||||
]);
|
||||
}else{
|
||||
$is_completed = 0;
|
||||
if($task_info['target_quantity'] == 1){
|
||||
$is_completed = 1;
|
||||
}
|
||||
$reslut = Db::name('vs_user_daily_tasks')->insert([
|
||||
'user_id' => $user_id,
|
||||
'task_id' => $task_id,
|
||||
'current_progress' => 1,
|
||||
'gold_reward' => $task_info['gold_reward'],
|
||||
'is_completed' => $is_completed,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
}
|
||||
if ($reslut) {
|
||||
if($is_completed==1){
|
||||
//每日任务直接领取奖励
|
||||
if($task_id==1){
|
||||
$this->daily_tasks_receive($user_id,$task_id);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => ['is_completed'=>1]];
|
||||
}else{
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => ['is_completed'=>0]];
|
||||
}
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//领取每日任务金币奖励
|
||||
public function daily_tasks_receive($user_id,$task_id){
|
||||
$task_info = Db::name('vs_daily_tasks')->where('task_id',$task_id)->find();
|
||||
if (!$task_info) {
|
||||
return ['code' => 0, 'msg' => '任务不存在','data' => null];
|
||||
}
|
||||
if($task_info['task_type']==3){
|
||||
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->find();
|
||||
}else{
|
||||
$user_daily_tasks = Db::name('vs_user_daily_tasks')->where('user_id',$user_id)->where('task_id',$task_id)->whereTime('createtime', 'today')->find();
|
||||
}
|
||||
|
||||
if (!$user_daily_tasks) {
|
||||
return ['code' => 0, 'msg' => '请完成该任务','data' => null];
|
||||
}
|
||||
if ($user_daily_tasks['is_completed'] == 0) {
|
||||
return ['code' => 0, 'msg' => '请完成该任务','data' => null];
|
||||
}
|
||||
if ($user_daily_tasks['is_claimed'] == 1) {
|
||||
return ['code' => 0, 'msg' => '您已领取该奖励','data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$reslut = Db::name('vs_user_daily_tasks')->where('id',$user_daily_tasks['id'])->update([
|
||||
'is_claimed' => 1,
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
if ($reslut) {
|
||||
//操作用户金币
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $user_daily_tasks['gold_reward'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::DAILY_TASKS_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DAILY_TASKS_REWARD)."( ".$task_info['task_name'].")");
|
||||
if ($res['code'] != 1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => "领取成功", 'data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 开启礼盒
|
||||
* $user_id 用户id
|
||||
* $gift_box_id 礼盒id
|
||||
*/
|
||||
public function open_gift_box($user_id,$gift_box_id){
|
||||
$gift_box_info = Db::name('vs_gift_bag')->where('id',$gift_box_id)->find();
|
||||
if (!$gift_box_info) {
|
||||
return ['code' => 0, 'msg' => '礼盒不存在','data' => null];
|
||||
}
|
||||
$ext = json_decode($gift_box_info['ext'],true);
|
||||
$gift_bag_receive_num = Db::name('vs_gift_bag_receive_log')->where('user_id',$user_id)->where('gift_bag_id',$gift_box_id)->whereTime('createtime', 'today')->count();
|
||||
if ($gift_bag_receive_num >= $ext['num']) {
|
||||
return ['code' => 0, 'msg' => '您已领取该礼盒','data' => null];
|
||||
}
|
||||
//查询礼盒详情
|
||||
$user_gift_box_details = db::name("vs_gift_bag_detail")->where('gift_bag_id',$gift_box_id)->orderRaw('rand()')->find();
|
||||
if (!$user_gift_box_details) {
|
||||
return ['code' => 0, 'msg' => '礼盒不存在','data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
switch ($user_gift_box_details['type']) {
|
||||
case 1: //金币 方法1:直接添加到用户钱包
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $user_gift_box_details['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::GIFT_BOX_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::GIFT_BOX_REWARD));
|
||||
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['gold']."金币";
|
||||
break;
|
||||
case 2: //礼物 方法2:添加到用户礼物背包
|
||||
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$user_gift_box_details['foreign_id'],$user_gift_box_details['quantity'],model('UserGiftPack')::GIFT_PACK_GET,$gift_box_info['name']);
|
||||
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['quantity']."X".$user_gift_box_details['name'];
|
||||
break;
|
||||
case 3: //坐骑 方法3:添加到用户装扮
|
||||
$res = model('Decorate')->pay_decorate($user_id,$user_gift_box_details['foreign_id'],$user_gift_box_details['days'],3);
|
||||
$return_data['gift_name']= "恭喜获得".$user_gift_box_details['quantity']."天".$user_gift_box_details['name'];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ($res['code'] != 1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_box_id,
|
||||
'parent_id' => $user_gift_box_details['id'],
|
||||
'gift_id' => $user_gift_box_details['foreign_id'],
|
||||
'num' => $user_gift_box_details['quantity'],
|
||||
'gift_price' => $user_gift_box_details['gold'],
|
||||
'bag_price' => $ext['meet'],
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
if ($reslut) {
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => $return_data];
|
||||
} else {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 礼盒记录
|
||||
*
|
||||
*/
|
||||
public function gift_bag_receive_list($user_id){
|
||||
//查询每日任务礼盒记录
|
||||
$gift_bag_receive_list = Db::name('vs_gift_bag_receive_log')
|
||||
->field('bag.name as gift_bag_name,de.name as gift_name,re.createtime as createtime,de.quantity,de.type,de.foreign_id,de.days,de.gold')
|
||||
->alias('re')
|
||||
->join('vs_gift_bag bag', 'bag.id = re.gift_bag_id', 'LEFT')
|
||||
->join('vs_gift_bag_detail de', 'de.gift_bag_id = re.gift_bag_id','LEFT')
|
||||
->where(['re.user_id'=>$user_id,'bag.activities_id'=>2,'bag.status'=>1])
|
||||
->order('re.createtime desc')
|
||||
->select();
|
||||
if (!$gift_bag_receive_list) {
|
||||
return ['code' => 0, 'msg' => '没有礼盒记录','data' => null];
|
||||
}
|
||||
$result = [];
|
||||
foreach ($gift_bag_receive_list as $k=>$v){
|
||||
$result[$k]['gift_bag_name'] = $v['gift_bag_name'];
|
||||
if($v['type'] == 1){
|
||||
$result[$k]['gift_name'] = $v['gold'].'金币';
|
||||
}elseif ($v['type'] == 2){
|
||||
$result[$k]['gift_name'] = $v['gift_name'].' x '.$v['quantity'];
|
||||
}elseif ($v['type'] == 3){
|
||||
$result[$k]['gift_name'] = $v['gift_name'].' x '.$v['days'].'天';
|
||||
}
|
||||
$result[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => $result];
|
||||
}
|
||||
|
||||
/*
|
||||
* 用户签到
|
||||
*/
|
||||
public function sign_in($user_id){
|
||||
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d')])->find();
|
||||
if ($sign_in_info) {
|
||||
return ['code' => 0, 'msg' => '今天已经签到过了','data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
//每日签到 【完成任务】
|
||||
$this->tasks_complete($user_id,1);
|
||||
//判断连续签到
|
||||
$continuous = 1;
|
||||
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id])->order('id desc')->find();
|
||||
if ($sign_in_info) {
|
||||
if ($sign_in_info['sign_in_date'] == date('Y-m-d',strtotime('-1 day'))) {
|
||||
$continuous = $sign_in_info['continuous'] + 1;
|
||||
} else {
|
||||
$continuous = 1;
|
||||
}
|
||||
}
|
||||
if($continuous>1){
|
||||
//连续签到任务送金币
|
||||
//连续签到7天 【完成任务】
|
||||
//$this->tasks_complete($user_id,2);
|
||||
//连续签到任务抽礼包【完成任务】
|
||||
//连续签到7天 【完成任务】
|
||||
//$this->tasks_complete($user_id,7);
|
||||
}
|
||||
$reslut = Db::name('vs_user_tasks_sign_in')->insert([
|
||||
'user_id' => $user_id,
|
||||
'sign_in_date' => date('Y-m-d'),
|
||||
'continuous' => $continuous,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
if ($reslut) {
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
} else {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 今日签到状态
|
||||
*/
|
||||
public function daily_tasks_sign_in_status($user_id){
|
||||
$sign_in_info = Db::name('vs_user_tasks_sign_in')->where(['user_id'=>$user_id,'sign_in_date'=>date('Y-m-d')])->find();
|
||||
$result = [];
|
||||
if ($sign_in_info) {
|
||||
$result['status'] = 1;
|
||||
$result['status_str'] = "已签到";
|
||||
}else{
|
||||
$result['status'] = 0;
|
||||
$result['status_str'] = "未签到";
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功','data' => $result];
|
||||
}
|
||||
|
||||
}
|
||||
420
application/api/model/Decorate.php
Normal file
420
application/api/model/Decorate.php
Normal file
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use think\Session;
|
||||
|
||||
/**
|
||||
* 装饰模型
|
||||
*/
|
||||
class Decorate extends Model
|
||||
{
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = true;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
// 定义字段类型 1头像框 2坐骑 3麦圈 6个人靓号 7房间靓号 8工会靓号
|
||||
public $TypeArray = [1=>'头像框',2=>'坐骑',3=>'麦圈',6=>'个人靓号',7=>'房间靓号',8=>'工会靓号'];
|
||||
protected $FromType = [1=>'购买',2=>'后台赠送',3=>'礼盒开奖',4=>'好友赠送',5=>'首充赠送',6=>'天降好礼获得',7=>'财富等级特权赠送'];
|
||||
public function __construct($data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
$this->table = 'vs_decorate';
|
||||
}
|
||||
|
||||
//获取装扮类型
|
||||
public function get_type_list($have_hot = 0)
|
||||
{
|
||||
$label = $this->TypeArray;
|
||||
if ($have_hot) {
|
||||
$label = [100 => '热门'] + array_filter($this->TypeArray, fn($key) => $key != 100, ARRAY_FILTER_USE_KEY);
|
||||
}
|
||||
$data = [];
|
||||
$i = 0;
|
||||
foreach ($label as $k => $v) {
|
||||
$data[$i]['id'] = $k;
|
||||
$data[$i]['name'] = $v;
|
||||
++$i;
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//拉去装扮列表
|
||||
public function get_decorate_list($type=100)
|
||||
{
|
||||
$map = [];
|
||||
if ($type == 100) {
|
||||
$map = [
|
||||
'a.delete_time' => 0,
|
||||
'a.show_status' => 1,
|
||||
'a.is_buy' => 1,
|
||||
'a.is_hot' => 1,
|
||||
'b.is_delete' => 1,
|
||||
];
|
||||
}elseif (in_array($type, [6,7,8])) {
|
||||
$map = [
|
||||
'a.delete_time' => 0,
|
||||
'a.show_status' => 1,
|
||||
'a.is_buy' => 1,
|
||||
'b.is_delete' => 1,
|
||||
'a.type' => $type,
|
||||
'a.is_user_buy' => 2
|
||||
];
|
||||
}else{
|
||||
$map = [
|
||||
'a.delete_time' => 0,
|
||||
'a.show_status' => 1,
|
||||
'a.is_buy' => 1,
|
||||
'b.is_delete' => 1,
|
||||
'a.type' => $type,
|
||||
];
|
||||
}
|
||||
$list = DB::name($this->table)->alias('a')->join('fa_vs_decorate_price b', 'a.did = b.did')->field('a.did,a.title,a.type,a.base_image,a.play_image,min(b.price) as price,special_num')->where($map)->group('b.did')->order('price asc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
$v['price'] = (int)$v['price'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
// 获取礼物详情
|
||||
public function get_decorate_detail($did)
|
||||
{
|
||||
$decorate = DB::name($this->table)->where(['did' => $did, 'delete_time' => 0, 'show_status' => 1])->find();
|
||||
if (!$decorate) {
|
||||
return ['code' => 0, 'msg' => '参数错误'];
|
||||
}
|
||||
$decorate_price = DB::name('vs_decorate_price')->where(['did' => $did, 'is_delete' => 1])->order('day asc')->select();
|
||||
if (!$decorate_price) {
|
||||
return ['code' => 0, 'msg' => '参数错误'];
|
||||
}
|
||||
$result['title'] = $decorate['title'];
|
||||
foreach ($decorate_price as $k => $v) {
|
||||
$result['price_list'][$k]['price'] = (int)$v['price'];
|
||||
$result['price_list'][$k]['discount'] = $v['discount'];
|
||||
$result['price_list'][$k]['day'] = $v['day'];
|
||||
//月
|
||||
$result['price_list'][$k]['month'] = $v['day']/30;
|
||||
//有效期至
|
||||
$result['price_list'][$k]['end_time'] = date('Y-m-d',strtotime("+".$v['day']." day"));
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $result];
|
||||
}
|
||||
|
||||
//购买/赠送 装扮
|
||||
/*
|
||||
* @param $uid (接受)用户id
|
||||
* @param $did 装扮id
|
||||
* @param $day 天数
|
||||
* @param $give_uid 赠送用户id 0 为系统赠送
|
||||
* @param $from_type 购买来源 1购买 2后台赠送 3礼盒开奖 4好友赠送 7财富等级特权赠送
|
||||
* @param $log_remark 日志备注
|
||||
*
|
||||
*/
|
||||
public function pay_decorate($uid, $did, $day,$from_type=1,$give_uid=0,$log_remark=""){
|
||||
if(empty($log_remark)){
|
||||
$log_remark = $this->FromType[$from_type];
|
||||
}
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
//该装扮是否存在
|
||||
$map = [];
|
||||
$map = [
|
||||
'did' => $did,
|
||||
'is_buy' => 1,
|
||||
'delete_time' => 0,
|
||||
];
|
||||
$decorate_info = DB::name($this->table)->where($map)->find();
|
||||
if(!$decorate_info){
|
||||
return ['code' => 0, 'msg' => '该装扮不存在'.$did, 'data' => null];
|
||||
}
|
||||
//该天数是否存在
|
||||
$map = [];
|
||||
$map = [
|
||||
'did' => $did,
|
||||
'day' => $day,
|
||||
'is_delete' => 1,
|
||||
];
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where($map)->find();
|
||||
if(!$decorate_price_info){
|
||||
return ['code' => 0, 'msg' => '该装扮天数不存在', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 6 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该个人靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 7 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该房间靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 8 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该工会靓号已被购买', 'data' => null];
|
||||
}
|
||||
$start_time = $now_time = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$pay_price = $decorate_price_info['price'];
|
||||
if($from_type ==1){
|
||||
$log_remark = "购买";
|
||||
//购买操作用户资金 金币是否足够
|
||||
$reslut = model('common/UserWallet')->change_user_money($user_info['id'], $pay_price, 1, model('common/UserWallet')::OPERATION_DECORATION,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::OPERATION_DECORATION));
|
||||
if ($reslut['code'] != 1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
} else if($from_type == 4 && $give_uid){
|
||||
//购买操作用户资金 金币是否足够
|
||||
$give_user_info = db::name('user')->find($give_uid);
|
||||
if(!$give_user_info){
|
||||
return ['code' => 0, 'msg' => '赠送用户不存在', 'data' => null];
|
||||
}
|
||||
$log_remark = $give_user_info['nickname']." 赠送";
|
||||
$reslut = model('common/UserWallet')->change_user_money($give_uid, $pay_price, 1, model('common/UserWallet')::OPERATION_DECORATION,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::OPERATION_DECORATION));
|
||||
if ($reslut['code'] != 1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//该用户是否有该装扮
|
||||
$map = [];
|
||||
$map = [
|
||||
'user_id' => $user_info['id'],
|
||||
'did' => $did,
|
||||
];
|
||||
$user_decorate_data = db::name('vs_user_decorate')->where($map)->find();
|
||||
$change_time = 0;
|
||||
if(empty($user_decorate_data)){
|
||||
$data = [];
|
||||
$data['user_id'] = $uid;
|
||||
$data['did'] = $did;
|
||||
$data['type'] = $decorate_info['type'];
|
||||
if($decorate_price_info['day'] == 0){//如果礼物购买配置的天数为0,则永久有效
|
||||
$data['is_using'] = 1;
|
||||
$data['end_time'] = 0;
|
||||
}else{
|
||||
$change_time = $day * 24 * 3600;
|
||||
$data['is_using'] = 2;
|
||||
$data['end_time'] = $now_time + $change_time;
|
||||
}
|
||||
$data['createtime'] = $now_time;
|
||||
$data['special_num'] = $decorate_info['special_num'];
|
||||
$result = db::name('vs_user_decorate')->insert($data);
|
||||
}else{
|
||||
if($decorate_price_info['day'] > 0){//是不是永久礼物
|
||||
if($decorate_price_info['price']<=0 && $user_decorate_data['end_time'] > $now_time + $change_time){
|
||||
return ['code' => 0, 'msg' => '您已购买过此装扮,请勿重复购买', 'data' => null];
|
||||
}
|
||||
$change_time = $day * 24 * 3600;
|
||||
$update['is_using'] = 2;
|
||||
$update['end_time'] = $user_decorate_data['end_time'] + $change_time;
|
||||
$result = db::name('vs_user_decorate')->where('udid', $user_decorate_data['udid'])->update($update);
|
||||
$start_time = $update['end_time'];
|
||||
}
|
||||
}
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
//记录日志
|
||||
$insert_data = [];
|
||||
$insert_data['user_id'] = $uid;
|
||||
$insert_data['type'] = $decorate_info['type'];
|
||||
$insert_data['did'] = $did;
|
||||
$insert_data['createtime'] = $now_time;
|
||||
$insert_data['remark'] = $log_remark;
|
||||
$insert_data['from_type'] = $from_type;
|
||||
$insert_data['start_time'] = $start_time;
|
||||
$insert_data['end_time'] = $start_time + $change_time;
|
||||
if($decorate_price_info['day'] ==0){
|
||||
$insert_data['end_time'] = 0; //永久礼物
|
||||
}
|
||||
$insert_data['day_num'] = $day;
|
||||
$insert_data['pay_price'] = $pay_price ;
|
||||
$insert_data['special_num'] = $decorate_info['special_num'];
|
||||
$insert_data['give_uid'] = $give_uid;
|
||||
$result = db::name('vs_user_decorate_log')->insert($insert_data);
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
//如果购买个人或房间靓号
|
||||
if($decorate_info['type'] == 6 || $decorate_info['type'] == 7 || $decorate_info['type'] == 8) {
|
||||
Db::name('vs_decorate')->where('did', $decorate_info['did'])->update(['is_user_buy' => 1, 'updatetime' => time()]);
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => "购买成功", 'data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//用户装扮列表
|
||||
public function user_decorate($uid, $type,$page=1, $limit=10){
|
||||
|
||||
$reslut = db::name('vs_user_decorate')
|
||||
->alias('ud')->join('vs_decorate d', 'ud.did = d.did')
|
||||
->field('ud.udid,ud.user_id,ud.is_using,ud.end_time,ud.is_perpetual,ud.special_num,d.title,d.base_image,d.play_image,d.type')
|
||||
->where('ud.user_id', $uid)
|
||||
->where('ud.type', $type)
|
||||
->where(['ud.end_time'=>[">=",time()]])
|
||||
->page($page, $limit)
|
||||
->select();
|
||||
foreach($reslut as $k => &$v){
|
||||
$remaining_day = ceil(($v['end_time'] - time())/86400);
|
||||
if($remaining_day <= 0){
|
||||
$remaining_day = 0;
|
||||
}
|
||||
//剩余天数 取整
|
||||
$v['remaining_day'] = $v['is_perpetual']==1 ? '永久' :$remaining_day;
|
||||
$v['end_time'] = date('Y-m-d H:i:s', $v['end_time']);
|
||||
|
||||
}
|
||||
return ['code' => 1, 'msg' => "获取成功", 'data' => $reslut];
|
||||
}
|
||||
|
||||
// 设置用户装修
|
||||
public function set_user_decorate($uid,$udid)
|
||||
{
|
||||
$map = [];
|
||||
$map = [
|
||||
'user_id' => $uid,
|
||||
'udid' => $udid
|
||||
];
|
||||
$info = db::name('vs_user_decorate')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 0, 'msg' => '装扮不存在', 'data' => null];
|
||||
}
|
||||
if ($info['end_time'] < time()) {
|
||||
return ['code' => 0, 'msg' => '装扮已过期', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//清理该类型装扮使用状态
|
||||
$map = [];
|
||||
$map = [
|
||||
'user_id' => $uid,
|
||||
'type' => $info['type']
|
||||
];
|
||||
$data = [];
|
||||
$data['is_using'] = 2;
|
||||
$data['updatetime'] = time();
|
||||
$reslut = Db::name('vs_user_decorate')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "设置失败", 'data' => null];
|
||||
}
|
||||
//设置使用中状态
|
||||
$map = [];
|
||||
$map = [
|
||||
'udid' => $info['udid']
|
||||
];
|
||||
$data = [];
|
||||
$data['is_using'] = 1;
|
||||
$data['updatetime'] = time();
|
||||
$reslut = Db::name('vs_user_decorate')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "设置失败", 'data' => null];
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
//推送信息去所在房间
|
||||
//查询当前所在房间
|
||||
$room_id = db::name('vs_room_visitor')->where(['user_id' => $uid])->order('id' , 'desc')->value('room_id');
|
||||
if($room_id){
|
||||
//当前用户信息
|
||||
//推送信息
|
||||
$text['jia_jia'] = model('Decorate')->user_decorate_detail($uid,2);
|
||||
$text['FromUserInfo'] = db::name('user')->where('id',$uid)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text['FromUserInfo']['dress'] = model('Decorate')->user_decorate_detail($uid,1);
|
||||
$text['FromUserInfo']['mic_dress'] = model('Decorate')->user_decorate_detail($uid,4);
|
||||
$text['FromUserInfo']['chat_dress'] = model('Decorate')->user_decorate_detail($uid,5);
|
||||
$text['text'] = '用户 ' . $text['FromUserInfo']['nickname'] .' 修改了信息';
|
||||
model('Chat')->sendMsg(1035,$room_id,$text,$uid);
|
||||
}
|
||||
return ['code' => 1, 'msg' => "设置成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "设置失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
//取消装扮
|
||||
public function cancel_user_decorate($uid, $type)
|
||||
{
|
||||
//查询当前用户装扮
|
||||
$user_decorate = db::name('vs_user_decorate')->where(['user_id' => $uid, 'type' => $type,'is_using'=>1,'end_time'=>['>',time()]])->find();
|
||||
if (!$user_decorate) {
|
||||
return ['code' => 0, 'msg' => "取消装扮失败,当前用户还未装扮", 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['is_using'] = 2;
|
||||
$data['updatetime'] = time();
|
||||
$reslut = Db::name('vs_user_decorate')->where('udid',$user_decorate['udid'])->update($data);
|
||||
if (!$reslut) {
|
||||
return ['code' => 0, 'msg' => "取消装扮失败", 'data' => null];
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => "取消成功", 'data' => null];
|
||||
}
|
||||
|
||||
//用户装扮详情
|
||||
/*
|
||||
* @param $id 对象id
|
||||
* @param $type 装扮类型 1头像框 2坐骑 3麦圈 6个人靓号 7房间靓号 8工会靓号
|
||||
*/
|
||||
public function user_decorate_detail($id, $type){
|
||||
//根据$type 组装查询条件
|
||||
$reslut = "";
|
||||
if($type == 7){//7房间靓号 8工会靓号
|
||||
$room = db::name('vs_room')->where('id', $id)->field('user_id,room_number')->find();
|
||||
if(empty($room)){
|
||||
return $reslut;
|
||||
}
|
||||
$map = [
|
||||
'user_id' => $room['user_id']??0,
|
||||
'type' => $type,
|
||||
'is_using' => 1
|
||||
];
|
||||
$reslut = db::name('vs_user_decorate')->where($map)->where('end_time',['>=',time()],'or')->value('special_num') ?? $room['room_number'];
|
||||
}elseif($type == 8){
|
||||
$guild = db::name('vs_guild')->where('id', $id)->field('user_id,guild_special_id')->find();
|
||||
$map = [
|
||||
'user_id' => $guild['user_id']??0,
|
||||
'type' => $type,
|
||||
'is_using' => 1
|
||||
];
|
||||
$reslut = db::name('vs_user_decorate')->where($map)->where('end_time',['>=',time()],'or')->value('special_num') ?? $guild['guild_special_id'];
|
||||
}elseif($type == 6){
|
||||
$map = [
|
||||
'user_id' => $id??0,
|
||||
'type' => $type,
|
||||
'is_using' => 1
|
||||
];
|
||||
$user_code = db::name('user')->where('id', $id)->value('user_code');
|
||||
$reslut = db::name('vs_user_decorate')->where($map)->where('end_time',['>=',time()],'or')->value('special_num') ?? $user_code;
|
||||
}else{
|
||||
$map = [
|
||||
'user_id' => $id??0,
|
||||
'type' => $type,
|
||||
'is_using' => 1
|
||||
];
|
||||
$did = db::name('vs_user_decorate')->where($map)->where('end_time',['>=',time()],'or')->value('did');
|
||||
if(empty($did)){
|
||||
$reslut = '';//返回数据
|
||||
}else{
|
||||
$reslut = db::name('vs_decorate')->where('did', $did)->value('play_image');
|
||||
}
|
||||
}
|
||||
return $reslut;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
68
application/api/model/Gift.php
Normal file
68
application/api/model/Gift.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use think\Session;
|
||||
|
||||
class Gift extends Model
|
||||
{
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = true;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
// 定义字段类型
|
||||
protected $label = [1=>'热门',2=>'趣味', 3=>'情侣', 4=>'挂件'];
|
||||
protected $table = 'fa_vs_gift';
|
||||
|
||||
//获取礼物类型
|
||||
public function get_gift_label()
|
||||
{
|
||||
$giftTypeData = db::name('vs_gift_label')->where('delete_time',0)->order("sort asc,id desc")->select();
|
||||
foreach ($giftTypeData as $key => $value) {
|
||||
$giftType[$key]['id'] = $value['id'];
|
||||
$giftType[$key]['name'] = $value['name'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $giftType];
|
||||
}
|
||||
|
||||
//拉去礼物列表
|
||||
public function get_gift_list($label=0)
|
||||
{
|
||||
$map['delete_time'] = 0;
|
||||
$where['is_show'] = 1;
|
||||
if ($label && $label !=99) {
|
||||
$map['label'] = $label;
|
||||
}
|
||||
if ($label == 99) {
|
||||
$gift_price = get_system_config_value('room_love_auction_cion');
|
||||
$where['gift_price'] = ['>',$gift_price];
|
||||
}
|
||||
$list = $this->field('gid as gift_id,gift_name,base_image,gift_price')->where($map)->where($where)->order('sort asc, gift_price asc')->select();
|
||||
|
||||
if($label==2){
|
||||
foreach ($list as &$v) {
|
||||
//获取盲盒列表
|
||||
$box_list = Db::name('vs_gift_bag')->where(['status'=>1])->where('activities_id',4)->select();
|
||||
foreach ($box_list as $key =>$box) {
|
||||
$ext = json_decode($box['ext'],true);
|
||||
if ($ext['gift_id'] == $v['gift_id']) {
|
||||
$v['gift_bag_name'] = $box['name'];
|
||||
$v['rule'] = $ext['description'];
|
||||
$v['rule_url'] = get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$box["id"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
/*
|
||||
* 盲盒规则链接
|
||||
*/
|
||||
public function get_gift_box_rule($box_id){
|
||||
|
||||
}
|
||||
}
|
||||
1108
application/api/model/GiveGift.php
Normal file
1108
application/api/model/GiveGift.php
Normal file
File diff suppressed because it is too large
Load Diff
915
application/api/model/Guild.php
Normal file
915
application/api/model/Guild.php
Normal file
@@ -0,0 +1,915 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
use think\Db;
|
||||
|
||||
class Guild extends Model
|
||||
{
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
/*
|
||||
* 获取公会列表
|
||||
* @param $page
|
||||
* @param $limit
|
||||
*/
|
||||
public function get_guild_list($page,$limit=10,$search='',$user_id=0)
|
||||
{
|
||||
$where ="1=1";
|
||||
if ($search) {
|
||||
$where = ['guild_special_id'=>['like',$search.'%']]; //通过工会ID搜索
|
||||
}
|
||||
$list = [];
|
||||
$list = Db::name('vs_guild')
|
||||
->field('id,guild_special_id,user_id,guild_name,cover,num,intro,createtime,income')
|
||||
->where(['is_show'=>1,'delete_time'=>0])
|
||||
->where($where)
|
||||
->order('income desc')
|
||||
->page($page,$limit)
|
||||
->select();
|
||||
$count = Db::name('vs_guild')
|
||||
->where(['is_show'=>1,'delete_time'=>0])
|
||||
->where($where)
|
||||
->count();
|
||||
if($list){
|
||||
foreach ($list as $key => &$value) {
|
||||
$list[$key]['cover'] = localpath_to_netpath( $value['cover']);
|
||||
$list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
||||
//会长信息
|
||||
$list[$key]['user_name'] = Db::name('user')->where(['id'=>$value['user_id']])->value('nickname');//会长昵称
|
||||
$list[$key]['user_avatar'] = Db::name('user')->where(['id'=>$value['user_id']])->value('avatar');//会长头像
|
||||
//当前用户是否加入该公会
|
||||
$guild_user = Db::name('vs_guild_user')->where(['guild_id'=>$value['id'],'user_id'=>$user_id,'status'=>1,'delete_time'=>0])->value('id');
|
||||
$list[$key]['is_join'] = $guild_user ? 1 : 0;
|
||||
//公会用户头像
|
||||
$guild_user_list = Db::name('vs_guild_user')->alias('a')
|
||||
->join('user b','a.user_id = b.id')
|
||||
->field('a.user_id,b.avatar')
|
||||
->where(['a.guild_id'=>$value['id'],'a.delete_time'=>0,'a.status'=>1,'a.is_deacon'=>2])
|
||||
->order('a.coin desc')
|
||||
->limit(3)
|
||||
->select();
|
||||
$list[$key]['guild_user_list'] = $guild_user_list;
|
||||
//工会总流水
|
||||
$list[$key]['total_transaction'] = $value['income'];
|
||||
//公会靓号处理
|
||||
$list[$key]['guild_special_id'] = model('api/Decorate')->user_decorate_detail($value['id'], 8);
|
||||
}
|
||||
}
|
||||
$data =[
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'count' => $count,
|
||||
'list' => $list
|
||||
];
|
||||
return ['code'=>1,'msg'=>'获取成功','data'=>$data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取公会详情
|
||||
* @param $id
|
||||
* @param $user_id
|
||||
*/
|
||||
public function get_guild_info($id,$user_id=0)
|
||||
{
|
||||
$info = Db::name('vs_guild')
|
||||
->field('id,guild_special_id,user_id,guild_name,cover,num,intro,createtime,income')
|
||||
->where(['id'=>$id,'is_show'=>1,'delete_time'=>0])
|
||||
->find();
|
||||
if($info){
|
||||
$info['cover'] = localpath_to_netpath( $info['cover']);
|
||||
$info['createtime'] = date('Y-m-d H:i:s',$info['createtime']);
|
||||
//当前用户是否是会长
|
||||
$info['is_leader'] = $info['user_id'] == $user_id ? 1 : 0;
|
||||
//当前用户是否加入当前工会
|
||||
$info['is_join'] = Db::name('vs_guild_user')->where(['user_id'=>$user_id,'guild_id'=>$id,'status'=>1,'delete_time'=>0])->value('guild_id')> 0 ? 1 : 0;
|
||||
//工会总流水
|
||||
$info['total_transaction'] = $info['income'];
|
||||
//工会房间数
|
||||
$info['room_num'] = Db::name('vs_guild_user')->where(['guild_id'=>$id,'status'=>1,'delete_time'=>0,'room_id'=>['<>',0]])->count();
|
||||
//付费退出公会所需金
|
||||
$info['quit_guild_gold'] = get_system_config_value('quit_guild_gold');
|
||||
//工会群组ID
|
||||
$info['group_id'] = "g".$info['id'];
|
||||
//会长信息
|
||||
$user_data = Db::name('user')->where(['id'=>$info['user_id']])->field('id,nickname,avatar')->find();
|
||||
$info['user_data']['nickname'] = $user_data['nickname'];
|
||||
$info['user_data']['avatar'] = localpath_to_netpath($user_data['avatar']);
|
||||
$info['user_data']['icon'][0] = model('UserData')->user_wealth_icon($info['user_id']);//财富图标
|
||||
$info['user_data']['icon'][1] = model('UserData')->user_charm_icon($info['user_id']);//魅力图标
|
||||
//公会靓号处理
|
||||
$info['guild_special_id'] = model('api/Decorate')->user_decorate_detail($info['id'], 8);
|
||||
}else{
|
||||
$info = [];
|
||||
}
|
||||
return ['code'=>1,'msg'=>'获取成功','data'=>$info];
|
||||
}
|
||||
|
||||
/*
|
||||
* 加入工会申请
|
||||
*/
|
||||
public function join_guild($guild_id,$user_id=0)
|
||||
{
|
||||
$user_info = model('User')->get_user_info($user_id);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
if($user_info['is_real']!=1 || empty($user_info['card_id'])){
|
||||
return ['code' => 0, 'msg' => '请先实名认证', 'data' => null];
|
||||
}
|
||||
//公会是否存在
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'delete_time'=>0])->find();
|
||||
if(!$guild_info){
|
||||
return ['code' => 0, 'msg' => '该公会不存在', 'data' => null];
|
||||
}
|
||||
$is_check_join = Db::name('vs_guild_user')->where(['user_id'=>$user_id,'delete_time'=>0])->find();
|
||||
if($is_check_join && $is_check_join['guild_id']!=$guild_id){
|
||||
return ['code'=>0,'msg'=>'您已加入别的工会,请先退出公会再加入', 'data' => null];
|
||||
}
|
||||
if($is_check_join && $is_check_join['guild_id']==$guild_id && $is_check_join['status']==1){
|
||||
return ['code'=>0,'msg'=>'您已加入该工会', 'data' => null];
|
||||
}
|
||||
if($is_check_join && $is_check_join['guild_id']==$guild_id && $is_check_join['status']==2){
|
||||
return ['code'=>0,'msg'=>'您已提交申请,请耐心等待', 'data' => null];
|
||||
}
|
||||
//是否被踢出过
|
||||
$ti_chu = db::name('vs_guild_user')->where(['user_id'=>$user_id,'guild_id'=>$guild_id,'delete_time'=>['<>',0],'quit_type'=>2])->find();
|
||||
if(!empty($ti_chu)){
|
||||
return ['code' => 0, 'msg' => '已被踢出,禁止加入!', 'data' => null];
|
||||
}
|
||||
//退出公会是否超过30天
|
||||
$map = [];
|
||||
$map['user_id'] = $user_id;
|
||||
$map['delete_time'] = ['<>',0];
|
||||
$map['quit_type'] = 1;
|
||||
$quit_guild_info = Db::name('vs_guild_user')->where($map)->order('quit_time', 'desc')->field('quit_time,guild_id,quit_type')->find();
|
||||
if(!empty($quit_guild_info)) {
|
||||
$quit_time = empty($quit_guild_info['quit_time']) ? 0 : $quit_guild_info['quit_time'];
|
||||
$quit_type = $quit_guild_info['quit_type'];
|
||||
if($quit_guild_info['guild_id'] != $guild_id) {
|
||||
$last_time = 30 * 24 * 3600;
|
||||
if((time() - $last_time) <= $quit_time) {
|
||||
return ['code' => 0, 'msg' => '退出公会未超过30天,不能重新加入其他公会', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
//是否有房间
|
||||
$rid = 0;
|
||||
$room_info = db::name('vs_room')->where('user_id', $user_id)->find();
|
||||
if($room_info){
|
||||
$rid = $room_info['id'];
|
||||
}
|
||||
$insert_data = [];
|
||||
$insert_data['user_id'] = $user_id;
|
||||
$insert_data['guild_id'] = $guild_id;
|
||||
$insert_data['room_id'] = $rid;
|
||||
$insert_data['status'] = 1;
|
||||
$insert_data['is_deacon'] = 2;
|
||||
$insert_data['createtime'] = time();
|
||||
$update_data['apply_time'] = time();
|
||||
$insert_data['is_show_room'] = 1;
|
||||
$reslut = db::name('vs_guild_user')->insert($insert_data);
|
||||
if($reslut){
|
||||
//增加公会人数
|
||||
db::name('vs_guild')->where('id', $guild_info['id'])->setInc('num', 1);
|
||||
//拉用户进入工会群聊
|
||||
model('Tencent')->add_group_member('g'.$guild_id, $user_id);
|
||||
// model('Tencent')->send_group_system_notification('g'.$guild_id,"欢迎".$user_info['nickname'].'加入公会');
|
||||
|
||||
return ['code' => 1, 'msg' => '提交成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '提交失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 申请列表
|
||||
*/
|
||||
public function get_apply_guild_list($uid, $guild_id, $page, $page_limit){
|
||||
$page = (int)$page;
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//公会信息
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'delete_time'=>0])->find();
|
||||
if(!$guild_info){
|
||||
return ['code' => 0, 'msg' => '该公会不存在', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map = [
|
||||
'a.guild_id' => $guild_id,
|
||||
'a.status' => 2
|
||||
];
|
||||
$count = db::name('vs_guild_user')-alias('a')->join('user b', 'a.user_id = b.id')->where($map)->count();
|
||||
$list = db::name('vs_guild_user')->alias('a')->join('user b', 'a.user_id = b.id')
|
||||
->field('a.id, a.user_id, a.guild_id, a.room_id, a.status, b.nickname, b.avatar,b.user_code')
|
||||
->where($map)
|
||||
->order('id desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['user_code'] = model('Decorate')->user_decorate_detail($v['user_id'],6);
|
||||
}
|
||||
$data = [];
|
||||
$data =[
|
||||
'page' => $page,
|
||||
'limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'list' => $list,
|
||||
];
|
||||
return ['code' => 200, 'msg' => '获取成功', $data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 同意,拒绝申请
|
||||
*/
|
||||
public function operate_guild($uid, $apply_id, $type){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
//该申请是否已被操作
|
||||
$is_operate = db::name('vs_guild_user')->where(['id'=>$apply_id,'status'=>2])->find();
|
||||
if(!$is_operate){
|
||||
return ['code' => 201, 'msg' => '该申请不存在', 'data' => null];
|
||||
}
|
||||
if(!in_array($type, [1,2])){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$guild_info = db::name('vs_guild')->where('id', $is_operate['guild_id'])->find();
|
||||
if($uid != $guild_info['user_id']){
|
||||
return ['code' => 0, 'msg' => '您没有权限操作', 'data' => null];
|
||||
}
|
||||
//审核通过
|
||||
if($type == 1) {
|
||||
$is_join_guild = Db::name('vs_guild_user')->where(['user_id' => $is_operate['user_id'], 'delete_time' => 0, 'status' => 1])->find();
|
||||
if(!empty($is_join_guild)) {
|
||||
return ['code' => 0, 'msg' => '已加入其他工会', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($type == 1){//同意
|
||||
$update_data = [];
|
||||
$update_data['status'] = 1;
|
||||
$update_data['updatetime'] = time();
|
||||
$update_data['is_show_room'] = 1;
|
||||
$update_data['apply_time'] = time();
|
||||
$reslut = db::name('vs_guild_user')->where(['id'=>$apply_id])->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
//增加公会人数
|
||||
db::name('vs_guild')->where('id', $guild_info['id'])->setInc('num', 1);
|
||||
}else if($type == 2){//拒绝
|
||||
$update_data = [];
|
||||
$update_data['status'] = 3;
|
||||
$update_data['updatetime'] = time();
|
||||
$update_data['apply_time'] = time();
|
||||
$reslut = db::name('user_guild')->where(['id'=>$apply_id])->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 踢出工会
|
||||
*/
|
||||
public function kick_out_guild($uid,$user_id, $guild_id){
|
||||
$user_info = db::name('user')->find($user_id);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$guild_info = db::name('vs_guild')->find($guild_id);
|
||||
if(!$guild_id){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $guild_info['user_id']){
|
||||
return ['code' => 0, 'msg' => '您没有权限操作','data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map['user_id'] = $user_id;
|
||||
$map['guild_id'] = $guild_id;
|
||||
$map['status'] = 1;
|
||||
$map['delete_time'] = 0;
|
||||
$user_guild_info = db::name('vs_guild_user')->where($map)->find();
|
||||
if(!$user_guild_info){
|
||||
return ['code' => 0, 'msg' => '该用户不在该公会', 'data' => null];
|
||||
}
|
||||
if($user_guild_info['is_deacon'] == 1){
|
||||
return ['code' => 0, 'msg' => '会长无法被踢出','data' => null];
|
||||
}
|
||||
$update_data = [];
|
||||
$update_data['delete_time'] = time();
|
||||
$update_data['updatetime'] = time();
|
||||
$update_data['quit_time'] = time();
|
||||
$update_data['quit_type'] = 2;
|
||||
$reslut = db::name('vs_guild_user')->where('id', $user_guild_info['id'])->update($update_data);
|
||||
if($reslut){
|
||||
//减少公会人数
|
||||
db::name('vs_guild')->where('id', $guild_info['id'])->setDec('num');
|
||||
model('Tencent')->delete_group_member('g'.$guild_id, $user_id);
|
||||
return ['code' => 1, 'msg' => '踢出成功','data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '踢出失败','data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//退出公会
|
||||
public function quit_guild($uid, $guild_id,$type){
|
||||
$config = get_system_config();
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$guild_info = db::name('vs_guild')->find($guild_id);
|
||||
if(!$guild_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map['user_id'] = $uid;
|
||||
$map['guild_id'] = $guild_id;
|
||||
$map['status'] = 1;
|
||||
$map['delete_time'] = 0;
|
||||
$user_guild_info = db::name('vs_guild_user')->where($map)->find();
|
||||
if(!$user_guild_info){
|
||||
return ['code' => 0, 'msg' => '用户不在该公会', 'data' => null];
|
||||
}
|
||||
if($user_guild_info['is_deacon'] == 1){
|
||||
return ['code' => 0, 'msg' => '会长无法退出公会', 'data' => null];
|
||||
}
|
||||
$time = 60 * 60 * 24 * $config['quit_guild_time'];
|
||||
$time = $user_guild_info['createtime'] + $time;
|
||||
if($time > time() && $type != 2){
|
||||
return ['code' => 0, 'msg' => '加入公会'.$config['quit_guild_time'].'天内无法退出', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$update_data = [];
|
||||
if($type ==2){
|
||||
//付费退出
|
||||
//扣款
|
||||
$quit_guild_gold = $config['quit_guild_gold'];
|
||||
$res = model('common/UserWallet')->change_user_money($uid, $quit_guild_gold, model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::GUILD_EXIT,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::GUILD_EXIT));
|
||||
if($res['code'] == 0){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
$update_data['quit_type'] = 4;
|
||||
$update_data['quit_time'] = time();
|
||||
$update_data['delete_time'] = time();
|
||||
$update_data['updatetime'] = time();
|
||||
$reslut = db::name('vs_guild_user')->where('id',$user_guild_info['id'])->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 0, '' => '退出失败', 'data' => null];
|
||||
}
|
||||
//减少公会人数
|
||||
db::name('vs_guild')->where('id', $guild_info['id'])->setDec('num');
|
||||
model('Tencent')->delete_group_member('g'.$guild_id, $uid);
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '退出成功', 'data' => null];
|
||||
}else{
|
||||
$quit_log = db::name('vs_guild_user_quit_log')->where(['guild_id'=>$guild_id,'user_id'=>$uid,'status'=>0])->find();
|
||||
if($quit_log){
|
||||
return ['code' => 0, 'msg' => '您已提交退出申请,请等待会长审核', 'data' => null];
|
||||
}
|
||||
//加入审核表
|
||||
$insert_data = [];
|
||||
$insert_data['guid'] = $user_guild_info['id'];
|
||||
$insert_data['user_id'] = $uid;
|
||||
$insert_data['guild_id'] = $guild_id;
|
||||
$insert_data['status'] = 0;
|
||||
$insert_data['createtime'] = time();
|
||||
$insert_data['updatetime'] = time();
|
||||
$res = db::name('vs_guild_user_quit_log')->insert($insert_data);
|
||||
if(!$res){
|
||||
Db::rollback();
|
||||
return ['code' => 0, '' => '退出失败', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '退出成功,等待会长审核', 'data' => null];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '退出失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 退出申请列表
|
||||
*
|
||||
*/
|
||||
public function quit_apply_list($uid,$guild_id,$page, $page_limit){
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'delete_time'=>0])->find();
|
||||
if(empty($guild_info)){
|
||||
return ['code' => 0, 'msg' => '公会不存在!', 'data' => null];
|
||||
}
|
||||
if($guild_info['user_id'] != $uid){
|
||||
// return ['code' => 0, 'msg' => '您不是该公会会长,无法访问权限', 'data' => null];
|
||||
}
|
||||
//申请主动退出工会的列表
|
||||
$map = ['a.guild_id' => $guild_id];
|
||||
$list = db::name('vs_guild_user_quit_log')->alias('a')->join('user b', 'a.user_id = b.id')
|
||||
->field('a.id, a.user_id, a.guild_id,a.createtime,a.status,b.nickname, b.avatar,b.user_code')
|
||||
->where($map)
|
||||
->order('id desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$count = db::name('vs_guild_user_quit_log')->alias('a')->join('user b', 'a.user_id = b.id')->where($map)->count();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['apply_quit_time'] = (72*60*60 - (time() - $v['createtime']))/(60*60); //申请退出结束时间(时)
|
||||
$v['user_code'] = model('Decorate')->user_decorate_detail($v['user_id'],6);
|
||||
}
|
||||
$data = [];
|
||||
$data =[
|
||||
'page' => $page,
|
||||
'limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'list' => $list,
|
||||
];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
/*
|
||||
* quit_apply_audit
|
||||
* 退出申请审核
|
||||
* @param int $uid 用户id
|
||||
* @param int $guild_id 公会id
|
||||
* @param int $type 审核状态 1通过 2拒绝
|
||||
*
|
||||
*/
|
||||
public function quit_apply_audit($uid,$apply_id,$type){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$apply_info = db::name('vs_guild_user_quit_log')->where(['id'=>$apply_id,'status'=>0])->find();
|
||||
if(!$apply_info){
|
||||
return ['code' => 0, 'msg' => '申请不存在', 'data' => null];
|
||||
}
|
||||
try {
|
||||
Db::startTrans();
|
||||
if($type == 1){
|
||||
$update_data = [];
|
||||
$update_data['status'] = 1;
|
||||
$update_data['updatetime'] = time();
|
||||
$res = db::name('vs_guild_user_quit_log')->where('id',$apply_id)->update($update_data);
|
||||
if($res){
|
||||
$update_data['quit_type'] = 1;
|
||||
$update_data['quit_time'] = time();
|
||||
$update_data['delete_time'] = time();
|
||||
$update_data['updatetime'] = time();
|
||||
$reslut = db::name('vs_guild_user')->where('id',$apply_info['guid'])->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '审核失败', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '审核失败', 'data' => null];
|
||||
}
|
||||
//减少公会人数
|
||||
db::name('vs_guild')->where('id', $apply_id)->setDec('num');
|
||||
model('Tencent')->delete_group_member('g'.$apply_id, $apply_info['user_id']);
|
||||
} else {
|
||||
$update_data = [];
|
||||
$update_data['status'] = 2;
|
||||
$update_data['updatetime'] = time();
|
||||
$res = db::name('vs_guild_user_quit_log')->where('id',$apply_id)->update($update_data);
|
||||
if(!$res){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '审核失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '审核成功', 'data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '解散失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//解散公会
|
||||
public function diss_guild($uid,$guild_id){
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'user_id'=>$uid,'delete_time'=>0])->find();
|
||||
if(empty($guild_info)){
|
||||
return ['code' => 0, 'msg' => '公会不存在!', 'data' => null];
|
||||
}
|
||||
try {
|
||||
Db::startTrans();
|
||||
//成员解散
|
||||
db::name('vs_guild_user')->where(['guild_id'=>$guild_id,'status'=>1,'delete_time'=>0])->update(['delete_time'=>time(),'quit_type'=>3,'quit_time'=>time()]);
|
||||
//解散公会
|
||||
db::name('vs_guild')->where('id',$guild_id)->update(['delete_time'=>time(),'is_show'=>2,'num'=>0,'guild_special_id'=>""]);
|
||||
//解散群
|
||||
model('Tencent')->delete_group('g'.$guild_id);
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '解散成功!', 'data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '解散失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 工会房间列表
|
||||
* @param int $guild_id 公会id
|
||||
* @param int $page 分页
|
||||
* @param int $page_limit 每页数量
|
||||
*/
|
||||
public function get_guild_room_list($guild_id, $page = 1, $page_limit = 20){
|
||||
$map = [];
|
||||
$map['guild_id'] = $guild_id;
|
||||
$map['status'] = 1;
|
||||
$list = db::name('vs_guild_user')->where($map)->where("delete_time",0)->order('createtime desc')->page($page, $page_limit)->select();
|
||||
$data = [];
|
||||
foreach ($list as $k => $v){
|
||||
//房间信息
|
||||
$room_info = db::name('vs_room')->where(['id'=>$v['room_id'],'room_status'=>1,'delete_time'=>0])->find();
|
||||
if($room_info){
|
||||
$data[$k]['room_id'] = $room_info['id'];
|
||||
$data[$k]['room_number'] = model('Decorate')->user_decorate_detail($room_info['id'],7);
|
||||
$data[$k]['room_name'] = $room_info['room_name'];
|
||||
$data[$k]['room_cover'] = localpath_to_netpath($room_info['room_cover']);
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 工会补贴列表
|
||||
* @param int $guild_id 公会id
|
||||
* @param int $page 分页
|
||||
* int $page_limit 每页数量
|
||||
* @return array
|
||||
*/
|
||||
public function get_guild_subsidy_list($guild_id, $page = 1, $page_limit = 20){
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'delete_time'=>0])->find();
|
||||
if(empty($guild_info)){
|
||||
return ['code' => 0, 'msg' => '公会不存在!', 'data' => null];
|
||||
}
|
||||
$list = db::name('vs_guild_subsidy')
|
||||
->where("guild_id",$guild_id)
|
||||
->order('createtime asc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$count = db::name('vs_guild_subsidy')->where("guild_id",$guild_id)->count();
|
||||
$data = [];
|
||||
foreach ($list as $k => $v){
|
||||
$data[$k]['time'] = date('m.d',strtotime($v['start_time']))."-".date('m.d',strtotime($v['end_time']));
|
||||
$data[$k]['total_transaction'] = $v['total_transaction'];
|
||||
$data[$k]['subsidy_amount'] = $v['subsidy_amount'];
|
||||
$data[$k]['status_str'] = $v['status']==1 ? "已发放" : "未发放";
|
||||
}
|
||||
$return_data =[
|
||||
'page' => $page,
|
||||
'limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'list' => $data,
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $return_data];
|
||||
}
|
||||
/*
|
||||
* 工会补贴
|
||||
* @param int $guild_id 公会id
|
||||
* @param int $page 分页
|
||||
* int $page_limit 每页数量
|
||||
* @return array
|
||||
*/
|
||||
public function get_guild_subsidy($guild_id){
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'delete_time'=>0])->find();
|
||||
if(empty($guild_info)){
|
||||
return ['code' => 0, 'msg' => '公会不存在!', 'data' => null];
|
||||
}
|
||||
//规则
|
||||
$data['rule'] = get_system_config_value('web_site').'/api/Page/page_show?id=15';
|
||||
//上周流水
|
||||
$week_start = date('Y-m-d', strtotime('last monday'));
|
||||
$week_end = date('Y-m-d', strtotime('last monday +6 days'));
|
||||
$guild_subsidy = db::name('vs_guild_subsidy')
|
||||
->where(["guild_id"=>$guild_id,'start_time' => $week_start, 'end_time' => $week_end])
|
||||
->find();
|
||||
$data['list'] = [];
|
||||
$data['list'][0]['name'] = "上周流水";
|
||||
$data['list'][0]['total_transaction'] = isset($guild_subsidy['total_transaction'])?$guild_subsidy['total_transaction']:0;
|
||||
$data['list'][0]['subsidy_amount'] = isset($guild_subsidy['subsidy_amount'])?$guild_subsidy['subsidy_amount']:0;
|
||||
$data['list'][0]['status_str'] = isset( $guild_subsidy['status'])&& $guild_subsidy['status']==1 ? "已发放" : "未发放";
|
||||
//本周流水
|
||||
//本周的第一天
|
||||
$week = strtotime(date('Y-m-d', strtotime('this week Monday')));
|
||||
$guild_user = db::name('vs_guild_user')->where(['guild_id' => $guild_id,'status'=>1,"delete_time"=>null])->select();
|
||||
$guild_user_ids = array_column($guild_user,'room_id');
|
||||
$total_transaction = db::name('vs_give_gift')
|
||||
->where(['from'=>2,'from_id' => ['in',$guild_user_ids],'createtime' => ['between', [$week, time()]]])
|
||||
->sum('total_price');
|
||||
$ss = 0;
|
||||
if($total_transaction){
|
||||
//根据工会流水 获取补贴比例 单位%
|
||||
$subsidy_config = db::name('vs_guild_subsidy_config')->where('start_amount <= '. $total_transaction)
|
||||
->where('end_amount > '. $total_transaction)->getField('subsidy_ratio');
|
||||
$ss = $total_transaction * ($subsidy_config / 100);
|
||||
}
|
||||
//待开发
|
||||
$data['list'][1]['name'] = "本周流水";
|
||||
$data['list'][1]['total_transaction'] = isset($total_transaction)?$total_transaction:0;
|
||||
$data['list'][1]['subsidy_amount'] = $ss;
|
||||
$data['list'][1]['status_str'] = "未发放";
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取公会成员列表
|
||||
*/
|
||||
public function get_guild_member_list($guild_id, $start_time = 0, $end_time = 0, $page = 1, $page_limit = 20)
|
||||
{
|
||||
$coin_consumption_type_array = model('common/UserWallet')->coin_consumption_type_array;
|
||||
$coin_consumption_type_array = array_diff($coin_consumption_type_array, [model('common/UserWallet')::OPERATION_CONSUME]);
|
||||
|
||||
// // 获取所有工会成员的 user_id
|
||||
// $all_guild_users = Db::name('vs_guild_user')
|
||||
// ->where(['guild_id' => $guild_id, 'status' => 1, 'delete_time' => 0])
|
||||
// ->column('user_id');
|
||||
//
|
||||
// // 批量查询总消费
|
||||
// $total_consumption = Db::name('vs_user_money_log')
|
||||
// ->whereIn('change_type', $coin_consumption_type_array)
|
||||
// ->where(['money_type' => 1, 'createtime' => ['between', [$start_time, $end_time]]])
|
||||
// ->whereIn('user_id', $all_guild_users)
|
||||
// ->sum('change_value');
|
||||
//总消费
|
||||
//所有工会成员
|
||||
$all_guild_user = db::name('vs_guild_user')->where(['guild_id' => $guild_id,'status'=>1,"delete_time"=>0])->select();
|
||||
$total_consumption = 0;
|
||||
foreach ($all_guild_user as $key => $value) {
|
||||
if(!$start_time){
|
||||
$start_time_all = $value['createtime'];
|
||||
$end_time_all = time();
|
||||
}else{
|
||||
$start_time_all = strtotime($start_time." 00:00:00");
|
||||
$end_time_all = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
$consumption = db::name('vs_user_money_log')
|
||||
->whereIn('change_type',$coin_consumption_type_array)
|
||||
->where(['money_type'=>1,'user_id' => $value['user_id'],'createtime' => ['between', [$start_time_all, $end_time_all]]])
|
||||
->sum('change_value');
|
||||
$total_consumption = $total_consumption+$consumption;
|
||||
}
|
||||
|
||||
if (!$start_time || !$end_time) {
|
||||
$start_time = strtotime('-1 month'); // 默认最近一个月
|
||||
$end_time = time();
|
||||
}else{
|
||||
$start_time = strtotime($start_time." 00:00:00");
|
||||
$end_time = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
// 查询成员列表及各自消费
|
||||
$list = Db::name('vs_guild_user')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime BETWEEN ' . $start_time . ' AND ' . $end_time, 'LEFT')
|
||||
->field('a.id, a.user_id, a.guild_id, a.room_id, a.status, a.is_deacon, b.nickname, b.avatar, b.user_code, a.createtime, a.apply_time, SUM(c.change_value) AS total_consumption')
|
||||
->where(['a.guild_id' => $guild_id, 'a.status' => 1,'a.delete_time' => 0])
|
||||
->group('a.user_id')
|
||||
->order('a.id asc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$count = Db::name('vs_guild_user')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime BETWEEN ' . $start_time . ' AND ' . $end_time, 'LEFT')
|
||||
->field('a.id, a.user_id, a.guild_id, a.room_id, a.status, a.is_deacon, b.nickname, b.avatar, b.user_code, a.createtime, a.apply_time, SUM(c.change_value) AS total_consumption')
|
||||
->where(['a.guild_id' => $guild_id, 'a.status' => 1,'a.delete_time' => 0])
|
||||
->group('a.user_id')
|
||||
->count();
|
||||
$data = [];
|
||||
foreach ($list as $k => $v) {
|
||||
$data[$k]['id'] = $v['id'];
|
||||
$data[$k]['guild_id'] = $v['guild_id'];
|
||||
$data[$k]['user_id'] = $v['user_id'];
|
||||
$data[$k]['nickname'] = $v['nickname'];
|
||||
$data[$k]['avatar'] = localpath_to_netpath($v['avatar']);
|
||||
$data[$k]['user_code'] = model('Decorate')->user_decorate_detail($v['user_id'], 6);
|
||||
$data[$k]['is_deacon'] = $v['is_deacon'];
|
||||
$data[$k]['total_consumption'] = $v['total_consumption'] ?: 0;
|
||||
}
|
||||
$return_data =[
|
||||
'page' => $page,
|
||||
'limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'total_consumption' => $total_consumption,
|
||||
'list' => $data,
|
||||
];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $return_data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 工会流水查询
|
||||
* @return array
|
||||
*/
|
||||
public function get_guild_transaction($guild_id,$start_time=0,$end_time=0,$page=1,$page_limit=20){
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'delete_time'=>0])->find();
|
||||
if(empty($guild_info)){
|
||||
return ['code' => 0, 'msg' => '公会不存在!', 'data' => null];
|
||||
}
|
||||
//工会总流水
|
||||
$all_guild_room = db::name('vs_guild_user')->where(['guild_id' => $guild_id,'status'=>1,"delete_time"=>0])->select();
|
||||
$total_transaction = 0;
|
||||
foreach ($all_guild_room as $key => $value) {
|
||||
if(!$start_time){
|
||||
$start_time_all = $value['createtime'];
|
||||
$end_time_all = time();
|
||||
}else{
|
||||
$start_time_all = strtotime($start_time." 00:00:00");
|
||||
$end_time_all = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
$transaction = db::name('vs_give_gift')
|
||||
->where('from_id',$value['room_id'])
|
||||
->where(['from'=>2,'createtime' => ['between', [$start_time_all, $end_time_all]]])
|
||||
->sum('total_price');
|
||||
$total_transaction = $total_transaction+$transaction;
|
||||
}
|
||||
//查询工会所有房间流水
|
||||
$list = db::name('vs_guild_user')->where(['guild_id'=>$guild_id,'delete_time'=>0,'status'=>1,'room_id'=>['<>',0]])
|
||||
->order('coin desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
|
||||
$count = db::name('vs_guild_user')->where(['guild_id'=>$guild_id,'delete_time'=>0,'status'=>1,'room_id'=>['<>',0]])->count();
|
||||
$room_data = [];
|
||||
$i=0;
|
||||
foreach ($list as $k=>$v){
|
||||
if(!$start_time){
|
||||
$start_time = $v['createtime'];
|
||||
$end_time = time();
|
||||
}else{
|
||||
$start_time = strtotime($start_time." 00:00:00");
|
||||
$end_time = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
$room_info = db::name('vs_room')->where(['id'=>$v['room_id'],'room_status'=>1,'delete_time'=>0])->find();
|
||||
if($room_info){
|
||||
$room_data[$i]['room_id'] = $room_info['id'];
|
||||
$room_data[$i]['room_number'] = model('Decorate')->user_decorate_detail($room_info['id'],7);
|
||||
$room_data[$i]['room_name'] = $room_info['room_name'];
|
||||
$room_data[$i]['room_cover'] = localpath_to_netpath($room_info['room_cover']);
|
||||
$room_data[$i]['total_price'] = db::name('vs_give_gift')
|
||||
->where('from_id',$v['room_id'])
|
||||
->where(['from'=>2,'createtime' => ['between', [$start_time, $end_time]]])
|
||||
->sum('total_price');
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
$return_data = [];
|
||||
$return_data =[
|
||||
'page' => $page,
|
||||
'limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'total_transaction' => $total_transaction ? $total_transaction : 0,
|
||||
'list' => $room_data,
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $return_data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 用户是否加入工会
|
||||
* @param $user_id 用户id
|
||||
* @param $guild_id 工会id
|
||||
* @return array
|
||||
*/
|
||||
public function user_is_join($user_id){
|
||||
$guild_id = Db::name('vs_guild_user')->where(['user_id'=>$user_id,'status'=>1,'delete_time'=>0])->value('guild_id');
|
||||
if(empty($guild_id)){
|
||||
return 0;
|
||||
}else{
|
||||
return $guild_id;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取公会成员列表
|
||||
*/
|
||||
public function get_guild_user_list($guild_id,$user_id,$page=1,$page_limit=30){
|
||||
$count = Db::name('vs_guild_user')
|
||||
->alias('a')
|
||||
->join('user b','a.user_id = b.id')
|
||||
->where(['a.guild_id'=>$guild_id,'a.status'=>1,'a.delete_time'=>0])
|
||||
->count();
|
||||
$list = Db::name('vs_guild_user')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->field('a.id, a.user_id, a.guild_id, b.nickname, b.avatar, b.user_code, a.createtime')
|
||||
->where(['a.guild_id' => $guild_id, 'a.status' => 1,'a.delete_time' => 0])
|
||||
->order('a.id asc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$member_array = array_column($list, 'user_id');
|
||||
$member_array_str = [];
|
||||
foreach ($member_array as $k=> $v){
|
||||
$member_array_str[] = 'u' . $v;
|
||||
}
|
||||
$group_member_info = model('Tencent')->get_group_member_info('g' .$guild_id,$member_array_str);
|
||||
if($group_member_info['code'] == 0){
|
||||
return V($group_member_info['code'],$group_member_info['msg'], $group_member_info['data']);
|
||||
}
|
||||
$member = [];
|
||||
foreach ($group_member_info['data'] as $k=> $v){
|
||||
$member[$v['Member_Account']] = $v['Role'];
|
||||
}
|
||||
//Owner(群主),Admin(群管理员),Member(普通群成员),NotMember(非群成员)。
|
||||
$role = [
|
||||
'Owner'=>'群主',
|
||||
'Admin'=>'群管理员',
|
||||
'Member'=>'普通群成员',
|
||||
'NotMember'=>'非群成员'
|
||||
];
|
||||
foreach ($list as $key => $value) {
|
||||
if($user_id == $value['user_id']){
|
||||
$list[$key]['is_self'] = 1;
|
||||
}else{
|
||||
$list[$key]['is_self'] = 0;
|
||||
}
|
||||
$list[$key]['user_code'] = model('Decorate')->user_decorate_detail($value['user_id'], 6);
|
||||
//角色:
|
||||
$list[$key]['role'] = $member['u'.$value['user_id']];
|
||||
$list[$key]['role_str'] = $role[$list[$key]['role']];
|
||||
$list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
||||
//当前用户是否在房间
|
||||
$in_room = db::name('vs_room_visitor')->alias('a')
|
||||
->join('vs_room b', 'a.room_id = b.id')
|
||||
->field('a.room_id')
|
||||
->where(['b.type_id' =>['<>',6]])
|
||||
->where(['a.user_id' => $value['user_id'], 'a.is_delete' => 1])
|
||||
->find();
|
||||
$list[$key]['in_room_id'] = $in_room['room_id'] ?? 0;
|
||||
}
|
||||
$return_data =[
|
||||
'page' => $page,
|
||||
'limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'list' => $list,
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $return_data];
|
||||
|
||||
}
|
||||
/*
|
||||
* 群聊详情
|
||||
*/
|
||||
public function guild_info($guild_id,$user_id=0){
|
||||
if(!$guild_id){
|
||||
return ['code' => 0, 'msg' => '参数错误'];
|
||||
}
|
||||
$guild_info = db::name('vs_guild')->where(['id'=>$guild_id,'status'=>1,'delete_time'=>0])->find();
|
||||
$group_member_info = model('Tencent')->get_group_info('g'.$guild_id);
|
||||
if($group_member_info['code']!=1){
|
||||
return ['code' => 0, 'msg' => '群聊不存在',null];
|
||||
}
|
||||
$user_list = $this->get_guild_user_list($guild_id,0,1,10);
|
||||
$is_deacon = 2;
|
||||
if($guild_info['user_id'] ==$user_id){
|
||||
$is_deacon = 1;
|
||||
}
|
||||
$return_data =[
|
||||
'guild_id' => $guild_id,
|
||||
'guild_cover' => $guild_info['cover'],
|
||||
'is_deacon' => $is_deacon,
|
||||
'user_list' => $user_list['data']['list'],
|
||||
'name' => $group_member_info['data'][0]['Name'],
|
||||
'notification' => $group_member_info['data'][0]['Notification']
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $return_data];
|
||||
|
||||
}
|
||||
/*
|
||||
* 设置群聊信息
|
||||
*/
|
||||
public function set_guild_info($guild_id,$name,$notice,$avatar){
|
||||
$return = model('Tencent')->modify_group_base_info('g'.$guild_id, $name,$avatar, $notice);
|
||||
return ['code' => $return['code'], 'msg' => $return['msg'], 'data' => $return['data']];
|
||||
}
|
||||
}
|
||||
120
application/api/model/HeadLine.php
Normal file
120
application/api/model/HeadLine.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class HeadLine extends Model
|
||||
{
|
||||
protected $table = 'fa_vs_headline';
|
||||
//当前发(抢)头条需要的数据
|
||||
public function current_headline()
|
||||
{
|
||||
$config = get_system_config();
|
||||
|
||||
$reslut = db::name('vs_headline')->where('end_time' , '>', time())->where('is_now', 1)->find();
|
||||
if($reslut){
|
||||
$data = [
|
||||
'countdown' => $config['headline_time'],//倒计时时间 单位分钟
|
||||
'now_money' => $reslut['money'],
|
||||
'next_money' => $config['headline_incremental_money'] + $reslut['money'],
|
||||
];
|
||||
}else{
|
||||
$data = [
|
||||
'countdown' => $config['headline_time'],//倒计时时间 单位分钟
|
||||
'now_money' => 0,
|
||||
'next_money' => $config['headline_money'],//初始金额
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
//发布头条
|
||||
public function send_headline($uid, $money, $content,$room_id)
|
||||
{
|
||||
//维禁判断
|
||||
if(!empty($content)) {
|
||||
$result = model('Tencent')->content_moderation('Text', $content);
|
||||
if($result['code'] != 1) {
|
||||
return ['code' => 0, 'msg' => '内容存在违禁词!', 'data' => null];
|
||||
}
|
||||
}
|
||||
//检测用户余额
|
||||
$user_coin = model('UserWallet')->where('user_id' ,$uid)->value('coin');
|
||||
if($user_coin < $money) {
|
||||
return ['code' => 0, 'msg' => '余额不足!', 'data' => null];
|
||||
}
|
||||
//开启事务
|
||||
Db::startTrans();
|
||||
//发布头条 查询当前头条
|
||||
$res = db::name('vs_headline')->where('end_time' , '>', time())->where('is_now', 1)->find();
|
||||
if($res) {
|
||||
//判断当前头条是不是自己刚才抢的那一条 价格判断
|
||||
if(($res['money'] + get_system_config_value('headline_incremental_money')) != $money) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '手慢了,请重新抢!', 'data' => null];
|
||||
}
|
||||
//修改当前头条
|
||||
$res1 = db::name('vs_headline')->where('id', $res['id'])->update([
|
||||
'is_now' => 2,
|
||||
'end_time' => time(),
|
||||
]);
|
||||
if(!$res1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改当前头条失败!', 'data' => null];
|
||||
}
|
||||
}
|
||||
//新增头条
|
||||
$res3 = $this->save([
|
||||
'user_id' => $uid,
|
||||
'money' => $money,
|
||||
'content' => $content,
|
||||
'room_id' => $room_id,
|
||||
'is_now' => 1,
|
||||
'createtime' => time(),
|
||||
'end_time' => time() + get_system_config_value('headline_time') * 60,
|
||||
]);
|
||||
if(!$res3) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '抢头条失败!', 'data' => null];
|
||||
}
|
||||
|
||||
//扣除用户余额
|
||||
$res4 = model('UserWallet')->where('user_id' ,$uid)->setDec('coin', $money);
|
||||
if(!$res4) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '扣除用户余额失败!', 'data' => null];
|
||||
}
|
||||
//记录扣除用户余额
|
||||
$res5 =db::name('vs_user_money_log')->insert([
|
||||
'user_id' => $uid,
|
||||
'change_type' => 20,
|
||||
'money_type' => 1,
|
||||
'change_value' => $money,
|
||||
'from_id' => $res3,
|
||||
'remarks' => '发布头条扣除余额',
|
||||
'createtime' => time(),
|
||||
]);
|
||||
if(!$res5) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '记录扣除用户余额失败!', 'data' => null];
|
||||
}
|
||||
//给所有直播间发送消息 这个接口是要钱的 需要购买 暂时先藏起来
|
||||
$ToUserInfo = Db::name('user')->where(['id' => $uid])->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text = [
|
||||
'type' => 1,
|
||||
'content' => $content,
|
||||
'user_id' => $ToUserInfo['user_id'],
|
||||
'nickname' => $ToUserInfo['nickname'],
|
||||
'avatar' => $ToUserInfo['avatar'],
|
||||
'sex' => $ToUserInfo['sex'],
|
||||
'room_id' => $room_id,
|
||||
'end_time'=> time() + get_system_config_value('headline_time') * 60
|
||||
];
|
||||
model('Tencent')->send_broadcast_msg(json_encode($text));
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '发布成功!', 'data' => null];
|
||||
}
|
||||
}
|
||||
111
application/api/model/Invited.php
Normal file
111
application/api/model/Invited.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
use think\Db;
|
||||
|
||||
class Invited extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $table;
|
||||
public function __construct($data = [])
|
||||
{
|
||||
$prefix = config('database.prefix');
|
||||
$this->table = $prefix . 'vs_user_invited';
|
||||
parent::__construct($data);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 绑定推荐人(手动或后台绑定)
|
||||
*/
|
||||
public function invited_bind($init_code,$user_id){
|
||||
|
||||
$invited_user_info = model('User')->where('init_code', $init_code)->find();
|
||||
if (!$invited_user_info) {
|
||||
return ['code' => 0, 'msg' => "邀请码错误", 'data' => null];
|
||||
}
|
||||
//查询用户信息
|
||||
$user_info = model('User')->where('id', $user_id)->find();
|
||||
//查询绑定关系
|
||||
$bind_reslut = DB::name('vs_user_invited')->where('sub_user_id', $user_id)->find();
|
||||
if ($bind_reslut) {
|
||||
return ['code' => 0, 'msg' => "您已经绑定过上级用户", 'data' => null];
|
||||
}
|
||||
if ($init_code == $user_info['init_code']) {
|
||||
return ['code' => 0, 'msg' => "自己不能绑定自己", 'data' => null];
|
||||
}
|
||||
//绑定
|
||||
$reslut = model('Invited')->insert([
|
||||
'user_id' => $invited_user_info['id'],
|
||||
'sub_user_id' => $user_id,
|
||||
'init_code' => $init_code,
|
||||
'createtime' => time(),
|
||||
]);
|
||||
if (!$reslut) {
|
||||
return ['code' => 0, 'msg' => "绑定失败", 'data' => null];
|
||||
}
|
||||
//每日邀请1个好友注册app 【完成任务】
|
||||
model('DailyTasks')->tasks_complete($invited_user_info['id'],6);
|
||||
return ['code' => 1, 'msg' => "操作成功", 'data' => null];
|
||||
}
|
||||
|
||||
//下级充值推荐人收益计算
|
||||
public function invited_reward($sub_user_id,$money){
|
||||
//查询上级
|
||||
$invited_user_id = $this->where('sub_user_id', $sub_user_id)->value('user_id');
|
||||
if(!$invited_user_id){
|
||||
return ['code' => 0, 'msg' => "未绑定上级用户", 'data' => null];
|
||||
}
|
||||
$invited_draw_conf = get_system_config_value('invited_draw');//分成比例
|
||||
$invited_draw = $invited_draw_conf / 100;
|
||||
$invited_draw_money = $money * $invited_draw;
|
||||
//修改用户资金
|
||||
$reslut = model('common/UserWallet')->change_user_money($invited_user_id, $invited_draw_money, model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::OPERATION_INVITE_REBATE, '邀请用户充值返利');
|
||||
if($reslut['code'] == 1){
|
||||
//记录日志
|
||||
$data = [];
|
||||
$data['user_id'] = $invited_user_id;
|
||||
$data['sub_user_id'] = $sub_user_id;
|
||||
$data['coin'] = $money;
|
||||
$data['earnings'] = $invited_draw_money;
|
||||
$data['proportion'] = $invited_draw_conf;
|
||||
$data['createtime'] = time();
|
||||
$data['updatetime'] = time();
|
||||
$res = Db::name('vs_user_invited_income_log')->insert($data);
|
||||
if ($res) {
|
||||
return ['code' => 1, 'msg' => "操作成功", 'data' => null];
|
||||
}
|
||||
}else{
|
||||
return ['code' => $reslut['code'], 'msg' => $reslut['code'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//账单明细
|
||||
public function get_bill_list($user_id,$page=1,$page_size=10){
|
||||
$map = [
|
||||
'user_id' => $user_id,
|
||||
];
|
||||
$list = DB::name("vs_user_invited_income_log")
|
||||
->where($map)
|
||||
->field('id,user_id,sub_user_id,coin,earnings,proportion,createtime')
|
||||
->order('id desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['createtime'] = date('Y年m月d H:i', $v['createtime']);
|
||||
//查询用户昵称
|
||||
$v['nickname'] = model('User')->where('id', $v['sub_user_id'])->value('nickname');
|
||||
$v['coin'] = intval($v['coin']);
|
||||
$v['earnings'] = intval($v['earnings']);
|
||||
$v['proportion'] = intval($v['proportion']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
}
|
||||
415
application/api/model/Level.php
Normal file
415
application/api/model/Level.php
Normal file
@@ -0,0 +1,415 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
|
||||
class Level extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
public static function init()
|
||||
{
|
||||
self::beforeWrite(function ($row) {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* 魅力等级规则说明
|
||||
*/
|
||||
public function get_level_rule($uid)
|
||||
{
|
||||
//规则
|
||||
$return['rule_url'] = get_system_config_value('web_site')."/api/Page/page_show?id=10";
|
||||
//用户信息
|
||||
$user = model('User')->get_user_info($uid);
|
||||
//用户头像
|
||||
$return['user']['user_avatar'] = $user['avatar'];
|
||||
//当前用户等级信息
|
||||
$user_level = $this->get_charm_level_to_level($user['charm_level']);
|
||||
// 获取最后等级
|
||||
$level_last = Db::name('vs_charm_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'desc')
|
||||
->value('level');
|
||||
//用户当前经验
|
||||
$return['user']['level'] = $user['charm_level'];
|
||||
$return['user']['level_str'] = 'Lv.'.$user['charm_level'];
|
||||
$return['user']['exp'] = $user['charm_exp'];
|
||||
$return['user']['rights_icon'] = $user_level['rights_icon'];
|
||||
if($user['charm_level'] ==$level_last ){
|
||||
//距离下个等级需要的经验
|
||||
$return['user']['next_level'] = 0;
|
||||
$return['user']['next_level_str'] = "满级";
|
||||
$return['user']['next_exp'] = 0;
|
||||
$return['user']['next_rights_icon'] = "";
|
||||
}else{
|
||||
//距离下个等级需要的经验
|
||||
$return['user']['next_level'] = $user['charm_level']+1;
|
||||
$return['user']['next_level_str'] = 'Lv.'.$return['user']['next_level'];
|
||||
$return['user']['next_exp'] = $user_level['next_level_exp'] - $user['wealth_exp'];
|
||||
$return['user']['next_rights_icon'] = $user_level['next_rights_icon'];
|
||||
}
|
||||
|
||||
//获取等级
|
||||
// 获取用户当前等级
|
||||
$currentUserLevel = $user['charm_level'];
|
||||
if($currentUserLevel == 0){
|
||||
$level = Db::name('vs_charm_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'asc')
|
||||
->limit(3)
|
||||
->select();
|
||||
}elseif($currentUserLevel == $level_last){
|
||||
$level = Db::name('vs_charm_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'asc')
|
||||
->limit($level_last-2,3)
|
||||
->select();
|
||||
}else{
|
||||
$level = Db::name('vs_charm_level')
|
||||
->where('status', 1)
|
||||
->where('level', 'in', [$currentUserLevel - 1, $currentUserLevel, $currentUserLevel + 1])
|
||||
->order('level', 'asc')
|
||||
->select();
|
||||
}
|
||||
$return['level'] = [];
|
||||
if($level) {
|
||||
foreach ($level as $key => $value) {
|
||||
$return['level'][$key]['level'] = $value['level'];
|
||||
$return['level'][$key]['image'] = $value['image'];
|
||||
$return['level'][$key]['bg_image'] = $value['bg_image'];
|
||||
$return['level'][$key]['color'] = $value['color'];
|
||||
$return['level'][$key]['name'] = $value['name'];
|
||||
$return['level'][$key]['change_value'] = $value['change_value'];
|
||||
//当前用户距离当前段位的距离
|
||||
$return['level'][$key]['distance'] = $value['change_value'] - $user['wealth_exp'];
|
||||
$return['level'][$key]['rights_icon'] = $value['rights_icon'];
|
||||
}
|
||||
}
|
||||
$return['privilege'] = Db::name('vs_charm_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'asc')
|
||||
->select();
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $return];
|
||||
}
|
||||
|
||||
/*
|
||||
* 财富等级规则说明
|
||||
*/
|
||||
public function get_wealth_rule($uid)
|
||||
{
|
||||
//规则
|
||||
$return['rule_url'] = get_system_config_value('web_site')."/api/Page/page_show?id=11";
|
||||
//用户信息
|
||||
$user = model('User')->get_user_info($uid);
|
||||
//用户头像
|
||||
$return['user']['user_avatar'] = $user['avatar'];
|
||||
//当前用户等级信息
|
||||
$user_level = $this->get_wealth_level_to_level($user['wealth_level']);
|
||||
//用户当前经验
|
||||
$return['user']['level'] = $user['wealth_level'];
|
||||
$return['user']['level_str'] = 'Lv.'.$user['wealth_level'];
|
||||
$return['user']['exp'] = $user['wealth_exp'];
|
||||
$return['user']['coins'] = $user_level['coins'];
|
||||
//是否已领取金币
|
||||
$return['user']['is_get_coins'] = 0;
|
||||
$wealth_level_log = Db::name('vs_wealth_level_log')
|
||||
->where('user_id', $uid)
|
||||
->where('level', $user['wealth_level'])
|
||||
->find();
|
||||
if($wealth_level_log){
|
||||
$return['user']['is_get_coins'] = 1;
|
||||
}
|
||||
// 获取最后等级
|
||||
$level_last = Db::name('vs_wealth_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'desc')
|
||||
->value('level');
|
||||
if($user['wealth_level'] ==$level_last ){
|
||||
//距离下个等级需要的经验
|
||||
$return['user']['next_level'] = 0;
|
||||
$return['user']['next_level_str'] = "满级";
|
||||
$return['user']['next_exp'] = 0;
|
||||
$return['user']['next_coins'] = "";
|
||||
}else{
|
||||
//距离下个等级需要的经验
|
||||
$return['user']['next_level'] = $user['wealth_level']+1;
|
||||
$return['user']['next_level_str'] = 'Lv.'.$return['user']['next_level'];
|
||||
$return['user']['next_exp'] = $user_level['next_level_exp'] - $user['wealth_exp'];
|
||||
$return['user']['next_coins'] = $user_level['next_coins'];
|
||||
}
|
||||
//获取等级
|
||||
// 获取用户当前等级
|
||||
$currentUserLevel = $user['wealth_level'];
|
||||
if($currentUserLevel == 0){
|
||||
$level = Db::name('vs_wealth_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'asc')
|
||||
->limit(3)
|
||||
->select();
|
||||
}elseif($currentUserLevel == $level_last){
|
||||
$level = Db::name('vs_wealth_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'asc')
|
||||
->limit($level_last-2,3)
|
||||
->select();
|
||||
}else{
|
||||
$level = Db::name('vs_wealth_level')
|
||||
->where('status', 1)
|
||||
->where('level', 'in', [$currentUserLevel - 1, $currentUserLevel, $currentUserLevel + 1])
|
||||
->order('level', 'asc')
|
||||
->select();
|
||||
}
|
||||
$return['level'] = [];
|
||||
$return['privilege'] = [];
|
||||
if($level) {
|
||||
foreach ($level as $key => $value) {
|
||||
$return['level'][$key]['level'] = $value['level'];
|
||||
$return['level'][$key]['level_str'] = 'Lv.'.$value['level'];
|
||||
$return['level'][$key]['image'] = $value['image'];
|
||||
$return['level'][$key]['bg_image'] = $value['bg_image'];
|
||||
$return['level'][$key]['color'] = $value['color'];
|
||||
$return['level'][$key]['name'] = $value['name'];
|
||||
$return['level'][$key]['change_value'] = $value['change_value'];
|
||||
//当前用户距离当前段位的距离
|
||||
$return['level'][$key]['distance'] = $value['change_value'] - $user['wealth_exp'];
|
||||
$return['level'][$key]['coins'] = $value['coins'];
|
||||
//特权
|
||||
$privilege = Db::name('vs_wealth_level_rights')->alias('a')
|
||||
->join('vs_decorate b' , 'a.gift_id = b.did')
|
||||
->field('a.gift_id,b.title,b.base_image')
|
||||
->where('a.level_id', $value['id'])
|
||||
->find();
|
||||
$return['level'][$key]['privilege'] = '';
|
||||
if($privilege){
|
||||
$return['level'][$key]['privilege'] = $privilege['title'];
|
||||
$privilege['name'] = $value['name'].'解锁';
|
||||
$return['privilege'][$key] = $privilege;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $return];
|
||||
}
|
||||
|
||||
/*
|
||||
* 通过等级获取财富等级信息
|
||||
*/
|
||||
public function get_wealth_level_to_level($level=0){
|
||||
$return = [];
|
||||
$level_data = Db::name('vs_wealth_level')->where('level', $level)->find();
|
||||
$next_level_data = Db::name('vs_wealth_level')->where('level', $level+1)->find();
|
||||
if($level_data){
|
||||
$return['level'] = $level_data['level'];
|
||||
$return['level_name'] = $level_data['name'];
|
||||
$return['exp'] = $level_data['change_value'];
|
||||
$return['level_icon'] = $level_data['image'];
|
||||
$return['coins'] = $level_data['coins'];
|
||||
}else{
|
||||
$return['level'] = 0;
|
||||
$return['level_name'] = '';
|
||||
$return['exp'] = 0;
|
||||
$return['level_icon'] = '';
|
||||
$return['coins'] = 0;
|
||||
}
|
||||
|
||||
if($next_level_data){
|
||||
$return['next_level'] = $next_level_data['level'];
|
||||
$return['next_level_name'] = $next_level_data['name'];
|
||||
$return['next_level_exp'] = $next_level_data['change_value'];
|
||||
$return['next_level_icon'] = $next_level_data['image'];
|
||||
$return['next_coins'] = $next_level_data['coins'];
|
||||
}else{
|
||||
$return['next_level'] = 0;
|
||||
$return['next_level_name'] = '';
|
||||
$return['next_level_exp'] = 0;
|
||||
$return['next_level_icon'] = '';
|
||||
$return['next_coins'] = 0;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 通过等级获取魅力等级信息
|
||||
*
|
||||
*/
|
||||
public function get_charm_level_to_level($level){
|
||||
$return = [];
|
||||
$level_data = Db::name('vs_charm_level')->where('level', $level)->find();
|
||||
$next_level_data = Db::name('vs_charm_level')->where('level', $level+1)->find();
|
||||
if($level_data){
|
||||
$return['level'] = $level_data['level'];
|
||||
$return['level_name'] = $level_data['name'];
|
||||
$return['exp'] = $level_data['change_value'];
|
||||
$return['level_icon'] = $level_data['image'];
|
||||
$return['rights_icon'] = $level_data['rights_icon'];
|
||||
}else{
|
||||
$return['level'] = 0;
|
||||
$return['level_name'] = '';
|
||||
$return['exp'] = 0;
|
||||
$return['level_icon'] = '';
|
||||
$return['rights_icon'] = "";
|
||||
}
|
||||
|
||||
if($next_level_data){
|
||||
$return['next_level'] = $next_level_data['level'];
|
||||
$return['next_level_name'] = $next_level_data['name'];
|
||||
$return['next_level_exp'] = $next_level_data['change_value'];
|
||||
$return['next_level_icon'] = $next_level_data['image'];
|
||||
$return['next_rights_icon'] = $next_level_data['rights_icon'];
|
||||
}else{
|
||||
$return['next_level'] = 0;
|
||||
$return['next_level_name'] = '';
|
||||
$return['next_level_exp'] = 0;
|
||||
$return['next_level_icon'] = '';
|
||||
$return['next_rights_icon'] = "";
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/*
|
||||
* 用户财富/魅力等级更新
|
||||
* @param uid 用ID
|
||||
* @param value 金币数
|
||||
* @param type 类型 1:财富 2:魅力
|
||||
*/
|
||||
public function user_level_data_update($uid,$icon,$type,$room_id=0){
|
||||
$user = model('User')->get_user_info($uid,['user_level']);
|
||||
//配置
|
||||
if($type == 1){//财富
|
||||
$coin_charm_exp = get_system_config_value('coin_wealth_exp');
|
||||
$wealth_exp = $icon * $coin_charm_exp;//计算财富增长值
|
||||
//计算财富等级
|
||||
$user_wealth_level = $user['wealth_level'];
|
||||
$user_wealth_exp = $user['wealth_exp'] + $wealth_exp;
|
||||
//判断是否达到下一级别
|
||||
$user_wealth = $this->get_wealth_level_to_level($user_wealth_level);
|
||||
if($user_wealth_exp>= $user_wealth['exp']){
|
||||
$user_wealth_level= $user_wealth['next_level'];
|
||||
}
|
||||
$update_data = [];
|
||||
$update_data['wealth_level'] = $user_wealth_level;
|
||||
$update_data['wealth_exp'] = $user_wealth_exp;
|
||||
//修改用户信息
|
||||
$return = db('user_data')->where('user_id',$uid)->update($update_data);
|
||||
if($return){
|
||||
//发放特权礼物
|
||||
if($user_wealth_exp>= $user_wealth['exp']){
|
||||
$wealth_level_rights = db('vs_wealth_level_rights')->where('level_id',$user_wealth_level)->find();
|
||||
if(isset($wealth_level_rights['type']) && $wealth_level_rights['type'] ==1 ){//发座驾礼物
|
||||
$log_remark = "财富等级达到".$user_wealth_level."级 发放座驾礼物";
|
||||
$res = model('Decorate')->pay_decorate($uid,$wealth_level_rights['gift_id'],0,7,"");
|
||||
if($res['code']!=1){
|
||||
return ['code' => $res['code'], 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
}else{//魅力 coin_charm_exp
|
||||
$coin_charm_exp = get_system_config_value('coin_charm_exp');
|
||||
$charm_exp = $icon * $coin_charm_exp;//魅力增长值
|
||||
$user_charm_level = $user['charm_level'];
|
||||
$user_charm_exp = $user['charm_exp'] + $charm_exp;
|
||||
//判断是否达到下一级别
|
||||
$user_charm = $this->get_charm_level_to_level($user_charm_level);
|
||||
if($user_charm_exp>= $user_charm['exp']){
|
||||
$user_charm_level= $user_charm['next_level'];
|
||||
}
|
||||
$update_data = [];
|
||||
$update_data['charm_level'] = $user_charm_level;
|
||||
$update_data['charm_exp'] = $user_charm_exp;
|
||||
//修改用户信息
|
||||
$return = db('user_data')->where('user_id',$uid)->update($update_data);
|
||||
if(!$return){
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
//操作房间魅力值
|
||||
if($room_id){
|
||||
$return_charm = $this->room_user_charm_exp($uid,$room_id,$icon,$type);
|
||||
if($return_charm['code']==0){
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => "成功", 'data' => null];
|
||||
}
|
||||
|
||||
/*
|
||||
* 房间用户魅力值修改
|
||||
*/
|
||||
public function room_user_charm_exp($uid,$room_id,$exp,$type){
|
||||
//获取房间用户魅力
|
||||
$room_user_charm_exp = Db::name('vs_room_user_charm')->where(['user_id'=>$uid,'room_id'=>$room_id])->find();
|
||||
if($room_user_charm_exp){
|
||||
if($type == 1){
|
||||
$coin_charm_exp = get_system_config_value('coin_wealth_exp');
|
||||
$room_user_charm_exp_data['total_wealth'] = $room_user_charm_exp['total_wealth'] + $exp * $coin_charm_exp;
|
||||
}else{
|
||||
$coin_charm_exp = get_system_config_value('coin_charm_exp');
|
||||
$room_user_charm_exp_data['charm'] = $room_user_charm_exp['charm'] + $exp * $coin_charm_exp;
|
||||
$room_user_charm_exp_data['total_charm'] = $room_user_charm_exp['total_charm'] + $exp * $coin_charm_exp;
|
||||
}
|
||||
$room_user_charm_exp_data['updatetime'] = time();
|
||||
$return = Db::name('vs_room_user_charm')->where(['user_id'=>$uid,'room_id'=>$room_id])->update($room_user_charm_exp_data);
|
||||
}else{
|
||||
if($type == 1){
|
||||
$coin_charm_exp = get_system_config_value('coin_wealth_exp');
|
||||
$room_user_charm_exp_data['total_wealth'] = $exp * $coin_charm_exp;
|
||||
}else{
|
||||
$coin_charm_exp = get_system_config_value('coin_charm_exp');
|
||||
$room_user_charm_exp_data['charm'] = $exp * $coin_charm_exp;
|
||||
$room_user_charm_exp_data['total_charm'] = $exp * $coin_charm_exp;
|
||||
}
|
||||
$room_user_charm_exp_data['user_id'] = $uid;
|
||||
$room_user_charm_exp_data['room_id'] = $room_id;
|
||||
$room_user_charm_exp_data['createtime'] = time();
|
||||
$room_user_charm_exp_data['updatetime'] = time();
|
||||
$return = Db::name('vs_room_user_charm')->insert($room_user_charm_exp_data);
|
||||
}
|
||||
if($return){
|
||||
return ['code' => 1, 'msg' => "成功", 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 领取财富等级奖励金币
|
||||
*/
|
||||
public function get_wealth_level_reward($uid){
|
||||
$user_info = model('User')->get_user_info($uid,['user_level']);
|
||||
$wealth_level = $user_info['wealth_level'];
|
||||
$wealth_level = db('vs_wealth_level')->where('level',$wealth_level)->find();
|
||||
if(!$wealth_level){
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
if($wealth_level['coins']<=0){
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
$wealth_level_log = db('vs_wealth_level_log')->where(['user_id'=>$uid,'level'=>$wealth_level['level']])->find();
|
||||
if($wealth_level_log){
|
||||
return ['code' => 0, 'msg' => "你已领取该等级的奖励", 'data' => null];
|
||||
}
|
||||
//操作用户金币
|
||||
$res = model('common/UserWallet')->change_user_money($uid, $wealth_level['coins'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::FINANCE_LEVEL_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::FINANCE_LEVEL_REWARD));
|
||||
if($res['code']!=1){
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
$return = db('vs_wealth_level_log')->insert([
|
||||
'user_id'=>$uid,
|
||||
'level'=>$wealth_level['level'],
|
||||
'coins'=>$wealth_level['coins'],
|
||||
'createtime'=>time()]);
|
||||
if(!$return){
|
||||
return ['code' => 0, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => "成功", 'data' => null];
|
||||
}
|
||||
}
|
||||
449
application/api/model/Login.php
Normal file
449
application/api/model/Login.php
Normal file
@@ -0,0 +1,449 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use fast\Http;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class Login extends Model
|
||||
{
|
||||
|
||||
//注册
|
||||
public function user_reg($system,$login_device,$user_name='',$openid='',$ali_userid='',$apple_id='')
|
||||
{
|
||||
$block = db::name('block')->where(['type_text' => $login_device,'type' => 2])->find();
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => '设备已被封禁', 'data' => null];
|
||||
}
|
||||
$ip = request()->ip();
|
||||
$block = db::name('block')->where(['type_text' => $ip,'type' => 3])->find();
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => 'ip已被封禁', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$user_code = $this->get_user_code(); //获取用户code_id 过滤靓号
|
||||
|
||||
$data['user_code'] = $user_code;
|
||||
$data['username'] = $user_name;
|
||||
$data['mobile'] = $user_name;
|
||||
$data['nickname'] = '游客'.$user_code;
|
||||
$data['joinip'] = request()->ip();
|
||||
$data['birthday'] = date('Y-m-d');
|
||||
$data['avatar'] = get_system_config_value('web_site').'/data/avatar/head_pic.png';
|
||||
$data['profile'] = '这个人很懒,什么都没写';
|
||||
$data['system'] = $system;
|
||||
$data['login_device'] = $login_device;
|
||||
$data['createtime'] = time();
|
||||
$data['logintime'] = time();
|
||||
$data['status'] = 1;
|
||||
// $data['init_code'] = model('User')->invite_code();
|
||||
|
||||
$reslut = db::name('user')->insertGetId($data);
|
||||
//获取上一步的id
|
||||
$user_id = model('User')->where('user_code',$user_code)->value('id');
|
||||
|
||||
if (!$reslut) {
|
||||
return ['code' => 0, 'msg' => '登录失败le', 'data' => null];
|
||||
};
|
||||
|
||||
//创建钱包
|
||||
$user_wallet = model('UserWallet')->create_data($user_id);
|
||||
if (!$user_wallet) {
|
||||
return ['code' => 0, 'msg' => '登录失败1', 'data' => null];
|
||||
}
|
||||
|
||||
//注册即奖励金币【完成任务】
|
||||
model('DailyTasks')->tasks_complete($user_id,11);
|
||||
|
||||
/*********** 腾讯云IM ********/
|
||||
$user_sig = model('Tencent')->tencent_user_sig_info('u'.$user_id);
|
||||
model('Tencent')->account_import($user_id);
|
||||
if(empty($user_sig)){
|
||||
return ['code' => 0, 'msg' => '登录失败2', 'data' => null];
|
||||
}
|
||||
|
||||
//登录token
|
||||
$login_token = model('UserToken')->update_token($user_id);
|
||||
|
||||
if(isset($login_token['code']) && $login_token['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '登录失败3', 'data' => null];
|
||||
}
|
||||
|
||||
$user_data = [];
|
||||
$user_data['tencent_im'] = $user_sig;
|
||||
$user_data['createtime'] = time();
|
||||
$user_data['user_id'] = $user_id;
|
||||
$user_data['wx_openid'] = $openid;
|
||||
$user_data['ali_userid'] = $ali_userid;
|
||||
$user_data['apple_id'] = $apple_id;
|
||||
|
||||
$reslut_user_data = model('UserData')->save($user_data);
|
||||
if (!$reslut_user_data) {
|
||||
return ['code' => 0, 'msg' => '登录失败4', 'data' => null];
|
||||
}
|
||||
|
||||
$return_res[0]['user_id'] = $user_id;
|
||||
$return_res[0]['user_code'] = $user_code;
|
||||
$return_res[0]['avatar'] = 'data/avatar/head_pic.png';
|
||||
$return_res[0]['nickname'] = '游客'.$user_code;
|
||||
$return_res[0]['token'] = $login_token;
|
||||
$return_res[0]['tencent_im'] = $user_sig;
|
||||
$return_res[0]['sex'] = 0;
|
||||
$return_res[0]['mobile'] = $user_name;
|
||||
$return_res[0]['auth'] = 0;
|
||||
$return_res[0]['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$return_res[0]['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $return_res];
|
||||
}
|
||||
|
||||
//登录
|
||||
public function login($user_info, $system,$login_device ,$logtype='')
|
||||
{
|
||||
//查询账号封禁
|
||||
$block = db::name('block')->where(['type_text' => $user_info['id'],'type' => 1])->find();
|
||||
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => '用户已被封禁', 'data' => null];
|
||||
}
|
||||
$block = db::name('block')->where(['type_text' => $login_device,'type' => 2])->find();
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => '设备已被封禁', 'data' => null];
|
||||
}
|
||||
$ip = request()->ip();
|
||||
$block = db::name('block')->where(['type_text' => $ip,'type' => 3])->find();
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => 'ip已被封禁', 'data' => null];
|
||||
}
|
||||
|
||||
$save_data = [];
|
||||
$save_data['id'] = $user_info['id'];
|
||||
|
||||
//查询手机号绑定的账号
|
||||
$phone_user = $this->phone_login_query($user_info['mobile']);
|
||||
if($phone_user['code'] == 1){
|
||||
if(empty($logtype)){ //多账号登录
|
||||
//获取返回数据的长度
|
||||
if(count($phone_user['data']) >= 2){
|
||||
//多账号就返回多用户选择登录 id,user_code,avatar,nickname,sex
|
||||
$return_res = $phone_user['data'];
|
||||
foreach ($return_res as $key => $value){
|
||||
$return_res[$key]['token'] = '';
|
||||
$return_res[$key]['tencent_im'] = '';
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '用户获取成功', 'data' => $return_res];
|
||||
}else{
|
||||
$user_info = $phone_user['data'][0];
|
||||
}
|
||||
}
|
||||
|
||||
//登录token
|
||||
$login_token = model('UserToken')->update_token($user_info['id']);
|
||||
if(isset($login_token['code']) && $login_token['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '登录失败,', 'data' => null];
|
||||
}
|
||||
//获取userData 腾讯IM唯一标识
|
||||
$tencent_im = model('UserData')->get_tencent_im($user_info['id']);
|
||||
if(isset($tencent_im['code']) && $tencent_im['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '登录失败!', 'data' => null];
|
||||
}
|
||||
|
||||
$save_data['system'] = $system;
|
||||
$save_data['login_device'] = $login_device;
|
||||
$save_data['logintime'] = time();
|
||||
$save_data['loginip'] = request()->ip();
|
||||
$save_data['updatetime'] = time();
|
||||
$save_data['prevtime'] = $user_info['logintime'];//上次登录时间
|
||||
$reslut = model('User')->update($save_data);
|
||||
|
||||
if (!$reslut) {
|
||||
return ['code' => 0, 'msg' => '登录失败!!', 'data' => null];
|
||||
}
|
||||
|
||||
$return_res[0]['user_id'] = $user_info['id'];
|
||||
$return_res[0]['user_code'] = $user_info['user_code'];
|
||||
$return_res[0]['avatar'] = $user_info['avatar'];
|
||||
$return_res[0]['nickname'] = $user_info['nickname'];
|
||||
$return_res[0]['token'] = $login_token;
|
||||
$return_res[0]['tencent_im'] = $tencent_im;
|
||||
$return_res[0]['sex'] = $user_info['sex'];
|
||||
$return_res[0]['mobile'] = $user_info['mobile'];
|
||||
$return_res[0]['icon'][0] = model('UserData')->user_wealth_icon($user_info['id']);//财富图标
|
||||
$return_res[0]['icon'][1] = model('UserData')->user_charm_icon($user_info['id']);//魅力图标
|
||||
|
||||
$isAuth = 0;
|
||||
if($user_info['mobile']){
|
||||
$isAuth = db::name('user_auth')->where('mobile' , $user_info['mobile'])->value('is_real') == 1 ? 1 : 0;
|
||||
}
|
||||
$return_res[0]['auth'] = $isAuth;
|
||||
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $return_res];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '登录失败,账号失效', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//过滤靓号
|
||||
public function get_user_code()
|
||||
{
|
||||
$user_code = model('User')->order('user_code desc')->value('user_code');
|
||||
if(empty($user_code)){
|
||||
$user_code = 10000;
|
||||
}
|
||||
|
||||
$user_code = $user_code + 1;
|
||||
$vip_code = db::name('vip_code')->where(['type' => 1, 'status' => 1])->field('code')->select();
|
||||
|
||||
if (empty($vip_code)) {
|
||||
return $user_code;
|
||||
}
|
||||
if (in_array($user_code, (array)$vip_code)) {
|
||||
return $user_code + 2;
|
||||
}
|
||||
|
||||
return $user_code;
|
||||
}
|
||||
|
||||
//验证码/一键登录
|
||||
public function phone_verification_code_log($user_name, $system,$login_device)
|
||||
{
|
||||
if (empty($user_name)) {
|
||||
return ['code' => 0, 'msg' => '登录账号不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = db::name('user')->where(['mobile' => $user_name,'status' => ['<>',0]])->find();
|
||||
|
||||
if($user_info){//登录
|
||||
$login = $this->login($user_info,$system,$login_device);
|
||||
if($login['code'] != 1){
|
||||
return $login;
|
||||
}
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $login['data']];
|
||||
}else{//注册
|
||||
Db::startTrans();
|
||||
// try {
|
||||
$reslut = $this->user_reg($system,$login_device,$user_name);
|
||||
if($reslut['code'] != 1){
|
||||
Db::rollback();
|
||||
return $reslut;
|
||||
}
|
||||
$return_res = $reslut['data'];
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $return_res];
|
||||
// } catch (\Exception $e) {
|
||||
// // 回滚事务
|
||||
// Db::rollback();
|
||||
// return ['code' => 0, 'msg' => $e, 'data' => null];
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//账号密码登录
|
||||
public function user_login($user_name, $password, $system,$login_device)
|
||||
{
|
||||
if (empty($user_name)) {
|
||||
return ['code' => 0, 'msg' => '用户名不能为空', 'data' => null];
|
||||
}
|
||||
if (empty($password)) {
|
||||
return ['code' => 0, 'msg' => '密码不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = model('User')->where(['mobile' => $user_name,'status'=>1])->find();
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 0, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if (md5($password) != $user_info['password']) {
|
||||
return ['code' => 0, 'msg' => '密码错误', 'data' => null];
|
||||
}
|
||||
$multi_user = [];
|
||||
//查询手机号绑定的账号
|
||||
$phone_user = $this->phone_login_query($user_name);
|
||||
if($phone_user['code'] == 1){
|
||||
//获取返回数据的长度
|
||||
if(count($phone_user['data']) >= 2){
|
||||
$multi_user = $phone_user['data'];
|
||||
}
|
||||
}
|
||||
|
||||
$login = $this->login($user_info,$system,$login_device,$multi_user);
|
||||
if($login['code'] != 1){
|
||||
return $login;
|
||||
}
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $login['data']];
|
||||
}
|
||||
|
||||
//多账号选号登录
|
||||
public function multi_account_login($user_name,$system,$login_device){
|
||||
|
||||
$user_info = db::name('user')->where('id', $user_name)->find();
|
||||
|
||||
$login = $this->login($user_info,$system,$login_device,2);
|
||||
|
||||
if($login['code'] != 1){
|
||||
return $login;
|
||||
}
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $login['data']];
|
||||
}
|
||||
|
||||
//微信/支付宝 登录
|
||||
public function wechat_ali_Login($type,$userinfo,$system,$login_device){
|
||||
$ali_userid = '';
|
||||
$openid = '';
|
||||
$apple_id = '';
|
||||
if($type == 'wx'){
|
||||
$openid = $userinfo['openid'];
|
||||
$user_info_data = model('UserData')->where(['wx_openid' => $openid,'deletetime'=>0])->find();
|
||||
}elseif ($type == 'ali'){
|
||||
$ali_userid = $userinfo['open_id'];
|
||||
$user_info_data = model('UserData')->where(['ali_userid' => $ali_userid,'deletetime'=>0])->find();
|
||||
}elseif ($type == 'ios'){
|
||||
$apple_id = $userinfo;
|
||||
$user_info_data = model('UserData')->where(['apple_id' => $userinfo,'deletetime'=>0])->find();
|
||||
}
|
||||
else{
|
||||
return ['code' => 0, 'msg' => '登录类型错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info_data){//登录
|
||||
$return_res = [];
|
||||
$user_info = model('User')->where('id', $user_info_data['user_id'])->find();
|
||||
if($user_info['sex'] != 0){//已完善过自己的信息
|
||||
return $this->login($user_info,$system,$login_device,2);
|
||||
}else{//没有完善过自己的信息
|
||||
$return_res[0]['user_id'] = $user_info_data['user_id'];
|
||||
$return_res[0]['user_code'] = '';
|
||||
$return_res[0]['avatar'] = '';
|
||||
$return_res[0]['nickname'] = '';
|
||||
$return_res[0]['token'] = '';
|
||||
$return_res[0]['tencent_im'] = '';
|
||||
$return_res[0]['sex'] = 0;
|
||||
$return_res[0]['auth'] = 0;
|
||||
$return_res[0]['icon'][0] = model('UserData')->user_wealth_icon($user_info_data['user_id']);//财富图标
|
||||
$return_res[0]['icon'][1] = model('UserData')->user_charm_icon($user_info_data['user_id']);//魅力图标
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $return_res];
|
||||
}
|
||||
|
||||
}else{//注册
|
||||
//开启事务
|
||||
Db::startTrans();
|
||||
$reslut = $this->user_reg($system,$login_device,'',$openid,$ali_userid,$apple_id);
|
||||
if($reslut['code'] != 1){
|
||||
Db::rollback();
|
||||
return $reslut;
|
||||
}
|
||||
$return_res = $reslut['data'];
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $return_res];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//手机号相关登录时 查询此手机号在平台绑定的所有账号
|
||||
public function phone_login_query($phone){
|
||||
$user_info = db::name('user')->where(['mobile' => $phone,'status' =>['neq',0]])->select();
|
||||
if(empty($user_info)){
|
||||
return ['code' => 0, 'msg' => '查询失败', 'data' => null];
|
||||
}
|
||||
foreach ($user_info as &$value){
|
||||
$value['user_id'] = $value['id'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '查询成功', 'data' => $user_info];
|
||||
}
|
||||
|
||||
//退出登录
|
||||
public function logout($token){
|
||||
$user_info = model('UserToken')->where('token', $token)->find();
|
||||
if($user_info){
|
||||
model('UserToken')->where('id', $user_info['id'])->update(['token' => 1]);
|
||||
return ['code' => 1, 'msg' => '退出成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '退出失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//注销
|
||||
public function cancel($token){
|
||||
$user_info = model('UserToken')->where('token', $token)->find();
|
||||
if($user_info){
|
||||
model('UserToken')->where('id', $user_info['id'])->update(['token' => 1]);
|
||||
$isstatus = model('User')->where('id', $user_info['user_id'])->update(['status' => 0]);
|
||||
if($isstatus){
|
||||
//删除用户
|
||||
// model('Tencent')->account_delete($user_info['user_id']);
|
||||
model('User')->where('id', $user_info['user_id'])->update(['delete_time' => time()]);
|
||||
model('User')->where('id', $user_info['user_id'])->update(['avatar' => get_system_config_value('delete_avatar')]);
|
||||
model('UserData')->where('user_id', $user_info['user_id'])->update(['deletetime' => time()]);
|
||||
//查询创建的房间
|
||||
$room_list = db::name('vs_room')->where('user_id', $user_info['user_id'])->select();
|
||||
if($room_list){
|
||||
foreach ($room_list as &$value) {
|
||||
db::name('vs_room')->where('id', $value['id'])->update(['room_status' => 3]);
|
||||
}
|
||||
}
|
||||
//查询用户所在房间
|
||||
$room_list = db::name('vs_room_visitor')->where('user_id', $user_info['user_id'])->select();
|
||||
if($room_list){
|
||||
foreach ($room_list as &$value) {
|
||||
model('Room')->quit_room($user_info['user_id'], $value['room_id'],$user_info['user_id']);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '注销失败', 'data' => null];
|
||||
}
|
||||
|
||||
//查询绑定的手机号
|
||||
$mob = db::name('user')->where('id', $user_info['user_id'])->value('mobile');
|
||||
$mobile = db::name('user')->where('mobile', $mob)->select();
|
||||
if(isset($mobile) && count($mobile) < 2){
|
||||
$user_auth = db::name('user_auth')->where('mobile', $mobile[0]['mobile'])->find();
|
||||
if($user_auth){
|
||||
db::name('user_auth')->where('id', $user_auth['id'])->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '注销成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '注销失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//忘记密码
|
||||
public function forgot_password($mobile,$password){
|
||||
$user = model('User')->where(['mobile'=>$mobile,'status'=>1])->find();
|
||||
if(empty($user)){
|
||||
return ['code' => 0, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
$re = model('User')->where('id',$user['id'])->update(['password'=>md5($password)]);
|
||||
if(empty($re)){
|
||||
return ['code' => 0, 'msg' => '修改失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
26
application/api/model/Page.php
Normal file
26
application/api/model/Page.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Page extends Model
|
||||
{
|
||||
protected $table = 'fa_vs_page';
|
||||
|
||||
public function get_page($id)
|
||||
{
|
||||
$reslut = $this->where('aid', $id)->where('delete_time', 0)->find();
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
/*
|
||||
* 添加页面
|
||||
*/
|
||||
public function add_page($data){
|
||||
$data['createtime'] = time();
|
||||
$res = $this->insertGetId($data);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
58
application/api/model/QuanXian.php
Normal file
58
application/api/model/QuanXian.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class QuanXian extends Model
|
||||
{
|
||||
|
||||
public function quan_xian($user_id, $accept_user_id, $room_id)
|
||||
{
|
||||
//操作者
|
||||
//房主
|
||||
$owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
//管理
|
||||
$management = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null,'type' => 2])->find();
|
||||
//主持
|
||||
$host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null,'type' => 1])->find();
|
||||
//操作者的最大角色
|
||||
$max_role = 0;
|
||||
if ($host) {
|
||||
$max_role = 1;
|
||||
}
|
||||
if ($management) {
|
||||
$max_role = 2;
|
||||
}
|
||||
if ($owner) {
|
||||
$max_role = 3;
|
||||
}
|
||||
|
||||
//被操作者
|
||||
//房主
|
||||
$owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $accept_user_id])->field('id')->find();
|
||||
//管理
|
||||
$management = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $accept_user_id,'delete_time' => null,'type' => 2])->find();
|
||||
//主持
|
||||
$host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $accept_user_id,'delete_time' => null,'type' => 1])->find();
|
||||
|
||||
//被操作者最大角色
|
||||
$max_role_accept = 0;
|
||||
if ($host) {
|
||||
$max_role_accept = 1;
|
||||
}
|
||||
if ($management) {
|
||||
$max_role_accept = 2;
|
||||
}
|
||||
if ($owner) {
|
||||
$max_role_accept = 3;
|
||||
}
|
||||
|
||||
if ($max_role_accept > $max_role) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
380
application/api/model/Ranking.php
Normal file
380
application/api/model/Ranking.php
Normal file
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Ranking extends Model
|
||||
{
|
||||
protected $begin_time, $end_time, $type,$user_id, $lable, $page, $page_limit;
|
||||
|
||||
public function __construct($user_id,$type,$room_id,$page=1, $page_limit=30)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->type = $type;
|
||||
$this->user_id = $user_id;
|
||||
$this->room_id = $room_id;
|
||||
$this->page = $page;
|
||||
$this->page_limit = $page_limit;
|
||||
|
||||
switch ($type) {
|
||||
case 1://日榜
|
||||
$this->begin_time = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
|
||||
$this->end_time = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
|
||||
break;
|
||||
case 2://本周榜
|
||||
$this->begin_time = mktime(0, 0, 0, date('m'), date('d') - (date('w') ?: 7) + 1, date('Y'));
|
||||
$this->end_time = mktime(23, 59, 59, date('m'), date('d') - (date('w') ?: 7) + 7, date('Y'));
|
||||
break;
|
||||
case 3://本月榜
|
||||
$this->begin_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
|
||||
$this->end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
|
||||
break;
|
||||
default://总榜
|
||||
$this->begin_time = 0;
|
||||
$this->end_time = time();
|
||||
}
|
||||
}
|
||||
|
||||
//财富、魅力榜
|
||||
public function ranking($ranking_type)
|
||||
{
|
||||
if($ranking_type == 1){//1财富榜,2魅力榜
|
||||
$field = 'a.user_id,b.user_code,b.nickname,b.avatar,sum(a.total_wealth) as total';
|
||||
$order = 'total desc';
|
||||
$where['a.total_wealth'] = ['>', 0];
|
||||
}else{
|
||||
$field = 'a.user_id,b.user_code,b.nickname,b.avatar,sum(a.total_charm) as total';
|
||||
$order = 'total desc';
|
||||
$where['a.total_charm'] = ['>', 0];
|
||||
}
|
||||
$where['a.updatetime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
|
||||
$lists = db::name('vs_room_user_charm')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->group('a.user_id')
|
||||
->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
|
||||
$my_ranking = db::name('user')
|
||||
->field('user_code,avatar,nickname,id as user_id,user_code,sex')
|
||||
->where('id',$this->user_id)->find();
|
||||
$my_ranking['icon'][0] = model('UserData')->user_wealth_icon($my_ranking['user_id']);//财富图标
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = 0;
|
||||
if($lists){
|
||||
foreach ($lists as $key => &$value) {
|
||||
$lists[$key]['icon'][0] = model('UserData')->user_wealth_icon($value['user_id']);//财富图标
|
||||
$lists[$key]['icon'][1] = model('UserData')->user_charm_icon($value['user_id']);//魅力图标
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
if ($this->user_id == $value['user_id']) {
|
||||
$my_ranking = $lists[$key];
|
||||
$my_ranking['diff'] = $key == 0 ? 0 : ($lists[$key - 1]['total'] - $value['total']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$my_ranking && $lists && defined('UID')) {
|
||||
$my_ranking_data = db::name('vs_room_user_charm')->alias('a')
|
||||
->join('user b','a.user_id = b.id')
|
||||
->where($where)
|
||||
->where('a.user_id',$this->user_id)
|
||||
->field($field)
|
||||
->find();
|
||||
$my_ranking_data['icon'][0] = model('UserData')->user_wealth_icon($my_ranking_data['user_id']);//财富图标
|
||||
$my_ranking_data['icon'][1] = model('UserData')->user_charm_icon($my_ranking_data['user_id']);//魅力图标
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
|
||||
if (!isset($my_ranking_data['user_id']) || !$my_ranking_data['user_id']) {
|
||||
$my_ranking = db::name('user')
|
||||
->field('user_code,avatar,nickname,id as user_id,user_code,sex')
|
||||
->where('id',$this->user_id)->find();
|
||||
$my_ranking['icon'][0] = model('UserData')->user_wealth_icon($my_ranking['user_id']);//财富图标
|
||||
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
} else {
|
||||
$my_ranking = $my_ranking_data;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = numberFormat($my_ranking['total']);
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number - ($my_ranking_data['total'] ?: 0));
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'my_ranking' => $my_ranking,
|
||||
'lists' => $lists
|
||||
];
|
||||
|
||||
return ['code'=>1,'msg'=>'获取成功','data'=>$data];
|
||||
}
|
||||
|
||||
//房间榜
|
||||
public function room_ranking()
|
||||
{
|
||||
$where['a.createtime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
$where['b.type_id'] = ['<>', 6];
|
||||
$where['b.room_status'] = 1;
|
||||
$field = ['sum(a.total_price) as total,b.room_name,a.from_id as room_id,b.room_cover,b.room_number'];
|
||||
$lists = db::name('vs_give_gift')->alias('a')
|
||||
->join('vs_room b','a.from_id = b.id','left')
|
||||
->where($where)->field($field)->group('a.from_id')
|
||||
->order('total desc')
|
||||
->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
$my_ranking = null;
|
||||
if($lists){
|
||||
//获取当前用户的房间id
|
||||
$myRoom = db::name('vs_room')->where(['user_id' => UID ,'room_status' => 1])->find();
|
||||
if($myRoom){
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
if ($myRoom['id'] == $value['room_id']) {
|
||||
$my_ranking = $lists[$key];
|
||||
$my_ranking['diff'] = $key == 0 ? 0 : ($lists[$key - 1]['total'] - $value['total']);
|
||||
}
|
||||
// $lists[$key]['total'] = numberFormat($value['total']);
|
||||
}
|
||||
|
||||
if (!$my_ranking && $lists && defined('UID')) {
|
||||
$where1['a.createtime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
$where1['b.type_id'] = ['<>', 6];
|
||||
$my_ranking_data = db::name('vs_give_gift')->alias('a')
|
||||
->join('vs_room b','a.from_id = b.id','left')
|
||||
->where(['a.from_id' => $myRoom['id']])
|
||||
->where($where1)
|
||||
->field('a.from_id as room_id,sum(a.total_price) as total,b.room_name,b.room_cover,b.room_number')->find();
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
$diff = numberFormat($lists_last_number - ($my_ranking_data['total'] ?: 0));
|
||||
$diff = $diff<=0 ? 0 : $diff;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = numberFormat($my_ranking_data['total']);
|
||||
$my_ranking['diff'] = $diff;
|
||||
$my_ranking['room_name'] = $my_ranking_data['room_name'];
|
||||
$my_ranking['room_cover'] = $my_ranking_data['room_cover'];
|
||||
if(!$my_ranking_data['room_name']){
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['diff'] = $diff;
|
||||
$my_ranking['room_name'] = $myRoom['room_name'];
|
||||
$my_ranking['room_cover'] = $myRoom['room_cover'];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
}
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
//获取当前用户的房间id
|
||||
$myRoom = db::name('vs_room')->where(['user_id' => UID ,'room_status' => 1])->find();
|
||||
if($myRoom){
|
||||
$my_ranking['room_name'] = $myRoom['room_name'];
|
||||
$my_ranking['room_cover'] = $myRoom['room_cover'];
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
}else{
|
||||
$my_ranking['room_name'] = '';
|
||||
$my_ranking['room_cover'] = '';
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
//获取当前用户的房间id
|
||||
$myRoom = db::name('vs_room')->where(['user_id' => UID ,'room_status' => 1])->find();
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['diff'] = 0;
|
||||
$my_ranking['room_name'] = $myRoom['room_name'];
|
||||
$my_ranking['room_cover'] = $myRoom['room_cover'];
|
||||
}
|
||||
$data = [
|
||||
'my_ranking' => $my_ranking,
|
||||
'lists' => $lists
|
||||
];
|
||||
return ['code'=>1,'msg'=>'获取成功','data'=>$data];
|
||||
}
|
||||
|
||||
//公会榜
|
||||
public function guild_ranking()
|
||||
{
|
||||
$where['createtime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
|
||||
//所有工会
|
||||
$guilds = db::name('vs_guild')->where(['status' => 1])->select();
|
||||
if($guilds){
|
||||
foreach ($guilds as $k=>$value){
|
||||
$total = 0;
|
||||
$roomids[$k] = db::name('vs_guild_user')->where(['guild_id' => $value['id']])->field('room_id')->select();
|
||||
if($roomids[$k]){
|
||||
foreach ($roomids[$k] as $key => $value1){
|
||||
$toomType = db::name('vs_room')->where(['id' => $value1['room_id']])->where($where)->value('type_id');
|
||||
if($toomType == 6){
|
||||
continue;
|
||||
}
|
||||
$total += db::name('vs_give_gift')->where(['from_id' => $value1['room_id']])->sum('total_price');
|
||||
}
|
||||
}
|
||||
$guilds[$k]['total'] = $total;
|
||||
}
|
||||
//剔除$guilds[$k]['total'] = 0的
|
||||
$guilds = array_filter($guilds, function ($value) {
|
||||
return $value['total'] > 0;
|
||||
});
|
||||
//根据$guilds[$k]['total']排序
|
||||
array_multisort(array_column($guilds, 'total'), SORT_DESC, $guilds);
|
||||
}
|
||||
|
||||
$lists = $guilds ;
|
||||
$my_ranking = null;
|
||||
if($lists){
|
||||
//获取当前用户的工会
|
||||
$myGuild = db::name('vs_guild_user')->where(['user_id' => UID])->find();
|
||||
if($myGuild){
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
// $lists[$key]['total'] = numberFormat($value['total']);
|
||||
if ($myGuild['guild_id'] == $value['id']) {
|
||||
$my_ranking = $lists[$key];
|
||||
$my_ranking['diff'] = $key == 0 ? 0 : ($lists[$key - 1]['total'] - $value['total']);
|
||||
}
|
||||
}
|
||||
if (!$my_ranking && $lists && defined('UID')) {
|
||||
$my_rankings = null;
|
||||
//当前工会的所有房间
|
||||
$myguildroom = db::name('vs_guild_user')->where(['guild_id' => $myGuild['guild_id']])->field('room_id')->select();
|
||||
foreach ($myguildroom as $key => $gvalue1){
|
||||
$my_rankings['total'] += db::name('vs_give_gift')->where(['from_id' => $gvalue1['room_id']])->where($where)->sum('total_price');
|
||||
}
|
||||
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
$diff = numberFormat($lists_last_number - ($my_rankings['total'] ?: 0));
|
||||
$diff = $diff<=0 ? 0 : $diff;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = numberFormat($my_rankings['total']);
|
||||
$my_ranking['diff'] = $diff;
|
||||
$my_ranking['guild_name'] = $myGuild['room_name'];
|
||||
$my_ranking['cover'] = $myGuild['cover'];
|
||||
if(!$my_rankings){
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['diff'] = $diff;
|
||||
$my_ranking['guild_name'] = '';
|
||||
$my_ranking['cover'] = '';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
}
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
//获取当前用户所在工会
|
||||
$myGuild = db::name('vs_guild_user')->where(['user_id' => UID])->find();
|
||||
if($myGuild){
|
||||
$my_ranking['guild_name'] = db::name('vs_guild')->where(['id' => $myGuild['guild_id']])->value('guild_name');
|
||||
$my_ranking['cover'] = db::name('vs_guild')->where(['id' => $myGuild['guild_id']])->value('cover');
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
}else{
|
||||
$my_ranking['guild_name'] = '';
|
||||
$my_ranking['cover'] = '';
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'my_ranking' => $my_ranking,
|
||||
'lists' => $lists
|
||||
];
|
||||
return ['code'=>1,'msg'=>'获取成功','data'=>$data];
|
||||
}
|
||||
|
||||
//真爱榜
|
||||
public function love_ranking()
|
||||
{
|
||||
$where['c.createtime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
$where['a.status'] = 1;
|
||||
$field = ['a.user_id,a.user_id1,sum(c.total_price) as total,a.room_id,b.room_cover,b.room_intro as room_name'];
|
||||
$lists = db::name('vs_room_cp_movie')->alias('a')
|
||||
->join('vs_room b','a.room_id = b.id','left')
|
||||
->join('vs_give_gift c','a.room_id = c.from_id','left')
|
||||
->where($where)->field($field)->group('a.room_id')
|
||||
->order('total desc')
|
||||
->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
$my_ranking = null;
|
||||
if($lists){
|
||||
//获取当前用户的房间id $this->user_id
|
||||
$myRoom = db::name('vs_room_cp_movie')->where(['user_id' => UID ,'status' => 1])->find();
|
||||
if(!$myRoom){
|
||||
$myRoom = db::name('vs_room_cp_movie')->where(['user_id1' => UID ,'status' => 1])->find();
|
||||
}
|
||||
if($myRoom){
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
$lists[$key]['user_avatar'] = db::name('user')->where(['id' => $value['user_id']])->value('avatar');
|
||||
$lists[$key]['user_avatar1'] = db::name('user')->where(['id' => $value['user_id1']])->value('avatar');
|
||||
$lists[$key]['nickname'] = db::name('user')->where(['id' => $value['user_id']])->value('nickname');
|
||||
$lists[$key]['nickname1'] = db::name('user')->where(['id' => $value['user_id1']])->value('nickname');
|
||||
if ($myRoom['room_id'] == $value['room_id']) {
|
||||
$my_ranking = $lists[$key];
|
||||
$my_ranking['diff'] = $key == 0 ? 0 : ($lists[$key - 1]['total'] - $value['total']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$my_ranking && $lists && defined('UID')) {
|
||||
$where1['c.createtime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
$where1['a.status'] = 1;
|
||||
$my_ranking_data = db::name('vs_room_cp_movie')->alias('a')
|
||||
->join('vs_room b','a.room_id = b.id','left')
|
||||
->join('vs_give_gift c','a.room_id = c.from_id','left')
|
||||
->where(['c.from_id' => $myRoom['room_id']])
|
||||
->where($where1)
|
||||
->field('a.user_id,a.user_id1,a.room_id,sum(c.total_price) as total,b.room_intro as room_name,b.room_cover')->find();
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
$diff = numberFormat($lists_last_number - ($my_ranking_data['total'] ?: 0));
|
||||
$diff = $diff<=0 ? 0 : $diff;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = numberFormat($my_ranking_data['total']);
|
||||
$my_ranking['diff'] = $diff;
|
||||
$my_ranking['room_name'] = $my_ranking_data['room_name'];
|
||||
$my_ranking['room_cover'] = $my_ranking_data['room_cover'];
|
||||
$my_ranking['user_avatar'] = db::name('user')->where(['id' => $my_ranking_data['user_id']])->value('avatar');
|
||||
$my_ranking['user_avatar1'] = db::name('user')->where(['id' => $my_ranking_data['user_id1']])->value('avatar');
|
||||
|
||||
if(!$my_ranking_data['room_name']){
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['diff'] = $diff;
|
||||
$my_ranking['room_name'] = '';
|
||||
$my_ranking['room_cover'] = '';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
$lists[$key]['user_avatar'] = db::name('user')->where(['id' => $value['user_id']])->value('avatar');
|
||||
$lists[$key]['user_avatar1'] = db::name('user')->where(['id' => $value['user_id1']])->value('avatar');
|
||||
$lists[$key]['nickname'] = db::name('user')->where(['id' => $value['user_id']])->value('nickname');
|
||||
$lists[$key]['nickname1'] = db::name('user')->where(['id' => $value['user_id1']])->value('nickname');
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'my_ranking' => $my_ranking,
|
||||
'lists' => $lists
|
||||
];
|
||||
return ['code'=>1,'msg'=>'获取成功','data'=>$data];
|
||||
}
|
||||
}
|
||||
2459
application/api/model/Room.php
Normal file
2459
application/api/model/Room.php
Normal file
File diff suppressed because it is too large
Load Diff
504
application/api/model/RoomAuction.php
Normal file
504
application/api/model/RoomAuction.php
Normal file
@@ -0,0 +1,504 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomAuction extends Model
|
||||
{
|
||||
//房间关系列表
|
||||
public function room_relation_list($type_id)
|
||||
{
|
||||
$list = db::name('vs_relation')->field('id as relation_id,name,type,icon')->where(['type' => $type_id,'delete_time' => 0])->select();
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => $list];
|
||||
}
|
||||
|
||||
//礼物计算时间
|
||||
public function room_auction_time($gift_id)
|
||||
{
|
||||
//获取礼物价格
|
||||
$gift_price = db::name('vs_gift')->where('gid',$gift_id)->value('gift_price') ?? 0;
|
||||
if($gift_price == 0){
|
||||
return ['code' => 0, 'msg' => '礼物不存在!','data' => null];
|
||||
}
|
||||
return floor($gift_price/get_system_config_value('room_love_auction_cion')) * get_system_config_value('room_love_auction_hour');
|
||||
}
|
||||
|
||||
|
||||
// 房间竞拍开始
|
||||
public function room_auction($room_id,$user_id,$gift_id,$relation_id,$auction_type,$time_day)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '房间ID不能为空','data' => null];
|
||||
}
|
||||
if(!$user_id){
|
||||
return ['code' => 0, 'msg' => '用户ID不能为空','data' => null];
|
||||
}
|
||||
if(!$gift_id){
|
||||
return ['code' => 0, 'msg' => '礼物ID不能为空','data' => null];
|
||||
}
|
||||
|
||||
if(!$auction_type){
|
||||
return ['code' => 0, 'msg' => '竞拍类型不能为空','data' => null];
|
||||
}
|
||||
if(!$time_day){
|
||||
if($auction_type == 1){
|
||||
$time_day = $this->room_auction_time($gift_id);
|
||||
if($time_day <= 0){
|
||||
return ['code' => 0, 'msg' => '价值过低,请重新选择礼物!','data' => null];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '请选择时间!','data' => null];
|
||||
}
|
||||
}
|
||||
//查询房间是否正在拍卖
|
||||
$auction = db::name('vs_room_auction')->where('room_id',$room_id)->where('status',2)->find();
|
||||
if($auction){
|
||||
return ['code' => 0, 'msg' => '房间正在竞拍中!请稍后继续','data' => null];
|
||||
}
|
||||
$user_ids = Cache::get('auction_user_'.$room_id);
|
||||
if($user_ids != $user_id){
|
||||
return ['code' => 0, 'msg' => '您已被管理员取消本场次竞拍,请联系管理员','data' => null];
|
||||
}
|
||||
|
||||
$gift_price = db::name('vs_gift')->where('gid',$gift_id)->value('gift_price') ?? 0;
|
||||
//数据写入数据库
|
||||
$res = Db::name('vs_room_auction')->insertGetId([
|
||||
'auction_type' => $auction_type,
|
||||
'room_id' => $room_id,
|
||||
'user_id' => $user_id,
|
||||
'gift_id' => $gift_id,
|
||||
'gift_price' => $gift_price,
|
||||
'relation_id' => $relation_id,
|
||||
'time_day' => $time_day * 60 * 60,//s
|
||||
'createtime' => time(),
|
||||
'status'=> 2,
|
||||
'updatetime' => time(),
|
||||
'duration' => time() + 60 * 3 //截止时间
|
||||
]);
|
||||
|
||||
if(!$res){
|
||||
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
||||
}
|
||||
$auction = db::name('vs_room_auction')->alias('a')->join('user b', 'a.user_id = b.id', 'left')
|
||||
->field('a.auction_id,a.user_id,b.nickname,b.avatar,b.sex,b.user_code,a.auction_type,a.relation_id,a.gift_id,a.gift_price,a.time_day,a.duration')
|
||||
->where(['a.auction_id' => $res])->find();
|
||||
|
||||
if($auction){
|
||||
$auction['dress'] = model('Decorate')->user_decorate_detail($auction['user_id'], 1);
|
||||
$auction['relation_name'] = db::name('vs_relation')->where('id',$auction['relation_id'])->value('name');
|
||||
$auction['relation_icon'] = db::name('vs_relation')->where('id',$auction['relation_id'])->value('icon');
|
||||
$auction['base_image'] = db::name('vs_gift')->where('gid',$auction['gift_id'])->value('base_image');
|
||||
$auction['gift_name'] = db::name('vs_gift')->where('gid',$auction['gift_id'])->value('gift_name');
|
||||
$auction['time_day'] = $auction['time_day'] / 60 / 60;
|
||||
}
|
||||
// var_dump($auction);
|
||||
//推送消息
|
||||
$text = [
|
||||
'FromUserInfo' => null,
|
||||
'auction_user' => $auction ,
|
||||
'text' => '拍卖开始'
|
||||
];
|
||||
model('api/Chat')->sendMsg(1023,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => ['auction_id'=>$res]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//参与竞拍
|
||||
public function room_auction_join($auction_id,$user_id,$gift_id,$num,$type)
|
||||
{
|
||||
if(!$auction_id){
|
||||
return ['code' => 0, 'msg' => '拍卖已经结束','data' => null];
|
||||
}
|
||||
if(!$user_id){
|
||||
return ['code' => 0, 'msg' => '用户ID不能为空','data' => null];
|
||||
}
|
||||
if(!$gift_id){
|
||||
return ['code' => 0, 'msg' => '礼物ID不能为空','data' => null];
|
||||
}
|
||||
$auction = db::name('vs_room_auction')->where('auction_id',$auction_id)->field('room_id,gift_price,user_id,status')->find();
|
||||
$gift_price = db::name('vs_gift')->where('gid',$gift_id)->value('gift_price') ?? 0;
|
||||
if($user_id == $auction['user_id']){
|
||||
return ['code' => 0, 'msg' => '不能参与自己的竞拍!','data' => null];
|
||||
}
|
||||
|
||||
//走送礼流程
|
||||
$ree = model('GiveGift')->give_gift($user_id,$auction['user_id'],$gift_id,$num,2,$type,$auction['room_id'],0,0);
|
||||
if($ree['code'] != 1){
|
||||
return ['code' => $ree['code'], 'msg' => $ree['msg'],'data' => null];
|
||||
}
|
||||
if($auction['status'] == 2){//1未开启 2进行中 3已结束
|
||||
//数据写入数据库
|
||||
$res = db::name('vs_room_auction_bid_log')->insert([
|
||||
'auction_id' => $auction_id,
|
||||
'user_id' => $user_id,
|
||||
'gift_id' => $gift_id,
|
||||
'gift_price' => $num * $gift_price,
|
||||
'createtime' => time()
|
||||
]);
|
||||
if(!$res){
|
||||
return ['code' => 0, 'msg' => '操作失败,','data' => null];
|
||||
}
|
||||
|
||||
//整理数据 排序
|
||||
$list = $this->room_auction_list_on($auction_id);
|
||||
//推送消息
|
||||
$text = [
|
||||
'FromUserInfo' => null,
|
||||
'auction_user' => null ,
|
||||
'auction_list' => $list,
|
||||
'text' => '参与竞拍'
|
||||
];
|
||||
model('api/Chat')->sendMsg(1024,$auction['room_id'],$text);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => $list];
|
||||
}
|
||||
|
||||
|
||||
//房间竞拍上麦列表
|
||||
public function room_auction_list_on($auction_id)
|
||||
{
|
||||
$auction = db::name('vs_room_auction')->where('auction_id',$auction_id)->field('room_id,gift_price')->find();
|
||||
$list = db::name('vs_room_auction_bid_log')->field('user_id, SUM(gift_price) AS gift_prices')
|
||||
->where(['auction_id' => $auction_id])
|
||||
->group('user_id')
|
||||
->having('gift_prices >= ' . $auction['gift_price'])
|
||||
->order('gift_prices DESC')
|
||||
->limit(6)
|
||||
->select();
|
||||
if($list){
|
||||
foreach ($list as &$v){
|
||||
$v['charm'] = db::name('vs_room_user_charm')->where(['room_id' => $auction['room_id'],'user_id' => $v['user_id']])->value('charm');
|
||||
$v['dress'] = model('Decorate')->user_decorate_detail($v['user_id'],1);
|
||||
$v['user_code'] = model('Decorate')->user_decorate_detail($v['user_id'],6);
|
||||
$v['nickname'] = db::name('user')->where('id',$v['user_id'])->value('nickname');//nickname,b.avatar,b.sex
|
||||
$v['avatar'] = db::name('user')->where('id',$v['user_id'])->value('avatar');
|
||||
$v['sex'] = db::name('user')->where('id',$v['user_id'])->value('sex');
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
//房间竞拍全部列表
|
||||
public function room_auction_list($auction_id)
|
||||
{
|
||||
if(!$auction_id){
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
}
|
||||
$auction = db::name('vs_room_auction')->where('auction_id',$auction_id)->field('room_id,gift_price,user_id,status')->find();
|
||||
$list = db::name('vs_room_auction_bid_log')->field('user_id,sum(gift_price) as gift_prices')
|
||||
->where('auction_id',$auction_id)->group('user_id')->order('gift_prices desc')->select();
|
||||
if($list){
|
||||
foreach ($list as &$v){
|
||||
$v['charm'] = db::name('vs_room_user_charm')->where(['room_id' => $auction['room_id'],'user_id' => $v['user_id']])->value('charm');
|
||||
$v['dress'] = model('Decorate')->user_decorate_detail($v['user_id'],1);
|
||||
$v['user_code'] = model('Decorate')->user_decorate_detail($v['user_id'],6);
|
||||
$v['nickname'] = db::name('user')->where('id',$v['user_id'])->value('nickname');
|
||||
$v['avatar'] = db::name('user')->where('id',$v['user_id'])->value('avatar');
|
||||
$v['sex'] = db::name('user')->where('id',$v['user_id'])->value('sex');
|
||||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
||||
$v['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => $list];
|
||||
}
|
||||
|
||||
//延时
|
||||
public function room_auction_delay($auction_id)
|
||||
{
|
||||
if(!$auction_id){
|
||||
return ['code' => 0, 'msg' => '参数有误','data' => null];
|
||||
}
|
||||
$res = db::name('vs_room_auction')->where('auction_id',$auction_id)->find();
|
||||
if($res['status'] != 2){
|
||||
return ['code' => 0, 'msg' => '房间竞拍已结束','data' => null];
|
||||
}
|
||||
$res1 = db::name('vs_room_auction')->where('auction_id',$auction_id)->update(['duration' => $res['duration'] + 60]);
|
||||
if(!$res1){
|
||||
return ['code' => 0, 'msg' => '操作失败,','data' => null];
|
||||
}
|
||||
//推送消息1026
|
||||
$text = [
|
||||
'FromUserInfo' => null,
|
||||
'auction_user' => null ,
|
||||
'auction_list' => null,
|
||||
'duration'=> $res['duration'] + 60,
|
||||
'text' => '延时到'.($res['duration'] + 60).'秒'
|
||||
];
|
||||
model('api/Chat')->sendMsg(1026,$res['room_id'],$text);
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
}
|
||||
|
||||
//房间竞拍结束
|
||||
public function room_auction_end($room_id,$auction_id)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '参数有误,无房间','data' => null];
|
||||
}
|
||||
if(!$auction_id){
|
||||
//拍卖位下麦
|
||||
$host = db::name('vs_room')->where(['id' => $room_id])->value('user_id');
|
||||
model('api/RoomPit')->host_user_pit($host,$room_id,888,Cache::get('auction_user_'.$room_id),2);
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
}
|
||||
$res = db::name('vs_room_auction')->where('auction_id',$auction_id)->find();
|
||||
if(!$res){
|
||||
return ['code' => 0, 'msg' => '房间竞拍已结束','data' => null];
|
||||
}
|
||||
//获取出价列表
|
||||
$list = db::name('vs_room_auction_bid_log')->field('user_id,sum(gift_price) as gift_prices')
|
||||
->where('auction_id',$auction_id)->group('user_id')->order('gift_prices desc')->find();
|
||||
|
||||
if(!$list){
|
||||
$list_gift_prices = 0;
|
||||
}else{
|
||||
$list_gift_prices = $list['gift_prices'];
|
||||
}
|
||||
|
||||
$auction = null;
|
||||
$recipient = null;
|
||||
if($list_gift_prices < $res['gift_price']){ //流拍
|
||||
//修改竞拍状态
|
||||
$ress1 = db::name('vs_room_auction')->where('auction_id',$auction_id)->update(['status' => 3,'end_time' => time()]);
|
||||
if(!$ress1){
|
||||
return ['code' => 0, 'msg' => '操作失败','data' => null];
|
||||
}
|
||||
$texts = '很遗憾,本次竞拍未成功,请加油,下次再接再厉';
|
||||
}else{
|
||||
$cp_room_id = null;
|
||||
$auction = db::name('vs_room_auction')->alias('a')->join('user b', 'a.user_id = b.id', 'left')
|
||||
->field('a.auction_id,a.user_id,b.nickname,b.avatar,b.sex,b.user_code,a.auction_type,a.relation_id,a.gift_id,a.gift_price,a.time_day,a.duration')
|
||||
->where(['a.auction_id' => $res['auction_id']])->find();
|
||||
if($auction){
|
||||
$auction['dress'] = model('Decorate')->user_decorate_detail($auction['user_id'], 1);
|
||||
$auction['relation_name'] = db::name('vs_relation')->where('id',$auction['relation_id'])->value('name');
|
||||
$auction['relation_icon'] = db::name('vs_relation')->where('id',$auction['relation_id'])->value('icon');
|
||||
$auction['base_image'] = db::name('vs_gift')->where('gid',$auction['gift_id'])->value('base_image');
|
||||
$auction['gift_name'] = db::name('vs_gift')->where('gid',$auction['gift_id'])->value('gift_name');
|
||||
$auction['time_day'] = $auction['time_day'] / 60 / 60;
|
||||
}
|
||||
$recipient = db::name('user')->field('id as user_id,nickname,avatar,sex,user_code')->where('id',$list['user_id'])->find();
|
||||
$recipient['dress'] = model('api/Decorate')->user_decorate_detail($list['user_id'], 1);
|
||||
$recipient['user_code'] = model('api/Decorate')->user_decorate_detail($list['user_id'], 6);
|
||||
|
||||
if($res['relation_id'] != 0){
|
||||
//是否开启电影房
|
||||
$is_cp_movie = db::name('vs_relation')->where('id',$res['relation_id'])->value('is_open_movie');
|
||||
if($is_cp_movie == 1){
|
||||
//查询是否有电影房
|
||||
$cp_movie = $this->movie_room_create_or_add($list['user_id'],$res['user_id'],$res['relation_id'],$res['time_day']);
|
||||
if($cp_movie['code'] != 1){
|
||||
return ['code' => 0, 'msg'=>$cp_movie['msg'], 'data'=>$cp_movie['data']];
|
||||
}
|
||||
$cp_room_id = $cp_movie['data']['cp_room_id'];
|
||||
}
|
||||
$texts = '恭喜'.$auction['nickname'].' 和 '.$recipient['nickname'].',获得'.$auction['relation_name'].' 关系'.$auction['time_day'].'小时';
|
||||
}else{//拍得无关系
|
||||
$texts = '恭喜'.$recipient['nickname'].' 拍得 '.$auction['nickname'].'的拍卖关系'.$auction['time_day'].'小时';
|
||||
}
|
||||
|
||||
//修改竞拍状态
|
||||
$res1 = db::name('vs_room_auction')->where('auction_id',$auction_id)->update(
|
||||
[
|
||||
'status' => 3,
|
||||
'end_time' => time(),
|
||||
'bidder_user_id' => $list['user_id'],
|
||||
'auction_num' => $list['gift_prices'],
|
||||
'relation_end_time' => time() + $res['time_day'],
|
||||
'updatetime' => time(),
|
||||
'cp_room_id' => $cp_room_id
|
||||
]);
|
||||
if(!$res1){
|
||||
return ['code' => 0, 'msg' => '操作失败,','data' => null];
|
||||
}
|
||||
//关系增加时间
|
||||
$room_auction = $this->room_auction_create_or_add($list['user_id'],$res['user_id'],$res['relation_id'],$res['time_day'],$cp_room_id);
|
||||
if($room_auction['code'] != 1){
|
||||
return ['code' => 0, 'msg'=>$room_auction['msg'], 'data'=>$room_auction['data']];
|
||||
}
|
||||
}
|
||||
//拍卖位下麦
|
||||
$host = db::name('vs_room')->where(['id' => $res['room_id']])->value('user_id');
|
||||
model('api/RoomPit')->host_user_pit($host,$res['room_id'],888,$res['user_id'],2);
|
||||
|
||||
//推送消息
|
||||
$text = [
|
||||
'room_id' => $res['room_id'],
|
||||
'auction_user' => $auction,
|
||||
'recipient' => $recipient,
|
||||
'text' => $texts
|
||||
];
|
||||
model('api/Chat')->sendMsg(1025,$res['room_id'],$text);
|
||||
|
||||
//结束拍卖 右侧推空
|
||||
//推送消息
|
||||
$text = [
|
||||
'FromUserInfo' => null,
|
||||
'auction_user' => null ,
|
||||
'auction_list' => null,
|
||||
'text' => '竞拍结束'
|
||||
];
|
||||
model('api/Chat')->sendMsg(1024,$res['room_id'],$text);
|
||||
//本场心动值清0
|
||||
$roomUser = db::name('vs_room_visitor')->where(['room_id' => $res['room_id']])->select();
|
||||
if($roomUser){
|
||||
$host = db::name('vs_room')->where(['id' => $room_id])->value('user_id');
|
||||
foreach ($roomUser as $v){
|
||||
model('Room')->clear_user_charm($host, $room_id,$v['user_id']);
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
}
|
||||
|
||||
|
||||
//电影房创建或时间累加
|
||||
public function movie_room_create_or_add($user_id,$user_id1,$relation_id,$time_day){
|
||||
//查询两人是否已创建该关系的房间
|
||||
$room = db::name('vs_room_cp_movie')
|
||||
->where(['user_id' => $user_id,'user_id1' => $user_id1,'relation_id' => $relation_id])->field('cp_id,room_id,status,time_day')->order('cp_id desc')->find();
|
||||
if(!$room){
|
||||
$room = db::name('vs_room_cp_movie')
|
||||
->where(['user_id1' => $user_id,'user_id' => $user_id1,'relation_id' => $relation_id])->field('cp_id,room_id,status,time_day')->order('cp_id desc')->find();
|
||||
}
|
||||
if($room){
|
||||
if($room['status'] == 1 && $room['time_day'] > time()){
|
||||
$room_time = db::name('vs_room_cp_movie')->where('cp_id',$room['cp_id'])->setInc('time_day',$time_day);
|
||||
if(!$room_time){
|
||||
return ['code' => 0, 'msg' => 'cp电影房时间累加失败,请联系管理员','data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功,','data' => ['cp_room_id' => $room['room_id']]];
|
||||
}else{
|
||||
//销毁过期的腾讯IM的房间群组
|
||||
model('Tencent')->delete_group('room'.$room['room_id']);
|
||||
|
||||
//开启电影房
|
||||
$nickname = db::name('user')->where('id',$user_id)->value('nickname');
|
||||
$nickname1 = db::name('user')->where('id',$user_id1)->value('nickname');
|
||||
//创建房间
|
||||
$room_id = model('api/Room')->user_create_room($user_id,'的电影房',get_system_config_value('web_site').'/data/avatar/head_pic.png',$nickname.' 和 '.$nickname1.' 的Cp电影房',$user_id.$user_id1);
|
||||
if($room_id['code'] != 1){
|
||||
return ['code' => 0, 'msg' => 'cp电影房创建失败,请联系管理员','data' => null];
|
||||
}
|
||||
//添加到数据库
|
||||
$res2 = db::name('vs_room_cp_movie')->insert([
|
||||
'relation_id' => $relation_id,
|
||||
'room_id' => $room_id['data'],
|
||||
'user_id' => $user_id,
|
||||
'user_id1' => $user_id1,
|
||||
'time_day' => time() + $time_day,
|
||||
'createtime' => time(),
|
||||
'status' => 1
|
||||
]);
|
||||
if(!$res2){
|
||||
return ['code' => 0, 'msg' => '操作失败了,','data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功,','data' => ['cp_room_id' => $room_id['data']]];
|
||||
}
|
||||
}else{
|
||||
//开启电影房
|
||||
$nickname = db::name('user')->where('id',$user_id)->value('nickname');
|
||||
$nickname1 = db::name('user')->where('id',$user_id1)->value('nickname');
|
||||
//创建房间
|
||||
$room_id = model('api/Room')->user_create_room($user_id,'的电影房',get_system_config_value('web_site').'/data/avatar/head_pic.png',$nickname.' 和 '.$nickname1.' 的Cp电影房',$user_id.$user_id1);
|
||||
if($room_id['code'] != 1){
|
||||
return ['code' => 0, 'msg' => 'cp电影房创建失败,请联系管理员','data' => null];
|
||||
}
|
||||
//添加到数据库
|
||||
$res2 = db::name('vs_room_cp_movie')->insert([
|
||||
'relation_id' => $relation_id,
|
||||
'room_id' => $room_id['data'],
|
||||
'user_id' => $user_id,
|
||||
'user_id1' => $user_id1,
|
||||
'time_day' => time() + $time_day,
|
||||
'createtime' => time(),
|
||||
'status' => 1
|
||||
]);
|
||||
if(!$res2){
|
||||
return ['code' => 0, 'msg' => '操作失败了,','data' => null];
|
||||
}
|
||||
//查询拍卖者的房间
|
||||
$room_id1 = db::name('vs_room_cp_movie')->where(['user_id1' => $user_id1,'relation_id' => $relation_id,'status' => 1])
|
||||
->where(['user_id' => ['<>', $user_id]])->value('cp_id');
|
||||
if($room_id1){
|
||||
//修改房间时间
|
||||
$res3 = db::name('vs_room_cp_movie')->where('cp_id',$room_id1)->update(['status' =>4]);
|
||||
if(!$res3){
|
||||
return ['code' => 0, 'msg' => '操作失败了,','data' => null];
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功,','data' => ['cp_room_id' => $room_id['data']]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function room_auction_create_or_add($user_id,$user_id1,$relation_id,$time_day,$cp_room_id){
|
||||
//查询两人是否已创建该关系
|
||||
$room = db::name('vs_room_auction_relation')
|
||||
->where(['user_id1' => $user_id,'user_id2' => $user_id1,'relation_id' => $relation_id,'end_time'=>['>',time()]])->order('id desc')->find();
|
||||
if(!$room){
|
||||
$room = db::name('vs_room_auction_relation')
|
||||
->where(['user_id2' => $user_id,'user_id1' => $user_id1,'relation_id' => $relation_id,'end_time'=>['>',time()]])->order('id desc')->find();
|
||||
}
|
||||
if($room){
|
||||
|
||||
$data = [
|
||||
'end_time' => $room['end_time'] + $time_day,
|
||||
'time_day' => $room['time_day'] + $time_day,
|
||||
'updatetime' => time()
|
||||
];
|
||||
$room_time = db::name('vs_room_auction_relation')->where('id',$room['id'])->update($data);
|
||||
if(!$room_time){
|
||||
return ['code' => 0, 'msg' => '关系卡时间累加失败,请联系管理员','data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功,','data' => null];
|
||||
|
||||
}else{
|
||||
//添加到数据库
|
||||
$res2 = db::name('vs_room_auction_relation')->insert([
|
||||
'relation_id' => $relation_id,
|
||||
'user_id2' => $user_id,
|
||||
'user_id1' => $user_id1,
|
||||
'end_time' => time() + $time_day,
|
||||
'time_day' => $time_day,
|
||||
'updatetime' => time(),
|
||||
'cp_room_id' => $cp_room_id
|
||||
]);
|
||||
if(!$res2){
|
||||
return ['code' => 0, 'msg' => '操作失败了,','data' => null];
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '操作成功,','data' => null];
|
||||
}
|
||||
|
||||
|
||||
//房间竞拍模式
|
||||
public function room_auction_mode($room_id,$mode = 2)
|
||||
{
|
||||
if(!$room_id || !$mode){
|
||||
return ['code' => 0, 'msg' => '参数有误','data' => null];
|
||||
}
|
||||
//2亲密拍 1真爱拍
|
||||
if($mode == 2){
|
||||
$label_id = 3;
|
||||
}elseif ($mode == 1){
|
||||
$label_id = 4;
|
||||
}
|
||||
|
||||
$res = db::name('vs_room')->where('id',$room_id)->update(['label_id' => $label_id]);
|
||||
if(!$res){
|
||||
return ['code' => 0, 'msg' => '操作失败了,','data' => null];
|
||||
}
|
||||
//推送消息
|
||||
$text = [
|
||||
'room_id' => $room_id,
|
||||
'type' => $mode,
|
||||
'text' => '房间拍卖类型已修改'
|
||||
];
|
||||
model('api/Chat')->sendMsg(1027,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '操作成功,','data' => null];
|
||||
}
|
||||
}
|
||||
877
application/api/model/RoomPit.php
Normal file
877
application/api/model/RoomPit.php
Normal file
@@ -0,0 +1,877 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\controller\Push;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomPit extends Model
|
||||
{
|
||||
protected $table = 'fa_vs_room_pit';
|
||||
|
||||
//创建房间麦位
|
||||
public function create_room_pit($type,$room_id)
|
||||
{
|
||||
if($type == 2){ //K歌
|
||||
$pitnumber = 22;
|
||||
$ii = 11;
|
||||
}else{
|
||||
$pitnumber = 10;
|
||||
$ii = 1;
|
||||
}
|
||||
for ($i = $ii; $i <= $pitnumber; $i++){
|
||||
$data[] = [
|
||||
'room_id' => $room_id,
|
||||
'user_id' => 0,
|
||||
'pit_number' => $i,
|
||||
];
|
||||
}
|
||||
$reslut = $this->saveAll($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '创建失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '创建成功', 'data' => null];
|
||||
}
|
||||
|
||||
//获取房间所有的空麦位剔除一部分
|
||||
public function getRoomNullPitWithout($room_id, $not_in_pits) {
|
||||
$where['room_id'] = $room_id;
|
||||
$where['user_id'] = 0;
|
||||
$where['is_mute'] = 0;
|
||||
$where['is_lock'] = 0;
|
||||
|
||||
if ($not_in_pits) {
|
||||
$where['pit_number'] = ['not in', $not_in_pits];
|
||||
}
|
||||
|
||||
return db::name('vs_room_pit')->where($where)->order('pit_number asc')->value('pit_number');
|
||||
}
|
||||
|
||||
//用户上麦
|
||||
public function OnPit($user_id,$room_id,$pit_number)
|
||||
{
|
||||
$on = $this->where(['room_id' => $room_id, 'pit_number' => $pit_number])->update(['user_id' => $user_id]);
|
||||
if(!$on){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
// $nickname = model('User')->where(['id' => $user_id])->value('nickname');
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($user_id,1);
|
||||
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $user_id,'room_id' => $room_id])->value('charm');
|
||||
//推送告诉前端上了几号麦位
|
||||
if($pit_number == 9){
|
||||
$pit_text = '主持麦';
|
||||
//查询房间是否隐藏
|
||||
$is_hide = db::name('vs_room')->where(['id' => $room_id])->value('is_show_room');
|
||||
if($is_hide == 2){
|
||||
db::name('vs_room')->where(['id' => $room_id])->update(['is_show_room' => 1]);
|
||||
}
|
||||
}elseif ($pit_number == 10) {
|
||||
$pit_text = '嘉宾麦';
|
||||
}else{
|
||||
$pit_text = $pit_number . '号麦';
|
||||
}
|
||||
$text['text'] = $FromUserInfo['nickname'].' 上了 ' . $pit_text;
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = $pit_number;
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1003,$room_id,$text);
|
||||
if($pit_number == 9){
|
||||
//推送消息给设置此用户开播提醒的人
|
||||
$remind_users = db::name('vs_user_live_remind')->where('remind_user_id' , $user_id)->select('user_id');
|
||||
$remind_user = [];
|
||||
foreach ($remind_users as $k=>$v){
|
||||
$remind_user[$k] = 'u'.$v['user_id'];
|
||||
if($k >= 499){ //批量发单聊消息 最大数500个
|
||||
//结束整个循环
|
||||
break;
|
||||
}
|
||||
}
|
||||
$content = [
|
||||
'type' => 1,
|
||||
'roomID' => $room_id,
|
||||
'content' => '您关注的用户' . $FromUserInfo['nickname'] . '正在直播,快去围观吧!',
|
||||
];
|
||||
model('Tencent')->batchsendmsg($remind_user,json_encode($content));
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
|
||||
//用户下麦
|
||||
public function DownPit($user_id,$room_id,$pit_number)
|
||||
{
|
||||
if(!$pit_number){
|
||||
$pit_number = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id])->value('pit_number');
|
||||
if(!$pit_number){
|
||||
return ['code' => 0, 'msg' => '该用户已不在'.$pit_number.'麦', 'data' => null];
|
||||
}
|
||||
}
|
||||
$where['room_id'] = $room_id;
|
||||
$where['pit_number'] = $pit_number;
|
||||
$where['user_id'] = $user_id;
|
||||
$accept_pit_info = db::name('vs_room_pit')->where($where)->find();
|
||||
if(!$accept_pit_info){
|
||||
return ['code' => 0, 'msg' => '该用户已不在'.$pit_number.'麦', 'data' => null];
|
||||
}
|
||||
|
||||
//判断当前房间是否正在pk
|
||||
$is_pk = db::name('vs_room_pk')->where(['room_id_a' => $room_id])->where(['status' => ['in',[2,3,4]]])->value('room_id_b') ?? 0;
|
||||
if(!$is_pk){
|
||||
$is_pk = db::name('vs_room_pk')->where(['room_id_b' => $room_id])->where(['status' => ['in',[2,3,4]]])->value('room_id_a') ?? 0;
|
||||
}
|
||||
if($is_pk > 0 && $pit_number == 9){
|
||||
return ['code' => 0, 'msg' => '当前房间正在pk中', 'data' => null];
|
||||
}
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
if($pit_number == 888){
|
||||
$text['text'] = $FromUserInfo['nickname'].' 下了拍卖位 ';
|
||||
$text['type'] = 2 ;
|
||||
}else{
|
||||
if($pit_number <= 0){
|
||||
$pit_number = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id])->value('pit_number');
|
||||
}
|
||||
$down = $this->where(['room_id' => $room_id, 'user_id' => $user_id])->update(['user_id' => 0]);
|
||||
if(!$down){
|
||||
return ['code' => 0, 'msg' => '下麦失败', 'data' => null];
|
||||
}
|
||||
if($pit_number == 9){
|
||||
$pit_text = '主持麦';
|
||||
}elseif ($pit_number == 10) {
|
||||
$pit_text = '嘉宾麦';
|
||||
}else{
|
||||
$pit_text = $pit_number . '号麦';
|
||||
}
|
||||
$text['text'] = $FromUserInfo['nickname'].' 下了 ' . $pit_text;
|
||||
}
|
||||
|
||||
//推送告诉前端下了几号麦位
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = $pit_number;
|
||||
if($pit_number == 888){
|
||||
model('Chat')->sendMsg(1022,$room_id,$text);
|
||||
}else{
|
||||
model('Chat')->sendMsg(1004,$room_id,$text);
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '下麦成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//申请上麦
|
||||
public function apply_pit($user_id,$room_id,$pit_number = 0)
|
||||
{
|
||||
if($room_id <= 0){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
//查询房间状态
|
||||
$room_info = db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->field('id,room_status,room_up_pit_type,label_id')->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 0, 'msg' => '房间不存在', 'data' => null];
|
||||
}
|
||||
if($room_info['room_status'] != 1){
|
||||
return ['code' => 0, 'msg' => '房间违规或关闭', 'data' => null];
|
||||
}
|
||||
|
||||
if($pit_number == 10){
|
||||
return ['code' => 0, 'msg' => '请等待主持抱麦', 'data' => null];
|
||||
}
|
||||
|
||||
//检查是否在坑位上
|
||||
$pit_infos = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id])->field('id,pit_number')->find();
|
||||
if($pit_infos){
|
||||
return ['code' => 0, 'msg' => '您已上麦', 'data' => null];
|
||||
}
|
||||
|
||||
//自由麦
|
||||
if($room_info['room_up_pit_type'] == 2){
|
||||
if($pit_number > 0){
|
||||
//查询当前麦位是否有人
|
||||
$pit_info = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_number])->field('id,user_id,is_lock')->find();
|
||||
if($pit_info['user_id'] > 0){
|
||||
return ['code' => 0, 'msg' => '该麦位有人', 'data' => null];
|
||||
}
|
||||
//当前麦位是否正常
|
||||
if($pit_info['is_lock'] == 1){
|
||||
return ['code' => 0, 'msg' => '该麦位被锁定', 'data' => null];
|
||||
}
|
||||
if($pit_number ==9){
|
||||
//检查用户是否是房主或主持
|
||||
$is_room_owner =db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$is_room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->field('id')->find();
|
||||
if(!$is_room_owner && !$is_room_host){
|
||||
return ['code' => 0, 'msg' => '您还不是房间主持人', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
// if($room_info['label_id'] == 2){
|
||||
$pit_number = $this->getRoomNullPitWithout($room_id, [9, 10]);
|
||||
// }else{
|
||||
// $pit_number = $this->getRoomNullPitWithout($room_id, [9, 10, 11,12,13,14,15,16,17,18,19,20,21,22]);
|
||||
// }
|
||||
|
||||
if(!$pit_number){
|
||||
return ['code' => 0, 'msg' => '当前房间没有空麦位', 'data' => null];
|
||||
}
|
||||
}
|
||||
//换麦使用
|
||||
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
|
||||
//下麦
|
||||
$dow = $this ->DownPit($user_id,$room_id,$pit_infos['pit_number']);
|
||||
if($dow['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
$ompit = $this->OnPit($user_id,$room_id,$pit_number);//用户上了这个房间的几号麦位
|
||||
if($ompit['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}else{
|
||||
if($pit_number == 9){
|
||||
//检查用户是否是房主或主持
|
||||
$is_room_owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$is_room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->field('id')->find();
|
||||
//查看主持坑9坑
|
||||
$host_pit = $this->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
|
||||
if(($is_room_owner || $is_room_host) && $host_pit == 0){
|
||||
//查询用户是否在麦位上
|
||||
$is_on = $this->where(['room_id' => $room_id, 'user_id' => $user_id])->value('pit_number');
|
||||
if($is_on){
|
||||
//下麦
|
||||
$dow = $this ->DownPit($user_id,$room_id,$is_on);
|
||||
if($dow['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
//直接上主持麦
|
||||
$ont = $this->OnPit($user_id,$room_id,9);//用户上了这个房间的几号麦位
|
||||
if($ont['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
//查找是否在申请列表里
|
||||
$apply_pit = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->find();
|
||||
if($apply_pit){
|
||||
$this->clear_apply_pit_list($user_id, $room_id, $user_id);
|
||||
// db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->delete();
|
||||
// $count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
// //申请上麦推送消息
|
||||
// $text = [
|
||||
// 'text' => '申请上麦',
|
||||
// 'count' => $count
|
||||
// ];
|
||||
// model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
//检查用户是否已经申请
|
||||
$apply_pit_info = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id,'apply_type' =>1])->field('id')->find();
|
||||
if($apply_pit_info){
|
||||
return ['code' => 0, 'msg' => '请勿重复申请', 'data' => null];
|
||||
}
|
||||
|
||||
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
|
||||
return ['code' => 0, 'msg' => '用户已在麦上,请先下麦后再申请', 'data' => null];
|
||||
}
|
||||
|
||||
//放入等待区
|
||||
$data = [
|
||||
'room_id' => $room_id,
|
||||
'user_id' => $user_id,
|
||||
'status' => 0,
|
||||
'apply_type' => 1
|
||||
];
|
||||
$reslut = db::name('vs_room_pit_apply')->insert($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '申请失败', 'data' => null];
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '申请成功,请等待房主审核', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//申请上麦列表
|
||||
public function apply_pit_list($userId,$room_id)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
|
||||
$where = [
|
||||
'a.room_id' => $room_id,
|
||||
'a.status' => 0,
|
||||
];
|
||||
|
||||
// $res = model('Room')->get_room_label($room_id);
|
||||
// $room_label = $res['data']['label_id'];
|
||||
// $room_type = $res['data']['type_id'];
|
||||
// if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $where['a.apply_type'] = 1;
|
||||
// }elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $where['a.apply_type'] = 2;
|
||||
// }
|
||||
|
||||
$list['regular'] = db::name('vs_room_pit_apply')->alias('a')->join('user b','a.user_id = b.id')
|
||||
->where($where)->where('a.type',0)->field('a.user_id,a.rank_value,b.nickname,b.avatar')
|
||||
->order('a.rank_value desc')->select();
|
||||
$list['special'] = db::name('vs_room_pit_apply')->alias('a')->join('user b','a.user_id = b.id')
|
||||
->where($where)->where('a.type',1)->field('a.user_id,a.rank_value,b.nickname,b.avatar')
|
||||
->order('a.rank_value desc')->select();
|
||||
$list['gift_info'] = db::name('vs_room_pit_apply_help_gift')->where('room_id',$room_id)->find();
|
||||
if($list['gift_info']){
|
||||
$list['gift_info']['gift_name'] = db::name('vs_gift')->where('gid',$list['gift_info']['gift_id'])->value('gift_name');
|
||||
$list['gift_info']['base_image'] = db::name('vs_gift')->where('gid',$list['gift_info']['gift_id'])->value('base_image');
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//上麦助力
|
||||
public function help_apply_pit($user_id,$room_id,$apply_id)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
if(!$apply_id){
|
||||
return ['code' => 0, 'msg' => '请选择助力用户', 'data' => null];
|
||||
}
|
||||
|
||||
//查询当前房间设置的助力;礼物
|
||||
$gift_info = db::name('vs_room_pit_apply_help_gift')->where(['room_id' => $room_id])->field('id,gift_id,gift_price')->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 0, 'msg' => '当前房间没有设置助力礼物', 'data' => null];
|
||||
}
|
||||
|
||||
// $res = model('Room')->get_room_label($room_id);
|
||||
// $room_label = $res['data']['label_id'];
|
||||
// $room_type = $res['data']['type_id'];
|
||||
// if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $apply_type = 1;
|
||||
// }elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $apply_type = 2;
|
||||
// }
|
||||
|
||||
//助力
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'help_user_id' => $apply_id,
|
||||
'room_id' => $room_id,
|
||||
'rank_value' => $gift_info['gift_price'],
|
||||
// 'apply_type' => $apply_type,
|
||||
'createtime'=> time(),
|
||||
];
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
$reslut = db::name('vs_room_pit_apply_help')->insert($data);
|
||||
if(!$reslut){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '助力失败!', 'data' => null];
|
||||
}
|
||||
$apply_user = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'user_id'=>$apply_id,'status'=>0])->find();
|
||||
if(!$apply_user){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '用户已上麦或退出', 'data' => null];
|
||||
}
|
||||
$apply_data = [
|
||||
'type' => 1,
|
||||
'updatetime'=> time(),
|
||||
'rank_value'=>$apply_user['rank_value']+$gift_info['gift_price'],
|
||||
];
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['id' => $apply_user['id']])->update($apply_data);
|
||||
if(!$reslut){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '助力失败,', 'data' => null];
|
||||
}
|
||||
//当前房间主持人麦位是谁
|
||||
$room_host_id = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => 9])->value('user_id');
|
||||
if($room_host_id == 0){
|
||||
$room_host_id = db::name('vs_room')->where(['id' => $room_id])->value('user_id');
|
||||
}
|
||||
|
||||
//走送礼流程(用户,在房间中,给谁(插队上麦给当前主持人),送了什么礼物,多少个)
|
||||
$give_gift = model('GiveGift')->give_gift($user_id,$room_host_id,$gift_info['gift_id'],1,2,1,$room_id,9);
|
||||
if($give_gift['code'] != 1){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => $give_gift['msg'].'助力失败。', 'data' => null];
|
||||
}
|
||||
db::commit();
|
||||
$data = $this -> apply_pit_list($user_id,$room_id);
|
||||
|
||||
return ['code' => 1, 'msg' => '助力成功', 'data' => $data['data']];
|
||||
}
|
||||
|
||||
//同意上麦
|
||||
public function agree_pit($user_id,$room_id,$apply_id)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
if(!$apply_id){
|
||||
return ['code' => 0, 'msg' => '请选择申请用户', 'data' => null];
|
||||
}
|
||||
|
||||
$res = model('Room')->get_room_label($room_id);
|
||||
$room_label = $res['data']['label_id'];
|
||||
$room_type = $res['data']['type_id'];
|
||||
if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
$apply_type = 1;//聊天
|
||||
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
$apply_type = 2;//K歌
|
||||
}elseif($room_type == 2){
|
||||
$apply_type = 3;//拍卖
|
||||
}else{
|
||||
$apply_type = 1;//聊天
|
||||
}
|
||||
|
||||
// if($apply_type == 1){
|
||||
// //判断当前用户是否是房主或在主持麦位上的主持
|
||||
// $is_room_owner = model('Room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
// $is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id,'pit_number' => 9])->field('id')->find();
|
||||
// if(!$is_room_owner && !$is_room_host){
|
||||
// return ['code' => 0, 'msg' => '您不是房主 或 不在主持位,没有权限操作', 'data' => null];
|
||||
// }
|
||||
// }else{
|
||||
// $is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id,'pit_number' => 9])->field('id')->find();
|
||||
// if(!$is_room_host){
|
||||
// return ['code' => 0, 'msg' => '您不在主持位,没有权限操作', 'data' => null];
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$to_user = explode(',',$apply_id);
|
||||
|
||||
if(count($to_user) >= 1){
|
||||
if($apply_type == 1) {
|
||||
$i = 0;
|
||||
foreach ($to_user as &$value) {
|
||||
//查询当前空麦位
|
||||
$empty_pit = $this->getRoomNullPitWithout($room_id, [9, 10]);
|
||||
if (!$empty_pit) {
|
||||
//退出循环 并终止循环
|
||||
break;
|
||||
}
|
||||
//查询是否已经上麦
|
||||
$is_on_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $value])->field('id')->find();
|
||||
if ($is_on_pit) {
|
||||
continue;
|
||||
}
|
||||
//删除他的申请上麦
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0,'apply_type' => 1])->delete();
|
||||
if (!$reslut) {
|
||||
continue;
|
||||
}
|
||||
$on = $this->OnPit($value, $room_id, $empty_pit);//用户上了这个房间的几号麦位
|
||||
if ($on['code'] != 1) {
|
||||
continue;
|
||||
}
|
||||
$i++;
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($user_id,$room_id,8,$value,$empty_pit);
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息(数据重置)
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => $i . '位用户上麦成功', 'data' => null];
|
||||
}elseif($apply_type == 2){
|
||||
if(db::name('vs_room_pit_simulate')->where(['room_id' => $room_id])->count() >= 20){
|
||||
return ['code' => 0, 'msg' => '暂无空麦位', 'data' => null];
|
||||
}
|
||||
foreach ($to_user as &$value) {
|
||||
if(db::name('vs_room_pit_simulate')->where(['room_id' => $room_id])->count() >= 20){
|
||||
//结束循环
|
||||
break;
|
||||
}
|
||||
//删除他的申请上麦
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0,'apply_type' => 2])->delete();
|
||||
if (!$reslut) {
|
||||
continue;
|
||||
}
|
||||
$ompit = db::name('vs_room_pit_simulate')->insert(
|
||||
[
|
||||
'room_id' => $room_id,
|
||||
'user_id' => $value,
|
||||
'status' => 1,//1-K歌模式虚假上麦
|
||||
]
|
||||
);//用户上了这个房间的麦位
|
||||
if (!$ompit) {
|
||||
continue;
|
||||
}
|
||||
//聊天室推送系统消息
|
||||
$FromUserInfo = db::name('user')->where('id',$value)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($value);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($value);//魅力图标
|
||||
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($value,1);
|
||||
$text['text'] = $FromUserInfo['nickname'].' 上麦了 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = 9999;
|
||||
model('Chat')->sendMsg(1003,$room_id,$text);
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($user_id,$room_id,8,$value);
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}elseif($apply_type == 3){
|
||||
if(count($to_user) >= 2){
|
||||
return ['code' => 0, 'msg' => '拍卖模式下只能一个人上麦', 'data' => null];
|
||||
}
|
||||
//拍卖房当前到哪一步了
|
||||
$step = db::name('vs_room_auction')->where(['room_id' => $room_id])->order('auction_id desc')->value('status');
|
||||
if($step == 2){
|
||||
return ['code' => 0, 'msg' => '拍卖已经开始', 'data' => null];
|
||||
}
|
||||
//拍卖位上有人吗
|
||||
$paimai_user = Cache::get('auction_user_'.$room_id);
|
||||
if($paimai_user){
|
||||
//有人就让他下麦
|
||||
return ['code' => 0, 'msg' => '拍卖位上已有人,请先抱对方下麦', 'data' => null];
|
||||
}
|
||||
$i = 0;
|
||||
foreach ($to_user as &$value) {
|
||||
$i++;
|
||||
//删除他的申请上麦
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete();
|
||||
if (!$reslut) {
|
||||
continue;
|
||||
}
|
||||
//聊天室推送系统消息
|
||||
$FromUserInfo = db::name('user')->where('id',$value)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($value);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($value);//魅力图标
|
||||
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($value,1);
|
||||
$text['text'] = $FromUserInfo['nickname'].' 上了拍卖位 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = 888;
|
||||
$text['type'] = 1 ;
|
||||
model('Chat')->sendMsg(1022,$room_id,$text);
|
||||
Cache::set('auction_user_'.$room_id,$value);
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($user_id,$room_id,8,$value);
|
||||
if($i >= 1){
|
||||
break;
|
||||
}
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
return ['code' => 0, 'msg' => '请选择申请上麦的用户', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//清空上麦申请
|
||||
public function clear_apply_pit_list($userId,$room_id,$apply_id = 0)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
//判断当前用户是否是房主或主持
|
||||
$is_room_owner = model('Room')->where(['id' => $room_id, 'user_id' => $userId])->field('id')->find();
|
||||
$is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $userId,'pit_number' => 9])->field('id')->find();
|
||||
if(!$is_room_owner && !$is_room_host){
|
||||
return ['code' => 0, 'msg' => '您不是房主 或 不在主持麦,没有权限操作', 'data' => null];
|
||||
}
|
||||
// $res = model('Room')->get_room_label($room_id);
|
||||
// $room_label = $res['data']['label_id'];
|
||||
// $room_type = $res['data']['type_id'];
|
||||
// if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $apply_type = 1;
|
||||
// }elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $apply_type = 2;
|
||||
// }else{
|
||||
// $apply_type = 1;
|
||||
// }
|
||||
|
||||
if($apply_id){
|
||||
$to_user = explode(',',$apply_id);
|
||||
if(count($to_user) >= 1){
|
||||
foreach ($to_user as &$value){
|
||||
$where['user_id'] = $value;
|
||||
$where['room_id'] = $room_id;
|
||||
$where['status'] = 0;
|
||||
// $where['apply_type'] = $apply_type;
|
||||
db::name('vs_room_pit_apply')->where($where)->delete();
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($userId,$room_id,9,$value);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$where['room_id'] = $room_id;
|
||||
$where['status'] = 0;
|
||||
// $where['apply_type'] = $apply_type;
|
||||
db::name('vs_room_pit_apply')->where($where)->delete();
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
|
||||
//设置插麦礼物
|
||||
public function set_room_pit_apply_help_gift($user_id,$room_id,$gift_id,$gift_price)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
if(!$gift_id){
|
||||
return ['code' => 0, 'msg' => '请选择礼物', 'data' => null];
|
||||
}
|
||||
if(!$gift_price){
|
||||
$gift_price = db::name('vs_gift')->where(['gid' => $gift_id])->value('gift_price');
|
||||
}
|
||||
//判断当前用户是否是房主或在主持麦位上的主持
|
||||
$is_room_owner = model('Room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$is_room_host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id,'pit_number' => 9])->field('id')->find();
|
||||
if(!$is_room_owner && !$is_room_host){
|
||||
return ['code' => 0, 'msg' => '您不是房主 或 不在主持位,没有权限操作', 'data' => null];
|
||||
}
|
||||
$room_pit_apply_help_gift = db::name('vs_room_pit_apply_help_gift')->where(['room_id' => $room_id])->find();
|
||||
if($room_pit_apply_help_gift) {
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'gift_id' => $gift_id,
|
||||
'gift_price' => $gift_price,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
$reslut = db::name('vs_room_pit_apply_help_gift')->where(['room_id' => $room_id])->update($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'room_id' => $room_id,
|
||||
'gift_id' => $gift_id,
|
||||
'gift_price' => $gift_price,
|
||||
'createtime' => time(),
|
||||
];
|
||||
$reslut = db::name('vs_room_pit_apply_help_gift')->insert($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
|
||||
//修改房间上麦模式
|
||||
public function change_room_up_pit_type($user_id,$room_id)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
|
||||
//判断当前用户是否有权限
|
||||
$owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->find();
|
||||
if(!$owner && !$host){
|
||||
return ['code' => 0, 'msg' => '没有权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
$pit_type = db::name('vs_room')->where(['id' => $room_id])->value('room_up_pit_type');
|
||||
if($pit_type == 1){
|
||||
//房间模式
|
||||
$room_type = db::name('vs_room')->where(['id' => $room_id])->value('type_id');
|
||||
if($room_type == 2){
|
||||
return ['code' => 0, 'msg' => '房间模式下,不允许切换麦位模式', 'data' => null];
|
||||
}
|
||||
$type = 2;
|
||||
}else{
|
||||
$type = 1;
|
||||
}
|
||||
$reslut = db::name('vs_room')->where(['id' => $room_id])->update(['room_up_pit_type' => $type]);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
if($pit_type == 1){
|
||||
//申请上麦的全部下麦
|
||||
model('RoomPit')->clear_apply_pit_list($user_id, $room_id);
|
||||
}
|
||||
//推送消息给前端
|
||||
$text['room_up_pit_type'] = $type;
|
||||
model('Chat')->sendMsg(1014,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
|
||||
//抱麦
|
||||
//1-抱麦 2-踢下去
|
||||
public function host_user_pit($user_id,$room_id,$pit_number,$accept_user_id,$type)
|
||||
{
|
||||
if(!$room_id){
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
|
||||
if(!$accept_user_id){
|
||||
return ['code' => 0, 'msg' => '请选择用户', 'data' => null];
|
||||
}
|
||||
|
||||
if($type == 1){//抱麦
|
||||
$on_9_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
|
||||
if($on_9_pit <= 0){
|
||||
return ['code' => 0, 'msg' => '您暂未上主持麦位,请先上麦', 'data' => null];
|
||||
}
|
||||
if(!$pit_number){
|
||||
$room_type = db::name('vs_room')->where(['id' => $room_id])->value('type_id');
|
||||
if($room_type == 2){
|
||||
if(Cache::get('auction_user_'.$room_id)){
|
||||
return ['code' => 0, 'msg' => '拍卖位上已有人,请先抱对方下麦', 'data' => null];
|
||||
}else{
|
||||
$FromUserInfo = db::name('user')->where('id',$accept_user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('api/UserData')->user_wealth_icon($accept_user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('api/UserData')->user_charm_icon($accept_user_id);//魅力图标
|
||||
$FromUserInfo['dress'] = model('api/Decorate')->user_decorate_detail($accept_user_id,1);
|
||||
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['room_id' => $room_id, 'user_id' => $accept_user_id])->value('charm');
|
||||
//推送告诉前端上了几号麦位
|
||||
$text['text'] = $FromUserInfo['nickname'].' 上了拍卖位 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = $pit_number;
|
||||
$text['type'] = 1 ;
|
||||
//聊天室推送系统消息
|
||||
model('api/Chat')->sendMsg(1022,$room_id,$text);
|
||||
Cache::set('auction_user_'.$room_id,$accept_user_id);
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
//查询当前空麦位
|
||||
$empty_pit = $this->getRoomNullPitWithout($room_id, [9, 10]);
|
||||
if(!$empty_pit){
|
||||
return ['code' => 0, 'msg' => '没有空麦位', 'data' => null];
|
||||
}else{
|
||||
$pit_number = $empty_pit;
|
||||
}
|
||||
}else{
|
||||
if($pit_number == 888){
|
||||
$FromUserInfo = db::name('user')->where('id',$accept_user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('api/UserData')->user_wealth_icon($accept_user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('api/UserData')->user_charm_icon($accept_user_id);//魅力图标
|
||||
$FromUserInfo['dress'] = model('api/Decorate')->user_decorate_detail($accept_user_id,1);
|
||||
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['room_id' => $room_id, 'user_id' => $accept_user_id])->value('charm');
|
||||
//推送告诉前端上了几号麦位
|
||||
$text['text'] = $FromUserInfo['nickname'].' 上了拍卖位 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = $pit_number;
|
||||
$text['type'] = 1 ;
|
||||
//聊天室推送系统消息
|
||||
model('api/Chat')->sendMsg(1022,$room_id,$text);
|
||||
Cache::set('auction_user_'.$room_id,$accept_user_id);
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
//判断当前麦位是否为空
|
||||
$where['room_id'] = $room_id;
|
||||
$where['pit_number'] = $pit_number;
|
||||
$pit_user_id = db::name('vs_room_pit')->where($where)->value('user_id');
|
||||
if($pit_user_id > 0){
|
||||
return ['code' => 0, 'msg' => '麦位上有人', 'data' => null];
|
||||
}
|
||||
}
|
||||
$where['room_id'] = $room_id;
|
||||
$where['pit_number'] = $pit_number;
|
||||
$where['is_lock'] = 0;
|
||||
$pit_info = db::name('vs_room_pit')->where($where)->find();
|
||||
if(!$pit_info){
|
||||
return ['code' => 0, 'msg' => '麦位不存在或已锁麦', 'data' => null];
|
||||
}
|
||||
$where['user_id'] = $accept_user_id;
|
||||
unset($where['pit_number']);
|
||||
$accept_pit_info = db::name('vs_room_pit')->where($where)->find();
|
||||
if($accept_pit_info){
|
||||
return ['code' => 0, 'msg' => '该用户已上麦', 'data' => null];
|
||||
}
|
||||
|
||||
$onpit = $this ->OnPit($accept_user_id,$room_id,$pit_number);
|
||||
if($onpit['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
//删除申请上麦
|
||||
model('RoomPit')->clear_apply_pit_list($user_id, $room_id, $accept_user_id);
|
||||
}else{//2-踢下去
|
||||
//判断权限
|
||||
if($pit_number != 888){
|
||||
if(!model('QuanXian')->quan_xian($user_id, $accept_user_id, $room_id)){
|
||||
return ['code' => 0, 'msg' => '您没有权限操作', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if(!$pit_number || $pit_number == 888){
|
||||
$roomInfo = db::name('vs_room')->where('id',$room_id)->field('label_id,type_id')->find();
|
||||
if($roomInfo['type_id'] == 2){//拍卖
|
||||
//查询当前是否处于拍卖中
|
||||
$auctioning = db::name('vs_room_auction')
|
||||
->where(['room_id' => $room_id, 'status' => 2, 'user_id' => $accept_user_id])->find();
|
||||
if($auctioning){
|
||||
return ['code' => 0, 'msg' => '该用户正在拍卖中', 'data' => null];
|
||||
}
|
||||
//查询当前用户是否正在拍卖中
|
||||
if($pit_number == 888 && Cache::get('auction_user_'.$room_id) != $accept_user_id){
|
||||
return ['code' => 0, 'msg' => '拍卖用户不是当前操作用户', 'data' => null];
|
||||
}
|
||||
//清除缓存
|
||||
Cache::rm('auction_user_'.$room_id);
|
||||
$FromUserInfo = db::name('user')->where('id',$accept_user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($accept_user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($accept_user_id);//魅力图标
|
||||
//推送告诉前端下了几号麦位
|
||||
$text['text'] = $FromUserInfo['nickname'].' 下了拍卖位 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = $pit_number;
|
||||
$text['type'] = 2 ;
|
||||
model('api/Chat')->sendMsg(1022,$room_id,$text);
|
||||
}
|
||||
if($roomInfo['label_id'] == 2 && ($roomInfo['type_id'] == 1 || $roomInfo['type_id'] == 4 || $roomInfo['type_id'] == 3)){
|
||||
$res = model('RoomSong')->down_kpit($accept_user_id, $room_id);
|
||||
if($res['code'] != 1){
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$where['room_id'] = $room_id;
|
||||
$where['pit_number'] = $pit_number;
|
||||
$where['user_id'] = $accept_user_id;
|
||||
$accept_pit_info = db::name('vs_room_pit')->where($where)->find();
|
||||
if(!$accept_pit_info){
|
||||
return ['code' => 0, 'msg' => '该用户已不在'.$pit_number.'麦', 'data' => null];
|
||||
}
|
||||
$dow = $this ->DownPit($accept_user_id,$room_id,$pit_number);
|
||||
if($dow['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
551
application/api/model/RoomPk.php
Normal file
551
application/api/model/RoomPk.php
Normal file
@@ -0,0 +1,551 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomPk extends Model
|
||||
{
|
||||
protected $table = 'fa_vs_room_pk';
|
||||
|
||||
// 发起PK邀请 10秒不接受 自动关闭这个申请
|
||||
public function send_pk($room_id_a, $create_user_id, $room_id_b)
|
||||
{
|
||||
if(!$room_id_a || !$create_user_id ){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => ''];
|
||||
}
|
||||
//逃跑次数
|
||||
$escape_number = db::name('vs_user_pk_close')->where(['user_id' => $create_user_id, 'create_time' => ['between',[strtotime(date('Y-m-d')),time()]]])->find();
|
||||
if($escape_number){
|
||||
if($escape_number['close_num'] >= 3){
|
||||
return ['code' => 0, 'msg' => '今天pk您已中断3次,今天已不能再发起PK', 'data' => ''];
|
||||
}elseif($escape_number['close_num'] == 2){
|
||||
$second = get_system_config_value('second_close_time') * 60;//分钟转为秒
|
||||
if($escape_number['update_time'] + $second > time()){
|
||||
return ['code' => 0, 'msg' => '今天pk您已中断2次,'.$second/60 .'分钟内不能发起PK', 'data' => ''];
|
||||
}
|
||||
}elseif($escape_number['close_num'] == 1){
|
||||
$first_close = get_system_config_value('first_close_time') * 60;//分钟转为秒
|
||||
if($escape_number['update_time'] + $first_close > time()){
|
||||
return ['code' => 0, 'msg' => '今天pk您已中断1次,'.$first_close/60 .'分钟内不能发起PK', 'data' => ''];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//判断发起者是否是房间的主持
|
||||
$is_host = db::name('vs_room_host')->where('room_id', $room_id_a)->where('user_id', $create_user_id)->where(['type' => 1,'delete_time' =>null ])->find();
|
||||
$owner = db::name('vs_room')->where('id', $room_id_a)->value('user_id');
|
||||
if (!$is_host && $owner != $create_user_id) {
|
||||
return ['code' => 0, 'msg' => '您不是此房间的主持人,请联系房主', 'data' => ''];
|
||||
}
|
||||
//没有接收者
|
||||
if(!$room_id_b){
|
||||
$where = [
|
||||
'a.id' => ['<>',$room_id_a],
|
||||
'a.room_status' => 1,
|
||||
'a.apply_status' => 2,
|
||||
'a.is_pk' => 1,
|
||||
'a.is_show_room' => 1,
|
||||
'b.pit_number' => 9,
|
||||
'b.user_id' => ['<>',0],
|
||||
'a.type_id' => 1,
|
||||
'a.label_id' => 1,
|
||||
];
|
||||
$room_id_b = db::name('vs_room')->alias('a')->join('vs_room_pit b','a.id = b.room_id')
|
||||
->field('a.id as room_id,a.room_name,a.room_cover,a.room_number,b.user_id')
|
||||
->where($where)
|
||||
->orderRaw('rand()')
|
||||
->value('a.id');
|
||||
}
|
||||
if(!$room_id_b){
|
||||
return ['code' => 0, 'msg' => '暂无推荐房间可PK', 'data' => ''];
|
||||
}
|
||||
|
||||
//查看推荐是否正在pk中
|
||||
$is_pks = db::name('vs_room_pk')->where(['room_id_a' => $room_id_b,'status' => 1])->find();
|
||||
if (!$is_pks) {
|
||||
$is_pks = db::name('vs_room_pk')->where(['room_id_b' => $room_id_b,'status' => 1])->find();
|
||||
if ($is_pks) {
|
||||
return ['code' => 0, 'msg' => '此房间正在PK中,请勿重复操作!', 'data' => ''];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '此房间正在PK中,请勿重复操作!', 'data' => ''];
|
||||
}
|
||||
|
||||
//查看他是否有PK没有被拒绝和接受的
|
||||
$is_pk = db::name('vs_room_pk')->where(['room_id_a' => $room_id_a,'status' => 1])->find();
|
||||
if ($is_pk) {
|
||||
return ['code' => 0, 'msg' => '您已发起过PK,请勿重复操作!', 'data' => ''];
|
||||
}
|
||||
|
||||
//接受PK的房只有在聊天模式下接受
|
||||
$room_mode = db::name('vs_room')->where('id', $room_id_b)->field('type_id,label_id')->find();
|
||||
if ($room_mode['type_id'] != 1 || $room_mode['label_id'] != 1) {
|
||||
return ['code' => 0, 'msg' => '此房间模式不支持PK', 'data' => ''];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'room_id_a' => $room_id_a,
|
||||
'create_user_id' => $create_user_id,
|
||||
'room_id_b' => $room_id_b,
|
||||
'status' => 1,
|
||||
'createtime' => time(),
|
||||
];
|
||||
$res = $this->insertGetId($data);
|
||||
if ($res) {
|
||||
//发送消息给对方在主持麦的用户
|
||||
$SendUserName = db::name('user')->where('id', $create_user_id)->value('nickname');//发送者昵称
|
||||
$text = [
|
||||
'SendRoomId' => $room_id_a,//发起者所在房间id
|
||||
'AcceptRoomId' => $room_id_b,//接受者所在房间id
|
||||
'PkId' => $res,
|
||||
'text' => $SendUserName.'邀请您进行直播Pk,快来一起嗨!',
|
||||
];
|
||||
|
||||
model('Chat')->sendMsg(1029,$room_id_b,$text);
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($create_user_id,$room_id_a,10,0,0,$res);
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => ''];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '失败', 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 接受/拒绝 PK邀请
|
||||
public function accept_pk($pk_id ,$type,$user_id = 0)
|
||||
{
|
||||
$pk_info = db::name('vs_room_pk')->where('pk_id', $pk_id)->find();
|
||||
if($user_id == 0 && $type == 2){
|
||||
$user_id = -1;//申请倒计时结束系统拒绝
|
||||
}
|
||||
|
||||
if($type == 1){
|
||||
//逃跑次数
|
||||
$escape_number = db::name('vs_user_pk_close')->where(['user_id' => $user_id, 'create_time' => ['between',[strtotime(date('Y-m-d')),time()]]])->find();
|
||||
if($escape_number){
|
||||
if($escape_number['close_num'] >= 3){
|
||||
$text = [
|
||||
'type' => $type,
|
||||
'text' => '对方无法接受PK邀请,请重新选择PK房间!',
|
||||
];
|
||||
model('Chat')->sendMsg(1030,$pk_info['room_id_a'],$text);
|
||||
return ['code' => 0, 'msg' => '今天pk您已中断3次,今天已不能再接受PK', 'data' => ''];
|
||||
}elseif($escape_number['close_num'] == 2){
|
||||
$second = get_system_config_value('second_close_time') * 60;//分钟转为秒
|
||||
if($escape_number['update_time'] + $second > time()){
|
||||
$text = [
|
||||
'type' => $type,
|
||||
'text' => '对方无法接受PK邀请,请重新选择PK房间!',
|
||||
'user_id' => $pk_info['create_user_id'],
|
||||
];
|
||||
model('Chat')->sendMsg(1030,$pk_info['room_id_a'],$text);
|
||||
return ['code' => 0, 'msg' => '今天pk您已中断2次,'.$second/60 .'分钟内不能接受PK', 'data' => ''];
|
||||
}
|
||||
}elseif($escape_number['close_num'] == 1){
|
||||
$first_close = get_system_config_value('first_close_time') * 60;//分钟转为秒
|
||||
if($escape_number['update_time'] + $first_close > time()){
|
||||
$text = [
|
||||
'type' => $type,
|
||||
'text' => '对方无法接受PK邀请,请重新选择PK房间!',
|
||||
'user_id' => $pk_info['create_user_id'],
|
||||
];
|
||||
model('Chat')->sendMsg(1030,$pk_info['room_id_a'],$text);
|
||||
return ['code' => 0, 'msg' => '今天pk您已中断1次,'.$first_close/60 .'分钟内不能接受PK', 'data' => ''];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//判断发起方还在主持麦位吗
|
||||
$is_host = db::name('vs_room_pit')->where(['room_id' => $pk_info['room_id_a'],'pit_number' =>9])->value('user_id');
|
||||
if($is_host != $pk_info['create_user_id']){
|
||||
$this->accept_pk($pk_id,2);
|
||||
return ['code' => 0, 'msg' => '对方主持已离开,暂不能响应PK邀请', 'data' => ''];
|
||||
}
|
||||
//判断发起者是否和别人开启了pk
|
||||
$is_pk = db::name('vs_room_pk')->where(['pk_id' => ['<>',$pk_id],'room_id_a' => $pk_info['room_id_a'],'status' => ['in',[1,2,3,4]]])->find();
|
||||
$is_pk1 = db::name('vs_room_pk')->where(['pk_id' => ['<>',$pk_id],'room_id_b' => $pk_info['room_id_a'],'status' => ['in',[1,2,3,4]]])->find();
|
||||
if($is_pk || $is_pk1){
|
||||
return ['code' => 0, 'msg' => '发起方已经重新开启了PK,请重新选择PK房间!', 'data' => ''];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'receive_user_id' => $user_id,
|
||||
'status' => 2,//1-申请,2-链接中,3-PK进行中,4-已结束,5-拒绝 -6断开链接
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}else{
|
||||
$data = [
|
||||
'receive_user_id' => $user_id,
|
||||
'status' => 5,//1-申请,2-链接中,3-PK进行中,4-已结束,5-拒绝 -6断开链接
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
$res = db::name('vs_room_pk')->where('pk_id', $pk_id)->update($data);
|
||||
if ($res) {
|
||||
//修改上次的pk_room_id
|
||||
$wq = db::name('vs_room')->where('id', $pk_info['room_id_a'])->update(['last_pk_room_id' => $pk_info['room_id_b'],'updatetime' => time()]);
|
||||
if(!$wq){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改房间失败', 'data' => ''];
|
||||
}
|
||||
$we = db::name('vs_room')->where('id', $pk_info['room_id_b'])->update(['last_pk_room_id' => $pk_info['room_id_a'],'updatetime' => time()]);
|
||||
if(!$we){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改房间失败', 'data' => ''];
|
||||
}
|
||||
db::commit();
|
||||
//发送消息给对方
|
||||
if($type == 1){//1接受,2拒绝
|
||||
$texta = [
|
||||
'type' => $type,
|
||||
'room_id' => $pk_info['room_id_b'],
|
||||
'user_id' => $pk_info['create_user_id'],
|
||||
'text' => '对方接受了您的PK!',
|
||||
'pk_id' => $pk_id,
|
||||
];
|
||||
$textb = [
|
||||
'type' => $type,
|
||||
'room_id' => $pk_info['room_id_a'],
|
||||
'user_id' => $user_id,
|
||||
'text' => '接受了对方的PK!',
|
||||
'pk_id' => $pk_id,
|
||||
];
|
||||
model('Chat')->sendMsg(1030,$pk_info['room_id_a'],$texta);
|
||||
model('Chat')->sendMsg(1030,$pk_info['room_id_b'],$textb);
|
||||
}else{
|
||||
$text = [
|
||||
'type' => $type,
|
||||
'text' => '对方拒绝了您的PK邀请,请重新选择PK房间!',
|
||||
'user_id' => $pk_info['create_user_id'],
|
||||
];
|
||||
model('Chat')->sendMsg(1030,$pk_info['room_id_a'],$text);
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '成功!', 'data' => ''];
|
||||
} else {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '失败', 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 开始PK
|
||||
public function start_pk($user_id,$pk_id,$pk_times = 5)
|
||||
{
|
||||
// 判断用户是否两者的主持
|
||||
$pk_info = db::name('vs_room_pk')->where('pk_id', $pk_id)->find();
|
||||
if(!$pk_info){
|
||||
return ['code' => 0, 'msg' => '此房间不存在!', 'data' => ''];
|
||||
}
|
||||
if($pk_info['status'] == 3){
|
||||
return ['code' => 0, 'msg' => '此房间已开始PK,请勿重复操作!', 'data' => ''];
|
||||
}
|
||||
if($pk_info['status'] == 4 || $pk_info['status'] == 5 || $pk_info['status'] == 6){
|
||||
return ['code' => 0, 'msg' => '此房间已结束PK,请勿重复操作!', 'data' => ''];
|
||||
}
|
||||
|
||||
if($user_id != $pk_info['create_user_id'] && $user_id != $pk_info['receive_user_id']){
|
||||
return ['code' => 0, 'msg' => '您不是此房间的主持人,请联系房主', 'data' => ''];
|
||||
}
|
||||
$data = [
|
||||
'status' => 3,//1-申请,2-链接中,3-PK进行中,4-已结束,5-拒绝 -6断开链接
|
||||
'start_time' => time(),
|
||||
'updatetime' => time(),
|
||||
'pk_times' => $pk_times
|
||||
];
|
||||
$res = db::name('vs_room_pk')->where('pk_id', $pk_id)->update($data);
|
||||
if ($res) {
|
||||
$text = [
|
||||
'pk_end_times' => time() + $pk_times * 60,
|
||||
'text' => 'pk 开始!',
|
||||
'pk_id' => $pk_id,
|
||||
];
|
||||
model('Chat')->sendMsg(1031,$pk_info['room_id_a'],$text);
|
||||
model('Chat')->sendMsg(1031,$pk_info['room_id_b'],$text);
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => ''];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '失败', 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
//搜索 或 推荐房间列表
|
||||
public function search_pk_room($user_id,$room_id,$page,$limit)
|
||||
{
|
||||
//自己当前房间
|
||||
$room_id_a = db::name('vs_room')->where('user_id', $user_id)->value('id');
|
||||
$room_id_b = db::name('vs_room_pit')->where(['pit_number' => 9, 'user_id' => $user_id])->value('room_id') ?? 0;
|
||||
$room_id_c = [$room_id_a,$room_id_b];
|
||||
$where = [
|
||||
'a.id' => ['not in',$room_id_c],
|
||||
'a.room_status' => 1,
|
||||
'a.apply_status' => 2,
|
||||
'a.is_pk' => 1,
|
||||
'a.is_show_room' => 1,
|
||||
'b.pit_number' => 9,
|
||||
'b.user_id' => ['<>',0],
|
||||
'a.type_id' => ['in',[1,3,4]],
|
||||
'a.label_id' => 1,
|
||||
];
|
||||
|
||||
if($room_id){
|
||||
//是纯数字
|
||||
if(is_numeric($room_id)){
|
||||
$where['a.room_number'] = $room_id;
|
||||
}else{
|
||||
$where['a.room_name'] = ['like','%'.$room_id.'%'];
|
||||
}
|
||||
}
|
||||
|
||||
$list = db::name('vs_room')->alias('a')->join('vs_room_pit b','a.id = b.room_id')
|
||||
->field('a.id as room_id,a.room_name,a.room_cover,a.room_number,b.user_id')
|
||||
->where($where)
|
||||
// ->orderRaw('rand()')
|
||||
->page($page,$limit)
|
||||
->select();
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
|
||||
// pk结束
|
||||
public function end_pk($pk_id,$type = 1,$user_id = 0)
|
||||
{
|
||||
$pk_info = db::name('vs_room_pk')->where('pk_id', $pk_id)->find();
|
||||
if($type == 1){//pk结束
|
||||
$data = [
|
||||
'status' => 4,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接
|
||||
'end_time' => time(),
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}elseif($type == 2){//断开链接
|
||||
$data = [
|
||||
'status' => 6,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接
|
||||
'close_time' => time(),
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}elseif($type == 3){//中途关闭
|
||||
if($user_id == 0){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => ''];
|
||||
}else{
|
||||
//查询pk信息现在在哪个阶段
|
||||
if($pk_info['status'] == 4){
|
||||
if($pk_info['shibaifang_id'] == $user_id){
|
||||
$data = [
|
||||
'status' => 7,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接 7-败方申请断开链接',
|
||||
'close_time' => time(),
|
||||
'close_user_id' => $user_id,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}else{
|
||||
$data = [
|
||||
'status' => 6,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接
|
||||
'close_time' => time(),
|
||||
'close_user_id' => $user_id,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}
|
||||
}elseif($pk_info['status'] == 7){
|
||||
if($pk_info['shibaifang_id'] != $user_id){
|
||||
$data = [
|
||||
'status' => 6,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接
|
||||
'close_time' => time(),
|
||||
];
|
||||
}
|
||||
$data['updatetime'] = time();
|
||||
}elseif ($pk_info['status'] == 2){
|
||||
$data = [
|
||||
'status' => 6,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接
|
||||
'close_time' => time(),
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}
|
||||
else{
|
||||
$data['end_time'] = time();
|
||||
//今天逃跑次数
|
||||
$where = [
|
||||
'create_time' => ['between',[strtotime(date('Y-m-d')),time()]],
|
||||
'user_id' => $user_id,
|
||||
];
|
||||
$close = db::name('vs_user_pk_close')->where($where)->find();
|
||||
if($close){
|
||||
db::name('vs_user_pk_close')->where($where)->update(
|
||||
['update_time' => time(),
|
||||
'pk_id' => $close['pk_id'].','.$pk_id,
|
||||
'close_num' => $close['close_num'] + 1
|
||||
]);
|
||||
}else{
|
||||
db::name('vs_user_pk_close')->insert(
|
||||
['user_id' => $user_id,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
'pk_id' => $pk_id,
|
||||
'close_num' => 1
|
||||
]);
|
||||
}
|
||||
$data = [
|
||||
'status' => 6,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接
|
||||
'close_time' => time(),
|
||||
'close_user_id' => $user_id,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$data = [
|
||||
'status' => 6,//1-申请,2-链接中,3-PK进行中,4-已结束(惩罚阶段),5-拒绝 -6断开链接
|
||||
'close_time' => time(),
|
||||
'close_user_id' => $user_id,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
$res = db::name('vs_room_pk')->where('pk_id', $pk_id)->update($data);
|
||||
$pk_info = db::name('vs_room_pk')->where('pk_id', $pk_id)->find(); //这个不要删除是为了更新下面的$pk_info['end_time']
|
||||
if ($res) {
|
||||
if($type == 1){//1-pk结束,2-断开链接,3-中途关闭
|
||||
if($pk_info['create_value_a'] > $pk_info['receive_value_b']){
|
||||
db::name('vs_room_pk')->where('pk_id', $pk_id)->update(['shibaifang_id' => $pk_info['receive_user_id']]);
|
||||
$texta = [
|
||||
'type' => 1,//胜利
|
||||
'victory_name' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_name'),
|
||||
'victory_cover' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_cover'),
|
||||
'defeated_name' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_name'),
|
||||
'defeated_cover' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_cover'),
|
||||
'text' => 'pk 结束!',
|
||||
'end_time' => $pk_info['end_time'] + 300,
|
||||
];
|
||||
$textb = [
|
||||
'type' => 0,//失败
|
||||
'victory_name' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_name'),
|
||||
'victory_cover' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_cover'),
|
||||
'defeated_name' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_name'),
|
||||
'defeated_cover' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_cover'),
|
||||
'text' => 'pk 结束!',
|
||||
'end_time' => $pk_info['end_time'] + 300,
|
||||
];
|
||||
model('Chat')->sendMsg(1032,$pk_info['room_id_a'],$texta);
|
||||
model('Chat')->sendMsg(1032,$pk_info['room_id_b'],$textb);
|
||||
}elseif($pk_info['create_value_a'] < $pk_info['receive_value_b']){
|
||||
db::name('vs_room_pk')->where('pk_id', $pk_id)->update(['shibaifang_id' => $pk_info['create_user_id']]);
|
||||
$texta = [
|
||||
'type' => 0,//失败
|
||||
'victory_name' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_name'),
|
||||
'victory_cover' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_cover'),
|
||||
'defeated_name' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_name'),
|
||||
'defeated_cover' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_cover'),
|
||||
'text' => 'pk 结束!',
|
||||
'end_time' => $pk_info['end_time'] + 300,
|
||||
];
|
||||
$textb = [
|
||||
'type' => 1,//胜利
|
||||
'victory_name' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_name'),
|
||||
'victory_cover' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_cover'),
|
||||
'defeated_name' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_name'),
|
||||
'defeated_cover' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_cover'),
|
||||
'text' => 'pk 结束!',
|
||||
'end_time' => $pk_info['end_time'] + 300,
|
||||
];
|
||||
model('Chat')->sendMsg(1032,$pk_info['room_id_a'],$texta);
|
||||
model('Chat')->sendMsg(1032,$pk_info['room_id_b'],$textb);
|
||||
}else{
|
||||
db::name('vs_room_pk')->where('pk_id', $pk_id)->update(['shibaifang_id' => -1]);
|
||||
$texta = [
|
||||
'type' => 2,//失败
|
||||
'victory_name' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_name'),
|
||||
'victory_cover' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_cover'),
|
||||
'defeated_name' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_name'),
|
||||
'defeated_cover' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_cover'),
|
||||
'text' => 'pk 结束!',
|
||||
'end_time' => $pk_info['end_time'] + 300,
|
||||
];
|
||||
$textb = [
|
||||
'type' => 2,//胜利
|
||||
'victory_name' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_name'),
|
||||
'victory_cover' => db::name('vs_room')->where('id', $pk_info['room_id_b'])->value('room_cover'),
|
||||
'defeated_name' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_name'),
|
||||
'defeated_cover' => db::name('vs_room')->where('id', $pk_info['room_id_a'])->value('room_cover'),
|
||||
'text' => 'pk 结束!',
|
||||
'end_time' => $pk_info['end_time'] + 300,
|
||||
];
|
||||
|
||||
model('Chat')->sendMsg(1032,$pk_info['room_id_a'],$texta);
|
||||
model('Chat')->sendMsg(1032,$pk_info['room_id_b'],$textb);
|
||||
}
|
||||
|
||||
}elseif($type == 2){
|
||||
$text = [
|
||||
'type' => 1,//正常断开
|
||||
'text' => 'pk结束,已断开链接!',
|
||||
];
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_a'],$text);
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_b'],$text);
|
||||
}elseif($type == 3){
|
||||
if($pk_info['status'] == 7){
|
||||
if($pk_info['shibaifang_id'] == $user_id){
|
||||
if($user_id == $pk_info['create_user_id']){
|
||||
$pk_room_id = $pk_info['room_id_b'];
|
||||
}elseif($user_id == $pk_info['receive_user_id']){
|
||||
$pk_room_id = $pk_info['room_id_a'];
|
||||
}else{
|
||||
return json(['code' => 0,'msg' => '您不是本场PK的对手!']);
|
||||
}
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'text' => '对方申请提前结束PK!',
|
||||
];
|
||||
model('Chat')->sendMsg(1037,$pk_room_id,$text);
|
||||
}
|
||||
}else if($pk_info['status'] == 6){
|
||||
$text = [
|
||||
'type' => 1,//正常断开
|
||||
'text' => 'pk结束,已断开链接!',
|
||||
];
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_a'],$text);
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_b'],$text);
|
||||
}
|
||||
else{
|
||||
$text = [
|
||||
'type' => 2,//中途中断
|
||||
'text' => '本场PK由于中途断开,不计输赢!',
|
||||
];
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_a'],$text);
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_b'],$text);
|
||||
}
|
||||
}else{
|
||||
$text = [
|
||||
'type' => 3,//没开始结束关闭
|
||||
'text' => 'pk结束,已关闭!',
|
||||
];
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_a'],$text);
|
||||
model('Chat')->sendMsg(1033,$pk_info['room_id_b'],$text);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => ''];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '失败', 'data' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
//不接受 PK
|
||||
public function refuse_pk($is_pk, $room_id)
|
||||
{
|
||||
$is_pks = db::name('vs_room')->where('id', $room_id)->value('is_pk');
|
||||
if ($is_pk == $is_pks) {
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => ''];
|
||||
}else{
|
||||
$data = [
|
||||
'is_pk' => $is_pk,
|
||||
];
|
||||
$res = db::name('vs_room')->where('id', $room_id)->update($data);
|
||||
if ($res) {
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => ''];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '失败', 'data' => ''];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
649
application/api/model/RoomSong.php
Normal file
649
application/api/model/RoomSong.php
Normal file
@@ -0,0 +1,649 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\Cache;
|
||||
|
||||
class RoomSong extends Model
|
||||
{
|
||||
protected $name = 'vs_room_song';
|
||||
|
||||
//申请点歌模式
|
||||
public function apply_song($uid,$room_id){
|
||||
if(!$room_id){
|
||||
return ['code'=>0,'msg'=>'请选择房间','data'=>null];
|
||||
}
|
||||
//查找当房间的主持麦有无主持
|
||||
$host_id = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => 9])->value('user_id');
|
||||
if($host_id <= 0){
|
||||
return ['code'=>0,'msg'=>'当前暂无主持人!,不能申请点歌!','data'=>null];
|
||||
}
|
||||
//查询当前房间是否在PK中
|
||||
$is_pk = db::name('vs_room_pk')->where(['room_id_a' => $room_id])->where(['status' => ['in',[2,3,4,7]]])
|
||||
->field('pk_id')->find();
|
||||
if(!$is_pk){
|
||||
$is_pk = db::name('vs_room_pk')->where(['room_id_b' => $room_id])->where(['status' => ['in',[2,3,4,7]]])
|
||||
->field('pk_id')->find();
|
||||
}
|
||||
if($is_pk){
|
||||
return ['code'=>0,'msg'=>'当前房间PK中!不能申请点歌!','data'=>null];
|
||||
}
|
||||
//查询当前房间的状态 点歌状态:1-等待点歌申请,2-申请中,3-点歌中 4-拒绝'
|
||||
$room_status = db::name('vs_room')->where('id',$room_id)->value('is_song');
|
||||
if($room_status == 1 || $room_status == 4){
|
||||
$res = db::name('vs_room')->where('id',$room_id)->update(['is_song' => 2]);
|
||||
//缓存申请时间
|
||||
Cache::set('apply_song_time_'.$room_id,time());
|
||||
//缓存申请用户
|
||||
Cache::set('apply_song_user_'.$room_id,$uid);
|
||||
if(!$res){
|
||||
return ['code'=>0,'msg'=>'申请失败!','data'=>null];
|
||||
}
|
||||
//推送消息
|
||||
$FromUserInfo = db::name('user')->where('id',$uid)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'action' => 1 //申请点歌
|
||||
];
|
||||
model('Chat')->sendMsg(1013,$room_id,$text);
|
||||
return ['code'=>1,'msg'=>'申请成功!等待主持同意!','data'=>null];
|
||||
}elseif($room_status == 2){
|
||||
//获取申请时间
|
||||
$apply_song_time = Cache::get('apply_song_time_'.$room_id);
|
||||
if(time() - $apply_song_time > 20){
|
||||
//修改房间状态
|
||||
$res = db::name('vs_room')->where('id',$room_id)->update(['is_song' => 1]);
|
||||
if(!$res){
|
||||
return ['code'=>0,'msg'=>'操作失败!','data'=>null];
|
||||
}
|
||||
//拒绝上一次的申请
|
||||
//获取上次申请用户
|
||||
$apply_song_user = Cache::get('apply_song_user_'.$room_id);
|
||||
if($apply_song_user != $uid){
|
||||
$FromUserInfo = db::name('user')->where('id',$apply_song_user)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'action' => 4 //拒绝申请点歌
|
||||
];
|
||||
model('Chat')->sendMsg(1013,$room_id,$text);
|
||||
}
|
||||
|
||||
$this->apply_song($uid,$room_id);
|
||||
}else{
|
||||
return ['code'=>1,'msg'=>'已经申请,等待主持同意!','data'=>null];
|
||||
}
|
||||
}else{
|
||||
return ['code'=>0,'msg'=>'点歌中!请稍后再试!','data'=>null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//同意点歌
|
||||
public function agree_song($user_id,$room_id,$type){
|
||||
//判断用户是否在主持麦
|
||||
$host_id = db::name('vs_room_pit')->where(['room_id' => $room_id,'user_id' => $user_id])->value('pit_number');
|
||||
if($host_id != 9){
|
||||
return ['code'=>0,'msg'=>'您不在主持麦,不能操作!','data'=>null];
|
||||
}
|
||||
$res1 = db::name('vs_room')->where('id',$room_id)->where(['label_id'=>2,'is_song'=>3])->find();
|
||||
if($res1){
|
||||
return ['code'=>0,'msg'=>'点歌中!请稍后再试!','data'=>null];
|
||||
}
|
||||
if($type == 1){//1同意 2拒绝
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
$res2 = db::name('vs_room')->where('id',$room_id)->field('room_up_pit_type')->find();
|
||||
if($res2['room_up_pit_type'] == 2){
|
||||
$data['room_up_pit_type'] = 1;
|
||||
}
|
||||
//修改房间label
|
||||
$data['label_id'] = 2;
|
||||
$data['is_song'] = 3;
|
||||
$res = db::name('vs_room')->where('id',$room_id)->update($data);
|
||||
if(!$res){
|
||||
db::rollback();
|
||||
return ['code'=>0,'msg'=>'操作失败,','data'=>null];
|
||||
}
|
||||
|
||||
$roomPit = db::name('vs_room_pit')->where(['room_id' => $room_id])
|
||||
->where('pit_number','<',9)
|
||||
->where('user_id','>',0)->select();
|
||||
if(!empty($roomPit)){
|
||||
foreach ($roomPit as $k=>$v){
|
||||
model('RoomPit')->DownPit($v['user_id'],$room_id,$v['pit_number']);
|
||||
}
|
||||
}
|
||||
|
||||
//获取房间麦位
|
||||
// $roomPit = db::name('vs_room_pit')->where(['room_id' => $room_id])->count();
|
||||
// if($roomPit == 10){
|
||||
// //麦位增加到22个
|
||||
// $add_pit = model('RoomPit')->create_room_pit(2,$room_id);
|
||||
// if($add_pit['code'] == 0){
|
||||
// Db::rollback();
|
||||
// return ['code' => 0, 'msg' => '操作失败了', 'data' => null];
|
||||
// }
|
||||
// }elseif($roomPit == 22){
|
||||
// //开启11-22麦位
|
||||
// $pit_up = db::name('vs_room_pit')->where(['room_id' => $room_id])
|
||||
// ->where('pit_number','>',10)
|
||||
// ->update(['status'=>1]);
|
||||
// if(!$pit_up){
|
||||
// Db::rollback();
|
||||
// return ['code' => 0, 'msg' => '操作失败了.', 'data' => null];
|
||||
// }
|
||||
// }
|
||||
|
||||
db::commit();
|
||||
//推送消息
|
||||
$text = [
|
||||
'text' => '房间类型变成k歌--2'
|
||||
];
|
||||
model('Chat')->sendMsg(1012,$room_id,$text);
|
||||
}else{
|
||||
$res = db::name('vs_room')->where('id',$room_id)->update(['is_song'=>4]);
|
||||
if(!$res){
|
||||
return ['code'=>0,'msg'=>'操作失败','data'=>null];
|
||||
}
|
||||
//推送消息
|
||||
$uid = Cache::get('apply_song_user_'.$room_id);
|
||||
if($uid){
|
||||
$FromUserInfo = db::name('user')->where('id',$uid)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'action' => 4 //拒绝申请点歌
|
||||
];
|
||||
model('Chat')->sendMsg(1013,$room_id,$text);
|
||||
}
|
||||
}
|
||||
//删除申请缓存
|
||||
Cache::rm('apply_song_time_'.$room_id);
|
||||
Cache::rm('apply_song_user_'.$room_id);
|
||||
return ['code'=>1,'msg'=>'操作成功','data'=>null];
|
||||
}
|
||||
|
||||
|
||||
//点歌
|
||||
public function song($room_id,$user_id,$song_code,$song_name,$singer,$poster,$duration){
|
||||
$action = 0;//初始值,1-申请点歌,2-切歌,3-下一首歌曲变化,4-拒绝申请点歌
|
||||
//查询当前房间中的场次状态
|
||||
$times_status = db::name('vs_room_song')->where('room_id',$room_id)->field('times,times_status')->order('did desc')->find();
|
||||
if(!empty($times_status)){//已经有歌曲
|
||||
if($times_status['times_status'] == 2){//这一场次结束了
|
||||
$data['sort'] = 10000;//排序,新场次第一首歌
|
||||
$data['times'] = $times_status['times'] + 1;//新场次
|
||||
//本场次无歌曲
|
||||
$action = 2;//走切歌,当前要唱的歌
|
||||
}else{//正在进行中
|
||||
$data['times'] = $times_status['times'];
|
||||
//获取当前进行中的 最后一位歌曲
|
||||
$qq = db::name('vs_room_song')
|
||||
->where('room_id',$room_id)
|
||||
->where('times',$times_status['times'])
|
||||
->field('sort,status')->order('sort asc')->find();
|
||||
$data['sort'] = $qq['sort'] - 100;
|
||||
|
||||
//查询本场次本次点歌是否等待位第一首(也是就是本场次的第二首歌)
|
||||
$song_status = db::name('vs_room_song')
|
||||
->where('room_id',$room_id)
|
||||
->where('times',$times_status['times'])
|
||||
->where('status',1)//待唱
|
||||
->order('sort desc')->select();
|
||||
$nowSong = db::name('vs_room_song') ->where('room_id',$room_id)
|
||||
->where('times',$times_status['times'])
|
||||
->where('status',2)
|
||||
->find();
|
||||
if(empty($song_status) && $nowSong){//本场次无待唱歌曲,本此点歌是下一首播放歌曲
|
||||
$action = 3;//下一首歌曲有变化,推送给前端
|
||||
}elseif(empty($song_status) && empty($nowSong)){
|
||||
$action = 2;
|
||||
}
|
||||
}
|
||||
}else{//没有歌曲,新场次
|
||||
$data['sort'] = 10000;
|
||||
$data['times'] = 1;//本房间第一场
|
||||
$action = 2;//走切歌,当前要唱的歌
|
||||
}
|
||||
|
||||
$data['room_id'] = $room_id;
|
||||
$data['user_id'] = $user_id;
|
||||
|
||||
$data['song_code'] = $song_code;
|
||||
$data['song_name'] = $song_name;
|
||||
$data['singer'] = $singer;
|
||||
$data['poster'] = $poster;
|
||||
$data['duration'] = $duration;
|
||||
if($action == 2){//切歌 当前歌曲为正要唱的歌
|
||||
$data['status'] = 2;//把当前歌曲设为演唱中
|
||||
}else{
|
||||
$data['status'] = 1;//放入等待区
|
||||
}
|
||||
|
||||
$data['times_status'] = 1;
|
||||
$data['createtime'] = time();
|
||||
$res = db::name('vs_room_song')->insertGetId($data,false,'did');
|
||||
$did = $res;
|
||||
if(!$res){
|
||||
return ['code'=>0,'msg'=>'申请失败','data'=>null];
|
||||
}
|
||||
//房间中待唱歌曲总数
|
||||
$total = db::name('vs_room_song')
|
||||
->where(['room_id' => $room_id,'status' => 1,'times_status' => 1])
|
||||
->count();
|
||||
|
||||
$info = [
|
||||
'did' => $did,
|
||||
'song_code' => $song_code,
|
||||
'song_name' => $song_name,
|
||||
'singer' => $singer,
|
||||
'poster' => $poster,
|
||||
'duration' => $duration,
|
||||
'user_id' => $user_id,
|
||||
'dress' => model('Decorate')->user_decorate_detail($user_id, 1),
|
||||
'nickname' => db::name('user')->where('id',$user_id)->value('nickname'),
|
||||
'avatar' => db::name('user')->where('id',$user_id)->value('avatar'),
|
||||
'charm' => db::name('vs_room_user_charm')->where(['user_id' =>$user_id,'room_id' => $room_id])->value('charm'),
|
||||
];
|
||||
$nowInfo = null;
|
||||
$nextInfo = null;
|
||||
if($action == 2){//切歌 应该播放的歌曲推给前端
|
||||
$nowInfo = $info;
|
||||
}elseif ($action == 3){//下一首变化后 推给前端做预加载歌词
|
||||
$nextInfo = $info;
|
||||
//把这个信息存储到redis
|
||||
Cache::set("api:room:song:nextInfo:" . $room_id, $did);
|
||||
}
|
||||
$text = [
|
||||
'action' => $action,
|
||||
'total' => $total,
|
||||
'songInfo' => $nowInfo,
|
||||
'nextInfo' => $nextInfo
|
||||
];
|
||||
model('Chat')->sendMsg(1013,$room_id,$text);
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($user_id,$room_id,10,0,0,$did);
|
||||
return ['code'=>1,'msg'=>'申请成功','data'=>null];
|
||||
}
|
||||
|
||||
//已点歌曲列表
|
||||
public function song_list($room_id){
|
||||
$list = db::name('vs_room_song')
|
||||
->field('did,room_id,song_code,song_name,singer,poster,duration,sort,user_id')
|
||||
->where(['room_id' => $room_id,'status' => 1,'times_status' => 1])
|
||||
->order('sort desc')->select();
|
||||
if($list){
|
||||
foreach ($list as &$v){
|
||||
$v['nickname'] = db::name('user')->where('id',$v['user_id'])->value('nickname');
|
||||
$v['avatar'] = db::name('user')->where('id',$v['user_id'])->value('avatar');
|
||||
$v['dress'] = model('Decorate')->user_decorate_detail($v['user_id'], 1);
|
||||
}
|
||||
}
|
||||
return ['code'=>1,'msg'=>'操作成功','data'=>$list];
|
||||
}
|
||||
|
||||
|
||||
//上移歌 $type 1上移 2置顶
|
||||
public function up_song($room_song_id,$type=1){
|
||||
//查询当前数据的信息
|
||||
$sort = db::name('vs_room_song')->where('did',$room_song_id)->field('room_id,sort,times')->find();
|
||||
//根据房间ID查询当前房间中正在排序的歌曲 并获取当前排序的前一位的ID
|
||||
$sort_up = db::name('vs_room_song')->where(['room_id' => $sort['room_id'],'status' => 1,'times' =>$sort['times'],'times_status' => 1])->field('did')->order('sort desc')->select();
|
||||
if($sort_up[0]['did'] == $room_song_id){
|
||||
return ['code'=>0,'msg'=>'已经是第一首歌了','data'=>null];
|
||||
}
|
||||
if($type == 1){ //上移
|
||||
foreach ($sort_up as $k=>$v){
|
||||
if($v['did'] == $room_song_id){
|
||||
$sort_ups = $sort_up[$k-1]['did'];
|
||||
}
|
||||
}
|
||||
$fa_zhi = 0;
|
||||
}else{ //置顶
|
||||
foreach ($sort_up as $k=>$v){
|
||||
$sort_ups = $sort_up[0]['did'];
|
||||
}
|
||||
$fa_zhi = 9;//阈值 为了防止置顶后被上移歌曲覆盖
|
||||
}
|
||||
$sortt = db::name('vs_room_song')->where('did',$sort_ups)->value('sort');
|
||||
$sort_upp = $sortt + 1 + $fa_zhi;
|
||||
$res = db::name('vs_room_song')->where('did',$room_song_id)->update(['sort'=>$sort_upp]);
|
||||
if(!$res){
|
||||
return ['code'=>0,'msg'=>'操作失败','data'=>null];
|
||||
}
|
||||
$data = db::name('vs_room_song')->where(['room_id' => $sort['room_id'],'status' => 1,'times' =>$sort['times'],'times_status' => 1])
|
||||
->order('sort desc')->select();
|
||||
$did = Cache::get("api:room:song:nextInfo:" . $sort['room_id']);
|
||||
//歌曲移动后,下一首播放歌曲信息 发生改变 推送给前端
|
||||
if($data[0]['did'] != $did){
|
||||
$total = db::name('vs_room_song')
|
||||
->where(['room_id' => $sort['room_id'],'status' => 1,'times_status' => 1])
|
||||
->count();
|
||||
$info = [
|
||||
'did' => $data[0]['did'],
|
||||
'song_code' => $data[0]['song_code'],
|
||||
'song_name' => $data[0]['song_name'],
|
||||
'singer' => $data[0]['singer'],
|
||||
'poster' => $data[0]['poster'],
|
||||
'duration' => $data[0]['duration'],
|
||||
'user_id' => $data[0]['user_id'],
|
||||
'dress' => model('Decorate')->user_decorate_detail($data[0]['user_id'], 1),
|
||||
'nickname' => db::name('user')->where('id',$data[0]['user_id'])->value('nickname'),
|
||||
'avatar' => db::name('user')->where('id',$data[0]['user_id'])->value('avatar'),
|
||||
'charm' => db::name('vs_room_user_charm')->where(['user_id' => $data[0]['user_id'],'room_id' => $sort['room_id']])->value('charm'),
|
||||
];
|
||||
$text = [
|
||||
'action' => 3,//下一首播放歌曲信息推送给前端
|
||||
'total' => $total,
|
||||
'songInfo' => null,
|
||||
'nextInfo' => $info
|
||||
];
|
||||
model('Chat')->sendMsg(1013,$sort['room_id'],$text);
|
||||
Cache::set("api:room:song:nextInfo:" . $sort['room_id'],$data[0]['did']);
|
||||
}
|
||||
return ['code'=>1,'msg'=>'操作成功','data'=>$data];
|
||||
}
|
||||
|
||||
//切歌
|
||||
public function change_song($room_id,$now_room_song_id){
|
||||
//根据传过来的参数查询当前场次
|
||||
$times = db::name('vs_room_song')->where('did',$now_room_song_id)->value('times');
|
||||
//查询下一首歌曲
|
||||
$data = db::name('vs_room_song')->where(['room_id' => $room_id,'status' => 1,'times' =>$times,'times_status' => 1])
|
||||
->order('sort desc')->select();
|
||||
//结束本首歌
|
||||
$now_song = db::name('vs_room_song')->where('did',$now_room_song_id)->update(['status'=>3]);
|
||||
if(empty($data)){
|
||||
Cache::rm("api:room:song:nextInfo:" . $room_id);
|
||||
$text = [
|
||||
'action' => 2,
|
||||
'total' => 0,
|
||||
'songInfo' => null,
|
||||
'nextInfo' => null
|
||||
];
|
||||
model('Chat')->sendMsg(1013,$room_id,$text);
|
||||
return ['code'=>0,'msg'=>'已经是最后一首歌了','data'=>null];
|
||||
}
|
||||
$total = db::name('vs_room_song')
|
||||
->where(['room_id' => $room_id,'status' => 1,'times' =>$times,'times_status' => 1])
|
||||
->count();
|
||||
|
||||
//修改 准备唱的歌曲状态
|
||||
$next_song = db::name('vs_room_song')->where('did',$data[0]['did'])->update(['status' => 2]);
|
||||
if(!$now_song || !$next_song){
|
||||
return ['code'=>0,'msg'=>'切歌失败','data'=>null];
|
||||
}
|
||||
if(array_count_dim($data) > 1){
|
||||
//有两首以上的歌曲 第二首放入 推送的下一首中
|
||||
$next_song_info = [
|
||||
'did' => $data[1]['did'],
|
||||
'song_code' => $data[1]['song_code'],
|
||||
'song_name' => $data[1]['song_name'],
|
||||
'singer' => $data[1]['singer'],
|
||||
'poster' => $data[1]['poster'],
|
||||
'duration' => $data[1]['duration'],
|
||||
'user_id' => $data[1]['user_id'],
|
||||
'dress' => model('Decorate')->user_decorate_detail($data[1]['user_id'], 1),
|
||||
'nickname' => db::name('user')->where('id',$data[1]['user_id'])->value('nickname'),
|
||||
'avatar' => db::name('user')->where('id',$data[1]['user_id'])->value('avatar'),
|
||||
'charm' => db::name('vs_room_user_charm')->where(['user_id' =>$data[1]['user_id'],'room_id' => $room_id])->value('charm'),
|
||||
];
|
||||
//缓存
|
||||
Cache::set("api:room:song:nextInfo:" . $room_id,$data[1]['did']);
|
||||
}else{
|
||||
//一首歌曲 推送下一首没有
|
||||
$next_song_info = null;
|
||||
}
|
||||
|
||||
$text = [
|
||||
'action' => 2,
|
||||
'total' => $total,
|
||||
'songInfo' => [
|
||||
'did' => $data[0]['did'],
|
||||
'song_code' => $data[0]['song_code'],
|
||||
'song_name' => $data[0]['song_name'],
|
||||
'singer' => $data[0]['singer'],
|
||||
'poster' => $data[0]['poster'],
|
||||
'duration' => $data[0]['duration'],
|
||||
'user_id' => $data[0]['user_id'],
|
||||
'dress' => model('Decorate')->user_decorate_detail($data[0]['user_id'], 1),
|
||||
'nickname' => db::name('user')->where('id',$data[0]['user_id'])->value('nickname'),
|
||||
'avatar' => db::name('user')->where('id',$data[0]['user_id'])->value('avatar'),
|
||||
'charm' => db::name('vs_room_user_charm')->where(['user_id' =>$data[0]['user_id'],'room_id' => $room_id])->value('charm'),
|
||||
],
|
||||
'nextInfo' => $next_song_info
|
||||
];
|
||||
model('Chat')->sendMsg(1013,$room_id,$text);
|
||||
return ['code'=>1,'msg'=>'切歌成功','data'=>null];
|
||||
}
|
||||
|
||||
//结束本场唱歌
|
||||
public function end_song($room_id){
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
//本场次结束
|
||||
db::name('vs_room_song')->where(['room_id' => $room_id,'times_status' => 1,'status' => 1])->update(['status'=>4]);
|
||||
if(db::name('vs_room_song')->where(['room_id' => $room_id,'times_status' => 1,'status' => 2])->find()){
|
||||
db::name('vs_room_song')->where(['room_id' => $room_id,'times_status' => 1,'status' => 2])->update(['status'=>3]);
|
||||
}
|
||||
if(db::name('vs_room_song')->where('room_id',$room_id)->where(['times_status'=>1])->find()){
|
||||
$times_status = db::name('vs_room_song')->where('room_id',$room_id)->update(['times_status'=>2]);
|
||||
if(!$times_status){
|
||||
db::rollback();
|
||||
return ['code'=>0,'msg'=>'操作失败!','data'=>null];
|
||||
}
|
||||
}
|
||||
|
||||
//修改房间类型
|
||||
//修改房间label
|
||||
$res = db::name('vs_room')->where('id',$room_id)->update(['label_id'=>1,'is_song'=>1]);
|
||||
if(!$res){
|
||||
db::rollback();
|
||||
return ['code'=>0,'msg'=>'操作失败','data'=>null];
|
||||
}
|
||||
|
||||
//关闭11-22麦位
|
||||
// $pit_up = db::name('vs_room_pit')->where(['room_id' => $room_id])
|
||||
// ->where('pit_number','>',10)
|
||||
// ->update(['status'=>2]);
|
||||
// if(!$pit_up){
|
||||
// Db::rollback();
|
||||
// return ['code' => 0, 'msg' => '操作失败了.', 'data' => null];
|
||||
// }
|
||||
$roomPit = db::name('vs_room_pit')->where(['room_id' => $room_id])
|
||||
->where('pit_number','<',9)
|
||||
->where('pit_number','>',10)
|
||||
->where('user_id','>',0)->select();
|
||||
if(!empty($roomPit)){
|
||||
foreach ($roomPit as $k=>$v){
|
||||
model('RoomPit')->DownPit($v['user_id'],$room_id,$v['pit_number']);
|
||||
}
|
||||
}
|
||||
db::name('vs_room_pit_simulate')->where(['room_id' => $room_id])->delete();
|
||||
//推送消息
|
||||
$text = [
|
||||
'text' => '房间类型变成聊天--1'
|
||||
];
|
||||
model('Chat')->sendMsg(1012,$room_id,$text);
|
||||
Cache::rm("api:room:song:nextInfo:" . $room_id);
|
||||
db::commit();
|
||||
return ['code'=>1,'msg'=>'操作成功','data'=>null];
|
||||
}
|
||||
|
||||
//申请上麦
|
||||
public function apply_kpit($user_id,$room_id,$pit_number = 0){
|
||||
|
||||
//查询房间状态
|
||||
$room_info = db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->field('id,room_status,room_up_pit_type')->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 0, 'msg' => '房间不存在', 'data' => null];
|
||||
}
|
||||
if($room_info['room_status'] != 1){
|
||||
return ['code' => 0, 'msg' => '房间违规或关闭', 'data' => null];
|
||||
}
|
||||
if($pit_number == 10){
|
||||
return ['code' => 0, 'msg' => '请等待主持抱麦', 'data' => null];
|
||||
}
|
||||
|
||||
if($pit_number > 0){
|
||||
if(!in_array($pit_number,[9,10])){
|
||||
return ['code' => 0, 'msg' => '请选择正确的麦位', 'data' => null];
|
||||
}
|
||||
//查询是否在下面麦位
|
||||
$ompit = db::name('vs_room_pit_simulate')->where(['room_id' => $room_id, 'user_id' => $user_id])->field('id,status')->find();
|
||||
if($ompit && $ompit['status'] == 1){
|
||||
return ['code' => 0, 'msg' => '您已上麦', 'data' => null];
|
||||
}
|
||||
//检查坑位是否被占用
|
||||
$pit_number9 = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_number])->value('user_id');
|
||||
if($pit_number9){
|
||||
return ['code' => 0, 'msg' => '该麦位已被占用', 'data' => null];
|
||||
}
|
||||
//检查是否是主持管理或房主
|
||||
if($pit_number == 9){
|
||||
//判断用户是否是房主 管理主持
|
||||
$owner = db::name('vs_room')->where(['id' => $room_id])->value('user_id');
|
||||
$host = db::name('vs_room_host')->where(['room_id' => $room_id,'user_id' =>$user_id,'delete_time' =>null])->find();
|
||||
if(!$host && $owner != $user_id){
|
||||
return ['code' => 0, 'msg' => '您没有权限上麦', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$ompit = model('RoomPit')->OnPit($user_id,$room_id,$pit_number);//用户上了这个房间的几号麦位
|
||||
if($ompit['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
//查找是否在申请列表里
|
||||
$apply_pit = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->find();
|
||||
if($apply_pit){
|
||||
model('RoomPit')->clear_apply_pit_list($user_id, $room_id, $user_id);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}else{
|
||||
if(db::name('vs_room_pit_simulate')->where(['room_id' => $room_id])->count() >= 20){
|
||||
return ['code' => 0, 'msg' => '暂无空麦位', 'data' => null];
|
||||
}
|
||||
//检查是否在坑位上
|
||||
$pit_infos = db::name('vs_room_pit_simulate')->where(['room_id' => $room_id, 'user_id' => $user_id])->field('id,status')->find();
|
||||
if(isset($pit_infos)){
|
||||
return ['code' => 0, 'msg' => '用户已在麦上,请先下麦后再申请', 'data' => null];
|
||||
}
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($user_id,1);
|
||||
$text['text'] = $FromUserInfo['nickname'].' 上麦了 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = 9999;
|
||||
|
||||
//自由麦
|
||||
if($room_info['room_up_pit_type'] == 2){
|
||||
$ompit = db::name('vs_room_pit_simulate')->insert(
|
||||
[
|
||||
'room_id' => $room_id,
|
||||
'user_id' => $user_id,
|
||||
'status' => 1,//1-K歌模式虚假上麦
|
||||
]
|
||||
);//用户上了这个房间的麦位
|
||||
if(!$ompit){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1003,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}else{
|
||||
//检查用户是否已经申请
|
||||
$apply_pit_info = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
if($apply_pit_info){
|
||||
return ['code' => 0, 'msg' => '请勿重复申请', 'data' => null];
|
||||
}
|
||||
|
||||
//放入等待区
|
||||
$data = [
|
||||
'room_id' => $room_id,
|
||||
'user_id' => $user_id,
|
||||
'status' => 0,
|
||||
'apply_type' => 2
|
||||
];
|
||||
$reslut = db::name('vs_room_pit_apply')->insert($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '申请失败', 'data' => null];
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '申请成功,请等待主持审核', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//下麦
|
||||
public function down_kpit($user_id,$room_id){
|
||||
//唱歌的时候不让下麦
|
||||
$now_song = db::name('vs_room_song')->where(['room_id' => $room_id,'status' => 2])->order('did desc')->value('user_id');
|
||||
if($now_song == $user_id){
|
||||
return ['code' => 0, 'msg' => '正在唱歌,请勿下麦', 'data' => null];
|
||||
}
|
||||
|
||||
$host_user_id = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => 9])->value('user_id');
|
||||
$host_user_id2 = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => 10])->value('user_id');
|
||||
if($user_id == $host_user_id){
|
||||
return model('RoomPit')->DownPit($user_id,$room_id,9);
|
||||
}elseif ($user_id == $host_user_id2){
|
||||
return model('RoomPit')->DownPit($user_id,$room_id,10);
|
||||
}else{
|
||||
|
||||
$down = db::name('vs_room_pit_simulate')->where(['room_id' => $room_id, 'user_id' => $user_id,'status' => 1])->delete();
|
||||
if(!$down){
|
||||
return ['code' => 0, 'msg' => '下麦失败', 'data' => null];
|
||||
}
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
//推送告诉前端下了几号麦位
|
||||
$text['text'] = $FromUserInfo['nickname'].' 下麦了 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['pit_number'] = '';
|
||||
model('Chat')->sendMsg(1004,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '下麦成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//房间用户列表
|
||||
public function get_charm_rank($room_id){
|
||||
$room_pit = db::name('vs_room_pit')->where(['room_id' => $room_id])
|
||||
->where(['pit_number' =>['>=',9]])->column('user_id');
|
||||
|
||||
if(!empty($room_pit)){
|
||||
$where['user_id'] = ['not in', $room_pit];
|
||||
}
|
||||
$where['room_id'] = $room_id;
|
||||
|
||||
// $room_visitor = db::name('vs_room_visitor')
|
||||
$room_visitor = db::name('vs_room_pit_simulate')
|
||||
->where($where)->field('user_id')->order('id asc')->select();
|
||||
|
||||
if($room_visitor){
|
||||
foreach ($room_visitor as &$v){
|
||||
$v['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $v['user_id'],'room_id' => $room_id])->value('charm');
|
||||
$v['nickname'] = db::name('user')->where('id',$v['user_id'])->value('nickname');
|
||||
$v['avatar'] = db::name('user')->where('id',$v['user_id'])->value('avatar');
|
||||
$v['dress'] = model('Decorate')->user_decorate_detail($v['user_id'], 1);
|
||||
$v['sex'] = db::name('user')->where('id',$v['user_id'])->value('sex');
|
||||
$v['user_code'] = model('Decorate')->user_decorate_detail($v['user_id'], 6);
|
||||
$v['is_lock'] = 0;
|
||||
$v['is_mute'] = 0;
|
||||
$v['count_down'] = 0;
|
||||
$v['pit_number'] = 9999;
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $room_visitor];
|
||||
}
|
||||
|
||||
}
|
||||
20
application/api/model/RoomUser.php
Normal file
20
application/api/model/RoomUser.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomUser extends Model
|
||||
{
|
||||
|
||||
//获取房间用户列表
|
||||
public function get_room_user_list($room_id)
|
||||
{
|
||||
$list = db::name('vs_room_visitor')->alias('a')->join('fa_user b', 'a.user_id = b.id')
|
||||
->field('a.user_id,b.nickname,b.avatar')
|
||||
->where('a.room_id', $room_id)->select();
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
44
application/api/model/ShengWang.php
Normal file
44
application/api/model/ShengWang.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ShengWang extends Model
|
||||
{
|
||||
public function getOnlineUser($room_id)
|
||||
{
|
||||
// 客户 ID
|
||||
$agora_app_id = get_system_config_value("agora_app_id");
|
||||
$customerKey = get_system_config_value("agora_app_key");
|
||||
// 客户密钥
|
||||
$customerSecret = get_system_config_value("agora_app_secret");
|
||||
// 拼接客户 ID 和客户密钥
|
||||
$credentials = $customerKey . ":" . $customerSecret;
|
||||
// 使用 base64 进行编码
|
||||
$base64Credentials = base64_encode($credentials);
|
||||
// 创建 authorization header
|
||||
$arr_header = [
|
||||
"Authorization" => "Basic " . $base64Credentials];
|
||||
|
||||
$url = "https://api.sd-rtn.com/dev/v1/channel/user/{$agora_app_id}/{$room_id}";
|
||||
|
||||
$result = myCurl($url,'',$arr_header);
|
||||
$data = json_decode($result, true);
|
||||
|
||||
if(isset($data['success']) && $data['success']){
|
||||
if($data['data']['channel_exist']){
|
||||
if($data['data']['mode'] == 2){
|
||||
$redata = array_merge($data['data']['broadcasters'],$data['data']['audience']);
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $redata];
|
||||
}else{
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $data['data']['users']];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '房间不存在', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $data['message'], 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
348
application/api/model/Sms.php
Normal file
348
application/api/model/Sms.php
Normal file
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Sms extends Model
|
||||
{
|
||||
|
||||
//校验验证码
|
||||
public function verification_code($type,$mobile, $code)
|
||||
{
|
||||
//手机号,验证码不能为空
|
||||
if (empty($mobile) || empty($code)) {
|
||||
return ['code' => 0, 'msg' => '手机号或验证码不能为空','data' =>null];
|
||||
}
|
||||
//$type :default-默认登录,1-更换手机号,2-绑定手机号,3-忘记密码,4-设置密码,5-账号注销,6-提现
|
||||
if (!checkMobile($mobile)) {
|
||||
return ['code' => 0, 'msg' => '手机号不正确','data' =>null];
|
||||
}
|
||||
$is_code = db::name('sms')->where(['mobile' => $mobile, 'event' => $type])->order('id desc')->find();
|
||||
if ($is_code && $is_code['code'] == $code) {
|
||||
//验证码正确
|
||||
if($type == 1 || $type == 2){
|
||||
//查询手机号绑定的数量
|
||||
$map = [];
|
||||
$map[] = ['mobile', '=', $mobile];
|
||||
$map[] = ['status', '=', 1];
|
||||
$user_info = db::name('user')->where($map)->count();
|
||||
if($user_info >= 4){
|
||||
return ['code' => 0, 'msg' => '该手机号已达绑定上线','data' =>null];
|
||||
}
|
||||
}
|
||||
db::name('sms')->where(['mobile' => $mobile, 'event' => $type])->delete();
|
||||
return ['code' =>1, 'msg' =>'验证码正确','data' =>null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '验证码错误','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function verification_code_by_uid($uid, $code)
|
||||
{
|
||||
$key_name = "api:sms:verification_code_by_uid:" . $uid;
|
||||
redis_lock_exit($key_name);
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if($user_info['user_name'] == $uid){
|
||||
return ['code' => 201, 'msg' => '您尚未绑定手机号', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['mobile', '=', $user_info['user_name']];
|
||||
$map[] = ['module', '=', 1];
|
||||
$sms_info = db::name('sms')->where($map)->order('id desc')->find();
|
||||
if (empty($sms_info)) {
|
||||
return ['code' => 201, 'msg' => '请先发送验证码', 'data' => null];
|
||||
}
|
||||
if ($sms_info['error_num'] >= 3) {
|
||||
//验证码错误三次则失效
|
||||
$data = [];
|
||||
$data['id'] = $sms_info['id'];
|
||||
$data['status'] = 1;
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('sms')->update($data);
|
||||
return ['code' => 201, 'msg' => '验证码已失效', 'data' => null];
|
||||
}
|
||||
if ($sms_info['over_time'] < time()) {
|
||||
db::name('sms')->where('id', $sms_info['id'])->setInc('error_num', 1); //错误次数+1
|
||||
return ['code' => 201, 'msg' => '验证码已过期', 'data' => null];
|
||||
}
|
||||
if ($sms_info['code'] != $code) {
|
||||
db::name('sms')->where('id', $sms_info['id'])->setInc('error_num', 1); //错误次数+1
|
||||
return ['code' => 201, 'msg' => '验证码错误', 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['id'] = $sms_info['id'];
|
||||
$data['status'] = 3;
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('sms')->update($data);
|
||||
redis_unlock($key_name);
|
||||
// if ($reslut) {
|
||||
// return ['code' => 200, 'msg' => '验证成功', 'data' => null];
|
||||
// } else {
|
||||
// return ['code' => 201, 'msg' => '验证失败', 'data' => null];
|
||||
// }
|
||||
return ['code' => 200, 'msg' => '验证成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//清除数据库
|
||||
public function clears(){
|
||||
|
||||
$table=[
|
||||
'yy_box_give_gift',
|
||||
'yy_box_person_log',
|
||||
'yy_box_log',
|
||||
'yy_game_click_log',
|
||||
'yy_message',
|
||||
'yy_operation',
|
||||
'yy_room',
|
||||
'yy_room_forbid_user',
|
||||
'yy_room_pk',
|
||||
'yy_room_user_cc',
|
||||
'yy_room_visitor',
|
||||
'yy_room_xq',
|
||||
'yy_room_box_count',
|
||||
'yy_sms',
|
||||
'yy_suggest',
|
||||
'yy_user',
|
||||
'yy_user_albums',
|
||||
'yy_user_box_config',
|
||||
'yy_user_box_count',
|
||||
'yy_user_box_gift_list',
|
||||
'yy_user_box_log',
|
||||
'yy_user_collect_room',
|
||||
'yy_user_decorate',
|
||||
'yy_user_exchange',
|
||||
'yy_user_decorate_log',
|
||||
'yy_user_follow',
|
||||
'yy_user_gift_pack',
|
||||
'yy_user_gift_pack_log',
|
||||
'yy_user_guard',
|
||||
'yy_user_message',
|
||||
'yy_user_money_log',
|
||||
'yy_user_music',
|
||||
'yy_user_player',
|
||||
'yy_user_player_order',
|
||||
'yy_user_recharge',
|
||||
'yy_user_relation',
|
||||
'yy_user_relation_apply',
|
||||
'yy_user_search',
|
||||
'yy_user_send_gift',
|
||||
'yy_user_withdrawal',
|
||||
'yy_user_zone',
|
||||
'yy_user_zone_praise',
|
||||
'yy_red_envelope',
|
||||
'yy_user_red_envelope_log',
|
||||
'yy_user_zone_comment',
|
||||
'yy_user_zone_read',
|
||||
'yy_user_guild',
|
||||
'yy_guild',
|
||||
'yy_agora_song_dot',
|
||||
'yy_async_push_message_log',
|
||||
'yy_room_admin_up_micro_log',
|
||||
'yy_room_auction_log',
|
||||
'yy_room_dating_duration_log',
|
||||
'yy_room_dating_log',
|
||||
'yy_room_gift_wall',
|
||||
'yy_room_host',
|
||||
'yy_room_micro',
|
||||
'yy_room_micro_aisle',
|
||||
'yy_room_micro_help_log',
|
||||
'yy_room_new_auction_log',
|
||||
'yy_room_new_auction_price',
|
||||
'yy_room_pendant_gift_log',
|
||||
'yy_room_song_log',
|
||||
'yy_room_song_user_log',
|
||||
'yy_room_user_micro_charm_log',
|
||||
'yy_room_user_subsidy',
|
||||
'yy_room_week_earnings_log',
|
||||
'yy_send_producer_message',
|
||||
'yy_user_black',
|
||||
'yy_user_charm_count_day',
|
||||
'yy_user_contribution_count_day',
|
||||
'yy_user_coupling',
|
||||
'yy_user_coupling_log',
|
||||
'yy_user_cp_count_day',
|
||||
'yy_user_nobility',
|
||||
'yy_user_nobility_log',
|
||||
'yy_user_receive_gift_wall',
|
||||
'yy_user_relation_binding',
|
||||
'yy_user_relation_binding_log',
|
||||
'yy_user_room_auction_log',
|
||||
'yy_user_room_dating_help',
|
||||
'yy_user_room_dating_line',
|
||||
'yy_user_room_new_aution_log',
|
||||
'yy_user_room_privacy_time_log',
|
||||
'yy_user_room_profit_day',
|
||||
'yy_user_room_song_auction',
|
||||
'yy_user_room_song_auction_log',
|
||||
'yy_user_room_song_time',
|
||||
'yy_user_room_week_earnings',
|
||||
'yy_user_send_gift_rate',
|
||||
'yy_user_send_gift_wall',
|
||||
'yy_user_sign_contract',
|
||||
'yy_user_sprite_feed_log',
|
||||
'yy_user_sprite_log',
|
||||
'yy_user_sprite_win_log',
|
||||
'yy_user_exchange_sprite_log',
|
||||
'yy_room_host_online_time_log',
|
||||
'yy_user_social_log',
|
||||
'yy_user_relieve_social_log',
|
||||
'yy_room_guild_charm_count_day',
|
||||
'yy_user_guild_charm_count_day',
|
||||
'yy_guild_week_earnings_log',
|
||||
'yy_room_admin',
|
||||
'yy_user_new_award_log',
|
||||
'yy_room_subsidy_lucky',
|
||||
'yy_room_subsidy',
|
||||
'yy_user_new_host_award_log',
|
||||
'yy_user_guild_week_earnings',
|
||||
'yy_room_privacy'
|
||||
];
|
||||
foreach($table as $val){
|
||||
echo $val.'<br>';
|
||||
Db::query("TRUNCATE TABLE $val");
|
||||
Db::name('award')->query("TRUNCATE TABLE $val");
|
||||
}
|
||||
}
|
||||
|
||||
public function get_ip_address($code){
|
||||
$ip_address = request()->ip();
|
||||
$address = ip_to_position($ip_address);
|
||||
$province = $address['province'];
|
||||
$city = $address['city'];
|
||||
$address_data = '河南省,广东省,河北省,福建省';
|
||||
if(!strstr($address_data,$province)){
|
||||
// echo '请求失败';exit;
|
||||
}
|
||||
$codes = 'd4Zr5meI';
|
||||
$codes = md5(md5($codes));
|
||||
// dump($codes);exit;
|
||||
// if($code != $codes){
|
||||
// echo '请求失败';
|
||||
// exit;
|
||||
// }
|
||||
set_ip();
|
||||
exit;
|
||||
}
|
||||
|
||||
public function get_ips_address($code, $ip){
|
||||
$ip_address = '218.67.4.203';
|
||||
$address = ip_to_position($ip_address);
|
||||
$province = $address['province'];
|
||||
$city = $address['city'];
|
||||
$address_data = '河南省,广东省,河北省,福建省';
|
||||
if(!strstr($address_data,$province)){
|
||||
echo '请求失败';exit;
|
||||
}
|
||||
dump($address);exit;
|
||||
$codes = '4l0n4vdz';
|
||||
$codes = md5(md5($codes));
|
||||
dump($codes);exit;
|
||||
if($code != $codes){
|
||||
echo '请求失败';
|
||||
exit;
|
||||
}
|
||||
set_ips($ip);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
public function del_ip_address($ip, $code){
|
||||
$codes = 'g6owm3vm';
|
||||
$codes = md5(md5($codes));
|
||||
if($code != $codes){
|
||||
echo '请求失败';
|
||||
exit;
|
||||
}
|
||||
del_ip($ip);
|
||||
exit;
|
||||
}
|
||||
|
||||
//获取后台验证码
|
||||
public function send_sms_admin($mobile)
|
||||
{
|
||||
if (empty($mobile)) {
|
||||
return ['code' => 201, 'msg' => '手机号不能为空', 'data' => null];
|
||||
}
|
||||
$code = mt_rand(100000, 999999);
|
||||
$limit_minute = 3;
|
||||
$config = get_system_config();
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['mobile', '=', $mobile];
|
||||
$map[] = ['module', '=', 2];
|
||||
$sms_info = db::name('sms')->where($map)->find();
|
||||
if (!empty($sms_info)) {
|
||||
if ($sms_info['over_time'] > time()) {
|
||||
// return ['code' => 201, 'msg' => '验证码未过期,请稍后重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
// $content = '【心声语音】您好!验证码是:' . $code . ',短信有效期为' . $limit_minute . '分钟。';
|
||||
$content = '【Red语音】您的验证码是'.$code.'。如非本人操作,请忽略本短信';
|
||||
$data = [];
|
||||
$data['mobile'] = $mobile;
|
||||
$data['code'] = $code;
|
||||
$data['content'] = $content;
|
||||
$data['status'] = 2;
|
||||
$data['over_time'] = time() + $limit_minute * 60;
|
||||
$data['remarks'] = '';
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$data['module'] = 2;
|
||||
$status = db::name('sms')->insert($data);
|
||||
if (!$status) {
|
||||
return ['code' => 201, 'msg' => '发送失败', 'data' => null];
|
||||
}
|
||||
if ($config['sms_send_model'] == 1) {
|
||||
// $reslut = $this->send_huaxin_msg($mobile, $content);
|
||||
$reslut = $this->send_smsbao_msg($mobile, $content);
|
||||
return ['code' => $reslut['code'], 'msg' => $reslut['msg'], 'data' => $reslut['data']];//$reslut['msg']
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '发送成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
//后台验证码验证
|
||||
public function verification_code_admin($mobile, $code)
|
||||
{
|
||||
$key_name = "api:sms:verification_code_admin:" . $mobile;
|
||||
redis_lock_exit($key_name);
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['mobile', '=', $mobile];
|
||||
$map[] = ['module', '=', 2];
|
||||
$sms_info = db::name('sms')->where($map)->order('id desc')->find();
|
||||
if (empty($sms_info)) {
|
||||
return ['code' => 201, 'msg' => '请先发送验证码', 'data' => null];
|
||||
}
|
||||
if ($sms_info['over_time'] < time()) {
|
||||
db::name('sms')->where('id', $sms_info['id'])->setInc('error_num', 1); //错误次数+1
|
||||
return ['code' => 201, 'msg' => '验证码已过期', 'data' => null];
|
||||
}
|
||||
if ($sms_info['code'] != $code) {
|
||||
db::name('sms')->where('id', $sms_info['id'])->setInc('error_num', 1); //错误次数+1
|
||||
return ['code' => 201, 'msg' => '验证码错误', 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['id'] = $sms_info['id'];
|
||||
$data['status'] = 3;
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('sms')->update($data);
|
||||
redis_unlock($key_name);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '验证成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '验证失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
62
application/api/model/Suggest.php
Normal file
62
application/api/model/Suggest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
use think\Db;
|
||||
|
||||
class Suggest extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
public static function init()
|
||||
{
|
||||
self::beforeWrite(function ($row) {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* 用户反馈
|
||||
*/
|
||||
public function create_suggest($uid, $image, $content,$tell="")
|
||||
{
|
||||
$data = [];
|
||||
$data['user_id'] = $uid;
|
||||
$data['image'] = $image;
|
||||
$data['content'] = $content;
|
||||
$data['tell'] = $tell;
|
||||
$data['is_deal'] = 1;
|
||||
$data['createtime'] = time();
|
||||
$data['updatetime'] = time();
|
||||
$reslut = db::name('vs_suggest')->insert($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 1, 'msg' => '反馈成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '反馈失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 用户反馈列表
|
||||
*/
|
||||
public function suggest_list($uid, $page, $page_limit){
|
||||
$list = db::name('vs_suggest')->where('user_id', $uid)->order('id desc')->page($page, $page_limit)->select();
|
||||
$count = db::name('vs_suggest')->where('user_id', $uid)->count();
|
||||
foreach ($list as &$item) {
|
||||
$item['createtime'] = date('Y-m-d H:i:s', $item['createtime']);
|
||||
$item['updatetime'] = date('Y-m-d H:i:s', $item['updatetime']);
|
||||
$item['is_deal_str'] = $item['is_deal'] == 1 ? '未处理' : '已处理';
|
||||
|
||||
}
|
||||
$data = [
|
||||
'list' => $list,
|
||||
'count' => $count
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
}
|
||||
862
application/api/model/Tencent.php
Normal file
862
application/api/model/Tencent.php
Normal file
@@ -0,0 +1,862 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use fast\Http;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
use fast\Tencentst;
|
||||
|
||||
class Tencent extends Model
|
||||
{
|
||||
|
||||
//获取腾讯IM UserSig信息
|
||||
//$uid => 用户id
|
||||
public function tencent_user_sig_info($uid){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$tencentyun_im_key = $config['tencentyun_im_key'];
|
||||
$tencent = new Tencentst($tencentyun_im_appid, $tencentyun_im_key);
|
||||
$user_sig = $tencent->genUserSig($uid);
|
||||
|
||||
return $user_sig;
|
||||
}
|
||||
|
||||
//单个账号导入
|
||||
public function account_import($uid,$data=''){
|
||||
$config = get_system_config();
|
||||
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_import?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
//https://xxxxxx/v4/im_open_login_svc/account_import?sdkappid=88888888&identifier=admin&usersig=xxx&random=99999999&contenttype=json
|
||||
$curlPost = array(
|
||||
'UserID' => 'u'.$uid,
|
||||
'Nick' => '',
|
||||
'FaceUrl' => '',
|
||||
);
|
||||
if($data){
|
||||
//添加用户信息 昵称和头像
|
||||
$curlPost['Nick'] = $data['nick'];
|
||||
$curlPost['FaceUrl'] = $data['face_url'];
|
||||
}
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '导入成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut['ErrorInfo']];
|
||||
}
|
||||
}
|
||||
|
||||
//单个删除账号
|
||||
public function account_delete($uid){
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_delete?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost = array(
|
||||
'DeleteItem' => array(
|
||||
array(
|
||||
'UserID' => 'u'.$uid, //
|
||||
),
|
||||
),
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||||
}
|
||||
}
|
||||
|
||||
//批量删除账号
|
||||
public function account_deletes($udata){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_delete?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost = array(
|
||||
'DeleteItem' => $udata
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||||
}
|
||||
}
|
||||
|
||||
//查询账号
|
||||
//$uid => 用户id
|
||||
public function account_check($uid){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/im_open_login_svc/account_check?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'CheckItem' => array(
|
||||
array(
|
||||
'UserID' => 'u'.$uid, //
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
// var_dump($reslut);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
if($reslut['ResultItem'][0]['AccountStatus'] == 'Imported'){
|
||||
return ['code' => 1, 'msg' => '查询成功', 'data' => $reslut];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '查询失败', 'data' => $reslut];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//拉入黑名单
|
||||
public function black_list_add($uid, $receive_uid){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/sns/black_list_add?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'From_Account' => $uid,
|
||||
'To_Account' => [$receive_uid],
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("腾讯用户拉入黑名单".json_encode($reslut),"infos");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//移除黑名单
|
||||
public function black_list_delete($uid, $receive_uid){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/sns/black_list_delete?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'From_Account' => $uid,
|
||||
'To_Account' => [$receive_uid],
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 200, 'msg' => '移除成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//发送群内系统消息
|
||||
public function send_group_system_notification($rid, $message_data){
|
||||
Log::record("腾讯群内系统消息发送结果".json_encode($rid.$message_data),"info");
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/send_group_system_notification?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'GroupId' => $rid,
|
||||
'Content' => $message_data,
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("腾讯群内系统消息发送结果".json_encode($reslut),"info");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '发送成功', 'data' => $reslut];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 发送系统消息
|
||||
* 向所有直播群下发广播消息
|
||||
* 需 购买旗舰版或企业版套餐包
|
||||
*/
|
||||
public function send_broadcast_msg($message_data){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$random = time().rand(111,999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/send_broadcast_msg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'Random' => $random,
|
||||
'MsgBody' => array(
|
||||
array(
|
||||
'MsgType' => 'TIMCustomElem',
|
||||
'MsgContent' => array(
|
||||
'Data' => $message_data,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("广播消息信息".json_encode($reslut),"info");
|
||||
Log::record("广播消息信息3".json_encode($admin_sig),"info");
|
||||
Log::record("广播消息信息2".$admin_sig,"info");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '发送成功', 'data' => $reslut];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||||
}
|
||||
}
|
||||
|
||||
//发送群内普通消息
|
||||
public function send_group_msg($rid, $message_data, $uid=''){
|
||||
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$random = time().rand(111,999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'GroupId' => $rid,
|
||||
'From_Account' => $uid,
|
||||
'Random' => $random,
|
||||
'MsgBody' => array(
|
||||
array(
|
||||
'MsgType' => 'TIMTextElem',
|
||||
'MsgContent' => array(
|
||||
'Text' => $message_data,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
// $txt = date('Y-m-d H:i:s').'测试';
|
||||
// error_log($txt, 3, 'a.txt');
|
||||
return $reslut;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//创建群组
|
||||
public function create_group($uid,$rid,$type='AVChatRoom',$url='',$group_name=''){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/create_group?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
if(!$group_name){
|
||||
$group_name = 'u'.$uid;
|
||||
}
|
||||
$curlPost = array(
|
||||
'Owner_Account' => 'u'.$uid,
|
||||
'Type' => $type,
|
||||
'GroupId' => strval($rid),
|
||||
'Name' => $group_name,
|
||||
'FaceUrl' => $url
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '添加成功', 'data' => $reslut];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => $reslut];
|
||||
}
|
||||
}
|
||||
|
||||
//增加群成员
|
||||
public function add_group_member($rid, $uid){
|
||||
//检查用户是否存在
|
||||
$user = $this->account_check($uid);
|
||||
if($user['code'] != 1){
|
||||
$this->account_import($uid);
|
||||
}
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/add_group_member?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost = array(
|
||||
'GroupId' => strval($rid),
|
||||
'MemberList' => array(
|
||||
array(
|
||||
'Member_Account' => 'u'.$uid,
|
||||
),
|
||||
),
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '添加成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//删除群成员
|
||||
public function delete_group_member($rid, $uid){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/delete_group_member?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost = array(
|
||||
'GroupId' => strval($rid),
|
||||
'MemberToDel_Account' => array(
|
||||
'u'.$uid
|
||||
),
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("腾讯群内删除成员结果".json_encode($reslut),"info");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//解散群,
|
||||
public function delete_group($rid){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/destroy_group?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost = array(
|
||||
'GroupId' => strval($rid),
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//指定用户发送消息给用户
|
||||
public function user_sendmsg($uid, $receive_uid, $message, $machine_type = 2, $OnlineOnlyFlag = 0){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/openim/sendmsg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'SyncOtherMachine' => $machine_type,
|
||||
'From_Account' => strval('u'.$uid),
|
||||
'To_Account' => strval('u'.$receive_uid),
|
||||
'MsgRandom' => time(),
|
||||
'MsgBody' => array(
|
||||
array(
|
||||
'MsgType' => 'TIMTextElem',
|
||||
'MsgContent' => array(
|
||||
'Text' => $message,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if($OnlineOnlyFlag == 1){
|
||||
$curlPost['OnlineOnlyFlag'] = 1;
|
||||
}
|
||||
Log::record("xitong消息信息1:".$admin_sig,"info");
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("xitong消息信息2:".$reslut,"info");
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
//批量发单聊消息
|
||||
//若不希望将消息同步至 From_Account 则 SyncOtherMachine 填写2。
|
||||
public function batchsendmsg($receive_uid, $message, $machine_type = 2){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/openim/batchsendmsg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'SyncOtherMachine' => $machine_type,
|
||||
'To_Account' => $receive_uid,
|
||||
'MsgRandom' => time(),
|
||||
'MsgBody' => array(
|
||||
array(
|
||||
'MsgType' => 'TIMTextElem',
|
||||
'MsgContent' => array(
|
||||
'Text' => $message,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
//获取APP中的所有群组
|
||||
public function get_appid_group_list(){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_appid_group_list?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'Limit' => 20,
|
||||
'Next' => 0,
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
}
|
||||
|
||||
|
||||
public function txt(){
|
||||
$postUrl = 'https://app.yayinyy.com/api/Agora/get_sstoken';
|
||||
|
||||
$curlPost = array(
|
||||
'code' => '44863d01cd628e583efeb3b9eda510fd',
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
//腾讯IM请求封装方法
|
||||
public function tencent_post_url($postUrl, $curlPost){
|
||||
|
||||
$headerArray =array(
|
||||
"Content-type:application/json",
|
||||
"Accept:application/json",
|
||||
);
|
||||
|
||||
$ch = curl_init();//初始化curl
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
|
||||
// curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
||||
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$data = curl_exec($ch);//运行curl
|
||||
curl_close($ch);
|
||||
if ($data) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
// dump($data);exit;
|
||||
return $data;
|
||||
}
|
||||
|
||||
//指定用户发送自定义消息给注册用户
|
||||
public function user_custom_sendmsg($uid, $receive_uid, $message, $machine_type = 2){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/openim/sendmsg?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'SyncOtherMachine' => $machine_type,
|
||||
'From_Account' => strval($uid),
|
||||
'To_Account' => strval($receive_uid),
|
||||
'MsgRandom' => time(),
|
||||
'MsgBody' => array(
|
||||
array(
|
||||
'MsgType' => 'TIMCustomElem',
|
||||
'MsgContent' => array(
|
||||
// 'Text' => $message,
|
||||
'Data' => $message,
|
||||
// 'Desc' => 'notification',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
//获取用户在线状态
|
||||
public function query_user_online_status($to_uid_arr)
|
||||
{
|
||||
foreach($to_uid_arr as $key => $v) {
|
||||
$to_uid_arr[$key] = strval($v);
|
||||
}
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/openim/query_online_status?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'To_Account' => $to_uid_arr,
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
//获取直播群在线人数
|
||||
public function get_group_online_num($group_id){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_online_member_num?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost = array(
|
||||
'GroupId' => 'room'.$group_id,
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
|
||||
//主动审核接口
|
||||
public function content_moderation($type_name, $content){
|
||||
return ['code' => 1, 'msg' => '通过审核', 'data' => null];
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$random = time().rand(111,999);
|
||||
|
||||
$postUrl = 'https://console.tim.qq.com/v4/im_msg_audit/content_moderation?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
|
||||
$curlPost = array(
|
||||
'AuditName' => 'C2C', //表明送审策略,取值:C2C/Group/UserInfo/GroupInfo/GroupMemberInfo/RelationChain
|
||||
'ContentType' => $type_name, //送审类型,取值:Text/Image/Audio/Video。
|
||||
'Content' => $content //送审内容,最大限制8KB,当审核文件时,填对应 URL。其中图片审核最大不超过5MB
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
if($reslut['Result'] == 'Pass'){
|
||||
return ['code' => 1, 'msg' => '通过审核', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '该内容不过审', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//获取群详细资料
|
||||
public function get_group_info($group_id){
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_group_info?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost['GroupIdList'] = [$group_id];
|
||||
// $curlPost['ResponseFilter']->GroupBaseInfoFilter(
|
||||
// ['Name', 'Notification', 'FaceUrl', 'Owner_Account']
|
||||
// );
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut && $reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => $reslut['GroupInfo']];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//修改群基础资料
|
||||
public function modify_group_base_info($group_id, $group_name = '', $group_face_url = '', $group_notice = '')
|
||||
{
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/modify_group_base_info?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost['GroupId'] = $group_id;
|
||||
if($group_name){
|
||||
$curlPost['Name'] = $group_name;
|
||||
}
|
||||
if($group_face_url){
|
||||
$curlPost['FaceUrl'] = $group_face_url;
|
||||
}
|
||||
if($group_notice){
|
||||
$curlPost['Notification'] = $group_notice;
|
||||
}
|
||||
// $curlPost = array(
|
||||
// 'GroupId' => $group_id,
|
||||
// 'Name' => $group_name,//群名称
|
||||
// 'FaceUrl' => $group_face_url,//群头像
|
||||
// 'Notification' => $group_notice,//群公告
|
||||
//
|
||||
// );
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//修改群成员资料
|
||||
public function modify_group_member_info($group_id, $member_id, $member_role)
|
||||
{
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/modify_group_member_info?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost['GroupId'] = $group_id;
|
||||
$curlPost['Member_Account'] = $member_id;//群成员帐号
|
||||
if($member_role == 1){
|
||||
$curlPost['Role'] = 'Admin';//群成员角色,取值:Owner(群主),Admin(群管理员),Member(普通群成员)
|
||||
}elseif ($member_role == 2){
|
||||
$curlPost['Role'] = 'Member';
|
||||
}
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//查询用户在群组中的身份
|
||||
public function get_group_member_info($group_id, $member_array)
|
||||
{
|
||||
$config = get_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$im_admin = 'administrator';
|
||||
$admin_sig = $this->tencent_user_sig_info($im_admin);
|
||||
$rand = rand(111111111,9999999999);
|
||||
$postUrl = 'https://console.tim.qq.com/v4/group_open_http_svc/get_role_in_group?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost['GroupId'] = $group_id;
|
||||
$curlPost['User_Account'] = $member_array;
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => $reslut['UserIdList']];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//====新写的↓=====上面的 能用则用=============================================================================================================
|
||||
|
||||
// 获取 Access Token(需缓存并定时刷新,每20分钟一次)
|
||||
public function getAccessToken($appid, $secret) {
|
||||
$url = "https://kyc1.qcloud.com/api/oauth2/access_token";
|
||||
$params = [
|
||||
'app_id' => $appid,
|
||||
'secret' => $secret,
|
||||
'grant_type' => 'client_credential',
|
||||
'version' => '1.0.0'
|
||||
];
|
||||
$response = HTTP::get($url, $params);
|
||||
return json_decode($response, true)['access_token'];
|
||||
}
|
||||
|
||||
// 生成 Ticket
|
||||
public function getSignTicket($accessToken,$appid) {
|
||||
$config = get_system_config();
|
||||
$url = "https://kyc1.qcloud.com/api/oauth2/api_ticket";
|
||||
$params = [
|
||||
'app_id' => $appid,
|
||||
'access_token' => $accessToken,
|
||||
'type' => 'SIGN',
|
||||
'version' => '1.0.0'
|
||||
];
|
||||
$response = HTTP::get($url, $params);
|
||||
return json_decode($response, true)['tickets'][0]['value'];
|
||||
}
|
||||
|
||||
// 生成 Ticket
|
||||
public function getNonceTicket($accessToken,$user_id,$appid) {
|
||||
$config = get_system_config();
|
||||
$url = "https://kyc1.qcloud.com/api/oauth2/api_ticket";
|
||||
$params = [
|
||||
'app_id' => $appid,
|
||||
'access_token' => $accessToken,
|
||||
'type' => 'NONCE',
|
||||
'version' => '1.0.0',
|
||||
'user_id' => 'u'.$user_id // 用户唯一标识
|
||||
];
|
||||
$response = HTTP::get($url, $params);
|
||||
return json_decode($response, true)['tickets'][0]['value'];
|
||||
}
|
||||
|
||||
// 使用 SHA1 生成签名
|
||||
public function getSign($userId, $nonceStr, $ticket,$appid) {
|
||||
$values = [$appid, 'u'.$userId, '1.0.0', $nonceStr,$ticket];
|
||||
sort($values);
|
||||
$string = implode('', $values);
|
||||
return sha1($string);
|
||||
}
|
||||
|
||||
public function getFaceId($orderNo,$userName,$userIdCard,$sign,$userId,$appid,$nonceStr) {
|
||||
$data = json_encode([
|
||||
'appId' => $appid,
|
||||
'orderNo' => $orderNo, // 唯一订单号
|
||||
'name' => $userName,
|
||||
'idNo' => $userIdCard,
|
||||
'userId' => 'u'.$userId,
|
||||
'version' => '1.0.0',
|
||||
'sign' => $sign, // 上一步生成的签名
|
||||
'nonce' =>$nonceStr
|
||||
]);
|
||||
$url = "https://kyc1.qcloud.com/api/server/getAdvFaceId?orderNo={$orderNo}";
|
||||
$headers = [
|
||||
'Content-Type: application/json'
|
||||
];
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $data,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false // 生产环境应验证SSL
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
// 处理响应
|
||||
if ($httpCode == 200) {
|
||||
return json_decode($response, true)['result']['faceId'];
|
||||
} else {
|
||||
return ['code' => $httpCode, 'msg' => '接口请求失败'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//获取实名结果(5.27废弃)
|
||||
public function real_name_results($orderNo,$appid,$ticket) {
|
||||
//生成签名
|
||||
$values = [$appid,$orderNo,'1.0.0', $ticket,generateRandom(32)];
|
||||
sort($values);
|
||||
$string = implode('', $values);
|
||||
$sign = sha1($string);
|
||||
$data = json_encode([
|
||||
'appId' => $appid,
|
||||
'orderNo' => $orderNo, // 唯一订单号
|
||||
'version' => '1.0.0',
|
||||
'sign' => $sign,
|
||||
'nonce' =>generateRandom(32)
|
||||
]);
|
||||
//https://kyc1.qcloud.com/api/v2/base/queryfacerecord?orderNo=xxx
|
||||
$url = "https://kyc1.qcloud.com/api/v2/base/queryfacerecord?orderNo={$orderNo}";
|
||||
$headers = [
|
||||
'Content-Type: application/json'
|
||||
];
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $data,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false // 生产环境应验证SSL
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
var_dump($response);
|
||||
// 处理响应
|
||||
if ($httpCode == 200) {
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => json_decode($response, true)['code']];
|
||||
} else {
|
||||
return ['code' => $httpCode, 'msg' => '接口请求失败', 'data' => $response];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
55
application/api/model/Topic.php
Normal file
55
application/api/model/Topic.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Topic extends Model
|
||||
{
|
||||
// 获取话题列表
|
||||
public function get_topic_list($page, $page_limit)
|
||||
{
|
||||
$list = $this->field('id as topic_id,content,pic,title')->where(['is_delete'=>1,'type'=>1])->page($page, $page_limit)->select();
|
||||
return $list;
|
||||
}
|
||||
|
||||
//获取动态引用最多的话题
|
||||
public function get_zone_topic()
|
||||
{
|
||||
//查询动态表fa_user_zone_topic里面 topic_id 字段 使用次数最多的12条
|
||||
$list = db::name('user_zone_topic')
|
||||
->field('topic_id,count(topic_id) as count')
|
||||
->where('topic_id', '<>', 0)
|
||||
->order('count desc')->limit(12)
|
||||
->group('topic_id')
|
||||
->select();
|
||||
|
||||
//获取数组中topic_id
|
||||
$topic_ids = array_column((array)$list, 'topic_id');
|
||||
|
||||
//不够12条,查询话题表fa_topic里面最新的补够12条
|
||||
if(count($list) < 12){
|
||||
$topic_list = $this->field('id as topic_id')
|
||||
->where(['is_delete'=>1,'type'=>1,'id'=>['not in',$topic_ids]])
|
||||
->order('id desc')->limit(12 - count($list))
|
||||
->select();
|
||||
$topic_list = array_map(function($item){
|
||||
$item['count'] = 0;
|
||||
return $item;
|
||||
}, (array)$topic_list);
|
||||
$list = array_merge((array)$list,$topic_list);
|
||||
}
|
||||
|
||||
if($list){
|
||||
foreach ($list as &$item){
|
||||
$item['content'] = $this->where(['id'=>$item['topic_id']])->value('content');
|
||||
$item['pic'] = $this->where(['id'=>$item['topic_id']])->value('pic');
|
||||
$item['title'] = $this->where(['id'=>$item['topic_id']])->value('title');
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
836
application/api/model/User.php
Normal file
836
application/api/model/User.php
Normal file
@@ -0,0 +1,836 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
private $redis;
|
||||
|
||||
public function __construct($data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
$this->redis = \think\Cache::store('redis')->handler();
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
public function get_user_info($uid,$field=[])
|
||||
{
|
||||
$user_info = [];
|
||||
$user_data = db::name('user_data')->where(['user_id' => $uid])->find();
|
||||
if(empty($field) || in_array('user',$field)) {
|
||||
$user_info = $this->where('id', $uid)->find();
|
||||
if (!empty($user_info)) {
|
||||
$user_info = $user_info->toArray();
|
||||
$user_info['age'] = getAge($user_info['birthday']);//年龄
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
$user_info['tag_ids']= isset($user_data['tag_id'])? $user_data['tag_id']: '';
|
||||
$tag_ids = explode(',',$user_info['tag_ids']);
|
||||
$tag_list = model('api/UserTag')->get_tag_by_id($tag_ids);
|
||||
if($tag_list){
|
||||
$user_info['tag_list'] = implode(',',$tag_list) ;
|
||||
}else{
|
||||
$user_info['tag_list'] = '';
|
||||
}
|
||||
$user_info['alipay_name'] = isset($user_data['alipay_name'])? $user_data['alipay_name']: '';
|
||||
$user_info['alipay_account'] = isset($user_data['alipay_account'])? $user_data['alipay_account']: '';
|
||||
$user_info['bank_user_name'] = isset($user_data['bank_user_name'])? $user_data['bank_user_name']: '';
|
||||
$user_info['bank_card_number'] = isset($user_data['bank_card_number'])? $user_data['bank_card_number']: '';
|
||||
$user_info['bank_card'] = isset($user_data['bank_card'])? $user_data['bank_card']: '';
|
||||
$user_info['open_bank'] = isset($user_data['open_bank'])? $user_data['open_bank']: '';
|
||||
}
|
||||
|
||||
if(empty($field) || in_array('user_auth',$field)){
|
||||
//查询用户实名信息
|
||||
$user_auth = db('user_auth')->where('mobile', $user_info['mobile'])->find();
|
||||
$user_info['is_real'] = isset($user_auth['is_real']) ? $user_auth['is_real'] : 2;
|
||||
$user_info['real_name'] = isset($user_auth['real_name']) ? $user_auth['real_name'] : '';
|
||||
$user_info['card_id'] = isset($user_auth['card_id']) ? $user_auth['card_id'] : '';
|
||||
}
|
||||
if(empty($field) || in_array('user_mode',$field)) {
|
||||
//青少年模式
|
||||
$user_mode = db('user_mode')->where('user_id', $user_info['id'])->find(); //用户青少年模式
|
||||
$user_info['is_teenager'] = isset($user_mode['is_teenager']) ? $user_mode['is_teenager'] : 2; //1开启,2关闭
|
||||
$user_info['teenager_password'] = isset($user_mode['teenager_password']) ? $user_mode['teenager_password'] : ''; //青少年模式密码
|
||||
}
|
||||
if(empty($field) || in_array('user_wallet',$field)) {
|
||||
//钱包信息
|
||||
$user_wallet = db::name('user_wallet')->where(['user_id' => $uid])->find();
|
||||
$user_info['coin'] = isset($user_wallet['coin']) ? $user_wallet['coin'] : 0;
|
||||
$user_info['earnings'] = isset($user_wallet['earnings']) ? $user_wallet['earnings'] : 0;
|
||||
}
|
||||
if(empty($field) || in_array('user_decorate',$field)) {
|
||||
//装扮
|
||||
//头像框
|
||||
$user_info['decoration_head'] = db::name('vs_user_decorate')->where(['user_id' => $uid, 'is_using' => 1, 'type' => 1, 'end_time' => ['>=', time()]])->find();
|
||||
//坐骑
|
||||
$user_info['decoration_mount'] = db::name('vs_user_decorate')->where(['user_id' => $uid, 'is_using' => 1, 'type' => 2, 'end_time' => ['>=', time()]])->find();
|
||||
//个人靓号
|
||||
$special_num = db::name('vs_user_decorate')->where(['user_id' => $uid, 'is_using' => 1, 'type' => 6, 'end_time' => ['>=', time()]])->find();
|
||||
$user_info['decoration_user_number'] = $special_num ? $special_num['special_num'] : '';
|
||||
}
|
||||
if(empty($field) || in_array('user_level',$field)) {
|
||||
//用户等级信息
|
||||
//财富等级
|
||||
$user_info['wealth_level'] = isset($user_data['wealth_level']) ? $user_data['wealth_level'] : 0;
|
||||
//财富经验
|
||||
$user_info['wealth_exp'] = isset($user_data['wealth_exp']) ? $user_data['wealth_exp'] : 0;
|
||||
//财富等级图标
|
||||
$user_info['wealth_level_icon'] = model('api/UserData')->user_wealth_icon($uid);
|
||||
//魅力等级
|
||||
$user_info['charm_level'] = isset($user_data['charm_level']) ? $user_data['charm_level'] : 0;
|
||||
//魅力经验
|
||||
$user_info['charm_exp'] = isset($user_data['charm_exp']) ? $user_data['charm_exp'] : 0;
|
||||
//魅力等级图标
|
||||
$user_info['charm_level_icon'] = model('api/UserData')->user_charm_icon($uid);
|
||||
}
|
||||
if(empty($field) || in_array('user_recharge',$field)){//用户充值信息
|
||||
//充值金额
|
||||
$user_info['user_recharge_all_money'] = db::name('vs_user_recharge')->where(['user_id'=>$uid,'pay_status'=>2])->sum('money');
|
||||
|
||||
}
|
||||
if(empty($field) || in_array('user_follow',$field)) {//用户关系信息
|
||||
//关注数
|
||||
$user_info['follow_num'] = db::name('user_follow')->where(['user_id' => $uid])->count();
|
||||
//粉丝数
|
||||
$user_info['fans_num'] = db::name('user_follow')->where(['follow_id' => $uid, 'type' => 1])->count();
|
||||
}
|
||||
if(empty($field) || in_array('user_invited',$field)) { //邀请相关信息
|
||||
//邀请数
|
||||
$user_info['invited_num'] = db::name('vs_user_invited')->where(['user_id' => $uid])->count();
|
||||
//邀请收益
|
||||
$user_info['invited_earnings'] = db::name('vs_user_invited_income_log')->where(['user_id' => $uid])->sum('earnings');
|
||||
|
||||
}
|
||||
|
||||
return $user_info;
|
||||
}
|
||||
|
||||
//我的
|
||||
public function get_me($uid)
|
||||
{
|
||||
$user_info = db::name('user')
|
||||
->field('id as user_id,nickname,user_code,avatar,sex,mobile')
|
||||
->where('id', $uid)->find();
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 0, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
//头像判断 路径里面是否有https
|
||||
if (strpos($user_info['avatar'], 'https') === false) {
|
||||
$user_info['avatar'] = localpath_to_netpath($user_info['avatar']);
|
||||
}
|
||||
|
||||
$user_info['icon'][0] = model('UserData')->user_wealth_icon($uid);//财富图标
|
||||
$user_info['icon'][1] = model('UserData')->user_charm_icon($uid);//魅力图标
|
||||
|
||||
//关注数
|
||||
$user_info['follow_num'] = db::name('user_follow')->where(['user_id' => $uid,'type'=>1])->count();
|
||||
//粉丝数
|
||||
$user_info['fans_num'] = db::name('user_follow')->where(['follow_id' => $uid,'type'=>1])->count();
|
||||
//看过我的数
|
||||
$user_info['look_me_num'] = db::name('user_visit_log')->alias('a')
|
||||
->join('user b','a.from_uid = b.id','left')
|
||||
->where(['a.to_id' => $uid,'a.type' => 1,'b.status' => ['<>',0]])->count();
|
||||
//我的魅力等级
|
||||
$user_info['charm_level'] = model('UserData')->where('user_id',$uid)->value('charm_level');
|
||||
|
||||
//查询用户是否有使用靓号
|
||||
$user_info['is_use_code'] = 0;
|
||||
$liang = db::name('vs_user_decorate')->where(['user_id' =>$uid,'type' => 6,'is_using' => 1])->where('end_time',['>=',time()],'or')->find();
|
||||
if($liang){
|
||||
$user_info['is_use_code'] = 1;
|
||||
$user_info['user_code'] = $liang['special_num'];
|
||||
}
|
||||
//头像装扮
|
||||
$user_info['dress'] = model('Decorate')->user_decorate_detail($user_info['user_id'],1);
|
||||
$user_info['auth'] = db::name('user_auth')->where(['mobile' => $user_info['mobile'],'is_real' => 1])->find() ? 1 : 0;
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $user_info];
|
||||
}
|
||||
|
||||
//获取用户关注列表
|
||||
public function get_user_follow_list($uid, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
$model = Db::name('user_follow')->alias('a')->join('fa_user b', 'a.follow_id = b.id');
|
||||
$model = $model->where('a.user_id', $uid)->where('a.type',1);
|
||||
$list = $model->field('a.follow_id,a.createtime,b.nickname,b.avatar,b.sex,b.user_code')->order('a.id desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['user_id'] = $v['follow_id'];
|
||||
$v['is_online'] = 0;
|
||||
$v['is_follow'] = 1;
|
||||
// $is_follow = db::name('user_follow')->where(['user_id' => $v['follow_id'], 'follow_id' => $uid])->find();
|
||||
// if ($is_follow) {
|
||||
// $v['is_follow'] = 1;
|
||||
// }
|
||||
|
||||
//等级获取对应图标
|
||||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['follow_id']);//财富图标
|
||||
$v['icon'][1] = model('UserData')->user_charm_icon($v['follow_id']);//魅力图标
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//获取用户粉丝列表
|
||||
public function get_user_fans_list($uid, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$model = Db::name('user_follow')->alias('a')->join('fa_user b', 'a.user_id = b.id');
|
||||
$model = $model->where('a.follow_id', $uid)->where('a.type',1);
|
||||
$list = $model->field('a.user_id,a.createtime,b.nickname,b.avatar,b.sex,b.user_code')->order('a.id desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['is_online'] = $this->redis->get('user_online_' . $v['user_id']) ? 1: 0;//是否在线 在redis里获取
|
||||
$v['is_follow'] = 2;
|
||||
$is_follow = db::name('user_follow')->where(['user_id' => $uid, 'follow_id' => $v['user_id'],'type' => 1])->find();
|
||||
if ($is_follow) {
|
||||
$v['is_follow'] = 1;
|
||||
}
|
||||
//等级获取对应图标
|
||||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
||||
$v['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//黑名单
|
||||
public function get_blacklist($uid, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$model = Db::name('user_black')->alias('a')->join('fa_user b', 'a.user_id = b.id');
|
||||
$model = $model->where(['a.from_id' => $uid, 'a.type' => 1]);
|
||||
$list = $model->field('a.id,a.user_id,b.nickname,b.avatar,b.sex,b.createtime')->order('a.id desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
//等级获取对应图标
|
||||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
||||
$v['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//添加黑名单
|
||||
public function add_blacklist($uid, $receive_uid)
|
||||
{
|
||||
$map = [];
|
||||
$map['from_id'] = $uid;
|
||||
$map['user_id'] = $receive_uid;
|
||||
if (db::name('user_black')->where($map)->find()) {
|
||||
return ['code' => 0, 'msg' => '此用户已存在您的黑名单', 'data' => null];
|
||||
} else {
|
||||
$data = [];
|
||||
$data['from_id'] = $uid;
|
||||
$data['user_id'] = $receive_uid;
|
||||
$data['type'] = 1;
|
||||
$data['createtime'] = time();
|
||||
$res = db::name('user_black')->insert($data);
|
||||
if ($res) {
|
||||
//腾讯拉黑
|
||||
model('Tencent')->black_list_add('u'.$uid, 'u'.$receive_uid);
|
||||
return ['code' => 1, 'msg' => '添加成功', 'data' => null];
|
||||
}
|
||||
return ['code' => 0, 'msg' => '添加失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//移除黑名单
|
||||
public function remove_blacklist($uid, $receive_uid)
|
||||
{
|
||||
$map = [];
|
||||
$map['from_id'] = $uid;
|
||||
$map['user_id'] = $receive_uid;
|
||||
$res = db::name('user_black')->where($map)->delete();
|
||||
if ($res) {
|
||||
//腾讯移除黑名单
|
||||
model('Tencent')->black_list_delete('u'.$uid, 'u'.$receive_uid);
|
||||
return ['code' => 1, 'msg' => '移除成功', 'data' => null];
|
||||
}
|
||||
return ['code' => 0,'msg' => '移除失败', 'data' => null];
|
||||
}
|
||||
|
||||
//邀请码生成
|
||||
public function invite_code(){
|
||||
$code = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
|
||||
$reg_code = '';
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$reg_code .= $code[mt_rand(0, strlen($code) - 1)];
|
||||
}
|
||||
$user_info = db::name('user')->where(['init_code' => $reg_code])->find();
|
||||
if (!empty($user_info)) {
|
||||
$this->invite_code();
|
||||
}
|
||||
return $reg_code;
|
||||
}
|
||||
|
||||
//用户主页
|
||||
/*
|
||||
* @param $uid 用户id
|
||||
* @param $from_id 访问者id
|
||||
*/
|
||||
public function get_user_home($from_uid,$uid)
|
||||
{
|
||||
$user_info = db::name('user')->alias('u')->join('user_data ud', 'u.id = ud.user_id')
|
||||
->field('u.id as user_id,u.nickname,u.user_code,u.avatar,u.sex,u.birthday,u.profile,ud.tag_id,ud.home_bgimages')
|
||||
->where(['u.id' => $uid,'u.status' => ['<>',0]])->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '用户不存在或已注销', 'data' => null];
|
||||
}
|
||||
//标签
|
||||
$user_info['tag_list'] = [];
|
||||
if(isset($user_info['tag_id'])) {
|
||||
$tag_list = db::name('user_tag')->whereIn('id', explode(',', $user_info['tag_id']))->field('id,tag_name')->select();
|
||||
$user_info['tag_list'] = $tag_list;
|
||||
}
|
||||
|
||||
//礼物墙 获取收到的礼物图片名称数量 以及送每个礼物数量最多的用户的头像昵称 数量一样选最后送的用户
|
||||
$user_info['gift_wall'] = [];
|
||||
|
||||
$user_info['icon'][0] = model('UserData')->user_wealth_icon($uid) ?? '';//财富图标
|
||||
$user_info['icon'][1] = model('UserData')->user_charm_icon($uid) ?? '';//魅力图标
|
||||
|
||||
//查询用户是否有使用靓号
|
||||
$user_info['is_use_code'] = 0;
|
||||
$liang = db::name('vs_user_decorate')->where(['user_id' => $uid, 'is_using' => 1, 'type' => 6, 'end_time' => ['>=', time()]])->find();
|
||||
if($liang){
|
||||
$user_info['is_use_code'] = 1;
|
||||
$user_info['user_code'] = $liang['special_num'] ?? '';
|
||||
}
|
||||
|
||||
//是否关注
|
||||
$user_info['is_follow'] = 0;
|
||||
if (db::name('user_follow')->where(['user_id' => $from_uid, 'follow_id' => $uid])->find()) {
|
||||
$user_info['is_follow'] = 1;
|
||||
}
|
||||
//是否在房间
|
||||
$user_info['room_id'] = db::name('vs_room_visitor')->where(['user_id' => $uid, 'is_delete' => 1])->order('id desc')->value('room_id') ?? 0;
|
||||
//用户年龄
|
||||
$user_info['age'] = getAge($user_info['birthday']);
|
||||
//头像装扮
|
||||
$user_info['dress'] = model('Decorate')->user_decorate_detail($user_info['user_id'],1);
|
||||
|
||||
//记录用户访问记录
|
||||
if($from_uid != $uid){
|
||||
$this->add_user_visit_log(1,$from_uid, $uid);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $user_info];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户礼物墙信息
|
||||
* @param int $uid 用户ID
|
||||
* @return array
|
||||
*/
|
||||
public function get_user_gift_wall_info($uid)
|
||||
{
|
||||
//查询用户礼物墙 以gift_id,send_user_id分组 同一用户送的同一礼物相加
|
||||
$result = db::name('vs_give_gift')
|
||||
->where(['gift_user' => $uid])
|
||||
->field('gift_id,user_id,sum(number) as total')
|
||||
->group('gift_id,user_id')
|
||||
->order('total desc')
|
||||
->select();
|
||||
// var_dump($result);exit;
|
||||
// 根据礼物二次分组 获取礼物的总数和送的数量最多的三用户
|
||||
$data = [];
|
||||
// 按 gift_id 聚合数据
|
||||
foreach ($result as $item) {
|
||||
$giftId = $item['gift_id'];
|
||||
$sendUserId = $item['user_id'];
|
||||
$sendUserNickname = db::name('user')->where(['id' => $sendUserId])->value('nickname');
|
||||
$sendUserAvatar = db::name('user')->where(['id' => $sendUserId])->value('avatar');
|
||||
$total = $item['total'];
|
||||
|
||||
if (!isset($data[$giftId])) {
|
||||
$data[$giftId] = [
|
||||
'gift_id' => $giftId,
|
||||
'gift_price' => model('Gift')->where(['gid' => $giftId])->value('gift_price'),
|
||||
'gift_name' => model('Gift')->where(['gid' => $giftId])->value('gift_name'),
|
||||
'base_image' => model('Gift')->where(['gid' => $giftId])->value('base_image'),
|
||||
'total_count' => 0,
|
||||
'top_users' => []
|
||||
];
|
||||
}
|
||||
|
||||
// 累加总数量
|
||||
$data[$giftId]['total_count'] += $total;
|
||||
|
||||
// 存储用户赠送记录
|
||||
$data[$giftId]['top_users'][] = [
|
||||
'user_id' => $sendUserId,
|
||||
'nickname' => $sendUserNickname,
|
||||
'avatar' => $sendUserAvatar,
|
||||
'count' => $total
|
||||
];
|
||||
}
|
||||
|
||||
// 对每个礼物的 top_users 排序并取前三名
|
||||
foreach ($data as &$giftData) {
|
||||
// 按 count 降序排序
|
||||
usort($giftData['top_users'], function ($a, $b) {
|
||||
return $b['count'] <=> $a['count'];
|
||||
});
|
||||
$giftData['top_users_count'] = count($giftData['top_users']);
|
||||
// 取前3位
|
||||
$giftData['top_users'] = array_slice($giftData['top_users'], 0, 3);
|
||||
}
|
||||
$data = array_values($data);
|
||||
//查询所有的礼物
|
||||
$gift_list = db::name('vs_gift')->field('gid as gift_id,gift_name,base_image,gift_price')->where(['delete_time' => 0,'is_show' => 1])->select();
|
||||
//对比去除$data 里面的礼物
|
||||
$gift_list = array_filter((array)$gift_list, function ($item) use ($data) {
|
||||
return !in_array($item['gift_id'], array_column($data, 'gift_id'));
|
||||
});
|
||||
//数组重组 从下标0 开始
|
||||
$gift_list = array_values($gift_list);
|
||||
$redata['no_liang'] = $gift_list;
|
||||
$redata['liang'] = $data;
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $redata];
|
||||
}
|
||||
|
||||
//添加用户访问记录
|
||||
/*
|
||||
* @param $to_id 被访问对象id
|
||||
* @param $from_id 访问者id
|
||||
* @param $type 类型:1 用户主页 2 直播间
|
||||
*/
|
||||
public function add_user_visit_log($type,$from_uid,$to_uid){
|
||||
$visit = db::name('user_visit_log')->where(['from_uid' => $from_uid,'to_id' => $to_uid,'type' => $type])->find();
|
||||
if($visit){
|
||||
return true;
|
||||
}
|
||||
$data = [
|
||||
'type' => $type,
|
||||
'from_uid' => $from_uid,
|
||||
'to_id' => $to_uid,
|
||||
'createtime' => time(),
|
||||
];
|
||||
db::name('user_visit_log')->insert($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
//相册列表
|
||||
public function get_album_list($user_id){
|
||||
$album_list = db::name('user_album')->where(['user_id' => $user_id,'deletetime' => 0])->field('id,name,image,pwd,read_num,like_num')->select();
|
||||
if($album_list){
|
||||
foreach ($album_list as $k=>$item){
|
||||
if($item['pwd']){
|
||||
$album_list[$k]['is_pwd'] = 1;
|
||||
}else{
|
||||
$album_list[$k]['is_pwd'] = 0;
|
||||
}
|
||||
$album_list[$k]['img_num'] = db::name('user_album_image')->where('album_id',$item['id'])->count();
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $album_list];
|
||||
}
|
||||
|
||||
//相册详情
|
||||
public function get_album_detail($user_id,$id,$pwd, $page, $page_limit,$is_admin = 0){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$album_info = db::name('user_album')->where(['id' => $id])->field('id,image,pwd,read_num,like_num,user_id,like_user,name')->find();
|
||||
if(empty($album_info)){
|
||||
return ['code' => 0, 'msg' => '相册不存在', 'data' => null];
|
||||
}
|
||||
if($is_admin!=1){
|
||||
if($album_info['user_id'] != $user_id){
|
||||
if($album_info['pwd']){
|
||||
if($pwd != $album_info['pwd']){
|
||||
return ['code' => 0, 'msg' => '相册密码错误', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//判断是否点赞
|
||||
$album_info['is_like'] = 0;
|
||||
if(!empty($album_info['like_user'])){
|
||||
if(in_array($user_id,explode(',',$album_info['like_user']))){
|
||||
$album_info['is_like'] = 1;
|
||||
}
|
||||
}
|
||||
unset($album_info['like_user']);
|
||||
|
||||
$album_info['count'] = db::name('user_album_image')
|
||||
->where(['album_id' => $id])
|
||||
->count();
|
||||
|
||||
$album_info['image_list'] = [];
|
||||
$image_list = db::name('user_album_image')
|
||||
->where(['album_id' => $id])
|
||||
->field('id,image,content,createtime')
|
||||
->order('createtime desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
if($image_list){
|
||||
$album_info['image_list'] = $image_list;
|
||||
}
|
||||
//增加浏览次数
|
||||
db::name('user_album')->where(['id' => $id])->setInc('read_num');
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $album_info];
|
||||
}
|
||||
|
||||
//创建相册
|
||||
public function create_album($user_id,$name,$pwd,$image){
|
||||
if(empty($name)){
|
||||
return ['code' => 0, 'msg' => '相册名称不能为空', 'data' => null];
|
||||
}
|
||||
if(empty($image)){
|
||||
return ['code' => 0, 'msg' => '相册封面图不能为空', 'data' => null];
|
||||
}
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'name' => $name,
|
||||
'pwd' => $pwd,
|
||||
'image' => $image,
|
||||
'createtime' => time()
|
||||
];
|
||||
db::name('user_album')->insert($data);
|
||||
return ['code' => 1, 'msg' => '创建成功', 'data' => null];
|
||||
}
|
||||
|
||||
//添加相册图片
|
||||
public function add_album_content($user_id,$album_id,$image,$content){
|
||||
if(empty($album_id)){
|
||||
return ['code' => 0, 'msg' => '相册ID不能为空', 'data' => null];
|
||||
}
|
||||
// if(empty($content)){
|
||||
// return ['code' => 0, 'msg' => '内容不能为空', 'data' => null];
|
||||
// }
|
||||
//把图片JSON转换成数组
|
||||
$image = explode(',',$image);
|
||||
if(!empty($image)){
|
||||
foreach ($image as $v){
|
||||
$data = [
|
||||
'album_id' => $album_id,
|
||||
'image' => $v,
|
||||
'content' => $content,
|
||||
'createtime' => time()
|
||||
];
|
||||
//循环插入数据库
|
||||
db::name('user_album_image')->insert($data);
|
||||
}
|
||||
//首次创建相册并上传9张照片【完成任务】
|
||||
$user_album_image_count = db::name('user_album_image')->where('album_id',$album_id)->count();
|
||||
if($user_album_image_count >= 9){
|
||||
model('DailyTasks')->tasks_complete($user_id,14);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '添加成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '图片不能为空', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//把普通相册转为私密相册
|
||||
public function change_album_pwd($user_id,$album_id,$pwd){
|
||||
if(empty($album_id)){
|
||||
return ['code' => 0, 'msg' => '相册ID不能为空', 'data' => null];
|
||||
}
|
||||
if(empty($pwd)){
|
||||
return ['code' => 0, 'msg' => '相册密码不能为空', 'data' => null];
|
||||
}
|
||||
$album_info = db::name('user_album')->where(['id' => $album_id])->find();
|
||||
if(!$album_info){
|
||||
return ['code' => 0, 'msg' => '相册不存在', 'data' => null];
|
||||
}else{
|
||||
db::name('user_album')->where(['id' => $album_id])->update(['pwd' => $pwd]);
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//移动相册图片
|
||||
public function move_album_images($user_id,$id,$album_id){
|
||||
if(empty($id)){
|
||||
return ['code' => 0, 'msg' => '强选择想要移动的图片', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($album_id)){
|
||||
return ['code' => 0, 'msg' => '目标相册ID不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
$album_info = db::name('user_album')->where(['id' => $album_id,'user_id' => $user_id])->find();
|
||||
if(!$album_info){
|
||||
return ['code' => 0, 'msg' => '目标相册不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$ids = explode(',',$id);
|
||||
foreach ($ids as $v){
|
||||
db::name('user_album_image')->where(['id' => $v])->update(['album_id' => $album_id]);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '移动成功', 'data' => null];
|
||||
}
|
||||
|
||||
//删除相册
|
||||
public function delete_album($user_id,$album_id){
|
||||
if(empty($album_id)){
|
||||
return ['code' => 0, 'msg' => '相册ID不能为空', 'data' => null];
|
||||
}
|
||||
$album_info = db::name('user_album')->where(['id' => $album_id,'user_id' => $user_id])->find();
|
||||
if(!$album_info){
|
||||
return ['code' => 0, 'msg' => '相册不存在', 'data' => null];
|
||||
}
|
||||
db::name('user_album')->where(['id' => $album_id])->update(['deletetime' => time()]);
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
}
|
||||
|
||||
//相册点赞
|
||||
public function like_album($user_id,$album_id){
|
||||
if(empty($album_id)){
|
||||
return ['code' => 0, 'msg' => '相册ID不能为空', 'data' => null];
|
||||
}
|
||||
$album_info = db::name('user_album')->where(['id' => $album_id])->find();
|
||||
if(!$album_info){
|
||||
return ['code' => 0, 'msg' => '相册不存在', 'data' => null];
|
||||
}
|
||||
//把用户的ID添加到相册的点赞用户列表中
|
||||
if(in_array($user_id,explode(',',$album_info['like_user']))){
|
||||
//把用户的ID删除
|
||||
$album_info['like_user'] = str_replace($user_id.',', '', $album_info['like_user']);
|
||||
db::name('user_album')->where(['id' => $album_id])->update(['like_user' => $album_info['like_user']]);
|
||||
//点赞数减一
|
||||
db::name('user_album')->where(['id' => $album_id])->setDec('like_num');
|
||||
return ['code' => 1, 'msg' => '取消点赞', 'data' => null];
|
||||
}else{
|
||||
$album_info['like_user'] .= $user_id.',';
|
||||
|
||||
db::name('user_album')->where(['id' => $album_id])->update(['like_user' => $album_info['like_user']]);
|
||||
db::name('user_album')->where(['id' => $album_id])->setInc('like_num');
|
||||
return ['code' => 1, 'msg' => '点赞成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//删除相册图片
|
||||
public function delete_album_images($user_id,$id){
|
||||
if(empty($id)){
|
||||
return ['code' => 0, 'msg' => '请选择要删除的图片', 'data' => null];
|
||||
}
|
||||
$ids = explode(',',$id);
|
||||
foreach ($ids as $v){
|
||||
db::name('user_album_image')->where(['id' => $v])->delete();
|
||||
}
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
}
|
||||
|
||||
//编辑相册
|
||||
public function edit_album($user_id,$album_id,$name,$pwd,$image){
|
||||
if(empty($album_id)){
|
||||
return ['code' => 0, 'msg' => '相册ID不能为空', 'data' => null];
|
||||
}
|
||||
if(empty($name)){
|
||||
return ['code' => 0, 'msg' => '相册名称不能为空', 'data' => null];
|
||||
}
|
||||
if(empty($image)){
|
||||
return ['code' => 0, 'msg' => '封面图不能为空', 'data' => null];
|
||||
}
|
||||
$album_info = db::name('user_album')->where(['id' => $album_id,'user_id' => $user_id])->find();
|
||||
if(!$album_info){
|
||||
return ['code' => 0, 'msg' => '相册不存在', 'data' => null];
|
||||
}else{
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'image' => $image,
|
||||
'pwd' => $pwd,
|
||||
'updatetime' => time()
|
||||
];
|
||||
db::name('user_album')->where(['id' => $album_id])->update($data);
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//编辑用户信息
|
||||
public function edit_user_info($user_id,$nickname,$sex,$birthday,$profile,$avatar,$tag_id){
|
||||
$data = [];
|
||||
if(!empty($nickname)){
|
||||
//名称中不能有 系统管理 等关键字
|
||||
if(!nickname_filter($nickname)){
|
||||
return ['code' => 0, 'msg' => '名称中不能有 系统管理 等相关字', 'data' => null];
|
||||
}
|
||||
$data['nickname'] = $nickname;
|
||||
}
|
||||
if(!empty($sex)){
|
||||
$data['sex'] = $sex;
|
||||
}
|
||||
if(!empty($birthday)){
|
||||
$data['birthday'] = $birthday;
|
||||
}
|
||||
if(!empty($profile)){
|
||||
$data['profile'] = $profile;
|
||||
}
|
||||
if(!empty($avatar)){
|
||||
$data['avatar'] = $avatar;
|
||||
}
|
||||
if(!empty($tag_id)){
|
||||
$user_data['tag_id'] = $tag_id;
|
||||
}
|
||||
|
||||
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
try{
|
||||
$data['updatetime'] = time();
|
||||
|
||||
$re = db::name('user')->where(['id' => $user_id])->update($data);
|
||||
if(!$re){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败', 'data' => null];
|
||||
}
|
||||
$user_data['updatetime'] = time();
|
||||
$ree = db::name('user_data')->where(['user_id' => $user_id])->update($user_data);
|
||||
if(!$ree){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败了', 'data' => null];
|
||||
}
|
||||
if(!empty($avatar)) {
|
||||
//记录头像修改
|
||||
$save = db::name('user_avatar_log')->insert(['user_id' => $user_id, 'avatar' => $avatar, 'createtime' => time()]);
|
||||
if (!$save) {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败!', 'data' => null];
|
||||
}
|
||||
}
|
||||
db::commit();
|
||||
//推送信息去所在房间
|
||||
//查询当前所在房间
|
||||
$room_id = db::name('vs_room_visitor')->where(['user_id' => $user_id])->order('id' , 'desc')->value('room_id');
|
||||
if($room_id){
|
||||
//当前用户信息
|
||||
//推送信息
|
||||
$text['jia_jia'] = model('Decorate')->user_decorate_detail($user_id,2);
|
||||
$text['FromUserInfo'] = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$text['FromUserInfo']['dress'] = model('Decorate')->user_decorate_detail($user_id,1);
|
||||
$text['FromUserInfo']['mic_dress'] = model('Decorate')->user_decorate_detail($user_id,4);
|
||||
$text['FromUserInfo']['chat_dress'] = model('Decorate')->user_decorate_detail($user_id,5);
|
||||
$text['text'] = '用户 ' . $text['FromUserInfo']['nickname'] .' 修改了信息';
|
||||
model('Chat')->sendMsg(1035,$room_id,$text,$user_id);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
catch(\Exception $e){
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => $e, 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//修改用户背景图
|
||||
public function edit_user_bg($user_id,$image){
|
||||
|
||||
$data = [
|
||||
'home_bgimages' => $image,
|
||||
'updatetime' => time()
|
||||
];
|
||||
$re = db::name('user_data')->where(['user_id' => $user_id])->update($data);
|
||||
if(!$re){
|
||||
return ['code' => 0, 'msg' => '修改失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
|
||||
//查询用户修改头像的次数
|
||||
public function get_user_avatar_num($user_id){
|
||||
//查询用户本月修改头像的次数
|
||||
$time = strtotime(date('Y-m-01'));
|
||||
$num = db::name('user_avatar_log')->where('id' , $user_id)->where('createtime' , '>' , $time)->count();
|
||||
if(!$num){
|
||||
$num = 0;
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $num];
|
||||
}
|
||||
|
||||
//看过我的 魅力等级达到20级以上才能查看
|
||||
public function get_look_me_list($user_id,$page,$limit){
|
||||
$user_info = db::name('user')->where(['id' => $user_id])->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
//魅力等级
|
||||
$charm_level = model('UserData')->where('user_id',$user_id)->value('charm_level');
|
||||
$look_me_level = get_system_config_value('look_me_level');
|
||||
if($charm_level < $look_me_level){
|
||||
return ['code' => 0, 'msg' => '魅力等级不足', 'data' => null];
|
||||
}
|
||||
$user_data = db::name('user_visit_log')->alias('a')->join('user b','a.from_uid = b.id')
|
||||
->field('b.id as user_id,b.nickname,b.avatar,b.sex,b.birthday,a.from_uid')
|
||||
->where('a.to_id',$user_id)
|
||||
->where('a.type',1)
|
||||
->where('b.status','<>',0)
|
||||
->page($page,$limit)->select();
|
||||
foreach ($user_data as &$v){
|
||||
//等级获取对应图标
|
||||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['from_uid']);//财富图标
|
||||
$v['icon'][1] = model('UserData')->user_charm_icon($v['from_uid']);//魅力图标
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $user_data];
|
||||
}
|
||||
|
||||
//关注(回关)取消关注
|
||||
public function follow($user_id,$to_id,$type){
|
||||
if(empty($to_id)){
|
||||
return ['code' => 0, 'msg' => '要关注的ID不能为空', 'data' => null];
|
||||
}
|
||||
if($type == 1){
|
||||
if($user_id == $to_id){
|
||||
return ['code' => 0, 'msg' => '不能关注自己', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$follow_info = db::name('user_follow')->where(['user_id' => $user_id,'follow_id' => $to_id,'type' => $type])->find();
|
||||
if($follow_info){
|
||||
//取消关注
|
||||
$re = db::name('user_follow')->where(['user_id' => $user_id,'follow_id' => $to_id,'type' => $type])->delete();
|
||||
if(!$re){
|
||||
return ['code' => 0, 'msg' => '取消关注失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '取消关注成功', 'data' => null];
|
||||
}else{
|
||||
//关注
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'follow_id' => $to_id,
|
||||
'type' => $type,
|
||||
'createtime' => time()
|
||||
];
|
||||
$re = db::name('user_follow')->insert($data);
|
||||
if(!$re){
|
||||
return ['code' => 0, 'msg' => '关注失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '关注成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//更新用户ip
|
||||
public function update_user_ip($user_id,$ip){
|
||||
$data = [
|
||||
'address_ip' => $ip
|
||||
];
|
||||
$re = db::name('user')->where(['id' => $user_id])->update($data);
|
||||
if(!$re){
|
||||
return ['code' => 0, 'msg' => '更新失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '更新成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//是否可以发起私聊
|
||||
public function can_start_private_chat($user_id){
|
||||
$user_rechange = db::name('vs_user_recharge')->field('sum(money) as money')->where(['user_id' => $user_id,'pay_status' => 2])->find();
|
||||
//系统配置
|
||||
$config_money = get_system_config_value('private_chat_recharge_money');
|
||||
if($user_rechange['money'] < $config_money){
|
||||
return ['code' => 0, 'msg' => '充值金额不足', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '可以发起私聊', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
14
application/api/model/UserCp.php
Normal file
14
application/api/model/UserCp.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class UserCp extends Model
|
||||
{
|
||||
//用户关系卡(亲密拍)、关系位(真爱拍 ->有电影房)
|
||||
public function user_cp_list($uid,$user_id)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
564
application/api/model/UserData.php
Normal file
564
application/api/model/UserData.php
Normal file
@@ -0,0 +1,564 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
|
||||
class UserData extends Model
|
||||
{
|
||||
private $redis;
|
||||
|
||||
public function __construct($data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
$this->redis = \think\Cache::store('redis')->handler();
|
||||
}
|
||||
//获取腾讯IM
|
||||
public function get_tencent_im($user_id)
|
||||
{
|
||||
$tencent_im = $this->where('user_id', $user_id)->value('tencent_im');
|
||||
if(empty($tencent_im)){
|
||||
$tencent_im = model('Tencent')->tencent_user_sig_info('u'.$user_id);
|
||||
$data = [
|
||||
'nick' => db::name('user')->where('id', $user_id)->value('nickname'),
|
||||
'face_url' => db::name('user')->where('id', $user_id)->value('avatar'),
|
||||
];
|
||||
model('Tencent')->account_import($user_id,$data);
|
||||
if(empty($tencent_im)){
|
||||
return ['code' => 0, 'msg' => '获取腾讯IM唯一标识失败','data' =>null];
|
||||
}
|
||||
//更新腾讯IM唯一标识
|
||||
$this->where(['user_id' => $user_id])->update(['tencent_im' => $tencent_im]);
|
||||
}
|
||||
return $tencent_im;
|
||||
}
|
||||
|
||||
//第一次修改用户信息
|
||||
public function modify_fist_user_info($nick_name, $birthday, $sex, $head_pic,$reg_code,$uid)
|
||||
{
|
||||
$text = $nick_name;
|
||||
if(!empty($text)) {
|
||||
$result = model('Tencent')->content_moderation('Text', $text);
|
||||
if($result['code'] != 1) {
|
||||
return ['code' => 0, 'msg' => '昵称有违禁词!','data' =>null];
|
||||
}
|
||||
}
|
||||
$data = [];
|
||||
$data['id'] = $uid;
|
||||
if (!empty($nick_name)) {
|
||||
$data['nickname'] = $nick_name;
|
||||
$nick_name_info = db::name('user')->where('nickname', $nick_name)->find();
|
||||
if(!empty($nick_name_info)){
|
||||
if($uid != $nick_name_info['id']){
|
||||
return['code' => 0, 'msg' => '该昵称已被占用','data' =>null];
|
||||
}
|
||||
}
|
||||
if(mb_strlen($nick_name) > 24){
|
||||
return['code' => 0, 'msg' => '昵称长度不能超过24个字符','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($birthday)) {
|
||||
$data['birthday'] = $birthday;
|
||||
}
|
||||
if (!empty($reg_code)) {
|
||||
// $data['init_code'] = $reg_code;
|
||||
//绑定
|
||||
$reslut = model('api/Invited')->invited_bind($reg_code, $uid);
|
||||
if ($reslut['code'] == 0) {
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($head_pic)) {
|
||||
$data['avatar'] = $head_pic;
|
||||
}
|
||||
|
||||
$data['sex'] =$sex;
|
||||
$data['updatetime'] = time();
|
||||
|
||||
$reslut = model('User')->update($data);
|
||||
if ($reslut) {
|
||||
$user_info = model('User')->where('id', $uid)->field('id,nickname,avatar,user_code')->find();
|
||||
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => $user_info];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '修改失败,','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
//根据性别选择用户头像
|
||||
public function modify_pic_user_info($sex)
|
||||
{
|
||||
if (empty($sex)){
|
||||
return ['code' => 0, 'msg' => '选择性别!','data' =>null];
|
||||
}
|
||||
if ($sex==1){
|
||||
$impag = Db::name('user_head_pic')
|
||||
->where('sex',1)->where('is_delete',1)->orderRaw('rand()')->find();
|
||||
if(empty($impag)){
|
||||
return ['code' => 0, 'msg' => '暂无头像','data' =>null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '男生图像', 'data' => $impag['head_pic']];
|
||||
}
|
||||
|
||||
if ($sex==2){
|
||||
$impag = Db::name('user_head_pic')
|
||||
->where('sex',2)->where('is_delete',1)->orderRaw('rand()')->find();
|
||||
if(empty($impag)){
|
||||
return ['code' => 0, 'msg' => '暂无头像','data' =>null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '女生图像', 'data' => $impag['head_pic']];
|
||||
}
|
||||
return ['code' => 0, 'msg' => '获取失败','data' =>null];
|
||||
}
|
||||
|
||||
//修改用户 信息
|
||||
public function modify_user_info($uid, $nick_name, $birthday, $sex, $head_pic, $images, $autograph,$tag_id)
|
||||
{
|
||||
$text = $nick_name . $autograph ;
|
||||
if(!empty($text)) {
|
||||
$result = model('Tencent')->content_moderation('Text', $text);
|
||||
if($result['code'] != 1) {
|
||||
return ['code' => 0, 'msg' => '昵称或简介有违禁词!','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
if (!empty($nick_name)) {
|
||||
$data['nick_name'] = $nick_name;
|
||||
$data['base64_nick_name'] = base64_encode($nick_name);
|
||||
$nick_name_info = db::name('user')->where('base64_nick_name', $data['base64_nick_name'])->find();
|
||||
if(!empty($nick_name_info)){
|
||||
if($uid != $nick_name_info['uid']){
|
||||
return['code' => 0, 'msg' => '该昵称已被占用','data' =>null];
|
||||
}
|
||||
}
|
||||
if(mb_strlen($nick_name) > 24){
|
||||
return['code' => 0, 'msg' => '昵称长度不能超过24个字符','data' =>null];
|
||||
}
|
||||
}
|
||||
if (!empty($birthday)) {
|
||||
$data['birthday'] = $birthday;
|
||||
$constellation = $this->get_user_constellation($birthday);
|
||||
$data['constellation'] = $constellation['data'];
|
||||
}
|
||||
|
||||
if (!empty($head_pic)) {
|
||||
// $data['head_pic'] = $param['path'];
|
||||
$filepath_url = get_filepath_url();
|
||||
$params = parse_url($filepath_url);
|
||||
$param = parse_url($head_pic);
|
||||
if(isset($param['host'])) {
|
||||
if (!empty($param['path'])) {
|
||||
if($params['host'] == $param['host']) {
|
||||
$head_pic = $param['path'];
|
||||
$head_pic = trim($head_pic, '/');
|
||||
}
|
||||
$data['head_pic'] = $head_pic;
|
||||
}
|
||||
} else {
|
||||
$data['head_pic'] = $head_pic;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($autograph)) {
|
||||
$data['autograph'] = $autograph;
|
||||
}
|
||||
|
||||
$validate = validate('admin/User');
|
||||
$reslut = $validate->scene('apiEditInfo')->check($data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 0, 'msg' => $validate->getError(),'data' =>null];
|
||||
}
|
||||
$data['sex'] = $sex;
|
||||
$data['update_time'] = time();
|
||||
|
||||
$images_data = explode(',', json_decode($images));
|
||||
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
try{
|
||||
$reslut = db::name('user')->where('uid', $uid)->update($data);
|
||||
if (!$reslut) {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
$tag_data = [];
|
||||
if(!empty($tag_id)){
|
||||
//删除之前的标签
|
||||
$deldt['tag_id'] = '';
|
||||
$delres = db::name('user_data')->where('uid', $uid)->update($deldt);
|
||||
if (!$delres) {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
$tag_data['tag_id'] = $tag_id;
|
||||
$tareslut = db::name('user_data')->where('uid', $uid)->update($tag_data);
|
||||
if (!$tareslut) {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
}
|
||||
if (!empty($images_data)) {
|
||||
//删除之前的图片
|
||||
$deldata['is_delete'] = 2;
|
||||
$deldata['delete_time'] = time();
|
||||
$reslutd = db::name('user_home_bgimages')->where('uid', $uid)->update($deldata);
|
||||
if($reslutd){
|
||||
//循环插入图片
|
||||
$dd['uid'] = $uid;
|
||||
$dd['add_time'] = time();
|
||||
$dd['update_time'] = time();
|
||||
foreach ($images_data as $key => $value) {
|
||||
$dd['image'] = $value;
|
||||
db::name('user_home_bgimages')->insert($dd);
|
||||
}
|
||||
}else {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '修改成功','data' =>null];
|
||||
} catch (\Exception $e) {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//修改,设置用户密码
|
||||
public function modify_password($password,$user_id)
|
||||
{
|
||||
if (empty($user_id)) {
|
||||
return ['code' => 0, 'msg' => '登录失效,请重新登录','data' =>null];
|
||||
}
|
||||
|
||||
$reslut = db::name('user')->where('id' , $user_id)->update(['password' => md5($password)]);
|
||||
|
||||
if ($reslut) {
|
||||
return ['code' => 1, 'msg' => '修改成功','data' =>null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
//修改手机号
|
||||
public function modify_mobile($new_mobile,$user_id)
|
||||
{
|
||||
//查询旧手机号
|
||||
$mobile = db::name('user')->where(['id' => $user_id])->value('user_name');
|
||||
//查询是否实名
|
||||
$is_real = db::name('user_auth')->where(['mobile' => $mobile,'is_real' => 1])->find();
|
||||
if($is_real){
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
//修改实名手机号
|
||||
$red = db::name('user_auth')->where(['id' => $is_real['id']])->update(['mobile' => $new_mobile]);
|
||||
$reslut = db::name('user')->where(['id' => $user_id])->update(['user_name' => $new_mobile]);
|
||||
if ($reslut && $red) {
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '修改成功','data' =>null];
|
||||
} else {
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
}else{
|
||||
$reslut = db::name('user')->where(['id' => $user_id])->update(['user_name' => $new_mobile]);
|
||||
if ($reslut) {
|
||||
return ['code' => 1, 'msg' => '修改成功','data' =>null];
|
||||
}
|
||||
}
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
|
||||
//实名认证
|
||||
public function real_name($user_id,$real_name,$id_card)
|
||||
{
|
||||
$user_mobile = db::name('user')->where(['id' => $user_id,'status'=>1])->value('mobile');
|
||||
if(empty($user_mobile)){
|
||||
return ['code' => 0, 'msg' => '请先绑定手机号','data' =>null];
|
||||
}
|
||||
$auth = [
|
||||
'mobile' => $user_mobile,
|
||||
'real_name' => $real_name,
|
||||
'card_id' => $id_card,
|
||||
'is_real' => 3
|
||||
];
|
||||
db::name('user_auth')->insert($auth);
|
||||
|
||||
$config = get_system_config();
|
||||
//获取Access Token
|
||||
$access_token = $this->redis->get('access_token_'.$config['tencent_app_id']);
|
||||
//判断是否过期
|
||||
if(empty($access_token)){
|
||||
$access_token = model('Tencent')->getAccessToken($config['tencent_app_id'],$config['tencent_app_secret']);
|
||||
$this->redis->set('access_token_'.$config['tencent_app_id'],$access_token,1000);
|
||||
sleep(1);
|
||||
//获取SignTicket
|
||||
$sign_ticket = model('Tencent')->getSignTicket($access_token,$config['tencent_app_id']);
|
||||
$this->redis->set('sign_ticket_'.$config['tencent_app_id'],$sign_ticket,1100);
|
||||
}
|
||||
$sign_ticket = $this->redis->get('sign_ticket_'.$config['tencent_app_id']);
|
||||
|
||||
//获取NONCE Ticket
|
||||
$nonce_ticket = model('Tencent')->getNonceTicket($access_token,$user_id,$config['tencent_app_id']);
|
||||
//获取随机字符串
|
||||
$nonceStr = generateRandom(32);
|
||||
//生成一个订单号 并保存在redis
|
||||
$orderNo = generateRandom(12);
|
||||
//保存在redis
|
||||
$this->redis->set('order_no_tencent_'.$user_id,$orderNo,3600);
|
||||
//生成签名
|
||||
$sign = model('Tencent')->getSign($user_id,$nonceStr,$sign_ticket,$config['tencent_app_id']);
|
||||
//生成faceId
|
||||
$faceId = model('Tencent')->getFaceId($orderNo,$real_name,$id_card,$sign,$user_id,$config['tencent_app_id'],$nonceStr);
|
||||
|
||||
$data = [
|
||||
'userid' => 'u'.$user_id,
|
||||
'nonce' => $nonceStr,
|
||||
'sign' => $sign,
|
||||
'appid' => $config['tencent_app_id'],
|
||||
'orderNo' => $orderNo,
|
||||
'apiVersion'=>'1.0.0',
|
||||
'licence'=>$config['tencent_licence'],
|
||||
'faceId' => $faceId
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功','data' =>$data];
|
||||
}
|
||||
|
||||
//实名认证结果
|
||||
public function real_name_result($user_id,$orderNo)
|
||||
{
|
||||
$user_mobile = db::name('user')->where(['id' => $user_id,'status'=>1])->value('mobile');
|
||||
//修改状态
|
||||
$reslut = db::name('user_auth')->where('mobile' , $user_mobile)->update(['is_real' => 1]);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '实名失败','data' =>null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '实名成功','data' =>null];
|
||||
}
|
||||
|
||||
//实名认证后的信息
|
||||
public function real_name_info($user_id)
|
||||
{
|
||||
$mobile = db::name('user')->where(['id' => $user_id,'status'=>1])->value('mobile');
|
||||
$data = db::name('user_auth')->where('mobile' , $mobile)->field('real_name,card_id,is_real,mobile')->find();
|
||||
if(!$data){
|
||||
return ['code' => 0, 'msg' => '未实名','data' =>null];
|
||||
}
|
||||
|
||||
$datas = [
|
||||
'real_name' => name_format($data['real_name']),
|
||||
'card_id' => id_format($data['card_id']),
|
||||
'mobile' => $data['mobile'],
|
||||
'is_real' => $data['is_real']
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功','data' =>$datas];
|
||||
}
|
||||
|
||||
//用户的财富等级和经验值
|
||||
public function user_wealth_icon($user_id)
|
||||
{
|
||||
$data = $this->field('wealth_level,wealth_exp')->where('user_id',$user_id)->find();
|
||||
if(!$data){
|
||||
return localpath_to_netpath('data/default/xin.png');
|
||||
}
|
||||
$icon = db::name('vs_wealth_level')->where('level',$data['wealth_level'])->value('image');
|
||||
if($icon == ''){
|
||||
return localpath_to_netpath('data/default/xin.png');
|
||||
}
|
||||
return $icon;
|
||||
}
|
||||
|
||||
//用户的魅力等级和经验值
|
||||
public function user_charm_icon($user_id)
|
||||
{
|
||||
$data = $this->field('charm_level,charm_exp')->where('user_id',$user_id)->find();
|
||||
if(!$data){
|
||||
return localpath_to_netpath('data/default/xin.png');
|
||||
}
|
||||
$icon = db::name('vs_charm_level')->where('level',$data['charm_level'])->value('image');
|
||||
if($icon == ''){
|
||||
return localpath_to_netpath('data/default/xin.png');
|
||||
}
|
||||
return $icon;
|
||||
}
|
||||
|
||||
//房间历史足迹
|
||||
public function user_room_history_list($uid,$page,$page_limit){
|
||||
$list = db::name('user_visit_log')->alias('a')->join('fa_vs_room b','a.to_id = b.id')
|
||||
->field('b.id as room_id,b.room_number,b.room_name,b.room_cover,b.room_intro,b.label_id,b.room_password,b.is_show_room,b.today_hot_value as hot_value')
|
||||
->where('a.from_uid',$uid)
|
||||
->where('a.type',2)
|
||||
->where('b.type_id','<>',6)
|
||||
->where('b.room_status',1)
|
||||
->order('a.id desc')
|
||||
->page($page,$page_limit)
|
||||
->select();
|
||||
if($list){
|
||||
foreach($list as &$item){
|
||||
if($item['is_show_room'] == 2){ //是否显示房间 1是2否
|
||||
//查询当前房间是否有主持在麦上
|
||||
$room_host_info = db::name('vs_room_pit')->where(['room_id' => $item['room_id'], 'pit_number' => 9])->value('user_id');
|
||||
if($room_host_info == 0){
|
||||
unset($list[$item]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$item['label_icon'] = db::name('vs_room_label')->where('id',$item['label_id'])->value('label_icon');
|
||||
//获取房间用户总数
|
||||
$item['user_count'] = db::name('vs_room_visitor')->where('room_id',$item['room_id'])->count();
|
||||
//房间是否有靓号 7房间靓号
|
||||
$item['room_number'] = model('Decorate')->user_decorate_detail($item['room_id'],7);
|
||||
// $item['hot_value'] = $item['hot_value'] * 10;
|
||||
}
|
||||
$list = array_values((array)$list);
|
||||
}else{
|
||||
$list = [];
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功','data' =>$list];
|
||||
}
|
||||
|
||||
//删除房间历史足迹
|
||||
public function delete_room_history($uid){
|
||||
$reslut = db::name('user_visit_log')->where(['from_uid' => $uid,'type' => 2])->delete();
|
||||
if($reslut){
|
||||
return ['code' => 1, 'msg' => '删除成功','data' =>null];
|
||||
}
|
||||
return ['code' => 0, 'msg' => '删除失败','data' =>null];
|
||||
}
|
||||
|
||||
|
||||
//绑定提现账户的信息
|
||||
public function bind_withdraw_account($user_id,$system='')
|
||||
{
|
||||
if($system == 'iOS'){
|
||||
$lists['ali']['name'] = "支付宝";
|
||||
$lists['wx']['name'] = "微信";
|
||||
$lists['bank']['name'] = "银行卡";
|
||||
$lists['ali_tl']['name'] = "支付宝(通联)";
|
||||
$lists['wx_tl']['name'] = "微信(通联)";
|
||||
$lists['ali']['icon'] = localpath_to_netpath('data/default/alipay.png');
|
||||
$lists['wx']['icon'] = localpath_to_netpath('data/default/wxpay.png');
|
||||
$lists['bank']['icon'] = localpath_to_netpath('data/default/bankpay.png');
|
||||
$lists['ali_tl']['icon'] = localpath_to_netpath('data/default/alipay.png');
|
||||
$lists['wx_tl']['icon'] = localpath_to_netpath('data/default/wxpay.png');
|
||||
$lists['ali']['is_with_draw_open'] = get_system_config_value('withdraw_ali');
|
||||
$lists['wx']['is_with_draw_open'] = get_system_config_value('withdraw_wx');
|
||||
$lists['bank']['is_with_draw_open'] = get_system_config_value('withdraw_bank');
|
||||
$lists['ali_tl']['is_with_draw_open'] = 0;
|
||||
$lists['wx_tl']['is_with_draw_open'] = 0;
|
||||
$lists['ali']['is_bind'] = db::name('user_data')->where('user_id',$user_id)->value('alipay_account') ? 1 : 0;
|
||||
$lists['wx']['is_bind'] = 0;
|
||||
$lists['bank']['is_bind'] = db::name('user_data')->where('user_id',$user_id)->value('bank_card_number') ? 1 : 0;
|
||||
$lists['ali_tl']['is_bind'] = 0;
|
||||
$lists['wx_tl']['is_bind'] = 0;
|
||||
$lists['ali']['type'] = 2;
|
||||
$lists['wx']['type'] = 1;
|
||||
$lists['bank']['type'] = 3;
|
||||
$lists['ali_tl']['type'] = 4;
|
||||
$lists['wx_tl']['type'] = 5;
|
||||
// $lists['ali']['is_pay_open'] = 0;
|
||||
// $lists['wx']['is_pay_open'] = 0;
|
||||
// $lists['bank']['is_pay_open'] = 0;
|
||||
// $lists['ali_tl']['is_pay_open'] = 0;
|
||||
// $lists['wx_tl']['is_pay_open'] = 0;
|
||||
$lists['ali']['is_pay_open'] = get_system_config_value('pay_open_ali');
|
||||
$lists['wx']['is_pay_open'] = get_system_config_value('pay_open_wx');
|
||||
$lists['bank']['is_pay_open'] = get_system_config_value('pay_open_bank');
|
||||
$lists['ali_tl']['is_pay_open'] = get_system_config_value('pay_open_ali_tl');
|
||||
$lists['wx_tl']['is_pay_open'] = get_system_config_value('pay_open_wx_tl');
|
||||
}else{
|
||||
$lists['ali']['name'] = "支付宝";
|
||||
$lists['wx']['name'] = "微信";
|
||||
$lists['bank']['name'] = "银行卡";
|
||||
$lists['ali_tl']['name'] = "支付宝(通联)";
|
||||
$lists['wx_tl']['name'] = "微信(通联)";
|
||||
$lists['ali']['icon'] = localpath_to_netpath('data/default/alipay.png');
|
||||
$lists['wx']['icon'] = localpath_to_netpath('data/default/wxpay.png');
|
||||
$lists['bank']['icon'] = localpath_to_netpath('data/default/bankpay.png');
|
||||
$lists['ali_tl']['icon'] = localpath_to_netpath('data/default/alipay.png');
|
||||
$lists['wx_tl']['icon'] = localpath_to_netpath('data/default/wxpay.png');
|
||||
$lists['ali']['is_with_draw_open'] = get_system_config_value('withdraw_ali');
|
||||
$lists['wx']['is_with_draw_open'] = get_system_config_value('withdraw_wx');
|
||||
$lists['bank']['is_with_draw_open'] = get_system_config_value('withdraw_bank');
|
||||
$lists['ali_tl']['is_with_draw_open'] = 0;
|
||||
$lists['wx_tl']['is_with_draw_open'] = 0;
|
||||
$lists['ali']['is_bind'] = db::name('user_data')->where('user_id',$user_id)->value('alipay_account') ? 1 : 0;
|
||||
$lists['wx']['is_bind'] = 0;
|
||||
$lists['bank']['is_bind'] = db::name('user_data')->where('user_id',$user_id)->value('bank_card_number') ? 1 : 0;
|
||||
$lists['ali_tl']['is_bind'] = 0;
|
||||
$lists['wx_tl']['is_bind'] = 0;
|
||||
$lists['ali']['type'] = 2;
|
||||
$lists['wx']['type'] = 1;
|
||||
$lists['bank']['type'] = 3;
|
||||
$lists['ali_tl']['type'] = 4;
|
||||
$lists['wx_tl']['type'] = 5;
|
||||
$lists['ali']['is_pay_open'] = get_system_config_value('pay_open_ali');
|
||||
$lists['wx']['is_pay_open'] = get_system_config_value('pay_open_wx');
|
||||
$lists['bank']['is_pay_open'] = get_system_config_value('pay_open_bank');
|
||||
$lists['ali_tl']['is_pay_open'] = get_system_config_value('pay_open_ali_tl');
|
||||
$lists['wx_tl']['is_pay_open'] = get_system_config_value('pay_open_wx_tl');
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功','data' =>$lists];
|
||||
}
|
||||
|
||||
//绑定
|
||||
public function bind_xinxi($user_id,$type,$alipay_account,$bank_card_number,$bank_user_name,$bank_card,$open_bank)
|
||||
{
|
||||
if($type == 2){
|
||||
$data = [
|
||||
// 'alipay_name' => $alipay_name,// 姓名
|
||||
'alipay_account' => $alipay_account,// 支付宝账号
|
||||
];
|
||||
$reslut = db::name('user_data')->where('user_id',$user_id)->update($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '绑定失败','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
if($type == 3){
|
||||
$data = [
|
||||
'bank_card_number' => $bank_card_number,
|
||||
'bank_user_name' => $bank_user_name,
|
||||
'bank_card' => $bank_card,
|
||||
'open_bank' => $open_bank,
|
||||
];
|
||||
$reslut = db::name('user_data')->where('user_id',$user_id)->update($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '绑定失败','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
// if($type == 3){
|
||||
// $data = [
|
||||
// 'user_id' => $user_id,
|
||||
// ];
|
||||
// $reslut = db::name('user_data')->where('user_id',$user_id)->update($data);
|
||||
// if(!$reslut){
|
||||
// return ['code' => 0, 'msg' => '绑定失败','data' =>null];
|
||||
// }
|
||||
// }
|
||||
return ['code' => 1, 'msg' => '绑定成功','data' =>null];
|
||||
}
|
||||
|
||||
//绑定的详情
|
||||
public function bind_xinxi_detail($user_id,$type)
|
||||
{
|
||||
if($type == 2){
|
||||
$data = db::name('user_data')->where('user_id',$user_id)->field('id,alipay_name,alipay_account')->find();
|
||||
}
|
||||
if($type == 3){
|
||||
$data = db::name('user_data')->where('user_id',$user_id)->field('id,bank_card_number,bank_user_name,bank_card,open_bank')->find();
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功','data' =>$data];
|
||||
}
|
||||
}
|
||||
218
application/api/model/UserGiftPack.php
Normal file
218
application/api/model/UserGiftPack.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
use think\Db;
|
||||
|
||||
class UserGiftPack extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
|
||||
// 初始化
|
||||
//fa_vs_user_gift_pack_log type
|
||||
//log_type
|
||||
//系统赠送
|
||||
const SYSTEM_ADJUSTMENT = 1;
|
||||
//礼包获得
|
||||
const GIFT_PACK_GET = 2;
|
||||
//礼物赠送
|
||||
const GIFT_SEND = 3;
|
||||
//系统扣除
|
||||
const SYSTEM_DEDUCTION = 4;
|
||||
//礼物使用
|
||||
const GIFT_USE = 5;
|
||||
//首充获得
|
||||
const FIRST_CHARGE = 6;
|
||||
//天降好礼
|
||||
const DRAW_GIFT = 7;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
self::beforeWrite(function ($row) {
|
||||
});
|
||||
}
|
||||
public static function TypeLable()
|
||||
{
|
||||
//1系统赠送2宝箱获得3个人赠送
|
||||
return [
|
||||
self::SYSTEM_ADJUSTMENT => '系统赠送',
|
||||
self::GIFT_PACK_GET => '礼包获得',
|
||||
self::GIFT_SEND => '礼物赠送',
|
||||
self::SYSTEM_DEDUCTION => '系统扣除',
|
||||
self::GIFT_USE => '礼物使用',
|
||||
self::FIRST_CHARGE => '首充获得',
|
||||
self::DRAW_GIFT => '天降好礼获得'
|
||||
];
|
||||
}
|
||||
|
||||
// 获取背包列表
|
||||
public function get_gift_pack_list($uid)
|
||||
{
|
||||
$model = Db::name('vs_user_gift_pack')->alias('a')->join('fa_vs_gift b', 'a.gid = b.gid');
|
||||
$model = $model->where(['a.user_id'=>$uid,'a.is_use_give'=>1,'a.num'=>['>',0]]);
|
||||
$list = $model->field('a.num,b.gid,b.gift_name,b.base_image,b.gift_price,b.sort')->order('b.sort desc')->select();
|
||||
$return_data = [];
|
||||
foreach ($list as $k => $v) {
|
||||
$return_data[$k]['gift_id'] = $v['gid'];
|
||||
$return_data[$k]['gift_name'] = $v['gift_name'];
|
||||
$return_data[$k]['base_image'] = $v['base_image'];
|
||||
$return_data[$k]['gift_price'] = $v['gift_price'];
|
||||
$return_data[$k]['num'] = $v['num'];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $return_data];
|
||||
}
|
||||
//背包收入
|
||||
public function income_user_gift_pack($uid,$page=1,$page_limit=10)
|
||||
{
|
||||
$type = [
|
||||
self::SYSTEM_ADJUSTMENT,
|
||||
self::GIFT_PACK_GET,
|
||||
// self::GIFT_SEND,
|
||||
self::FIRST_CHARGE,
|
||||
self::DRAW_GIFT
|
||||
];
|
||||
//获取背包日志列表
|
||||
$log_model = Db::name('vs_user_gift_pack_log')->where(['user_id'=>$uid])->whereIn('type', $type)
|
||||
->order('createtime desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
if (empty($log_model)) {
|
||||
return ['code' => 0, 'msg' => '没有数据', 'data' => null];
|
||||
}
|
||||
$list = [];
|
||||
foreach ($log_model as $k => $v){
|
||||
$gift_info = db::name('vs_gift')->where(['gid'=>$v['gid']])->find();
|
||||
$list[$k]['remarks'] = $v['remarks'];
|
||||
$list[$k]['gift_num'] = $v['change_num'];
|
||||
$list[$k]['gift_name'] = "X".$v['change_num'].$gift_info['gift_name'];
|
||||
$list[$k]['gift_image'] = $gift_info['play_image'];
|
||||
$list[$k]['time'] = date('Y-m-d H:i:s', $v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
|
||||
}
|
||||
//背包礼物支出列表
|
||||
public function get_gift_pack_outcome($uid, $page = 1, $page_limit = 10)
|
||||
{
|
||||
$type = [
|
||||
self::SYSTEM_DEDUCTION,
|
||||
self::GIFT_USE,
|
||||
self::GIFT_SEND
|
||||
];
|
||||
$log_model = Db::name('vs_user_gift_pack_log')->where(['user_id'=>$uid])->whereIn('type', $type)
|
||||
->order('createtime desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
if (empty($log_model)) {
|
||||
return ['code' => 0, 'msg' => '没有数据', 'data' => null];
|
||||
}
|
||||
$list = [];
|
||||
foreach ($log_model as $k => $v){
|
||||
$gift_info = db::name('vs_gift')->where(['gid'=>$v['gid']])->find();
|
||||
$list[$k]['remarks'] = $v['remarks'];
|
||||
$list[$k]['gift_num'] = $v['change_num'];
|
||||
$list[$k]['gift_name'] = "-".$v['change_num'].$gift_info['gift_name'];
|
||||
$list[$k]['gift_image'] = $gift_info['play_image'];
|
||||
$list[$k]['time'] = date('Y-m-d H:i:s', $v['createtime']);
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//背包变更
|
||||
public function change_user_gift_pack($uid, $gid, $num,$type, $remarks = '')
|
||||
{
|
||||
$TypeLable = $this->TypeLable();
|
||||
if (!in_array($type, array_keys($TypeLable))) {
|
||||
return ['code' => 0, 'msg' => 'type参数非法', 'data' => null];
|
||||
}
|
||||
if(empty($remarks)){
|
||||
$remarks = $TypeLable[$type];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$user_gift_pack_info = db::name('vs_user_gift_pack')->where(['user_id' => $uid, 'gid' => $gid])->find();
|
||||
if (empty($user_gift_pack_info) && $num > 0) {
|
||||
$data = [];
|
||||
$data['user_id'] = $uid;
|
||||
$data['gid'] = $gid;
|
||||
$data['total_num'] = $num;
|
||||
$data['num'] = $num;
|
||||
$data['createtime'] = time();
|
||||
$data['updatetime'] = time();
|
||||
$reslut = db::name('vs_user_gift_pack')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
if ($num > 0) {
|
||||
$reslut = db::name('vs_user_gift_pack')->where('pid', '=', $user_gift_pack_info['pid'])->setInc('total_num', $num);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
$reslut = db::name('vs_user_gift_pack')->where('pid', '=', $user_gift_pack_info['pid'])->setInc('num', $num);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
} elseif ($num < 0) {
|
||||
if(empty($user_gift_pack_info) || $user_gift_pack_info['num'] < abs($num)){
|
||||
return ['code' => 0, 'msg' => '礼物数量不足', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map = [
|
||||
'pid'=>$user_gift_pack_info['pid'],
|
||||
'num'=>['>=', abs($num)]
|
||||
];
|
||||
$reslut = db::name('vs_user_gift_pack')->where($map)->setInc('num', $num);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '无效礼物数量', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
//写入背包日志
|
||||
$log_data = [];
|
||||
$log_data['user_id'] = $uid;
|
||||
$log_data['gid'] = $gid;
|
||||
$log_data['type'] = $type;
|
||||
$log_data['change_num'] = $num;
|
||||
if (empty($user_gift_pack_info)){
|
||||
$log_data['after_num'] = $num;
|
||||
}else {
|
||||
$log_data['after_num'] = $user_gift_pack_info['num'] + $num;
|
||||
}
|
||||
$log_data['remarks'] = $remarks;
|
||||
$log_data['createtime'] = time();
|
||||
$log_data['updatetime'] = time();
|
||||
$log_reslut = db::name('vs_user_gift_pack_log')->insert($log_data);
|
||||
if (!$log_reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试', 'data' => null];
|
||||
} else {
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $e->getMessage(), 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
159
application/api/model/UserMessage.php
Normal file
159
application/api/model/UserMessage.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserMessage extends Model
|
||||
{
|
||||
//系统消息接口【废弃】
|
||||
public function get_message($uid,$message_id)
|
||||
{
|
||||
//获取系统消息
|
||||
$mesage = db::name('system_message')
|
||||
->where('id', $message_id)
|
||||
->find();
|
||||
if(!$mesage){
|
||||
return ['code' => 0, 'msg' => '消息不存在', 'data' => null];
|
||||
}
|
||||
//插入用户消息表
|
||||
$data = [];
|
||||
$data['source_id'] = $message_id;
|
||||
$data['user_id'] = $uid;
|
||||
$data['type'] = $mesage['type'];
|
||||
$data['title'] = $mesage['title'];
|
||||
$data['content'] = $mesage['content'];
|
||||
$data['image'] = $mesage['image'];
|
||||
$data['room_id'] = $mesage['room_id'];
|
||||
$data['url'] = $mesage['url'];
|
||||
$data['createtime'] = time();
|
||||
$res = db::name('user_message')->insert($data);
|
||||
if ($res) {
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '获取失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//系统封面消息接口
|
||||
public function get_user_message_cover_info($uid)
|
||||
{
|
||||
//获取系统消息
|
||||
$system_message = db::name('system_message')
|
||||
->where('type', 1)//1系统消息 3公告下的房间推荐,4公告下的活动'
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->count();
|
||||
|
||||
//自己已经阅读过的信息
|
||||
$user_read_message = db::name('user_message')
|
||||
->where(['user_id' => $uid,'type' => 1])
|
||||
->count();
|
||||
|
||||
$system_no_read_count = $system_message - $user_read_message;
|
||||
$system_last_message = db::name('system_message')
|
||||
->where('type', 1)//1系统消息 3公告下的房间推荐,4公告下的活动'
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->order('id desc')
|
||||
->find() ?? null;
|
||||
|
||||
//获取2官方公告
|
||||
$map['type'] = ['in' , [3, 4]];
|
||||
$system_message1 = db::name('system_message')
|
||||
->field('id')
|
||||
->where($map)
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->select();
|
||||
|
||||
//自己已经阅读过的信息
|
||||
$map['user_id'] = $uid;
|
||||
$user_read_message1 = db::name('user_message')
|
||||
->field('source_id')
|
||||
->where($map)
|
||||
->select();
|
||||
|
||||
$announcement_read_count = count($system_message1) - count($user_read_message1);
|
||||
unset($map['user_id']);
|
||||
$announcement_last_message = db::name('system_message')
|
||||
->where($map)
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->order('id desc')
|
||||
->find() ?? null;
|
||||
|
||||
$data = [];
|
||||
$data['system_no_read_count'] = max($system_no_read_count, 0);
|
||||
$data['system_last_message'] = $system_last_message;
|
||||
$data['announcement_read_count'] = $announcement_read_count;
|
||||
$data['announcement_last_message'] = $announcement_last_message;
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//消息列表接口
|
||||
public function get_user_message_list($uid, $type, $page, $page_limit)
|
||||
{
|
||||
if (!in_array($type, [1, 2])) {
|
||||
return ['code' => 0, 'msg' => 'type非法参数', 'data' => null];
|
||||
}
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
|
||||
if($type == 1){
|
||||
$where['type'] = $type;
|
||||
}else{
|
||||
$where['type'] = ['in' , [3, 4]];
|
||||
}
|
||||
//获取系统消息
|
||||
$system_message = db::name('system_message')
|
||||
->field('id as source_id')
|
||||
->where($where)//1系统消息 3公告下的房间推荐,4公告下的活动'
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->select();
|
||||
|
||||
//自己已经阅读过的信息
|
||||
$where['user_id'] = $uid;
|
||||
$user_read_message = db::name('user_message')
|
||||
->field('source_id')
|
||||
->where($where)
|
||||
->select();
|
||||
//取出$system_message和$user_read_message 的差集
|
||||
// 提取 source_id 列表
|
||||
$systemMessageIds = array_column((array)$system_message, 'source_id');
|
||||
$userReadMessageIds = array_column((array)$user_read_message, 'source_id');
|
||||
|
||||
// 获取未读消息 ID
|
||||
$unreadMessageIds = array_diff($systemMessageIds, $userReadMessageIds);
|
||||
|
||||
unset($where['user_id']);
|
||||
if($unreadMessageIds){ //阅读过插入到用户消息表
|
||||
foreach ($unreadMessageIds as $k=>$v){
|
||||
$data_s = db::name('system_message')->field('id,type')->where('id', $v)->where($where)->find();
|
||||
$data[$k]['type'] = $data_s['type'];
|
||||
$data[$k]['source_id'] = $data_s['id'];
|
||||
$data[$k]['user_id'] = $uid;
|
||||
$data[$k]['createtime'] = time();
|
||||
db::name('user_message')->insert($data[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
//获取消息
|
||||
$list = db::name('system_message')
|
||||
->where($where)
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->order('id desc')
|
||||
->page($page, $page_limit)->select();
|
||||
if($list){
|
||||
foreach ($list as &$v){
|
||||
if($v['type'] == 1){
|
||||
$v['content'] = '【'.$v['title'].'】' . $v['content'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
}
|
||||
84
application/api/model/UserMode.php
Normal file
84
application/api/model/UserMode.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use think\Session;
|
||||
|
||||
class UserMode extends Model
|
||||
{
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = true;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
public function __construct($data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
// $this->table = config('database.prefix').'user_mode';
|
||||
}
|
||||
|
||||
//开启、修改青少年模式
|
||||
public function open_teen_mode($uid, $type, $password, $again_password){
|
||||
$user_info = model('User')->get_user_info($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($password != $again_password){
|
||||
return ['code' => 0, 'msg' => '两次密码不一致', 'data' => null];
|
||||
}
|
||||
if($user_info['is_real']!=1){
|
||||
return ['code' => 0, 'msg' => '未实名认证无法开启青少年模式', 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
if($type == 1){//开启
|
||||
$msg = '开启';
|
||||
$data['is_teenager'] = 1;
|
||||
$data['teenager_password'] = md5($password);
|
||||
}else if($type == 2){//修改密码
|
||||
if($user_info['is_teenager'] == 2){
|
||||
return ['code' => 0, 'msg' => '青少年模式尚未开启', 'data' => null];
|
||||
}
|
||||
$msg = '修改';
|
||||
$data['teenager_password'] = md5($password);
|
||||
$data['updatetime'] = time();
|
||||
}
|
||||
$reslut = $this->where('user_id', $uid)->update($data);
|
||||
if($reslut){
|
||||
return ['code' => 1, 'msg' => $msg.'成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $msg.'失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//关闭、修改青少年模式
|
||||
public function close_teen_mode($uid, $type, $password){
|
||||
$user_info = model('User')->get_user_info($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info['is_teenager'] == 2){
|
||||
return ['code' => 0, 'msg' => '青少年模式尚未开启', 'data' => null];
|
||||
}
|
||||
|
||||
if(md5($password) != $user_info['teenager_password']){
|
||||
return ['code' => 0, 'msg' => '密码不正确', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if($type == 1){//关闭
|
||||
$msg = '关闭';
|
||||
$data['is_teenager'] = 2;
|
||||
$reslut = $this->where('user_id', $uid)->update($data);
|
||||
if($reslut){
|
||||
return ['code' => 1, 'msg' => $msg.'成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $msg.'失败', 'data' => null];
|
||||
}
|
||||
}else if($type == 2){//确认密码
|
||||
return ['code' => 1, 'msg' => '密码正确', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
25
application/api/model/UserTag.php
Normal file
25
application/api/model/UserTag.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class UserTag extends Model
|
||||
{
|
||||
//标签列表
|
||||
public function get_tag_list()
|
||||
{
|
||||
$reslut = $this->select();
|
||||
return V(1, '获取成功', $reslut);
|
||||
}
|
||||
public function get_tag_by_id($ids=[])
|
||||
{
|
||||
$reslut = $this->where('id', 'in', $ids)->select();
|
||||
$reslut_data = [];
|
||||
foreach ($reslut as $key => $value) {
|
||||
$reslut_data[$value['id']] = $value['tag_name'];
|
||||
}
|
||||
return $reslut_data;
|
||||
}
|
||||
|
||||
}
|
||||
65
application/api/model/UserToken.php
Normal file
65
application/api/model/UserToken.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserToken extends Model
|
||||
{
|
||||
// 检测登录
|
||||
public function check_login_token($token)
|
||||
{
|
||||
if (empty($token)) {
|
||||
return ['code' => 301, 'msg' => '登录失效!', 'data' =>null];
|
||||
}
|
||||
$user_token = $this->where('token', $token)->find();
|
||||
if (empty($user_token)) {
|
||||
return ['code' => 301, 'msg' => '登录失效!!', 'data' => null];
|
||||
}
|
||||
if ($user_token['expiretime'] < time()) {
|
||||
return ['code' => 301, 'msg'=> '登录失效!!!', 'data' => null];
|
||||
}
|
||||
|
||||
$block1 = db::name('block')->where(['type' => 1,'type_text' => $user_token['user_id']])->find();
|
||||
$userState = db::name('user')->where(['id' => $user_token['user_id']])->value('status');
|
||||
if(isset($block1) && $userState == 2){
|
||||
return ['code' => 204, 'msg'=> '账号已被封禁,请联系管理员','data' => null];
|
||||
}
|
||||
$login_device = request()->header('deviceId');
|
||||
$block2 = db::name('block')->where(['type' => 2,'type_text' => $login_device])->find();
|
||||
if(isset($block2)){
|
||||
return ['code' => 205, 'msg'=> '设备已被封禁,请联系管理员','data' => null];
|
||||
}
|
||||
$Ip = request()->ip();
|
||||
$block3 = db::name('block')->where(['type' => 3,'type_text' => $Ip])->find();
|
||||
if(isset($block3)){
|
||||
return ['code' => 206, 'msg'=> 'IP已被封禁,请联系管理员','data' => null];
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg'=> '成功','data' => $user_token['user_id']];
|
||||
}
|
||||
|
||||
//更新token
|
||||
public function update_token($user_id)
|
||||
{
|
||||
$token =md5($user_id . date('YmdHis') . generateRandom(32));
|
||||
$expiretime = time() + 3600 * 24 * 7;
|
||||
$data_token = $this->where('user_id', $user_id)->find();
|
||||
if(empty($data_token)){
|
||||
$data_token = [];
|
||||
$data_token['user_id'] = $user_id;
|
||||
$data_token['token'] = $token;
|
||||
$data_token['expiretime'] = $expiretime;
|
||||
if(!($this->save($data_token))){
|
||||
return ['code' => 0, 'msg'=> 'token更新失败'];
|
||||
}
|
||||
}else{
|
||||
if(!($this->where('user_id', $user_id)->update(['token' => $token, 'expiretime' => $expiretime]))){
|
||||
return ['code' => 0, 'msg'=> 'token更新失败'];
|
||||
}
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
}
|
||||
198
application/api/model/UserWallet.php
Normal file
198
application/api/model/UserWallet.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use Yzh\YunPay;
|
||||
|
||||
|
||||
class UserWallet extends Model
|
||||
{
|
||||
public function create_data($uid)
|
||||
{
|
||||
$insert_data = ['user_id' => $uid];
|
||||
return Db::name('user_wallet')->insert($insert_data);
|
||||
}
|
||||
|
||||
//钱包
|
||||
public function wallet($uid)
|
||||
{
|
||||
if(!isset($uid)){
|
||||
return ['code' => 301, 'msg' => '登录失效,请重新登录!', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = db::name('user_wallet')->where('user_id', $uid)->find();
|
||||
//获取云账号签约协议
|
||||
$yun_pay = new YunPay();
|
||||
$yun_pay_agreement = $yun_pay->getAgreementPreviewUrl();
|
||||
if($yun_pay_agreement['code'] == 1){
|
||||
$user_info['url'] = $yun_pay_agreement['data']['url'];
|
||||
$user_info['title'] = $yun_pay_agreement['data']['title'];
|
||||
}else{
|
||||
$user_info['url'] = "";
|
||||
$user_info['title'] = "";
|
||||
}
|
||||
if($user_info){
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $user_info];
|
||||
}
|
||||
return ['code' => 0, 'msg' => '获取失败', 'data' => null];
|
||||
}
|
||||
|
||||
//金币/钻石 明细
|
||||
public function log_list($uid, $page, $page_limit,$in_out_type,$start_time,$end_time,$gift_type)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
$map = [];
|
||||
$map['money_type'] = $gift_type;//1金币,2收益(钻石)
|
||||
$in_out_types = [];
|
||||
// 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
|
||||
// 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
|
||||
// 15.首充 16.天降好礼充值 17.退出工会扣款 18.房主收益 19.主持人收益,20.发布头条扣除余额,21.公会长收益,22.提现驳回或提现失败返还,23.财富等级奖励金币领取,24.删除关系扣金币
|
||||
if($gift_type == 1){ //1金币,2收益(钻石)
|
||||
if($in_out_type == 1){//1收入
|
||||
$in_out_types = [2,5,6,8,13,14,15,16,22,23,26];
|
||||
}elseif($in_out_type == 2){//2支出
|
||||
$in_out_types = [4,7,10,17,20,24,25];
|
||||
}
|
||||
}elseif($gift_type == 2){ //1金币,2收益(钻石)
|
||||
if($in_out_type == 1){//1收入
|
||||
$in_out_types = [6,9,11,12,18,19,21];
|
||||
}elseif($in_out_type == 2){//2支出
|
||||
$in_out_types = [3,14];
|
||||
}
|
||||
}
|
||||
|
||||
$map['change_type'] = ['in', $in_out_types];
|
||||
$map['user_id'] =$uid;
|
||||
|
||||
// 时间范围处理
|
||||
if (!empty($start_time) && !empty($end_time)) {
|
||||
$start_time = strtotime($start_time);
|
||||
$end_time = strtotime($end_time.' 23:59:59');
|
||||
$map['createtime'] = ['between', [$start_time, $end_time]];
|
||||
}
|
||||
|
||||
$list = Db::name('vs_user_money_log')
|
||||
->where($map)
|
||||
->field('log_id, user_id, change_type, change_value, remarks, createtime')
|
||||
->order('log_id desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
foreach ($list as $key => &$value) {
|
||||
$value['change_type_name'] = model('common/UserWallet')->ChangeTypeLable($value['change_type']);
|
||||
if($in_out_type==2){
|
||||
$value['change_value'] = $value['change_value'] * -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//收益(钻石)兑换金币
|
||||
public function exchange_coin($uid, $earnings_num)
|
||||
{
|
||||
if(empty($earnings_num)){
|
||||
return ['code' => 0, 'msg' => '请输入需要兑换的钻石数量', 'data' => null];
|
||||
}
|
||||
//判断钻石数量 小数点后有效数字是一位
|
||||
if(strlen($earnings_num) - strlen(str_replace('.', '', $earnings_num)) > 1){
|
||||
return ['code' => 0, 'msg' => '请输入正确的钻石数量', 'data' => null];
|
||||
}
|
||||
//判断用户的钻石数量是否大于等于兑换数量
|
||||
$user_info = db::name('user_wallet')->where('user_id',$uid)->find();
|
||||
if($user_info['earnings'] < $earnings_num){
|
||||
return ['code' => 0, 'msg' => '钻石数量不足', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_id' => $uid,
|
||||
'earnings_num' => $earnings_num,
|
||||
'coin_num' => $earnings_num * 10,
|
||||
'createtime' => time(),
|
||||
];
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
|
||||
$give_gift_id = db::name('user_exchange')->insertGetId($data);
|
||||
// 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
|
||||
// 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
|
||||
$account_log[] = [
|
||||
'user_id' => $uid,
|
||||
'money_type' => 2,//1金币2钻石
|
||||
'change_value' => $earnings_num,
|
||||
'remarks' => '收益兑换',
|
||||
'change_type' => 14,
|
||||
'createtime' => time(),
|
||||
'from_id' => $give_gift_id,
|
||||
];
|
||||
$account_log[] = [
|
||||
'user_id' => $uid,
|
||||
'money_type' => 1,
|
||||
'change_value' => $earnings_num * 10,
|
||||
'remarks' => '收益兑换',
|
||||
'change_type' => 14,
|
||||
'createtime' => time(),
|
||||
'from_id' => $give_gift_id,
|
||||
];
|
||||
$re = db::name('vs_user_money_log')->insertAll($account_log);
|
||||
$re1 = db::name('user_wallet')->where('user_id',$uid)->setDec('earnings',$earnings_num);
|
||||
$re2 = db::name('user_wallet')->where('user_id',$uid)->setInc('coin',$earnings_num * 10);
|
||||
if($re && $re1 && $re2){
|
||||
db::commit();
|
||||
return ['code' => 1, 'msg' => '兑换成功', 'data' => null];
|
||||
}else{
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '兑换失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//转币
|
||||
public function give_coin($uid, $give_uid, $coin){
|
||||
if(empty($coin)){
|
||||
return ['code' => 0, 'msg' => '请输入需要转的金币数量', 'data' => null];
|
||||
}
|
||||
if(strlen($coin) - strlen(str_replace('.', '', $coin)) > 1){
|
||||
return ['code' => 0, 'msg' => '请输入正确的金币数量', 'data' => null];
|
||||
}
|
||||
$user_info = db::name('user_wallet')->where('user_id',$uid)->find();
|
||||
if($user_info['coin'] < $coin){
|
||||
return ['code' => 0, 'msg' => '金币数量不足', 'data' => null];
|
||||
}
|
||||
$user_info = db::name('user')->where('id',$uid)->find();
|
||||
$give_useer = db::name('user')->where('id',$give_uid)->find();
|
||||
if(empty($user_info)){
|
||||
return ['code' => 0, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
if(empty($give_useer)){
|
||||
return ['code' => 0, 'msg' => '接受用户不存在', 'data' => null];
|
||||
}
|
||||
if($user_info['red_status'] == 0){
|
||||
return ['code' => 0, 'msg' => '未开启转赠功能', 'data' => null];
|
||||
}
|
||||
if($user_info['id'] == $give_uid){
|
||||
return ['code' => 0, 'msg' => '不能转给自己', 'data' => null];
|
||||
}
|
||||
$data = [
|
||||
'user_id' => $uid,
|
||||
'accept_user_id' => $give_uid,
|
||||
'coin_num' => $coin,
|
||||
'createtime' => time(),
|
||||
];
|
||||
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
$give_gift_id = db::name('user_coin_transfer')->insertGetId($data);
|
||||
//金币处理
|
||||
$res1 = model('common/UserWallet')->change_user_money($uid, $coin, model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::TRANSFER_COIN,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::TRANSFER_COIN).':转赠给'.$give_useer['nickname'].$coin.'金币');
|
||||
$res2 = model('common/UserWallet')->change_user_money($give_uid, $coin, model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::RECEIVE_COIN,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::RECEIVE_COIN).':收到好友'.$user_info['nickname'].$coin.'金币');
|
||||
if($res1 && $res2){
|
||||
db::commit();
|
||||
return ['code' => 1, 'msg' => '转赠成功', 'data' => null];
|
||||
}else{
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '转赠失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
217
application/api/model/UserWithdrawal.php
Normal file
217
application/api/model/UserWithdrawal.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use Yzh\YunPay;
|
||||
|
||||
|
||||
class UserWithdrawal extends Model
|
||||
{
|
||||
public $withdraw_status = [
|
||||
1=>'待处理',
|
||||
2=>'已通过',
|
||||
3=>'已拒绝',
|
||||
4=>'打款中[云账户]',
|
||||
5=>'打款失败[云账户]',
|
||||
6=>'已打款[云账户]',
|
||||
];
|
||||
/*
|
||||
* 用户提现
|
||||
*/
|
||||
public function withdrawal($user_id,$number, $type,$sms_code){
|
||||
if(empty($sms_code)){
|
||||
return V(0, '请输入短信验证码');
|
||||
}
|
||||
$user_info = model('User')->get_user_info($user_id);
|
||||
// default-默认登录,1-更换手机号,2绑定手机号,3-忘记密码,4-设置密码,5-账号注销,6-提现
|
||||
$sms_reslut = model('sms')->verification_code(6,$user_info['mobile'], $sms_code);
|
||||
if ($sms_reslut['code'] == 0) {
|
||||
return v($sms_reslut['code'], $sms_reslut['msg'], $sms_reslut['data']);
|
||||
}
|
||||
if($user_info['status'] != 1){
|
||||
return ['code' => 0, 'msg' => '用户被禁用', 'data' => null];
|
||||
}
|
||||
if($user_info['is_real']!=1 || empty($user_info['card_id'])){
|
||||
return ['code' => 0, 'msg' => '请先实名认证', 'data' => null];
|
||||
}
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 0, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
}
|
||||
$age = getAgeId($user_info['card_id']);
|
||||
if(!$age){
|
||||
return ['code' => 0, 'msg' => '该身份证号未满18岁', 'data' => null];
|
||||
}
|
||||
//判断用户是否签约云账户
|
||||
$yun_pay = new YunPay();
|
||||
$sign_status = $yun_pay->getApiUserSignStatus($user_info['real_name'],$user_info['card_id']);
|
||||
if($sign_status['code'] == 1){
|
||||
if($sign_status['data']['sign_status'] !=1){
|
||||
//用户签约
|
||||
$reslut = $yun_pay->apiUserSign($user_info['real_name'],$user_info['card_id']);
|
||||
if($reslut['code'] != 1){
|
||||
return ['code' => $reslut['code'], 'msg' => $reslut['msg'], 'data' => $reslut['data']];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return ['code' => $sign_status['code'], 'msg' => $sign_status['msg'], 'data' => $sign_status['data']];
|
||||
}
|
||||
//每日提现次数
|
||||
$daily_withdrawals_num = get_system_config_value('daily_withdrawals_num');
|
||||
//今日已提现次数
|
||||
$today_withdrawals_num = db::name('vs_user_withdrawal')->where(['user_id'=>$user_id,'status'=>1])->whereTime('createtime', 'today')->count();
|
||||
if($today_withdrawals_num >= $daily_withdrawals_num){
|
||||
return ['code' => 0, 'msg' => '今日提现次数已用完,每日最多提现'.$daily_withdrawals_num.'次', 'data' => null];
|
||||
}
|
||||
if($type == 1){//微信
|
||||
|
||||
}else if($type == 2){//支付宝
|
||||
if (empty($user_info['alipay_account'])) {
|
||||
return ['code' => 0, 'msg' => '请先绑定支付宝', 'data' => null];
|
||||
}
|
||||
}else if($type == 3){//银行卡
|
||||
if (empty($user_info['bank_card_number'])) {
|
||||
return ['code' => 0, 'msg' => '请先绑定银行卡', 'data' => null];
|
||||
}
|
||||
//银行卡姓名 和 真实姓名
|
||||
if(trim($user_info['bank_user_name']) != trim($user_info['real_name'])){
|
||||
return ['code' => 0, 'msg' => '实名认证姓名和银行卡姓名不一致!', 'data' => null];
|
||||
}
|
||||
}
|
||||
if ($number > $user_info['earnings']) {
|
||||
return ['code' => 0, 'msg' => '余额不足', 'data' => null];
|
||||
}
|
||||
//钻石兑换人民币比例
|
||||
$diamond_to_rmb_ratio = get_system_config_value('diamond_to_rmb_ratio');
|
||||
$money = $number / $diamond_to_rmb_ratio; //提现金额转换 钻石转为人民币
|
||||
|
||||
$min_withdraw_amount = get_system_config_value('min_withdraw_amount');
|
||||
if($money < $min_withdraw_amount){
|
||||
return ['code' => 0, 'msg' => '提现金额需大于等于'.$min_withdraw_amount."钻石", 'data' => null];
|
||||
}
|
||||
//提现服务费
|
||||
$withdrawal_service_fee = get_system_config_value('withdrawal_service_fee');
|
||||
$withdrawal_service_fee = $withdrawal_service_fee ? $withdrawal_service_fee / 100 : 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order_sn = $this->create_user_withdrawal_order_sn(); //订单号
|
||||
$data = [];
|
||||
$data['order_sn'] = $order_sn;
|
||||
$data['user_id'] = $user_id;
|
||||
$data['money'] = $money;
|
||||
//向上取小数
|
||||
$data['server_money'] = round((($money * $withdrawal_service_fee) * 100))/100; //提现服务费
|
||||
$data['general_money'] = $money -$data['server_money']; //到账金额
|
||||
$data['type'] = $type;
|
||||
if($type == 2){
|
||||
$data['real_name'] = $user_info['real_name'];
|
||||
$data['alipay_account'] = $user_info['alipay_account'];
|
||||
}else if($type == 3){
|
||||
$data['real_name'] = $user_info['bank_user_name']??$user_info['real_name'];
|
||||
$data['bank_card'] = $user_info['bank_card'];
|
||||
$data['open_bank'] = $user_info['open_bank'];
|
||||
$data['bank_card_number'] = $user_info['bank_card_number'];
|
||||
}
|
||||
$data['remarke'] = '';
|
||||
$data['status'] = 1;
|
||||
$data['deal_time'] = 0;
|
||||
$data['createtime'] = time();
|
||||
$data['updatetime'] = time();
|
||||
$user_withdrawal_wid = db::name('vs_user_withdrawal')->insertGetId($data);
|
||||
if (!$user_withdrawal_wid) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试1", 'data' => null];
|
||||
}
|
||||
//扣除账户余额
|
||||
$reslut = model('common/UserWallet')->change_user_money($user_id, $number, model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::OPERATION_WITHDRAW,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::OPERATION_WITHDRAW));
|
||||
if ($reslut['code'] != 1) {
|
||||
Db::rollback();
|
||||
return V($reslut['code'],$reslut['msg']);
|
||||
}
|
||||
//增加冻结余额
|
||||
$reslut = Db::name('user_wallet')->where('user_id', $user_id)->setInc('frozen_earnings', $number);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试2", 'data' => null];
|
||||
}
|
||||
//修改提现余额
|
||||
$surplus_earnings = Db::name('user_wallet')->where('user_id', $user_id)->value('earnings');
|
||||
if ($surplus_earnings > 0) {
|
||||
$surplus_earnings = $surplus_earnings / $diamond_to_rmb_ratio; //剩余金额(人民币)
|
||||
}
|
||||
DB::name('vs_user_withdrawal')->where(['wid'=>$user_withdrawal_wid])->update(['surplus_money'=>$surplus_earnings]);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => "提现成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "提现失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
//生成订单号
|
||||
private function create_user_withdrawal_order_sn()
|
||||
{
|
||||
$order_sn = 'TX' . date('YmdHis') . mt_rand(10000, 99999);
|
||||
$reslut = db::name('vs_user_withdrawal')->where('order_sn', $order_sn)->find();
|
||||
if (empty($reslut)) {
|
||||
return $order_sn;
|
||||
} else {
|
||||
$this->create_user_withdrawal_order_sn();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 提现失败处理
|
||||
*/
|
||||
public function withdrawal_fail($order_id){
|
||||
$withdraw_info = db::name('vs_user_withdrawal')->where('order_sn', $order_id)->find();
|
||||
//退回提现金额(释放冻结金额)
|
||||
//钻石兑换人民币比例
|
||||
$diamond_to_rmb_ratio = get_system_config_value('diamond_to_rmb_ratio');
|
||||
$money = $withdraw_info['money'] * $diamond_to_rmb_ratio; //提现金额转换 人民币转为钻石
|
||||
$result = db::name('user_wallet')->where('user_id', $withdraw_info['user_id'])->setDec('frozen_earnings', $money);
|
||||
if (!$result) {
|
||||
return ['code' => 0, 'msg' => '提现失败'];
|
||||
}
|
||||
//归还账户余额
|
||||
$reslut = model('common/UserWallet')->change_user_money($withdraw_info['user_id'], $money, model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::WITHDRAW_FAILURE,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::WITHDRAW_FAILURE));
|
||||
if ($reslut['code'] != 1) {
|
||||
return ['code' => 0, 'msg' => $reslut['msg']];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功'];
|
||||
}
|
||||
/*
|
||||
* 提现列表
|
||||
*/
|
||||
public function withdrawal_list($user_id,$page=1,$page_limit=10,$search_stime="",$search_etime=""){
|
||||
$where = [];
|
||||
$where['user_id'] = $user_id;
|
||||
if($search_stime){
|
||||
$where['createtime'] = ['>=',strtotime($search_stime)];
|
||||
}
|
||||
if($search_etime){
|
||||
$where['createtime'] = ['<=',strtotime($search_etime.' 23:59:59')];
|
||||
}
|
||||
if(!empty($search_stime) && !empty($search_etime)){
|
||||
$where['createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime.' 23:59:59')]];
|
||||
}
|
||||
$withdraw_list = db::name('vs_user_withdrawal')
|
||||
->where($where)
|
||||
->page($page,$page_limit)
|
||||
->select();
|
||||
$return_data = [];
|
||||
foreach ($withdraw_list as $key=>$value){
|
||||
$return_data[$key]['name'] = "收益提现";
|
||||
$return_data[$key]['money'] = $value['money'];
|
||||
$return_data[$key]['status'] = $value['status'];
|
||||
$return_data[$key]['status_str'] = $this->withdraw_status[$value['status']];
|
||||
$return_data[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $return_data];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
699
application/api/model/UserZone.php
Normal file
699
application/api/model/UserZone.php
Normal file
@@ -0,0 +1,699 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
|
||||
class UserZone extends Model
|
||||
{
|
||||
//发布(动态)
|
||||
public function publish_zone($uid, $images, $content,$topic_id = '',$room_id = '',$ip = '')
|
||||
{
|
||||
// $images_data = explode(',', json_decode($images));
|
||||
if (empty($content)) {
|
||||
return ['code' => 0, 'msg' => '发布内容和图片不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
//维禁判断
|
||||
if(!empty($content)) {
|
||||
$result = model('Tencent')->content_moderation('Text', $content);
|
||||
if($result['code'] != 1) {
|
||||
return ['code' => 0, 'msg' => '内容存在违禁词!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['user_id'] = $uid;
|
||||
$data['images'] = $images;
|
||||
$data['content'] = $content;
|
||||
$data['show_status'] = 1; ///1:显示 0不显示
|
||||
$data['topic_id'] = $topic_id;
|
||||
$data['room_id'] = $room_id;
|
||||
$data['ip'] = $ip;
|
||||
$data['createtime'] = time();
|
||||
|
||||
$reslut = $this->save($data);
|
||||
//获取上一步的id
|
||||
$did = $this->id;
|
||||
if ($reslut) {
|
||||
//$topic_id 有值
|
||||
if (isset($topic_id)) {
|
||||
$top = explode(',', $topic_id);
|
||||
foreach ($top as $kk){
|
||||
//插入关联表
|
||||
$datad = [];
|
||||
$datad['zone_id'] = $did;
|
||||
$datad['topic_id'] = $kk;
|
||||
$res = db::name('user_zone_topic')->insert($datad);
|
||||
}
|
||||
}
|
||||
//判断是不是第一次发布
|
||||
$count = db::name('user_zone')->where('user_id' , $uid)->count();
|
||||
if($count <= 1){
|
||||
//首次发布动态【完成任务】
|
||||
model('DailyTasks')->tasks_complete($uid,12);
|
||||
}
|
||||
//发布的是几张 图片
|
||||
$count_images = count(explode(',', $images));
|
||||
if($count_images == 9){
|
||||
$first = db::name('vs_user_zone_manjiujiang')->where('user_id' , $uid)->find();
|
||||
if(!$first){
|
||||
//发布动态头图上传满九张【完成任务】第一次给奖励
|
||||
model('DailyTasks')->tasks_complete($uid,13);
|
||||
db::name('vs_user_zone_manjiujiang')->insert(['user_id' => $uid, 'createtime' =>time()]);
|
||||
}
|
||||
|
||||
}
|
||||
//注册后累计发布M条动态,奖励X金币 【完成任务】
|
||||
model('DailyTasks')->tasks_complete($uid,16);
|
||||
|
||||
return ['code' => 1, 'msg' => '发布成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '发布失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//获取动态列表
|
||||
public function get_zone_list($uid, $page, $page_limit,$topic_id = 0)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 15;
|
||||
|
||||
$map = [];
|
||||
if($topic_id){
|
||||
//查询引用话题的动态ID
|
||||
$topic_id = db::name('user_zone_topic')->where('topic_id' , $topic_id)->field('zone_id')->select();
|
||||
$topic_id = array_map(function($item){
|
||||
return $item['zone_id'];
|
||||
},$topic_id);
|
||||
$map['a.id'] = ['in',$topic_id];
|
||||
}
|
||||
$map['a.show_status'] = 1;//1:显示 0不显示
|
||||
$map['a.is_delete'] = 1;//是否删除 1否2是
|
||||
$map['b.status'] = ['<>',0];//是否注销 1正常,2禁止登录,0注销
|
||||
|
||||
$order_string = 'a.createtime desc'; //排序规则
|
||||
|
||||
$list = db::name('user_zone')->alias('a')->join('fa_user b', 'a.user_id = b.id','left')
|
||||
->where($map)
|
||||
->field('a.id,a.user_id,a.images,a.content,a.like_num,a.comment_num,a.is_recommend,b.nickname,b.sex,b.avatar,b.user_code,a.room_id,a.ip,a.createtime,a.topic_id')
|
||||
->order($order_string)->page($page, $page_limit)->select();
|
||||
|
||||
foreach ($list as $k => &$v) {
|
||||
//头像装扮
|
||||
$v['dress'] = model('Decorate')->user_decorate_detail($v['user_id'],1);
|
||||
$v['title'] = [];
|
||||
if(isset($v['topic_id'])){
|
||||
$top = explode(',', $v['topic_id']);
|
||||
foreach ($top as $kk){
|
||||
$title = db::name('topic')->where(['id' => $kk])->find();
|
||||
if(isset($title)){
|
||||
$title['topic_id'] = $title['id'];
|
||||
$title['count'] = db::name('user_zone_topic')->where('topic_id',$kk)->count();
|
||||
}
|
||||
$v['title'][] =$title;
|
||||
}
|
||||
}
|
||||
|
||||
//房间分享到动态
|
||||
if($v['room_id']){
|
||||
//查询房主此时是否在聊天室
|
||||
$room_id = db::name('vs_room_visitor')->where(['user_id' => $v['user_id'], 'is_delete' => 1])->value('room_id');
|
||||
if ($room_id) {
|
||||
$room = db::name('vs_room')->where(['id' => $room_id, 'room_status' => 1])->field('id,room_name,room_number,room_cover,room_intro,today_hot_value as hot_value,type_id')->find();
|
||||
$v['room_id'] = $room['id'];
|
||||
$v['room_cover'] = $room['room_cover'];
|
||||
$v['room_type'] = db::name('vs_room_type')->where(['id' => $room['type_id'], 'status' => 1])->field('type_name');
|
||||
$v['room_intro'] = $room['intro'];
|
||||
$v['hot_value'] = $room['hot_value'];
|
||||
$v['room_number'] = $room['room_number'];
|
||||
$v['room_name'] = $room['room_name'];
|
||||
} else {
|
||||
$v['room_id'] = 0;
|
||||
}
|
||||
//分享出去的URL
|
||||
$v['share_url'] = get_system_config_value('web_site').'/api/Share/zone_detail?id='.$v['id'];
|
||||
}else{
|
||||
$v['is_like'] = 0; //是否点赞is_room
|
||||
$praise = db::name('user_zone_like')->where(['zone_id' => $v['id'], 'user_id' => $uid,'delete_time' => 0])->find();
|
||||
if (!empty($praise)) {
|
||||
$v['is_like'] = 1;
|
||||
}
|
||||
|
||||
$v['room_id'] = 0; //是否在聊天室
|
||||
//判断是否在聊天室
|
||||
$room_id = db::name('vs_room_visitor')->where(['user_id' => $v['user_id'], 'is_delete' => 1])->order('id desc')->value('room_id');
|
||||
if (isset($room_id)) {
|
||||
$v['room_id'] = $room_id;
|
||||
}
|
||||
$v['rewards_num'] = 0;//打赏
|
||||
$rewards = db::name('user_zone_rewards')->where('zone_id' , $v['id'])->field('sum(gift_price_total) as rewards_num')->find();
|
||||
if (isset($rewards)) {
|
||||
$v['rewards_num'] = $rewards['rewards_num']??0;
|
||||
}
|
||||
//分享出去的URL
|
||||
$v['share_url'] = get_system_config_value('web_url').'/share/index.html?id='.$v['id'];
|
||||
}
|
||||
}
|
||||
//根据 is_recommend = 1推荐 排序 推荐的拍前面
|
||||
$top = array_filter((array)$list, function($item) { return $item['is_recommend'] == 1; });
|
||||
$untop = array_filter((array)$list, function($item) { return $item['is_recommend'] != 1; });
|
||||
$list = array_merge($top, $untop);
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//动态详情
|
||||
public function get_zone_info($zid,$uid=0)
|
||||
{
|
||||
$map = [];
|
||||
$map['a.id'] = $zid;
|
||||
$map['a.show_status'] = 1;//1:显示 0不显示
|
||||
$map['a.is_delete'] =1;//是否删除 1否2是
|
||||
|
||||
$model = Db::name('UserZone')->alias('a')->join('fa_user b', 'a.user_id = b.id');
|
||||
$model = $model->where($map);
|
||||
$info = $model->field('a.id,a.user_id,a.images,a.content,a.like_num,a.read_num,a.comment_num,a.is_recommend,a.createtime,a.ip,b.nickname,b.sex,b.avatar,b.user_code,a.topic_id')->find();
|
||||
|
||||
if (empty($info)) {
|
||||
return ['code' => 0, 'msg' => '动态不存在', 'data' => null];
|
||||
}
|
||||
$info['title'] = [];
|
||||
if(isset($info['topic_id'])){
|
||||
$top = explode(',', $info['topic_id']);
|
||||
foreach ($top as $kk){
|
||||
$title = db::name('topic')->where(['id' => $kk])->find();
|
||||
if(isset($title)){
|
||||
$title['topic_id'] = $title['id'];
|
||||
$title['count'] = db::name('user_zone_topic')->where('topic_id',$kk)->count();
|
||||
}
|
||||
$info['title'][] =$title;
|
||||
}
|
||||
}
|
||||
|
||||
$info['is_like'] = 0; //是否点赞
|
||||
if(isset($uid) && $uid > 0){
|
||||
$praise = db::name('user_zone_like')->where(['zone_id' => $info['id'], 'user_id' => $uid,'delete_time' => 0])->find();
|
||||
if (!empty($praise)) {
|
||||
$info['is_like'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//点赞列表
|
||||
$info['like_list'] = [];
|
||||
$praise_list = db::name('user_zone_like')->alias('a')->join('fa_user b', 'a.user_id = b.id')
|
||||
->field('a.user_id,b.nickname,b.sex,b.avatar,b.birthday')
|
||||
->where(['a.zone_id' => $zid,'a.delete_time' => 0])
|
||||
->limit(3)
|
||||
->select();
|
||||
if (!empty($praise_list)) {
|
||||
foreach ($praise_list as $k => &$v) {
|
||||
if ($v['birthday']) {
|
||||
$v['age'] = getAge($v['birthday']);
|
||||
$v['constellation'] = get_user_constellation($v['birthday']);
|
||||
}else{
|
||||
$v['age'] = 0;
|
||||
$v['constellation'] = '';
|
||||
}
|
||||
}
|
||||
$info['like_list'] = $praise_list;
|
||||
}
|
||||
|
||||
$info['room_id'] = "0";
|
||||
//判断是否在聊天室
|
||||
$rid = db::name('vs_room_visitor')->where(['user_id' => $info['user_id'], 'is_delete' => 1])->order('id desc')->value('room_id');
|
||||
if ($rid) {
|
||||
$info['room_id'] = $rid;
|
||||
}
|
||||
//打赏列表
|
||||
$info['rewards_list'] = [];
|
||||
$info['rewards_num'] = 0;//打赏金额
|
||||
$rewards = db::name('user_zone_rewards')->where(['zone_id' => $info['id']])->field('sum(gift_price_total) as rewards_num')->find();
|
||||
if ($rewards) {
|
||||
$info['rewards_num'] = $rewards['rewards_num']??0;
|
||||
$rewards_list = db::name('user_zone_rewards')->alias('a')->join('fa_user b', 'a.user_id = b.id')
|
||||
->where(['a.zone_id' => $zid])->field('a.user_id,a.gift_price_total,b.nickname,b.avatar')
|
||||
->order('a.gift_price_total desc')
|
||||
->select();
|
||||
if (!empty($rewards_list)) {
|
||||
foreach ($rewards_list as $k => &$v) {
|
||||
$v['room_id'] = 0; //是否在聊天室
|
||||
$rrid = db::name('vs_room_visitor')->where(['user_id' => $v['user_id'], 'is_delete' => 1])->value('room_id');
|
||||
if ($rrid) {
|
||||
$v['room_id'] = $rrid;
|
||||
}
|
||||
}
|
||||
$info['rewards_list'] = $rewards_list;
|
||||
}
|
||||
}
|
||||
//评论数量
|
||||
// $info['comment_num'] = db::name('user_zone_comment')->where(['zone_id' => $zid])->count();
|
||||
$info['comment_list'] = [];
|
||||
$comment_list = db::name('user_zone_comment')->alias('a')->join('fa_user b', 'a.user_id = b.id')
|
||||
->where(['a.zone_id' => $zid,'a.is_delete' => 1,'pid' => 0,'is_show' => 1])
|
||||
->field('a.id,a.user_id,a.content,a.createtime,b.nickname,b.avatar,b.sex,b.birthday')
|
||||
->order('a.createtime desc')
|
||||
->limit(3)
|
||||
->select();
|
||||
|
||||
if (!empty($comment_list)) {
|
||||
foreach ($comment_list as $k => &$v) {
|
||||
//时间戳转换为日期格式
|
||||
$v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
|
||||
if ($v['birthday']) {
|
||||
$v['age'] = getAge($v['birthday']);
|
||||
$v['constellation'] = get_user_constellation($v['birthday']);
|
||||
}else{
|
||||
$v['age'] = 0;
|
||||
$v['constellation'] = '';
|
||||
}
|
||||
}
|
||||
$info['comment_list'] = $comment_list;
|
||||
}
|
||||
//分享出去的URL
|
||||
$info['share_url'] = get_system_config_value('web_url').'/share/index.html?id='.$zid;
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $info];
|
||||
}
|
||||
|
||||
//(动态)评论
|
||||
public function comment_zone($uid, $zid, $content,$pid, $reply_to)
|
||||
{
|
||||
$info = db::name('user_zone')->find($zid);
|
||||
if (empty($info)) {
|
||||
return ['code' => 0, 'msg' => "评论的动态不存在", 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
$data = [];
|
||||
$data['zone_id'] = $zid;
|
||||
$data['user_id'] = $uid;
|
||||
$data['pid'] = $pid;
|
||||
$data['reply_to'] = $reply_to;
|
||||
$data['content'] = $content;
|
||||
// $data['praise_num'] = 0;
|
||||
$data['is_show'] = 1;
|
||||
$data['createtime'] = time();
|
||||
|
||||
$reslut = db::name('user_zone_comment')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试,', 'data' => null];
|
||||
}
|
||||
//评论別人的帖子- 每天第一条奖励【完成任务】
|
||||
if($info['user_id'] != $uid){
|
||||
//今天的第一条评论奖励
|
||||
$first_comment = db::name('user_zone_comment')->where(['user_id' => $uid, 'createtime' => ['between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]])->count();
|
||||
if ($first_comment ==1) {
|
||||
model('DailyTasks')->tasks_complete($uid,5);
|
||||
}
|
||||
}
|
||||
//增加评论数量
|
||||
$reslut = db::name('user_zone')->where('id', $zid)->setInc('comment_num', 1);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试。', 'data' => null];
|
||||
}
|
||||
//提醒说说动态发布人有人评论
|
||||
$user_info=db::name('user')->where('id',$uid)->find();
|
||||
$content = $user_info['nickname'] . "评论了您的动态";
|
||||
// model('api/user_message')->send_message($info['user_id'], 4,$info['zid'], "我的动态", $content);
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => "评论成功", 'data' => null];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论及其回复
|
||||
*/
|
||||
public function getCommentsWithReplies($zid, $page, $page_limit)
|
||||
{
|
||||
// 获取顶级评论
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
$map = [];
|
||||
$map['a.is_show'] = 1;
|
||||
$map['a.zone_id'] = $zid;
|
||||
$map['a.pid'] = 0;
|
||||
$map['a.is_delete'] = 1;//是否删除 1否2是
|
||||
$order_string = 'a.createtime desc'; //排序规则
|
||||
$model = Db::name('user_zone_comment')->alias('a')->join('fa_user b', 'a.user_id = b.id');
|
||||
$model = $model->where($map);
|
||||
$list = $model->field('a.id,a.zone_id,a.content,a.createtime,a.user_id,b.nickname,b.avatar')
|
||||
->order($order_string)->page($page, $page_limit)->select();
|
||||
|
||||
if ($list) {
|
||||
$commentIds = array_column($list, 'id');
|
||||
foreach ($list as $k => &$v) {
|
||||
//判断评论用户是否是作者
|
||||
$v['is_author'] = 0;
|
||||
$uid = Db::name('user_zone')->where('id', $zid)->value('user_id');
|
||||
if (isset($uid) && $v['user_id'] == $uid) {
|
||||
$v['is_author'] = 1;
|
||||
}
|
||||
}
|
||||
// 获取这些评论的回复
|
||||
$replies = Db::name('user_zone_comment')->alias('a')->join('fa_user b', 'a.user_id = b.id')
|
||||
->whereIn('a.pid', $commentIds)
|
||||
->where('a.is_show', 1)
|
||||
->where('a.is_delete', 1)
|
||||
->field('a.id,a.reply_to,a.zone_id,a.content,a.createtime,a.user_id,b.nickname,b.avatar,a.pid')
|
||||
->order('a.createtime', 'asc')
|
||||
->select();
|
||||
if($replies){
|
||||
foreach ($replies as $k => &$vv) {
|
||||
//判断评论用户是否是作者
|
||||
$vv['is_author'] = 0;
|
||||
$uidd = Db::name('user_zone')->where('id', $zid)->value('user_id');
|
||||
if (isset($uidd) && $vv['user_id'] == $uidd) {
|
||||
$vv['is_author'] = 1;
|
||||
}
|
||||
$vv['reply_to_user'] = "";
|
||||
if(isset($vv['reply_to'])){
|
||||
$vv['reply_to_user'] = Db::name('user')->where('id',$vv['reply_to'])->value('nickname');
|
||||
}
|
||||
}
|
||||
// 将回复按父评论ID分组
|
||||
$replyGroups = [];
|
||||
foreach ($replies as $reply) {
|
||||
$replyGroups[$reply['pid']][] = $reply;
|
||||
}
|
||||
}
|
||||
|
||||
// 将回复关联到对应的评论
|
||||
foreach ($list as &$comment) {
|
||||
$comment['replies'] = $replyGroups[$comment['id']] ?? [];
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评论总数
|
||||
*/
|
||||
public function getCommentCount($zid)
|
||||
{
|
||||
return Db::name('user_zone_comment')->where(['zone_id'=> $zid,'is_show' => 1, 'is_delete' => 1])->count();
|
||||
}
|
||||
|
||||
//点赞 取消点赞
|
||||
public function praise_zone($uid, $zid)
|
||||
{
|
||||
//第一条点赞奖励 【任务废弃】
|
||||
// $first_praise = db::name('user_zone_like')->where('user_id',$uid)->find();
|
||||
// if(empty($first_praise)){
|
||||
// $kay = get_system_config_value('task_like_others_for_the_first_time');
|
||||
// model('DailyTasks')->daily_tasks_complete($uid,$kay);
|
||||
// }
|
||||
|
||||
$map['user_id'] = $uid;
|
||||
$map['zone_id'] = $zid;
|
||||
$info = db::name('user_zone_like')->where($map)->find();
|
||||
if (!empty($info)) {
|
||||
if ($info['delete_time'] == 0) {
|
||||
$del1 = db::name('user_zone')->where('id',$zid)->setDec('like_num');
|
||||
$del = db::name('user_zone_like')->where($map)->update(['delete_time' => time()]);
|
||||
if (!$del || !$del1) {
|
||||
return ['code' => 0, 'msg' => '请重试!', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '取消点赞成功', 'data' => null];
|
||||
}else{
|
||||
$add1 = db::name('user_zone')->where('id',$zid)->setInc('like_num');
|
||||
$add = db::name('user_zone_like')->where($map)->update(['delete_time' => 0]);
|
||||
if (!$add || !$add1) {
|
||||
return ['code' => 0, 'msg' => '请重试!', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '点赞成功', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
Db::startTrans();
|
||||
$data = [];
|
||||
$data['user_id'] = $uid;
|
||||
$data['zone_id'] = $zid;
|
||||
$data['createtime'] = time();
|
||||
$reslut = db::name('user_zone_like')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试!', 'data' => null];
|
||||
}
|
||||
//增加点赞数量
|
||||
$reslut = db::name('user_zone')->where('id', $zid)->setInc('like_num');
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试!!', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => "点赞成功", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//点赞列表
|
||||
public function get_like_list($zid, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$praise_list = db::name('user_zone_like')->alias('a')->join('fa_user b', 'a.user_id = b.id')
|
||||
->field('a.user_id,b.nickname,b.sex,b.avatar,b.birthday')
|
||||
->where('a.zone_id' , $zid)
|
||||
->where('a.delete_time', 0)
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
if (!empty($praise_list)) {
|
||||
foreach ($praise_list as $k => &$v) {
|
||||
if ($v['birthday']) {
|
||||
$v['age'] = getAge($v['birthday']);
|
||||
$v['constellation'] = get_user_constellation($v['birthday']);
|
||||
}else{
|
||||
$v['age'] = 0;
|
||||
$v['constellation'] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $praise_list;
|
||||
}
|
||||
|
||||
//引用话题的动态
|
||||
public function get_zone_topic_list($uid,$topic_id, $page, $page_limit)
|
||||
{
|
||||
$list = $this->get_zone_list($uid, $page, $page_limit,$topic_id);
|
||||
return $list['data'];
|
||||
}
|
||||
|
||||
//用户主页的动态列表
|
||||
/*
|
||||
* @param $uid 当前用户id
|
||||
* @param $from_id 访问id 要看谁的ID
|
||||
*/
|
||||
public function get_user_zone_list($uid ,$from_id,$page=1, $page_limit=0)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$map = [];
|
||||
$map['user_id'] = $from_id;
|
||||
$map['show_status'] = 1;//1:显示
|
||||
$map['is_delete'] =1;//是否删除 1否2是
|
||||
|
||||
$order_string = 'createtime desc'; //排序规则
|
||||
$model = Db::name('user_zone');
|
||||
$list = $model->where($map)
|
||||
->field('id,images,content,like_num,comment_num,user_id,createtime,topic_id')
|
||||
->order($order_string)->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['is_like'] = 0; //是否点赞
|
||||
$praise = db::name('user_zone_like')->where(['zone_id' => $v['id'], 'user_id' => $uid])->find();
|
||||
if (!empty($praise)) {
|
||||
$v['is_like'] = 1;
|
||||
}
|
||||
$v['rewards_num'] = 0;
|
||||
$rewards = db::name('user_zone_rewards')->where(['zone_id' => $v['id']])->field('sum(gift_price_total) as rewards_num')->find();
|
||||
if ($rewards) {
|
||||
$v['rewards_num'] = $rewards['rewards_num']??0;
|
||||
}
|
||||
$v['avatar'] = db::name('user')->where('id', $v['user_id'])->value('avatar');
|
||||
$v['nickname'] = db::name('user')->where('id', $v['user_id'])->value('nickname');
|
||||
$v['sex'] = db::name('user')->where('id', $v['user_id'])->value('sex');
|
||||
//头像装扮
|
||||
$v['dress'] = model('Decorate')->user_decorate_detail($v['user_id'],1);
|
||||
|
||||
$v['title'] = [];
|
||||
if(isset($v['topic_id'])){
|
||||
$top = explode(',', $v['topic_id']);
|
||||
foreach ($top as $kk){
|
||||
$title = db::name('topic')->where(['id' => $kk])->find();
|
||||
if(isset($title)){
|
||||
$title['topic_id'] = $title['id'];
|
||||
$title['count'] = db::name('user_zone_topic')->where('topic_id',$kk)->count();
|
||||
}
|
||||
$v['title'][] =$title;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
//删除动态
|
||||
public function delete_zone($uid, $zid)
|
||||
{
|
||||
$map['user_id'] = $uid;
|
||||
$map['id'] = $zid;
|
||||
$map['is_delete'] = 1;
|
||||
$zone_info = db::name('user_zone')->where($map)->find();
|
||||
if (empty($zone_info)) {
|
||||
return ['code' => 0, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['is_delete'] = 2;
|
||||
$data['delete_time'] = time();
|
||||
$reslut = db::name('user_zone')->where('id', $zid)->update($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '删除失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//删除评论
|
||||
public function delete_zone_comment($uid,$cid)
|
||||
{
|
||||
$map = [];
|
||||
$map['user_id'] = $uid;
|
||||
$map['id'] = $cid;
|
||||
$map['is_delete'] =1;
|
||||
$comment_info = db::name('user_zone_comment')->where($map)->find();
|
||||
if (empty($comment_info)) {
|
||||
return ['code' => 0, 'msg'=> '评论不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['is_delete'] = 2;
|
||||
$data['updatetime'] = time();
|
||||
//开启事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
$reslut = db::name('user_zone_comment')->where('id', $cid)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试!', 'data' => null];
|
||||
}
|
||||
//删除评论的回复
|
||||
$dd = db::name('user_zone_comment')->where('pid', $cid)->find();
|
||||
if($dd){
|
||||
$reslut1 = db::name('user_zone_comment')->where('pid', $cid)->update(['is_delete' => 2,'updatetime' => time()]);
|
||||
if (!$reslut1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试!!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//减少评论数量
|
||||
$num = db::name('user_zone_comment')->where('pid', $cid)->count();
|
||||
if($num > 0){
|
||||
$num = $num + 1;
|
||||
}else{
|
||||
$num = 1;
|
||||
}
|
||||
$reslut2 = db::name('user_zone')->where('id', $comment_info['zone_id'])->setDec('comment_num', $num);
|
||||
if (!$reslut2) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '请重试!!', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试.", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//扩列
|
||||
public function expand_zone($uid, $type, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
if($type){
|
||||
$map['a.sex'] = $type;
|
||||
}else{
|
||||
$map['a.sex'] = ['in', [1, 2]];
|
||||
}
|
||||
$map['a.status'] = 1;
|
||||
//查询用户信息
|
||||
$user_info = db::name('user')->alias('a')->join('fa_user_data b', 'a.id = b.user_id')
|
||||
->where($map)->field('a.id as user_id,a.sex,a.nickname,a.avatar,a.birthday,a.address_ip as loginip,b.home_bgimages')
|
||||
->order('a.id desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
if($user_info){
|
||||
foreach ($user_info as &$v){
|
||||
if($v['loginip'] == null){
|
||||
$v['loginip'] = '未知';
|
||||
}else{
|
||||
//获取字符串的长度和 判断字符串里面是否有,
|
||||
if((mb_strlen($v['loginip'], 'utf-8') > 8 && mb_strpos($v['loginip'], ',') !== false)){
|
||||
$ipd = explode(',', $v['loginip']);
|
||||
$v['loginip'] = $ipd[0].' · '.$ipd[1];//省·市
|
||||
}else{
|
||||
$v['loginip'] = '未知';
|
||||
}
|
||||
}
|
||||
$v['room_id'] = 0;
|
||||
//是否在房间
|
||||
$is_room = db::name('vs_room_visitor')->where(['user_id' => $v['user_id'], 'is_delete' => 1])->order('id desc')->value('room_id');
|
||||
if ($is_room) {
|
||||
$v['room_id'] = $is_room;
|
||||
}
|
||||
//用户等级标
|
||||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
||||
$v['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
|
||||
}
|
||||
}
|
||||
return $user_info;
|
||||
}
|
||||
|
||||
//相互关注的用户
|
||||
public function mutual_follow($uid, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
$map = [];
|
||||
$map['a.user_id'] = $uid;//我关注的
|
||||
$map['a.type'] = 1;
|
||||
$model = Db::name('user_follow')->alias('a')->join('fa_user b', 'a.follow_id = b.id');
|
||||
$list = $model->where($map)
|
||||
->field('b.id as user_id,b.nickname,b.avatar,b.sex')
|
||||
->order('a.id desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$user_list = [];
|
||||
if($list){
|
||||
foreach ($list as &$v){
|
||||
//我关注的是否关注我了
|
||||
$is_follow = db::name('user_follow')->where(['user_id' => $v['id'], 'follow_id' => $uid, 'type' => 1])->find();
|
||||
if($is_follow){
|
||||
$i = 0;
|
||||
$user_list[$i]['user_id'] = $v['user_id'];
|
||||
$user_list[$i]['nickname'] = $v['nickname'];
|
||||
$user_list[$i]['avatar'] = $v['avatar'];
|
||||
$user_list[$i]['sex'] = $v['sex'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $user_list??[];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
27
application/api/model/Version.php
Normal file
27
application/api/model/Version.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\Model;
|
||||
use think\Session;
|
||||
|
||||
class Version extends Model
|
||||
{
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'salt'
|
||||
];
|
||||
|
||||
public static function init()
|
||||
{
|
||||
self::beforeWrite(function ($row) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user