初始化代码
This commit is contained in:
71
application/api/model/AdaPay.php
Normal file
71
application/api/model/AdaPay.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class AdaPay
|
||||
{
|
||||
|
||||
private $config_object = [
|
||||
"api_key_live" => "api_live_e6e24c8d-c257-4dd7-856c-3d82f475820b",
|
||||
"rsa_private_key" => "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAN+4r227xPKzSWRaaDRZmVdANi/0y6kuPs/x6r9JmOaOL8T3PRLnSLLPZiKQYIPxyxsdnvxWn4tA7R6SndfQtOHxpMcefLanwDnCGDDIYEHKk8laSN6UmqFhF8xY50uIf73EdGQ7P1RmjyeSqjtakzjHM9nIM24I+8Rxyr1i67yjAgMBAAECgYEAodXHkWmzHp3zCVUc7EGkWyloCWjbqpZ5eZNWbOmgYaeZhrISzAni3PaKu5YVO109v2++AmvnHaTp4qPM6sFfFngmbp0ztsGmomoNFP9z+ruGlHbK8iWt8PlrfrgttAoIi7PrAbz+9fkbI4mPs149ECV+RHlU+EjkWh9bwqL9/wECQQD8tUEYm4ILvy8CJ67i/sE1MV8Nwjkbxy+ayY7h0mUBgo02e5W0CZYmyq4KUyshqjsOLVXcuefH9OkP7D0TkToJAkEA4qLDx1B3R8d6dbm8UgWxDlX5Tab/aO2WXjbIM7W1lW+jI34A2wNbR11VIhzY2gqyBgP0tz0fc2pfSx1NbYDcSwJBAPPBJgRFY+BOzlomyvObxeO4Nra/xHQ94nZMuyyp09HsCqgl9xXNNW8/izbcWDtFx2b6Zdrd22utme1I8vTf3XkCQHAeochrEHecQgMXvgi99BfphIpcAaNBVtCJPYYHcSvarNSUM4wmHvQxQjq8FrPX8rZzIo+8V2Db0QTyHCn+Q/0CQDdNUVfKNrcDBaAtNKW5GBzjXdVYbb4g6vOZ8FT/G8C4kwXsQlwtl61N1ZpQhao9vml6UJEP72hMU8XLMyEFRv4=",
|
||||
"rsa_public_key" => "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB"
|
||||
];
|
||||
private $app_id = 'app_260e8610-8ee2-498a-8fec-66fa866bb072';
|
||||
public function create_order($order_sn, $amount, $uid)
|
||||
{
|
||||
require_once Env::get('root_path') . 'extend/adapay_sdk_php_v1.4.4/AdapaySdk/init.php';
|
||||
\AdaPay\AdaPay::init($this->config_object, "live", true);
|
||||
$payment = new \AdaPaySdk\Payment();
|
||||
$payment_params = array(
|
||||
'app_id'=> $this->app_id,
|
||||
// 'app_id'=> 'app_f7841d17-8d4e-469f-82da-1c3f43c3e470',
|
||||
'order_no'=> $order_sn,
|
||||
'pay_channel'=> 'alipay',
|
||||
//'time_expire'=> date("YmdHis", time()+86400),
|
||||
'pay_amt'=> bcdiv(bcmul($amount, 100, 2), 100, 2),
|
||||
'goods_title'=> '狸猫支付',
|
||||
'goods_desc'=> '狸猫支付',
|
||||
'description'=> 'description',
|
||||
'device_info'=> ['device_p'=>"111.121.9.10"],
|
||||
'notify_url' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/api/pay_notify/ada_ali_pay_notify'
|
||||
);
|
||||
|
||||
//延迟分账
|
||||
// if($uid==217072){
|
||||
$payment_params['pay_mode'] = 'delay';
|
||||
// }
|
||||
|
||||
|
||||
# 发起支付
|
||||
$payment->create($payment_params);
|
||||
|
||||
# 对支付结果进行处理
|
||||
if ($payment->isError()){
|
||||
//失败处理
|
||||
return ['code' => 201, 'msg' => '支付失败', 'data' => null];
|
||||
} else {
|
||||
//成功处理
|
||||
|
||||
return ['code' => 200, 'msg' => '支付成功', 'data' => ['pay_info' => $payment->result['expend']['pay_info']],'result'=>$payment->result];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function verify_sign($post_data_str, $post_sign_str)
|
||||
{
|
||||
require_once Env::get('root_path') . 'extend/adapay_sdk_php_v1.4.4/AdapaySdk/init.php';
|
||||
\AdaPay\AdaPay::init($this->config_object, "live", true);
|
||||
$adapay_tools = new \AdaPaySdk\AdapayTools();
|
||||
$sign_flag = $adapay_tools->verifySign($post_data_str, $post_sign_str);
|
||||
if ($sign_flag){
|
||||
return ['code' => 200, 'msg' => '验签成功', 'data' => null];
|
||||
# 业务方自己的逻辑
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '验签失败', 'data' => null];
|
||||
# 业务方自己的逻辑
|
||||
}
|
||||
}
|
||||
}
|
||||
475
application/api/model/Agora.php
Normal file
475
application/api/model/Agora.php
Normal file
@@ -0,0 +1,475 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class Agora extends Model
|
||||
{
|
||||
//获取歌曲列表
|
||||
public function agora_song_list($page, $page_limit, $song_code){
|
||||
$config = get_uncache_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_uncache_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_uncache_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){
|
||||
require_once Env::get('root_path') . 'extend/shengwang/Shengwang.php';
|
||||
$config = model('admin/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_uncache_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)
|
||||
{
|
||||
require_once Env::get('root_path') . 'extend/shengwang/Shengwang.php';
|
||||
$config = model('admin/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->RtmTokenBuilder($uid, $agora_app_id, $agora_app_certificate);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
307
application/api/model/AgoraAuth.php
Normal file
307
application/api/model/AgoraAuth.php
Normal file
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class AgoraAuth extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 登录接口,获取针对当前用户(UID)的短期令牌Code
|
||||
* 调用方:APP端
|
||||
*/
|
||||
public function get_code($uid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$now_time = time();
|
||||
|
||||
//删除用户已有code
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$user_code = db::name('user_agora_code')->where($map)->delete();
|
||||
|
||||
$code = md5($uid . date('YmdHis') . generateRandom(32));
|
||||
|
||||
//生成用户code
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['code'] = $code;
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['expire_time'] = $now_time + (60*60*2);
|
||||
$reslut = db::name('user_agora_code')->insert($insert);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '获取失败', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['code'] = $code;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 短期令牌Code更换长期令牌SSToken
|
||||
* 调用方:游戏服务
|
||||
*
|
||||
*/
|
||||
public function get_sstoken($data){
|
||||
$now_time = time();
|
||||
// $data = json_decode($data,true);
|
||||
// dump($data);exit;
|
||||
$code = $data['code'];
|
||||
|
||||
$map = [];
|
||||
$map[] = ['code', '=', $code];
|
||||
$code_info = db::name('user_agora_code')->where($map)->find();
|
||||
if(!$code_info){
|
||||
$data = [];
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Code非法', 'sdk_error_code' => 9999, 'data' => $data];
|
||||
}
|
||||
|
||||
//code 是否过期
|
||||
if($code_info['expire_time'] < time()){
|
||||
$data = [];
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Code已过期', 'sdk_error_code' => 1005, 'data' => $data];
|
||||
}
|
||||
|
||||
//是否有该用户token
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $code_info['uid']];
|
||||
$token_info = db::name('user_agora_token')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.uid,a.token,a.expire_time,b.nick_name,b.base64_nick_name,b.head_pic,b.sex')->where($map)->order('a.add_time desc')->find();
|
||||
if($token_info){
|
||||
//是否过期
|
||||
if($token_info['expire_time'] < time()){
|
||||
$datas = [];
|
||||
$datas['ss_token'] = $token_info['token'];
|
||||
// $data['expire_date'] = $token_info['expire_time'] * 1000;
|
||||
// return ['ret_code' => 1, 'ret_msg' => 'Token已过期,请重新生成', 'sdk_error_code' => 1005, 'data' => $data];
|
||||
$update_sstoken = $this->update_sstoken($datas);
|
||||
if($update_sstoken['ret_code'] == 0){
|
||||
$data = $update_sstoken['data'];
|
||||
}else{
|
||||
$data = [];
|
||||
return ['ret_code' => 1, 'ret_msg' => '未知错误', 'sdk_error_code' => 9999, 'data' => $data];
|
||||
}
|
||||
}else{
|
||||
if($token_info['sex'] == 1){
|
||||
$sex = 'male';
|
||||
}else if($token_info['sex'] == 2){
|
||||
$sex = 'female';
|
||||
}else{
|
||||
$sex = '';
|
||||
}
|
||||
$data = [];
|
||||
$data['ss_token'] = $token_info['token'];
|
||||
$data['expire_date'] = $token_info['expire_time'] * 1000;
|
||||
$data['user_info']['uid'] = strval($token_info['uid']);
|
||||
$data['user_info']['nick_name'] = mb_convert_encoding(base64_decode($token_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['user_info']['avatar_url'] = localpath_to_netpath($token_info['head_pic']);
|
||||
$data['user_info']['gender'] = $sex;
|
||||
$data['user_info']['is_ai'] = 0;
|
||||
|
||||
}
|
||||
}else{
|
||||
$token = md5(md5($code_info['uid'] . date('YmdHis') . generateRandom(32)));
|
||||
//生成用户token
|
||||
$insert = [];
|
||||
$insert['uid'] = $code_info['uid'];
|
||||
$insert['token'] = $token;
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['expire_time'] = $now_time + (60*60*24*30);
|
||||
$reslut = db::name('user_agora_token')->insert($insert);
|
||||
if(!$reslut){
|
||||
$data = [];
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Token创建失败', 'sdk_error_code' => 1001, 'data' => $data];
|
||||
}
|
||||
|
||||
$user_info = db::name('user')->find($code_info['uid']);
|
||||
if($user_info['sex'] == 1){
|
||||
$sex = 'male';
|
||||
}else if($user_info['sex'] == 2){
|
||||
$sex = 'female';
|
||||
}else{
|
||||
$sex = '';
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['ss_token'] = $token;
|
||||
$data['expire_date'] = $insert['expire_time'] * 1000;
|
||||
$data['user_info']['uid'] = strval($code_info['uid']);
|
||||
$data['user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['user_info']['avatar_url'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$data['user_info']['gender'] = $sex;
|
||||
$data['user_info']['is_ai'] = 0;
|
||||
|
||||
}
|
||||
|
||||
return ['ret_code' => 0, 'ret_msg' => '', 'sdk_error_code' => 0, 'data' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新长期令牌
|
||||
* 调用方:游戏服务
|
||||
*
|
||||
*/
|
||||
public function update_sstoken($data){
|
||||
$token = $data['ss_token'];
|
||||
$map = [];
|
||||
$map[] = ['token', '=', $token];
|
||||
$token_info = db::name('user_agora_token')->where($map)->find();
|
||||
if(!$token_info){
|
||||
$data = [];
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Token非法', 'sdk_error_code' => 1004, 'data' => $data];
|
||||
}
|
||||
|
||||
$uid = $token_info['uid'];
|
||||
$token = md5(md5($uid . date('YmdHis') . generateRandom(32)));
|
||||
$now_time = time();
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if($user_info['sex'] == 1){
|
||||
$sex = 'male';
|
||||
}else if($user_info['sex'] == 2){
|
||||
$sex = 'female';
|
||||
}else{
|
||||
$sex = '';
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//删除之前的token
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$reslut = db::name('user_agora_token')->where($map)->delete();
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['ret_code' => 1, 'ret_msg' => '未知错误', 'sdk_error_code' => 9999, 'data' => []];
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['token'] = $token;
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['expire_time'] = $now_time + (60*60*24*30);
|
||||
$reslut = db::name('user_agora_token')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Token创建失败', 'sdk_error_code' => 1001, 'data' => []];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['ss_token'] = $token;
|
||||
$data['expire_date'] = $insert['expire_time'] * 1000;
|
||||
$data['user_info']['uid'] = strval($user_info['uid']);
|
||||
$data['user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['user_info']['avatar_url'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$data['user_info']['gender'] = $sex;
|
||||
$data['user_info']['is_ai'] = 0;
|
||||
|
||||
Db::commit();
|
||||
return ['ret_code' => 0, 'ret_msg' => '', 'sdk_error_code' => 0, 'data' => $data];
|
||||
} catch (\Exception $e) {
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['ret_code' => 1, 'ret_msg' => '未知错误', 'sdk_error_code' => 9999, 'data' => []];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* 调用方:游戏服务
|
||||
*
|
||||
*/
|
||||
public function get_user_info($data){
|
||||
$token = $data['ss_token'];
|
||||
|
||||
$map = [];
|
||||
$map[] = ['token', '=', $token];
|
||||
$token_info = db::name('user_agora_token')->where($map)->find();
|
||||
if(!$token_info){
|
||||
$data = [];
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Token非法', 'sdk_error_code' => 1004, 'data' => $data];
|
||||
}
|
||||
|
||||
//token是否过期
|
||||
if($token_info['expire_time'] < time()){
|
||||
$data = [];
|
||||
$data['ss_token'] = $token_info['token'];
|
||||
$data['expire_date'] = $token_info['expire_time'];
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Token已过期', 'sdk_error_code' => 1005, 'data' => $data];
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
$user_info = db::name('user')->find($token_info['uid']);
|
||||
if($user_info['sex'] == 1){
|
||||
$sex = 'male';
|
||||
}else if($user_info['sex'] == 2){
|
||||
$sex = 'female';
|
||||
}else{
|
||||
$sex = '';
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = strval($user_info['uid']);
|
||||
$data['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['avatar_url'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$data['gender'] = $sex;
|
||||
|
||||
return ['ret_code' => 0, 'ret_msg' => '', 'sdk_error_code' => 0, 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 游戏服务端上报游戏接入方的游戏的数据
|
||||
* 调用方:游戏服务
|
||||
*
|
||||
*/
|
||||
public function report_game_info($data){
|
||||
$now_time = time();
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $data['uid']];
|
||||
$map[] = ['token', '=', $data['ss_token']];
|
||||
$token_info = db::name('user_agora_token')->where($map)->find();
|
||||
if(!$token_info){
|
||||
$data = [];
|
||||
return ['ret_code' => 1, 'ret_msg' => 'Token非法', 'sdk_error_code' => 1004, 'data' => $data];
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
if($data['report_type'] == 'game_start'){
|
||||
$insert['report_type'] = 1;
|
||||
$insert['players'] = json_encode($data['report_msg']['players']);
|
||||
}else{
|
||||
$insert['report_type'] = 2;
|
||||
$insert['battle_end_at'] = $data['report_msg']['battle_end_at'];
|
||||
$insert['battle_duration'] = $data['report_msg']['battle_duration'];
|
||||
$insert['results'] = json_encode($data['report_msg']['results']);
|
||||
}
|
||||
$insert['mg_id'] = $data['report_msg']['mg_id'];
|
||||
$insert['room_id'] = $data['report_msg']['room_id'];
|
||||
$insert['game_mode'] = $data['report_msg']['game_mode'];
|
||||
$insert['game_round_id'] = $data['report_msg']['game_round_id'];
|
||||
$insert['battle_start_at'] = $data['report_msg']['battle_start_at'];
|
||||
$insert['report_game_info_extras'] = $data['report_msg']['report_game_info_extras'];
|
||||
$insert['report_game_info_key'] = $data['report_msg']['report_game_info_key'];
|
||||
$insert['uid'] = $data['uid'];
|
||||
$insert['token'] = $data['ss_token'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$reslut = db::name('agora_game_log')->insert($insert);
|
||||
if($reslut){
|
||||
return ['ret_code' => 0, 'ret_msg' => ''];
|
||||
}else{
|
||||
return ['ret_code' => 1, 'ret_msg' => ''];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
117
application/api/model/AgoraCallback.php
Normal file
117
application/api/model/AgoraCallback.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class AgoraCallback extends Model
|
||||
{
|
||||
|
||||
//封禁用户
|
||||
public function kicking_user($uid, $rid, $time = 1){
|
||||
$config = get_uncache_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];
|
||||
|
||||
$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);
|
||||
|
||||
$curlPost = array(
|
||||
'appid' => $agora_app_id,
|
||||
'cname' => strval($rid),
|
||||
'uid' => $uid,
|
||||
'time' => $time,
|
||||
'privileges' => array(
|
||||
'join_channel'
|
||||
)
|
||||
);
|
||||
|
||||
$postUrl = "https://api.sd-rtn.com/dev/v1/kicking-rule";
|
||||
$curlPost = json_encode($curlPost);
|
||||
$result = $this->agora_post_url($postUrl, $curlPost);
|
||||
if($result['status'] == 'success'){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public function channel_room($rid){
|
||||
$config = get_uncache_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];//cc71b8df2c254c35bc96fbf591b6801f
|
||||
$agora_app_key = $config['agora_app_key'];
|
||||
$agora_app_secret = $config['agora_app_secret'];
|
||||
$credentials = $agora_app_key . ":" . $agora_app_secret;
|
||||
$rid = strval($rid);
|
||||
|
||||
// 使用 base64 进行编码
|
||||
$AuthorizationHeader = base64_encode($credentials);
|
||||
|
||||
$postUrl = 'https://api.sd-rtn.com/dev/v1/channel/user/'.$agora_app_id.'/'.$rid.'/hosts_only';
|
||||
$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['success']){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//请求封装方法
|
||||
public function agora_post_url($postUrl, $curlPost){
|
||||
$config = get_uncache_system_config();
|
||||
$agora_app_id = $config['agora_app_id'];
|
||||
|
||||
$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);
|
||||
|
||||
$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, 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;
|
||||
}
|
||||
}
|
||||
113
application/api/model/AgoraGame.php
Normal file
113
application/api/model/AgoraGame.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class AgoraGame extends Model
|
||||
{
|
||||
|
||||
//房间开始游戏
|
||||
public function room_game_start($uid, $rid, $game_id){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限
|
||||
// $room_admin_uid_arr = explode(',', $room_info['room_admin_uid']);
|
||||
// if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr)) {
|
||||
// return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
// }
|
||||
|
||||
|
||||
$room_admin_uid_arr = db::name('room_admin')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
$room_host_uid_arr = db::name('room_host')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
// if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr) && !in_array($uid, $room_host_uid_arr)) {
|
||||
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_host_uid_arr)) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//修改状态
|
||||
$update = [];
|
||||
$update['game_status'] = 1;
|
||||
$update['game_id'] = $game_id;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '开始失败', 'data' => null];
|
||||
}
|
||||
|
||||
//发送socket
|
||||
$data = [];
|
||||
$data['rid'] = $rid;
|
||||
$data['game_id'] = $game_id;
|
||||
$data['game_status'] = 1;
|
||||
$push_data = [];
|
||||
$push_data['code'] = 330;
|
||||
$push_data['msg'] = "房间游戏开始";
|
||||
$push_data['data'] = $data;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
|
||||
|
||||
model('Room')->push_room_micro_data($rid); //推送最新房间麦位信息
|
||||
|
||||
return ['code' => 200, 'msg' => '游戏开始', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
//房间结束游戏
|
||||
public function room_game_end($uid, $rid, $game_id){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限
|
||||
// $room_admin_uid_arr = explode(',', $room_info['room_admin_uid']);
|
||||
// if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr)) {
|
||||
// return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
// }
|
||||
|
||||
|
||||
$room_admin_uid_arr = db::name('room_admin')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
$room_host_uid_arr = db::name('room_host')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
// if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr) && !in_array($uid, $room_host_uid_arr)) {
|
||||
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_host_uid_arr)) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//修改状态
|
||||
$update = [];
|
||||
$update['game_status'] = 2;
|
||||
$update['game_id'] = 0;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//发送socket
|
||||
$data = [];
|
||||
$data['rid'] = $rid;
|
||||
$data['game_id'] = $game_id;
|
||||
$data['game_status'] = 2;
|
||||
$push_data = [];
|
||||
$push_data['code'] = 331;
|
||||
$push_data['msg'] = "房间游戏结束";
|
||||
$push_data['data'] = $data;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
|
||||
model('Room')->push_room_micro_data($rid); //推送最新房间麦位信息
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '游戏结束', 'data' => $data];
|
||||
}
|
||||
|
||||
}
|
||||
56
application/api/model/AliRealNameVerify.php
Normal file
56
application/api/model/AliRealNameVerify.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class AliRealNameVerify extends Model
|
||||
{
|
||||
|
||||
//身份证二要素认证
|
||||
public function real_name_verify($real_name, $card_id)
|
||||
{
|
||||
|
||||
$host = "https://eid.shumaidata.com";
|
||||
$path = "/eid/check";
|
||||
$method = "POST";
|
||||
// $appcode = "b984f1e3220649bb8e9a9796808da36f";
|
||||
$appcode = "c98b2b9cdde747cabd1878dc4eefefc8";
|
||||
|
||||
|
||||
$headers = array();
|
||||
array_push($headers, "Authorization:APPCODE " . $appcode);
|
||||
$querys = "idcard=".$card_id."&name=".urlencode($real_name);
|
||||
$bodys = "";
|
||||
$url = $host . $path . "?" . $querys;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
//设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
|
||||
//如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
if (1 == strpos("$".$host, "https://"))
|
||||
{
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
|
||||
$result = curl_exec($curl);
|
||||
if($result) {
|
||||
$arr = json_decode($result, true);
|
||||
if($arr){
|
||||
if($arr['code'] == 0) {
|
||||
return ['code' => 200, 'msg' => '验证成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '姓名与身份证核验不一致', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['code' => 201, 'msg' => '验证错误', 'data' => null];
|
||||
}
|
||||
}
|
||||
193
application/api/model/AsyncPushMessage.php
Normal file
193
application/api/model/AsyncPushMessage.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class AsyncPushMessage
|
||||
{
|
||||
//数据存入队列
|
||||
public $keyname = 'async:push:message';
|
||||
public $mutil = 0.8;
|
||||
public $is_compute = 0; //1 计算 0 不计算
|
||||
public $integral_name = '金币';
|
||||
/*
|
||||
$type=1 1 转赠 2 单个礼物 3 一键送礼物 4 盲盒
|
||||
*/
|
||||
public function store_message($message_data, $type)
|
||||
{
|
||||
$this->deal_message_data($message_data, $type);
|
||||
}
|
||||
private function _store_message($from_uid, $to_uid, $message, $type)
|
||||
{
|
||||
$data = [
|
||||
'from_uid' => $from_uid,
|
||||
'to_uid' => $to_uid,
|
||||
'message' => $message,
|
||||
'type' => $type,
|
||||
];
|
||||
$json_data = json_encode($data);
|
||||
$redis = connectionRedis();
|
||||
$redis->rpush($this->keyname, $json_data);
|
||||
}
|
||||
|
||||
//发送消息
|
||||
public function send_message()
|
||||
{
|
||||
$redis = connectionRedis();
|
||||
$redis_len = $redis->llen($this->keyname);
|
||||
// dump($redis_len);die;
|
||||
if(empty($redis_len)) {
|
||||
return true;
|
||||
}
|
||||
$json_data = $redis->blpop($this->keyname, 1);
|
||||
if(empty($json_data)) {
|
||||
return true;
|
||||
}
|
||||
$json_data = $json_data[1];
|
||||
$data = json_decode($json_data, true);
|
||||
$from_uid = $data['from_uid'];
|
||||
$to_uid = $data['to_uid'];
|
||||
$message = $data['message'];
|
||||
$type = $data['type'];
|
||||
$send_data['text'] = $message;
|
||||
if($type == 2) {
|
||||
$send_data['businessID'] = 'custom_gift_record';
|
||||
}elseif($type == 1) {
|
||||
$send_data['businessID'] = 'custom_hongbao';
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
$tencent_message = json_encode($send_data);
|
||||
$res = model('api/Tencent')->user_custom_sendmsg($from_uid, $to_uid, $tencent_message, 1);
|
||||
|
||||
}
|
||||
|
||||
public function deal_message_data($message_data, $type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$from_uid = $message_data['from_uid'];
|
||||
$to_uid = $message_data['to_uid'];
|
||||
$integral = $message_data['integral'];
|
||||
$message = '给您发了' . $integral . $this->integral_name;
|
||||
$this->_store_message($from_uid, $to_uid, $message, 1);
|
||||
$async_push_message_data = [
|
||||
'uid' => $from_uid,
|
||||
'receive_uid' => $to_uid,
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'total_amount' => $integral,
|
||||
'add_time' => time(),
|
||||
'rid' => 0
|
||||
];
|
||||
Db::name('async_push_message_log')->insert($async_push_message_data);
|
||||
// code...
|
||||
break;
|
||||
case 2:
|
||||
$async_push_message_data = [];
|
||||
foreach($message_data as $val) {
|
||||
$from_uid = $val['from_uid'];
|
||||
$to_uid = $val['to_uid'];
|
||||
$gift_name = $val['gift_name'];
|
||||
$gift_num = $val['gift_num'];
|
||||
$gift_price = $val['gift_price'];
|
||||
$total_gift_price = $gift_price * $gift_num;
|
||||
$message = "送出了{$gift_name}({$gift_price}".$this->integral_name.")*{$gift_num}";
|
||||
if($this->is_compute == 1) {
|
||||
$message .= "\n总计:" . $total_gift_price . '*' . $this->mutil . '=' . (bcmul($total_gift_price, $this->mutil, 2));
|
||||
} else {
|
||||
$message .= "总计:" . $total_gift_price;
|
||||
}
|
||||
$this->_store_message($from_uid, $to_uid, $message, 2);
|
||||
$temp = [
|
||||
'uid' => $from_uid,
|
||||
'receive_uid' => $to_uid,
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'total_amount' => $total_gift_price,
|
||||
'add_time' => time(),
|
||||
'rid' => $val['rid']
|
||||
];
|
||||
$async_push_message_data[] = $temp;
|
||||
}
|
||||
if($async_push_message_data) {
|
||||
Db::name('async_push_message_log')->insertAll($async_push_message_data);
|
||||
}
|
||||
// code...
|
||||
break;
|
||||
case 3:
|
||||
$from_uid = $message_data['from_uid'];
|
||||
$to_uid = $message_data['to_uid'];
|
||||
$gift_list = $message_data['gift_list'];
|
||||
$rid = $message_data['rid'];
|
||||
$total_amount = 0;
|
||||
$message = '送出了';
|
||||
foreach($gift_list as $val) {
|
||||
|
||||
$gift_name = $val['gift_name'];
|
||||
$gift_num = $val['gift_num'];
|
||||
$gift_price = $val['gift_price'];
|
||||
$gift_total_price = ($gift_price * $gift_num);
|
||||
$total_amount += $gift_total_price;
|
||||
$message .= "{$gift_name}({$gift_price}".$this->integral_name.")*{$gift_num}";
|
||||
}
|
||||
$message .= ";";
|
||||
if($this->is_compute == 1) {
|
||||
$message .= "总计:". $total_amount . "*" . $this->mutil . "=" . (bcmul($total_amount, $this->mutil, 2));
|
||||
} else {
|
||||
$message .= "总计:" . $total_amount;
|
||||
}
|
||||
$this->_store_message($from_uid, $to_uid, $message, 2);
|
||||
$async_push_message_data = [
|
||||
'uid' => $from_uid,
|
||||
'receive_uid' => $to_uid,
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'total_amount' => $total_amount,
|
||||
'add_time' => time(),
|
||||
'rid' => $rid
|
||||
];
|
||||
Db::name('async_push_message_log')->insert($async_push_message_data);
|
||||
// code...
|
||||
break;
|
||||
case 4:
|
||||
$from_uid = $message_data['from_uid'];
|
||||
$to_uid = $message_data['to_uid'];
|
||||
$gift_list = $message_data['gift_list'];
|
||||
$rid = $message_data['rid'];
|
||||
$total_amount = 0;
|
||||
$message = '送出了';
|
||||
foreach($gift_list as $val) {
|
||||
$gift_name = $val['gift_name'];
|
||||
$gift_num = $val['gift_num'];
|
||||
$gift_price = $val['gift_price'];
|
||||
$gift_total_price = ($gift_price * $gift_num);
|
||||
$total_amount += $gift_total_price;
|
||||
$message .= "{$gift_name}({$gift_price}".$this->integral_name.")*{$gift_num}";
|
||||
}
|
||||
$message .= ";";
|
||||
if($this->is_compute == 1) {
|
||||
$message .= "总计:". $total_amount . "*" . $this->mutil . "=" . (bcmul($total_amount, $this->mutil, 2));
|
||||
} else {
|
||||
$message .= "总计:" . $total_amount;
|
||||
}
|
||||
$this->_store_message($from_uid, $to_uid, $message, 2);
|
||||
$async_push_message_data = [
|
||||
'uid' => $from_uid,
|
||||
'receive_uid' => $to_uid,
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'total_amount' => $total_amount,
|
||||
'add_time' => time(),
|
||||
'rid' => $rid
|
||||
];
|
||||
Db::name('async_push_message_log')->insert($async_push_message_data);
|
||||
break;
|
||||
default:
|
||||
// code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
552
application/api/model/AuctionRoom - 副本.php
Normal file
552
application/api/model/AuctionRoom - 副本.php
Normal file
@@ -0,0 +1,552 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class AuctionRoom extends Model
|
||||
{
|
||||
|
||||
//天数列表
|
||||
public function get_day_list(){
|
||||
$list = db::name('relation_duration')->field('day')->where('is_delete', 1)->order('day asc')->select();
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//礼物列表
|
||||
public function get_gift_list(){
|
||||
$config = get_uncache_system_config();
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
if(!empty($config['cp_gift_id'])){
|
||||
$map[] = ['gid', 'neq', $config['cp_gift_id']];
|
||||
}
|
||||
$list = db::name('gift')->field('gid,gift_name,base_image,gift_price')->where($map)->order('gift_price asc')->select();
|
||||
foreach($list as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//设置用户拍卖信息
|
||||
public function options_user_auction_info($uid, $rid, $relation_id, $gid, $day){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//当前麦上拍卖信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_auction_log')->where($map)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前尚未有拍卖信息', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_auction_info['status'] != 1){
|
||||
return ['code' => 201, 'msg' => '当前已开始竞拍,无法设置', 'data' => null];
|
||||
}
|
||||
|
||||
//是否是该用户的配置信息
|
||||
if($room_auction_info['uid'] != $uid){
|
||||
return ['code' => 201, 'msg' => '你无权限设置', 'data' => null];
|
||||
}
|
||||
|
||||
//关系是否存在
|
||||
$relation_info = db::name('relation')->where('id', $relation_id)->where('is_delete', 1)->find();
|
||||
if(!$relation_info){
|
||||
return ['code' => 201, 'msg' => '该关系不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//礼物是否存在
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$gift_info = db::name('gift')->where($map)->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '该礼物不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//天数是否存在
|
||||
$day_info = db::name('relation_duration')->where('is_delete', 1)->find();
|
||||
if(!$day_info){
|
||||
return ['code' => 201, 'msg' => '该天数不存在', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$update = [];
|
||||
$update['relation_id'] = $relation_id;
|
||||
$update['gid'] = $gid;
|
||||
$update['day'] = $day;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '设置失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '设置成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
|
||||
Db::rollback();
|
||||
dump($e);
|
||||
return ['code' => 201, 'msg' => '设置失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//开始拍卖
|
||||
public function open_auction($uid, $rid)
|
||||
{
|
||||
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限
|
||||
if($uid != $room_info['room_host_uid'] && $uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '您无权限进行该操作', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有新人在拍卖位上
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', '=', 1];
|
||||
$room_micro_info = db::name('room_micro')->where($map)->find();
|
||||
if($room_micro_info && $room_micro_info['uid'] <= 0){
|
||||
return ['code' => 201, 'msg' => '当前尚未有人在麦上,无法开启', 'data' => null];
|
||||
}
|
||||
|
||||
//当前是否已有待开始的拍卖
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_auction_log')->where($map)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前尚未有拍卖信息', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_auction_info['status'] == 2){
|
||||
return ['code' => 201, 'msg' => '当前已有进行中的拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($room_auction_info['relation_id']) || empty($room_auction_info['gid']) || empty($room_auction_info['day'])){
|
||||
return ['code' => 201, 'msg' => '拍卖位信息尚未设置完成', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//清除财富值
|
||||
db::name('room_visitor')->where([['rid','=',$rid]])->update(['change_value'=>0,'update_time'=>time()]);
|
||||
|
||||
|
||||
//开始拍卖
|
||||
$update = [];
|
||||
$update['status'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '开启成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//竞拍信息
|
||||
public function get_auction_info($uid, $rid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_auction_info = db::name('room_auction_log')->where('rid', $rid)->where('status', 2)->where('is_delete', 1)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未开启拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
$auction_user_info = db::name('user')->find($room_auction_info['uid']);
|
||||
$auction_gift_info = db::name('gift')->find($room_auction_info['gid']);
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $room_auction_info['uid'];
|
||||
$data['nick_name'] = mb_convert_encoding(base64_decode($auction_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['head_pic'] = localpath_to_netpath($auction_user_info['head_pic']);
|
||||
$data['gid'] = $room_auction_info['gid'];
|
||||
$data['gift_name'] = $auction_gift_info['gift_name'];
|
||||
$data['base_image'] = localpath_to_netpath($auction_gift_info['base_image']);
|
||||
$data['gift_price'] = $auction_gift_info['gift_price'];
|
||||
$data['integral'] = $user_info['integral'];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//记录用户竞拍信息
|
||||
public function record_user_auction_info($uid, $user_id, $rid, $gid, $gift_price, $num, $room_owner_uid){
|
||||
//当前房间进行中的拍卖信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
// $map[] = ['gid', '=', $gid];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_auction_log')->where($map)->order('id desc')->find();
|
||||
if($room_auction_info){
|
||||
if($uid == $room_owner_uid){
|
||||
return ['code' => 201, 'msg' => '主持无法参与竞拍', 'data' => null];
|
||||
}
|
||||
|
||||
if(!empty($room_auction_info['gid'])){
|
||||
$gift_info1 = db::name('gift')->where(['gid'=>$room_auction_info['gid'],'is_delete'=>1])->field('gift_price')->find();
|
||||
if(empty($gift_info1)){
|
||||
return ['code' => 201, 'msg' => '竞拍礼物不存在!', 'data' => null];
|
||||
}
|
||||
|
||||
$gift_info1_price = $gift_info1['gift_price'];
|
||||
if($gift_price < $gift_info1_price){
|
||||
return ['code' => 201, 'msg' => "礼物竞拍单价小于{$gift_info1_price}金币!", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//是否有该场次的赠送信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['raid', '=', $room_auction_info['id']];
|
||||
$map[] = ['auction_uid', '=', $uid];
|
||||
$map[] = ['uid', '=', $room_auction_info['uid']];
|
||||
// $map[] = ['gid', '=', $gid];
|
||||
$user_auction_info = db::name('user_room_auction_log')->where($map)->find();
|
||||
if(!$user_auction_info){
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['raid'] = $room_auction_info['id'];
|
||||
$insert['auction_uid'] = $uid;
|
||||
$insert['uid'] = $room_auction_info['uid'];
|
||||
// $insert['gid'] = $gid;
|
||||
$insert['num'] = $num;
|
||||
$insert['total_price'] = $gift_price * $num;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_room_auction_log')->insertGetId($insert);
|
||||
$pid = $reslut;
|
||||
}else{
|
||||
$total_price = $gift_price * $num;
|
||||
$reslut = db::name('user_room_auction_log')->where('id', $user_auction_info['id'])->inc('num', $num)->inc('total_price', $total_price)->update(['update_time' => time()]);
|
||||
$pid = $user_auction_info['id'];
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//总计
|
||||
// $room_auction_tj_info = db::name('user_room_auction_tj')->where(['pid'=>$pid,'auction_uid'=>$uid,'uid'=>$room_auction_info['uid']])->find();
|
||||
// if(empty($room_auction_tj_info)){
|
||||
// db::name('user_room_auction_tj')->insert([
|
||||
// 'pid' => $pid,
|
||||
// 'auction_uid' =>$uid,
|
||||
// 'uid' => $room_auction_info['uid'],
|
||||
// 'gift_total_price' => $gift_price * $num,
|
||||
// 'add_time' => time(),
|
||||
// 'update_time' => time()
|
||||
// ]);
|
||||
// }else{
|
||||
// $gift_total_price = $gift_price * $num;
|
||||
// db::name('user_room_auction_tj')->where(['id'=>$room_auction_tj_info['id']])->inc('gift_total_price',$gift_total_price)->update(['update_time' => time()]);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//明细
|
||||
db::name('user_room_auction_detail_log')->insert([
|
||||
'pid' => $pid,
|
||||
'auction_uid' =>$uid,
|
||||
'uid' => $room_auction_info['uid'],
|
||||
'gid' => $gid,
|
||||
'num' => $num,
|
||||
'gift_total_price' => $gift_price * $num,
|
||||
'add_time' => time()
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
//更新竞拍麦位信息
|
||||
$this->update_auction_micro($rid, $room_auction_info['id']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => null];
|
||||
|
||||
}
|
||||
|
||||
//更新竞拍麦位信息
|
||||
public function update_auction_micro($rid, $raid){
|
||||
//当前房间竞拍麦信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [2,3,4]];
|
||||
$room_micro_arr = db::name('room_micro')->where($map)->order('micro_id asc')->column('uid');
|
||||
|
||||
//当前竞拍前三
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['raid', '=', $raid];
|
||||
$list = db::name('user_room_auction_log')->where($map)->find();
|
||||
if(!empty($list)){
|
||||
$user_auction_arr = db::name('user_room_auction_log')->where($map)->order('total_price desc')->limit(3)->column('auction_uid');
|
||||
if($user_auction_arr != $room_micro_arr){
|
||||
foreach ($user_auction_arr as $k => $v){
|
||||
if($v != $room_micro_arr[$k]){
|
||||
//变更麦位信息
|
||||
$micro_id = $k + 2;
|
||||
db::name('room_micro')->where('rid', $rid)->where('micro_id', $micro_id)->update(['uid' => $v, 'update_time' => time()]);
|
||||
//是否有在其他麦位
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [5,6,7,8]];
|
||||
$map[] = ['uid', '=', $v];
|
||||
$info = db::name('room_micro')->where($map)->find();
|
||||
if($info){
|
||||
db::name('room_micro')->where('id', $info['id'])->update(['uid' => 0, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//结束拍卖
|
||||
public function finish_auction($uid, $rid){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限结束
|
||||
if($room_info['room_host_uid'] != $uid){
|
||||
return ['code' => 201, 'msg' => '当前麦上主持才可结束', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_auction_info = db::name('room_auction_log')->where('rid', $rid)->where('status', 2)->where('is_delete', 1)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未开启拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
//
|
||||
Db::startTrans();
|
||||
try {
|
||||
$now_time = time();
|
||||
|
||||
//是否有最高出价
|
||||
$room_auction_price_info = db::name('user_room_auction_log')->where('raid', $room_auction_info['id'])->order('total_price desc')->limit(1)->find();
|
||||
if(empty($room_auction_price_info)){//流拍
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update(['status' => 3, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 2;
|
||||
}else{
|
||||
//绑定关系
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['auction_uid']];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['uid']];
|
||||
$map[] = ['relation_id', '=', $room_auction_info['relation_id']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation = db::name('user_relation_binding')->where($map)->find();
|
||||
if($user_relation){//延长时间
|
||||
$update = [];
|
||||
// $update['day'] = $relation_info['day'];
|
||||
$update['end_time'] = $user_relation['end_time'] + ($room_auction_info['day'] * 60 * 60 * 24);
|
||||
$update['update_time'] = $now_time;
|
||||
$reslut = db::name('user_relation_binding')->where('id', $user_relation['id'])->inc('day', $room_auction_info['day'])->update($update);
|
||||
|
||||
}else{//添加
|
||||
$insert = [];
|
||||
$insert['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$insert['receive_uid'] = $room_auction_price_info['uid'];
|
||||
$insert['relation_id'] = $room_auction_info['relation_id'];
|
||||
$insert['day'] = $room_auction_info['day'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['end_time'] = $now_time + ($room_auction_info['day'] * 60 * 60 *24);
|
||||
$reslut = db::name('user_relation_binding')->insert($insert);
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//记录
|
||||
$insert = [];
|
||||
$insert['type'] = 2;
|
||||
$insert['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$insert['receive_uid'] = $room_auction_price_info['uid'];
|
||||
$insert['relation_id'] = $room_auction_info['relation_id'];
|
||||
$insert['day'] = $room_auction_info['day'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$reslut = db::name('user_relation_binding_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//摩天轮数据增加
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['auction_uid']];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['uid']];
|
||||
$map[] = ['r_date', '=', date('Y-m-d')];
|
||||
$dating_mt_wheel = db::name('dating_mt_wheel')->where($map)->find();
|
||||
if(!empty($dating_mt_wheel)){
|
||||
db::name('dating_mt_wheel')->where(['id'=>$dating_mt_wheel['id']])->inc('rank_value', $room_auction_price_info['total_price'])->update(['update_time'=>time()]);
|
||||
}else{
|
||||
//建立关系以后数据存储
|
||||
db::name('dating_mt_wheel')->insert([
|
||||
'uid' => $room_auction_price_info['auction_uid'],
|
||||
'receive_uid' => $room_auction_price_info['uid'],
|
||||
'rank_value' => $room_auction_price_info['total_price'],
|
||||
'r_date' => date('Y-m-d'),
|
||||
'add_time' => time(),
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update(['auction_uid' => $room_auction_price_info['auction_uid'], 'auction_num' => $room_auction_price_info['num'], 'status' => 3, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//结束当前拍卖价位
|
||||
$reslut = db::name('user_room_auction_log')->where('raid', $room_auction_info['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 1;
|
||||
}
|
||||
|
||||
//拍卖用户下麦
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [1,2,3,4]];
|
||||
$map[] = ['uid', '>', 0];
|
||||
$reslut = db::name('room_micro')->where($map)->update(['uid' => 0, 'update_time' => time(), 'frame_gid' => 0, 'centre_gid' => 0, 'above_gid' => 0, 'below_gid' => 0, 'left_gid' => 0, 'right_gid' => 0]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
// $reslut = model('api/room')->user_down_micro($room_auction_info['uid'], $rid, 2);
|
||||
// if($reslut['code'] != 200){
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
|
||||
//更新老板麦位
|
||||
model('RoomBossMicro')->update_room_boss_micro($rid);
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
if($is_push == 1){
|
||||
$auction_user_info = db::name('user')->find($room_auction_price_info['auction_uid']);
|
||||
$sign_user_info = db::name('user')->find($room_auction_price_info['uid']);
|
||||
|
||||
$push_message = [];
|
||||
$push_message['auction_user_info']['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$push_message['auction_user_info']['nick_name'] = mb_convert_encoding(base64_decode($auction_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['auction_user_info']['head_pic'] = localpath_to_netpath($auction_user_info['head_pic']);
|
||||
$push_message['sign_user_info']['uid'] = $room_auction_price_info['uid'];
|
||||
$push_message['sign_user_info']['nick_name'] = mb_convert_encoding(base64_decode($sign_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['sign_user_info']['head_pic'] = localpath_to_netpath($sign_user_info['head_pic']);
|
||||
$push_message['relation_name'] = db::name('relation')->where('id', $room_auction_info['relation_id'])->value('name');
|
||||
|
||||
//提示签约成功
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3005;
|
||||
$push_data['msg'] = "绑定关系成功";
|
||||
$push_data['data'] = $push_message;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '结束成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
865
application/api/model/AuctionRoom.php
Normal file
865
application/api/model/AuctionRoom.php
Normal file
@@ -0,0 +1,865 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Log;
|
||||
|
||||
class AuctionRoom extends Model
|
||||
{
|
||||
|
||||
//天数列表
|
||||
public function get_day_list(){
|
||||
$list = db::name('relation_duration')->field('day')->where('is_delete', 1)->order('day asc')->select();
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//礼物列表
|
||||
public function get_gift_list(){
|
||||
$config = get_uncache_system_config();
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
if(!empty($config['cp_gift_id'])){
|
||||
$map[] = ['gid', 'neq', $config['cp_gift_id']];
|
||||
}
|
||||
$list = db::name('gift')->field('gid,gift_name,base_image,gift_price')->where($map)->order('gift_price asc')->select();
|
||||
foreach($list as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//设置用户拍卖信息
|
||||
public function options_user_auction_info($uid, $rid, $relation_id, $gid, $day){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//当前麦上拍卖信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_auction_log')->where($map)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前尚未有拍卖信息', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_auction_info['status'] != 1){
|
||||
return ['code' => 201, 'msg' => '当前已开始竞拍,无法设置', 'data' => null];
|
||||
}
|
||||
|
||||
//是否是该用户的配置信息
|
||||
if($room_auction_info['uid'] != $uid){
|
||||
return ['code' => 201, 'msg' => '你无权限设置', 'data' => null];
|
||||
}
|
||||
|
||||
//关系是否存在
|
||||
$relation_info = db::name('relation')->where('id', $relation_id)->where('is_delete', 1)->find();
|
||||
if(!$relation_info){
|
||||
return ['code' => 201, 'msg' => '该关系不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//礼物是否存在
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$gift_info = db::name('gift')->where($map)->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '该礼物不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//天数是否存在
|
||||
$day_info = db::name('relation_duration')->where('is_delete', 1)->find();
|
||||
if(!$day_info){
|
||||
return ['code' => 201, 'msg' => '该天数不存在', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$update = [];
|
||||
$update['relation_id'] = $relation_id;
|
||||
$update['gid'] = $gid;
|
||||
$update['day'] = $day;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '设置失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '设置成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
|
||||
Db::rollback();
|
||||
dump($e);
|
||||
return ['code' => 201, 'msg' => '设置失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//开始拍卖
|
||||
public function open_auction($uid, $rid)
|
||||
{
|
||||
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限
|
||||
if($uid != $room_info['room_host_uid'] && $uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '您无权限进行该操作', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有新人在拍卖位上
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', '=', 1];
|
||||
$room_micro_info = db::name('room_micro')->where($map)->find();
|
||||
if($room_micro_info && $room_micro_info['uid'] <= 0){
|
||||
return ['code' => 201, 'msg' => '当前尚未有人在麦上,无法开启', 'data' => null];
|
||||
}
|
||||
|
||||
//当前是否已有待开始的拍卖
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_auction_log')->where($map)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前尚未有拍卖信息', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_auction_info['status'] == 2){
|
||||
return ['code' => 201, 'msg' => '当前已有进行中的拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($room_auction_info['relation_id']) || empty($room_auction_info['gid']) || empty($room_auction_info['day'])){
|
||||
return ['code' => 201, 'msg' => '拍卖位信息尚未设置完成', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//清除财富值
|
||||
db::name('room_visitor')->where([['rid','=',$rid]])->update(['change_value'=>0,'update_time'=>time()]);
|
||||
|
||||
$paimai_long_time = get_uncache_system_config('paimai_long_time');
|
||||
//开始拍卖
|
||||
$update = [];
|
||||
$update['status'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$update['end_time'] = $paimai_long_time + time();
|
||||
$update['duration'] = $paimai_long_time;
|
||||
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '开启成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//竞拍信息
|
||||
public function get_auction_info($uid, $rid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_auction_info = db::name('room_auction_log')->where('rid', $rid)->where('status', 2)->where('is_delete', 1)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未开启拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
$auction_user_info = db::name('user')->find($room_auction_info['uid']);
|
||||
$auction_gift_info = db::name('gift')->find($room_auction_info['gid']);
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $room_auction_info['uid'];
|
||||
$data['nick_name'] = mb_convert_encoding(base64_decode($auction_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['head_pic'] = localpath_to_netpath($auction_user_info['head_pic']);
|
||||
$data['gid'] = $room_auction_info['gid'];
|
||||
$data['gift_name'] = $auction_gift_info['gift_name'];
|
||||
$data['base_image'] = localpath_to_netpath($auction_gift_info['base_image']);
|
||||
$data['gift_price'] = $auction_gift_info['gift_price'];
|
||||
$data['integral'] = $user_info['integral'];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//记录用户竞拍信息
|
||||
public function record_user_auction_info($uid, $user_id, $rid, $gid, $gift_price, $num, $room_owner_uid){
|
||||
//当前房间进行中的拍卖信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
// $map[] = ['gid', '=', $gid];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_auction_log')->where($map)->order('id desc')->find();
|
||||
if($room_auction_info){
|
||||
if($uid == $room_owner_uid){
|
||||
return ['code' => 201, 'msg' => '主持无法参与竞拍', 'data' => null];
|
||||
}
|
||||
|
||||
if(!empty($room_auction_info['gid'])){
|
||||
$gift_info1 = db::name('gift')->where(['gid'=>$room_auction_info['gid'],'is_delete'=>1])->field('gift_price')->find();
|
||||
if(empty($gift_info1)){
|
||||
return ['code' => 201, 'msg' => '竞拍礼物不存在!', 'data' => null];
|
||||
}
|
||||
|
||||
//任何礼物都可以竞拍
|
||||
$gift_info1_price = $gift_info1['gift_price'];
|
||||
|
||||
|
||||
// if($gift_price < $gift_info1_price){
|
||||
// return ['code' => 201, 'msg' => "礼物竞拍单价小于{$gift_info1_price}金币!", 'data' => null];
|
||||
// }
|
||||
}
|
||||
|
||||
//是否有该场次的赠送信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['raid', '=', $room_auction_info['id']];
|
||||
$map[] = ['auction_uid', '=', $uid];
|
||||
$map[] = ['uid', '=', $room_auction_info['uid']];
|
||||
// $map[] = ['gid', '=', $gid];
|
||||
$user_auction_info = db::name('user_room_auction_log')->where($map)->find();
|
||||
if(!$user_auction_info){
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['raid'] = $room_auction_info['id'];
|
||||
$insert['auction_uid'] = $uid;
|
||||
$insert['uid'] = $room_auction_info['uid'];
|
||||
// $insert['gid'] = $gid;
|
||||
$insert['num'] = $num;
|
||||
$insert['total_price'] = $gift_price * $num;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_room_auction_log')->insertGetId($insert);
|
||||
$pid = $reslut;
|
||||
}else{
|
||||
$total_price = $gift_price * $num;
|
||||
$reslut = db::name('user_room_auction_log')->where('id', $user_auction_info['id'])->inc('num', $num)->inc('total_price', $total_price)->update(['update_time' => time()]);
|
||||
$pid = $user_auction_info['id'];
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//总计
|
||||
// $room_auction_tj_info = db::name('user_room_auction_tj')->where(['pid'=>$pid,'auction_uid'=>$uid,'uid'=>$room_auction_info['uid']])->find();
|
||||
// if(empty($room_auction_tj_info)){
|
||||
// db::name('user_room_auction_tj')->insert([
|
||||
// 'pid' => $pid,
|
||||
// 'auction_uid' =>$uid,
|
||||
// 'uid' => $room_auction_info['uid'],
|
||||
// 'gift_total_price' => $gift_price * $num,
|
||||
// 'add_time' => time(),
|
||||
// 'update_time' => time()
|
||||
// ]);
|
||||
// }else{
|
||||
// $gift_total_price = $gift_price * $num;
|
||||
// db::name('user_room_auction_tj')->where(['id'=>$room_auction_tj_info['id']])->inc('gift_total_price',$gift_total_price)->update(['update_time' => time()]);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//明细
|
||||
db::name('user_room_auction_detail_log')->insert([
|
||||
'pid' => $pid,
|
||||
'auction_uid' =>$uid,
|
||||
'uid' => $room_auction_info['uid'],
|
||||
'gid' => $gid,
|
||||
'num' => $num,
|
||||
'gift_total_price' => $gift_price * $num,
|
||||
'add_time' => time()
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
//更新竞拍麦位信息
|
||||
$this->update_auction_micro($rid, $room_auction_info['id'],$gift_info1_price);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => null];
|
||||
|
||||
}
|
||||
|
||||
//更新竞拍麦位信息[排行榜 2 3 4 5 6 7 拍卖位]
|
||||
public function update_auction_micro($rid, $raid,$gift_info1_price){
|
||||
if(empty($gift_info1_price)){
|
||||
$gift_info1_price = 0;
|
||||
}
|
||||
//当前房间竞拍麦信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [2,3,4,5,6,7]];
|
||||
$room_micro_arr = db::name('room_micro')->where($map)->order('micro_id asc')->column('uid');
|
||||
|
||||
//当前竞拍前三
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['raid', '=', $raid];
|
||||
$map[] = ['total_price','>=', $gift_info1_price];
|
||||
$list = db::name('user_room_auction_log')->where($map)->find();
|
||||
if(!empty($list)){
|
||||
//排名 并且单价 大于 指定礼物价值
|
||||
$user_auction_arr = db::name('user_room_auction_log')->where($map)->order('total_price desc')->limit(6)->column('auction_uid');
|
||||
if($user_auction_arr != $room_micro_arr){
|
||||
foreach ($user_auction_arr as $k => $v){
|
||||
if($v != $room_micro_arr[$k]){
|
||||
//变更麦位信息
|
||||
$micro_id = $k + 2;
|
||||
db::name('room_micro')->where('rid', $rid)->where('micro_id', $micro_id)->update(['uid' => $v, 'update_time' => time()]);
|
||||
//是否有在其他麦位
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [8,9,10,11,12]];
|
||||
$map[] = ['uid', '=', $v];
|
||||
$info = db::name('room_micro')->where($map)->find();
|
||||
if($info){
|
||||
db::name('room_micro')->where('id', $info['id'])->update(['uid' => 0, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//结束拍卖
|
||||
public function finish_auction($uid, $rid){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限结束
|
||||
if($room_info['room_host_uid'] != $uid){
|
||||
return ['code' => 201, 'msg' => '当前麦上主持才可结束', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_auction_info = db::name('room_auction_log')->where('rid', $rid)->where('status', 2)->where('is_delete', 1)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未开启拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
//获取最低拍卖价格
|
||||
$gift_info1 = db::name('gift')->where(['gid'=>$room_auction_info['gid'],'is_delete'=>1])->field('gift_price')->find();
|
||||
if(empty($gift_info1)){
|
||||
return ['code' => 201, 'msg' => '竞拍礼物不存在!', 'data' => null];
|
||||
}
|
||||
$gift_info1_price = $gift_info1['gift_price'];
|
||||
|
||||
|
||||
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$now_time = time();
|
||||
|
||||
//是否有最高出价
|
||||
$room_auction_price_info = db::name('user_room_auction_log')->where([['raid','=',$room_auction_info['id']],['total_price','>=',$gift_info1_price]])->order('total_price desc')->limit(1)->find();
|
||||
|
||||
if(empty($room_auction_price_info)){//流拍
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update(['status' => 3, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 2;
|
||||
}else{
|
||||
//绑定关系
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['auction_uid']];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['uid']];
|
||||
$map[] = ['relation_id', '=', $room_auction_info['relation_id']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation = db::name('user_relation_binding')->where($map)->find();
|
||||
if($user_relation){//延长时间
|
||||
$update = [];
|
||||
// $update['day'] = $relation_info['day'];
|
||||
$update['end_time'] = $user_relation['end_time'] + ($room_auction_info['day'] * 60 * 60 * 24);
|
||||
$update['update_time'] = $now_time;
|
||||
$reslut = db::name('user_relation_binding')->where('id', $user_relation['id'])->inc('day', $room_auction_info['day'])->update($update);
|
||||
|
||||
}else{//添加
|
||||
$insert = [];
|
||||
$insert['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$insert['receive_uid'] = $room_auction_price_info['uid'];
|
||||
$insert['relation_id'] = $room_auction_info['relation_id'];
|
||||
$insert['day'] = $room_auction_info['day'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['end_time'] = $now_time + ($room_auction_info['day'] * 60 * 60 *24);
|
||||
$reslut = db::name('user_relation_binding')->insert($insert);
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//记录
|
||||
$insert = [];
|
||||
$insert['type'] = 2;
|
||||
$insert['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$insert['receive_uid'] = $room_auction_price_info['uid'];
|
||||
$insert['relation_id'] = $room_auction_info['relation_id'];
|
||||
$insert['day'] = $room_auction_info['day'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$reslut = db::name('user_relation_binding_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//摩天轮数据增加
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['auction_uid']];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['uid']];
|
||||
$map[] = ['r_date', '=', date('Y-m-d')];
|
||||
$dating_mt_wheel = db::name('dating_mt_wheel')->where($map)->find();
|
||||
if(!empty($dating_mt_wheel)){
|
||||
db::name('dating_mt_wheel')->where(['id'=>$dating_mt_wheel['id']])->inc('rank_value', $room_auction_price_info['total_price'])->update(['update_time'=>time()]);
|
||||
}else{
|
||||
//建立关系以后数据存储
|
||||
db::name('dating_mt_wheel')->insert([
|
||||
'uid' => $room_auction_price_info['auction_uid'],
|
||||
'receive_uid' => $room_auction_price_info['uid'],
|
||||
'rank_value' => $room_auction_price_info['total_price'],
|
||||
'r_date' => date('Y-m-d'),
|
||||
'add_time' => time(),
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update(['auction_uid' => $room_auction_price_info['auction_uid'], 'auction_num' => $room_auction_price_info['num'], 'status' => 3, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//结束当前拍卖价位
|
||||
$reslut = db::name('user_room_auction_log')->where('raid', $room_auction_info['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 1;
|
||||
}
|
||||
|
||||
//拍卖用户下麦
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [1,2,3,4,5,6,7]];
|
||||
$map[] = ['uid', '>', 0];
|
||||
$reslut = db::name('room_micro')->where($map)->update(['uid' => 0, 'update_time' => time(), 'frame_gid' => 0, 'centre_gid' => 0, 'above_gid' => 0, 'below_gid' => 0, 'left_gid' => 0, 'right_gid' => 0]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//更新老板麦位 下麦
|
||||
// model('RoomBossMicro')->update_room_boss_micro($rid);
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
if($is_push == 1){
|
||||
$auction_user_info = db::name('user')->find($room_auction_price_info['auction_uid']);
|
||||
$sign_user_info = db::name('user')->find($room_auction_price_info['uid']);
|
||||
|
||||
$push_message = [];
|
||||
$push_message['auction_user_info']['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$push_message['auction_user_info']['nick_name'] = mb_convert_encoding(base64_decode($auction_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['auction_user_info']['head_pic'] = localpath_to_netpath($auction_user_info['head_pic']);
|
||||
$push_message['sign_user_info']['uid'] = $room_auction_price_info['uid'];
|
||||
$push_message['sign_user_info']['nick_name'] = mb_convert_encoding(base64_decode($sign_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['sign_user_info']['head_pic'] = localpath_to_netpath($sign_user_info['head_pic']);
|
||||
$push_message['relation_name'] = db::name('relation')->where('id', $room_auction_info['relation_id'])->value('name');
|
||||
|
||||
//提示签约成功
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3005;
|
||||
$push_data['msg'] = "绑定关系成功";
|
||||
$push_data['data'] = $push_message;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '结束成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//自动倒计时拍卖
|
||||
public function close_auction_pm(){
|
||||
$config = get_uncache_system_config();
|
||||
$now_time = time();
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_auction_info = db::name('room_auction_log')->where([['status','=',2],['is_delete','=',1],['end_time','<',$now_time]])->order('id asc')->find();
|
||||
if(empty($room_auction_info)){
|
||||
return ['code' => 201, 'msg' => '暂没有要结束的拍卖活动!', 'data' => null];
|
||||
}
|
||||
$rid = $room_auction_info['rid'];
|
||||
|
||||
|
||||
//获取最低拍卖价格
|
||||
$gift_info1 = db::name('gift')->where(['gid'=>$room_auction_info['gid'],'is_delete'=>1])->field('gift_price')->find();
|
||||
if(empty($gift_info1)){
|
||||
Log::write(['msg'=>'竞拍礼物不存在','data_msg'=>$gift_info1],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => "竞拍礼物不存在,房间rid:{$rid}!", 'data' => null];
|
||||
}
|
||||
$gift_info1_price = $gift_info1['gift_price'];
|
||||
try {
|
||||
Db::startTrans();
|
||||
//是否有最高出价
|
||||
$room_auction_price_info = db::name('user_room_auction_log')->where([['raid','=',$room_auction_info['id']],['total_price','>=',$gift_info1_price]])->order('total_price desc')->limit(1)->find();
|
||||
if(empty($room_auction_price_info)){//流拍
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update(['status' => 3, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'结束失败1','data_msg'=>$reslut],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
$is_push = 2;
|
||||
}else{
|
||||
//绑定关系
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['auction_uid']];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['uid']];
|
||||
$map[] = ['relation_id', '=', $room_auction_info['relation_id']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation = db::name('user_relation_binding')->where($map)->find();
|
||||
if($user_relation){//延长时间
|
||||
$update = [];
|
||||
// $update['day'] = $relation_info['day'];
|
||||
$update['end_time'] = $user_relation['end_time'] + ($room_auction_info['day'] * 60 * 60 * 24);
|
||||
$update['update_time'] = $now_time;
|
||||
$reslut = db::name('user_relation_binding')->where('id', $user_relation['id'])->inc('day', $room_auction_info['day'])->update($update);
|
||||
|
||||
}else{//添加
|
||||
$insert = [];
|
||||
$insert['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$insert['receive_uid'] = $room_auction_price_info['uid'];
|
||||
$insert['relation_id'] = $room_auction_info['relation_id'];
|
||||
$insert['day'] = $room_auction_info['day'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['end_time'] = $now_time + ($room_auction_info['day'] * 60 * 60 *24);
|
||||
$reslut = db::name('user_relation_binding')->insert($insert);
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'结束失败2','data_msg'=>$user_relation],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//记录
|
||||
$insert = [];
|
||||
$insert['type'] = 2;
|
||||
$insert['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$insert['receive_uid'] = $room_auction_price_info['uid'];
|
||||
$insert['relation_id'] = $room_auction_info['relation_id'];
|
||||
$insert['day'] = $room_auction_info['day'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$reslut = db::name('user_relation_binding_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'结束失败3','data_msg'=>$reslut],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//摩天轮数据增加
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['auction_uid']];
|
||||
$map[] = ['uid|receive_uid', '=', $room_auction_price_info['uid']];
|
||||
$map[] = ['r_date', '=', date('Y-m-d')];
|
||||
$dating_mt_wheel = db::name('dating_mt_wheel')->where($map)->find();
|
||||
if(!empty($dating_mt_wheel)){
|
||||
db::name('dating_mt_wheel')->where(['id'=>$dating_mt_wheel['id']])->inc('rank_value', $room_auction_price_info['total_price'])->update(['update_time'=>time()]);
|
||||
}else{
|
||||
//建立关系以后数据存储
|
||||
db::name('dating_mt_wheel')->insert([
|
||||
'uid' => $room_auction_price_info['auction_uid'],
|
||||
'receive_uid' => $room_auction_price_info['uid'],
|
||||
'rank_value' => $room_auction_price_info['total_price'],
|
||||
'r_date' => date('Y-m-d'),
|
||||
'add_time' => time(),
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_auction_info['id'])->update(['auction_uid' => $room_auction_price_info['auction_uid'], 'auction_num' => $room_auction_price_info['num'], 'status' => 3, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'结束失败4','data_msg'=>$reslut,'room_auction_price_info'=>$room_auction_price_info],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//结束当前拍卖价位
|
||||
$reslut = db::name('user_room_auction_log')->where('raid', $room_auction_info['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'结束失败5','reslut'=>$reslut],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 1;
|
||||
}
|
||||
|
||||
//拍卖用户下麦 结束拍卖下麦
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [1,2,3,4,5,6,7]];
|
||||
$map[] = ['uid', '>', 0];
|
||||
$reslut = db::name('room_micro')->where($map)->update(['uid' => 0, 'update_time' => time(), 'frame_gid' => 0, 'centre_gid' => 0, 'above_gid' => 0, 'below_gid' => 0, 'left_gid' => 0, 'right_gid' => 0]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'结束失败6','reslut'=>$reslut],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
if($is_push == 1){
|
||||
$auction_user_info = db::name('user')->find($room_auction_price_info['auction_uid']);
|
||||
$sign_user_info = db::name('user')->find($room_auction_price_info['uid']);
|
||||
|
||||
$push_message = [];
|
||||
$push_message['auction_user_info']['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$push_message['auction_user_info']['nick_name'] = mb_convert_encoding(base64_decode($auction_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['auction_user_info']['head_pic'] = localpath_to_netpath($auction_user_info['head_pic']);
|
||||
$push_message['sign_user_info']['uid'] = $room_auction_price_info['uid'];
|
||||
$push_message['sign_user_info']['nick_name'] = mb_convert_encoding(base64_decode($sign_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['sign_user_info']['head_pic'] = localpath_to_netpath($sign_user_info['head_pic']);
|
||||
$push_message['relation_name'] = db::name('relation')->where('id', $room_auction_info['relation_id'])->value('name');
|
||||
|
||||
//提示签约成功
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3005;
|
||||
$push_data['msg'] = "绑定关系成功";
|
||||
$push_data['data'] = $push_message;
|
||||
$a = model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
Log::write(['msg'=>'绑定关系成功','reslut'=>$a],'close_auction_pm');
|
||||
}
|
||||
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '结束成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'异常报错','reslut'=>$e],'close_auction_pm');
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//增加拍卖时长
|
||||
public function add_pm_line_duration($uid, $rid, $duration=1){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$duration_time = 60;
|
||||
|
||||
|
||||
$room_admin_uid_arr = db::name('room_admin')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
if ($uid != $room_info['room_owner_uid'] && $uid != $room_info['room_host_uid']) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_dating_log = db::name('room_auction_log')->where('rid', $rid)->where('status', 2)->where('is_delete', 1)->order('id desc')->find();
|
||||
if(empty($room_dating_log)){
|
||||
return ['code' => 201, 'msg' => '当前房间没有正在进行的拍卖!', 'data' => null];
|
||||
}
|
||||
if($room_dating_log['end_time'] < time()){
|
||||
return ['code' => 201, 'msg' => '当前房间没有正在进行的拍卖1', 'data' => null];
|
||||
}
|
||||
|
||||
$max_paimai_long_time = $config['max_paimai_long_time'];
|
||||
if($room_dating_log['duration'] + $duration_time > ($max_paimai_long_time * 60)){
|
||||
return ['code' => 201, 'msg' => "单场拍卖活动最长{$max_paimai_long_time}分钟!", 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$update = [];
|
||||
$update['duration'] = $room_dating_log['duration'] + $duration_time;
|
||||
$update['end_time'] = $room_dating_log['end_time'] + $duration_time;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_auction_log')->where('id', $room_dating_log['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
//添加记录
|
||||
$insert = [];
|
||||
$insert['user_id'] = $uid;
|
||||
$insert['pid'] = $room_dating_log['id'];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['duration'] = $duration;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('room_auction_duration_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//当前排行榜
|
||||
public function auction_room_rank($rid,$page,$limit=20){
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_auction_info = db::name('room_auction_log')->where('rid', $rid)->where('status', 2)->where('is_delete', 1)->order('id desc')->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未开启拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
//获取最低拍卖价格
|
||||
$gift_info1 = db::name('gift')->where(['gid'=>$room_auction_info['gid'],'is_delete'=>1])->field('gift_price')->find();
|
||||
if(empty($gift_info1)){
|
||||
return ['code' => 201, 'msg' => '竞拍礼物不存在!', 'data' => null];
|
||||
}
|
||||
$gift_info1_price = $gift_info1['gift_price'];
|
||||
|
||||
//是否有最高出价
|
||||
$room_auction_price_info = db::name('user_room_auction_log')
|
||||
->alias('ul')
|
||||
->join('user u',"u.uid = ul.auction_uid")
|
||||
->where([['ul.raid','=',$room_auction_info['id']],['ul.total_price','>=',$gift_info1_price]])
|
||||
->field('ul.auction_uid,ul.total_price,u.base64_nick_name as nick_name,u.head_pic')
|
||||
->order(['total_price'=>'desc'])
|
||||
->page($page,$limit)
|
||||
->select();
|
||||
|
||||
if(!empty($room_auction_price_info)){
|
||||
foreach ($room_auction_price_info as &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['charm_level_image'] = '';
|
||||
$v['contribution_level_image'] = '';
|
||||
$reslut = model('api/User')->get_user_charm_contribution_info($v['auction_uid']);
|
||||
// if(!empty($reslut['data']['user_charm_contribution_info'])){
|
||||
$v['charm_level_image'] = $reslut['data']['charm_level_image'];
|
||||
$v['contribution_level_image'] = $reslut['data']['contribution_level_image'];
|
||||
// }
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => $room_auction_price_info];
|
||||
}
|
||||
|
||||
}
|
||||
29
application/api/model/Banner.php
Normal file
29
application/api/model/Banner.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Banner extends Model
|
||||
{
|
||||
//轮播图列表
|
||||
public function get_banner_list()
|
||||
{
|
||||
$web_site_url = get_uncache_system_config('web_site');
|
||||
$map = [];
|
||||
$map[] = ['show_status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = db::name('banner')->field('bid,aid,type,image')->where($map)->order('sort desc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['image'] = localpath_to_netpath($v['image']);
|
||||
$v['url'] ="";
|
||||
if ($v['type'] == 2) {
|
||||
// if ($v['type'] == 1) {
|
||||
// $v['url'] = url('index/index/page_show', ['id' => $v['aid']], 'html', true);;
|
||||
$v['url'] =$web_site_url."/index.php/index/index/page_show?id={$v['aid']}";
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
}
|
||||
530
application/api/model/BlindBox.php
Normal file
530
application/api/model/BlindBox.php
Normal file
@@ -0,0 +1,530 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
|
||||
class BlindBox
|
||||
{
|
||||
//进行中的活动
|
||||
public static function get_blind_box_term()
|
||||
{
|
||||
|
||||
try {
|
||||
// 是否开启
|
||||
$map = [
|
||||
['status', '=', 2],
|
||||
['real_end_time', '>', time()]
|
||||
];
|
||||
$blind_box_term = Db::name('blind_box_term')
|
||||
->alias('b')
|
||||
->join('blind_box_term_params p', 'b.id = p.term_id AND b.stage = p.stage')
|
||||
->where($map)
|
||||
->field('b.*, p.gid, p.multi as now_multi, p.time_long, p.num as min_num,p.reward_gid,p.reward_gid_r')
|
||||
->order('b.real_end_time desc')
|
||||
->find();
|
||||
|
||||
if (empty($blind_box_term)) {
|
||||
return ['code' => 201, 'msg' => '未开启', 'data' => null];
|
||||
}
|
||||
// 验证和过滤数据
|
||||
$blind_box_term = array_filter($blind_box_term, function($value) {
|
||||
return is_scalar($value);
|
||||
});
|
||||
|
||||
$blind_box_term['term_id'] = $blind_box_term['id'];
|
||||
unset($blind_box_term['id']);
|
||||
|
||||
return ['code' => 200, 'msg' => '开启中', 'data' => $blind_box_term];
|
||||
} catch (\Exception $e) {
|
||||
// 记录日志
|
||||
dump($e);
|
||||
return ['code' => 201, 'msg' => '服务器内部错误', 'data' => null];
|
||||
}
|
||||
}
|
||||
//进度条
|
||||
public function stage_process_bar($stage, $total_num, $min_num, $max_num)
|
||||
{
|
||||
if ($stage == 5) {
|
||||
$max_config_num = Db::name('config')->where('key_title', 'blind_box_max_amount')
|
||||
->value('key_value');
|
||||
$max_nums = $max_config_num;
|
||||
if ($total_num > $max_nums) {
|
||||
$now_num = $max_nums - $min_num;
|
||||
} else {
|
||||
$now_num = $total_num - $min_num;
|
||||
}
|
||||
} else {
|
||||
$now_num = $total_num - $min_num;
|
||||
$max_nums = $max_num - $min_num;
|
||||
}
|
||||
return [
|
||||
'min_num' => $now_num,
|
||||
'max_num' => $max_nums
|
||||
];
|
||||
}
|
||||
//判断是都进入下一阶段
|
||||
public function check_next_stage($term_id, $stage, $total_num)
|
||||
{
|
||||
// dump($total_num);
|
||||
// 新的阶段
|
||||
$new_stage_info = [];
|
||||
if ($stage < 5) {
|
||||
$map = [];
|
||||
$map[] = ['a.term_id', '=', $term_id];
|
||||
$map[] = ['a.stage', '>', $stage];
|
||||
$map[] = ['a.num', '<', $total_num];
|
||||
|
||||
$stage_info = db::name('blind_box_term_params')->alias('a')
|
||||
->leftJoin('gift b', 'a.reward_gid = b.gid')
|
||||
->field('a.*,b.base_image,b.gift_name')
|
||||
->where($map)->order('stage asc')
|
||||
->limit(1)->find();
|
||||
if (!empty($stage_info)) {
|
||||
$now_gift_image = localpath_to_netpath($stage_info['base_image']);
|
||||
if ($stage_info['stage'] == 5) {
|
||||
$data = [
|
||||
'now_gift_image' => $now_gift_image,
|
||||
'now_multi' => $stage_info['multi'],
|
||||
'now_num' => $stage_info['num'],
|
||||
'now_gift_name' => $stage_info['gift_name'],
|
||||
'next_gift_image' => '',
|
||||
'next_multi' => 0,
|
||||
'next_num' => 0,
|
||||
];
|
||||
} else {
|
||||
$map = [];
|
||||
$map[] = ['a.term_id', '=', $term_id];
|
||||
$map[] = ['a.stage', '=', $stage_info['stage'] + 1];
|
||||
$next_info = db::name('blind_box_term_params')->alias('a')
|
||||
->leftJoin('gift b', 'a.reward_gid = b.gid')
|
||||
->field('a.*,b.base_image,b.gift_name')
|
||||
->where($map)->order('stage asc')->find();
|
||||
$data = [
|
||||
'now_gift_image' => localpath_to_netpath($stage_info['base_image']),
|
||||
'now_multi' => $stage_info['multi'],
|
||||
'now_num' => $stage_info['num'],
|
||||
'next_gift_image' => localpath_to_netpath($next_info['base_image']),
|
||||
'next_multi' => $next_info['multi'],
|
||||
'next_num' => $next_info['num'],
|
||||
'now_gift_name' => $stage_info['gift_name']
|
||||
];
|
||||
}
|
||||
$data['pattern_id'] = $stage_info['pattern_id'];
|
||||
$data['gid'] = $stage_info['gid'];
|
||||
$data['time_long'] = $stage_info['time_long'];
|
||||
$data['stage'] = $stage_info['stage'];
|
||||
$data['reward_gid'] = $stage_info['reward_gid'];
|
||||
$data['reward_gid_r'] = $stage_info['reward_gid_r'];
|
||||
$data['lock_gift_name'] = Db::name('gift')->where('gid', $stage_info['gid'])->value('gift_name');
|
||||
$new_stage_info = $data;
|
||||
}
|
||||
}
|
||||
// dump($new_stage_info);
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $new_stage_info];
|
||||
}
|
||||
|
||||
|
||||
//获取锁定礼物
|
||||
public function get_lock_gift($term_id, $stage)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['term_id', '=', $term_id];
|
||||
$map[] = ['stage', '=', $stage];
|
||||
$lock_gid = db::name('blind_box_term_params')->where($map)->order('id desc')->find();
|
||||
return $lock_gid;
|
||||
}
|
||||
//活动初始化
|
||||
public function blind_box_init($uid, $to_uid, $gid)
|
||||
{
|
||||
$blind_box_term = self::get_blind_box_term();
|
||||
if ($blind_box_term['code'] == 201) {
|
||||
return ['code' => 200, 'msg' => '未开启', 'data' => ['is_open' => 2]];
|
||||
}
|
||||
|
||||
$to_user_info = Db::name('user')->where('uid', $to_uid)->field('uid,base64_nick_name,head_pic')->find();
|
||||
if (empty($to_user_info)) {
|
||||
return ['code' => 201, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
$gift_info = Db::name('gift')->where('gid', $gid)->find();
|
||||
if (empty($gift_info)) {
|
||||
return ['code' => 201, 'msg' => '盲盒不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$term_info = $blind_box_term['data'];
|
||||
$stage = $term_info['stage'];
|
||||
$pattern_id = $term_info['pattern_id'];
|
||||
$term_id = $term_info['term_id'];
|
||||
$map = [];
|
||||
if ($stage == 5) {
|
||||
$map[] = ['term_id', '=', $term_id];
|
||||
$map[] = ['stage', '=', $stage];
|
||||
$params = Db::name('blind_box_term_params')->where($map)->order('stage asc')->find();
|
||||
if (empty($params)) {
|
||||
return ['code' => 201, 'msg' => '未开启', 'data' => null];
|
||||
}
|
||||
|
||||
//奖励礼物信息
|
||||
$reward_gift_info = Db::name('gift')->where('gid', $params['reward_gid'])->find();
|
||||
$reward_base_image = '';
|
||||
if ($reward_gift_info) {
|
||||
$reward_base_image = $reward_gift_info['base_image'];
|
||||
}
|
||||
$max_config_num = Db::name('config')->where('key_title', 'blind_box_max_amount')->value('key_value');
|
||||
$data = [
|
||||
'now_gift_image' => localpath_to_netpath($reward_base_image),
|
||||
'now_multi' => $params['multi'],
|
||||
'next_gift_image' => '',
|
||||
'next_multi' => 0,
|
||||
'now_gift_name' => $reward_gift_info['gift_name'],
|
||||
];
|
||||
$min_num = $params['num'];
|
||||
$max_num = $max_config_num;
|
||||
$now_lock_gid = $params['gid'];
|
||||
} else {
|
||||
$map[] = ['a.term_id', '=', $term_id];
|
||||
$map[] = ['a.stage', '>=', $stage];
|
||||
|
||||
$list = Db::name('blind_box_term_params')->alias('a')
|
||||
->leftJoin('gift b', 'a.reward_gid = b.gid')
|
||||
->field('a.*,b.base_image,b.gift_name')
|
||||
->where($map)
|
||||
->order('a.stage', 'asc')
|
||||
->limit(2)->select();
|
||||
// dump($list);
|
||||
$data = [
|
||||
'now_gift_image' => localpath_to_netpath($list[0]['base_image']),
|
||||
'now_multi' => $list[0]['multi'],
|
||||
'next_gift_image' => localpath_to_netpath($list[1]['base_image']),
|
||||
'next_multi' => $list[1]['multi'],
|
||||
'now_gift_name' => $list[0]['gift_name'],
|
||||
];
|
||||
$min_nums = $list[0]['num'];
|
||||
$max_num = $list[1]['num'];
|
||||
$max_num = $max_num - $min_nums;
|
||||
$min_num = $term_info['gift_num'] - $min_nums;
|
||||
$now_lock_gid = $list[0]['gid'];
|
||||
}
|
||||
//锁定礼物图片
|
||||
$data['is_open'] = 1;
|
||||
$data['term_id'] = $term_id;
|
||||
$data['stage'] = $stage;
|
||||
$data['pattern_id'] = $pattern_id;
|
||||
$data['min_num'] = $min_num;
|
||||
$data['max_num'] = $max_num;
|
||||
$data['end_time'] = $term_info['real_end_time'] - time();
|
||||
$data['head_pic'] = localpath_to_netpath($to_user_info['head_pic']);
|
||||
$data['blind_info'] = [
|
||||
'base_image' => localpath_to_netpath($gift_info['base_image']),
|
||||
'gift_name' => $gift_info['gift_name'],
|
||||
'gift_price' => $gift_info['gift_price'],
|
||||
];
|
||||
//限定礼物id
|
||||
$lock_gift_info = Db::name('gift')->where('gid', $now_lock_gid)->find();
|
||||
$lock_base_image = '';
|
||||
$lock_gift_name = '';
|
||||
if ($lock_gift_info) {
|
||||
$lock_base_image = $lock_gift_info['base_image'];
|
||||
$lock_gift_name = $lock_gift_info['gift_name'];
|
||||
}
|
||||
$lock_user_info = [
|
||||
'send_head_pic' => '',
|
||||
'send_uid' => 0,
|
||||
'send_nick_name' => '',
|
||||
'receive_head_pic' => '',
|
||||
'receive_uid' => 0,
|
||||
'receive_nick_name' => '',
|
||||
'base_image' => localpath_to_netpath($lock_base_image),
|
||||
'receive_base_image' => '',
|
||||
'multi' => $data['now_multi']
|
||||
];
|
||||
|
||||
$data['lock_gift_name'] = $lock_gift_name;
|
||||
$map = [];
|
||||
$map[] = ['term_id', '=', $term_id];
|
||||
// $map[] = ['stage', '=', $stage];
|
||||
// $map[] = ['gid', '=', $now_lock_gid];
|
||||
$user_send_box_info = Db::name('user_blind_box_win')->where($map)->order('id','desc')->find();
|
||||
if ($user_send_box_info) {
|
||||
$send_uid = $user_send_box_info['uid'];
|
||||
$receive_uid = $user_send_box_info['receive_uid'];
|
||||
$uid_arr = [$send_uid, $receive_uid];
|
||||
$user_list = Db::name('user')->field('uid,base64_nick_name,head_pic')
|
||||
->where('uid', 'in', $uid_arr)->select();
|
||||
$user_arr = [];
|
||||
foreach ($user_list as $v) {
|
||||
$user_arr[$v['uid']] = [
|
||||
'head_pic' => localpath_to_netpath($v['head_pic']),
|
||||
'nick_name' => mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8'),
|
||||
];
|
||||
}
|
||||
$reward_gid = $user_send_box_info['reward_gid'];
|
||||
$reward_gid_r = $user_send_box_info['reward_gid_r'];
|
||||
$gift_arr = Db::name('gift')->whereIn('gid', [$reward_gid, $reward_gid_r])
|
||||
->column('base_image', 'gid');
|
||||
$lock_user_info = [
|
||||
'send_head_pic' => $user_arr[$send_uid]['head_pic'] ?? '',
|
||||
'send_uid' => $user_send_box_info['uid'],
|
||||
'send_nick_name' => $user_arr[$send_uid]['nick_name'] ?? '',
|
||||
'receive_head_pic' => $user_arr[$receive_uid]['head_pic'] ?? '',
|
||||
'receive_uid' => $user_send_box_info['receive_uid'],
|
||||
'receive_nick_name' => $user_arr[$receive_uid]['nick_name'] ?? '',
|
||||
'base_image' => isset($gift_arr[$reward_gid]) ? localpath_to_netpath($gift_arr[$reward_gid]) : '',
|
||||
'receive_base_image' => isset($gift_arr[$reward_gid_r]) ? localpath_to_netpath($gift_arr[$reward_gid_r]) : '',
|
||||
'multi' => $user_send_box_info['multi']
|
||||
];
|
||||
|
||||
}
|
||||
$data['lock_user_info'] = $lock_user_info;
|
||||
$map = [];
|
||||
$map[] = ['term_id', '=', $term_id];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['receive_uid', '=', $to_uid];
|
||||
$send_gift_list = Db::name('user_blind_box_log')->alias('a')
|
||||
->leftJoin('gift b', 'a.gid = b.gid')
|
||||
->field('b.gift_name,a.gift_num')
|
||||
->where($map)
|
||||
->order('id desc')
|
||||
->limit(100)
|
||||
->select();
|
||||
foreach ($send_gift_list as &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($to_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
$data['send_gift_list'] = $send_gift_list;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
//数据录入
|
||||
public function user_blind_box_log($insert_data)
|
||||
{
|
||||
return Db::name('user_blind_box_log')->insertAll($insert_data);
|
||||
}
|
||||
//锁定礼物写入
|
||||
public function user_blind_box_win($insert_data)
|
||||
{
|
||||
return Db::name('user_blind_box_win')->insertAll($insert_data);
|
||||
}
|
||||
//送礼物日统计
|
||||
public function user_blind_box_count_day($uid, $gid, $gift_num, $gift_price, $total_gift_price)
|
||||
{
|
||||
$day_time = date('Ymd');
|
||||
$day_time = intval($day_time);
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['day_time', '=', $day_time];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$info = Db::name('user_blind_box_count_day')->where($map)->find();
|
||||
if ($info) {
|
||||
Db::name('user_blind_box_count_day')->where('id', $info['id'])
|
||||
->inc('gift_num', $gift_num)
|
||||
->inc('total_gift_price', $total_gift_price)
|
||||
->update(['update_time' => time()]);
|
||||
} else {
|
||||
$data = [
|
||||
'uid' => $uid,
|
||||
'day_time' => $day_time,
|
||||
'gid' => $gid,
|
||||
'gift_num' => $gift_num,
|
||||
'gift_price' => $gift_price,
|
||||
'total_gift_price' => $total_gift_price,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('user_blind_box_count_day')->insert($data);
|
||||
}
|
||||
|
||||
}
|
||||
//送礼物排行榜
|
||||
public function get_blind_box_rank($time_type, $page, $page_limit)
|
||||
{
|
||||
$day_time = date('Ymd');
|
||||
$week_start_day = date('Ymd', strtotime("this week"));
|
||||
$map = [];
|
||||
$start_time = $day_time;
|
||||
if ($time_type == 2) {
|
||||
$start_time = $week_start_day;
|
||||
}
|
||||
$map[] = ['day_time', '>=', $start_time];
|
||||
$list = Db::name('user_blind_box_count_day')->alias('a')
|
||||
->leftJoin('user b', 'a.uid = b.uid')
|
||||
->field('a.uid,sum(a.total_gift_price) as total_gift_price,b.base64_nick_name,b.head_pic')
|
||||
->where($map)
|
||||
->group('uid')
|
||||
->order('total_gift_price desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
|
||||
foreach ($list as &$v) {
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$maps = [];
|
||||
$maps[] = ['a.day_time', '>=', $start_time];
|
||||
$maps[] = ['a.uid', '=', $v['uid']];
|
||||
$gift_list = Db::name('user_blind_box_count_day')->alias('a')
|
||||
->leftJoin('gift b', 'a.gid = b.gid')
|
||||
->where($maps)
|
||||
->field('sum(gift_num) as gift_num,b.base_image')
|
||||
->group('a.gid')
|
||||
->order('a.gift_price desc, gift_num desc')
|
||||
->limit(3)
|
||||
->select();
|
||||
foreach ($gift_list as &$vv) {
|
||||
$vv['base_image'] = localpath_to_netpath($vv['base_image']);
|
||||
}
|
||||
$v['gift_list'] = $gift_list;
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $list];
|
||||
}
|
||||
//开奖记录
|
||||
public function get_blind_box_win_log($page, $page_limit)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['is_win', '=', 1];
|
||||
$list = Db::name('user_blind_box_win')->alias('a')
|
||||
->leftJoin('gift b', 'a.reward_gid = b.gid')
|
||||
->leftJoin('gift c', 'a.reward_gid_r = c.gid')
|
||||
->field('a.uid,a.receive_uid,a.gid,a.gift_num,a.multi,a.gift_price,b.gift_name,b.base_image,
|
||||
c.base_image as receive_base_image,a.add_time,c.gift_name as receive_gift_name')
|
||||
->where($map)
|
||||
->page($page, $page_limit)
|
||||
->order('id desc')
|
||||
->select();
|
||||
$uid_arr = array_column($list, 'uid');
|
||||
$receive_arr = array_column($list, 'receive_uid');
|
||||
$user_arr = Db::name('user')->where('uid', 'in', array_merge($uid_arr, $receive_arr))
|
||||
->column('base64_nick_name,head_pic', 'uid');
|
||||
foreach ($list as &$v) {
|
||||
$v['head_pic'] = localpath_to_netpath($user_arr[$v['uid']]['head_pic']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($user_arr[$v['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['receive_head_pic'] = localpath_to_netpath($user_arr[$v['receive_uid']]['head_pic']);
|
||||
$v['receive_nick_name'] = mb_convert_encoding(base64_decode($user_arr[$v['receive_uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$v['receive_base_image'] = localpath_to_netpath($v['receive_base_image']);
|
||||
$v['gift_num'] = $v['multi'];
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $list];
|
||||
}
|
||||
//玩法介绍
|
||||
public function get_blind_box_note()
|
||||
{
|
||||
$content = Db::name('config')->where('key_title', 'blind_box_note')->value('key_value');
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $content];
|
||||
}
|
||||
|
||||
// //结束一期盲盒活动
|
||||
// public function close_blind_box()
|
||||
// {
|
||||
// $map = [];
|
||||
// $map[] = ['status', '=', 2];
|
||||
// $map[] = ['real_end_time', '<', time()];
|
||||
// $result = Db::name('blind_box_term')->where($map)->update(['status' => 3, 'update_time' => time()]);
|
||||
// if ($result) {
|
||||
// $push_data = [];
|
||||
// $push_data['code'] = 316;
|
||||
// $push_data['msg'] = '活动结束';
|
||||
// $push_data['data'] = [];
|
||||
// model('api/WebSocketPush')->send_to_all($push_data);
|
||||
// }
|
||||
// }
|
||||
// //活动结束奖励
|
||||
// public function blind_box_reward()
|
||||
// {
|
||||
// $map = [];
|
||||
// $map[] = ['status', '=', 3];
|
||||
// $info = Db::name('blind_box_term')->where($map)->find();
|
||||
// if ($info) {
|
||||
// $term_id = $info['id'];
|
||||
// $stage = $info['stage'];
|
||||
// // for ($i = 1; $i <= $stage; $i++) {
|
||||
// // $map = [];
|
||||
// // $map[] = ['term_id', '=', $term_id];
|
||||
// // $map[] = ['stage', '=', $i];
|
||||
// // $map[] = ['is_win', '=', 2];
|
||||
// // $win_info = Db::name('user_blind_box_win')->where($map)->order('id', 'desc')->find();
|
||||
// // if ($win_info) {
|
||||
// // $remarks = '盲盒巡乐会第' . $term_id . '期第' . $i . '阶段';
|
||||
// // model('api/UserGiftPack')->change_user_gift_pack($win_info['uid'], $win_info['gid'], $win_info['gift_num'], 5, $remarks);
|
||||
// // model('api/UserGiftPack')->change_user_gift_pack($win_info['receive_uid'], $win_info['gid'], $win_info['gift_num'], 5, $remarks);
|
||||
// // Db::name('user_blind_box_win')->where('id', $win_info['id'])->update(['is_win' => 1, 'update_time' => time()]);
|
||||
// // }
|
||||
// // }
|
||||
// $map = [];
|
||||
// $map[] = ['term_id', '=', $term_id];
|
||||
// $map[] = ['stage', '=', $stage];
|
||||
// $map[] = ['is_win', '=', 2];
|
||||
// $win_info = Db::name('user_blind_box_win')->where($map)->order('id', 'desc')->find();
|
||||
// if ($win_info) {
|
||||
// $remarks = '盲盒巡乐会第' . $term_id . '期第' . $stage . '阶段';
|
||||
// model('api/UserGiftPack')->change_user_gift_pack($win_info['uid'], $win_info['reward_gid'], $win_info['multi'], 5, $remarks);
|
||||
// model('api/UserGiftPack')->change_user_gift_pack($win_info['receive_uid'], $win_info['reward_gid_r'], $win_info['multi'], 5, $remarks);
|
||||
// Db::name('user_blind_box_win')->where('id', $win_info['id'])->update(['is_win' => 1, 'update_time' => time()]);
|
||||
// }
|
||||
// Db::name('blind_box_term')->where('id', $info['id'])->update(['status' => 4, 'update_time' => time()]);
|
||||
// }
|
||||
// }
|
||||
//结束一期盲盒活动
|
||||
public function close_blind_box()
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['real_end_time', '<', time()];
|
||||
|
||||
$result = Db::name('blind_box_term')->where($map)->update(['status' => 3, 'update_time' => time()]);
|
||||
if ($result) {
|
||||
$content = '';
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 3];
|
||||
$info = Db::name('blind_box_term')->where($map)->order('id', 'desc')->find();
|
||||
if($info) {
|
||||
$term_id = $info['id'];
|
||||
$stage = $info['stage'];
|
||||
$map = [];
|
||||
$map[] = ['term_id', '=', $term_id];
|
||||
// $map[] = ['stage', '=', $stage];
|
||||
$map[] = ['is_win', '=', 2];
|
||||
$win_info = Db::name('user_blind_box_win')->where($map)->order('id', 'desc')->find();
|
||||
|
||||
if($win_info) {
|
||||
$base64_nick_name = Db::name('user')->where('uid', $win_info['uid'])->value('base64_nick_name');
|
||||
$nick_name = mb_convert_encoding(base64_decode($base64_nick_name), 'UTF-8', 'UTF-8');
|
||||
$content = '恭喜' . $nick_name . '获得巡乐会最终大奖!';
|
||||
}
|
||||
}
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 316;
|
||||
$push_data['msg'] = '活动结束';
|
||||
$push_data['data'] = [
|
||||
'content' => $content,
|
||||
];
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
}
|
||||
}
|
||||
//活动结束奖励
|
||||
public function blind_box_reward()
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 3];
|
||||
$info = Db::name('blind_box_term')->where($map)->order('id', 'desc')->find();
|
||||
if ($info) {
|
||||
$term_id = $info['id'];
|
||||
$stage = $info['stage'];
|
||||
|
||||
$map = [];
|
||||
$map[] = ['term_id', '=', $term_id];
|
||||
// $map[] = ['stage', '=', $stage];
|
||||
$map[] = ['is_win', '=', 2];
|
||||
$win_info = Db::name('user_blind_box_win')->where($map)->order('id', 'desc')->find();
|
||||
if ($win_info) {
|
||||
$remarks = '盲盒巡乐会第' . $term_id . '期第' . $stage . '阶段';
|
||||
model('api/UserGiftPack')->change_user_gift_pack($win_info['uid'], $win_info['reward_gid'], $win_info['multi'], 5, $remarks);
|
||||
model('api/UserGiftPack')->change_user_gift_pack($win_info['receive_uid'], $win_info['reward_gid_r'], $win_info['multi'], 5, $remarks);
|
||||
Db::name('user_blind_box_win')->where('id', $win_info['id'])->update(['is_win' => 1, 'update_time' => time()]);
|
||||
}
|
||||
Db::name('blind_box_term')->where('id', $info['id'])->update(['status' => 4, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
2428
application/api/model/Box.php
Normal file
2428
application/api/model/Box.php
Normal file
File diff suppressed because it is too large
Load Diff
2053
application/api/model/Box2.php
Normal file
2053
application/api/model/Box2.php
Normal file
File diff suppressed because it is too large
Load Diff
2682
application/api/model/Box3.php
Normal file
2682
application/api/model/Box3.php
Normal file
File diff suppressed because it is too large
Load Diff
1724
application/api/model/BoxHundred.php
Normal file
1724
application/api/model/BoxHundred.php
Normal file
File diff suppressed because it is too large
Load Diff
1733
application/api/model/BoxTen.php
Normal file
1733
application/api/model/BoxTen.php
Normal file
File diff suppressed because it is too large
Load Diff
17
application/api/model/CanRecharge.php
Normal file
17
application/api/model/CanRecharge.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class CanRecharge extends Model
|
||||
{
|
||||
public function get_can_recharge_list()
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = Db::name('can_recharge')->field('crid,money,integral')->where($map)->select();
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
}
|
||||
185
application/api/model/Contract.php
Normal file
185
application/api/model/Contract.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
|
||||
//签约列表
|
||||
public function get_user_contract_list($uid, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 20 ? $page_limit : 20;
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$list = db::name('user_sign_contract')->alias('a')->join('yy_user b', 'a.sign_uid = b.uid')->field('a.id, b.uid, b.sex, b.nick_name, b.base64_nick_name, b.head_pic, a.end_time')->where($map)->order('a.id desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//制作人续约是否缴费
|
||||
public function user_renewal_contract_status($uid, $id){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//签约信息
|
||||
$user_sign_contract_info = db::name('user_sign_contract')->where('id', $id)->where('is_delete', 1)->find();
|
||||
if(!$user_sign_contract_info){
|
||||
return ['code' => 201, 'msg' => '该签约信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $user_sign_contract_info['uid']){
|
||||
return ['code' => 201, 'msg' => '您不是该签约信息的制作人', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_sign_contract_info['renew_num'] >= 3){//续约缴费
|
||||
$sign_user_info = db::name('user')->find($user_sign_contract_info['sign_uid']);
|
||||
$money = (int)($sign_user_info['social'] * 0.1);
|
||||
|
||||
}else{//续约免费
|
||||
$money = 0;
|
||||
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['money'] = $money;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//制作人续约
|
||||
public function user_renewal_contract($uid, $id){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//签约信息
|
||||
$user_sign_contract_info = db::name('user_sign_contract')->where('id', $id)->where('is_delete', 1)->find();
|
||||
if(!$user_sign_contract_info){
|
||||
return ['code' => 201, 'msg' => '该签约信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $user_sign_contract_info['uid']){
|
||||
return ['code' => 201, 'msg' => '您不是该签约信息的制作人', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$renewal_time = 60*60*24*7;
|
||||
|
||||
if($user_sign_contract_info['renew_num'] >= 3){//续约缴费
|
||||
//当前截止日期
|
||||
$end_time = $user_sign_contract_info['end_time'] - (60*60*24*2);
|
||||
if($end_time > time()){
|
||||
return ['code' => 201, 'msg' => '到期前两天才可续约', 'data' => null];
|
||||
}
|
||||
|
||||
$sign_user_info = db::name('user')->find($user_sign_contract_info['sign_uid']);
|
||||
$money = (int)($sign_user_info['social'] * 0.1);
|
||||
|
||||
//扣除制作人金币续约
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$money, 2, 25, "制作人续约", $uid, 0, 0);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//更新签约信息
|
||||
$reslut = db::name('user_sign_contract')->where('id', $id)->inc('end_time', $renewal_time)->update(['renew_num' => 0, 'send_message_num' => 0, 'update_time' => time()]);
|
||||
}else{//续约免费
|
||||
$money = 0;
|
||||
|
||||
//更新签约信息
|
||||
$reslut = db::name('user_sign_contract')->where('id', $id)->inc('end_time', $renewal_time)->inc('renew_num', 1)->update(['send_message_num' => 0, 'update_time' => time()]);
|
||||
}
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '续约失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return ['code' => 200, 'msg' => '续约成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '续约失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//制作人解约
|
||||
public function user_cancel_contract($uid, $id){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//签约信息
|
||||
$user_sign_contract_info = db::name('user_sign_contract')->where('id', $id)->where('is_delete', 1)->find();
|
||||
if(!$user_sign_contract_info){
|
||||
return ['code' => 201, 'msg' => '该签约信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $user_sign_contract_info['uid']){
|
||||
return ['code' => 201, 'msg' => '您不是该签约信息的制作人', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('user_sign_contract')->where('id', $id)->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '解约失败', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 200, 'msg' => '解约成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//收礼物涨身价
|
||||
public function receive_gift_rise_user_social($uid, $total_gift_price){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
//该用户是否已签约
|
||||
$user_sign_contract_info = db::name('user_sign_contract')->where('sign_uid', $uid)->where('is_delete', 1)->find();
|
||||
if($user_sign_contract_info && $user_info['social'] > 0){
|
||||
//添加身价金额
|
||||
$add_social = (int)($total_gift_price * 0.2);
|
||||
if($add_social > 0){
|
||||
$reslut = db::name('user')->where('uid', $uid)->inc('social', $add_social)->update();
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['total_gift_price'] = $total_gift_price;
|
||||
$insert['add_social'] = $add_social;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_social_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
627
application/api/model/Coupling.php
Normal file
627
application/api/model/Coupling.php
Normal file
@@ -0,0 +1,627 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Coupling extends Model
|
||||
{
|
||||
//获取该用户CP信息
|
||||
public function get_coupling_info($uid, $receive_uid, $integral){
|
||||
//是否绑定cp
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_coupling_info = db::name('user_coupling')->where($map)->find();
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($user_coupling_info){
|
||||
//已绑定CP则判断对方是否同一人
|
||||
if($user_coupling_info['uid'] == $uid){
|
||||
if($user_coupling_info['receive_uid'] == $receive_uid){//增加cp值
|
||||
$where = [];
|
||||
$where[] = ['is_delete', '=', 1];
|
||||
$cp_level_list = db::name('cp_privilege')->where($where)->order('level asc')->select();
|
||||
$rest_value = $user_coupling_info['cp_value'] + $integral;
|
||||
$now_level = 0;
|
||||
foreach ($cp_level_list as $k => $v){
|
||||
$rest_value = $rest_value - $v['number'];
|
||||
if($rest_value < 0){
|
||||
break;
|
||||
}
|
||||
$now_level = $v['level'];
|
||||
}
|
||||
$level_difference = $now_level - $user_coupling_info['cp_level'];
|
||||
$now_levels = $now_level+1;
|
||||
$contribution_level = $user_coupling_info['cp_level']+1;
|
||||
|
||||
if($level_difference > 0){
|
||||
for ($i = $contribution_level; $i < $now_levels; $i++){
|
||||
$cp_level_info = db::name('cp_privilege')->where('level', $i)->where('is_delete', 1)->find();
|
||||
if(!empty($cp_level_info['head_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试1', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试2', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['mount_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试3', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['left_wing_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['uid'], $cp_level_info['left_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试3', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['right_wing_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['receive_uid'], $cp_level_info['right_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试3', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $user_coupling_info['id']];
|
||||
$update = [];
|
||||
$update['cp_level'] = $now_level;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_coupling')->where($map)->inc('cp_value', $integral)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}else{//申请绑定cp
|
||||
$send_coupling = $this->apply_coupling($uid, $receive_uid);
|
||||
if($send_coupling['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $send_coupling['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
}else if($user_coupling_info['receive_uid'] == $uid){
|
||||
if($user_coupling_info['uid'] == $receive_uid){//增加cp值
|
||||
$where = [];
|
||||
$where[] = ['is_delete', '=', 1];
|
||||
$cp_level_list = db::name('cp_privilege')->where($where)->order('level asc')->select();
|
||||
$rest_value = $user_coupling_info['cp_value'] + $integral;
|
||||
$now_level = 0;
|
||||
foreach ($cp_level_list as $k => $v){
|
||||
$rest_value = $rest_value - $v['number'];
|
||||
if($rest_value < 0){
|
||||
break;
|
||||
}
|
||||
$now_level = $v['level'];
|
||||
}
|
||||
$level_difference = $now_level - $user_coupling_info['cp_level'];
|
||||
$now_levels = $now_level+1;
|
||||
$contribution_level = $user_coupling_info['cp_level']+1;
|
||||
|
||||
if($level_difference > 0){
|
||||
for ($i = $contribution_level; $i < $now_levels; $i++){
|
||||
$cp_level_info = db::name('cp_privilege')->where('level', $i)->where('is_delete', 1)->find();
|
||||
if(!empty($cp_level_info['head_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试5', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试6', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['mount_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试7', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试8', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['left_wing_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['uid'], $cp_level_info['left_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试3', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['right_wing_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['receive_uid'], $cp_level_info['right_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试3', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $user_coupling_info['id']];
|
||||
$update = [];
|
||||
$update['cp_level'] = $now_level;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_coupling')->where($map)->inc('cp_value', $integral)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}else{//申请绑定cp
|
||||
$send_coupling = $this->apply_coupling($uid, $receive_uid);
|
||||
if($send_coupling['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $send_coupling['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//增加cp榜单记录
|
||||
model('Statistics')->day_cp_value($uid, $receive_uid, $integral);
|
||||
}else{//申请绑定cp
|
||||
$send_coupling = $this->apply_coupling($uid, $receive_uid);
|
||||
if($send_coupling['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $send_coupling['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//申请绑定cp
|
||||
public function apply_coupling($uid, $receive_uid){
|
||||
$now_time = time();
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['receive_uid', '=', $receive_uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_coupling_log_info = db::name('user_coupling_log')->where($map)->find();
|
||||
Db::startTrans();
|
||||
try {
|
||||
if(!$user_coupling_log_info){//未申请则申请
|
||||
//对方是否申请过
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $receive_uid];
|
||||
$map[] = ['receive_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$receive_coupling_log_info = db::name('user_coupling_log')->where($map)->find();
|
||||
if($receive_coupling_log_info){//对方申请则直接绑定
|
||||
//清除之前的绑定cp
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', 'in', [$uid,$receive_uid]];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$update = [];
|
||||
$update['is_delete'] = 2;
|
||||
$update['del_time'] = $now_time;
|
||||
$user_coupling_data = db::name('user_coupling')->where($map)->select();
|
||||
if($user_coupling_data){
|
||||
$reslut = db::name('user_coupling')->where($map)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
//清除之前的榜单记录
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', 'in', [$uid, $receive_uid]];
|
||||
$user_cp_rank = db::name('user_cp_count_day')->where($map)->find();
|
||||
if(!empty($user_cp_rank)){
|
||||
$reslut = db::name('user_cp_count_day')->where($map)->delete();
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($user_coupling_data as $a => $b){
|
||||
$user_cp_decorate = db::name('user_decorate')->where('cp_id', $b['id'])->select();
|
||||
if(!empty($user_cp_decorate)){
|
||||
$reslut = db::name('user_decorate')->where('cp_id', $b['id'])->delete();
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', 'in', [$uid,$receive_uid]];
|
||||
$map[] = ['id', 'neq', $receive_coupling_log_info['id']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$update = [];
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = $now_time;
|
||||
$user_coupling_log_data = db::name('user_coupling_log')->where($map)->select();
|
||||
if($user_coupling_log_data){
|
||||
$reslut = db::name('user_coupling_log')->where($map)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//新增绑定CP
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['receive_uid'] = $receive_uid;
|
||||
$insert['add_time'] = $now_time;
|
||||
$reslut = db::name('user_coupling_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('user_coupling')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}else{//对方为申请则只申请
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['receive_uid'] = $receive_uid;
|
||||
$insert['add_time'] = $now_time;
|
||||
$reslut = db::name('user_coupling_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//指定用户cp详情
|
||||
public function user_coupling_info($uid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_coupling_info = db::name('user_coupling')->field('uid, receive_uid, cp_value, cp_level')->where($map)->find();
|
||||
if($user_coupling_info){
|
||||
if($user_coupling_info['uid'] == $uid){
|
||||
$receive_uid = $user_coupling_info['receive_uid'];
|
||||
}else{
|
||||
$receive_uid = $user_coupling_info['uid'];
|
||||
$user_coupling_info['uid'] = $uid;
|
||||
$user_coupling_info['receive_uid'] = $receive_uid;
|
||||
}
|
||||
$receive_info = db::name('user')->find($receive_uid);
|
||||
$user_coupling_info['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_coupling_info['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$user_coupling_info['is_online'] = $user_info['is_online'];
|
||||
$user_coupling_info['receive_nick_name'] = mb_convert_encoding(base64_decode($receive_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_coupling_info['receive_head_pic'] = localpath_to_netpath($receive_info['head_pic']);
|
||||
$user_coupling_info['receive_is_online'] = $receive_info['is_online'];
|
||||
|
||||
//
|
||||
$rest_value = $user_coupling_info['cp_value'];
|
||||
$next_value = 0;
|
||||
$next_level = $user_coupling_info['cp_value'];
|
||||
$cp_level_list = db::name('cp_privilege')->where('is_delete', 1)->order('level asc')->select();
|
||||
foreach ($cp_level_list as $k => $v){
|
||||
$rest_values = $rest_value;
|
||||
$rest_value = $rest_value - $v['number'];
|
||||
//下一等级初始化
|
||||
$next_value = $v['level'];
|
||||
if ($rest_value < 0) {
|
||||
$rest_values = $rest_values;
|
||||
$next_value = $v['number'];
|
||||
$next_level = $v['level'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$user_coupling_info['now_level'] = $user_coupling_info['cp_level'];
|
||||
$user_coupling_info['now_value'] = $rest_values;
|
||||
$user_coupling_info['next_level'] = $next_level;
|
||||
$user_coupling_info['next_value'] = $next_value;
|
||||
|
||||
//头像框
|
||||
$user_decorate_info = model('user')->get_user_avatar_info($uid);
|
||||
|
||||
//cp装扮
|
||||
$coupling_decorate_info = db::name('cp_privilege')->where('level', $user_coupling_info['cp_level'])->where('is_delete', 1)->find();
|
||||
if(!empty($coupling_decorate_info['left_wing_decorate_id']) && !empty($coupling_decorate_info['right_wing_decorate_id'])){
|
||||
$left_wing_decorate = db::name('Decorate')->where('did', $coupling_decorate_info['left_wing_decorate_id'])->find();
|
||||
$right_wing_decorate = db::name('Decorate')->where('did', $coupling_decorate_info['right_wing_decorate_id'])->find();
|
||||
$user_coupling_info['win_base_image'] = localpath_to_netpath($left_wing_decorate['base_image']);
|
||||
$user_coupling_info['win_play_image'] = localpath_to_netpath($left_wing_decorate['play_image']);;
|
||||
$user_coupling_info['receive_win_base_image'] = localpath_to_netpath($right_wing_decorate['base_image']);;
|
||||
$user_coupling_info['receive_win_play_image'] = localpath_to_netpath($right_wing_decorate['play_image']);;
|
||||
|
||||
}else{
|
||||
$user_coupling_info['win_base_image'] = '';
|
||||
$user_coupling_info['win_play_image'] = '';
|
||||
$user_coupling_info['receive_win_base_image'] = '';
|
||||
$user_coupling_info['receive_win_play_image'] = '';
|
||||
}
|
||||
|
||||
$user_coupling_info['avatar_play_image'] = $user_decorate_info['data']['avatar_play_image'];
|
||||
|
||||
// $user_coupling_info['win_base_image'] = $user_decorate_info['data']['win_base_image'];
|
||||
// $user_coupling_info['win_play_image'] = $user_decorate_info['data']['win_play_image'];
|
||||
$receive_decorate_info = model('user')->get_user_avatar_info($receive_uid);
|
||||
$user_coupling_info['receive_avatar_play_image'] = $receive_decorate_info['data']['avatar_play_image'];
|
||||
// $user_coupling_info['receive_win_base_image'] = $receive_decorate_info['data']['win_base_image'];
|
||||
// $user_coupling_info['receive_win_play_image'] = $receive_decorate_info['data']['win_play_image'];
|
||||
$user_coupling_info['is_have_cp'] = 1;
|
||||
}else{
|
||||
$user_coupling_info['is_have_cp'] = 2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_coupling_info];
|
||||
}
|
||||
|
||||
//增加cp值
|
||||
public function update_user_cp_value($uid, $receive_uid, $integral){
|
||||
//是否绑定cp
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_coupling_info = db::name('user_coupling')->where($map)->find();
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($user_coupling_info){
|
||||
//已绑定CP则判断对方是否同一人
|
||||
if($user_coupling_info['uid'] == $uid){
|
||||
if($user_coupling_info['receive_uid'] == $receive_uid){//增加cp值
|
||||
$where = [];
|
||||
$where[] = ['is_delete', '=', 1];
|
||||
$cp_level_list = db::name('cp_privilege')->where($where)->order('level asc')->select();
|
||||
$rest_value = $user_coupling_info['cp_value'] + $integral;
|
||||
$now_level = 0;
|
||||
foreach ($cp_level_list as $k => $v){
|
||||
$rest_value = $rest_value - $v['number'];
|
||||
if($rest_value < 0){
|
||||
break;
|
||||
}
|
||||
$now_level = $v['level'];
|
||||
}
|
||||
$level_difference = $now_level - $user_coupling_info['cp_level'];
|
||||
$now_levels = $now_level+1;
|
||||
$contribution_level = $user_coupling_info['cp_level']+1;
|
||||
|
||||
if($level_difference > 0){
|
||||
for ($i = $contribution_level; $i < $now_levels; $i++){
|
||||
$cp_level_info = db::name('cp_privilege')->where('level', $i)->where('is_delete', 1)->find();
|
||||
if(!empty($cp_level_info['head_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试9', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试10', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['mount_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试11', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试12', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['left_wing_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['uid'], $cp_level_info['left_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试301', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['right_wing_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['receive_uid'], $cp_level_info['right_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试302', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $user_coupling_info['id']];
|
||||
$update = [];
|
||||
$update['cp_level'] = $now_level;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_coupling')->where($map)->inc('cp_value', $integral)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}else if($user_coupling_info['receive_uid'] == $uid){
|
||||
if($user_coupling_info['uid'] == $receive_uid){//增加cp值
|
||||
$where = [];
|
||||
$where[] = ['is_delete', '=', 1];
|
||||
$cp_level_list = db::name('cp_privilege')->where($where)->order('level asc')->select();
|
||||
$rest_value = $user_coupling_info['cp_value'] + $integral;
|
||||
$now_level = 0;
|
||||
foreach ($cp_level_list as $k => $v){
|
||||
$rest_value = $rest_value - $v['number'];
|
||||
if($rest_value < 0){
|
||||
break;
|
||||
}
|
||||
$now_level = $v['level'];
|
||||
}
|
||||
$level_difference = $now_level - $user_coupling_info['cp_level'];
|
||||
$now_levels = $now_level+1;
|
||||
$contribution_level = $user_coupling_info['cp_level']+1;
|
||||
|
||||
if($level_difference > 0){
|
||||
for ($i = $contribution_level; $i < $now_levels; $i++){
|
||||
$cp_level_info = db::name('cp_privilege')->where('level', $i)->where('is_delete', 1)->find();
|
||||
if(!empty($cp_level_info['head_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试13', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['head_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试14', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['mount_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试15', 'data' => null];
|
||||
}
|
||||
$reslut = model('Decorate')->draw_user_decorate($receive_uid, $cp_level_info['mount_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试16', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['left_wing_decorate_id'])){
|
||||
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['uid'], $cp_level_info['left_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试303', 'data' => null];
|
||||
}
|
||||
}
|
||||
if(!empty($cp_level_info['right_wing_decorate_id'])){
|
||||
$reslut = model('Decorate')->draw_user_decorate($user_coupling_info['receive_uid'], $cp_level_info['right_wing_decorate_id'], 720, 'CP特权赠送', 1, $user_coupling_info['id']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试304', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $user_coupling_info['id']];
|
||||
$update = [];
|
||||
$update['cp_level'] = $now_level;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_coupling')->where($map)->inc('cp_value', $integral)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//增加cp榜单记录
|
||||
model('Statistics')->day_cp_value($uid, $receive_uid, $integral);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//CP榜
|
||||
public function get_cp_rank($uid, $time, $page = 1, $page_limit = 20){
|
||||
if(!in_array($time, [1,2,3])){
|
||||
return ['code' => 201, 'msg' => "参数非法", 'data' => null];
|
||||
}
|
||||
|
||||
if($time == 1){
|
||||
$whereTime = 'today';
|
||||
}else if($time == 2){
|
||||
$whereTime = 'week';
|
||||
}else{
|
||||
$whereTime = 'month';
|
||||
}
|
||||
$list = db::name('user_cp_count_day')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_user c', 'a.receive_uid = c.uid')->field('a.uid,a.receive_uid,sum(a.amount) as total_amount,b.nick_name,b.base64_nick_name,b.head_pic,c.nick_name as receive_nick_name, c.base64_nick_name as receive_base64_nick_name,c.head_pic as receive_head_pic')->whereTime('a.add_time', $whereTime)->group('a.uid,a.receive_uid')->order('total_amount desc')->page($page, $page_limit)->select();
|
||||
|
||||
foreach ($list as $k => &$v){
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $v['uid']];
|
||||
$map[] = ['uid|receive_uid', '=', $v['receive_uid']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_coupling_info = db::name('user_coupling')->where($map)->find();
|
||||
//cp装扮
|
||||
$coupling_decorate_info = db::name('cp_privilege')->where('level', $user_coupling_info['cp_level'])->where('is_delete', 1)->find();
|
||||
if(!empty($coupling_decorate_info['left_wing_decorate_id']) && !empty($coupling_decorate_info['right_wing_decorate_id'])){
|
||||
$left_wing_decorate = db::name('Decorate')->where('did', $coupling_decorate_info['left_wing_decorate_id'])->find();
|
||||
$right_wing_decorate = db::name('Decorate')->where('did', $coupling_decorate_info['right_wing_decorate_id'])->find();
|
||||
$v['win_base_image'] = localpath_to_netpath($left_wing_decorate['base_image']);
|
||||
$v['win_play_image'] = localpath_to_netpath($left_wing_decorate['play_image']);;
|
||||
$v['receive_win_base_image'] = localpath_to_netpath($right_wing_decorate['base_image']);;
|
||||
$v['receive_win_play_image'] = localpath_to_netpath($right_wing_decorate['play_image']);;
|
||||
|
||||
}else{
|
||||
$v['win_base_image'] = '';
|
||||
$v['win_play_image'] = '';
|
||||
$v['receive_win_base_image'] = '';
|
||||
$v['receive_win_play_image'] = '';
|
||||
}
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['receive_nick_name'] = mb_convert_encoding(base64_decode($v['receive_base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['receive_head_pic'] = localpath_to_netpath($v['receive_head_pic']);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['list'] = $list;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
1678
application/api/model/DatingRoom.php
Normal file
1678
application/api/model/DatingRoom.php
Normal file
File diff suppressed because it is too large
Load Diff
365
application/api/model/DatingRoomGift.php
Normal file
365
application/api/model/DatingRoomGift.php
Normal file
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class DatingRoomGift extends Model
|
||||
{
|
||||
//私密续时礼物列表
|
||||
public function get_privacy_room_gift_list($uid){
|
||||
$map = [];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$map[] = ['b.is_delete', '=', 1];
|
||||
$map[] = ['b.is_show', '=', 1];
|
||||
$list = db::name('room_privacy_gift')->alias('a')->join('yy_gift b', 'a.gid = b.gid')->field('a.gid,a.duration,b.gift_name,b.base_image,b.gift_price')->where($map)->order('b.gift_price asc')->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
|
||||
//赠送私密小屋礼物
|
||||
public function send_gift($uid, $receive_uid, $rid, $prid, $gid, $num)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['a.gid', '=', $gid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$map[] = ['a.is_show', '=', 1];
|
||||
$gift_info = db::name('gift')->alias('a')->join('yy_room_privacy_gift b', 'a.gid = b.gid')->field('a.*, b.duration')->where($map)->find();
|
||||
if (empty($gift_info)) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物信息不存在', 'data' => null];
|
||||
}
|
||||
$gift_info['play_image'] = localpath_to_netpath($gift_info['play_image']);
|
||||
$gift_info['base_image'] = localpath_to_netpath($gift_info['base_image']);
|
||||
if (ceil($num) != $num) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物数量必须为整数', 'data' => null];
|
||||
}
|
||||
if ($num < 1) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物数量必须大于零', 'data' => null];
|
||||
}
|
||||
|
||||
//私密小屋信息
|
||||
$privacy_room = db::name('room_privacy')->find($prid);
|
||||
if($privacy_room['is_use'] == 2){
|
||||
return ['code' => 201, 'msg' => '该私密房间已到期', 'data' => null];
|
||||
}
|
||||
|
||||
$user_id_data = explode(',', $privacy_room['uid_data']);
|
||||
$user_id = $user_id_data[0];
|
||||
$received_uid = $user_id_data[1];
|
||||
|
||||
|
||||
if($uid == $user_id){
|
||||
$receive_uid = $received_uid;
|
||||
}else if($uid == $received_uid){
|
||||
$receive_uid = $user_id;
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($rid)){
|
||||
$rid = $privacy_room['rid'];
|
||||
if(empty($rid)){
|
||||
return ['code' => 201, 'msg' => '该私密房间已到期', 'data' => null];
|
||||
}
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_info = db::name('room')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '所处房间不存在', 'data' => null];
|
||||
}
|
||||
$room_owner_info = db::name('user')->where('uid', $room_info['room_owner_uid'])->find();
|
||||
|
||||
if ($uid == $receive_uid) {
|
||||
return ['code' => 201, 'msg' => '不能给自己打赏', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $receive_uid];
|
||||
$user_list = db::name('user')->field('uid,is_tester,money,integral,nick_name,base64_nick_name,head_pic,europe_key,airship')->where($map)->find();
|
||||
if (empty($user_list)) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物对象不能为空', 'data' => null];
|
||||
}
|
||||
$total_send_num = $num; //赠送礼物总数量
|
||||
$total_send_amount = $gift_info['gift_price'] * $num; //赠送礼物总价值
|
||||
$total_time = $gift_info['duration'] * $num;
|
||||
|
||||
$config = get_system_config();
|
||||
$now_time = time();
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '青少年模式已开启', 'data' => null];
|
||||
}
|
||||
|
||||
//扣款时进行用户资金是否充足判断
|
||||
if ($user_info['integral'] < $total_send_amount) {
|
||||
return ['code' => 201, 'msg' => '账户资金不足', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($user_info['is_tester'] == 2){
|
||||
return ['code' => 201, 'msg' => '虚拟号无法参与', 'data' => null];
|
||||
}
|
||||
|
||||
//计算赠送礼物总资金
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$total_send_amount, 2, 4, "打赏礼物", $uid, 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//赠送礼物增加财富值 贡献值
|
||||
$reslut = model('User')->change_user_contribution_value($uid, $total_send_amount);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试1', 'data' => null];
|
||||
}
|
||||
|
||||
//赠送者增加房间魅力值
|
||||
$reslut = model('User')->change_user_room_contribution_value($uid, $rid, $total_send_amount);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
|
||||
//日贡献
|
||||
model('Statistics')->day_contribution($uid, $rid, $total_send_amount);
|
||||
|
||||
//房间礼物墙
|
||||
$reslut = model('GiftWall')->room_gift_wall($rid, $gid, $total_send_num, $total_send_amount);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试5', 'data' => null];
|
||||
}
|
||||
|
||||
//增加房间热度值
|
||||
db::name('room')->where('rid', $rid)->inc('hot_value', $total_send_amount)->inc('today_hot_value', $total_send_amount)->update();
|
||||
|
||||
// $room_guild_info = model('Guild')->user_guild_info($room_info['room_owner_uid']);
|
||||
// $guild_id = 0;
|
||||
|
||||
//该用户是否有公会及公会收益
|
||||
// $user_guild_info = model('Guild')->user_guild_info($receive_uid);
|
||||
|
||||
$gift_total_price = $gift_info['gift_price'] * $num;
|
||||
|
||||
// $room_owner_profit = $gift_total_price * $room_owner_info['room_owner_commission'];
|
||||
$room_owner_profit = 0;
|
||||
|
||||
|
||||
$receiver_profit = $gift_total_price * 0.56;
|
||||
|
||||
$platform_profit = $gift_total_price - $room_owner_profit - $receiver_profit;
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['rid'] = $rid;
|
||||
// $data['guild_id'] = $user_guild_info['guild_id'];
|
||||
// $data['room_guild_id'] = $room_guild_info['guild_id'];
|
||||
$data['room_uid'] = $room_info['room_owner_uid'];
|
||||
$data['receive_uid'] = $receive_uid;
|
||||
$data['gid'] = $gid;
|
||||
$data['gift_name'] = $gift_info['gift_name'];
|
||||
$data['gift_price'] = $gift_info['gift_price'];
|
||||
$data['gift_type'] = $gift_info['type'];
|
||||
$data['gift_num'] = $num;
|
||||
$data['gift_total_price'] = $gift_total_price;
|
||||
$data['platform_profit'] = $platform_profit;
|
||||
$data['receiver_profit'] = $receiver_profit;
|
||||
$data['room_owner_profit'] = $room_owner_profit;
|
||||
$data['gift_from_type'] = 1;
|
||||
$data['is_tester'] = $user_info['is_tester'];
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
$sid = db::name('user_send_gift')->insertGetId($data);
|
||||
if (empty($sid)) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试3", 'data' => null];
|
||||
}
|
||||
|
||||
//发送数据开始
|
||||
$message_data_temp = [
|
||||
'from_uid' => $uid,
|
||||
'to_uid' => $receive_uid,
|
||||
'gift_name' => $gift_info['gift_name'],
|
||||
'gift_price' => $gift_info['gift_price'],
|
||||
'gift_num' => $num,
|
||||
'rid' => $rid,
|
||||
];
|
||||
$message_data[] = $message_data_temp;
|
||||
|
||||
//增加厅主收益记录
|
||||
if ($room_owner_profit > 0) {
|
||||
$change_value = $room_owner_profit / $config['exchange_rate'];
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_info['room_owner_uid'], $change_value, 1, 7, "打赏厅主流水收益", $uid, $sid, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//礼物接收者收益
|
||||
if ($receiver_profit > 0) {
|
||||
$change_value = $receiver_profit / $config['exchange_rate'];
|
||||
$reslut = model('admin/User')->change_user_money_by_user_info($user_list, $change_value, 1, 6, "礼物收入", $uid, $sid, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//收礼物增加魅力值
|
||||
$reslut = model('User')->change_user_charm_value($receive_uid, $gift_total_price);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
//接受者增加房间魅力值
|
||||
$reslut = model('User')->change_user_room_charm_value($receive_uid, $rid, $gift_total_price, $uid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
|
||||
//收礼物墙
|
||||
$reslut = model('GiftWall')->user_receive_gift_wall($receive_uid, $gid, $num, $uid);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//增加房间时长
|
||||
$reslut = db::name('room_privacy')->where('prid', $prid)->inc('end_time', $total_time)->update(['update_time' => $now_time]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
|
||||
//续时记录
|
||||
$insert = [];
|
||||
$insert['prid'] = $prid;
|
||||
$insert['uid'] = $uid;
|
||||
$insert['receive_uid'] = $receive_uid;
|
||||
$insert['gid'] = $gid;
|
||||
$insert['duration'] = $total_time;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_room_privacy_time_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
|
||||
//发送开始
|
||||
if($message_data) {
|
||||
model('api/AsyncPushMessage')->store_message($message_data, 2);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
$room_privacy_time = db::name('room_privacy')->where('prid', $prid)->value('end_time');
|
||||
$surplus_time = $room_privacy_time - time();
|
||||
if($surplus_time < 0){
|
||||
$surplus_time = 0;
|
||||
}
|
||||
|
||||
$push_room_time = [];
|
||||
$push_room_time['surplus_time'] = $surplus_time;
|
||||
$push_room_time['send_user_info']['uid'] = $uid;
|
||||
$push_room_time['send_user_info']['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$push_room_time['send_user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_room_time['recived_user_info']['uid'] = $receive_uid;
|
||||
$push_room_time['recived_user_info']['head_pic'] = localpath_to_netpath($user_list['head_pic']);
|
||||
$push_room_time['recived_user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_list['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_room_time['gift_price'] = $gift_info['gift_price'];
|
||||
$push_room_time['gift_name'] = $gift_info['gift_name'];
|
||||
$push_room_time['play_image'] = $gift_info['play_image'];
|
||||
$push_room_time['gift_type'] = $gift_info['gift_type'];
|
||||
$push_room_time['base_image'] = $gift_info['base_image'];
|
||||
$push_room_time['num'] = $num;
|
||||
|
||||
if(!empty($uid)){
|
||||
$pust_data = [];
|
||||
$pust_data['code'] = 352;
|
||||
$pust_data['msg'] = '更新私密小屋时间';
|
||||
$pust_data['data'] = $push_room_time;
|
||||
model('api/WebSocketPush')->send_to_one($uid, $pust_data);
|
||||
// dump($reslut);
|
||||
}
|
||||
|
||||
if(!empty($receive_uid)){
|
||||
$pust_data = [];
|
||||
$pust_data['code'] = 352;
|
||||
$pust_data['msg'] = '更新私密小屋时间';
|
||||
$pust_data['data'] = $push_room_time;
|
||||
model('api/WebSocketPush')->send_to_one($receive_uid, $pust_data);
|
||||
// dump($reslut);
|
||||
}
|
||||
|
||||
// model('Room')->push_room_micro_data($rid); //推送最新房间麦位信息
|
||||
// $user_decorate_info = model('api/room')->get_room_user_vip($uid, 0);
|
||||
|
||||
// $room_push_data = [];
|
||||
// $server_push_data = [];
|
||||
// $gift_list = [];
|
||||
// $gift_list[] = $gift_info;
|
||||
// foreach ($user_list as $k => $v) {
|
||||
// foreach ($gift_list as $m => $n) {
|
||||
// $ls_data = [];
|
||||
// $ls_data['send_user_info']['uid'] = $uid;
|
||||
// $ls_data['send_user_info']['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
// $ls_data['send_user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $ls_data['recived_user_info']['uid'] = $v['uid'];
|
||||
// $ls_data['recived_user_info']['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
// $ls_data['recived_user_info']['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $ls_data['lwtp_base_image'] = $user_decorate_info['data']['lwtp_base_image'];
|
||||
// $ls_data['gift_price'] = $n['gift_price'];
|
||||
// $ls_data['gift_name'] = $n['gift_name'];
|
||||
// $ls_data['play_image'] = $n['play_image'];
|
||||
// $ls_data['base_image'] = $n['base_image'];
|
||||
// $ls_data['gift_type'] = $n['gift_type'];
|
||||
// $ls_data['num'] = $num;
|
||||
// $ls_data['is_public_screen'] = $n['is_public_screen'];
|
||||
// $ls_data['is_public_server'] = $n['is_public_server'];
|
||||
// if ($ls_data['is_public_server'] == 1) {
|
||||
// $server_push_data[] = $ls_data;
|
||||
// }
|
||||
// $room_push_data[] = $ls_data;
|
||||
// }
|
||||
// }
|
||||
// if (!empty($server_push_data)) {
|
||||
// $pust_data = [];
|
||||
// $pust_data['code'] = 306;
|
||||
// $pust_data['msg'] = '打赏礼物';
|
||||
// // $pust_data['data'] = $server_push_data;
|
||||
// $pust_data['data']['room_info']['rid'] = $room_info['rid'];
|
||||
// $pust_data['data']['room_info']['room_name'] = mb_convert_encoding(base64_decode($room_info['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
// $pust_data['data']['gift_list'] = $server_push_data;
|
||||
// model('api/WebSocketPush')->send_to_all($pust_data);
|
||||
// }
|
||||
// if (!empty($room_push_data)) {
|
||||
// $pust_data = [];
|
||||
// $pust_data['code'] = 302;
|
||||
// $pust_data['msg'] = '打赏礼物';
|
||||
// $pust_data['data'] = $room_push_data;
|
||||
// model('api/WebSocketPush')->send_to_group($room_info['rid'], $pust_data);
|
||||
// }
|
||||
return ['code' => 200, 'msg' => "打赏成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试5", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
419
application/api/model/Decorate.php
Normal file
419
application/api/model/Decorate.php
Normal file
@@ -0,0 +1,419 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Decorate extends Model
|
||||
{
|
||||
//装扮列表
|
||||
// public function get_decorate_list($type, $page, $page_limit)
|
||||
// {
|
||||
// $page = intval($page);
|
||||
// $page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
// $map = [];
|
||||
// $map[] = ['type', '=', $type];
|
||||
// $map[] = ['is_buy', '=', 1];
|
||||
// $map[] = ['show_status', '=', 1];
|
||||
// $map[] = ['is_delete', '=', 1];
|
||||
// $list = db::name('decorate')->field('did,title,type,base_image,play_image,price,day')->where($map)->order('price asc')->page($page, $page_limit)->select();
|
||||
// foreach ($list as $k => &$v) {
|
||||
// $v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
// $v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
// }
|
||||
// return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
// }
|
||||
public function get_decorate_list($type, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.type', '=', $type];
|
||||
$map[] = ['a.show_status', '=', 1];
|
||||
$map[] = ['a.is_buy', '=', 1];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$map[] = ['b.is_delete', '=', 1];
|
||||
$map[] = ['a.is_user_buy', '=', 2];
|
||||
$list = db::name('decorate')->alias('a')->join('yy_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')->where($map)->group('b.did')->order('price asc')->page($page, $page_limit)->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' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//装扮详情
|
||||
public function get_decorate_info($did){
|
||||
$decorate_info = db::name('decorate')->field('did,title,type,base_image,play_image,special_num')->find($did);
|
||||
|
||||
$decorate_info['base_image'] = localpath_to_netpath($decorate_info['base_image']);
|
||||
$decorate_info['play_image'] = localpath_to_netpath($decorate_info['play_image']);
|
||||
$decorate_info['decorate_price'] = db::name('decorate_price')->where('did', $decorate_info['did'])->where('is_delete', 1)->field('price,day')->select();
|
||||
foreach ($decorate_info['decorate_price'] as $k => &$v){
|
||||
$v['price'] = (int)$v['price'];
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $decorate_info];
|
||||
}
|
||||
|
||||
|
||||
//购买装扮
|
||||
// public function pay_decorate($uid, $did, $num){
|
||||
// $user_info = db::name('user')->find($uid);
|
||||
// if(!$user_info){
|
||||
// return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
// }
|
||||
|
||||
// if($user_info['is_teenager'] == 1){
|
||||
// return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
// }
|
||||
|
||||
// //该装扮是否存在
|
||||
// $map = [];
|
||||
// $map[] = ['did', '=', $did];
|
||||
// $map[] = ['is_buy', '=', 1];
|
||||
// $map[] = ['show_status', '=', 1];
|
||||
// $map[] = ['is_delete', '=', 1];
|
||||
// $decorate_info = db::name('decorate')->where($map)->find();
|
||||
// if(!$decorate_info){
|
||||
// return ['code' => 201, 'msg' => '该装扮不存在', 'data' => null];
|
||||
// }
|
||||
|
||||
// if($num < 1){
|
||||
// return ['code' => 201, 'msg' => '购买数量不能小于1', 'data' => null];
|
||||
// }
|
||||
|
||||
// $now_time = time();
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// $pay_price = $decorate_info['price'] * $num;
|
||||
// $day = $decorate_info['day'] * $num;
|
||||
|
||||
// //金币是否足够
|
||||
// $reslut = model('admin/User')->change_user_money_by_user_info($user_info, -$pay_price, 2, 21, "购买装扮", $user_info['uid'], 0);
|
||||
// if ($reslut['code'] != 200) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
|
||||
// //该用户是否有该装扮
|
||||
// $map = [];
|
||||
// $map[] = ['uid', '=', $uid];
|
||||
// $map[] = ['did', '=', $did];
|
||||
// $user_decorate_data = db::name('user_decorate')->where($map)->find();
|
||||
// if(empty($user_decorate_data)){
|
||||
// $data = [];
|
||||
// $data['uid'] = $uid;
|
||||
// $data['did'] = $did;
|
||||
// $data['type'] = $decorate_info['type'];
|
||||
// $data['is_using'] = 2;
|
||||
// $data['add_time'] = $now_time;
|
||||
// $data['end_time'] = $now_time + $day * 24 * 3600;
|
||||
// $result = db::name('user_decorate')->insert($data);
|
||||
// $start_time = $now_time;
|
||||
// $change_time = $day * 24 * 3600;
|
||||
// }else{
|
||||
// if($user_decorate_data['end_time'] < $now_time){
|
||||
// $start_time = $now_time;
|
||||
// $change_time = $day * 24 * 3600;
|
||||
// $update = [];
|
||||
// $update['add_time'] = $now_time;
|
||||
// $update['end_time'] = $now_time + $day * 24 * 3600;
|
||||
// $result = db::name('user_decorate')->where('udid', $user_decorate_data['udid'])->update($update);
|
||||
// }else{
|
||||
// $start_time = $user_decorate_data['end_time'];
|
||||
// if($start_time >= 1893465753){
|
||||
// $change_time = 0;
|
||||
// $result = 1;
|
||||
// }else{
|
||||
// $change_time = $day * 24 * 3600;
|
||||
// $result = db::name('user_decorate')->where('udid', $user_decorate_data['udid'])->setInc('end_time', $change_time);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(!$result){
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
// }
|
||||
|
||||
// //记录日志
|
||||
// $insert_data = [];
|
||||
// $insert_data['uid'] = $uid;
|
||||
// $insert_data['type'] = $decorate_info['type'];
|
||||
// $insert_data['did'] = $did;
|
||||
// $insert_data['add_time'] = $now_time;
|
||||
// $insert_data['remark'] = '购买';
|
||||
// $insert_data['from_type'] = 2;
|
||||
// $insert_data['start_time'] = $start_time;
|
||||
// $insert_data['end_time'] = $start_time + $change_time;
|
||||
// $insert_data['day_num'] = $day;
|
||||
// $insert_data['pay_price'] = $pay_price;
|
||||
// $result = db::name('user_decorate_log')->insert($insert_data);
|
||||
// if(!$result){
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
// }
|
||||
// // 提交事务
|
||||
// Db::commit();
|
||||
// return ['code' => 200, 'msg' => "购买成功", 'data' => null];
|
||||
// } catch (\Exception $e) {
|
||||
// dump($e);
|
||||
// // 回滚事务
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
//购买装扮
|
||||
public function pay_decorate($uid, $did, $day){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//该装扮是否存在
|
||||
$map = [];
|
||||
$map[] = ['did', '=', $did];
|
||||
$map[] = ['is_buy', '=', 1];
|
||||
$map[] = ['show_status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$decorate_info = db::name('decorate')->where($map)->find();
|
||||
if(!$decorate_info){
|
||||
return ['code' => 201, 'msg' => '该装扮不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//该天数是否存在
|
||||
$map = [];
|
||||
$map[] = ['did', '=', $did];
|
||||
$map[] = ['day', '=', $day];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$decorate_price_info = db::name('decorate_price')->where($map)->find();
|
||||
if(!$decorate_price_info){
|
||||
return ['code' => 201, 'msg' => '该装扮天数不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($decorate_info['type'] == 6 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 201, 'msg' => '该个人靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 7 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 201, 'msg' => '该房间靓号已被购买', 'data' => null];
|
||||
}
|
||||
$now_time = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$pay_price = $decorate_price_info['price'];
|
||||
|
||||
//金币是否足够
|
||||
$reslut = model('admin/User')->change_user_money_by_user_info($user_info, -$pay_price, 2, 21, "购买装扮", $user_info['uid'], 0);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否有该装扮
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['did', '=', $did];
|
||||
$user_decorate_data = db::name('user_decorate')->where($map)->find();
|
||||
if(empty($user_decorate_data)){
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['did'] = $did;
|
||||
$data['type'] = $decorate_info['type'];
|
||||
$data['is_using'] = 2;
|
||||
$data['add_time'] = $now_time;
|
||||
$data['end_time'] = $now_time + $day * 24 * 3600;
|
||||
$data['special_num'] = $decorate_info['special_num'];
|
||||
$result = db::name('user_decorate')->insert($data);
|
||||
$start_time = $now_time;
|
||||
$change_time = $day * 24 * 3600;
|
||||
}else{
|
||||
if($user_decorate_data['end_time'] < $now_time){
|
||||
$start_time = $now_time;
|
||||
$change_time = $day * 24 * 3600;
|
||||
$update = [];
|
||||
$update['add_time'] = $now_time;
|
||||
$update['end_time'] = $now_time + $day * 24 * 3600;
|
||||
$result = db::name('user_decorate')->where('udid', $user_decorate_data['udid'])->update($update);
|
||||
}else{
|
||||
$start_time = $user_decorate_data['end_time'];
|
||||
if($start_time >= 1893465753){
|
||||
$change_time = 0;
|
||||
$result = 1;
|
||||
}else{
|
||||
$change_time = $day * 24 * 3600;
|
||||
$result = db::name('user_decorate')->where('udid', $user_decorate_data['udid'])->setInc('end_time', $change_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
//记录日志
|
||||
$insert_data = [];
|
||||
$insert_data['uid'] = $uid;
|
||||
$insert_data['type'] = $decorate_info['type'];
|
||||
$insert_data['did'] = $did;
|
||||
$insert_data['add_time'] = $now_time;
|
||||
$insert_data['remark'] = '购买';
|
||||
$insert_data['from_type'] = 2;
|
||||
$insert_data['start_time'] = $start_time;
|
||||
$insert_data['end_time'] = $start_time + $change_time;
|
||||
$insert_data['day_num'] = $day;
|
||||
$insert_data['pay_price'] = $pay_price;
|
||||
$insert_data['special_num'] = $decorate_info['special_num'];
|
||||
$result = db::name('user_decorate_log')->insert($insert_data);
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
//如果购买个人或房间靓号
|
||||
if($decorate_info['type'] == 6 || $decorate_info['type'] == 7) {
|
||||
Db::name('decorate')->where('did', $decorate_info['did'])->update(['is_user_buy' => 1, 'update_time' => time()]);
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "购买成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//奖励装扮 is_perpetual 是否永久,1是2否
|
||||
public function draw_user_decorate($uid, $did, $day, $remake, $is_perpetual = 2, $cp_id = 0){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$decorate_info = db::name('decorate')->where('did', $did)->find();
|
||||
if(!$decorate_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$now_time = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
//是否有该装扮
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['did', '=', $did];
|
||||
$map[] = ['cp_id', '=', $cp_id];
|
||||
$map[] = ['is_perpetual', '=', $is_perpetual];
|
||||
$user_decorate_data = db::name('user_decorate')->where($map)->find();
|
||||
if(empty($user_decorate_data)){
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['did'] = $did;
|
||||
$data['type'] = $decorate_info['type'];
|
||||
$data['is_using'] = 2;
|
||||
$data['add_time'] = $now_time;
|
||||
$data['end_time'] = $now_time + $day * 24 * 3600;
|
||||
$data['cp_id'] = $cp_id;
|
||||
$data['is_perpetual'] = $is_perpetual;
|
||||
$result = db::name('user_decorate')->insert($data);
|
||||
$start_time = $now_time;
|
||||
$change_time = $day * 24 * 3600;
|
||||
}else{
|
||||
if($user_decorate_data['end_time'] < $now_time){
|
||||
$start_time = $now_time;
|
||||
$change_time = $day * 24 * 3600;
|
||||
$update = [];
|
||||
$update['add_time'] = $now_time;
|
||||
$update['end_time'] = $now_time + $day * 24 * 3600;
|
||||
$result = db::name('user_decorate')->where('udid', $user_decorate_data['udid'])->update($update);
|
||||
}else{
|
||||
$start_time = $user_decorate_data['end_time'];
|
||||
if($start_time >= 1893465753){
|
||||
$change_time = 0;
|
||||
$result = 1;
|
||||
}else{
|
||||
$change_time = $day * 24 * 3600;
|
||||
$result = db::name('user_decorate')->where('udid', $user_decorate_data['udid'])->setInc('end_time', $change_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
//记录日志
|
||||
$insert_data = [];
|
||||
$insert_data['uid'] = $uid;
|
||||
$insert_data['type'] = $decorate_info['type'];
|
||||
$insert_data['did'] = $did;
|
||||
$insert_data['add_time'] = $now_time;
|
||||
$insert_data['remark'] = $remake;
|
||||
$insert_data['from_type'] = 4;
|
||||
$insert_data['start_time'] = $start_time;
|
||||
$insert_data['end_time'] = $start_time + $change_time;
|
||||
$insert_data['day_num'] = $day;
|
||||
$result = db::name('user_decorate_log')->insert($insert_data);
|
||||
if(!$result){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function get_cp_decorate_list($uid,$type){
|
||||
if(!in_array($type,[1,9])){
|
||||
return ['code' => 201, 'msg' => "头像框非法!", 'data' => null];
|
||||
}
|
||||
$user_coupling = db::name('user_coupling')->where([["uid|receive_uid",'=',$uid],['is_delete','=',1]])->order(['id'=>'desc'])->find();
|
||||
if(empty($user_coupling)){
|
||||
return ['code' => 201, 'msg' => "您尚未建立cp!", 'data' => null];
|
||||
}
|
||||
$cp_id = $user_coupling['id'];
|
||||
//查询我的装扮
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
590
application/api/model/Envelope.php
Normal file
590
application/api/model/Envelope.php
Normal file
@@ -0,0 +1,590 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Envelope extends Model
|
||||
{
|
||||
|
||||
//抢红包生成金额
|
||||
public function red_envelope_create_money($min = 1, $max = 50, $num = 10, $total){
|
||||
$max = ($total/$num)*2;
|
||||
$max = (int)$max;
|
||||
$sum = 0;
|
||||
$totals = $total;
|
||||
$nums = $num;
|
||||
$data = [];
|
||||
if ($min * $num > $total) {
|
||||
return [];
|
||||
}
|
||||
if($max*$num < $total){
|
||||
return [];
|
||||
}
|
||||
while ($num >= 1) {
|
||||
$num--;
|
||||
$kmix = max($min, $total - $num * $max);
|
||||
$kmax = min($max, $total - $num * $min);
|
||||
$kAvg = $total / ($num + 1);
|
||||
//获取最大值和最小值的距离之间的最小值
|
||||
$kDis = min($kAvg - $kmix, $kmax - $kAvg);
|
||||
//获取0到1之间的随机数与距离最小值相乘得出浮动区间,这使得浮动区间不会超出范围
|
||||
$r = ((float)(rand(1, 10000) / 10000) - 0.5) * $kDis * 2;
|
||||
$k = sprintf("%.2f", $kAvg + $r);
|
||||
$k = round($k, 0);
|
||||
$total -= $k;
|
||||
$data[] = $k;
|
||||
$sum += $k;
|
||||
}
|
||||
|
||||
if($totals != (int)$sum){
|
||||
$return = $this->red_envelope_create_money($min, $max, $nums, $totals);
|
||||
return $return;
|
||||
}else{
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//红包展示
|
||||
public function get_red_envelope_list($uid, $type){
|
||||
$config = get_uncache_system_config();
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//红包类型
|
||||
$envelope_type_info = db::name('envelope_type')->find($type);
|
||||
if(!$envelope_type_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有进行中的
|
||||
$map = [];
|
||||
$map[] = ['tid', '=', $type];
|
||||
$map[] = ['is_finish', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['is_stop', '=', 2];
|
||||
$red_envelope_info = db::name('red_envelope')->where($map)->find();
|
||||
$data = [];
|
||||
$data['type'] = $type;
|
||||
$data['type_name'] = $envelope_type_info['type_name'];
|
||||
$data['price'] = $envelope_type_info['price'];
|
||||
if($red_envelope_info){
|
||||
$data['unopen_num'] = $red_envelope_info['num'] - $red_envelope_info['open_num'];
|
||||
$data['is_finish'] = $red_envelope_info['is_finish'];
|
||||
$data['num'] = $red_envelope_info['num'];
|
||||
}else{
|
||||
$data['unopen_num'] = 0;
|
||||
$data['is_finish'] = 1;
|
||||
if($type == 1){
|
||||
$data['num'] = $config['silver_envelope_num'];
|
||||
}else if($type == 2){
|
||||
$data['num'] = $config['gold_envelope_num'];
|
||||
}else if($type == 3){
|
||||
$data['num'] = $config['drill_envelope_num'];
|
||||
}
|
||||
}
|
||||
$data['integral'] = $user_info['integral'];
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//抢红包
|
||||
public function snatch_red_envelope($uid, $rid, $type){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info['is_tester'] == 2){
|
||||
return ['code' => 201, 'msg' => '虚拟号无法参与', 'data' => null];
|
||||
}
|
||||
|
||||
//房间是否存在
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$room_info = db::name('room')->where($map)->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//红包类型
|
||||
$envelope_type_info = db::name('envelope_type')->find($type);
|
||||
if(!$envelope_type_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//金币是否充足
|
||||
if($user_info['integral'] < $envelope_type_info['price']){
|
||||
return ['code' => 201, 'msg' => '金币不足', 'data' => null];
|
||||
}
|
||||
$where = [];
|
||||
$where[] = ['a.uid', '=', $uid];
|
||||
$where[] = ['b.is_stop', '=', 2];
|
||||
$red_envelope_log = db::name('user_red_envelope_log')->alias('a')->join('yy_red_envelope b', 'a.eid = b.id')->field('sum(b.money) as money')->where($where)->find();
|
||||
$surplus_money = $user_info['integral'] - $red_envelope_log['money'];
|
||||
if($envelope_type_info['price'] > $surplus_money){
|
||||
return ['code' => 201, 'msg' => '金币不足', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有进行中的
|
||||
$map = [];
|
||||
$map[] = ['tid', '=', $type];
|
||||
$map[] = ['is_finish', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['is_stop', '=', 2];
|
||||
$red_envelope_info = db::name('red_envelope')->where($map)->find();
|
||||
if(!$red_envelope_info){
|
||||
return ['code' => 201, 'msg' => '暂未开放', 'data' => null];
|
||||
}
|
||||
|
||||
//开始十秒内无法抢红包
|
||||
$time = time() - $red_envelope_info['add_time'];
|
||||
if($time < 10){
|
||||
return ['code' => 201, 'msg' => '请在开始十秒后再抢', 'data' => null];
|
||||
}
|
||||
|
||||
//是否抢过该红包
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['eid', '=', $red_envelope_info['id']];
|
||||
$user_snatch_red_envelope = db::name('user_red_envelope_log')->where($map)->find();
|
||||
if($user_snatch_red_envelope){
|
||||
return ['code' => 201, 'msg' => '你已抢过该红包', 'data' => null];
|
||||
}
|
||||
|
||||
//该红包数量是否剩余
|
||||
$map = [];
|
||||
$map[] = ['eid', '=', $red_envelope_info['id']];
|
||||
$user_snatch_red_envelope_sum = db::name('user_red_envelope_log')->where($map)->count();
|
||||
if($user_snatch_red_envelope_sum == $red_envelope_info['num']){
|
||||
return ['code' => 201, 'msg' => '红包已被抢完', 'data' => null];
|
||||
}
|
||||
|
||||
$config = get_uncache_system_config();
|
||||
$redis = connectionRedis();
|
||||
$user_red_envelope_id_list = [];
|
||||
$is_open = 1;
|
||||
if($type == 1){
|
||||
$keyname = "silver:envelope:key:name:".$red_envelope_info['id'];
|
||||
$envelope_num = $config['silver_envelope_num'];
|
||||
if($config['open_silver_envelope'] != 1){
|
||||
$is_open = 2;
|
||||
}
|
||||
}else if($type == 2){
|
||||
$keyname = "gold:envelope:key:name:".$red_envelope_info['id'];
|
||||
$envelope_num = $config['gold_envelope_num'];
|
||||
if($config['open_gold_envelope'] != 1){
|
||||
$is_open = 2;
|
||||
}
|
||||
}else if($type == 3){
|
||||
$keyname = "drill:envelope:key:name:".$red_envelope_info['id'];
|
||||
$envelope_num = $config['drill_envelope_num'];
|
||||
if($config['open_drill_envelope'] != 1){
|
||||
$is_open = 2;
|
||||
}
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//抢红包记录
|
||||
$list_len = $redis->llen($keyname);
|
||||
if($list_len = 0){
|
||||
return ['code' => 201, 'msg' => '该轮红包已被抢完,请稍后', 'data' => null];
|
||||
}
|
||||
$snatch_price_data = $redis->blpop($keyname, 2);
|
||||
if(empty($snatch_price_data)){
|
||||
return ['code' => 201, 'msg' => '红包已被抢完', 'data' => null];
|
||||
}
|
||||
$snatch_price = $snatch_price_data[1];
|
||||
|
||||
$data = [];
|
||||
$data['price'] = $snatch_price;
|
||||
$user_red_envelope_id_list[] = $data;
|
||||
|
||||
//记录
|
||||
$insert_data_log = [];
|
||||
$insert_data_log['uid'] = $uid;
|
||||
$insert_data_log['rid'] = $rid;
|
||||
$insert_data_log['tid'] = $type;
|
||||
$insert_data_log['eid'] = $red_envelope_info['id'];
|
||||
$insert_data_log['money'] = $red_envelope_info['money'];
|
||||
$insert_data_log['price'] = $red_envelope_info['price'];
|
||||
$insert_data_log['snatch_price'] = $snatch_price;
|
||||
$insert_data_log['envelope_price'] = $config['envelope_rate'] * $red_envelope_info['money'];
|
||||
$insert_data_log['room_price'] = $room_info['envelope_rate'] * $snatch_price;
|
||||
$insert_data_log['add_time'] = time();
|
||||
$sid = db::name('user_red_envelope_log')->insertGetId($insert_data_log);
|
||||
if(!$sid){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//修改红包已开次数
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $red_envelope_info['id']];
|
||||
$map[] = ['open_num', '<', $red_envelope_info['num']];
|
||||
$reslut = db::name('red_envelope')->where($map)->inc('open_num', 1)->update();
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//抢红包收入
|
||||
$resluts = model('admin/User')->change_user_money_by_user_info($user_info, $snatch_price, 2, 19, "抢红包收入", $uid, $sid, $rid);
|
||||
if(!$resluts){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//厅主收益
|
||||
if($insert_data_log['room_price'] > 0){
|
||||
$room_user_info = db::name('user')->find($room_info['room_owner_uid']);
|
||||
$reslut = model('admin/User')->change_user_money_by_user_info($room_user_info, $insert_data_log['room_price'], 1, 20, "抢红包厅主流水", $uid, $sid, $rid);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//是否最后一个红包
|
||||
$where = [];
|
||||
$where[] = ['eid', '=', $red_envelope_info['id']];
|
||||
$red_envelope_list = db::name('user_red_envelope_log')->where($where)->order('snatch_price desc,id asc')->select();
|
||||
if(count($red_envelope_list) == $red_envelope_info['num']){
|
||||
//修改红包状态
|
||||
$update_data = [];
|
||||
$update_data['is_finish'] = 1;
|
||||
$update_data['is_stop'] = 1;
|
||||
$update_data['stop_time'] = time();
|
||||
$reslut = db::name('red_envelope')->where('id', $red_envelope_info['id'])->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//找到手气最佳新生成一轮红包
|
||||
foreach ($red_envelope_list as $k => $v){
|
||||
if($k == 0){
|
||||
//修改手气最佳
|
||||
$update_data = [];
|
||||
$update_data['is_lucky'] = 1;
|
||||
$reslut = db::name('user_red_envelope_log')->where('id', $v['id'])->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//后台是否已关闭发红包功能
|
||||
if($is_open == 1){
|
||||
//发红包
|
||||
$insert_data = [];
|
||||
$insert_data['tid'] = $type;
|
||||
$insert_data['uid'] = $v['uid'];
|
||||
$insert_data['type'] = 2;
|
||||
$insert_data['money'] = $envelope_type_info['price'];
|
||||
$insert_data['price'] = $insert_data['money'] * (1 - $config['envelope_rate']);
|
||||
$insert_data['num'] = $envelope_num;
|
||||
$insert_data['add_time'] = time();
|
||||
$sid = db::name('red_envelope')->insertGetId($insert_data);
|
||||
if(!$sid){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
$insert_user_info = db::name('user')->find($v['uid']);
|
||||
//扣除发红包金币数
|
||||
$resluts = model('admin/User')->change_user_money_by_user_info($insert_user_info, -$envelope_type_info['price'], 2, 18, "发红包支出", $v['uid'], $sid, $rid);
|
||||
if(!$resluts){
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//生成红包队列
|
||||
$redis->del($keyname);
|
||||
if($type == 1){
|
||||
$key_name = "silver:envelope:key:name:". $sid;
|
||||
}else if($type == 2){
|
||||
$key_name = "gold:envelope:key:name:" . $sid;
|
||||
}else if($type == 3){
|
||||
$key_name = "drill:envelope:key:name:" . $sid;
|
||||
}
|
||||
|
||||
|
||||
$envelope_price_array = model('Envelope')->red_envelope_create_money(1, 500, $envelope_num, $insert_data['price']);
|
||||
$envelope_insert_data = $envelope_price_array;
|
||||
array_unshift($envelope_insert_data, $key_name);
|
||||
call_user_func_array([$redis, 'rPush'], $envelope_insert_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
//抢红包socket
|
||||
$snatch_red_envelope = [];
|
||||
$snatch_red_envelope['uid'] = $uid;
|
||||
$snatch_red_envelope['rid'] = $rid;
|
||||
$snatch_red_envelope['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$snatch_red_envelope['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$snatch_red_envelope['type'] = $type;
|
||||
$snatch_red_envelope['type_name'] = $envelope_type_info['type_name'];
|
||||
$snatch_red_envelope['num'] = $red_envelope_info['num'] - $red_envelope_info['open_num'] - 1;
|
||||
$snatch_red_envelope['room_name'] = mb_convert_encoding(base64_decode($room_info['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$snatch_red_envelope['is_show_price'] = 2;
|
||||
|
||||
if(count($red_envelope_list) == $red_envelope_info['num']){
|
||||
$red_envelope_over = [];
|
||||
|
||||
$where = [];
|
||||
$where[] = ['a.eid', '=', $red_envelope_info['id']];
|
||||
$user_red_envelope_log_list = db::name('user_red_envelope_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_room c', 'a.rid = c.rid')->field('a.id,a.uid,a.rid,a.eid,a.snatch_price,b.head_pic,b.base64_nick_name,c.base64_room_name,a.is_lucky')->where($where)->order('a.id asc')->select();
|
||||
foreach ($user_red_envelope_log_list as $k => $v){
|
||||
$user_log_array = [];
|
||||
$user_log_array['uid'] = $v['uid'];
|
||||
$user_log_array['rid'] = $v['rid'];
|
||||
$user_log_array['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$user_log_array['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_log_array['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$user_log_array['snatch_price'] = $v['snatch_price'];
|
||||
$user_log_array['is_show_price'] = 1;
|
||||
$user_log_array['is_lucky'] = $v['is_lucky'];
|
||||
$red_envelope_over[] = $user_log_array;
|
||||
}
|
||||
|
||||
//结束socket
|
||||
$push_all_snatch_envelope_data = [];
|
||||
$push_all_snatch_envelope_data['snatch_red_envelope'] = $snatch_red_envelope;
|
||||
$push_all_snatch_envelope_data['red_envelope_over'] = $red_envelope_over;
|
||||
$push_all_snatch_envelope_data['type'] = $type;
|
||||
$push_all_snatch_envelope_data['type_name'] = $envelope_type_info['type_name'];
|
||||
if($is_open == 1){
|
||||
$push_all_snatch_envelope_data['is_open'] = 1;
|
||||
$push_all_snatch_envelope_data['num'] = $envelope_num;
|
||||
$push_all_snatch_envelope_data['second'] = 10;
|
||||
}else{
|
||||
$push_all_snatch_envelope_data['is_open'] = 2;
|
||||
$push_all_snatch_envelope_data['num'] = 0;
|
||||
$push_all_snatch_envelope_data['second'] = 0;
|
||||
}
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 412;
|
||||
$push_data['msg'] = '抢红包结束数据播报';
|
||||
$push_data['data'] = $push_all_snatch_envelope_data;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
|
||||
}else{
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 411;
|
||||
$push_data['msg'] = '抢红包数据播报';
|
||||
$push_data['data'] = $snatch_red_envelope;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
}
|
||||
$snatch_red_envelope['integral'] = db::name('user')->where('uid', $uid)->value('integral');
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => $snatch_red_envelope];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
$this->redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list);
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//返还用户抽中红包金额到队列
|
||||
private function redis_envelope_data_rollback($redis, $keyname, $user_red_envelope_id_list)
|
||||
{
|
||||
$insert_data = [];
|
||||
foreach ($user_red_envelope_id_list as $k => $v) {
|
||||
$insert_data[] = $v['price'];
|
||||
}
|
||||
if (!empty($insert_data)) {
|
||||
array_unshift($insert_data, $keyname);
|
||||
//右侧取 右侧插入
|
||||
call_user_func_array([$redis, 'lPush'], $insert_data);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '返还成功', 'data' => null];
|
||||
}
|
||||
|
||||
//红包记录信息
|
||||
public function red_envelope_info($uid, $type){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
//最新红包记录
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['is_finish', '=', 2];
|
||||
$map[] = ['is_stop', '=', 2];
|
||||
$map[] = ['tid', '=', $type];
|
||||
$red_envelope_info = db::name('red_envelope')->where($map)->order('id desc')->limit(1)->find();
|
||||
if($red_envelope_info){
|
||||
$user_red_envelope_log_list = db::name('user_red_envelope_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_room c', 'a.rid = c.rid')->where('a.eid', $red_envelope_info['id'])->field('a.id, a.uid, a.rid, a.eid, b.head_pic,b.base64_nick_name,c.base64_room_name')->order('a.id asc')->select();
|
||||
foreach ($user_red_envelope_log_list as $k => &$v){
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$v['is_show_price'] = 2;
|
||||
}
|
||||
$data['red_envelope_list'] = $user_red_envelope_log_list;
|
||||
}else{
|
||||
$data['red_envelope_list'] = [];
|
||||
}
|
||||
|
||||
//前一次红包记录
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['is_stop', '=', 1];
|
||||
$map[] = ['tid', '=', $type];
|
||||
$last_red_envelope_info = db::name('red_envelope')->where($map)->order('id desc')->limit(1)->find();
|
||||
// dump($last_red_envelope_info);
|
||||
if($last_red_envelope_info){
|
||||
$user_red_envelope_log_lists = db::name('user_red_envelope_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_room c', 'a.rid = c.rid')->where('a.eid', $last_red_envelope_info['id'])->field('a.id, a.uid, a.rid, a.eid,a.snatch_price,a.is_lucky, b.head_pic,b.base64_nick_name,c.base64_room_name')->order('a.id asc')->select();
|
||||
|
||||
foreach ($user_red_envelope_log_lists as $a => &$b){
|
||||
$b['head_pic'] = localpath_to_netpath($b['head_pic']);
|
||||
$b['nick_name'] = mb_convert_encoding(base64_decode($b['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$b['room_name'] = mb_convert_encoding(base64_decode($b['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$b['is_show_price'] = 2;
|
||||
}
|
||||
// dump($user_red_envelope_log_lists);
|
||||
$user_red_envelope_list = db::name('user_red_envelope_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_room c', 'a.rid = c.rid')->where('a.eid', $last_red_envelope_info['id'])->field('a.id, a.uid, a.rid, a.eid,a.snatch_price,a.is_lucky, b.head_pic,b.base64_nick_name,c.base64_room_name')->order('a.id asc')->select();
|
||||
foreach ($user_red_envelope_list as $x => &$y){
|
||||
$y['head_pic'] = localpath_to_netpath($y['head_pic']);
|
||||
$y['nick_name'] = mb_convert_encoding(base64_decode($y['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$y['room_name'] = mb_convert_encoding(base64_decode($y['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$y['is_show_price'] = 1;
|
||||
}
|
||||
|
||||
$data['last_red_envelope_list'] = array_merge($user_red_envelope_log_lists, $user_red_envelope_list);
|
||||
|
||||
}else{
|
||||
$data['last_red_envelope_list'] = [];
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//红包规则
|
||||
public function envelope_note(){
|
||||
$envelope_note = get_system_config('envelope_note');
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $envelope_note];
|
||||
}
|
||||
|
||||
//用户抢红包记录
|
||||
public function user_red_envelope_log_list($uid, $type, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$map[] = ['a.tid', '=', $type];
|
||||
$list = db::name('user_red_envelope_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_room c', 'a.rid = c.rid')->field('a.id,a.uid,a.rid,a.tid,a.snatch_price,b.head_pic,b.base64_nick_name,c.base64_room_name')->where($map)->order('id desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//限时结束
|
||||
public function red_envelope_time_limit(){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($config['envelope_sustain_duration'] != 0){
|
||||
//是否有已开宝藏
|
||||
$map = [];
|
||||
$map[] = ['is_stop', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$red_envelope_list = db::name('red_envelope')->where($map)->select();
|
||||
if($red_envelope_list){
|
||||
foreach ($red_envelope_list as $k => $v){
|
||||
//是否超时
|
||||
$time = time() - $v['add_time'];
|
||||
if($time > $config['envelope_sustain_duration']){
|
||||
$red_envelope_log_list = db::name('user_red_envelope_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_room c', 'a.rid = c.rid')->field('a.id,a.uid,a.rid,a.eid,a.snatch_price,b.head_pic,b.base64_nick_name,c.base64_room_name,a.is_lucky')->where('eid', $v['id'])->order('id asc')->select();
|
||||
if(count($red_envelope_log_list) != $v['num']){
|
||||
//修改宝藏状态
|
||||
$update_data = [];
|
||||
$update_data['is_stop'] = 1;
|
||||
$update_data['stop_time'] = time();
|
||||
$reslut = db::name('red_envelope')->where('id', $v['id'])->update($update_data);
|
||||
if($reslut){
|
||||
//发布socekt
|
||||
$snatch_red_envelope = [];
|
||||
$snatch_red_envelope['uid'] = 0;
|
||||
$red_envelope_over = [];
|
||||
if(!empty($red_envelope_log_list)){
|
||||
foreach ($red_envelope_log_list as $a => $b){
|
||||
$user_log_array = [];
|
||||
$user_log_array['uid'] = $b['uid'];
|
||||
$user_log_array['rid'] = $b['rid'];
|
||||
$user_log_array['head_pic'] = localpath_to_netpath($b['head_pic']);
|
||||
$user_log_array['nick_name'] = mb_convert_encoding(base64_decode($b['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_log_array['room_name'] = mb_convert_encoding(base64_decode($b['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$user_log_array['snatch_price'] = $b['snatch_price'];
|
||||
$user_log_array['is_show_price'] = 1;
|
||||
$user_log_array['is_lucky'] = $b['is_lucky'];
|
||||
$red_envelope_over[] = $user_log_array;
|
||||
}
|
||||
}
|
||||
$push_all_snatch_envelope_data = [];
|
||||
$push_all_snatch_envelope_data['snatch_red_envelope'] = $snatch_red_envelope;
|
||||
$push_all_snatch_envelope_data['red_envelope_over'] = $red_envelope_over;
|
||||
$push_all_snatch_envelope_data['type'] = $v['tid'];
|
||||
$push_all_snatch_envelope_data['type_name'] = db::name('envelope_type')->where('id', $v['tid'])->value('type_name');
|
||||
$push_all_snatch_envelope_data['is_open'] = 2;
|
||||
$push_all_snatch_envelope_data['num'] = 0;
|
||||
$push_all_snatch_envelope_data['second'] = 0;
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 412;
|
||||
$push_data['msg'] = '抢红包结束数据播报';
|
||||
$push_data['data'] = $push_all_snatch_envelope_data;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
60
application/api/model/FaceVerifyCallback.php
Normal file
60
application/api/model/FaceVerifyCallback.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class FaceVerifyCallback extends Model
|
||||
{
|
||||
//轮播图列表
|
||||
public function verify($uid)
|
||||
{
|
||||
$data = [
|
||||
'verify_result' => 2,
|
||||
];
|
||||
$open_face_verify = db::name('config')->where('key_title', 'open_face_verify')->value('key_value');
|
||||
if($open_face_verify != 1) {
|
||||
return ['code' => 200, 'msg' => '获取验证信息成功', 'data' => $data];
|
||||
}
|
||||
|
||||
$user_info = Db::name('user')->where('uid', $uid)->field('is_real, uid')->find();
|
||||
if(empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '用户信息不存在', 'data' => null];
|
||||
}
|
||||
if($user_info['is_real'] == 3) {
|
||||
|
||||
return ['code' => 201, 'msg' => '人工审核中,请联系管理员', 'data' => null];
|
||||
}
|
||||
if($user_info['is_real'] == 2) {
|
||||
|
||||
return ['code' => 201, 'msg' => '请进行实名认证', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['verify_time', '>=', strtotime(date('Ymd'))];
|
||||
$verify = Db::name('face_verify_callback')->where($map)->find();
|
||||
// dump($verify);die;
|
||||
if($verify) {
|
||||
$verify_result = 2;
|
||||
} else {
|
||||
$verify_result = 1;
|
||||
}
|
||||
// $verify_result = 2;
|
||||
$data = [
|
||||
'verify_result' => $verify_result,
|
||||
];
|
||||
return ['code' => 200, 'msg' => '获取验证信息成功', 'data' => $data];
|
||||
}
|
||||
//人脸识别成功回调
|
||||
public function call_back($uid, $card_id, $real_name)
|
||||
{
|
||||
$time = strtotime(date('Ymd'));
|
||||
$insert_data = ['uid' => $uid, 'verify_time' => $time, 'add_time' => time(), 'card_id' => $card_id, 'real_name' => $real_name];
|
||||
$res = Db::name('face_verify_callback')->insert($insert_data);
|
||||
if($res) {
|
||||
return ['code' => 200, 'msg' => '提交成功', 'data' => null];
|
||||
}
|
||||
return ['code' => 201, 'msg' => '提交失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
108
application/api/model/Game.php
Normal file
108
application/api/model/Game.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Game extends Model
|
||||
{
|
||||
//获取游戏列表
|
||||
public function get_game_list($uid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$room_type_log_list = db::name('game_click_log')->field('count(1) as count,gid')->group('gid')->limit(50)->order('id desc')->select();
|
||||
$room_type_log_data = [];
|
||||
foreach ($room_type_log_list as $k => $v) {
|
||||
$room_type_log_data[$v['gid']] = $v['count'];
|
||||
}
|
||||
|
||||
|
||||
$map = [];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = db::name('game')->field('gid,game_name,game_ico,game_ico1,sort')->where($map)->order('sort desc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['game_ico'] = localpath_to_netpath($v['game_ico']);
|
||||
$v['game_ico1'] = localpath_to_netpath($v['game_ico1']);
|
||||
$v['click_num'] = 0;
|
||||
if (!empty($room_type_log_data[$v['gid']])) {
|
||||
$v['click_num'] = $room_type_log_data[$v['gid']];
|
||||
}
|
||||
}
|
||||
if (!empty($room_type_log_data)) {
|
||||
array_multisort(array_column($list, 'click_num'), SORT_DESC, $list);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
public function add_game_click_log($uid, $gid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$info = db::name('game')->field('gid,game_name,cover_image,skill_image,game_ico,sort')->cache(10)->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
//记录用户访问日志
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['gid'] = $gid;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
db::name('game_click_log')->insert($data);
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}
|
||||
//获取游戏详情
|
||||
public function get_game_info($gid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$info = db::name('game')->field('gid,game_name,cover_image,skill_image,game_ico,sort')->cache(10)->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
$info['game_ico'] = localpath_to_netpath($info['game_ico']);
|
||||
$info['cover_image'] = localpath_to_netpath($info['cover_image']);
|
||||
$info['skill_image'] = localpath_to_netpath($info['skill_image']);
|
||||
$skill_level_list = $this->get_game_skill_level_list($gid);
|
||||
$info['skill_level_list'] = $skill_level_list['data'];
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $info];
|
||||
}
|
||||
}
|
||||
public function get_game_skill_level_list($gid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = db::name('game_skill_level')->field('lid,gid,game_level_name')->where($map)->order('lid asc')->select();
|
||||
if (empty($list)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
}
|
||||
public function get_game_skill_level_info($gid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$info = db::name('game_skill_level')->field('gid,game_level_name')->where($map)->order('lid asc')->select();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $info];
|
||||
}
|
||||
}
|
||||
}
|
||||
2825
application/api/model/Gift.php
Normal file
2825
application/api/model/Gift.php
Normal file
File diff suppressed because it is too large
Load Diff
899
application/api/model/GiftBlind.php
Normal file
899
application/api/model/GiftBlind.php
Normal file
@@ -0,0 +1,899 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Log;
|
||||
class GiftBlind extends Model
|
||||
{
|
||||
private function file_unlock($fh) {
|
||||
flock($fh, LOCK_UN);
|
||||
fclose($fh);
|
||||
}
|
||||
//盲盒礼物
|
||||
public function open_blind_box_to_multi($uid, $rid, $type, $open_num, $recived_uid, $is_on_micro = 1)
|
||||
{
|
||||
// dump($open_num);die;
|
||||
if($open_num > 10) {
|
||||
return ['code' => 201, 'msg' => '全麦盲盒赠送不能超过10个', 'data' => null];
|
||||
}
|
||||
|
||||
if (ceil($open_num) != $open_num) {
|
||||
return ['code' => 201, 'msg' => '开奖次数参数非法', 'data' => null];
|
||||
}
|
||||
$config = get_system_config();
|
||||
$map = [];
|
||||
$map['rid'] = $rid;
|
||||
$map['is_delete'] = 1;
|
||||
$room_info = db::name('room')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
//房主id
|
||||
$room_owner_uid = $room_info['room_owner_uid'];
|
||||
$room_owner_info = db::name('user')->where('uid', $room_info['room_owner_uid'])->find();
|
||||
|
||||
//该房间是否加入公会
|
||||
|
||||
$guild_id = 0;
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $room_info['room_owner_uid']];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$guild_info = db::name('user_guild')->where($map)->find();
|
||||
if($guild_info){
|
||||
$guild_id = $guild_info['guild_id'];
|
||||
}
|
||||
|
||||
if(count($recived_uid) > 1){
|
||||
// return ['code' => 201, 'msg' => '打赏礼物对象不能为多个', 'data' => null];
|
||||
}
|
||||
$recived_uid_arr = $recived_uid;
|
||||
|
||||
if(in_array($uid, $recived_uid_arr)) {
|
||||
// return ['code' => 201, 'msg' => '不能给自己打赏', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', $recived_uid_arr];
|
||||
$recived_user_info = db::name('user')->field('uid,is_tester,money,integral,nick_name,base64_nick_name,head_pic')
|
||||
->where($map)->select();
|
||||
if (empty($recived_user_info)) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物对象不能为空', 'data' => null];
|
||||
}
|
||||
if(count($recived_uid_arr) != count($recived_user_info)) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物对象不能为空', 'data' => null];
|
||||
}
|
||||
$received_num = count($recived_uid_arr);
|
||||
// dump($recived_uid);exit;
|
||||
$redis = connectionRedis();
|
||||
$user_gift_id_list = []; //用户抽中礼物id集合
|
||||
$user_gift_id_redis_list = []; //用户抽中redis礼物id集合
|
||||
$user_win_gift_data = []; //抽中礼物列表
|
||||
$box_log_data = []; //抽中礼物期数数据
|
||||
$box_type_data = []; //宝箱类型配置信息
|
||||
$user_pay_amount = 0; //用户支付总额
|
||||
$user_win_gift_total_value = 0; //抽中礼物总价值
|
||||
$surplus_user_money = 0; //用户剩余资金
|
||||
$now_time = time();
|
||||
$tid = '';
|
||||
|
||||
$user_info = db::name('user')->find($uid); //获取用户信息
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '用户信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//用户消费所对应的宝箱类型
|
||||
if ($type == 32) {//琉璃魔盒
|
||||
$tid = 101;
|
||||
// $gift_level_type = db::name('gift')->where('gid',31)->value('level_type');
|
||||
} else if($type == 33) {//琥珀魔盒
|
||||
$tid = 102;
|
||||
// $gift_level_type = db::name('gift')->where('gid',32)->value('level_type');
|
||||
} else if($type == 34) {//钻石魔盒
|
||||
$tid = 103;
|
||||
// $gift_level_type = db::name('gift')->where('gid',33)->value('level_type');
|
||||
}
|
||||
|
||||
//判断是否是虚拟用户
|
||||
if($user_info['is_tester']==2){
|
||||
return ['code' => 201, 'msg' => '虚拟用户无法购买', 'data' => null];
|
||||
}
|
||||
// dump($tid);exit;
|
||||
//该奖池是否配置礼物
|
||||
$map = [];
|
||||
$map[] = ['tid', '=', $tid];
|
||||
$is_box_config = db('box_config')->where($map)->select();
|
||||
// dump($is_box_config);die;
|
||||
if(!$is_box_config){
|
||||
return ['code' => 201, 'msg' => '盲盒数量不足', 'data' => null];
|
||||
}
|
||||
|
||||
//获取宝箱类型配置信息
|
||||
$box_type_list = db::name('box_type')->field('tid,open_price,open_status,show_name')->cache(10)->select();
|
||||
foreach ($box_type_list as $k => &$v) {
|
||||
$box_type_data[$v['tid']] = $v;
|
||||
}
|
||||
if (empty($box_type_data[$tid])) {
|
||||
return ['code' => 201, 'msg' => '开奖类型非法参数', 'data' => null];
|
||||
}
|
||||
if ($box_type_data[$tid]['open_status'] != 1) {
|
||||
return ['code' => 201, 'msg' => '该开奖类型暂时已关闭', 'data' => null];
|
||||
}
|
||||
$unique_key = $tid;
|
||||
$path = './lock/lock_blind_box' . $unique_key . '.txt';
|
||||
$fh = fopen($path, 'w');
|
||||
flock($fh, LOCK_EX);
|
||||
$need_open_num = $open_num * $received_num;
|
||||
$user_pay_amount = $need_open_num * $box_type_data[$tid]['open_price'];
|
||||
$keyname = "box:list:tid:".$tid;
|
||||
$len = $redis->llen($keyname);
|
||||
if ($keyname == "box:list:tid:") {
|
||||
return ['code' => 201, 'msg' => '开奖类型非法参数', 'data' => null];
|
||||
}
|
||||
if($len < $need_open_num) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
//补礼物用户id
|
||||
$give_user_id_arr = [];
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
//获取用户必中信息 (每次补发一个)
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['tid', '=', $tid];
|
||||
$map[] = ['give_status', '=', 1];
|
||||
$box_give_gift_info = db::name('box_give_gift')->where($map)->order('id','asc')->find();
|
||||
if($box_give_gift_info) {
|
||||
$key = mt_rand(0, (count($recived_uid_arr) - 1));
|
||||
$data = [
|
||||
'uid' => $recived_uid_arr[$key],
|
||||
'bl_id' => 0,
|
||||
'gid' => $val['gid'],
|
||||
];
|
||||
$user_gift_id_list[] = $data;
|
||||
$give_user_id_arr[$val['id']] = $data['uid'];
|
||||
}
|
||||
|
||||
$give_user_id_arrs = $give_user_id_arr;
|
||||
//补发礼物领取id
|
||||
$give_box_gift_id = [];
|
||||
//获取待核销必中礼物数据
|
||||
$map = [];
|
||||
$map[] = ['tid', '=', $tid];
|
||||
$map[] = ['give_status', '=', 2];
|
||||
$map[] = ['deduction_status', '=', 1];
|
||||
$box_un_deduction_give_gift_list = db::name('box_give_gift')->where($map)->order('id desc')->column('id', 'gid'); //每种礼物只核销第一个
|
||||
//待核销数据id
|
||||
$un_deduction_give_gift_id = [];
|
||||
//更新开奖记录条件
|
||||
$update_user_box_log = [];
|
||||
|
||||
for($i = 0; $i < $open_num; $i++) {
|
||||
foreach($recived_uid_arr as $val) {
|
||||
if(in_array($val, $give_user_id_arrs)) {
|
||||
$keys = array_search($val, $give_user_id_arrs);
|
||||
$give_box_gift_id[] = $keys;
|
||||
unset($give_user_id_arrs[$keys]);
|
||||
} else {
|
||||
$gift_data = $redis->blpop($keyname, 2); //1s 超时
|
||||
if (empty($gift_data)) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '', 'data' => null];
|
||||
} else {
|
||||
//获取是否有待核销必中
|
||||
$gift_data_data = explode('-', $gift_data[1]);
|
||||
$bl_id = $gift_data_data[0];
|
||||
$gid = $gift_data_data[1];
|
||||
if (!empty($box_un_deduction_give_gift_list[$gid])) {
|
||||
$id = $box_un_deduction_give_gift_list[$gid];
|
||||
unset($box_un_deduction_give_gift_list[$gid]);
|
||||
$un_deduction_give_gift_id[] = $id;
|
||||
$data = [];
|
||||
$data['bl_id'] = $bl_id;
|
||||
$data['gid'] = $gid;
|
||||
$data['uid'] = $val;
|
||||
$user_gift_id_redis_list[] = $data;
|
||||
|
||||
|
||||
//开宝箱记录表更新
|
||||
$update_user_box_log_item = [];
|
||||
$map = [];
|
||||
$map[] = ['tid', '=', $tid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$map[] = ['num', '=', 1];
|
||||
$map[] = ['bl_id', '=', 0];
|
||||
$update_user_box_log_item['map'] = $map;
|
||||
$data = [];
|
||||
$data['bl_id'] = $bl_id;
|
||||
$data['update_time'] = time();
|
||||
$update_user_box_log_item['data'] = $data;
|
||||
$update_user_box_log[] = $update_user_box_log_item;
|
||||
//重新从队列获取一个礼物信息
|
||||
$gift_data = $redis->blpop($keyname, 2); //1s 超时
|
||||
if (empty($gift_data)) {
|
||||
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '盲盒数量不足', 'data' => null];
|
||||
}
|
||||
|
||||
$gift_data_data = explode('-', $gift_data[1]);
|
||||
$bl_id = $gift_data_data[0];
|
||||
$gid = $gift_data_data[1];
|
||||
}
|
||||
$data = [];
|
||||
$data['bl_id'] = $bl_id;
|
||||
$data['gid'] = $gid;
|
||||
$data['uid'] = $val;
|
||||
|
||||
$user_gift_id_redis_list[] = $data;
|
||||
$user_gift_id_list[] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($user_gift_id_list) != (count($recived_uid_arr) * $open_num)) {
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '盲盒数量不足', 'data' => null];
|
||||
}
|
||||
//取出所有礼物数据
|
||||
$gift_list = db::name('gift')->field('gid,gift_name,gift_price,base_image,play_image,gift_type,is_special')->cache(10)->select();
|
||||
$gift_list_data = [];
|
||||
foreach ($gift_list as $k => &$v) {
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
$gift_list_data[$v['gid']] = $v;
|
||||
}
|
||||
|
||||
//获取宝箱礼物配置信息
|
||||
$box_config_list = db::name('box_config')->field('gid,tid,is_public_screen,is_public_server')->cache(10)->select();
|
||||
$box_config_list_data = [];
|
||||
|
||||
foreach ($box_config_list as $k => $v) {
|
||||
$box_config_list_data[$v['gid']][$v['tid']] = $v;
|
||||
}
|
||||
|
||||
//用户获取礼物价值
|
||||
$user_win_gift_price_by_uid = [];
|
||||
//整理用户抽中礼物数量
|
||||
foreach ($user_gift_id_list as $k => $v) {
|
||||
if (empty($gift_list_data[$v['gid']])) {
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '礼物信息不存在', 'data' => null];
|
||||
}
|
||||
if (empty($box_config_list_data[$v['gid']])) {
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '宝箱礼物信息不存在', 'data' => null];
|
||||
}
|
||||
if (empty($user_win_gift_data[$v['gid']])) {
|
||||
$user_win_gift_data[$v['gid']] = $gift_list_data[$v['gid']];
|
||||
$user_win_gift_data[$v['gid']]['open_num'] = 1;
|
||||
} else {
|
||||
$user_win_gift_data[$v['gid']]['open_num']++;
|
||||
}
|
||||
$user_win_gift_data[$v['gid']]['bl_id'] = $v['bl_id'];
|
||||
$user_win_gift_data[$v['gid']]['is_public_screen'] = $box_config_list_data[$v['gid']][$tid]['is_public_screen'];
|
||||
$user_win_gift_data[$v['gid']]['is_public_server'] = $box_config_list_data[$v['gid']][$tid]['is_public_server'];
|
||||
|
||||
if (empty($box_log_data[$v['bl_id']])) {
|
||||
$box_log_data[$v['bl_id']]['open_num'] = 1;
|
||||
$box_log_data[$v['bl_id']]['open_gift_value'] = $gift_list_data[$v['gid']]['gift_price'];
|
||||
} else {
|
||||
$box_log_data[$v['bl_id']]['open_num']++;
|
||||
$box_log_data[$v['bl_id']]['open_gift_value'] += $gift_list_data[$v['gid']]['gift_price'];
|
||||
}
|
||||
$user_win_gift_total_value += $gift_list_data[$v['gid']]['gift_price'];
|
||||
$unique_key = $v['uid'] . '_' . $v['gid'];
|
||||
|
||||
if(!isset($user_win_gift_price_by_uid[$unique_key]['num'])) {
|
||||
$user_win_gift_price_by_uid[$unique_key]['num'] = 1;
|
||||
$user_win_gift_price_by_uid[$unique_key]['gift_price'] = $gift_list_data[$v['gid']]['gift_price'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['uid'] = $v['uid'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['gid'] = $v['gid'];
|
||||
// $user_win_gift_price_by_uid[$unique_key]['is_special'] = $gift_list_data[$v['gid']]['is_special'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['gift_name'] = $gift_list_data[$v['gid']]['gift_name'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['base_image'] = $gift_list_data[$v['gid']]['base_image'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['play_image'] = $gift_list_data[$v['gid']]['play_image'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['gift_type'] = $gift_list_data[$v['gid']]['gift_type'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['is_public_screen'] = $box_config_list_data[$v['gid']][$tid]['is_public_screen'];
|
||||
$user_win_gift_price_by_uid[$unique_key]['is_public_server'] = $box_config_list_data[$v['gid']][$tid]['is_public_server'];
|
||||
} else {
|
||||
$user_win_gift_price_by_uid[$unique_key]['num']++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($user_info['is_tester'] == 1){
|
||||
//扣除账户积分
|
||||
$reslut = model('admin/User')->change_user_money_by_user_info($user_info, -$user_pay_amount, 2, 16, "开盲盒送礼物", $user_info['uid'], 0);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$surplus_user_money = $user_info['integral'] - $user_pay_amount;
|
||||
|
||||
}
|
||||
|
||||
foreach ($box_log_data as $k => $v) {
|
||||
if ($k != 0) {
|
||||
$map = [];
|
||||
$map[] = ['bl_id', '=', $k];
|
||||
$reslut = db::name('box_log')->where($map)->inc('open_num', $v['open_num'])->inc('open_gift_value', $v['open_gift_value'])->update();
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//用户必中礼物状态更新
|
||||
if (!empty($box_give_gift_info)) {
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $box_give_gift_info['id']];
|
||||
$data = [];
|
||||
$data['give_time'] = $now_time;
|
||||
$data['give_status'] = 2;
|
||||
$data['update_time'] = $now_time;
|
||||
$reslut = db::name('box_give_gift')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//添加用户开宝箱日志 可能存在2期奖情况 特殊处理
|
||||
$user_box_data_by_bl_id = [];
|
||||
foreach ($user_gift_id_list as $k => $v) {
|
||||
if (empty($user_box_data_by_bl_id[$v['bl_id']][$v['gid']])) {
|
||||
$user_box_data_by_bl_id[$v['bl_id']][$v['gid']]['bl_id'] = $v['bl_id'];
|
||||
$user_box_data_by_bl_id[$v['bl_id']][$v['gid']]['gid'] = $v['gid'];
|
||||
$user_box_data_by_bl_id[$v['bl_id']][$v['gid']]['open_num'] = 1;
|
||||
} else {
|
||||
$user_box_data_by_bl_id[$v['bl_id']][$v['gid']]['open_num']++;
|
||||
}
|
||||
}
|
||||
foreach ($user_box_data_by_bl_id as $k => $v) {
|
||||
$insert_user_box_data = [];
|
||||
foreach ($v as $m => $n) {
|
||||
$gift_info = $gift_list_data[$n['gid']];
|
||||
$data = [];
|
||||
$data['uid'] = $user_info['uid'];
|
||||
$data['rid'] = $rid;
|
||||
$data['tid'] = $tid;
|
||||
$data['bl_id'] = $n['bl_id'];
|
||||
$data['gid'] = $n['gid'];
|
||||
$data['num'] = $n['open_num'];
|
||||
$data['gift_price'] = $gift_info['gift_price'];
|
||||
$data['total_price'] = $n['open_num'] * $gift_info['gift_price'];
|
||||
$data['total_open_num'] = $open_num;
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
// $data['last_login_device'] = $user_info['last_login_device'];
|
||||
$insert_user_box_data[] = $data;
|
||||
}
|
||||
$reslut = db::name('user_box_log')->insertAll($insert_user_box_data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//添加用户开宝箱统计数据
|
||||
$time = strtotime(date("Y-m-d"));
|
||||
$box_type = 0;
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $user_info['uid']];
|
||||
$map[] = ['box_type', '=', $tid];
|
||||
$box_type = $tid;
|
||||
$map[] = ['add_time', '>', $time];
|
||||
$user_box_count_info = db::name('user_box_count')->where($map)->find();
|
||||
|
||||
if (!empty($user_box_count_info)) {
|
||||
$rate = 0; //支收比
|
||||
$rate = round(($user_win_gift_total_value + $user_box_count_info['in_amount']) / ($user_box_count_info['out_amount'] + $user_pay_amount), 4);
|
||||
$map = [];
|
||||
$map[] = ['sid', '=', $user_box_count_info['sid']];
|
||||
// $map[] = ['uid', '=', $user_info['uid']];
|
||||
// $map[] = ['box_type', '=', $box_type];
|
||||
$data = [];
|
||||
$data['rate'] = $rate;
|
||||
$data['update_time'] = $now_time;
|
||||
$profit = $user_win_gift_total_value - $user_pay_amount;
|
||||
$reslut = db::name('user_box_count')->where($map)->inc('out_amount', $user_pay_amount)->inc('in_amount', $user_win_gift_total_value)->inc('profit', $profit)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
$rate = round($user_win_gift_total_value / $user_pay_amount, 4);
|
||||
$profit = $user_win_gift_total_value - $user_pay_amount;
|
||||
$data = [];
|
||||
$data['uid'] = $user_info['uid'];
|
||||
$data['out_amount'] = $user_pay_amount;
|
||||
$data['in_amount'] = $user_win_gift_total_value;
|
||||
$data['profit'] = $profit;
|
||||
$data['rate'] = $rate;
|
||||
$data['box_type'] = $box_type;
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
|
||||
$reslut = db::name('user_box_count')->insert($data);
|
||||
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
//礼物放入背包
|
||||
$insert_user_gift_pack_log_data = [];
|
||||
foreach ($user_win_gift_data as $k => $v) {
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $user_info['uid']];
|
||||
$map[] = ['gid', '=', $v['gid']];
|
||||
$data = [];
|
||||
$data['gid'] = $v['gid'];
|
||||
$data['update_time'] = $now_time;
|
||||
$reslut = db::name('user_gift_pack')->where($map)->inc('num', $v['open_num'])->inc('total_num', $v['open_num'])->update($data);
|
||||
if (!$reslut) {
|
||||
$data = [];
|
||||
$data['uid'] = $user_info['uid'];
|
||||
$data['gid'] = $v['gid'];
|
||||
$data['total_num'] = $v['open_num'];
|
||||
$data['num'] = $v['open_num'];
|
||||
$data['is_tester'] = $user_info['is_tester'];
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
$reslut = db::name('user_gift_pack')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $user_info['uid'];
|
||||
$data['type'] = 2;
|
||||
$data['bl_id'] = $v['bl_id'];
|
||||
$data['gid'] = $v['gid'];
|
||||
$data['gift_price'] = $gift_list_data[$v['gid']]['gift_price'];
|
||||
$data['change_num'] = $v['open_num'];
|
||||
$data['total_gift_price'] = $gift_list_data[$v['gid']]['gift_price'] * $v['open_num'];
|
||||
$data['after_num'] = 0;
|
||||
$data['is_tester'] = $user_info['is_tester'];
|
||||
$data['remarks'] = "开盲盒获得";
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
$insert_user_gift_pack_log_data[] = $data;
|
||||
}
|
||||
|
||||
if (!empty($insert_user_gift_pack_log_data)) {
|
||||
$reslut = db::name('user_gift_pack_log')->insertAll($insert_user_gift_pack_log_data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
// dump($user_win_gift_data);exit;
|
||||
|
||||
//礼物信息 $user_win_gift_data 扣除背包礼物
|
||||
$gift_total_price = 0;
|
||||
foreach($user_win_gift_data as $a => $b){
|
||||
//扣除背包礼物
|
||||
$reslut = model('UserGiftPack')->change_user_gift_pack($uid, $b['gid'], -$b['open_num'], 3, '开盲盒,背包打赏礼物');
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$gift_total_price += $b['open_num'] * $b['gift_price'];
|
||||
}
|
||||
|
||||
//赠送礼物增加财富值 贡献值
|
||||
$reslut = model('User')->change_user_contribution_value($uid, $gift_total_price);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试1', 'data' => null];
|
||||
}
|
||||
//赠送者增加房间魅力值
|
||||
$reslut = model('User')->change_user_room_contribution_value($uid, $rid, $gift_total_price);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
|
||||
//增加房间热度值
|
||||
$when = [];
|
||||
$when[] = ['rid', '=', $rid];
|
||||
db::name('room')->where($when)->setInc('hot_value', $gift_total_price);
|
||||
// db::name('room')->where($when)->setInc('today_hot_value', $gift_total_price);
|
||||
|
||||
|
||||
|
||||
//礼物是否参加PK计算
|
||||
//判断该礼物是否参加PK
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_close', '=', 1];
|
||||
$map[] = ['over_time', '>', time()];
|
||||
$room_pk_info = db::name('room_pk')->where($map)->find();
|
||||
$total_total_gift_price = 0;
|
||||
foreach ($user_win_gift_price_by_uid as $k => $v) {
|
||||
$this_gift_total_price = $v['gift_price'] * $v['num'];
|
||||
$total_total_gift_price += $this_gift_total_price;
|
||||
$this_room_owner_profit = $this_gift_total_price * $room_owner_info['room_owner_commission']; //房主厅主收益
|
||||
$this_receiver_profit = $this_gift_total_price * 0.7;//接收人收益
|
||||
$this_platform_profit = $this_gift_total_price - $this_room_owner_profit - $this_receiver_profit;//平台收益
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['rid'] = $rid;
|
||||
$data['guild_id'] = $guild_id;
|
||||
$data['room_uid'] = $room_info['room_owner_uid'];
|
||||
$data['receive_uid'] = $v['uid'];
|
||||
$data['gid'] = $v['gid'];
|
||||
$data['gift_name'] = $v['gift_name'];
|
||||
$data['gift_price'] = $v['gift_price'];
|
||||
$data['gift_num'] = $v['num'];
|
||||
$data['gift_total_price'] = $this_gift_total_price;
|
||||
$data['platform_profit'] = $this_platform_profit;
|
||||
$data['receiver_profit'] = $this_receiver_profit;
|
||||
$data['room_owner_profit'] = $this_room_owner_profit;
|
||||
$data['gift_from_type'] = 2; //背包
|
||||
$data['is_tester'] = $user_info['is_tester'];
|
||||
// $data['micro_id'] = $micro_id;
|
||||
// $data['room_user_profit'] = $room_user_profit;
|
||||
$data['gift_level_type'] = 0;
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
// $data['room_type_tid'] = $room_type_tid;
|
||||
$sid = db::name('user_send_gift')->insertGetId($data);
|
||||
if (empty($sid)) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => "请重试3", 'data' => null];
|
||||
}
|
||||
//增加厅主收益记录
|
||||
if ($this_room_owner_profit > 0) {
|
||||
// $change_value = $this_room_owner_profit / $config['exchange_rate'];
|
||||
$change_value = $this_room_owner_profit;
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_info['room_owner_uid'], $change_value, 1, 7, "打赏厅主流水收益", $uid, $sid, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
//增加用户厅主收益统计
|
||||
$reslut = model('User')->change_user_room_profit($room_info['room_owner_uid'],$rid, $change_value);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
//礼物接收者收益
|
||||
if ($this_receiver_profit > 0) {
|
||||
// $change_value = $this_receiver_profit / $config['exchange_rate'];
|
||||
$change_value = $this_receiver_profit;
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($v['uid'], $change_value, 1, 6, "礼物收入", $uid, $sid, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
// if($uid == $room_owner_uid && $v['uid'] == $room_owner_uid) {
|
||||
// //增加厅主收益记录
|
||||
// if ($this_room_owner_profit > 0) {
|
||||
// // $change_value = $room_owner_profit / $config['exchange_rate'];
|
||||
// $change_value = round($this_room_owner_profit, 2);
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($room_info['room_owner_uid'], $change_value, 2, 41, "自刷礼物获得钻石(房主)", $uid, $sid, $rid);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
// //增加用户厅主收益统计
|
||||
// $reslut = model('User')->change_user_room_profit_integral($room_info['room_owner_uid'],$rid, $change_value);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// //增加厅主收益记录
|
||||
// if ($this_room_owner_profit > 0) {
|
||||
// $change_value = $this_room_owner_profit / $config['exchange_rate'];
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($room_info['room_owner_uid'], $change_value, 1, 7, "打赏厅主流水收益", $uid, $sid, $rid);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
// //增加用户厅主收益统计
|
||||
// $reslut = model('User')->change_user_room_profit($room_info['room_owner_uid'],$rid, $change_value);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if($uid == $v['uid']) {
|
||||
// if ($this_receiver_profit > 0) {
|
||||
// // $change_value = $receiver_profit / $config['exchange_rate'];
|
||||
// $change_value = round($this_receiver_profit, 2);
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($v['uid'], $change_value, 2, 42, "自刷礼物获得钻石", $uid, $sid, $rid);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// //礼物接收者收益
|
||||
// if ($this_receiver_profit > 0) {
|
||||
// $change_value = $this_receiver_profit / $config['exchange_rate'];
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($v['uid'], $change_value, 1, 6, "礼物收入", $uid, $sid, $rid);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//收礼物增加魅力值
|
||||
$reslut = model('User')->change_user_charm_value($v['uid'], $this_gift_total_price);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
//接受者增加房间魅力值
|
||||
$reslut = model('User')->change_user_room_charm_value($v['uid'], $rid, $this_gift_total_price);
|
||||
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
//公会流水
|
||||
if($guild_id > 0 && $total_total_gift_price > 0) {
|
||||
$result = model('GuildWeekAmount')->add_data($guild_id, $total_total_gift_price, $room_info['room_owner_uid']);
|
||||
if($result['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试5', 'data' => null];
|
||||
}
|
||||
}
|
||||
// $user_list = [];
|
||||
$user_list = [];
|
||||
foreach($recived_user_info as $val) {
|
||||
$user_list[$val['uid']] = $val;
|
||||
}
|
||||
// dump($user_list);die;
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
$this->file_unlock($fh);
|
||||
if($is_on_micro == 1) {
|
||||
model('Room')->push_room_micro_data($rid); //推送最新房间麦位信息
|
||||
}
|
||||
//新增
|
||||
$charm_user_id = $recived_uid_arr;
|
||||
$charm_user_id[] = $uid;
|
||||
|
||||
//推送赠送礼物信息
|
||||
$room_push_data = [];
|
||||
$server_push_data = [];
|
||||
|
||||
// dump($user_list);die;
|
||||
$send_user_info = [
|
||||
'uid' => $uid,
|
||||
'nick_name' => mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8'),
|
||||
'head_pic' => localpath_to_netpath($user_info['head_pic']),
|
||||
];
|
||||
$box_name = db::name('box_type')->where('tid',$tid)->value('show_name');
|
||||
foreach($user_win_gift_price_by_uid as $key => $val) {
|
||||
$key_arr = explode('_', $key);
|
||||
|
||||
$ls_data = [];
|
||||
$ls_data['send_user_info'] = $send_user_info;
|
||||
$receive_uid = $key_arr[0];
|
||||
$box_gid = $key_arr[1];
|
||||
$ls_data['recived_user_info']['uid'] = $val['uid'];
|
||||
$ls_data['recived_user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_list[$val['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$ls_data['recived_user_info']['head_pic'] = localpath_to_netpath($user_list[$val['uid']]['head_pic']);
|
||||
|
||||
$ls_data['gift_name'] = $val['gift_name'];
|
||||
$ls_data['play_image'] = $val['play_image'];
|
||||
$ls_data['base_image'] = $val['base_image'];
|
||||
$ls_data['gift_type'] = $val['gift_type'];
|
||||
$ls_data['gift_price'] = $val['gift_price'];
|
||||
$ls_data['blind_box_image'] = localpath_to_netpath($val['base_image']);
|
||||
$ls_data['num'] = $val['num'];
|
||||
$ls_data['is_public_screen'] = $val['is_public_screen'];
|
||||
$ls_data['is_public_server'] = $val['is_public_server'];
|
||||
$ls_data['is_blind_box'] = 1;
|
||||
$ls_data['is_blind_gift'] = 1;
|
||||
$ls_data['blind_box_name'] = $box_name;
|
||||
$ls_data['is_special_gift'] = $val['is_special'];
|
||||
$ls_data['rid'] = 0;
|
||||
if($ls_data['is_special_gift'] == 1) {
|
||||
$ls_data['rid'] = $rid;
|
||||
}
|
||||
if ($ls_data['is_public_server'] == 1) {
|
||||
$server_push_data[] = $ls_data;
|
||||
}
|
||||
$room_push_data[] = $ls_data;
|
||||
|
||||
}
|
||||
|
||||
if (!empty($server_push_data)) {
|
||||
$pust_data = [];
|
||||
$pust_data['code'] = 306;
|
||||
$pust_data['msg'] = '打赏礼物';
|
||||
// $pust_data['data'] = $server_push_data;
|
||||
$pust_data['data']['room_info']['rid'] = $room_info['rid'];
|
||||
$pust_data['data']['room_info']['room_name'] = mb_convert_encoding(base64_decode($room_info['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$pust_data['data']['gift_list'] = $server_push_data;
|
||||
model('api/WebSocketPush')->send_to_all($pust_data);
|
||||
}
|
||||
if (!empty($room_push_data)) {
|
||||
$pust_data = [];
|
||||
$pust_data['code'] = 302;
|
||||
$pust_data['msg'] = '打赏礼物';
|
||||
$pust_data['data'] = $room_push_data;
|
||||
model('api/WebSocketPush')->send_to_group($room_info['rid'], $pust_data);
|
||||
}
|
||||
return ['code' => 200, 'msg' => "打赏成功", 'data' => $room_push_data];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $user_gift_id_redis_list);
|
||||
Db::rollback();
|
||||
$this->file_unlock($fh);
|
||||
dump($e);
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//返还用户抽中礼物到奖池
|
||||
private function redis_gift_data_rollback($redis, $keyname, $user_gift_id_list)
|
||||
{
|
||||
$insert_data = [];
|
||||
foreach ($user_gift_id_list as $k => $v) {
|
||||
$insert_data[] = $v['bl_id'] . '-' . $v['gid'];
|
||||
}
|
||||
if (!empty($insert_data)) {
|
||||
array_unshift($insert_data, $keyname);
|
||||
//右侧取 右侧插入
|
||||
call_user_func_array([$redis, 'lPush'], $insert_data);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '返还成功', 'data' => null];
|
||||
}
|
||||
|
||||
//喵咪盲盒礼物
|
||||
public function get_cate_blind_box_gift()
|
||||
{
|
||||
$gid_arr = [203, 204, 205];
|
||||
$gift_image_list = Db::name('gift')->whereIn('gid', $gid_arr)->column('base_image', 'gid');
|
||||
$box_open_price = Db::name('box_type')->whereIn('tid', [104, 105, 106])->column('open_price', 'tid');
|
||||
$blind_box_gift_list = Db::name('box_config')->alias('a')
|
||||
->join('yy_gift b', 'a.gid = b.gid')
|
||||
->field('a.tid,b.gift_name,b.base_image,b.gift_price')
|
||||
->where('a.tid', 'in', [104,105,106])
|
||||
->order('b.gift_price', 'asc')
|
||||
->select();
|
||||
// dump($blind_box_gift_list);die;
|
||||
$one_cate_blind_box_gift = $two_cate_blind_box_gift = $three_cate_blind_box_gift = [];
|
||||
foreach($blind_box_gift_list as $val){
|
||||
$temp = $val;
|
||||
$temp['base_image'] = localpath_to_netpath($val['base_image']);
|
||||
unset($temp['tid']);
|
||||
if($val['tid'] == 106) {
|
||||
$one_cate_blind_box_gift[] = $temp;
|
||||
}
|
||||
if($val['tid'] == 105) {
|
||||
$two_cate_blind_box_gift[] = $temp;
|
||||
}
|
||||
if($val['tid'] == 104) {
|
||||
$three_cate_blind_box_gift[] = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
$one_cate_blind_box = [
|
||||
'open_price' => $box_open_price[106],
|
||||
'base_image' => localpath_to_netpath($gift_image_list[205]),
|
||||
'max_gift' => $this->get_max_gift($one_cate_blind_box_gift),
|
||||
'gift_list' => $one_cate_blind_box_gift,
|
||||
|
||||
];
|
||||
$two_cate_blind_box = [
|
||||
'open_price' => $box_open_price[105],
|
||||
'base_image' => localpath_to_netpath($gift_image_list[204]),
|
||||
'max_gift' => $this->get_max_gift($two_cate_blind_box_gift),
|
||||
'gift_list' => $two_cate_blind_box_gift,
|
||||
|
||||
];
|
||||
$three_cate_blind_box = [
|
||||
'open_price' => $box_open_price[104],
|
||||
'base_image' => localpath_to_netpath($gift_image_list[203]),
|
||||
'max_gift' => $this->get_max_gift($three_cate_blind_box_gift),
|
||||
'gift_list' => $three_cate_blind_box_gift,
|
||||
|
||||
];
|
||||
$data = [
|
||||
'one_cate_blind_box' => $one_cate_blind_box,
|
||||
'two_cate_blind_box' => $two_cate_blind_box,
|
||||
'three_cate_blind_box' => $three_cate_blind_box,
|
||||
];
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//获取最大礼物信息
|
||||
private function get_max_gift($gift_list)
|
||||
{
|
||||
$big_gift_info = ['gift_name' => '', 'gift_price' => 0];
|
||||
if($gift_list) {
|
||||
$big_gift_info['gift_name'] = $gift_list[count($gift_list) -1]['gift_name'];
|
||||
$big_gift_info['gift_price'] = $gift_list[count($gift_list) -1]['gift_price'];
|
||||
}
|
||||
return $big_gift_info;
|
||||
}
|
||||
|
||||
//获取盲盒礼物
|
||||
public function get_cate_blind_box_gift_by_gid($gid)
|
||||
{
|
||||
$tid = 0;
|
||||
if($gid == 203) {
|
||||
$tid = 104;
|
||||
}elseif($gid == 204) {
|
||||
$tid = 105;
|
||||
}elseif($gid == 205) {
|
||||
$tid = 106;
|
||||
}
|
||||
$blind_box_gift_list = Db::name('box_config')->alias('a')
|
||||
->join('yy_gift b', 'a.gid = b.gid')
|
||||
->field('b.base_image')
|
||||
->where('a.tid', '=', $tid)
|
||||
->order('b.gift_price', 'asc')
|
||||
->select();
|
||||
foreach ($blind_box_gift_list as &$val){
|
||||
$val['base_image'] = localpath_to_netpath($val['base_image']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $blind_box_gift_list];
|
||||
}
|
||||
|
||||
}
|
||||
513
application/api/model/GiftMultiple.php
Normal file
513
application/api/model/GiftMultiple.php
Normal file
@@ -0,0 +1,513 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class GiftMultiple extends Model
|
||||
{
|
||||
|
||||
public function send_gift_multiple($uid, $to_uid_list, $rid, $gid, $num, $send_type, $help_uid)
|
||||
{
|
||||
$config = get_uncache_system_config();
|
||||
if($config['lucky_gift_earnings_rate'] > 1){
|
||||
$config['lucky_gift_earnings_rate'] = 0.05;
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$gift_info = db::name('gift')->where($map)->find();
|
||||
if (empty($gift_info)) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物信息不存在', 'data' => null];
|
||||
}
|
||||
$gift_info['play_image'] = localpath_to_netpath($gift_info['play_image']);
|
||||
$gift_info['base_image'] = localpath_to_netpath($gift_info['base_image']);
|
||||
if (ceil($num) != $num) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物数量必须为整数', 'data' => null];
|
||||
}
|
||||
if ($num < 1) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物数量必须大于零', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($gift_info['mid'])){
|
||||
return ['code' => 201, 'msg' => '该礼物尚未设置倍率', 'data' => null];
|
||||
}
|
||||
|
||||
$gift_multiple_type = db::name('gift_multiple_type')->where('id', $gift_info['mid'])->where('is_delete', 1)->find();
|
||||
if(!$gift_multiple_type){
|
||||
return ['code' => 201, 'msg' => '该礼物尚未设置倍率', 'data' => null];
|
||||
}
|
||||
|
||||
$gift_multiple_rate_list = db::name('gift_multiple_rate')->where('pid', $gift_info['mid'])->where('is_delete', 1)->select();
|
||||
if(empty($gift_multiple_rate_list)){
|
||||
return ['code' => 201, 'msg' => '该礼物尚未设置倍率', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_info = db::name('room')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '所处房间不存在', 'data' => null];
|
||||
}
|
||||
$room_owner_info = db::name('user')->where('uid', $room_info['room_owner_uid'])->find();
|
||||
|
||||
$to_uid_data = explode(',', $to_uid_list);
|
||||
$to_uid_data = array_values(array_unique($to_uid_data));
|
||||
if (in_array($uid, $to_uid_data)) {
|
||||
return ['code' => 201, 'msg' => '不能给自己打赏', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', $to_uid_data];
|
||||
$user_list = db::name('user')->field('uid,is_tester,money,integral,nick_name,base64_nick_name,head_pic,europe_key,airship')->where($map)->select();
|
||||
if (empty($user_list)) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物对象不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
if (count($to_uid_data) != count($user_list)) {
|
||||
return ['code' => 201, 'msg' => '打赏礼物对象不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$send_count = count($user_list); //赠送总人数
|
||||
$total_send_num = $num * $send_count; //赠送礼物总数量
|
||||
$total_send_amount = $gift_info['gift_price'] * $num * $send_count; //赠送礼物总价值
|
||||
|
||||
$now_time = time();
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
|
||||
if ($send_type == 1) { //直接购买
|
||||
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '青少年模式已开启', 'data' => null];
|
||||
}
|
||||
|
||||
//扣款时进行用户资金是否充足判断
|
||||
$user_auction_price = model('NewRoom')->get_user_auction_price($uid);
|
||||
if ($user_info['integral'] < ($total_send_amount + $user_auction_price)) {
|
||||
return ['code' => 201, 'msg' => '账户资金不足', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '参数非法', 'data' => null];
|
||||
}
|
||||
|
||||
// $redis = connectionRedis();
|
||||
// $user_gift_multiple_redis_list = [];
|
||||
// $keyname = "multiple:list:type:".$gift_info['mid'];
|
||||
|
||||
//当前主持比例
|
||||
$room_host_commission = 0;
|
||||
if($room_info['room_owner_uid'] != $room_info['room_host_uid']){
|
||||
$room_host_info = db::name('room_host')->where('rid', $rid)->where('uid', $room_info['room_host_uid'])->find();
|
||||
if(!empty($room_host_info)){
|
||||
$room_host_commission = $room_host_info['ratio'];
|
||||
}
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($user_info['is_tester'] == 1) { //测试用户只推送赠送礼物信息
|
||||
if ($send_type == 1) { //直接购买
|
||||
//计算赠送礼物总资金
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$total_send_amount, 2, 29, "打赏幸运礼物", $uid, 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}else {
|
||||
return ['code' => 201, 'msg' => '参数非法', 'data' => null];
|
||||
}
|
||||
|
||||
//赠送礼物增加财富值 贡献值
|
||||
$reslut = model('User')->change_user_contribution_value($uid, $total_send_amount);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试1', 'data' => null];
|
||||
}
|
||||
//赠送者增加房间贡献值
|
||||
$reslut = model('User')->change_user_room_contribution_value($uid, $rid, $total_send_amount);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
}
|
||||
|
||||
//日贡献
|
||||
model('Statistics')->day_contribution($uid, $rid, $total_send_amount, 2);
|
||||
|
||||
//房间礼物墙
|
||||
$reslut = model('GiftWall')->room_gift_wall($rid, $gid, $total_send_num, $total_send_amount);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试5', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
db::name('room')->where('rid', $rid)->inc('hot_value', $total_send_amount)->inc('today_hot_value', $total_send_amount)->update();
|
||||
|
||||
//当前礼物倍率配置
|
||||
$gift_multiple_rate_data = '';
|
||||
$total_num = 0;
|
||||
$win_multiple_data = [];
|
||||
foreach ($gift_multiple_rate_list as $a => $b){
|
||||
$da = $b['id'].'-'.$b['multiple'].'-'.$b['rate_num'].';';
|
||||
$gift_multiple_rate_data .= $da;
|
||||
$total_num += $b['rate_num'];
|
||||
for($i = 0; $i < $b['rate_num']; $i++){
|
||||
$win_multiple_data[] = $b['id'];
|
||||
}
|
||||
}
|
||||
|
||||
shuffle($win_multiple_data);
|
||||
|
||||
// $room_guild_info = model('Guild')->user_guild_info($room_info['room_owner_uid']);
|
||||
$total_win_price = 0;
|
||||
$user_win_multiple = [];
|
||||
foreach ($user_list as $k => $v) {
|
||||
//该用户是否有公会及公会收益
|
||||
// $user_guild_info = model('Guild')->user_guild_info($v['uid']);
|
||||
$gift_total_price = $gift_info['gift_price'] * $num;
|
||||
|
||||
// $win_multiple_data = $redis->blpop($keyname, 2);
|
||||
// if(empty($win_multiple_data)){
|
||||
// return ['code' => 201, 'msg' => '', 'data' => null];
|
||||
// }else{
|
||||
// $win_multiple_data_data = explode('-', $win_multiple_data[1]);
|
||||
// $bl_id = $win_multiple_data_data[0];
|
||||
// $win_multiple = $win_multiple_data_data[1];
|
||||
|
||||
// $data = [];
|
||||
// $data['bl_id'] = $bl_id;
|
||||
// $data['multiple'] = $win_multiple;
|
||||
// $user_gift_multiple_redis_list[] = $data;
|
||||
// }
|
||||
|
||||
//增加当期开启数量
|
||||
// $reslut = db::name('gift_multiple_log')->where('bl_id', $bl_id)->inc('open_num', 1)->update();
|
||||
// if(!$reslut){
|
||||
// Db::rollback();
|
||||
// $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
// return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
// }
|
||||
|
||||
//多次数量累计倍率
|
||||
$win_multiple = 0;
|
||||
for($i = 1; $i <= $num; $i++){
|
||||
//随机抽取倍率id
|
||||
$win_key = array_rand($win_multiple_data);
|
||||
$win_gift_multiple_rate_id = $win_multiple_data[$win_key];
|
||||
$multiple = db::name('gift_multiple_rate')->where('id', $win_gift_multiple_rate_id)->value('multiple');
|
||||
$win_multiple += $multiple;
|
||||
}
|
||||
|
||||
//获取金币数
|
||||
// $win_price = $gift_total_price * $win_multiple;
|
||||
$win_price = $gift_info['gift_price'] * $win_multiple;
|
||||
$total_win_price += $win_price;
|
||||
// $room_owner_profits = $gift_total_price * $room_owner_info['room_owner_lucky_commission'];
|
||||
// $room_owner_profit = $room_owner_profits * (1 - $room_host_commission);
|
||||
// $room_host_profit = $room_owner_profits * $room_host_commission;
|
||||
if($room_info['is_earnings'] == 1){
|
||||
$room_owner_profits = $gift_total_price * 0.02;
|
||||
$room_owner_profit = $room_owner_profits * 1;
|
||||
$room_host_profit = $room_owner_profits * 0;
|
||||
}else{
|
||||
$room_owner_profits = 0;
|
||||
$room_owner_profit = 0;
|
||||
$room_host_profit = 0;
|
||||
}
|
||||
// $room_host_profit = $gift_total_price * 0.01;
|
||||
// $receiver_profit = $gift_total_price * $config['lucky_gift_earnings_rate'];
|
||||
$receiver_profit = $gift_total_price * 0.002;
|
||||
// $platform_profit = $gift_total_price - $room_owner_profit - $room_host_profit - $receiver_profit;
|
||||
$platform_profit = $gift_total_price - $room_owner_profits - $receiver_profit;
|
||||
$data = [];
|
||||
// $data['bl_id'] = $bl_id;
|
||||
$data['uid'] = $uid;
|
||||
$data['rid'] = $rid;
|
||||
// $data['guild_id'] = $user_guild_info['guild_id'];
|
||||
// $data['room_guild_id'] = $room_guild_info['guild_id'];
|
||||
$data['room_uid'] = $room_info['room_owner_uid'];
|
||||
$data['room_host_uid'] = $room_info['room_host_uid'];
|
||||
$data['receive_uid'] = $v['uid'];
|
||||
$data['gid'] = $gid;
|
||||
$data['gift_name'] = $gift_info['gift_name'];
|
||||
$data['gift_price'] = $gift_info['gift_price'];
|
||||
$data['gift_num'] = $num;
|
||||
$data['gift_total_price'] = $gift_total_price;
|
||||
$data['platform_profit'] = $platform_profit;
|
||||
$data['receiver_profit'] = $receiver_profit;
|
||||
$data['room_owner_profit'] = $room_owner_profit;
|
||||
$data['room_host_profit'] = $room_host_profit;
|
||||
$data['win_multiple'] = $win_multiple;
|
||||
$data['win_price'] = $win_price;
|
||||
// $data['config_text'] = $gift_multiple_rate_data;
|
||||
// $data['total_multiple_num'] = $total_num;
|
||||
$data['gift_from_type'] = $send_type;
|
||||
$data['is_tester'] = $user_info['is_tester'];
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
$sid = db::name('user_send_gift_rate')->insertGetId($data);
|
||||
if (empty($sid)) {
|
||||
Db::rollback();
|
||||
// $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
return ['code' => 201, 'msg' => "请重试3", 'data' => null];
|
||||
}
|
||||
|
||||
//发送数据开始
|
||||
$message_data_temp = [
|
||||
'from_uid' => $uid,
|
||||
'to_uid' => $v['uid'],
|
||||
'gift_name' => $gift_info['gift_name'],
|
||||
'gift_price' => $gift_info['gift_price'],
|
||||
'gift_num' => $num,
|
||||
'rid' => $rid,
|
||||
];
|
||||
$message_data[] = $message_data_temp;
|
||||
|
||||
//增加厅主收益记录
|
||||
if ($room_owner_profit > 0) {
|
||||
$change_value = $room_owner_profit / $config['exchange_rate'];
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_info['room_owner_uid'], $change_value, 1, 32, "打赏厅主流水收益", $uid, $sid, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
// $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
//收益记录
|
||||
model('Statistics')->day_room_profit($room_info['room_owner_uid'], $rid, $change_value, 1);
|
||||
}
|
||||
// if($room_host_profit > 0 && !empty($room_info['room_host_uid'])){
|
||||
if($room_host_profit > 0 && $room_info['room_host_uid'] > 0){
|
||||
$change_value = $room_host_profit / $config['exchange_rate'];
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_info['room_host_uid'], $change_value, 1, 33, "打赏主持流水收益", $uid, $sid, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
// $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
//收益记录
|
||||
model('Statistics')->day_room_profit($room_info['room_host_uid'], $rid, $change_value, 2);
|
||||
}
|
||||
|
||||
//礼物接收者收益
|
||||
if ($receiver_profit > 0) {
|
||||
$change_value = $receiver_profit / $config['exchange_rate'];
|
||||
$reslut = model('admin/User')->change_user_money_by_user_info($v, $change_value, 1, 31, "礼物收入", $uid, $sid, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
// $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//收礼物增加魅力值
|
||||
// $reslut = model('User')->change_user_charm_value($v['uid'], $gift_total_price);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// // $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
// return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
// }
|
||||
//接受者增加房间魅力值
|
||||
// $reslut = model('User')->change_user_room_charm_value($v['uid'], $rid, $gift_total_price,$uid);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// // $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
// return ['code' => 201, 'msg' => '请重试4', 'data' => null];
|
||||
// }
|
||||
|
||||
//日收益
|
||||
model('Statistics')->day_charm($v['uid'], $rid, $gift_total_price, 2);
|
||||
|
||||
//收礼物墙
|
||||
$reslut = model('GiftWall')->user_receive_gift_wall($v['uid'], $gid, $num, $uid);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
if($gift_total_price > 0){
|
||||
if($room_info['cate_id'] == 29){
|
||||
$reslut = model('DatingRoom')->user_send_gift_heartbeat_line($uid, $v['uid'], $rid, $gift_total_price, $help_uid);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试7', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if($room_info['cate_id'] == 28 && $uid != $v['uid']){
|
||||
$reslut = model('AuctionRoom')->record_user_auction_info($uid, $v['uid'], $rid, $gid, $gift_info['gift_price'], $num, $room_info['room_host_uid']);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试7', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if($room_info['cate_id'] == 27){
|
||||
$reslut = model('KtvRoom')->send_gift_add_song_time($uid, $v['uid'], $rid, $gid, $num, $gift_total_price);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试7', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($win_multiple > 0){
|
||||
$to_uid_win_multiple = [];
|
||||
$to_uid_win_multiple['recived_uid'] = $v['uid'];
|
||||
$to_uid_win_multiple['head_pic'] = $v['head_pic'];
|
||||
$to_uid_win_multiple['base64_nick_name'] = $v['base64_nick_name'];
|
||||
$to_uid_win_multiple['win_multiple'] = $win_multiple;
|
||||
$user_win_multiple[] = $to_uid_win_multiple;
|
||||
}
|
||||
|
||||
$user_list[$k]['win_multiple'] = $win_multiple;
|
||||
}
|
||||
|
||||
//计算返币资金
|
||||
if($total_win_price > 0){
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, $total_win_price, 2, 30, "幸运礼物爆币获取", $uid, 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
// $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//更新房间在线用户财富值
|
||||
if(in_array($room_info['cate_id'], [27,28])){
|
||||
$reslut = model('RoomBossMicro')->update_room_visitor_value($uid, $rid, $total_send_amount);
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//发送开始
|
||||
// if($message_data) {
|
||||
// model('api/AsyncPushMessage')->store_message($message_data, 2);
|
||||
// }
|
||||
|
||||
} else{
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('Room')->push_room_micro_data($rid); //推送最新房间麦位信息
|
||||
// $user_decorate_info = model('api/room')->get_room_user_vip($uid, 0);
|
||||
// $push_room_pendant_data = [];
|
||||
// $push_is_open = '';
|
||||
|
||||
$room_push_data = [];
|
||||
$server_push_data = [];
|
||||
$gift_list = [];
|
||||
$gift_list[] = $gift_info;
|
||||
foreach ($user_list as $k => $v) {
|
||||
foreach ($gift_list as $m => $n) {
|
||||
$ls_data = [];
|
||||
$ls_data['rid'] = $rid;
|
||||
$ls_data['send_user_info']['uid'] = $uid;
|
||||
$ls_data['send_user_info']['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$ls_data['send_user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$ls_data['recived_user_info']['uid'] = $v['uid'];
|
||||
$ls_data['recived_user_info']['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$ls_data['recived_user_info']['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $ls_data['lwtp_base_image'] = $user_decorate_info['data']['lwtp_base_image'];
|
||||
$ls_data['gift_price'] = $n['gift_price'];
|
||||
$ls_data['gift_name'] = $n['gift_name'];
|
||||
$ls_data['play_image'] = $n['play_image'];
|
||||
$ls_data['base_image'] = $n['base_image'];
|
||||
$ls_data['is_multiple_gift'] = 1;
|
||||
$ls_data['num'] = $num;
|
||||
$ls_data['win_multiple'] = $v['win_multiple'];
|
||||
$ls_data['is_public_screen'] = $n['is_public_screen'];
|
||||
$ls_data['is_public_server'] = $n['is_public_server'];
|
||||
if ($ls_data['is_public_server'] == 1) {
|
||||
$server_push_data[] = $ls_data;
|
||||
}
|
||||
$room_push_data[] = $ls_data;
|
||||
}
|
||||
}
|
||||
// if (!empty($server_push_data)) {
|
||||
// $pust_data = [];
|
||||
// $pust_data['code'] = 306;
|
||||
// $pust_data['msg'] = '打赏礼物';
|
||||
// // $pust_data['data'] = $server_push_data;
|
||||
// $pust_data['data']['room_info']['rid'] = $room_info['rid'];
|
||||
// $pust_data['data']['room_info']['room_name'] = mb_convert_encoding(base64_decode($room_info['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
// $pust_data['data']['gift_list'] = $server_push_data;
|
||||
// model('api/WebSocketPush')->send_to_all($pust_data);
|
||||
// }
|
||||
if (!empty($room_push_data)) {
|
||||
$pust_data = [];
|
||||
$pust_data['code'] = 302;
|
||||
$pust_data['msg'] = '打赏礼物';
|
||||
$pust_data['data'] = $room_push_data;
|
||||
model('api/WebSocketPush')->send_to_group($room_info['rid'], $pust_data);
|
||||
}
|
||||
if(!empty($user_win_multiple)){
|
||||
foreach ($user_win_multiple as $k => $v){
|
||||
// dump($v);
|
||||
$push_user_multiple = [];
|
||||
$push_user_multiple['send_user_info']['uid'] = $uid;
|
||||
$push_user_multiple['send_user_info']['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$push_user_multiple['send_user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_user_multiple['recived_user_info']['uid'] = $v['recived_uid'];
|
||||
$push_user_multiple['recived_user_info']['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$push_user_multiple['recived_user_info']['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_user_multiple['gift_name'] = $gift_info['gift_name'];
|
||||
$push_user_multiple['gift_price'] = $gift_info['gift_price'];
|
||||
$push_user_multiple['base_image'] = localpath_to_netpath($gift_info['base_image']);
|
||||
$push_user_multiple['num'] = $num;
|
||||
$push_user_multiple['win_multiple'] = $v['win_multiple'];
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 357;
|
||||
$push_data['msg'] = '爆币推送';
|
||||
$push_data['data'] = $push_user_multiple;
|
||||
$reslut = model('api/WebSocketPush')->send_to_group($room_info['rid'], $push_data);
|
||||
// dump($reslut);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['integral'] = db::name('user')->where('uid', $uid)->value('integral');
|
||||
$data['integral'] = (int)$data['integral'];
|
||||
$data['data'] = $room_push_data;
|
||||
return ['code' => 200, 'msg' => "打赏成功", 'data' => $data];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// $this->redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_redis_list);
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试5", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//返还用户抽中礼物到奖池
|
||||
private function redis_gift_multiple_data_rollback($redis, $keyname, $user_gift_multiple_list)
|
||||
{
|
||||
$insert_data = [];
|
||||
foreach ($user_gift_multiple_list as $k => $v) {
|
||||
$insert_data[] = $v['bl_id'] . '-' . $v['multiple'];
|
||||
}
|
||||
if (!empty($insert_data)) {
|
||||
array_unshift($insert_data, $keyname);
|
||||
//右侧取 右侧插入
|
||||
call_user_func_array([$redis, 'lPush'], $insert_data);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '返还成功', 'data' => null];
|
||||
}
|
||||
|
||||
public function txt(){
|
||||
$num = input('num', 0);
|
||||
for($i=1; $i <= $num; $i++){
|
||||
dump($i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
219
application/api/model/GiftWall.php
Normal file
219
application/api/model/GiftWall.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class GiftWall extends Model
|
||||
{
|
||||
|
||||
//礼物列表
|
||||
public function get_room_gift_list($uid, $type){
|
||||
$user_info = db::name('user')->field('uid, integral')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$user_pack_gift_total_price = 0;
|
||||
$map = [];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
if($type == 2){//背包
|
||||
$map = [];
|
||||
// $map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$gift_list = db::name('gift')->where($map)->field('gid, gift_type, gift_name, gift_price, base_image, play_image, is_public_server, is_public_screen,tag_name')->order('sort desc')->select();
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['num', '>', 0];
|
||||
$map[] = ['is_use_give', '=', 1];
|
||||
$user_pack_gift_list = db::name('user_gift_pack')->field('gid,num')->where($map)->select();
|
||||
$gift_data = [];
|
||||
foreach ($gift_list as $k => $v) {
|
||||
$v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$gift_data[$v['gid']] = $v;
|
||||
}
|
||||
|
||||
// $user_pack_gift_total_price = 0;
|
||||
foreach ($user_pack_gift_list as $m => &$n) {
|
||||
$n['gift_name'] = $gift_data[$n['gid']]['gift_name'];
|
||||
$n['play_image'] = $gift_data[$n['gid']]['play_image'];
|
||||
$n['base_image'] = $gift_data[$n['gid']]['base_image'];
|
||||
$n['gift_price'] = $gift_data[$n['gid']]['gift_price'];
|
||||
$user_pack_gift_total_price += $n['gift_price'] * $n['num'];
|
||||
}
|
||||
array_multisort(array_column($user_pack_gift_list, 'gift_price'), SORT_ASC, $user_pack_gift_list);
|
||||
|
||||
$gift_list = $user_pack_gift_list;
|
||||
} else{// 1普通 3新人 4幸运礼物 5盲盒 6爵位 7麦位 8挂件
|
||||
$map[] = ['type', '=', $type];
|
||||
$gift_list = db::name('gift')->where($map)->field('gid, gift_type, gift_name, gift_price, base_image, play_image, is_public_server, is_public_screen,tag_name,sort')->order(['sort'=>'desc','gift_price'=> 'asc'])->select();
|
||||
$gift_data = [];
|
||||
foreach ($gift_list as $k => $v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
|
||||
$gift_data[$v['gid']] = $v;
|
||||
}
|
||||
$gift_list = array_values($gift_data);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['gift_list'] = $gift_list;
|
||||
$data['integral'] = (int)$user_info['integral'];
|
||||
$data['user_pack_gift_price'] = $user_pack_gift_total_price;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//记录收礼物墙
|
||||
public function user_receive_gift_wall($uid, $gid, $num, $send_uid){
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['send_uid', '=', $send_uid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$user_receive_gift_wall = db::name('user_receive_gift_wall')->where($map)->find();
|
||||
if($user_receive_gift_wall){
|
||||
$reslut = db::name('user_receive_gift_wall')->where('id', $user_receive_gift_wall['id'])->inc('num', $num)->update(['update_time' => time()]);
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['send_uid'] = $send_uid;
|
||||
$insert['gid'] = $gid;
|
||||
$insert['num'] = $num;
|
||||
$insert['update_time'] = time();
|
||||
$reslut = db::name('user_receive_gift_wall')->insert($insert);
|
||||
}
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//记录送礼物墙
|
||||
public function user_send_gift_wall($uid, $gid, $num, $receive_uid){
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['receive_uid', '=', $receive_uid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$user_send_gift_wall = db::name('user_send_gift_wall')->where($map)->find();
|
||||
if($user_send_gift_wall){
|
||||
$reslut = db::name('user_send_gift_wall')->where('id', $user_send_gift_wall['id'])->inc('num', $num)->update(['update_time' => time()]);
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['receive_uid'] = $receive_uid;
|
||||
$insert['gid'] = $gid;
|
||||
$insert['num'] = $num;
|
||||
$insert['update_time'] = time();
|
||||
$reslut = db::name('user_send_gift_wall')->insert($insert);
|
||||
}
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//记录房间礼物墙
|
||||
public function room_gift_wall($rid, $gid, $num, $gift_total_price){
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$room_gift_wall = db::name('room_gift_wall')->where($map)->find();
|
||||
if($room_gift_wall){
|
||||
$reslut = db::name('room_gift_wall')->where('id', $room_gift_wall['id'])->inc('num', $num)->inc('gift_total_price', $gift_total_price)->update(['update_time' => time()]);
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['gid'] = $gid;
|
||||
$insert['num'] = $num;
|
||||
$insert['gift_total_price'] = $gift_total_price;
|
||||
$insert['update_time'] = time();
|
||||
$reslut = db::name('room_gift_wall')->insert($insert);
|
||||
}
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//用户点亮礼物墙
|
||||
public function get_user_illume_gift_wall($uid, $user_id, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 100 ? $page_limit : 100;
|
||||
|
||||
if(empty($user_id)){
|
||||
$user_id = $uid;
|
||||
}
|
||||
|
||||
$user_info = db::name('user')->find($user_id);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $user_id];
|
||||
$map[] = ['b.is_delete', '=', 1];
|
||||
$map[] = ['b.is_show', '=', 1];
|
||||
$list = db::name('user_receive_gift_wall')->alias('a')->join('yy_gift b', 'a.gid = b.gid')->where($map)->field('a.gid,b.gift_name,b.base_image,b.gift_price,sum(a.num) as num')->group('a.gid')->order('b.gift_price asc')->page($page, $page_limit)->select();
|
||||
|
||||
foreach ($list as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$where = [];
|
||||
$where[] = ['a.uid', '=', $user_id];
|
||||
$where[] = ['a.gid', '=', $v['gid']];
|
||||
$user_send_gift_info = db::name('user_receive_gift_wall')->alias('a')->join('yy_user b', 'a.send_uid = b.uid')->where($where)->field('a.send_uid as uid,b.base64_nick_name, b.head_pic,a.num')->order('a.num desc')->find();
|
||||
$user_send_gift_info['nick_name'] = mb_convert_encoding(base64_decode($user_send_gift_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_send_gift_info['head_pic'] = localpath_to_netpath($user_send_gift_info['head_pic']);
|
||||
$v['max_gift_num_user'] = $user_send_gift_info;
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//用户未点亮礼物墙
|
||||
public function get_user_unillume_gift_wall($uid, $user_id, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 100 ? $page_limit : 100;
|
||||
|
||||
if(empty($user_id)){
|
||||
$user_id = $uid;
|
||||
}
|
||||
|
||||
$user_info = db::name('user')->find($user_id);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$receive_gift_id_array = db::name('user_receive_gift_wall')->where('uid', $user_id)->group('gid')->column('gid');
|
||||
// dump($receive_gift_id_array);exit;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['gid', 'not in', $receive_gift_id_array];
|
||||
$list = db::name('gift')->where($map)->field('gid, gift_name, base_image, gift_price')->order('gift_price asc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
154
application/api/model/Guard.php
Normal file
154
application/api/model/Guard.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Guard extends Model
|
||||
{
|
||||
|
||||
//获取可购买守护列表
|
||||
public function get_guard_list()
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = db::name('guard')->field('gid,guard_name,title_image,position_image,frame_image')->cache(60)->where($map)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['title_image'] = localpath_to_netpath($v['title_image']);
|
||||
$v['position_image'] = localpath_to_netpath($v['position_image']);
|
||||
$v['frame_image'] = localpath_to_netpath($v['frame_image']);
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $v['gid']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$v['guard_price_list'] = db::name('guard_price')->cache(60)->field('id,day,sell_price')->where($map)->select();
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
//购买守护
|
||||
public function buy_guard($uid, $id, $guard_rid, $guard_uid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $guard_rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_info = db::name('room')->field('rid,tid,room_micro,room_owner_uid')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
if ($uid == $guard_uid) {
|
||||
return ['code' => 201, 'msg' => '自己不能购买自己的守护', 'data' => null];
|
||||
}
|
||||
if ($guard_uid != $room_info['room_host_uid']) {
|
||||
return ['code' => 201, 'msg' => '守护人当前不是房间主持', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $id];
|
||||
$guard_price_info = db::name('guard_price')->where($map)->find();
|
||||
if (empty($guard_price_info)) {
|
||||
return ['code' => 201, 'msg' => '购买守护信息不存在', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['gid', '=', $guard_price_info['gid']];
|
||||
$map[] = ['guard_rid', '=', $guard_rid];
|
||||
$map[] = ['guard_uid', '=', $guard_uid];
|
||||
$user_guard_info = db::name('user_guard')->where($map)->find();
|
||||
$ugid = 0;
|
||||
if (!empty($user_guard_info)) {
|
||||
$ugid = $user_guard_info['ugid'];
|
||||
$map = [];
|
||||
$map[] = ['ugid', '=', $ugid];
|
||||
$data = [];
|
||||
$data['over_time'] = $user_guard_info['over_time'] + $guard_price_info['day'] * 24 * 3600;
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_guard')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
} else {
|
||||
|
||||
$now_time = time();
|
||||
$over_time = $now_time + $guard_price_info['day'] * 24 * 3600;
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['gid'] = $guard_price_info['gid'];
|
||||
$data['guard_rid'] = $guard_rid;
|
||||
$data['guard_uid'] = $guard_uid;
|
||||
$data['over_time'] = $over_time;
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
$ugid = db::name('user_guard')->insertGetId($data);
|
||||
if (empty($ugid)) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//扣除账户积分
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$guard_price_info['sell_price'], 2, 8, "购买守护", $uid, $ugid);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return ['code' => 200, 'msg' => "购买成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
public function get_user_guard_list($uid, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['over_time', '>', time()];
|
||||
$user_guard_list = db::name('user_guard')->where($map)->group('guard_uid')->order('ugid desc')->page($page, $page_limit)->select();
|
||||
$uid_list = array_column($user_guard_list, 'uid');
|
||||
$guard_uid_list = array_column($user_guard_list, 'guard_uid');
|
||||
$uid_data = array_merge($uid_list, $guard_uid_list);
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', $uid_data];
|
||||
$user_list = db::name('user')->field('uid,base64_nick_name,head_pic,sex,special_uid')->where($map)->select();
|
||||
$user_list_data = [];
|
||||
foreach ($user_list as $k => &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$user_list_data[$v['uid']] = $v;
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$guard_list = db::name('guard')->cache(60)->where($map)->column('guard_name', 'gid');
|
||||
$now_time = time();
|
||||
$return_data = [];
|
||||
foreach ($user_guard_list as $k => $v) {
|
||||
$data = [];
|
||||
$data['guard_user_info']['uid'] = $user_list_data[$v['guard_uid']]['uid'];
|
||||
$data['guard_user_info']['special_uid'] = $user_list_data[$v['guard_uid']]['special_uid'];
|
||||
$data['guard_user_info']['nick_name'] = $user_list_data[$v['guard_uid']]['nick_name'];
|
||||
$data['guard_user_info']['head_pic'] = $user_list_data[$v['guard_uid']]['head_pic'];
|
||||
//获取当前守护用户 多条守护信息
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $v['uid']];
|
||||
$map[] = ['guard_uid', '=', $v['guard_uid']];
|
||||
$map[] = ['over_time', '>', $now_time];
|
||||
$user_guard_list = db::name('user_guard')->where($map)->select();
|
||||
foreach ($user_guard_list as $m => $n) {
|
||||
$data['guard_list']['guard_name'] = $guard_list[$v['gid']];
|
||||
$valid_day = ceil(($v['over_time'] - $now_time) / 86400);
|
||||
$data['guard_list']['valid_day'] = $valid_day;
|
||||
}
|
||||
$return_data[] = $data;
|
||||
}
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $return_data];
|
||||
}
|
||||
}
|
||||
872
application/api/model/Guild.php
Normal file
872
application/api/model/Guild.php
Normal file
@@ -0,0 +1,872 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use app\common\libs\DealTimeLib;
|
||||
class Guild extends Model
|
||||
{
|
||||
//公会列表
|
||||
public function get_guild_list($uid, $time, $page = 1, $page_limit){
|
||||
$keywords = input('keywords', '');
|
||||
$page = (int)$page;
|
||||
$page_limit = $page_limit < 20 ? $page_limit : 20;
|
||||
if($time == 1){
|
||||
$build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'yesterday')->group('guild_id')->buildSql();
|
||||
}else if($time == 2){
|
||||
$build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'today')->group('guild_id')->buildSql();
|
||||
}else if($time == 3){
|
||||
$build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'week')->group('guild_id')->buildSql();
|
||||
}else if($time == 4){
|
||||
$build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'last week')->group('guild_id')->buildSql();
|
||||
}else if($time == 5){
|
||||
$build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'month')->group('guild_id')->buildSql();
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
// $build_sql = db::name('user_send_gift')->field('guild_id,SUM(gift_total_price) as total_gift_total_price')->group('guild_id')->buildSql();
|
||||
|
||||
$map = [];
|
||||
if(!empty($keywords)){
|
||||
$map[] = ['a.guild_name|a.id|a.guild_special_id', 'like', '%'.$keywords.'%'];
|
||||
// $map[] = ['a.id', '=', $keywords];
|
||||
// $map[] = ['a.guild_special_id','=',$keywords];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$map[] = ['a.is_show', '=', 1];
|
||||
$list = db::name('guild')->alias('a')->join($build_sql.'b', 'a.id = b.guild_id', 'LEFT')->field('a.id as guild_id, a.guild_name, a.base64_guild_name, a.cover, b.total_gift_total_price, a.num,a.guild_special_id')->where($map)->order('b.total_gift_total_price desc')->page($page, $page_limit)->select();
|
||||
|
||||
if(empty($list)){
|
||||
$data = [];
|
||||
$data['list'] = $list;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
foreach ($list as $k => &$v){
|
||||
$v['guild_name'] = mb_convert_encoding(base64_decode($v['base64_guild_name']), 'UTF-8', 'UTF-8');
|
||||
$v['cover'] = localpath_to_netpath($v['cover']);
|
||||
if(empty($v['total_gift_total_price'])){
|
||||
$v['total_gift_total_price'] = 0;
|
||||
}else{
|
||||
$v['total_gift_total_price'] = (int)$v['total_gift_total_price'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['list'] = $list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//加入公会
|
||||
public function join_guild($uid, $guild_id){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//公会是否存在
|
||||
$guild_info = db::name('guild')->where('id', $guild_id)->find();
|
||||
if(!$guild_info){
|
||||
return ['code' => 201, 'msg' => '该公会不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否已加入过公会
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$is_check_join = db::name('user_guild')->where($map)->find();
|
||||
if($is_check_join){
|
||||
return ['code' => 201, 'msg' => '您已加入过公会', 'data' => null];
|
||||
}
|
||||
|
||||
//是否提交过 ==》自动同意
|
||||
// $map = [];
|
||||
// $map[] = ['uid', '=', $uid];
|
||||
// $map[] = ['guild_id', '=', $guild_id];
|
||||
// $map[] = ['status', '=', 2];
|
||||
// $is_join = db::name('user_guild')->where($map)->find();
|
||||
// if($is_join){
|
||||
// return ['code' => 201, 'msg' => '该公会您已提交过申请', 'data' => null];
|
||||
// }
|
||||
|
||||
//是否被踢出过
|
||||
$ti_chu = db::name('user_guild')->where(['uid'=>$uid,'guild_id'=>$guild_id,'is_delete'=>2,'quit_type'=>2])->find();
|
||||
if(!empty($ti_chu)){
|
||||
return ['code' => 201, 'msg' => '已被踢出,禁止加入!', 'data' => null];
|
||||
}
|
||||
|
||||
//退出公会是否超过20天
|
||||
// $map = [];
|
||||
// $map[] = ['uid', '=', $uid];
|
||||
// $map[] = ['is_delete', '=', 2];
|
||||
// $quit_guild_info = Db::name('user_guild')->where($map)->order('quit_time', 'desc')->field('quit_time,guild_id,quit_type')->find();
|
||||
// $quit_time = 0;
|
||||
// $quit_type = 2;
|
||||
// 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 && $quit_type != 2 && $quit_type != 3) {
|
||||
// // if($quit_guild_info['guild_id'] != $guild_id && $quit_type != 1 && $quit_type != 3) {
|
||||
// $last_time = 20 * 24 * 3600;
|
||||
// if((time() - $last_time) < $quit_time) {
|
||||
// return ['code' => 201, 'msg' => '退出公会未超过20天,不能重新加入其他公会', 'data' => null];
|
||||
// }
|
||||
// }
|
||||
|
||||
//退出公会是否超过20天
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 2];
|
||||
$map[] = ['quit_type', '=', 1];
|
||||
$quit_guild_info = Db::name('user_guild')->where($map)->order('quit_time', 'desc')->field('quit_time,guild_id,quit_type')->find();
|
||||
$quit_time = 0;
|
||||
$quit_type = 2;
|
||||
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 && $quit_type != 2 && $quit_type != 3) {
|
||||
if($quit_guild_info['guild_id'] != $guild_id) {
|
||||
$last_time = 20 * 24 * 3600;
|
||||
if((time() - $last_time) < $quit_time) {
|
||||
return ['code' => 201, 'msg' => '退出公会未超过20天,不能重新加入其他公会', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//该用户是否绑定身份证切已进入过别的公会
|
||||
if(!empty($user_info['card_id'])){
|
||||
$map = [];
|
||||
// $map[] = ['card_id', '=', $user_info['card_id']];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$is_check_joins = db::name('user_guild')->where($map)->order('id desc')->find();
|
||||
if($is_check_joins){
|
||||
if($is_check_joins['guild_id'] != $guild_id){
|
||||
return ['code' => 201, 'msg' => '您无法加入别的公会', 'data' => null];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '请先实名认证', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有房间
|
||||
$rid = 0;
|
||||
$room_info = db::name('room')->where('room_owner_uid', $uid)->find();
|
||||
if($room_info){
|
||||
$rid = $room_info['rid'];
|
||||
}
|
||||
|
||||
//提交申请
|
||||
// $insert_data = [];
|
||||
// $insert_data['uid'] = $uid;
|
||||
// $insert_data['guild_id'] = $guild_id;
|
||||
// $insert_data['rid'] = $rid;
|
||||
// $insert_data['card_id'] = $user_info['card_id'];
|
||||
// $insert_data['status'] = 2;
|
||||
// $insert_data['is_deacon'] = 2;
|
||||
// $insert_data['add_time'] = time();
|
||||
|
||||
|
||||
$insert_data = [];
|
||||
$insert_data['uid'] = $uid;
|
||||
$insert_data['guild_id'] = $guild_id;
|
||||
$insert_data['rid'] = $rid;
|
||||
$insert_data['card_id'] = $user_info['card_id'];
|
||||
$insert_data['status'] = 1;
|
||||
$insert_data['is_deacon'] = 2;
|
||||
$insert_data['add_time'] = time();
|
||||
$insert_data['is_show_room'] = 1;
|
||||
|
||||
$reslut = db::name('user_guild')->insert($insert_data);
|
||||
if($reslut){
|
||||
//增加公会人数
|
||||
db::name('guild')->where('id', $guild_info['id'])->inc('num', 1)->update();
|
||||
return ['code' => 200, 'msg' => '提交成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, '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' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//公会信息
|
||||
$guild_info = db::name('guild')->where('id', $guild_id)->find();
|
||||
if(!$guild_info){
|
||||
return ['code' => 201, 'msg' => '该公会不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.guild_id', '=', $guild_id];
|
||||
$map[] = ['a.status', '=', 2];
|
||||
$list = db::name('user_guild')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.id, a.uid, a.guild_id, a.rid, a.card_id, a.status, b.nick_name, b.base64_nick_name, b.head_pic')->where($map)->order('id desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['list'] = $list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
public function txt(){
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
|
||||
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '申请成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '申请失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//同意、拒绝申请
|
||||
public function operate_guild($uid, $apply_id, $type){
|
||||
return ['code' => 201, 'msg' => '请升级新版本', 'data' => null];
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//该申请是否已被操作
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $apply_id];
|
||||
$map[] = ['status', '=', 2];
|
||||
$is_operate = db::name('user_guild')->where($map)->find();
|
||||
if(!$is_operate){
|
||||
return ['code' => 201, 'msg' => '该申请不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if(!in_array($type, [1,2])){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//
|
||||
$guild_info = db::name('guild')->where('id', $is_operate['guild_id'])->find();
|
||||
if($uid != $guild_info['uid']){
|
||||
return ['code' => 201, 'msg' => '您没有权限操作', 'data' => null];
|
||||
}
|
||||
//审核通过
|
||||
if($type == 1) {
|
||||
$is_join_guild = Db::name('user_guild')->where(['uid' => $is_operate['uid'], 'is_delete' => 1, 'status' => 1])->find();
|
||||
if(!empty($is_join_guild)) {
|
||||
return ['code' => 201, 'msg' => '已加入其他工会', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($type == 1){//同意
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $apply_id];
|
||||
$update_data = [];
|
||||
$update_data['status'] = 1;
|
||||
$update_data['update_time'] = time();
|
||||
$update_data['is_show_room'] = 1;
|
||||
$reslut = db::name('user_guild')->where($map)->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
//增加公会人数
|
||||
db::name('guild')->where('id', $guild_info['id'])->inc('num', 1)->update();
|
||||
}else if($type == 2){//拒绝
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $apply_id];
|
||||
$update_data = [];
|
||||
$update_data['status'] = 3;
|
||||
$update_data['update_time'] = time();
|
||||
$reslut = db::name('user_guild')->where($map)->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//公会信息
|
||||
public function get_guild_info($uid, $guild_id, $type, $page, $page_limit){
|
||||
$page = (int)$page;
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$guild_info = db::name('guild')->where('id', $guild_id)->find();
|
||||
if(!$guild_id){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($type == 1){
|
||||
$map = [];
|
||||
$map[] = ['a.guild_id', '=', $guild_id];
|
||||
$map[] = ['a.status', '=', 1];
|
||||
$map[] = ['a.rid', '>', 0];
|
||||
$map[] = ['a.is_show_room', '=', 1];
|
||||
$list = db::name('user_guild')->alias('a')->join('yy_room b', 'a.uid = b.room_owner_uid')->field('a.id,a.uid,a.rid,a.guild_id,b.room_name,b.base64_room_name,b.room_cover,b.today_hot_value')->where($map)->order('b.today_hot_value desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$v['room_cover'] = localpath_to_netpath($v['room_cover']);
|
||||
}
|
||||
}else if($type == 2){
|
||||
$map = [];
|
||||
$map[] = ['a.guild_id', '=', $guild_id];
|
||||
$map[] = ['a.status', '=', 1];
|
||||
$list = db::name('user_guild')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.id,a.uid,a.rid,a.guild_id,b.nick_name,b.base64_nick_name,b.head_pic')->where($map)->order('a.is_deacon asc, a.id desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['list'] = $list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if($time == 1){
|
||||
// $build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'yesterday')->group('guild_id')->buildSql();
|
||||
// }else if($time == 2){
|
||||
// $build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'today')->group('guild_id')->buildSql();
|
||||
// }else if($time == 3){
|
||||
// $build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'week')->group('guild_id')->buildSql();
|
||||
// }else if($time == 4){
|
||||
// $build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'last week')->group('guild_id')->buildSql();
|
||||
// }else if($time == 5){
|
||||
// $build_sql = db::name('room_guild_charm_count_day')->field('guild_id,SUM(amount) as total_gift_total_price')->whereTime('add_time', 'month')->group('guild_id')->buildSql();
|
||||
// }else{
|
||||
// return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function get_guild_money_log_list($uid, $guild_id, $type, $time, $page = 1, $page_limit){
|
||||
$page = (int)$page;
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
// $page = $page * $page_limit;
|
||||
//time 1当日 2本周 3本月
|
||||
if(!in_array($time, [1,2,3,4,5])){
|
||||
return ['code' => 201, 'msg' => '参数非法1', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数非法2', 'data' => null];
|
||||
}
|
||||
|
||||
$guild_info = db::name('guild')->find($guild_id);
|
||||
if(!$guild_info){
|
||||
return ['code' => 201, 'msg' => '参数非法3', 'data' => null];
|
||||
}
|
||||
|
||||
$is_deacon = 2;
|
||||
if($uid == $guild_info['uid']){
|
||||
$is_deacon = 1;
|
||||
}
|
||||
|
||||
if($type == 1){//房间
|
||||
//公会所有房间
|
||||
$map = [];
|
||||
$map[] = ['c.guild_id', '=', $guild_id];
|
||||
$map[] = ['c.rid', '>', 0];
|
||||
$map[] = ['c.is_delete', '=', 1];
|
||||
$map[] = ['c.is_show_room', '=', 1];
|
||||
$map[] = ['c.status', '=', 1];
|
||||
$build_sql = Db::name('room_guild_charm_count_day')->field('SUM(amount) as total_gift_total_price, rid as guild_rid');
|
||||
if($time == 1){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'yesterday');
|
||||
}else if($time == 2){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'today');
|
||||
}else if($time == 3){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'week');
|
||||
}else if($time == 4){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'last week');
|
||||
}else if($time == 5){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'month');
|
||||
}
|
||||
$build_sql = $build_sql->where('guild_id', $guild_id)->group('rid')->buildSql();
|
||||
|
||||
// dump($map);die;
|
||||
$order_string = 'b.total_gift_total_price desc'; //排序规则
|
||||
$model = Db::name('user_guild')->alias('c');
|
||||
$model = $model->where($map);
|
||||
$model = $model->field('a.rid,a.room_owner_uid,a.room_name,a.base64_room_name,a.room_cover,b.total_gift_total_price,a.room_number');
|
||||
$model = $model->join($build_sql . ' b', 'c.rid = b.guild_rid', 'left');
|
||||
$model = $model->join('yy_room a', 'c.rid = a.rid');
|
||||
$list = $model->order($order_string)->page($page, $page_limit)->select();
|
||||
// dump($list);exit;
|
||||
foreach ($list as $k => &$v){
|
||||
$v['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$v['room_cover'] = localpath_to_netpath($v['room_cover']);
|
||||
if(empty($v['total_gift_total_price'])){
|
||||
$v['total_gift_total_price'] = 0;
|
||||
}else{
|
||||
$v['total_gift_total_price'] = (int)$v['total_gift_total_price'];
|
||||
}
|
||||
}
|
||||
$total_gift_price = Db::name('room_guild_charm_count_day')->where('guild_id', $guild_id);
|
||||
if($time == 1){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'yesterday');
|
||||
}else if($time == 2){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'today');
|
||||
}else if($time == 3){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'week');
|
||||
}else if($time == 4){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'last week');
|
||||
}else if($time == 5){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'month');
|
||||
}
|
||||
// $total_gift_price = '****';
|
||||
if($is_deacon == 1) {
|
||||
$total_gift_price = $total_gift_price->sum('amount');
|
||||
} else {
|
||||
$total_gift_price = '****';
|
||||
}
|
||||
//
|
||||
|
||||
}else if($type == 2){//个人
|
||||
//公会用户成员
|
||||
$map = [];
|
||||
$map[] = ['a.guild_id', '=', $guild_id];
|
||||
$map[] = ['a.status', '=', 1];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
|
||||
$build_sql = Db::name('user_guild_charm_count_day')->field('SUM(amount) as total_gift_total_price, uid');
|
||||
if($time == 1){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'yesterday');
|
||||
}else if($time == 2){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'today');
|
||||
}else if($time == 3){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'week');
|
||||
}else if($time == 4){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'last week');
|
||||
}else if($time == 5){
|
||||
$build_sql = $build_sql->whereTime('add_time', 'month');
|
||||
}
|
||||
$build_sql = $build_sql->group('uid')->buildSql();
|
||||
|
||||
$order_string = 'a.is_deacon asc, b.total_gift_total_price desc'; //排序规则
|
||||
$model = Db::name('user_guild')->alias('a');
|
||||
$model = $model->field('a.uid,c.base64_nick_name,c.head_pic,b.total_gift_total_price,c.special_uid');
|
||||
$model = $model->join('yy_user c', 'a.uid = c.uid');
|
||||
$model = $model->join($build_sql . ' b', 'a.uid = b.uid', 'left');
|
||||
$model = $model->where($map);
|
||||
|
||||
$list = $model->order($order_string)->page($page, $page_limit)->select();
|
||||
// dump($list);exit;
|
||||
foreach ($list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
if(empty($v['total_gift_total_price'])){
|
||||
$v['total_gift_total_price'] = 0;
|
||||
}else{
|
||||
$v['total_gift_total_price'] = (int)$v['total_gift_total_price'];
|
||||
}
|
||||
}
|
||||
$total_gift_price = Db::name('user_guild_charm_count_day')->where('guild_id', $guild_id);
|
||||
if($time == 1){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'yesterday');
|
||||
}else if($time == 2){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'today');
|
||||
}else if($time == 3){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'week');
|
||||
}else if($time == 4){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'last week');
|
||||
}else if($time == 5){
|
||||
$total_gift_price = $total_gift_price->whereTime('add_time', 'month');
|
||||
}
|
||||
// $total_gift_price = $total_gift_price->sum('amount');
|
||||
if($is_deacon == 1) {
|
||||
$total_gift_price = $total_gift_price->sum('amount');
|
||||
} else {
|
||||
$total_gift_price = '****';
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['is_deacon'] = $is_deacon;
|
||||
$data['list'] = $list;
|
||||
$data['total_gift_price'] = $total_gift_price;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
//踢出公会
|
||||
public function kick_out_guild($uid, $user_id, $guild_id){
|
||||
$user_info = db::name('user')->find($user_id);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$guild_info = db::name('guild')->find($guild_id);
|
||||
if(!$guild_id){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $guild_info['uid']){
|
||||
return ['code' => 201, 'msg' => '您没有权限操作','data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
$map[] = ['guild_id', '=', $guild_id];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_guild_info = db::name('user_guild')->where($map)->find();
|
||||
if(!$user_guild_info){
|
||||
return ['code' => 201, 'msg' => '该用户不在该公会', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_guild_info['is_deacon'] == 1){
|
||||
return ['code' => 201, 'msg' => '会长无法被踢出','data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $user_guild_info['id']];
|
||||
$update_data = [];
|
||||
$update_data['is_delete'] = 2;
|
||||
$update_data['update_time'] = time();
|
||||
$update_data['quit_time'] = time();
|
||||
$update_data['quit_type'] = 2;
|
||||
$reslut = db::name('user_guild')->where($map)->update($update_data);
|
||||
if($reslut){
|
||||
//减少公会人数
|
||||
db::name('guild')->where('id', $guild_info['id'])->inc('num', -1)->update();
|
||||
return ['code' => 200, 'msg' => '踢出成功','data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '踢出失败','data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//退出公会
|
||||
public function quit_guild($uid, $guild_id){
|
||||
$config = get_system_config();
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$guild_info = db::name('guild')->find($guild_id);
|
||||
if(!$guild_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['guild_id', '=', $guild_id];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_guild_info = db::name('user_guild')->where($map)->find();
|
||||
if(!$user_guild_info){
|
||||
return ['code' => 201, 'msg' => '用户不在该公会', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_guild_info['is_deacon'] == 1){
|
||||
return ['code' => 201, 'msg' => '会长无法退出公会', 'data' => null];
|
||||
}
|
||||
|
||||
$time = 60 * 60 * 24 * $config['quit_guild_time'];
|
||||
$time = $user_guild_info['start_time'] + $time;
|
||||
if($time > time()){
|
||||
return ['code' => 201, 'msg' => '加入公会'.$config['quit_guild_time'].'天内无法退出', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($guild_info['money'] > 0){
|
||||
|
||||
if($user_info['integral'] < $guild_info['money']){
|
||||
return ['code' => 201, 'msg' => '金币不足', 'data' => null];
|
||||
}
|
||||
|
||||
//扣除用户金币
|
||||
$reslut = model('admin/User')->change_user_money_by_user_info($user_info, -$guild_info['money'], 2, 18, "主动退出公会,扣除金币", $user_info['uid'], 0);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//增加会长金币
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($guild_info['uid'], $guild_info['money'], 2, 19, "成员退出公会,会长获取金币", $user_info['uid'], 0);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $user_guild_info['id']];
|
||||
$update_data = [];
|
||||
$update_data['is_delete'] = 2;
|
||||
$update_data['update_time'] = time();
|
||||
$update_data['quit_time'] = time();
|
||||
$update_data['quit_type'] = 1;
|
||||
$reslut = db::name('user_guild')->where($map)->update($update_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, '' => '退出失败', 'data' => null];
|
||||
}
|
||||
//减少公会人数
|
||||
db::name('guild')->where('id', $guild_info['id'])->inc('num', -1)->update();
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '退出成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '退出失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//是否是公会会长
|
||||
public function user_is_deacon($uid, $guild_id){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$guild_info = db::name('guild')->find($guild_id);
|
||||
if(!$guild_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$is_deacon = 2;
|
||||
if($uid == $guild_info['uid']){
|
||||
$is_deacon = 1;
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['guild_id', '=', $guild_id];
|
||||
$info = Db::name('user_guild')->where($map)->find();
|
||||
$is_join_guild = 2;
|
||||
if($info) {
|
||||
$is_join_guild = 1;
|
||||
}
|
||||
$data = [];
|
||||
$data['is_deacon'] = $is_deacon;
|
||||
$data['guild_name'] = mb_convert_encoding(base64_decode($guild_info['base64_guild_name']), 'UTF-8', 'UTF-8');
|
||||
$data['quit_money'] = $guild_info['money'];
|
||||
$data['is_join_guild'] = $is_join_guild;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//用户公会信息
|
||||
public function user_guild_info($uid){
|
||||
$guild_id = 0;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['is_show_room', '=', 1];
|
||||
$user_guild_info = db::name('user_guild')->where($map)->find();
|
||||
if($user_guild_info){
|
||||
$guild_id = $user_guild_info['guild_id'];
|
||||
}
|
||||
|
||||
return $guild_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//解散公会
|
||||
public function diss_guild($uid,$guild_id){
|
||||
$guild_info = db::name('guild')->where(['id'=>$guild_id,'uid'=>$uid,'is_delete'=>1])->find();
|
||||
if(empty($guild_info)){
|
||||
return ['code' => 201, 'msg' => '公会不存在!', 'data' => null];
|
||||
}
|
||||
try {
|
||||
Db::startTrans();
|
||||
//成员解散
|
||||
db::name('user_guild')->where(['guild_id'=>$guild_id,'status'=>1,'is_delete'=>1])->update(['is_delete'=>2,'quit_type'=>3,'quit_time'=>time()]);
|
||||
|
||||
//退会
|
||||
$update_data = [];
|
||||
$update_data['is_deacon'] = 2;
|
||||
$update_data['update_time'] = time();
|
||||
$reslut = db::name('user')->where('uid', $uid)->update($update_data);
|
||||
|
||||
//解散公会
|
||||
db::name('guild')->where('id',$guild_id)->update(['is_delete'=>2,'is_show'=>2,'num'=>0,'guild_special_id'=>""]);
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '解散成功!', 'data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '解散失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//公会合并
|
||||
public function guild_combine($cancel_guild_id,$join_guild_id){
|
||||
$guild_info1 = db::name('guild')->where(['id'=>$cancel_guild_id,'is_delete'=>1])->find();
|
||||
if(empty($guild_info1)){
|
||||
return ['code' => 201, 'msg' => '被解散公会!', 'data' => null];
|
||||
}
|
||||
$guild_info2 = db::name('guild')->where(['id'=>$join_guild_id,'is_delete'=>1])->find();
|
||||
if(empty($guild_info2)){
|
||||
return ['code' => 201, 'msg' => '合并公会不存在!', 'data' => null];
|
||||
}
|
||||
try {
|
||||
Db::startTrans();
|
||||
//a公会成员人数统计
|
||||
$num = db::name('user_guild')->where(['guild_id'=>$cancel_guild_id,'status'=>1,'is_delete'=>1])->count("*");
|
||||
|
||||
|
||||
//将a公会成员加入b公会
|
||||
$s_date = date('Y-m-d H:i:s');
|
||||
db::name('user_guild')->where(['guild_id'=>$cancel_guild_id,'status'=>1,'is_delete'=>1])->update(['guild_id'=>$join_guild_id,'is_deacon'=>2,'remarks'=>"{$s_date}公会id:{$cancel_guild_id}合并到公会id:{$join_guild_id}"]);
|
||||
|
||||
//增加b公会人数
|
||||
db::name('guild')->where(['id'=>$join_guild_id,'is_delete'=>1])->inc('num',$num)->update(['update_time'=>time()]);
|
||||
|
||||
|
||||
//取消a公会 公会长身份
|
||||
$update_data = [];
|
||||
$update_data['is_deacon'] = 2;
|
||||
$update_data['update_time'] = time();
|
||||
$reslut = db::name('user')->where('uid', $guild_info1['uid'])->update($update_data);
|
||||
db::name('guild')->where(['id'=>$cancel_guild_id])->update(['guild_special_id'=>"",'num'=>0,'is_delete'=>2,'is_show'=>2]);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return ['code' => 200, 'msg' => '合并成功!', 'data' => null];
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '合并失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function get_the_guild_info($guild_id=0){
|
||||
$guild_info = db::name('guild')->where(['id'=>$guild_id,'is_delete'=>1,'is_show'=>1])->field('id,guild_special_id,uid,base64_guild_name as guild_name,cover,money,num,intro,add_time')->find();
|
||||
if(empty($guild_info)){
|
||||
return ['code' => 201, 'msg' => '公会不存在', 'data' => null];
|
||||
}
|
||||
$guild_info['guild_name'] = mb_convert_encoding(base64_decode($guild_info['guild_name']), 'UTF-8', 'UTF-8');
|
||||
$guild_info['cover'] = localpath_to_netpath($guild_info['cover']);
|
||||
|
||||
//贡献值
|
||||
$guild_info['contribution_value'] = db::name('user_guild_charm_count_day')->where(['guild_id'=>$guild_id])->sum('amount');
|
||||
|
||||
//公会长信息
|
||||
$ghz = db::name('user')->where(['uid'=>$guild_info['uid']])->field('uid,base64_nick_name as nick_name,head_pic,special_uid')->find();
|
||||
if($ghz){
|
||||
$ghz['nick_name'] = mb_convert_encoding(base64_decode($ghz['nick_name']), 'UTF-8', 'UTF-8');
|
||||
$ghz['head_pic'] = localpath_to_netpath($ghz['head_pic']);
|
||||
//获取爵位信息
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$map[] = ['a.status', '=', 1];
|
||||
$map[] = ['a.uid' , '=', $ghz['uid']];
|
||||
$map[] = ['a.end_time' , '>', time()];
|
||||
$noblity_image = db::name('user_nobility')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_nobility c', 'c.lid = a.lid')->where($map)->order('a.lid desc')->value('c.image');
|
||||
$ghz['noblity_image'] = localpath_to_netpath($noblity_image);
|
||||
|
||||
//获取用户魅力 财富等级
|
||||
$reslut = model('api/User')->get_user_charm_contribution_info($ghz['uid']);
|
||||
$ghz['charm_level_image'] = $reslut['data']['charm_level_image'];
|
||||
$ghz['contribution_level_image'] = $reslut['data']['contribution_level_image'];
|
||||
}
|
||||
$guild_info['ghz'] = $ghz;
|
||||
|
||||
|
||||
|
||||
//获取所有房间上周流水
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['guild_id', '=', $guild_id];
|
||||
$last_week_income = db::name('room_guild_charm_count_day')->where($map)->whereTime('add_time', 'last week')->sum('amount');
|
||||
$guild_info['last_week_income'] = $last_week_income;
|
||||
|
||||
|
||||
$week_start = date('Y-m-d', strtotime("last week Monday"));
|
||||
$week_end = date('Y-m-d', strtotime("last week Sunday"));
|
||||
$belong_week = $week_start.'-'.$week_end;
|
||||
|
||||
$earnings = db::name('guild_week_earnings_log')->where(['guild_id'=>$guild_id,'belong_week'=>$belong_week])->value('earnings');
|
||||
$guild_info['last_week_income_money'] = $earnings;
|
||||
|
||||
//上周补贴金额
|
||||
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['guild_id', '=', $guild_id];
|
||||
$this_week_income = db::name('room_guild_charm_count_day')->where($map)->whereTime('add_time', 'week')->sum('amount');
|
||||
$guild_info['this_week_income'] = $this_week_income;
|
||||
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => 'success', 'data' => $guild_info];
|
||||
// $guild_info['ghz'] =
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
145
application/api/model/GuildSubsidy.php
Normal file
145
application/api/model/GuildSubsidy.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class GuildSubsidy extends Model
|
||||
{
|
||||
|
||||
|
||||
//统计上周公会流水
|
||||
public function statistics_guild_last_week_earnings($subsidy_id){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
//公会补贴信息
|
||||
$room_subsidy_info = db::name('guild_subsidy')->where('id', $subsidy_id)->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
|
||||
$last_week_time = strtotime('-1 week last sunday', time());
|
||||
|
||||
//获取所有公会上周流水
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$last_week_income = db::name('room_guild_charm_count_day')->where($map)->field('guild_id,sum(amount) as amount')->whereTime('add_time', 'last week')->group('guild_id')->select();
|
||||
$insert_all = [];
|
||||
if(!empty($last_week_income)){
|
||||
foreach ($last_week_income as $k => $v){
|
||||
//上周补贴奖励金额
|
||||
$subsidy_money = 0;
|
||||
foreach ($room_subsidy_info as $a => &$b){
|
||||
$money = $b['money'];
|
||||
if($b['total_gift_price'] > $v['amount']){
|
||||
break;
|
||||
}else{
|
||||
if($b['type'] == 1){
|
||||
$subsidy_money = $b['money'];
|
||||
}else{
|
||||
$subsidy_money = $v['amount'] * $money * 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//上周是否已添加
|
||||
$where = [];
|
||||
$where[] = ['guild_id', '=', $v['guild_id']];
|
||||
$where[] = ['subsidy_id', '=', $subsidy_id];
|
||||
$where[] = ['type', '=', 1];
|
||||
$where[] = ['last_week_time', '=', $last_week_time];
|
||||
$info = db::name('guild_week_earnings_log')->where($where)->find();
|
||||
if(empty($info)){
|
||||
$insert = [];
|
||||
$insert['guild_id'] = $v['guild_id'];
|
||||
$insert['type'] = 1;
|
||||
$insert['subsidy_id'] = $subsidy_id;
|
||||
$insert['change_value'] = $v['amount'];
|
||||
$insert['earnings'] = $subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert_all[] = $insert;
|
||||
}
|
||||
}
|
||||
if(!empty($insert_all)){
|
||||
$reslut = db::name('guild_week_earnings_log')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
echo date('Y-m-d H:i:s').'执行失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
|
||||
}
|
||||
|
||||
|
||||
//统计公会长收益
|
||||
public function gives_user_guild_week_earnings($subsidy_id){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
$last_week_time = strtotime('-1 week last sunday', time());
|
||||
|
||||
//获取未发送的公会上周收益
|
||||
$map = [];
|
||||
$map[] = ['subsidy_id', '=', $subsidy_id];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['last_week_time', '=', $last_week_time];
|
||||
$list = db::name('guild_week_earnings_log')->where($map)->select();
|
||||
if(!empty($list)){
|
||||
foreach ($list as $k => $v){
|
||||
if($v['earnings'] > 0){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$insert_all = [];
|
||||
|
||||
//公会长获取公会补贴
|
||||
$deacon_uid = db::name('guild')->where('id', $v['guild_id'])->value('uid');
|
||||
$surplus_ratio = 100;
|
||||
$owner_subsidy_money = $v['earnings'] * $surplus_ratio * 0.01;
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($room_owner_uid, $owner_subsidy_money, 1, $user_money_log, $remarks, $room_owner_uid, 0, $v['rid']);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
$insert = [];
|
||||
$insert['type'] = 1;
|
||||
$insert['user_type'] = 1;
|
||||
$insert['guild_id'] = $v['guild_id'];
|
||||
$insert['subsidy_id'] = $subsidy_id;
|
||||
$insert['uid'] = $deacon_uid;
|
||||
$insert['ratio'] = $surplus_ratio;
|
||||
$insert['change_value'] = $v['change_value'];
|
||||
$insert['room_earnings'] = $v['earnings'];
|
||||
$insert['user_earnings'] = $owner_subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['is_delete'] = 1;
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert_all[] = $insert;
|
||||
$reslut = db::name('user_guild_week_earnings')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('guild_week_earnings_log')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
}
|
||||
}else{
|
||||
db::name('guild_week_earnings_log')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
}
|
||||
|
||||
}
|
||||
236
application/api/model/HuiFu.php
Normal file
236
application/api/model/HuiFu.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\facade\Env;
|
||||
use think\Model;
|
||||
require_once Env::get('root_path') . 'extend/adapay_sdk_php_v1.4.4/AdapaySdk/init.php';
|
||||
// require_once Env::get('root_path') . 'extend/adapay_sdk_php_v1.4.4/AdapayDemo/config.php';
|
||||
class HuiFu extends Model
|
||||
{
|
||||
|
||||
public $app_id = "app_260e8610-8ee2-498a-8fec-66fa866bb072";
|
||||
private $config_object = [
|
||||
"api_key_live" => "api_live_e6e24c8d-c257-4dd7-856c-3d82f475820b",
|
||||
"rsa_private_key" => "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAN+4r227xPKzSWRaaDRZmVdANi/0y6kuPs/x6r9JmOaOL8T3PRLnSLLPZiKQYIPxyxsdnvxWn4tA7R6SndfQtOHxpMcefLanwDnCGDDIYEHKk8laSN6UmqFhF8xY50uIf73EdGQ7P1RmjyeSqjtakzjHM9nIM24I+8Rxyr1i67yjAgMBAAECgYEAodXHkWmzHp3zCVUc7EGkWyloCWjbqpZ5eZNWbOmgYaeZhrISzAni3PaKu5YVO109v2++AmvnHaTp4qPM6sFfFngmbp0ztsGmomoNFP9z+ruGlHbK8iWt8PlrfrgttAoIi7PrAbz+9fkbI4mPs149ECV+RHlU+EjkWh9bwqL9/wECQQD8tUEYm4ILvy8CJ67i/sE1MV8Nwjkbxy+ayY7h0mUBgo02e5W0CZYmyq4KUyshqjsOLVXcuefH9OkP7D0TkToJAkEA4qLDx1B3R8d6dbm8UgWxDlX5Tab/aO2WXjbIM7W1lW+jI34A2wNbR11VIhzY2gqyBgP0tz0fc2pfSx1NbYDcSwJBAPPBJgRFY+BOzlomyvObxeO4Nra/xHQ94nZMuyyp09HsCqgl9xXNNW8/izbcWDtFx2b6Zdrd22utme1I8vTf3XkCQHAeochrEHecQgMXvgi99BfphIpcAaNBVtCJPYYHcSvarNSUM4wmHvQxQjq8FrPX8rZzIo+8V2Db0QTyHCn+Q/0CQDdNUVfKNrcDBaAtNKW5GBzjXdVYbb4g6vOZ8FT/G8C4kwXsQlwtl61N1ZpQhao9vml6UJEP72hMU8XLMyEFRv4=",
|
||||
"rsa_public_key" => "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCwN6xgd6Ad8v2hIIsQVnbt8a3JituR8o4Tc3B5WlcFR55bz4OMqrG/356Ur3cPbc2Fe8ArNd/0gZbC9q56Eb16JTkVNA/fye4SXznWxdyBPR7+guuJZHc/VW2fKH2lfZ2P3Tt0QkKZZoawYOGSMdIvO+WqK44updyax0ikK6JlNQIDAQAB"
|
||||
];
|
||||
|
||||
|
||||
public function __construct($data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
\AdaPay\AdaPay::init($this->config_object, "live", true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function member_create($memeberId,$nickname){
|
||||
# 初始化用户对象类
|
||||
$member = new \AdaPaySdk\Member();
|
||||
$member_params = array(
|
||||
# app_id
|
||||
'app_id'=> $this->app_id,
|
||||
# 用户id
|
||||
'member_id'=> $memeberId,
|
||||
// # 用户地址
|
||||
// 'location'=> '上海市闵行区汇付',
|
||||
// # 用户邮箱
|
||||
// 'email'=> '123123@126.com',
|
||||
// # 性别
|
||||
// 'gender'=> 'MALE',
|
||||
// # 用户手机号
|
||||
// 'tel_no'=> '18177722312',
|
||||
// # 用户昵称
|
||||
'nickname'=> $nickname,
|
||||
);
|
||||
# 创建
|
||||
$member->create($member_params);
|
||||
# 对创建用户对象结果进行处理
|
||||
if ($member->isError()){
|
||||
return $member->result;
|
||||
} else {
|
||||
//成功处理
|
||||
return $member->result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function bind_card($memberId,$accountInfo){
|
||||
# 初始化结算账户对象类
|
||||
$account = new \AdaPaySdk\SettleAccount();
|
||||
|
||||
$account_params = array(
|
||||
'app_id'=> $this->app_id,
|
||||
'member_id'=> $memberId,
|
||||
'channel'=> 'bank_account',
|
||||
'account_info'=> [
|
||||
'card_id' => $accountInfo['card_id'], //银行卡id(卡号)--必填
|
||||
'card_name' => $accountInfo['card_name'],//银行卡姓名 - 必填
|
||||
'cert_id' => $accountInfo['cert_id'], //证件号 -必填
|
||||
'cert_type' => '00', //证件类型 -必填
|
||||
'tel_no' => $accountInfo['tel_no'], //银行卡绑定的手机号 - 必填
|
||||
// 'bank_code' => '03060000', //银行编码
|
||||
// 'bank_name' => '建hua', //开户银行名称
|
||||
'bank_acct_type' => 2, //银行账户类型:1-对公;2-对私 -必填
|
||||
// 'prov_code' => '0031', //---银行账户开户银行所在省份编码 (省市编码),银行账户类型为对公时,必填
|
||||
// 'area_code' => '3100', //----银行账户开户银行所在地区编码(省市编码),银行账户类型为对公时,必填
|
||||
]
|
||||
);
|
||||
# 创建结算账户
|
||||
$account->create($account_params);
|
||||
|
||||
# 对创建结算账户结果进行处理
|
||||
if ($account->isError()){
|
||||
//失败处理
|
||||
return $account->result;
|
||||
} else {
|
||||
//成功处理
|
||||
return $account->result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function delete_card($memberId,$settle_account_id)
|
||||
{
|
||||
|
||||
# 初始化结算账户对象类
|
||||
$account = new \AdaPaySdk\SettleAccount();
|
||||
|
||||
$account_params = array(
|
||||
'app_id'=> $this->app_id,
|
||||
'member_id'=> $memberId,
|
||||
'settle_account_id'=> $settle_account_id
|
||||
);
|
||||
# 查询结算账户
|
||||
$account->delete($account_params);
|
||||
|
||||
# 对查询结算账户结果进行处理
|
||||
if ($account->isError()){
|
||||
//失败处理
|
||||
return $account->result;
|
||||
} else {
|
||||
//成功处理
|
||||
return $account->result;
|
||||
}
|
||||
}
|
||||
|
||||
public function check_member_card($memebrId){
|
||||
//根据会员id 查询结算卡 账户信息
|
||||
if(empty($memebrId)){
|
||||
return ['code' => '', 'msg' => '获取不到会员id', 'data' => null];
|
||||
}
|
||||
$result = db::name('user')->where(['uid'=>$memebrId])->field('uid,bind_bank_card_id')->find();
|
||||
if(empty($result['bind_bank_card_id'])){
|
||||
return ['code' => '', 'msg' => '未绑定结算卡!', 'data' => null];
|
||||
}
|
||||
$account = new \AdaPaySdk\SettleAccount();
|
||||
$account_params = array(
|
||||
'app_id'=> $this->app_id,
|
||||
'member_id'=> $memebrId,
|
||||
'settle_account_id'=> $result['bind_bank_card_id']
|
||||
);
|
||||
$data = $account->query($account_params);
|
||||
$account_result = $account->result;
|
||||
$code = isset($account_result[0])?$account_result[0]:-11;
|
||||
if($code != 200){
|
||||
return ['code' => $code, 'msg' => '银行卡绑定异常,请重新绑卡!', 'data' => null];
|
||||
}
|
||||
$end_data = json_decode($account_result[1],true);
|
||||
$end_data = json_decode($end_data['data'],true);
|
||||
return ['code' => 200, 'msg' => '操作成功!', 'data' => $end_data];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取手续费
|
||||
* avl_balance 可用余额
|
||||
*/
|
||||
public function commission(){
|
||||
# 初始化结算账户对象类
|
||||
$account = new \AdaPaySdk\SettleAccount();
|
||||
$account_params = array(
|
||||
'app_id'=> $this->app_id,
|
||||
'member_id'=> '0',
|
||||
'settle_account_id'=> '',
|
||||
'acct_type'=>'02'
|
||||
);
|
||||
# 查询账户余额
|
||||
$account->balance($account_params);
|
||||
$account_result = $account->result;
|
||||
$code = isset($account_result[0])?$account_result[0]:-11;
|
||||
if($code != 200){
|
||||
return ['code' => $code, 'msg' => '获取手续费失败', 'data' => null];
|
||||
}
|
||||
$end_data = json_decode($account_result[1],true);
|
||||
$end_data = json_decode($end_data['data'],true);
|
||||
return ['code' => $code, 'msg' => '获取手续费成功', 'data' => $end_data];
|
||||
}
|
||||
|
||||
|
||||
public function commission_gd(){
|
||||
# 初始化结算账户对象类
|
||||
$account = new \AdaPaySdk\SettleAccount();
|
||||
$account_params = array(
|
||||
'app_id'=> $this->app_id,
|
||||
'member_id'=> '0',
|
||||
'settle_account_id'=> '',
|
||||
'acct_type'=>'03'
|
||||
);
|
||||
# 查询账户余额
|
||||
$account->balance($account_params);
|
||||
$account_result = $account->result;
|
||||
$code = isset($account_result[0])?$account_result[0]:-11;
|
||||
if($code != 200){
|
||||
return ['code' => $code, 'msg' => '获取手续费失败', 'data' => null];
|
||||
}
|
||||
$end_data = json_decode($account_result[1],true);
|
||||
$end_data = json_decode($end_data['data'],true);
|
||||
return ['code' => $code, 'msg' => '过渡账户余额获取成功', 'data' => $end_data];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//确认分账
|
||||
public function confirm_divide_accounts($payment_id,$memberId,$confirm_amt){
|
||||
# 初始化支付确认对象类
|
||||
$confirm_amt = del_coin_num($confirm_amt,2);
|
||||
$payment = new \AdaPaySdk\PaymentConfirm();
|
||||
$div_members = [['member_id'=>$memberId,'amount'=>$confirm_amt,'fee_flag'=>"Y"]];
|
||||
# 支付设置
|
||||
$payment_params = array(
|
||||
'payment_id' => $payment_id,
|
||||
'order_no' => date("YmdHis") . rand(100000, 999999),
|
||||
'confirm_amt' => $confirm_amt,
|
||||
'description' => '用户'.$memberId.'进行提现',
|
||||
'div_members' =>$div_members,
|
||||
// 'fee_mode'=>'O' //商户手续费账户扣取手续费
|
||||
// 'fee_mode'=>'O'
|
||||
'fee_mode'=>'I'
|
||||
);
|
||||
# 创建支付确认对象
|
||||
$payment->create($payment_params);
|
||||
$payment_result = $payment->result;
|
||||
$code = isset($payment_result[0])?$payment_result[0]:-11;
|
||||
if($code != 200){
|
||||
$end_data = json_decode($payment_result[1],true);
|
||||
$end_data = json_decode($end_data['data'],true);
|
||||
return ['code' => $code, 'msg' => '分账失败!', 'data' => $end_data];
|
||||
}
|
||||
// $end_data = json_decode($payment_result[1],true);
|
||||
// $end_data = json_decode($end_data['data'],true);
|
||||
return ['code' => 200, 'msg' => '操作成功!', 'data' => []];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
95
application/api/model/HuiFu1.php
Normal file
95
application/api/model/HuiFu1.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use app\common\hui_fu\HuiFuPayment;
|
||||
use app\common\hui_fu\HuiFuCallback;
|
||||
use think\db;
|
||||
class HuiFu1
|
||||
{
|
||||
|
||||
public function wx_pay_web($order_sn, $money, $open_id)
|
||||
{
|
||||
$notify_url = "http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/hui_fu_pay_notify";
|
||||
$ip = request()->ip();
|
||||
$pay_type = 42;
|
||||
|
||||
|
||||
$forbid_mer_no = Db::name('config')->where('key_title', 'wx_hui_fu_machid')->value('key_value');
|
||||
$forbid_mer_no_arr = [];
|
||||
if(!empty($forbid_mer_no)) {
|
||||
$forbid_mer_no_arr = explode('|', $forbid_mer_no);
|
||||
}
|
||||
// 获取随机键名
|
||||
$randomKey = array_rand($forbid_mer_no_arr);
|
||||
// 获取随机元素
|
||||
$huifu_id = $forbid_mer_no_arr[$randomKey];
|
||||
$config_name = $huifu_id . '.json';
|
||||
$project_path = app()->getRootPath()."application/";
|
||||
$config_info = $project_path.'common/hui_fu/config/' . $config_name;
|
||||
if (!file_exists($config_info)) {
|
||||
return ['code' => 201, 'msg' => '暂无有效商户!', 'data' => null];
|
||||
}
|
||||
$pay_data = ['order_sn' => $order_sn, 'money' => $money, 'openid' => $open_id, 'ip' => $ip, 'hui_fu_id'=>$huifu_id];
|
||||
$payment = new HuiFuPayment($pay_data, $pay_type, $notify_url);
|
||||
$result = $payment->pay_wxgzh();
|
||||
if($result['code'] == 201) {
|
||||
return $result;
|
||||
}
|
||||
$pay_info = $result['data']['pay_info'];
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => $pay_info];
|
||||
}
|
||||
|
||||
|
||||
//支付宝H5支付
|
||||
|
||||
public function ali_h5($order_sn, $money)
|
||||
{
|
||||
|
||||
$notify_url = "http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/hui_fu_pay_notify";
|
||||
$ip = request()->ip();
|
||||
$pay_type = 41;
|
||||
|
||||
// $forbid_mer_no_arr = [];
|
||||
// if(!empty($forbid_mer_no)) {
|
||||
// $forbid_mer_no_arr = explode('|', $forbid_mer_no);
|
||||
// }
|
||||
|
||||
// // 获取随机键名
|
||||
// $randomKey = array_rand($forbid_mer_no_arr);
|
||||
// // 获取随机元素
|
||||
// $huifu_id = $forbid_mer_no_arr[$randomKey];
|
||||
|
||||
|
||||
|
||||
$huifu_id = Db::name('config')->where('key_title', 'zfb_hui_fu_machid')->value('key_value');
|
||||
|
||||
|
||||
|
||||
$config_name = $huifu_id . '.json';
|
||||
$project_path = app()->getRootPath()."application/";
|
||||
$config_info = $project_path.'common/hui_fu/config/' . $config_name;
|
||||
if (!file_exists($config_info)) {
|
||||
return ['code' => 201, 'msg' => '暂无有效商户!', 'data' => null];
|
||||
}
|
||||
|
||||
$pay_data = ['order_sn' => $order_sn, 'money' => $money,'ip' => $ip,'hui_fu_id'=>$huifu_id];
|
||||
$payment = new HuiFuPayment($pay_data, $pay_type, $notify_url);
|
||||
$result = $payment->pay();
|
||||
if($result['code'] == 201) {
|
||||
return $result;
|
||||
}
|
||||
$pay_info = $result['data'];
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => $pay_info];
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function wx_verify_sign($resp_data, $sign, $huifu_id)
|
||||
{
|
||||
$object = new HuiFuCallback($huifu_id);
|
||||
return $object->verfiy_sign($resp_data, $sign);
|
||||
|
||||
}
|
||||
}
|
||||
54
application/api/model/ImgCaptcha.php
Normal file
54
application/api/model/ImgCaptcha.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
|
||||
|
||||
use app\common\component\captcha\Captcha;
|
||||
|
||||
class ImgCaptcha
|
||||
{
|
||||
protected $config = [
|
||||
'codeSet' => '0123456789',
|
||||
// 验证码字体大小
|
||||
'fontSize' => 30,
|
||||
// 验证码位数
|
||||
'length' => 4,
|
||||
// 关闭验证码杂点
|
||||
'useNoise' => false,
|
||||
//过期时间
|
||||
'expire' => 600,
|
||||
'useCurve' => false,
|
||||
];
|
||||
//生成验证码
|
||||
public function create_captcha()
|
||||
{
|
||||
$captcha = new Captcha($this->config);
|
||||
$id = $this->generateRandom(8). date('YmdHis');
|
||||
$res = $captcha->entry($id);
|
||||
$base64_image = "data:image/png;base64," . base64_encode($res->getData());
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => ['image' => $base64_image, 'key' => $id]];
|
||||
}
|
||||
//获取随机数
|
||||
private function generateRandom($num = 0)
|
||||
{
|
||||
$code = strtolower('ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789');
|
||||
$str = '';
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
$str .= $code[mt_rand(0, strlen($code) - 1)];
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
//验证验证码
|
||||
public function check_captcha($code, $key)
|
||||
{
|
||||
$captcha = new Captcha($this->config);
|
||||
$res = $captcha->check($code, $key);
|
||||
if ($res === true) {
|
||||
return ['code' => 200, 'msg' => '验证成功', 'data' => null];
|
||||
}
|
||||
return ['code' => 201, 'msg' => '验证失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
638
application/api/model/KtvRoom.php
Normal file
638
application/api/model/KtvRoom.php
Normal file
@@ -0,0 +1,638 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class KtvRoom extends Model
|
||||
{
|
||||
|
||||
|
||||
//开始K歌活动
|
||||
public function open_auction($uid, $rid)
|
||||
{
|
||||
$config = get_uncache_system_config();
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限
|
||||
if($uid != $room_info['room_host_uid'] && $uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '您无权限进行该操作', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有人在K歌麦上
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [1,2,3,4]];
|
||||
$map[] = ['uid', '>', 0];
|
||||
$room_micro_info = db::name('room_micro')->where($map)->find();
|
||||
if(!$room_micro_info){
|
||||
return ['code' => 201, 'msg' => '当前尚未有人在麦上,无法开启', 'data' => null];
|
||||
}
|
||||
|
||||
//当前是否已有进行中的K歌
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_song_log')->where($map)->find();
|
||||
if($room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前已有进行中的,请勿重复开启', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//当前前四个麦位在线用户
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [1,2,3,4]];
|
||||
$map[] = ['uid', '>', 0];
|
||||
$uid_arr = db::name('room_micro')->where($map)->order('micro_id asc')->column('uid');
|
||||
$uid_array = implode(',', $uid_arr);
|
||||
|
||||
//添加K歌活动记录记录
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['uid_array'] = $uid_array;
|
||||
$insert['uid'] = $uid_arr[0];
|
||||
$insert['status'] = 2;
|
||||
$insert['add_time'] = time();
|
||||
$rsid = db::name('room_song_log')->insertGetId($insert);
|
||||
if(!$rsid){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开始失败', 'data' => null];
|
||||
}
|
||||
|
||||
$now_time = time();
|
||||
|
||||
$insert_data = [];
|
||||
//添加K歌麦上用户记录
|
||||
foreach ($uid_arr as $k => $v){
|
||||
$micro_id = db::name('room_micro')->where('rid', $rid)->where('uid', $v)->value('micro_id');
|
||||
|
||||
//是否有制作人
|
||||
$producer_uid = 0;
|
||||
$user_sign_contract = db::name('user_sign_contract')->where('sign_uid', $v)->where('is_delete', 1)->find();
|
||||
if($user_sign_contract){
|
||||
$producer_uid = $user_sign_contract['uid'];
|
||||
}
|
||||
|
||||
//用户身价
|
||||
$social = $config['initial_user_social'];
|
||||
$user_social = db::name('user')->where('uid', $v)->find();
|
||||
if(!empty(ceil($user_social['social']))){
|
||||
$social = $user_social['social'];
|
||||
}
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['rsid'] = $rsid;
|
||||
$insert['uid'] = $v;
|
||||
$insert['micro_id'] = $micro_id;
|
||||
$insert['producer_uid'] = $producer_uid;
|
||||
if($k == 0){
|
||||
$insert['song_start_time'] = $now_time;
|
||||
$insert['song_end_time'] = $now_time + $config['ktv_room_start_time'];
|
||||
}else{
|
||||
$insert['song_start_time'] = 0;
|
||||
$insert['song_end_time'] = 0;
|
||||
}
|
||||
$insert['start_price'] = $social;
|
||||
$insert['end_price'] = $social;
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert_data[] = $insert;
|
||||
}
|
||||
|
||||
$reslut = db::name('room_song_user_log')->insertAll($insert_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开始失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '开始成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开始失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//定时结束唱歌时间
|
||||
public function colse_room_song_user_status(){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
$map = [];
|
||||
$map[] = ['song_end_time', '>', 0];
|
||||
$map[] = ['song_end_time', '<', time()];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = db::name('room_song_user_log')->where($map)->select();
|
||||
foreach ($list as $k => $v){
|
||||
db::name('room_song_user_log')->where('id', $v['id'])->update(['status' => 2, 'update_time' => time()]);
|
||||
model('api/room')->push_room_micro_data($v['rid']);
|
||||
model('api/Agora')->user_quit_song_del($v['uid'], $v['rid']);
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').'定时结束唱歌时间 执行成功';
|
||||
|
||||
}
|
||||
|
||||
//送礼物增加唱歌时长
|
||||
public function send_gift_add_song_time($uid, $user_id, $rid, $gid, $num, $total_gift_price){
|
||||
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
$map[] = ['song_start_time', '>', 0];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_song_user_log = db::name('room_song_user_log')->where($map)->find();
|
||||
if($room_song_user_log){
|
||||
$surplus_time = $room_song_user_log['song_end_time'] - $room_song_user_log['song_start_time'];
|
||||
$max_time = $room_song_user_log['song_start_time'] + 300;
|
||||
if($room_song_user_log['song_end_time'] > time() && $room_song_user_log['song_end_time'] < $max_time){
|
||||
$add_time = ceil($total_gift_price/10) * 2;
|
||||
if($add_time > 0){
|
||||
$song_add_time = $room_song_user_log['song_end_time'] + $add_time;
|
||||
if($song_add_time > $max_time){
|
||||
$song_add_time = $max_time;
|
||||
}
|
||||
|
||||
//增加唱歌时长
|
||||
$reslut = db::name('room_song_user_log')->where('id', $room_song_user_log['id'])->update(['song_end_time' => $song_add_time, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
//记录
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['user_id'] = $user_id;
|
||||
$insert['gid'] = $gid;
|
||||
$insert['num'] = $num;
|
||||
$insert['total_price'] = $total_gift_price;
|
||||
$insert['song_time'] = $song_add_time;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_room_song_time')->insert($insert);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => null];
|
||||
}
|
||||
|
||||
//用户出价
|
||||
public function user_auction_price($uid, $rid, $user_id, $price){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//该价位是否存在
|
||||
$auction_price = db::name('auction_price')->where('price', $price)->where('is_delete', 1)->find();
|
||||
if(!$auction_price){
|
||||
return ['code' => 201, 'msg' => '该加价信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid == $user_id){
|
||||
return ['code' => 201, 'msg' => '自己不能竞拍自己', 'data' => null];
|
||||
}
|
||||
|
||||
//当前拍卖信息
|
||||
$room_song_log = db::name('room_song_log')->where('rid', $rid)->where('is_delete', 1)->find();
|
||||
if(!$room_song_log){
|
||||
return ['code' => 201, 'msg' => '当前尚未开始', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否处于竞拍阶段
|
||||
$room_song_user_log = db::name('room_song_user_log')->where('rsid', $room_song_log['id'])->where('uid', $user_id)->where('is_delete', 1)->find();
|
||||
if(!$room_song_user_log){
|
||||
return ['code' => 201, 'msg' => '跟当前用户不符', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_song_user_log['status'] != 2){
|
||||
return ['code' => 201, 'msg' => '当前尚未处于签约阶段', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//当前竞拍价
|
||||
$now_auction_price = $room_song_user_log['end_price'];
|
||||
|
||||
//当前用户金额是否可以加价
|
||||
$user_auction_price = model('NewRoom')->get_user_auction_price($uid);
|
||||
if($user_info['integral'] < ($user_auction_price + $price + $now_auction_price)){
|
||||
return ['code' => 201, 'msg' => '您当前的金币不足以加价', 'data' => null];
|
||||
}
|
||||
|
||||
//用户加价信息
|
||||
$user_auction_info = db::name('user_room_song_auction')->where('rsid', $room_song_log['id'])->where('auction_uid', $uid)->where('uid', $user_id)->find();
|
||||
if($user_auction_info){
|
||||
$update = [];
|
||||
$update['price'] = $now_auction_price + $price;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_room_song_auction')->where('id', $user_auction_info['id'])->update($update);
|
||||
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['rsid'] = $room_song_log['id'];
|
||||
$insert['uid'] = $user_id;
|
||||
$insert['auction_uid'] = $uid;
|
||||
$insert['price'] = $now_auction_price + $price;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_room_song_auction')->insert($insert);
|
||||
|
||||
}
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '加价失败', 'data' => null];
|
||||
}
|
||||
|
||||
//用户加价记录
|
||||
$insert_data = [];
|
||||
$insert_data['rsid'] = $room_song_log['id'];
|
||||
$insert_data['rid'] = $rid;
|
||||
$insert_data['auction_uid'] = $uid;
|
||||
$insert_data['uid'] = $user_id;
|
||||
$insert_data['now_price'] = $now_auction_price;
|
||||
$insert_data['price'] = $price;
|
||||
$insert_data['add_time'] = time();
|
||||
$reslut = db::name('user_room_song_auction_log')->insert($insert_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
//修改当前用户当前最高竞拍价
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_song_user_log')->where('id', $room_song_user_log['id'])->inc('end_price', $price)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
//是否提醒制作人
|
||||
$is_push = 2;
|
||||
if(!empty($room_song_user_log['producer_uid'])){
|
||||
$producer_info = db::name('user')->where('uid', $room_song_user_log['producer_uid'])->find();
|
||||
if($producer_info){
|
||||
$send_producer_message = db::name('send_producer_message')->where('rsid', $room_song_log['id'])->where('uid', $user_id)->where('producer_uid', $room_song_user_log['producer_uid'])->find();
|
||||
if(empty($send_producer_message)){
|
||||
$insert = [];
|
||||
$insert['rsid'] = $room_song_log['id'];
|
||||
$insert['uid'] = $user_id;
|
||||
$insert['producer_uid'] = $room_song_user_log['producer_uid'];
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('send_producer_message')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
$is_push = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
//提醒制作人
|
||||
if($is_push == 1){
|
||||
$push_message = [];
|
||||
$push_message['rid'] = $rid;
|
||||
|
||||
//提示制作人自己的艺人被拍
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3010;
|
||||
$push_data['msg'] = "提示制作人自己的艺人被拍";
|
||||
$push_data['data'] = $push_message;
|
||||
model('api/WebSocketPush')->send_to_one($room_song_user_log['producer_uid'], $push_data);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '加价成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '加价失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//结束K歌活动
|
||||
public function finish_auction($uid, $rid, $user_id){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$user_id_info = db::name('user')->find($user_id);
|
||||
if(!$user_id_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限结束
|
||||
if($room_info['room_host_uid'] != $uid){
|
||||
return ['code' => 201, 'msg' => '当前麦上主持才可结束', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的K歌活动
|
||||
$room_song_log = db::name('room_song_log')->where('rid', $rid)->where('is_delete', 1)->find();
|
||||
if(!$room_song_log){
|
||||
return ['code' => 201, 'msg' => '当前尚未开始', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否处于竞拍阶段
|
||||
$room_song_user_log = db::name('room_song_user_log')->where('rsid', $room_song_log['id'])->where('uid', $user_id)->where('is_delete', 1)->find();
|
||||
if(!$room_song_user_log){
|
||||
return ['code' => 201, 'msg' => '跟当前用户不符', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_song_user_log['status'] != 2){
|
||||
return ['code' => 201, 'msg' => '当前尚未处于签约阶段', 'data' => null];
|
||||
}
|
||||
|
||||
//
|
||||
Db::startTrans();
|
||||
try {
|
||||
$now_time = time();
|
||||
|
||||
//是否有最高出价
|
||||
$user_room_song_auction = db::name('user_room_song_auction')->where('rsid', $room_song_log['id'])->where('uid', $user_id)->order('price desc')->limit(1)->find();
|
||||
if(empty($user_room_song_auction)){//流拍
|
||||
//当前用户K歌拍卖结束
|
||||
$reslut = db::name('room_song_user_log')->where('id', $room_song_user_log['id'])->update(['status' => 3, 'is_delete' => 2, 'update_time' => time(), 'end_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 2;
|
||||
}else{//签约
|
||||
|
||||
//是否何他签过约
|
||||
$user_sign_contract = db::name('user_sign_contract')->where('uid', $user_room_song_auction['auction_uid'])->where('sign_uid', $user_room_song_auction['uid'])->where('is_delete',1)->find();
|
||||
if(!empty($user_sign_contract)){
|
||||
$update = [];
|
||||
$update['price'] = $user_room_song_auction['price'];
|
||||
$update['end_time'] = $user_sign_contract['end_time'] + (60*60*24*7);
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_sign_contract')->where('id', $user_sign_contract['id'])->update($update);
|
||||
}else{
|
||||
//解除该用户之前的签约
|
||||
$last_sign_contract = db::name('user_sign_contract')->where('sign_uid', $user_room_song_auction['uid'])->where('is_delete', 1)->find();
|
||||
if(!empty($last_sign_contract)){
|
||||
$reslut = db::name('user_sign_contract')->where('id', $last_sign_contract['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
$insert['uid'] = $user_room_song_auction['auction_uid'];
|
||||
$insert['sign_uid'] = $user_room_song_auction['uid'];
|
||||
$insert['price'] = $user_room_song_auction['price'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['end_time'] = $now_time + (60*60*24*7);
|
||||
$reslut = db::name('user_sign_contract')->insert($insert);
|
||||
|
||||
}
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//修改用户身价及是否签约
|
||||
$reslut = db::name('user')->where('uid', $user_room_song_auction['uid'])->update(['social' => $user_room_song_auction['price'], 'is_sign' => 1, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//修改用户制作人身份
|
||||
$is_producer = db::name('user')->where('uid', $user_room_song_auction['auction_uid'])->value('is_producer');
|
||||
if($is_producer == 2){
|
||||
$reslut = db::name('user')->where('uid', $user_room_song_auction['auction_uid'])->update(['is_producer' => 1, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//扣除拍卖人的金币
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($user_room_song_auction['auction_uid'], -$user_room_song_auction['price'], 2, 24, "拍卖签约扣除金币", $user_room_song_auction['auction_uid'], 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//签约用户是否有制作人,扣除百分之十给前制作人
|
||||
if(!empty($room_song_user_log['producer_uid'])){
|
||||
$producer_price = $user_room_song_auction['price'] * 0.9;
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_song_user_log['producer_uid'], $producer_price, 2, 26, "前制作人获取签约用户被拍金币", $room_song_user_log['producer_uid'], 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//当前用户K歌拍卖结束
|
||||
$reslut = db::name('room_song_user_log')->where('id', $room_song_user_log['id'])->update(['auction_uid' => $user_room_song_auction['auction_uid'], 'end_price' => $user_room_song_auction['price'],'status' => 3, 'is_delete' => 2, 'update_time' => time(), 'end_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 1;
|
||||
}
|
||||
|
||||
//新人签约用户唱前三首歌获取收益
|
||||
$user_new_time = $user_id_info['add_time'] + (60*60*24*7);
|
||||
// if($user_new_time > $now_time){
|
||||
// //是否是前三首歌
|
||||
// $user_song_count = db::name('room_song_user_log')->where('uid', $user_id)->where('status', 3)->where('is_delete', 2)->count();
|
||||
// if($user_song_count < 3){
|
||||
// $user_song_money = 1;
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($user_id, $user_song_money, 1, 27, "新人签约唱歌获取金币", $user_id, 0, $rid);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//是否有下一个用户
|
||||
$next_user_song_auction = db::name('room_song_user_log')->where('rsid', $room_song_log['id'])->where('is_delete', 1)->order('micro_id asc')->find();
|
||||
if(!empty($next_user_song_auction)){//有则进行下一个
|
||||
$update = [];
|
||||
$update['song_start_time'] = $now_time;
|
||||
$update['song_end_time'] = $now_time + $config['ktv_room_start_time'];
|
||||
$update['update_time'] = $now_time;
|
||||
$reslut = db::name('room_song_user_log')->where('id', $next_user_song_auction['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('room_song_log')->where('id', $room_song_log['id'])->update(['uid' => $next_user_song_auction['uid'], 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
}else{//没有则结束该活动
|
||||
$reslut = db::name('room_song_log')->where('id', $room_song_log['id'])->update(['uid' => 0, 'status' => 3, 'update_time' => time(), 'is_delete' => 2]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//拍卖用户下麦
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [1,2,3,4]];
|
||||
$map[] = ['uid', '>', 0];
|
||||
$reslut = db::name('room_micro')->where($map)->update(['uid' => 0, 'frame_gid' => 0, 'centre_gid' => 0, 'above_gid' => 0, 'below_gid' => 0, 'left_gid'=> 0, 'right_gid' => 0, 'update_time' => time()]);
|
||||
// if(!$reslut){
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => '结束失败10', 'data' => null];
|
||||
// }
|
||||
|
||||
//更新老板麦位
|
||||
model('RoomBossMicro')->update_room_boss_micro($rid);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
if($is_push == 1){
|
||||
$auction_user_info = db::name('user')->find($user_room_song_auction['auction_uid']);
|
||||
$sign_user_info = db::name('user')->find($user_room_song_auction['uid']);
|
||||
|
||||
$push_message = [];
|
||||
$push_message['auction_user_info']['uid'] = $user_room_song_auction['auction_uid'];
|
||||
$push_message['auction_user_info']['nick_name'] = mb_convert_encoding(base64_decode($auction_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['auction_user_info']['head_pic'] = localpath_to_netpath($auction_user_info['head_pic']);
|
||||
$push_message['sign_user_info']['uid'] = $user_room_song_auction['uid'];
|
||||
$push_message['sign_user_info']['nick_name'] = mb_convert_encoding(base64_decode($sign_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['sign_user_info']['head_pic'] = localpath_to_netpath($sign_user_info['head_pic']);
|
||||
|
||||
//提示签约成功
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3012;
|
||||
$push_data['msg'] = "签约成功";
|
||||
$push_data['data'] = $push_message;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '结束成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//结束当前用户唱歌阶段
|
||||
public function finish_user_song($uid, $rid, $user_id){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$user_id_info = db::name('user')->find($user_id);
|
||||
if(!$user_id_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限结束
|
||||
if($room_info['room_host_uid'] != $uid){
|
||||
return ['code' => 201, 'msg' => '当前麦上主持才可操作', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的K歌活动
|
||||
$room_song_log = db::name('room_song_log')->where('rid', $rid)->where('is_delete', 1)->find();
|
||||
if(!$room_song_log){
|
||||
return ['code' => 201, 'msg' => '当前尚未开始', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否处于竞拍阶段
|
||||
$room_song_user_log = db::name('room_song_user_log')->where('rsid', $room_song_log['id'])->where('uid', $user_id)->where('is_delete', 1)->find();
|
||||
if(!$room_song_user_log){
|
||||
return ['code' => 201, 'msg' => '跟当前用户不符', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_song_user_log['status'] != 1){
|
||||
return ['code' => 201, 'msg' => '当前尚未处于唱歌阶段', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$reslut = db::name('room_song_user_log')->where('id', $room_song_user_log['id'])->update(['status' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
Db::commit();
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
model('api/Agora')->user_quit_song_del($user_id, $rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
742
application/api/model/Monster.php
Normal file
742
application/api/model/Monster.php
Normal file
@@ -0,0 +1,742 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Monster extends Model
|
||||
{
|
||||
|
||||
//选择金币列表
|
||||
public function choice_gold_list(){
|
||||
$list = db::name('monster_multiple')->field('multiple')->select();
|
||||
|
||||
$data = [];
|
||||
$data['list'] = $list;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
|
||||
}
|
||||
|
||||
|
||||
//当前国王游戏详情
|
||||
public function get_monster_info($uid){
|
||||
$config = get_uncache_system_config();
|
||||
$user_info = db::name('user')->field('uid, integral')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$now_time = time();
|
||||
|
||||
$data = [];
|
||||
$data['surplus_time'] = 0;
|
||||
$data['is_finsh'] = 3;
|
||||
$data['win_number'] = 0;
|
||||
// $data['list'] = [];
|
||||
$data['open_monster_price'] = $config['open_monster_price'];
|
||||
$data['integral'] = $user_info['integral'];
|
||||
$data['multiple_list'] = db::name('monster')->field('id,type,type_name,multiple')->order('id asc')->select();
|
||||
foreach ($data['multiple_list'] as $a => &$b){
|
||||
$b['num'] = 0;
|
||||
}
|
||||
//当前是否有开放该活动
|
||||
$monster_log = db::name('monster_log')->order('id desc')->limit(1)->find();
|
||||
if(empty($monster_log)){
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}else{
|
||||
if($monster_log['end_time'] <= $now_time){
|
||||
$is_finish = 1;
|
||||
$data['win_number'] = $monster_log['win_type'];
|
||||
}else{
|
||||
$is_finish = 2;
|
||||
$data['surplus_time'] = $monster_log['end_time'] - $now_time;
|
||||
}
|
||||
$data['is_finsh'] = $is_finish;
|
||||
foreach ($data['multiple_list'] as $a => &$b){
|
||||
$user_monster_feed_log = db::name('user_monster_log')->where('uid', $uid)->where('mid', $monster_log['id'])->where('type', $b['type'])->find();
|
||||
// dump($user_monster_feed_log);
|
||||
if(!empty($user_monster_feed_log)){
|
||||
$b['num'] = $user_monster_feed_log['num'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//当前参与用户探索列表
|
||||
// $list = db::name('user_monster_feed_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_monster c', 'a.type = c.type')->where('a.mid', $monster_log['id'])->field('a.id,b.uid,b.nick_name,b.base64_nick_name,b.head_pic,c.type_name,a.price')->order('a.id desc')->select();
|
||||
// foreach ($list as $k => &$v){
|
||||
// $v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
// }
|
||||
// $data['list'] = $list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
//生成当前国王游戏期数
|
||||
public function create_monster_log(){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
$config = get_uncache_system_config();
|
||||
$now_time = time();
|
||||
$is_push = 5;//不推送
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$monster_log = db::name('monster_log')->where($map)->find();
|
||||
if($monster_log){//当前有未结束的国王游戏期数
|
||||
if($now_time >= $monster_log['end_time']){
|
||||
$redis = connectionRedis();
|
||||
$key_name = "api:monster:create_monster_log:id".$monster_log['id'];
|
||||
$redis_order_sn = redis_lock_exits($key_name,1,7);
|
||||
if(!$redis_order_sn){
|
||||
return ['code' => 201, 'msg' => '请重试1', 'data' => null];
|
||||
}
|
||||
|
||||
$win_type = $monster_log['win_type'];
|
||||
$in_amount = 0;
|
||||
|
||||
$win_type = $this->check_win_type_is_loss($win_type, $monster_log);
|
||||
|
||||
$win_gift_info = db::name('gift')->alias('a')->join('yy_monster b', 'a.gid = b.gid')->where('b.type', $win_type)->field('a.gid,a.gift_name,a.gift_price,a.base_image,b.multiple')->find();
|
||||
|
||||
//获取得奖用户ID
|
||||
$map = [];
|
||||
$map[] = ['mid', '=', $monster_log['id']];
|
||||
$part_user_array = db::name('user_monster_log')->where($map)->group('uid')->column('uid');
|
||||
$map[] = ['type', '=', $win_type];
|
||||
$user_array = db::name('user_monster_log')->where($map)->group('uid')->column('uid');
|
||||
if(!empty($user_array)){
|
||||
//有获奖用户
|
||||
$insert_all = [];
|
||||
foreach ($user_array as $a => $b){
|
||||
$map = [];
|
||||
$map[] = ['mid', '=', $monster_log['id']];
|
||||
$map[] = ['uid', '=', $b];
|
||||
$map[] = ['type', '=', $win_type];
|
||||
$user_monster_log = db::name('user_monster_log')->where($map)->find();
|
||||
|
||||
$wim_num = floor($user_monster_log['price'] * $win_gift_info['multiple'] / $win_gift_info['gift_price']);
|
||||
|
||||
$in_amount += $win_gift_info['gift_price'] * $wim_num;
|
||||
|
||||
//礼物送到背包
|
||||
$reslut = model('api/UserGiftPack')->change_user_gift_pack($b, $win_gift_info['gid'], $wim_num, 4, '国王游戏中奖获取');
|
||||
if($reslut['code'] ==201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//用户中奖信息
|
||||
$insert = [];
|
||||
$insert['uid'] = $b;
|
||||
$insert['rid'] = $user_monster_log['rid'];
|
||||
$insert['mid'] = $monster_log['id'];
|
||||
$insert['win_type'] = $win_type;
|
||||
$insert['win_gid'] = $win_gift_info['gid'];
|
||||
$insert['price'] = $user_monster_log['price'];
|
||||
$insert['num'] = $wim_num;
|
||||
$insert['add_time'] = time();
|
||||
$insert_all[] = $insert;
|
||||
|
||||
}
|
||||
|
||||
$reslut = db::name('user_monster_win_log')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试2', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//结束当前抽卡期数
|
||||
$update = [];
|
||||
$update['win_type'] = $win_type;
|
||||
$update['in_amount'] = $in_amount;
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('monster_log')->where('id', $monster_log['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试3', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 2;
|
||||
}
|
||||
}else{//当前未有国王游戏期数
|
||||
if($config['open_monster_status'] != 1){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '国王游戏已关闭', 'data' => null];
|
||||
}
|
||||
|
||||
//距离上次多长时间
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 2];
|
||||
$last_monster_log = db::name('monster_log')->where($map)->order('id desc')->limit(1)->find();
|
||||
if($last_monster_log){
|
||||
// $interval_time = $last_monster_log['end_time'] + 10 + $config['end_interval_time'];
|
||||
$interval_time = time() - $last_monster_log['end_time'];
|
||||
if($interval_time < $config['end_interval_time']){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '距离上次结束尚未超过'.$config['end_interval_time'].'秒', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//当前国王游戏配置信息
|
||||
$monster_list = db::name('monster')->order('id asc')->select();
|
||||
$monster_data = '';
|
||||
$total_num = 0;
|
||||
$win_number_data = [];
|
||||
foreach ($monster_list as $a => $b){
|
||||
$da = $b['id'].'-'.$b['gid'].'-'.$b['num'].';';
|
||||
$monster_data .= $da;
|
||||
$total_num += $b['num'];
|
||||
for($i = 0; $i < $b['num']; $i++){
|
||||
$win_number_data[] = $b['id'];
|
||||
}
|
||||
}
|
||||
|
||||
shuffle($win_number_data);
|
||||
$win_key = array_rand($win_number_data);
|
||||
//随机抽取中奖数字
|
||||
$win_type = $win_number_data[$win_key];
|
||||
|
||||
//生成最新
|
||||
$insert = [];
|
||||
$insert['win_type'] = $win_type;
|
||||
$insert['total_num'] = $total_num;
|
||||
$insert['config_text'] = $monster_data;
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['end_time'] = $now_time + $config['monster_count_down_time'];
|
||||
$reslut = db::name('monster_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '生成失败', 'data' => null];
|
||||
}
|
||||
$is_push = 1;//开启推送
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
if($is_push == 1){
|
||||
$push_feed_monster_data = $this->get_new_feed_monster_info();
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3031;
|
||||
$push_data['msg'] = "探索开始播报";
|
||||
$push_data['data'] = $push_feed_monster_data;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
}else if($is_push == 2){
|
||||
$push_feed_monster_data = $this->get_new_feed_monster_info();
|
||||
$push_feed_monster_data['win_count'] = count($user_array);
|
||||
$push_feed_monster_data['game_name'] = '国王游戏';
|
||||
$push_feed_monster_data['win_type_name'] = db::name('monster')->where('type', $win_type)->value('type_name');
|
||||
$push_feed_monster_data['gift_name'] = $win_gift_info['gift_name'];
|
||||
$push_feed_monster_data['num'] = 0;
|
||||
$push_feed_monster_data['total_gift_price'] = 0;
|
||||
$push_feed_monster_data['is_push_message'] = 2;
|
||||
|
||||
if(!empty($part_user_array)){
|
||||
foreach ($part_user_array as $k => $v){
|
||||
$push_user_monster_data = [];
|
||||
$push_user_monster_data['win_type'] = $win_type;
|
||||
$push_user_monster_data['type_name'] = db::name('monster')->where('type', $win_type)->value('type_name');
|
||||
//是否中奖
|
||||
$map = [];
|
||||
$map[] = ['mid', '=', $monster_log['id']];
|
||||
$map[] = ['uid', '=', $v];
|
||||
$user_win_info = db::name('user_monster_win_log')->where($map)->find();
|
||||
if($user_win_info){//中奖
|
||||
$push_user_monster_data['is_win'] = 1;
|
||||
$push_user_monster_data['gid'] = $win_gift_info['gid'];
|
||||
$push_user_monster_data['gift_name'] = $win_gift_info['gift_name'];
|
||||
$push_user_monster_data['base_image'] = localpath_to_netpath($win_gift_info['base_image']);
|
||||
$push_user_monster_data['gift_price'] = $win_gift_info['gift_price'];
|
||||
$push_user_monster_data['num'] = $user_win_info['num'];
|
||||
$push_user_monster_data['total_gift_price'] = $win_gift_info['gift_price'] * $user_win_info['num'];
|
||||
$push_feed_monster_data['num'] += $user_win_info['num'];
|
||||
$push_feed_monster_data['total_gift_price'] += $push_user_monster_data['total_gift_price'];
|
||||
}else{//未中奖
|
||||
$push_user_monster_data['is_win'] = 2;
|
||||
$push_user_monster_data['gid'] = 0;
|
||||
$push_user_monster_data['gift_name'] = '';
|
||||
$push_user_monster_data['base_image'] = '';
|
||||
$push_user_monster_data['gift_price'] = 0;
|
||||
$push_user_monster_data['num'] = 0;
|
||||
}
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3032;
|
||||
$push_data['msg'] = "抽卡个人结束播报";
|
||||
$push_data['data'] = $push_user_monster_data;
|
||||
$reslut = model('api/WebSocketPush')->send_to_one($v, $push_data);
|
||||
// error_log(date('Y-m-d H:i:s').'_'.$v.'_'.$reslut."\r\n", 3, '1111.txt');
|
||||
}
|
||||
}
|
||||
|
||||
if($push_feed_monster_data['num'] > 0){
|
||||
$push_feed_monster_data['is_push_message'] = 1;
|
||||
}
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3033;
|
||||
$push_data['msg'] = "探索结束播报";
|
||||
$push_data['data'] = $push_feed_monster_data;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
|
||||
// $close_data = $this->get_close_monster_win_log();
|
||||
// $push_colse_data = [];
|
||||
// $push_colse_data['code'] = 3034;
|
||||
// $push_colse_data['msg'] = "国王游戏结束播报";
|
||||
// $push_colse_data['data'] = $close_data;
|
||||
// model('api/WebSocketPush')->send_to_all($push_colse_data);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//当前最新探索信息
|
||||
public function get_new_feed_monster_info(){
|
||||
$now_time = time();
|
||||
|
||||
$data = [];
|
||||
$data['surplus_time'] = 0;
|
||||
$data['is_finsh'] = 3;
|
||||
$data['win_number'] = 0;
|
||||
// $data['list'] = [];
|
||||
$data['multiple_list'] = db::name('monster')->field('id,type,type_name,multiple')->order('id asc')->select();
|
||||
|
||||
//当前是否有开放该活动
|
||||
$monster_log = db::name('monster_log')->order('id desc')->limit(1)->find();
|
||||
if(empty($monster_log)){
|
||||
return $data;
|
||||
}else{
|
||||
if($monster_log['end_time'] <= $now_time){
|
||||
$is_finish = 1;
|
||||
$data['win_number'] = $monster_log['win_type'];
|
||||
}else{
|
||||
$is_finish = 2;
|
||||
$data['surplus_time'] = $monster_log['end_time'] - $now_time;
|
||||
}
|
||||
$data['is_finsh'] = $is_finish;
|
||||
}
|
||||
|
||||
//当前参与用户探索列表
|
||||
// $list = db::name('user_monster_feed_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_monster c', 'a.type = c.type')->where('a.mid', $monster_log['id'])->field('a.id,b.uid,b.nick_name,b.base64_nick_name,b.head_pic,c.type_name,a.price')->order('a.id desc')->select();
|
||||
// foreach ($list as $k => &$v){
|
||||
// $v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
// }
|
||||
// $data['list'] = $list;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
//国王游戏
|
||||
public function open_beat_monster($uid, $rid, $type, $num){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$config = get_uncache_system_config();
|
||||
$now_time = time();
|
||||
|
||||
$monster = db::name('monster')->where('type', $type)->find();
|
||||
if(!$monster){
|
||||
return ['code' => 201, 'msg' => '当前类型不存在', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
$map = [];
|
||||
$map[] = ['end_time', '>', time()];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$monster_log = db::name('monster_log')->where($map)->find();
|
||||
if(!$monster_log){
|
||||
return ['code' => 201, 'msg' => '请等待新一轮开启', 'data' => null];
|
||||
}else{
|
||||
$surplus_time = $monster_log['end_time'] - 5;
|
||||
if($surplus_time < time()){
|
||||
return ['code' => 201, 'msg' => '最后五秒内无法参与', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if($user_info['is_tester'] != 1){
|
||||
return ['code' => 201, 'msg' => '虚拟号无法参与', 'data' => null];
|
||||
}
|
||||
|
||||
if($num < 1){
|
||||
return ['code' => 201, 'msg' => '次数不能小于1', 'data' => null];
|
||||
}
|
||||
|
||||
//该星途已探索多少次数
|
||||
$map = [];
|
||||
$map[] = ['mid', '=', $monster_log['id']];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$user_type_num = db::name('user_monster_log')->where($map)->column('type');
|
||||
$map[] = ['type', '=', $type];
|
||||
$user_monster_num = db::name('user_monster_log')->where($map)->sum('num');
|
||||
if($user_monster_num > 0){
|
||||
if($user_monster_num + $num > $config['open_monster_max_num']){
|
||||
return ['code' => 201, 'msg' => '该玩法次数已达上限', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
if($num > $config['open_monster_max_num']){
|
||||
return ['code' => 201, 'msg' => '该玩法次数已达上限', 'data' => null];
|
||||
}
|
||||
}
|
||||
$user_monster_log = db::name('user_monster_log')->where($map)->find();
|
||||
|
||||
if(count($user_type_num) >= 6 && !in_array($type, $user_type_num)){
|
||||
return ['code' => 201, 'msg' => '玩法类型不能大于六个', 'data' => null];
|
||||
}
|
||||
|
||||
// $open_monster_ticket = $config['open_monster_ticket'];
|
||||
// $pay_ticket = $num * $open_monster_ticket;
|
||||
// if($user_info['had_ticket_num'] < $pay_ticket){
|
||||
// return ['code' => 201, 'msg' => '用户剩余门票数不足', 'data' => null];
|
||||
// }
|
||||
$money = $num * $config['open_monster_price'];
|
||||
if($user_info['integral'] < $money){
|
||||
return ['code' => 201, 'msg' => '金币不足', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
//扣除用户金币
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$money, 2, 63, "国王游戏玩法扣除金币", $uid, 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//是否探索过
|
||||
if($user_monster_log){//已探索则继续
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_monster_log')->where('id', $user_monster_log['id'])->inc('num', $num)->inc('price', $money)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}else{//未探索则探索
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['rid'] = $rid;
|
||||
$insert['mid'] = $monster_log['id'];
|
||||
$insert['type'] = $type;
|
||||
$insert['num'] = $num;
|
||||
$insert['price'] = $money;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_monster_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//用户探索记录表
|
||||
$insert_data = [];
|
||||
$insert_data['uid'] = $uid;
|
||||
$insert_data['rid'] = $rid;
|
||||
$insert_data['mid'] = $monster_log['id'];
|
||||
$insert_data['type'] = $type;
|
||||
$insert_data['num'] = $num;
|
||||
$insert_data['price'] = $money;
|
||||
$insert_data['add_time'] = time();
|
||||
$fid = db::name('user_monster_feed_log')->insertGetId($insert_data);
|
||||
if(!$fid){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//计入当期支出累消
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('monster_log')->where('id', $monster_log['id'])->inc('out_amount', $money)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
$push_feed_monster_data = [];
|
||||
$push_feed_monster_data['id'] = $fid;
|
||||
$push_feed_monster_data['uid'] = $uid;
|
||||
$push_feed_monster_data['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_feed_monster_data['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$push_feed_monster_data['type'] = $type;
|
||||
$push_feed_monster_data['type_name'] = db::name('monster')->where('type', $type)->value('type_name');
|
||||
$push_feed_monster_data['price'] = $money;
|
||||
$push_feed_monster_data['num'] = db::name('user_monster_log')->where('mid',$monster_log['id'])->where('uid', $uid)->where('type', $type)->sum('num');
|
||||
// $push_feed_monster_data['pay_ticket'] = $pay_ticket;
|
||||
$push_feed_monster_data['integral'] = db::name('user')->where('uid', $uid)->value('integral');
|
||||
// $push_data = [];
|
||||
// $push_data['code'] = 334;
|
||||
// $push_data['msg'] = "探索公屏播报";
|
||||
// $push_data['data'] = $push_feed_monster_data;
|
||||
// model('api/WebSocketPush')->send_to_all($push_data);
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '探索成功', 'data' => $push_feed_monster_data];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
// dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '探索失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//规则
|
||||
public function get_monster_note(){
|
||||
$config = get_uncache_system_config();
|
||||
$note = $config['monster_feed_note'];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $note];
|
||||
|
||||
}
|
||||
|
||||
//奖池
|
||||
public function get_monster_box_list(){
|
||||
$monster_gift_list = db::name('monster')->alias('a')->join('yy_gift b', 'a.gid = b.gid')->field('a.gid,b.base_image,b.gift_name,b.gift_price')->order('b.gift_price asc')->select();
|
||||
foreach ($monster_gift_list as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $monster_gift_list];
|
||||
}
|
||||
|
||||
//开奖记录
|
||||
public function get_monster_log($uid, $page, $page_limit){
|
||||
$user_info = db::name('user')->field('uid')->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.is_delete', '=', 2];
|
||||
$monster_list = db::name('monster_log')->alias('a')->join('yy_monster b', 'a.win_type = b.type')->field('a.id,a.win_type,b.type_name,a.add_time')->where($map)->order('a.id desc')->page($page, $page_limit)->select();
|
||||
foreach ($monster_list as $k => &$v){
|
||||
$v['is_join'] = 3;
|
||||
$v['gift_name'] = '';
|
||||
$v['base_image'] = '';
|
||||
$v['gift_price'] = 0;
|
||||
$v['num'] = 0;
|
||||
$user_monster_log = db::name('user_monster_log')->where('uid', $uid)->where('mid', $v['id'])->find();
|
||||
if($user_monster_log){
|
||||
$v['is_join'] = 2;
|
||||
$user_monster_win_log = db::name('user_monster_win_log')->where('uid', $uid)->where('mid', $v['id'])->find();
|
||||
if($user_monster_win_log){
|
||||
$v['is_join'] = 1;
|
||||
$gift_info = db::name('gift')->find($user_monster_win_log['win_gid']);
|
||||
$v['gift_name'] = $gift_info['gift_name'];
|
||||
$v['base_image'] = localpath_to_netpath($gift_info['base_image']);
|
||||
$v['gift_price'] = $gift_info['gift_price'];
|
||||
$v['num'] = $user_monster_win_log['num'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $monster_list];
|
||||
}
|
||||
|
||||
//我的记录
|
||||
public function get_user_monster_log($uid, $page, $page_limit){
|
||||
$user_info = db::name('user')->field('uid')->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
// $map = [];
|
||||
// $map[] = ['a.uid', '=', $uid];
|
||||
$user_monster_log = db::name('user_monster_win_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->join('yy_monster c', 'a.win_type = c.type')->join('yy_gift d', 'd.gid = a.win_gid')->field('a.id,a.mid,b.uid,b.nick_name,b.base64_nick_name,b.head_pic,a.win_type,c.type_name,d.gift_name,d.base_image,d.gift_price,a.num,a.add_time')->order('a.id desc')->page($page, $page_limit)->select();
|
||||
foreach ($user_monster_log as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_monster_log];
|
||||
}
|
||||
|
||||
|
||||
//是否修改中奖类型
|
||||
public function check_win_type_is_loss($win_type, $monster_log){
|
||||
$config = get_uncache_system_config();
|
||||
//当前亏损数值是否大于
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 2];
|
||||
$map[] = ['out_amount', '>', 0];
|
||||
$now_monster_out_amount = db::name('monster_log')->where($map)->sum('out_amount');//投入
|
||||
$now_monster_in_amount = db::name('monster_log')->where($map)->sum('in_amount');//产出
|
||||
|
||||
//获取得奖用户ID
|
||||
$map = [];
|
||||
$map[] = ['mid', '=', $monster_log['id']];
|
||||
$map[] = ['type', '=', $win_type];
|
||||
$user_array = db::name('user_monster_log')->where($map)->group('uid')->column('uid');
|
||||
|
||||
if(!empty($user_array)){
|
||||
$wim_monster = db::name('monster')->where('type', $win_type)->find();
|
||||
$in_amount = 0;
|
||||
foreach ($user_array as $a => $b){
|
||||
$map = [];
|
||||
$map[] = ['mid', '=', $monster_log['id']];
|
||||
$map[] = ['uid', '=', $b];
|
||||
$map[] = ['type', '=', $win_type];
|
||||
$user_monster_log = db::name('user_monster_log')->where($map)->find();
|
||||
|
||||
//中奖金额
|
||||
$win_price = $user_monster_log['price'] * $wim_monster['multiple'];
|
||||
|
||||
$in_amount += $win_price;
|
||||
}
|
||||
|
||||
$profit = ($now_monster_in_amount + $in_amount) - ($now_monster_out_amount + $monster_log['out_amount']);
|
||||
if($profit > $config['monster_max_loss_price']){//亏损大于3w
|
||||
$type_price_1 = db::name('user_monster_log')->where('mid', $monster_log['id'])->where('type', 1)->sum('price');
|
||||
$win_type_amount_1 = $type_price_1 * 2;
|
||||
$type_price_2 = db::name('user_monster_log')->where('mid', $monster_log['id'])->where('type', 2)->sum('price');
|
||||
$win_type_amount_2 = $type_price_2 * 4;
|
||||
$type_price_3 = db::name('user_monster_log')->where('mid', $monster_log['id'])->where('type', 3)->sum('price');
|
||||
$win_type_amount_3 = $type_price_3 * 6.5;
|
||||
$type_price_4 = db::name('user_monster_log')->where('mid', $monster_log['id'])->where('type', 4)->sum('price');
|
||||
$win_type_amount_4 = $type_price_4 * 10;
|
||||
$type_price_5 = db::name('user_monster_log')->where('mid', $monster_log['id'])->where('type', 5)->sum('price');
|
||||
$win_type_amount_5 = $type_price_5 * 15;
|
||||
$type_price_6 = db::name('user_monster_log')->where('mid', $monster_log['id'])->where('type', 6)->sum('price');
|
||||
$win_type_amount_6 = $type_price_6 * 20;
|
||||
// $type_price_6 = db::name('user_monster_log')->where('mid', $monster_log['id'])->where('type', 6)->sum('price');
|
||||
// $win_type_amount_6 = $type_price_6 * 50;
|
||||
|
||||
// $win_type_amount_arr = [$win_type_amount_1, $win_type_amount_2, $win_type_amount_3, $win_type_amount_4, $win_type_amount_5, $win_type_amount_6];
|
||||
$win_type_amount_arr = [$win_type_amount_1, $win_type_amount_2, $win_type_amount_3, $win_type_amount_4, $win_type_amount_5, $win_type_amount_6];
|
||||
// $win_type_amount_arr = [$win_type_amount_1, $win_type_amount_2, $win_type_amount_3, $win_type_amount_4];
|
||||
$win_type_min = min($win_type_amount_arr);
|
||||
|
||||
// if($win_type_amount_4 == $win_type_min && $win_type_amount_3 == $win_type_min && $win_type_amount_2 == $win_type_min && $win_type_amount_1 == $win_type_min){
|
||||
// $win_type = rand(1,4);
|
||||
// }else
|
||||
if($win_type_amount_1 == $win_type_min){
|
||||
$win_type = 1;
|
||||
}else if($win_type_amount_2 == $win_type_min){
|
||||
$win_type = 2;
|
||||
}else if($win_type_amount_3 == $win_type_min){
|
||||
$win_type = 3;
|
||||
}else if($win_type_amount_4 == $win_type_min){
|
||||
$win_type = 4;
|
||||
}else if($win_type_amount_5 == $win_type_min){
|
||||
$win_type = 5;
|
||||
}else if($win_type_amount_6 == $win_type_min){
|
||||
$win_type = 6;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return $win_type;
|
||||
}
|
||||
|
||||
//获取最新三十个结束的中奖记录
|
||||
public function get_close_monster_win_log(){
|
||||
|
||||
$win_type_array = db::name('monster_log')->where('is_delete', 2)->order('id desc')->limit(80)->column('win_type');
|
||||
$win_type_data = '';
|
||||
foreach ($win_type_array as $k => $v){
|
||||
$win_type_data .= $v;
|
||||
}
|
||||
$win_type_data = strrev($win_type_data);
|
||||
|
||||
return $win_type_data;
|
||||
}
|
||||
|
||||
//中奖次数榜单
|
||||
public function get_monster_winner_num_list($uid, $time){
|
||||
if(in_array($time, [1,2,3])){
|
||||
|
||||
}
|
||||
|
||||
$model = db::name('user_monster_win_log')->field('uid, count(id) as win_num');
|
||||
if($time == 1){
|
||||
$model = $model->whereTime('add_time', 'today');
|
||||
}else if($time == 2){
|
||||
$model = $model->whereTime('add_time', 'week');
|
||||
}else if($time == 3){
|
||||
$model = $model->whereTime('add_time', 'month');
|
||||
}
|
||||
$list = $model->group('uid')->order('win_num desc, uid asc')->limit(30)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$user_info = db::name('user')->field('base64_nick_name, head_pic')->find($v['uid']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//设置房间期数开关
|
||||
public function operate_room_monster_show_status($uid, $rid, $is_show_monster_push){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$room_admin_uid_arr = explode(',', $room_info['room_admin_uid']);
|
||||
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr)) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$update = [];
|
||||
$update['is_show_monster_push'] = $is_show_monster_push;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
$data = [];
|
||||
$data['rid'] = $rid;
|
||||
$data['is_show_monster_push'] = $is_show_monster_push;
|
||||
|
||||
//推送
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3035;
|
||||
$push_data['msg'] = "修改房间期数开关";
|
||||
$push_data['data'] = $data;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
|
||||
return ['code' => 200, 'msg' => '修改成功', 'data' => $data];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
// dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '修改失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
26
application/api/model/Music.php
Normal file
26
application/api/model/Music.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Music extends Model
|
||||
{
|
||||
|
||||
public function get_user_music_list($uid, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map = [];
|
||||
// $map[] = ['upload_user', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 1];
|
||||
$user_music_list = db::name('music')->where($map)->field('mid,music_name,singer,music_url')->order('mid asc')->page($page, $page_limit)->select();
|
||||
foreach ($user_music_list as $k => &$v){
|
||||
$v['music_url'] = localpath_to_netpath($v['music_url']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $user_music_list];
|
||||
}
|
||||
}
|
||||
787
application/api/model/NewBox.php
Normal file
787
application/api/model/NewBox.php
Normal file
@@ -0,0 +1,787 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\db;
|
||||
|
||||
class NewBox extends Model
|
||||
{
|
||||
private function file_unlock($fh) {
|
||||
flock($fh, LOCK_UN);
|
||||
fclose($fh);
|
||||
}
|
||||
//获取奖励期数
|
||||
public function open_new_box($uid, $nbl_id, $pay_amount, $rid)
|
||||
{
|
||||
|
||||
$config = get_uncache_system_config();
|
||||
//宝箱是否关闭
|
||||
if($config['open_box_status'] != 1){
|
||||
return ['code' => 201, 'msg' => '功能关闭中', 'data' => null];
|
||||
}
|
||||
|
||||
if($config['explore_box_status'] != 1){
|
||||
return ['code' => 201, 'msg' => '奖池关闭中!', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
$redis = connectionRedis();
|
||||
if(intval($pay_amount) != $pay_amount) {
|
||||
return ['code' => 201, 'msg' => '投入金币只能为整数', 'data' => null];
|
||||
}
|
||||
$pay_amount_num = bcdiv($pay_amount, 10, 1);
|
||||
if(ceil($pay_amount_num) != $pay_amount_num) {
|
||||
return ['code' => 201, 'msg' => '投入金币只能为10的整数倍', 'data' => null];
|
||||
}
|
||||
$unique_key = $nbl_id;
|
||||
$path = './lock/lock_new_box' . $unique_key . '.txt';
|
||||
$fh = fopen($path, 'w');
|
||||
flock($fh, LOCK_EX);
|
||||
$keyname = 'user:new:box:nbl_id:'. $nbl_id;
|
||||
|
||||
$info = Db::name('new_box_log')->where('id', $nbl_id)->find();
|
||||
if(empty($info)) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '数据不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//活动队列名称
|
||||
$keyname_num_sn = 'new:box:nb_id:'. $info['nb_id'];
|
||||
|
||||
if($info['status'] != 1) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '本期已结束', 'data' => null];
|
||||
}
|
||||
if(($info['total_amount'] - $info['amount']) < $pay_amount) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '投入金币过多', 'data' => null];
|
||||
}
|
||||
$user_info = Db::name('user')->where('uid', $uid)->field('uid,integral,base64_nick_name,is_tester')->find();
|
||||
if(empty($user_info)) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '用户数据不存在', 'data' => null];
|
||||
}
|
||||
if($user_info['is_tester'] != 1) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '测试号不支持该玩法', 'data' => null];
|
||||
}
|
||||
if($user_info['integral'] < $pay_amount) {
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '用户金币不足', 'data' => null];
|
||||
}
|
||||
//是否需要回退redis数据
|
||||
$is_call_back_redis = 0;
|
||||
//如果投入金币等于总投入本期结束
|
||||
$is_over = 0;
|
||||
$gift_price = Db::name('gift')->where('gid', $info['gid'])->value('gift_price');
|
||||
//是否可回退编号
|
||||
$is_call_back_redis_num_sn = 0;
|
||||
//用户编号
|
||||
$user_new_box_num_sn = [];
|
||||
//回退数
|
||||
$user_new_box_num_sn_reids_list = [];
|
||||
//赢取礼物人id
|
||||
$win_uid = 0;
|
||||
// dump($redis->lrange($keyname_num_sn, 0, -1));die;
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
//在该奖池总投入
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, ($pay_amount * -1), 2, 61, "龙蛋神谕玩法", $uid, 0, $rid);
|
||||
if ($reslut['code'] != 200) {
|
||||
|
||||
Db::rollback();
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($uid, ($pay_amount), 5, 51, "钥匙增加", $uid, 0, $rid);
|
||||
// if ($reslut['code'] != 200) {
|
||||
|
||||
// Db::rollback();
|
||||
// $this->file_unlock($fh);
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['nbl_id', '=', $nbl_id];
|
||||
$user_new_box_account_info = Db::name('user_new_box_account')->where($map)->find();
|
||||
if($user_new_box_account_info) {
|
||||
Db::name('user_new_box_account')->where('id', $user_new_box_account_info['id'])->inc('pay_amount', $pay_amount)->update(['update_time' => time()]);
|
||||
} else {
|
||||
$insert_account = [
|
||||
'uid' => $uid,
|
||||
'nbl_id' => $nbl_id,
|
||||
'pay_amount' => $pay_amount,
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('user_new_box_account')->insert($insert_account);
|
||||
}
|
||||
|
||||
|
||||
//弹出随机编号
|
||||
for ($i = 0; $i < $pay_amount_num; $i++) {
|
||||
$num_data = $redis->blpop($keyname_num_sn, 2); //1s 超时
|
||||
if (empty($num_data)) {
|
||||
$this->redis_new_box_log_rollback($redis, $keyname_num_sn, $user_new_box_num_sn_reids_list);
|
||||
return ['code' => 201, 'msg' => '奖池数量不足', 'data' => null];
|
||||
} else {
|
||||
$num_data_data = explode('-', $num_data[1]);
|
||||
$nbl_ids = $num_data_data[0];
|
||||
$num_sn = $num_data_data[1];
|
||||
$user_new_box_num_sn_reids_list[] = $num_data[1];
|
||||
if($nbl_ids == $nbl_id) {
|
||||
$user_new_box_num_sn[] = $uid . '-'. $num_sn;
|
||||
$is_call_back_redis_num_sn = 1;
|
||||
} else {
|
||||
$this->redis_new_box_log_rollback($redis, $keyname_num_sn, $user_new_box_num_sn_reids_list);
|
||||
return ['code' => 201, 'msg' => '奖池参数错误', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//用户投入记录
|
||||
$user_new_box_log = [
|
||||
'uid' => $uid,
|
||||
'nbl_id' => $nbl_id,
|
||||
'pay_amount' => $pay_amount,
|
||||
'rid' => $rid,
|
||||
'add_time' => time()
|
||||
];
|
||||
$unbl_id = Db::name('user_new_box_log')->insertGetId($user_new_box_log);
|
||||
//本次投注获取号码
|
||||
$insert_user_new_box_log_sn = [];
|
||||
foreach($user_new_box_num_sn as $v) {
|
||||
$arr = explode('-', $v);
|
||||
$num_sn = $arr[1];
|
||||
$temp = [
|
||||
'nbl_id' => $nbl_id,
|
||||
'num_sn' => $num_sn,
|
||||
'uid' => $uid,
|
||||
'add_time' => time()
|
||||
];
|
||||
$insert_user_new_box_log_sn[] = $temp;
|
||||
}
|
||||
Db::name('user_new_box_log_num')->insertAll($insert_user_new_box_log_sn);
|
||||
|
||||
$update_data = ['update_time' => time()];
|
||||
if(($info['amount'] + $pay_amount) == $info['total_amount']) {
|
||||
//生成新的奖池
|
||||
|
||||
$update_data['status'] = 2;
|
||||
$update_data['over_time'] = time();
|
||||
//插入队列数据
|
||||
$result = $this->add_box_user_queue($redis, $keyname, $uid, $user_new_box_num_sn);
|
||||
if($result['code'] == 201) {
|
||||
|
||||
Db::rollback();
|
||||
$this->redis_new_box_log_rollback($redis, $keyname_num_sn, $user_new_box_num_sn_reids_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重新投注', 'data' => null];
|
||||
} else {
|
||||
$is_call_back_redis = 1;
|
||||
}
|
||||
//查找获取胜利的人
|
||||
$win_uid_str = $this->compute_new_box_log($redis, $keyname);
|
||||
$win_uid_arr = explode('-', $win_uid_str);
|
||||
$win_uid = $win_uid_arr[0];
|
||||
$win_num_sn = $win_uid_arr[1];
|
||||
//插入背包
|
||||
$now_time = time();
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $win_uid];
|
||||
$map[] = ['gid', '=', $info['gid']];
|
||||
$data = [];
|
||||
$data['gid'] = $info['gid'];
|
||||
$data['update_time'] = $now_time;
|
||||
$reslut = db::name('user_gift_pack')->where($map)->inc('num', 1)->inc('total_num', 1)->update($data);
|
||||
if (!$reslut) {
|
||||
$data = [];
|
||||
$data['uid'] = $win_uid;
|
||||
$data['gid'] = $info['gid'];
|
||||
$data['total_num'] = 1;
|
||||
$data['num'] = 1;
|
||||
$data['is_tester'] = 1;
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
$reslut = db::name('user_gift_pack')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
$this->redis_new_box_log_rollback($redis, $keyname_num_sn, $user_new_box_num_sn_reids_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $win_uid;
|
||||
$data['type'] = 5;
|
||||
$data['bl_id'] = $nbl_id;
|
||||
$data['gid'] = $info['gid'];
|
||||
$data['gift_price'] = $gift_price;
|
||||
$data['change_num'] = 1;
|
||||
$data['total_gift_price'] = $gift_price;
|
||||
$data['after_num'] = 1;
|
||||
$data['is_tester'] = 1;
|
||||
$data['remarks'] = "开宝箱获得";
|
||||
$data['add_time'] = $now_time;
|
||||
$data['update_time'] = $now_time;
|
||||
db::name('user_gift_pack_log')->insert($data);
|
||||
|
||||
$update_data['win_uid'] = $win_uid;
|
||||
$update_data['win_num_sn'] = $win_num_sn;
|
||||
$is_over = 1;
|
||||
} else {
|
||||
$result = $this->add_box_user_queue($redis, $keyname, $uid, $user_new_box_num_sn);
|
||||
if($result['code'] == 201) {
|
||||
|
||||
Db::rollback();
|
||||
$this->redis_new_box_log_rollback($redis, $keyname_num_sn, $user_new_box_num_sn_reids_list);
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 201, 'msg' => '请重新投注', 'data' => null];
|
||||
} else {
|
||||
$is_call_back_redis = 1;
|
||||
}
|
||||
}
|
||||
//更新期数
|
||||
Db::name('new_box_log')->where('id', $nbl_id)->inc('amount', $pay_amount)->update($update_data);
|
||||
//创建新期数
|
||||
if($is_over == 1) {
|
||||
|
||||
}
|
||||
|
||||
//开奖全服播报
|
||||
|
||||
if($is_over == 1) {
|
||||
//推送礼物信息
|
||||
$user_charm_info = model('User')->get_user_charm_contribution_info($win_uid);
|
||||
$win_user_info = Db::name('user')->where('uid', $win_uid)->field('uid,base64_nick_name,head_pic')->find();
|
||||
$push_all_gift_data = [];
|
||||
$push_group_gift_data = [];
|
||||
$push_sqb_gift_data = [];
|
||||
$push_all_gift_data['user_info']['uid'] = $win_user_info['uid'];
|
||||
$push_all_gift_data['user_info']['nick_name'] = mb_convert_encoding(base64_decode($win_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_all_gift_data['user_info']['head_pic'] = localpath_to_netpath($win_user_info['head_pic']);
|
||||
$push_all_gift_data['user_info']['contribution_level_image'] = $user_charm_info['data']['contribution_level_image'];
|
||||
$sqb_gift_info = db::name('gift')->field('gid,gift_name,gift_price,base_image,play_image,gift_type')->where('gid', $info['gid'])->find();
|
||||
$sqb_gift_info['base_image'] = localpath_to_netpath($sqb_gift_info['base_image']);
|
||||
$sqb_gift_info['play_image'] = localpath_to_netpath($sqb_gift_info['play_image']);
|
||||
$sqb_gift_info['open_num'] = 1;
|
||||
$sqb_gift_info['uid'] = $win_user_info['uid'];
|
||||
$sqb_gift_info['nick_name'] = mb_convert_encoding(base64_decode($win_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$sqb_gift_info['head_pic'] = localpath_to_netpath($win_user_info['head_pic']);
|
||||
$sqb_gift_info['num'] = 1;
|
||||
$sqb_gift_info['total_open_num'] = 1;
|
||||
$sqb_gift_info['box_type_name'] = '龙蛋神谕';
|
||||
$sqb_gift_info['type_name'] = '龙蛋神谕';
|
||||
$sqb_gift_info['box_type'] = 99;
|
||||
$sqb_gift_info['surprise'] = 0;
|
||||
$push_all_gift_data['gift_list'][] = $sqb_gift_info;
|
||||
$push_data = [];
|
||||
$push_data['code'] = 304;
|
||||
$push_data['msg'] = "开宝箱全服播报数据";
|
||||
$push_data['data'] = $push_all_gift_data;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
$this->clear_queue_list($redis, $keyname);
|
||||
$new_box_info = Db::name('new_box')->find($info['nb_id']);
|
||||
$this->create_new_box_log($new_box_info);
|
||||
$push_data_result = $this->get_new_box_log_info($uid,$info['nb_id']);
|
||||
$push_data_result['is_over'] = 1;
|
||||
$push_data = [];
|
||||
$push_data['code'] = 343;
|
||||
$push_data['msg'] = "开宝箱全服播报数据";
|
||||
$push_data['data'] = $push_data_result;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
} else {
|
||||
$push_data_result = $this->get_new_box_log_info($uid,$info['nb_id']);
|
||||
$push_data_result['is_over'] = 2;
|
||||
$push_data = [];
|
||||
$push_data['code'] = 343;
|
||||
$push_data['msg'] = "开宝箱全服播报数据";
|
||||
$push_data['data'] = $push_data_result;
|
||||
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
}
|
||||
Db::commit();
|
||||
$integral = $user_info['integral'] - $pay_amount;
|
||||
$this->file_unlock($fh);
|
||||
return ['code' => 200, 'msg' => '开启成功', 'data' => ['integral' => $integral]];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
if($is_call_back_redis == 1) {
|
||||
$this->redis_gift_data_rollback($redis, $keyname, $pay_amount_num);
|
||||
}
|
||||
if($is_call_back_redis_num_sn == 1) {
|
||||
|
||||
$this->redis_new_box_log_rollback($redis, $keyname_num_sn, $user_new_box_num_sn_reids_list);
|
||||
}
|
||||
Db::rollback();
|
||||
// dump($user_new_box_num_sn_reids_list);
|
||||
// dump($e);
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//回退编号
|
||||
public function redis_new_box_log_rollback($redis, $keyname, $arr)
|
||||
{
|
||||
if(!empty($arr)) {
|
||||
array_unshift($arr, $keyname);
|
||||
//右侧取 右侧插入
|
||||
call_user_func_array([$redis, 'lPush'], $arr);
|
||||
}
|
||||
|
||||
}
|
||||
//奖池归属算法
|
||||
public function compute_new_box_log($redis, $keyname)
|
||||
{
|
||||
$uid_arr = $redis->lrange($keyname, 0, -1);
|
||||
shuffle($uid_arr);
|
||||
$key = mt_rand(0, (count($uid_arr) - 1));
|
||||
// dump($uid_arr);die;
|
||||
return $uid_arr[$key];
|
||||
}
|
||||
//清空队列
|
||||
public function clear_queue_list($redis, $keyname)
|
||||
{
|
||||
$redis->del($keyname);
|
||||
}
|
||||
|
||||
//获取奖池信息
|
||||
public function get_new_box_log_info($uid, $nb_id)
|
||||
{
|
||||
$info = Db::name('new_box_log')
|
||||
->alias('a')
|
||||
->join('yy_gift b', 'a.gid = b.gid')
|
||||
->field('a.total_amount,a.amount,a.nb_id,a.nbl_sn,a.id as nbl_id,b.gift_name,b.base_image,b.gift_price')
|
||||
->where('nb_id', $nb_id)
|
||||
->where('a.status', 1)
|
||||
->order('id', 'desc')
|
||||
->find();
|
||||
if($info) {
|
||||
$my_pay_amount = Db::name('user_new_box_account')->where(['uid' => $uid, 'nbl_id' => $info['nbl_id']])->value('pay_amount');
|
||||
$info['my_pay_amount'] = $my_pay_amount ? $my_pay_amount : 0;
|
||||
$info['base_image'] = localpath_to_netpath($info['base_image']);
|
||||
$info['gift_name'] = $info['gift_name'] . '(' . intval($info['gift_price']) . ')';
|
||||
$info['uid'] = $uid;
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
//插入队列数据
|
||||
private function add_box_user_queue($redis, $keyname, $uid, $uid_arr)
|
||||
{
|
||||
if($uid_arr) {
|
||||
array_unshift($uid_arr, $keyname);
|
||||
//右侧取 右侧插入
|
||||
call_user_func_array([$redis, 'lPush'], $uid_arr);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '入队成功', 'data' => null];
|
||||
}
|
||||
//返还用户抽中礼物到奖池
|
||||
public function redis_gift_data_rollback($redis, $keyname, $pay_amount)
|
||||
{
|
||||
for($i=0; $i < $pay_amount; $i++) {
|
||||
$redis->lpop($keyname);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '返还成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
public function get_new_box_list($uid)
|
||||
{
|
||||
|
||||
//第一个奖池
|
||||
$one_nb_id = 1;
|
||||
$one_box_log_info = $this->get_new_box_log_info($uid,$one_nb_id);
|
||||
$one_nb_id_show = true;
|
||||
$one_box_info = Db::name('new_box')->find($one_nb_id);
|
||||
if($one_box_info['new_box_status'] == 2){
|
||||
$one_nb_id_show = false;
|
||||
}
|
||||
|
||||
if(empty($one_box_log_info)) {
|
||||
$this->create_new_box_log($one_box_info);
|
||||
$one_box_log_info = $this->get_new_box_log_info($uid,$one_nb_id);
|
||||
}
|
||||
//第二个奖池
|
||||
$two_nb_id = 2;
|
||||
$two_box_log_info = $this->get_new_box_log_info($uid,$two_nb_id);
|
||||
$two_nb_id_show = true;
|
||||
$two_box_info = Db::name('new_box')->find($two_nb_id);
|
||||
if($two_box_info['new_box_status'] == 2){
|
||||
$two_nb_id_show = false;
|
||||
}
|
||||
if(empty($two_box_log_info)) {
|
||||
$this->create_new_box_log($two_box_info);
|
||||
$two_box_log_info = $this->get_new_box_log_info($uid,$two_nb_id);
|
||||
}
|
||||
//第三个奖池
|
||||
$three_nb_id = 3;
|
||||
$three_box_log_info = $this->get_new_box_log_info($uid,$three_nb_id);
|
||||
$three_nb_id_show = true;
|
||||
$three_box_info = Db::name('new_box')->find($three_nb_id);
|
||||
if($three_box_info['new_box_status'] == 2){
|
||||
$three_nb_id_show = false;
|
||||
}
|
||||
|
||||
if(empty($three_box_log_info)) {
|
||||
$this->create_new_box_log($three_box_info);
|
||||
$three_box_log_info = $this->get_new_box_log_info($uid,$three_nb_id);
|
||||
}
|
||||
//第四个奖池
|
||||
$four_nb_id = 4;
|
||||
$four_box_log_info = $this->get_new_box_log_info($uid,$four_nb_id);
|
||||
$four_nb_id_show = true;
|
||||
$four_box_info = Db::name('new_box')->find($four_nb_id);
|
||||
if($four_box_info['new_box_status'] == 2){
|
||||
$four_nb_id_show = false;
|
||||
}
|
||||
if(empty($four_box_log_info)) {
|
||||
$this->create_new_box_log($four_box_info);
|
||||
$four_box_log_info = $this->get_new_box_log_info($uid,$four_nb_id);
|
||||
}
|
||||
|
||||
//第五个奖池
|
||||
$five_nb_id = 5;
|
||||
$five_box_log_info = $this->get_new_box_log_info($uid,$five_nb_id);
|
||||
$five_nb_id_show = true;
|
||||
$five_box_info = Db::name('new_box')->find($five_nb_id);
|
||||
if($five_box_info['new_box_status'] == 2){
|
||||
$five_nb_id_show = false;
|
||||
}
|
||||
if(empty($five_box_log_info)) {
|
||||
$this->create_new_box_log($five_box_info);
|
||||
$five_box_log_info = $this->get_new_box_log_info($uid,$five_nb_id);
|
||||
}
|
||||
//第六个奖池
|
||||
$six_nb_id = 6;
|
||||
$six_box_log_info = $this->get_new_box_log_info($uid,$six_nb_id);
|
||||
$six_nb_id_show = true;
|
||||
$six_box_info = Db::name('new_box')->find($six_nb_id);
|
||||
if($six_box_info['new_box_status'] == 2){
|
||||
$six_nb_id_show = false;
|
||||
}
|
||||
if(empty($six_box_log_info)) {
|
||||
$this->create_new_box_log($six_box_info);
|
||||
$six_box_log_info = $this->get_new_box_log_info($uid,$six_nb_id);
|
||||
}
|
||||
//第七个奖池
|
||||
$seven_nb_id = 7;
|
||||
$seven_box_log_info = $this->get_new_box_log_info($uid,$seven_nb_id);
|
||||
$seven_nb_id_show = true;
|
||||
$seven_box_info = Db::name('new_box')->find($seven_nb_id);
|
||||
if($seven_box_info['new_box_status'] == 2){
|
||||
$seven_nb_id_show = false;
|
||||
}
|
||||
if(empty($seven_box_log_info)) {
|
||||
$this->create_new_box_log($seven_box_info);
|
||||
$seven_box_log_info = $this->get_new_box_log_info($uid,$seven_nb_id);
|
||||
}
|
||||
|
||||
//第八个奖池
|
||||
$eight_nb_id = 8;
|
||||
$eight_box_log_info = $this->get_new_box_log_info($uid,$eight_nb_id);
|
||||
$eight_nb_id_show = true;
|
||||
$eight_box_info = Db::name('new_box')->find($eight_nb_id);
|
||||
if($eight_box_info['new_box_status'] == 2){
|
||||
$eight_nb_id_show = false;
|
||||
}
|
||||
if(empty($eight_box_log_info)) {
|
||||
$this->create_new_box_log($eight_box_info);
|
||||
$eight_box_log_info = $this->get_new_box_log_info($uid,$eight_nb_id);
|
||||
}
|
||||
|
||||
|
||||
// //第九个奖池
|
||||
$nine_nb_id = 9;
|
||||
$nine_box_log_info = $this->get_new_box_log_info($uid,$nine_nb_id);
|
||||
$nine_nb_id_show = true;
|
||||
$nine_box_info = Db::name('new_box')->find($nine_nb_id);
|
||||
if($nine_box_info['new_box_status'] == 2){
|
||||
$nine_nb_id_show = false;
|
||||
}
|
||||
if(empty($nine_box_log_info)) {
|
||||
$this->create_new_box_log($nine_box_info);
|
||||
$nine_box_log_info = $this->get_new_box_log_info($uid,$nine_nb_id);
|
||||
}
|
||||
|
||||
$list = [];
|
||||
if($one_nb_id_show){
|
||||
$list[] = $one_box_log_info;
|
||||
}
|
||||
|
||||
if($two_nb_id_show){
|
||||
$list[] = $two_box_log_info;
|
||||
}
|
||||
|
||||
if($three_nb_id_show){
|
||||
$list[] = $three_box_log_info;
|
||||
}
|
||||
|
||||
if($four_nb_id_show){
|
||||
$list[] = $four_box_log_info;
|
||||
}
|
||||
|
||||
if($five_nb_id_show){
|
||||
$list[] = $five_box_log_info;
|
||||
}
|
||||
|
||||
if($six_nb_id_show){
|
||||
$list[] = $six_box_log_info;
|
||||
}
|
||||
|
||||
if($seven_nb_id_show){
|
||||
$list[] = $seven_box_log_info;
|
||||
}
|
||||
|
||||
if($eight_nb_id_show){
|
||||
$list[] = $eight_box_log_info;
|
||||
}
|
||||
|
||||
if($nine_nb_id_show){
|
||||
$list[] = $nine_box_log_info;
|
||||
}
|
||||
|
||||
|
||||
// $list = [
|
||||
// $one_box_log_info,
|
||||
// $two_box_log_info,
|
||||
// $three_box_log_info,
|
||||
// $four_box_log_info,
|
||||
// $five_box_log_info,
|
||||
// $six_box_log_info,
|
||||
// $seven_box_log_info,
|
||||
// $eight_box_log_info,
|
||||
// $nine_box_log_info
|
||||
// ];
|
||||
$integral = Db::name('user')->where('uid', $uid)->value('integral');
|
||||
$data = [
|
||||
'integral' => $integral,
|
||||
'list' => $list
|
||||
];
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// public function get_new_box_list1($uid)
|
||||
// {
|
||||
// //第一个奖池
|
||||
// $one_nb_id = 1;
|
||||
// $one_box_log_info = $this->get_new_box_log_info($uid,$one_nb_id);
|
||||
// $one_nb_id_show = true;
|
||||
// $one_box_info = Db::name('new_box')->find($one_nb_id);
|
||||
// if($one_box_info['new_box_status'] == 2){
|
||||
// $one_nb_id_show = false;
|
||||
// }
|
||||
|
||||
// //第二个奖池
|
||||
// $two_nb_id = 2;
|
||||
// $two_box_log_info = $this->get_new_box_log_info($uid,$two_nb_id);
|
||||
// $two_nb_id_show = true;
|
||||
// $two_box_info = Db::name('new_box')->find($two_nb_id);
|
||||
// if($two_box_info['new_box_status'] == 2){
|
||||
// $two_nb_id_show = false;
|
||||
// }
|
||||
|
||||
// //第三个奖池
|
||||
// $three_nb_id = 3;
|
||||
// $three_box_log_info = $this->get_new_box_log_info($uid,$three_nb_id);
|
||||
// $three_nb_id_show = true;
|
||||
// $three_box_info = Db::name('new_box')->find($three_nb_id);
|
||||
// if($three_box_info['new_box_status'] == 2){
|
||||
// $three_nb_id_show = false;
|
||||
// }
|
||||
// //第四个奖池
|
||||
// $four_nb_id = 4;
|
||||
// $four_box_log_info = $this->get_new_box_log_info($uid,$four_nb_id);
|
||||
// $four_nb_id_show = true;
|
||||
// $four_box_info = Db::name('new_box')->find($four_nb_id);
|
||||
// if($four_box_info['new_box_status'] == 2){
|
||||
// $four_nb_id_show = false;
|
||||
// }
|
||||
|
||||
// //第五个奖池
|
||||
// $five_nb_id = 5;
|
||||
// $five_box_log_info = $this->get_new_box_log_info($uid,$five_nb_id);
|
||||
// $five_nb_id_show = true;
|
||||
// $five_box_info = Db::name('new_box')->find($five_nb_id);
|
||||
|
||||
// if($five_box_info['new_box_status'] == 2){
|
||||
// $five_nb_id_show = false;
|
||||
// }
|
||||
// //第六个奖池
|
||||
// $six_nb_id = 6;
|
||||
// $six_box_log_info = $this->get_new_box_log_info($uid,$six_nb_id);
|
||||
// $six_nb_id_show = true;
|
||||
// $six_box_info = Db::name('new_box')->find($six_nb_id);
|
||||
|
||||
// if($six_box_info['new_box_status'] == 2){
|
||||
// $six_nb_id_show = false;
|
||||
// }
|
||||
// //第七个奖池
|
||||
// $seven_nb_id = 7;
|
||||
// $seven_box_log_info = $this->get_new_box_log_info($uid,$seven_nb_id);
|
||||
// $seven_nb_id_show = true;
|
||||
// $seven_box_info = Db::name('new_box')->find($seven_nb_id);
|
||||
|
||||
|
||||
// if($seven_box_info['new_box_status'] == 2){
|
||||
// $seven_box_info = false;
|
||||
// }
|
||||
|
||||
// //第八个奖池
|
||||
// $eight_nb_id = 8;
|
||||
// $eight_box_log_info = $this->get_new_box_log_info($uid,$eight_nb_id);
|
||||
// $eight_nb_id_show = true;
|
||||
// $eight_box_info = Db::name('new_box')->find($eight_nb_id);
|
||||
|
||||
// if($eight_box_info['new_box_status'] == 2){
|
||||
// $eight_nb_id_show = false;
|
||||
// }
|
||||
|
||||
// //第九个奖池
|
||||
// $nine_nb_id = 9;
|
||||
// $nine_box_log_info = $this->get_new_box_log_info($uid,$nine_nb_id);
|
||||
// $nine_nb_id_show = true;
|
||||
// $nine_box_info = Db::name('new_box')->find($nine_nb_id);
|
||||
// if($nine_box_info['new_box_status'] == 2){
|
||||
// $nine_nb_id_show = false;
|
||||
// }
|
||||
|
||||
// halt([
|
||||
// $one_nb_id_show,
|
||||
// $two_nb_id_show,
|
||||
// $three_nb_id_show,
|
||||
// $four_nb_id_show,
|
||||
// $five_nb_id_show,
|
||||
// $six_nb_id_show,
|
||||
// $seven_nb_id_show,
|
||||
// $eight_nb_id_show,
|
||||
// $nine_nb_id_show
|
||||
|
||||
// ]);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
//生成奖池
|
||||
public function create_new_box_log($new_box_info)
|
||||
{
|
||||
//期数id
|
||||
$nbl_sn = 1;
|
||||
//查找上一期期数
|
||||
$last_new_box_log_info = Db::name('new_box_log')->where('nb_id', $new_box_info['id'])->order('id', 'desc')->find();
|
||||
if($last_new_box_log_info) {
|
||||
$nbl_sn = $last_new_box_log_info['nbl_sn'] + 1;
|
||||
}
|
||||
$insert_data = [
|
||||
'nb_id' => $new_box_info['id'],
|
||||
'total_amount' => $new_box_info['total_amount'],
|
||||
'gid' => $new_box_info['gid'],
|
||||
'nbl_sn' => $nbl_sn,
|
||||
'add_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
$log_id = Db::name('new_box_log')->insertGetId($insert_data);
|
||||
$num_arr = [];
|
||||
$total_num = intval($new_box_info['total_amount']/10);
|
||||
for($i=1; $i <= $total_num; $i++) {
|
||||
$num_arr[] = $log_id . '-'. $i;
|
||||
}
|
||||
shuffle($num_arr);
|
||||
$keyname = 'new:box:nb_id:' . $new_box_info['id'];
|
||||
array_unshift($num_arr, $keyname);
|
||||
$redis = connectionRedis();
|
||||
call_user_func_array([$redis, 'rPush'], $num_arr);
|
||||
}
|
||||
|
||||
//登顶记录
|
||||
public function get_new_box_win_user($nb_id, $page, $page_limit)
|
||||
{
|
||||
$map = [];
|
||||
if($nb_id) {
|
||||
$map[] = ['a.nb_id', '=', $nb_id];
|
||||
}
|
||||
|
||||
$map[] = ['a.status', '=', 2];
|
||||
$list = Db::name('new_box_log')
|
||||
->alias('a')
|
||||
->join('yy_user b', 'a.win_uid = b.uid')
|
||||
->where($map)
|
||||
->field('a.id,b.base64_nick_name,b.uid,b.head_pic,a.nbl_sn,a.win_num_sn,over_time')
|
||||
->order('a.id', 'desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
foreach($list as &$val) {
|
||||
$val['head_pic'] = localpath_to_netpath($val['head_pic']);
|
||||
$val['nick_name'] = mb_convert_encoding(base64_decode($val['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//我的成就
|
||||
public function get_my_new_box_log($uid, $box_type, $type, $page, $page_limit)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
if($box_type) {
|
||||
$map[] = ['nb_id', '=', $box_type];
|
||||
}
|
||||
|
||||
if($type == 1) {
|
||||
$map[] = ['b.status', '=', 1];
|
||||
} elseif($type == 2) {
|
||||
$map[] = ['b.status', '=', 2];
|
||||
$map[] = ['b.win_uid', '=', $uid];
|
||||
} elseif($type == 3) {
|
||||
$map[] = ['b.status', '=', 2];
|
||||
$map[] = ['b.win_uid', 'neq', $uid];
|
||||
}
|
||||
$list = Db::name('user_new_box_account')
|
||||
->alias('a')
|
||||
->join('yy_new_box_log b', 'a.nbl_id = b.id')
|
||||
->join('yy_gift c', 'b.gid = c.gid')
|
||||
->field('c.gift_name, b.total_amount,a.pay_amount as amount,c.base_image,a.nbl_id,b.nbl_sn')
|
||||
->where($map)
|
||||
->order('a.id', 'desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
foreach($list as &$val) {
|
||||
$val['base_image'] = localpath_to_netpath($val['base_image']);
|
||||
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//获取规则
|
||||
public function get_box_note()
|
||||
{
|
||||
$text = Db::name('config')->where('key_title', 'new_box_note')->value('key_value');
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => ['note' => $text]];
|
||||
}
|
||||
//我的号码
|
||||
public function get_my_box_num_sn($uid, $nbl_id, $page, $page_limit = 20)
|
||||
{
|
||||
$win_num_sn = Db::name('new_box_log')->where('id', $nbl_id)->value('win_num_sn');
|
||||
$list = Db::name('user_new_box_log_num')->where(['uid' => $uid, 'nbl_id' => $nbl_id])->page($page, $page_limit)->select();
|
||||
$data = [];
|
||||
foreach($list as $val) {
|
||||
$is_win = 0;
|
||||
if($val['num_sn'] == $win_num_sn) {
|
||||
$is_win = 1;
|
||||
}
|
||||
$temp['num_sn'] = $val['num_sn'];
|
||||
$temp['is_win'] = $is_win;
|
||||
$data[] = $temp;
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => ['list' => $data, 'win_num_sn' => $win_num_sn]];
|
||||
}
|
||||
}
|
||||
531
application/api/model/NewRoom.php
Normal file
531
application/api/model/NewRoom.php
Normal file
@@ -0,0 +1,531 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class NewRoom extends Model
|
||||
{
|
||||
|
||||
//开始拍卖
|
||||
public function open_auction($uid, $rid)
|
||||
{
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限
|
||||
if($uid != $room_info['room_host_uid'] && $uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '您无权限进行该操作', 'data' => null];
|
||||
}
|
||||
|
||||
//当前是否已有未结束的拍卖
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_stop', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_new_auction_log')->where($map)->find();
|
||||
if($room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前尚有进行中的拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有新人在拍卖位上
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', '=', 1];
|
||||
$room_micro_info = db::name('room_micro')->where($map)->find();
|
||||
if($room_micro_info && $room_micro_info['uid'] <= 0){
|
||||
return ['code' => 201, 'msg' => '当前尚未有人在麦上,无法开启', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否已被签约
|
||||
$map = [];
|
||||
$map[] = ['sign_uid', '=', $room_micro_info['uid']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_contract = db::name('user_sign_contract')->where($map)->find();
|
||||
if($user_contract){
|
||||
return ['code' => 201, 'msg' => '该用户已被签约', 'data' => null];
|
||||
}
|
||||
|
||||
//新人信息
|
||||
$new_user_info = db::name('user')->where('uid', $room_micro_info['uid'])->find();
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//开始拍卖
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['uid'] = $room_micro_info['uid'];
|
||||
$insert['auction_uid'] = 0;
|
||||
if($new_user_info['social'] < 1){
|
||||
$insert['start_value'] = $config['initial_user_social'];
|
||||
}else{
|
||||
$insert['start_value'] = $new_user_info['social'];
|
||||
}
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('room_new_auction_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '开启成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//当前拍卖前三名
|
||||
public function get_room_new_auction_rank($rid){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否有拍卖
|
||||
$room_new_auction_log = db::name('room_new_auction_log')->where('rid', $rid)->where('is_stop', 2)->where('is_delete', 1)->find();
|
||||
if(!$room_new_auction_log){
|
||||
$data = [];
|
||||
$data['list'] = [];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//前三
|
||||
$room_new_auction_price_list = db::name('room_new_auction_price')->alias('a')->join('yy_user b', 'a.auction_uid = b.uid')->field('a.id, b.uid, b.nick_name, b.base64_nick_name, b.head_pic, a.price')->where('a.nid', $room_new_auction_log['id'])->order('a.price desc')->limit(3)->select();
|
||||
foreach ($room_new_auction_price_list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['list'] = $room_new_auction_price_list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//出价列表
|
||||
public function get_room_auction_price_list(){
|
||||
$list = db::name('auction_price')->where('is_delete', 1)->field('price')->order('price asc')->select();
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => $list];
|
||||
|
||||
}
|
||||
|
||||
//用户出价
|
||||
public function user_auction_price($uid, $rid, $price){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//该价位是否存在
|
||||
$auction_price = db::name('auction_price')->where('price', $price)->where('is_delete', 1)->find();
|
||||
if(!$auction_price){
|
||||
return ['code' => 201, 'msg' => '该加价信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间拍卖信息
|
||||
$room_auction_info = db::name('room_new_auction_log')->where('rid', $rid)->where('is_stop', 2)->where('is_delete', 1)->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未开启拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid == $room_auction_info['uid']){
|
||||
return ['code' => 201, 'msg' => '自己不能竞拍自己', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//当前竞拍价
|
||||
$new_auction_price = db::name('room_new_auction_log')->where('id', $room_auction_info['id'])->value('start_value');
|
||||
|
||||
//当前用户金额是否可以加价
|
||||
$user_auction_price = model('NewRoom')->get_user_auction_price($uid);
|
||||
if($user_info['integral'] < ($user_auction_price + $price + $new_auction_price)){
|
||||
return ['code' => 201, 'msg' => '您当前的金币不足以加价', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//用户加价信息
|
||||
$room_auction_price = db::name('room_new_auction_price')->where('auction_uid', $uid)->where('nid', $room_auction_info['id'])->find();
|
||||
if($room_auction_price){
|
||||
$update = [];
|
||||
$update['price'] = $new_auction_price + $price;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_new_auction_price')->where('id', $room_auction_price['id'])->update($update);
|
||||
|
||||
}else{
|
||||
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['nid'] = $room_auction_info['id'];
|
||||
$insert['uid'] = $room_auction_info['uid'];
|
||||
$insert['auction_uid'] = $uid;
|
||||
$insert['price'] = $new_auction_price + $price;
|
||||
$insert['add_time'] = time();
|
||||
$insert['update_time'] = time();
|
||||
$reslut = db::name('room_new_auction_price')->insert($insert);
|
||||
|
||||
}
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
//用户加价记录
|
||||
$insert_data = [];
|
||||
$insert_data['nid'] = $room_auction_info['id'];
|
||||
$insert_data['rid'] = $rid;
|
||||
$insert_data['auction_uid'] = $uid;
|
||||
$insert_data['uid'] = $room_auction_info['uid'];
|
||||
$insert_data['change_value'] = $new_auction_price;
|
||||
$insert_data['add_value'] = $price;
|
||||
$insert_data['add_time'] = time();
|
||||
$reslut = db::name('user_room_new_aution_log')->insert($insert_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
//修改当前用户基础起拍价
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_new_auction_log')->where('id', $room_auction_info['id'])->inc('start_value', $price)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3001;
|
||||
$push_data['msg'] = "竞拍前三名信息";
|
||||
$data = $this->get_room_new_auction_rank($rid);
|
||||
$push_data['data'] = $data['data'];
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
|
||||
return ['code' => 200, 'msg' => '加价成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '加价失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//用户当前加价未支付的总金额
|
||||
public function get_user_auction_price($uid){
|
||||
$user_auction_price = 0;
|
||||
|
||||
//新人厅出价
|
||||
$map = [];
|
||||
$map[] = ['auction_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_new_auction_price = db::name('room_new_auction_price')->where($map)->select();
|
||||
if(!empty($room_new_auction_price)){
|
||||
$new_auction_price = db::name('room_new_auction_price')->where($map)->sum('price');
|
||||
$user_auction_price += $new_auction_price;
|
||||
}
|
||||
|
||||
//K歌厅出价
|
||||
$map = [];
|
||||
$map[] = ['auction_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_new_auction_price = db::name('user_room_song_auction')->where($map)->select();
|
||||
if(!empty($room_new_auction_price)){
|
||||
$song_auction_price = 0;
|
||||
foreach ($room_new_auction_price as $k => $v){
|
||||
$room_user_song_log = db::name('room_song_user_log')->where('rsid', $v['rsid'])->where('uid', $v['uid'])->find();
|
||||
if($room_user_song_log){
|
||||
if($room_user_song_log['is_delete'] == 1){
|
||||
$song_auction_price += $v['price'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// $song_auction_price = db::name('user_room_song_auction')->where($map)->sum('price');
|
||||
$user_auction_price += $song_auction_price;
|
||||
}
|
||||
|
||||
return $user_auction_price;
|
||||
}
|
||||
|
||||
//结束拍卖
|
||||
public function finish_auction($uid, $rid){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有权限结束
|
||||
if($room_info['room_host_uid'] != $uid){
|
||||
return ['code' => 201, 'msg' => '当前麦上主持才可结束', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间是否正在进行的拍卖
|
||||
$room_auction_info = db::name('room_new_auction_log')->where('rid', $rid)->where('is_stop', 2)->where('is_delete', 1)->find();
|
||||
if(!$room_auction_info){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未开启拍卖', 'data' => null];
|
||||
}
|
||||
|
||||
//
|
||||
Db::startTrans();
|
||||
try {
|
||||
$now_time = time();
|
||||
|
||||
//是否有最高出价
|
||||
$room_auction_price_info = db::name('room_new_auction_price')->where('nid', $room_auction_info['id'])->order('price desc')->limit(1)->find();
|
||||
if(empty($room_auction_price_info)){//流拍
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_new_auction_log')->where('id', $room_auction_info['id'])->update(['is_stop' => 1, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 2;
|
||||
}else{//签约
|
||||
$insert = [];
|
||||
$insert['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$insert['sign_uid'] = $room_auction_price_info['uid'];
|
||||
$insert['price'] = $room_auction_price_info['price'];
|
||||
$insert['add_time'] = $now_time;
|
||||
$insert['end_time'] = $now_time + (60*60*24*7);
|
||||
$reslut = db::name('user_sign_contract')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//修改用户身价及是否签约
|
||||
$reslut = db::name('user')->where('uid', $room_auction_price_info['uid'])->update(['social' => $room_auction_price_info['price'], 'is_sign' => 1, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//修改用户制作人身份
|
||||
$reslut = db::name('user')->where('uid', $room_auction_price_info['auction_uid'])->update(['is_producer' => 1, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//新手签约奖励
|
||||
$user_is_song_award = 2;
|
||||
$user_song_money = 1;
|
||||
$user_award_num = db::name('user_new_award_log')->where('uid', $room_auction_price_info['uid'])->find();
|
||||
if($user_award_num){
|
||||
if($user_award_num < 3){
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_auction_price_info['uid'], $user_song_money, 1, 43, "新手签约奖励", $room_auction_price_info['uid'], 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('user_new_award_log')->where('id', $user_award_num['id'])->inc('num', 1)->update();
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
$user_is_song_award = 1;
|
||||
}
|
||||
}else{
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_auction_price_info['uid'], $user_song_money, 1, 43, "新手签约奖励", $room_auction_price_info['uid'], 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
$insert['uid'] = $room_auction_price_info['uid'];
|
||||
$insert['num'] = 1;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_new_award_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
$user_is_song_award = 1;
|
||||
}
|
||||
|
||||
//主持获得签约成功的金币
|
||||
$host_is_award = 2;
|
||||
$money = 2;
|
||||
//主持当天是否达到100个艺人
|
||||
$room_host_num = db::name('user_new_host_award_log')->where('uid', $room_info['room_host_uid'])->whereTime('add_time', 'today')->find();
|
||||
if($room_host_num){
|
||||
if($room_host_num['num'] < 100){
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_info['room_host_uid'], $money, 2, 23, "签约成功主持获得金币", $room_info['room_host_uid'], 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('user_new_host_award_log')->where('id', $room_host_num['id'])->inc('num', 1)->update();
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
$host_is_award = 1;
|
||||
}
|
||||
}else{
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_info['room_host_uid'], $money, 2, 23, "签约成功主持获得金币", $room_info['room_host_uid'], 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
$insert['uid'] = $room_info['room_host_uid'];
|
||||
$insert['num'] = 1;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_new_host_award_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
$host_is_award = 1;
|
||||
}
|
||||
|
||||
//扣除拍卖人的金币
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_auction_price_info['auction_uid'], -$room_auction_price_info['price'], 2, 24, "拍卖签约扣除金币", $room_auction_price_info['auction_uid'], 0, $rid);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//当前拍卖结束
|
||||
$reslut = db::name('room_new_auction_log')->where('id', $room_auction_info['id'])->update(['auction_uid' => $room_auction_price_info['auction_uid'], 'end_value' => $room_auction_price_info['price'], 'is_stop' => 1, 'is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
//结束当前拍卖价位
|
||||
$reslut = db::name('room_new_auction_price')->where('nid', $room_auction_info['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
$is_push = 1;
|
||||
}
|
||||
|
||||
//拍卖用户下麦
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [1]];
|
||||
$map[] = ['uid', '>', 0];
|
||||
$reslut = db::name('room_micro')->where($map)->update(['uid' => 0, 'update_time' => time(), 'frame_gid' => 0, 'centre_gid' => 0, 'above_gid' => 0, 'below_gid' => 0, 'left_gid' => 0, 'right_gid' => 0]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
// $reslut = model('api/room')->user_down_micro($room_auction_info['uid'], $rid, 2);
|
||||
// if($reslut['code'] != 200){
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
|
||||
Db::commit();
|
||||
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
|
||||
if($is_push == 1){
|
||||
$auction_user_info = db::name('user')->find($room_auction_price_info['auction_uid']);
|
||||
$sign_user_info = db::name('user')->find($room_auction_price_info['uid']);
|
||||
$room_host_info = db::name('user')->find($room_info['room_host_uid']);
|
||||
|
||||
$push_message = [];
|
||||
$push_message['auction_user_info']['uid'] = $room_auction_price_info['auction_uid'];
|
||||
$push_message['auction_user_info']['nick_name'] = mb_convert_encoding(base64_decode($auction_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['auction_user_info']['head_pic'] = localpath_to_netpath($auction_user_info['head_pic']);
|
||||
$push_message['sign_user_info']['uid'] = $room_auction_price_info['uid'];
|
||||
$push_message['sign_user_info']['nick_name'] = mb_convert_encoding(base64_decode($sign_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['sign_user_info']['head_pic'] = localpath_to_netpath($sign_user_info['head_pic']);
|
||||
$push_message['is_push_user_song_award'] = $user_is_song_award;
|
||||
$push_message['push_user_song_award']['uid'] = 0;
|
||||
$push_message['push_user_song_award']['nick_name'] = '';
|
||||
$push_message['push_user_song_award']['head_pic'] = '';
|
||||
$push_message['push_user_song_award']['content'] = '';
|
||||
if($user_is_song_award == 1){
|
||||
$push_message['push_user_song_award']['uid'] = $room_auction_price_info['uid'];
|
||||
$push_message['push_user_song_award']['nick_name'] = mb_convert_encoding(base64_decode($sign_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['push_user_song_award']['head_pic'] = localpath_to_netpath($sign_user_info['head_pic']);
|
||||
$push_message['push_user_song_award']['content'] = '唱歌完成获得1钻石奖励';
|
||||
|
||||
}
|
||||
$push_message['is_push_host_award'] = $host_is_award;
|
||||
$push_message['push_host_award']['uid'] = 0;
|
||||
$push_message['push_host_award']['nick_name'] = '';
|
||||
$push_message['push_host_award']['head_pic'] = '';
|
||||
$push_message['push_host_award']['content'] = '';
|
||||
if($host_is_award == 1){
|
||||
$push_message['push_host_award']['uid'] = $room_info['room_host_uid'];
|
||||
$push_message['push_host_award']['nick_name'] = mb_convert_encoding(base64_decode($room_host_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$push_message['push_host_award']['head_pic'] = localpath_to_netpath($room_host_info['head_pic']);
|
||||
$push_message['push_host_award']['content'] = '获得签约新人奖励2金币';
|
||||
}
|
||||
|
||||
|
||||
//提示签约成功
|
||||
$push_data = [];
|
||||
$push_data['code'] = 3002;
|
||||
$push_data['msg'] = "签约成功";
|
||||
$push_data['data'] = $push_message;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '结束成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '结束失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
364
application/api/model/Nobility.php
Normal file
364
application/api/model/Nobility.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Nobility extends Model
|
||||
{
|
||||
//爵位列表
|
||||
public function get_nobility_list()
|
||||
{
|
||||
$list = db::name('nobility')->field('lid,name,image,change_value')->order('level asc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['image'] = localpath_to_netpath($v['image']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//爵位详情
|
||||
public function get_nobility_info($uid, $lid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$nobility_info = db::name('nobility')->field('lid,name,image,pay_price,renew_price,pay_coin,renew_coin,day_num')->find($lid);
|
||||
if(!$nobility_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$nobility_info['image'] = localpath_to_netpath($nobility_info['image']);
|
||||
$nobility_info['pay_coin'] = intval($nobility_info['pay_coin']);
|
||||
$nobility_info['renew_coin'] = intval($nobility_info['renew_coin']);
|
||||
$now_time = time();
|
||||
$is_nobility = 2;
|
||||
$nobility_type = $user_info['nobility_id'];
|
||||
$user_nobility_id = 0;
|
||||
$is_renew = 2;
|
||||
//该用户是否已开通
|
||||
if($user_info['nobility_id'] > 0 && $user_info['nobility_id'] >= $lid) {
|
||||
$is_nobility = 1;
|
||||
$nobility_type = $user_info['nobility_id'];
|
||||
$user_nobility_id = 0;
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['lid', '=', $lid];
|
||||
|
||||
$nobility_end_time = Db::name('user_nobility')->where($map)->value('end_time');
|
||||
|
||||
if($nobility_end_time < time()) {
|
||||
$nobility_end_time = 0;
|
||||
}
|
||||
$nobility_power_list = $this->nobility_power_list($lid);
|
||||
|
||||
$data = [];
|
||||
$data['nobility_info'] = $nobility_info;
|
||||
$data['user_nobility']['is_nobility'] = $is_nobility;
|
||||
$data['user_nobility']['nobility_type'] = $nobility_type;
|
||||
$data['user_nobility_end_time'] = $nobility_end_time;
|
||||
$data['nobility_power_list'] = $nobility_power_list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//爵位权限详情
|
||||
public function nobility_power_list($lid){
|
||||
$nobility_info = db::name('nobility')->find($lid);
|
||||
if(!$nobility_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$nobility_power_list = db::name('nobility_power')->field('id,name,content,image,images')->order('sort asc')->select();
|
||||
foreach ($nobility_power_list as $k => &$v){
|
||||
if($v['id'] == 1){//专属铭牌
|
||||
if($nobility_info['is_special_label'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 2){//专属表情
|
||||
if($nobility_info['is_special_emoji'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 3){//专属麦位光圈
|
||||
if($nobility_info['is_special_halo'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 4){//专属昵称颜色
|
||||
if($nobility_info['is_name_color'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 5){//专属礼物特效
|
||||
if($nobility_info['is_special_gift'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 6){//专属坐骑
|
||||
if($nobility_info['is_special_mount'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 7){//进厅隐身
|
||||
if($nobility_info['is_room_hinding'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 8){//厅内防踢
|
||||
if($nobility_info['is_kick_out'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}else if($v['id'] == 9){//防禁言
|
||||
if($nobility_info['is_shutup'] == 1){
|
||||
$v['is_power'] = 1;
|
||||
}else{
|
||||
$v['is_power'] = 2;
|
||||
}
|
||||
}
|
||||
$v['image'] = localpath_to_netpath($v['image']);
|
||||
$v['images'] = localpath_to_netpath($v['images']);
|
||||
}
|
||||
|
||||
return $nobility_power_list;
|
||||
|
||||
}
|
||||
|
||||
//用户消费升级爵位
|
||||
public function user_gain_nobility_value($uid, $change_value){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($change_value < 0){
|
||||
return ['code' => 201, 'msg' => '数值不能小于0', 'data' => null];
|
||||
}
|
||||
|
||||
$new_nobility_value = $user_info['nobility_value'] + $change_value;
|
||||
|
||||
$nobility_list = db::name('nobility')->order('lid asc')->select();
|
||||
$now_nobility_id = $user_info['nobility_id'];
|
||||
$nick_name_color = $user_info['nick_name_color'];
|
||||
foreach ($nobility_list as $k => $v){
|
||||
if($new_nobility_value < $v['change_value']){
|
||||
break;
|
||||
}
|
||||
$now_nobility_id = $v['lid'];
|
||||
$nick_name_color = $v['nick_name_color'];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
if($now_nobility_id != $user_info['nobility_id']){
|
||||
$update['nobility_id'] = $now_nobility_id;
|
||||
$update['nick_name_color'] = $nick_name_color;
|
||||
}
|
||||
$reslut = db::name('user')->where('uid', $uid)->inc('nobility_value', $change_value)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败1", 'data' => null];
|
||||
}
|
||||
|
||||
//升级则获取装扮
|
||||
if($now_nobility_id != $user_info['nobility_id']){
|
||||
$nobility_decorate = db::name('nobility_decorate')->where('lid', $now_nobility_id)->where('is_delete', 1)->select();
|
||||
if(!empty($nobility_decorate)){
|
||||
foreach ($nobility_decorate as $k => $v){
|
||||
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $v['did'], 1500, '爵位升级赠送', 1);
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败2", 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//更新用户爵位信息
|
||||
$user_nobility_info = db::name('user_nobility')->where('uid', $uid)->find();
|
||||
if($user_nobility_info){//有就更新没有新增
|
||||
$reslut = db::name('user_nobility')->where('id', $user_nobility_info['id'])->update(['lid' => $now_nobility_id, 'update_time' => time()]);
|
||||
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['lid'] = $now_nobility_id;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_nobility')->insert($insert);
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败3", 'data' => null];
|
||||
}
|
||||
|
||||
//记录
|
||||
$insert_data = [];
|
||||
$insert_data['uid'] = $uid;
|
||||
$insert_data['lid'] = $now_nobility_id;
|
||||
$insert_data['add_time'] = time();
|
||||
$reslut = db::name('user_nobility_log')->insert($insert_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败4", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败5", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
//用户消费升级爵位
|
||||
public function user_pay_nobility_value($uid, $type_params){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$lid = $type_params['lid'];
|
||||
$nobility_info = Db::name('nobility')->find($lid);
|
||||
$now_nobility_id = $lid;
|
||||
$nick_name_color = $nobility_info['nick_name_color'];
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
if($now_nobility_id != $user_info['nobility_id']){
|
||||
$update['nobility_id'] = $now_nobility_id;
|
||||
$update['nick_name_color'] = $nick_name_color;
|
||||
}
|
||||
Db::name('user')->where('uid', $uid)->update($update);
|
||||
//升级则获取装扮
|
||||
// if($now_nobility_id != $user_info['nobility_id']){
|
||||
$nobility_decorate = db::name('nobility_decorate')->where('lid', $now_nobility_id)->where('is_delete', 1)->select();
|
||||
if(!empty($nobility_decorate)){
|
||||
foreach ($nobility_decorate as $k => $v){
|
||||
$reslut = model('Decorate')->draw_user_decorate($uid, $v['did'], $nobility_info['day_num'], '购买爵位赠送');
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败2", 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//更新用户爵位信息
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['lid', '=', $lid];
|
||||
$user_nobility_info = db::name('user_nobility')->where($map)->find();
|
||||
if($user_nobility_info){//有就更新没有新增
|
||||
$end_time = $user_nobility_info['end_time'];
|
||||
if($end_time < time()) {
|
||||
$end_time = time();
|
||||
}
|
||||
$end_time = $end_time + ($type_params['day_num'] * 86400);
|
||||
$reslut = db::name('user_nobility')->where('id', $user_nobility_info['id'])
|
||||
->update(['end_time' => $end_time, 'update_time' => time(), 'status' => 1]);
|
||||
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['lid'] = $now_nobility_id;
|
||||
$insert['end_time'] = time() + ($type_params['day_num'] * 86400);
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_nobility')->insert($insert);
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败3", 'data' => null];
|
||||
}
|
||||
|
||||
//记录
|
||||
$insert_data = [];
|
||||
$insert_data['uid'] = $uid;
|
||||
$insert_data['lid'] = $now_nobility_id;
|
||||
$insert_data['add_time'] = time();
|
||||
$insert_data['day_num'] = $type_params['day_num'];
|
||||
$insert_data['is_renew'] = $type_params['is_renew'];
|
||||
$reslut = db::name('user_nobility_log')->insert($insert_data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败4", 'data' => null];
|
||||
}
|
||||
// }
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败5", 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//爵位到期取消
|
||||
public function user_nobility_over_time()
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['end_time', '<', time()];
|
||||
$list = Db::name('user_nobility')->where($map)->select();
|
||||
$id_arr = [];
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach($list as $v) {
|
||||
$id_arr[] = $v['id'];
|
||||
$uid = $v['uid'];
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['nobility_id', '=', $v['lid']];
|
||||
$user_info = Db::name('user')->where($map)->field('uid,nobility_id')->find();
|
||||
if($user_info) {
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $v['uid']];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['end_time', '>=', time()];
|
||||
$info = Db::name('user_nobility')->where($map)->order('lid', 'desc')->find();
|
||||
$update_lid = 0;
|
||||
if($info) {
|
||||
$update_lid = $info['lid'];
|
||||
}
|
||||
Db::name('user')->where('uid', $uid)->update(['nobility_id' => $update_lid]);
|
||||
}
|
||||
}
|
||||
Db::name('user_nobility')->whereIn('id', $id_arr)->update(['status' => 2, 'update_time' => time()]);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败5", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
682
application/api/model/Player.php
Normal file
682
application/api/model/Player.php
Normal file
@@ -0,0 +1,682 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Player extends Model
|
||||
{
|
||||
protected $name = 'user_player';
|
||||
//获取陪玩列表
|
||||
public function get_player_list($uid, $gid, $keywords, $is_top, $is_recommend, $sex, $lid, $sort, $sort_type, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map = [];
|
||||
$map['a.status'] = 2; //已审核通过
|
||||
// $map['a.status'] = 2; //已审核通过
|
||||
if (!empty($is_top)) {
|
||||
$map['a.is_top'] = $is_top;
|
||||
}
|
||||
if (!empty($is_recommend)) {
|
||||
$map['a.is_recommend'] = $is_recommend;
|
||||
}
|
||||
if (!empty($uid)) {
|
||||
$map['a.uid'] = $uid;
|
||||
}
|
||||
if (!empty($gid)) {
|
||||
$map['a.gid'] = $gid;
|
||||
}
|
||||
if (!empty($lid)) {
|
||||
$map['a.lid'] = $lid;
|
||||
}
|
||||
if (!empty($sex)) {
|
||||
$map['b.sex'] = $sex;
|
||||
}
|
||||
|
||||
$order_string = 'a.is_top desc,a.is_recommend desc,a.pid desc'; //排序规则
|
||||
$sort_string = $sort_type == 1 ? ' desc' : ' asc';
|
||||
if ($sort == 1) {
|
||||
$order_string = 'a.price' . $sort_string;
|
||||
} elseif ($sort == 2) {
|
||||
$order_string = 'a.order_count' . $sort_string;
|
||||
} elseif ($sort == 3) {
|
||||
$order_string = 'a.service_rate' . $sort_string;
|
||||
}
|
||||
|
||||
$game_data = db::name('game')->cache(60)->column('game_name', 'gid');
|
||||
$model = Db::name('user_player')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$model = $model->where($map);
|
||||
if (!empty($keywords)) {
|
||||
$model = $model->where("a.uid = :keywords or b.nick_name like '%:keywords%' or b.special_uid = ':keywords'", ['keywords' => $keywords]);
|
||||
}
|
||||
$list = $model->field('a.pid,a.gid,a.lid,a.price,a.cover_image,a.sound,a.sound_duration,a.order_duration,a.order_count,a.order_total_amount,a.service_rate,a.flag,a.is_top,a.is_recommend,a.is_business,b.base64_nick_name,b.sex')->order($order_string)->page($page, $page_limit)->group('a.uid')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['cover_image'] = localpath_to_netpath($v['cover_image']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['sound'] = localpath_to_netpath($v['sound']);
|
||||
$v['game_name'] = $game_data[$v['gid']];
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
public function get_player_user_list($page, $page_limit)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['is_player', '=', 2];
|
||||
$map[] = ['player_game_list', '<>', ""];
|
||||
$user_list = Db::name('user')->field('uid,head_pic,sex,base64_nick_name,player_game_list,palyer_order_count')->where($map)->page($page, $page_limit)->order('palyer_order_count desc')->select();
|
||||
$game_list_data = db::name('game')->field('gid,game_name,game_ico,sort')->column('game_ico', 'gid');
|
||||
foreach ($user_list as $k => &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$game_data = explode(',', $v['player_game_list']);
|
||||
$v['game_list'] = [];
|
||||
foreach ($game_data as $m => $n) {
|
||||
$v['game_list'][] = localpath_to_netpath($game_list_data[$n]);
|
||||
}
|
||||
unset($v['player_game_list']);
|
||||
unset($v['base64_nick_name']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_list];
|
||||
}
|
||||
|
||||
//获取陪玩详情
|
||||
public function get_player_info($pid)
|
||||
{
|
||||
if (empty($pid)) {
|
||||
return ['code' => 200, 'msg' => '非法参数', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['a.pid', '=', $pid];
|
||||
$model = Db::name('user_player')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$model = $model->where($map);
|
||||
$info = $model->field('a.pid,a.uid,a.gid,a.lid,a.price,a.cover_image,a.skill_image,a.sound,a.sound_duration,a.order_duration,a.order_count,a.order_total_amount,a.service_rate,a.flag,a.is_top,a.is_recommend,a.is_business,a.introduction,b.base64_nick_name,b.sex,b.head_pic')->find();
|
||||
$info['cover_image'] = localpath_to_netpath($info['cover_image']);
|
||||
$info['skill_image'] = localpath_to_netpath($info['skill_image']);
|
||||
$info['head_pic'] = localpath_to_netpath($info['head_pic']);
|
||||
$info['sound'] = localpath_to_netpath($info['sound']);
|
||||
$info['nick_name'] = mb_convert_encoding(base64_decode($info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$game_info = model('game')->get_game_info($info['gid']);
|
||||
$info['game_info'] = $game_info['data'];
|
||||
$game_level_info = model('game')->get_game_skill_level_info($info['gid']);
|
||||
// $info['game_level_info'] = $game_level_info['data'];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $info];
|
||||
}
|
||||
|
||||
//获取陪玩个人主页
|
||||
//from_id 个人主页用户uid
|
||||
public function player_home_page($uid, $from_id)
|
||||
{
|
||||
$user_info = db::name('user')->find($from_id);
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '用户信息不存在', 'data' => null];
|
||||
}
|
||||
$data['is_online'] = $user_info['is_online'];
|
||||
$data['uid'] = $user_info['uid']; //用户ID
|
||||
$data['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$data['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['sex'] = $user_info['sex']; //性别
|
||||
$data['country'] = $user_info['country']; //国家
|
||||
$data['constellation'] = $user_info['constellation']; //星座
|
||||
$data['special_uid'] = $user_info['special_uid']; //靓号
|
||||
$data['follow_num'] = $user_info['follow_num'];
|
||||
$data['fans_num'] = $user_info['fans_num'];
|
||||
$data['birthday'] = $user_info['birthday'];
|
||||
$data['is_player'] = $user_info['is_player'];
|
||||
$data['is_anchor'] = $user_info['is_anchor'];
|
||||
$data['hobby'] = $user_info['hobby'];
|
||||
$data['autograph'] = $user_info['autograph'];
|
||||
if(empty($user_info['province'])){
|
||||
$data['ip_address'] = '中国';
|
||||
}else{
|
||||
$data['ip_address'] = $user_info['province'];
|
||||
}
|
||||
|
||||
if($user_info['is_open_address'] == 2){
|
||||
$data['ip_address'] = '中国';
|
||||
}
|
||||
|
||||
//获取用户魅力 财富等级
|
||||
|
||||
$reslut = model('api/User')->get_user_charm_contribution_info($user_info);
|
||||
|
||||
$data['user_charm_contribution_info'] = $reslut['data'];
|
||||
$user_nobility_info = model('user')->get_user_nobility_info($from_id);
|
||||
$data['nobility_image'] = $user_nobility_info['data']['nobility_image'];
|
||||
//收藏数量
|
||||
$data['room_collect_num'] = 0;
|
||||
$data['user_room_rid'] = 0; //用户房间
|
||||
//获取用户所属房间
|
||||
$map = [];
|
||||
$map[] = ['room_owner_uid', '=', $from_id];
|
||||
$rid_data = db::name('room')->where($map)->column('rid');
|
||||
if (!empty($rid_data)) {
|
||||
$map = [];
|
||||
$map[] = ['rid', 'in', $rid_data];
|
||||
$data['room_collect_num'] = db::name('user_collect_room')->where($map)->count();
|
||||
$data['user_room_rid'] = current($rid_data);
|
||||
}
|
||||
//获取用户当前所在房间
|
||||
|
||||
$room_visitor=[];
|
||||
$room_visitor['rid'] = 0;
|
||||
$room_visitor['room_name'] = '';
|
||||
$room_visitor['room_cover'] = '';
|
||||
$data['user_room_visitor'] = $room_visitor;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $from_id];
|
||||
$room_visitor_rid = db::name('room_visitor')->where($map)->order('update_time desc')->value('rid');
|
||||
if(!empty($room_visitor_rid)){
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $room_visitor_rid];
|
||||
$room_info = db::name('room')->where($map)->field('rid,room_name,base64_room_name,room_cover')->find();
|
||||
if(!empty($room_info)){
|
||||
$data['user_room_visitor']['rid'] = $room_info['rid'];
|
||||
$data['user_room_visitor']['room_name'] = mb_convert_encoding(base64_decode($room_info['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$data['user_room_visitor']['room_cover'] = localpath_to_netpath($room_info['room_cover']);
|
||||
}
|
||||
}
|
||||
|
||||
//获取用户陪玩游戏里列表
|
||||
$player_list = [];
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $from_id];
|
||||
$map[] = ['b.is_show', '=', 1];
|
||||
$map[] = ['b.is_delete', '=', 1];
|
||||
$model = Db::name('user_player')->alias('a')->join('yy_game b', 'a.gid = b.gid');
|
||||
$player_list = $model->field('a.pid,a.gid,a.cover_image,a.order_duration,a.order_count,a.service_rate,a.price')->where($map)->order('order_count desc')->select();
|
||||
$game_data = db::name('game')->column('game_name', 'gid');
|
||||
foreach ($player_list as $k => &$v) {
|
||||
$v['cover_image'] = localpath_to_netpath($v['cover_image']);
|
||||
if (!empty($game_data[$v['gid']])) {
|
||||
$v['game_name'] = $game_data[$v['gid']];
|
||||
} else {
|
||||
$v['game_name'] = "";
|
||||
}
|
||||
}
|
||||
$data['user_player_list'] = $player_list;
|
||||
//获取用户所有收到的礼物总数量
|
||||
$receive_gift_list = [];
|
||||
|
||||
$map = [];
|
||||
$map[] = ['receive_uid', '=', $from_id];
|
||||
$receive_gift_list = db::name('user_send_gift')->field('gid,gift_name,gift_price,sum(gift_num) as gift_total_sum,gift_total_price')->where($map)->group('gid')->order('gift_num desc')->select();
|
||||
if (!empty($receive_gift_list)) {
|
||||
$gift_data = db::name('gift')->cache(10)->column('base_image', 'gid');
|
||||
foreach ($receive_gift_list as $k => &$v) {
|
||||
$v['base_image'] = localpath_to_netpath($gift_data[$v['gid']]);
|
||||
}
|
||||
}
|
||||
$data['receive_gift_list'] = $receive_gift_list;
|
||||
//获取用户相册
|
||||
$user_albums_list = [];
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $from_id];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_albums_list = db::name('user_albums')->field('aid,image')->where($map)->order('aid desc')->limit(30)->select();
|
||||
foreach ($user_albums_list as $k => &$v) {
|
||||
$v['image'] = localpath_to_netpath($v['image']);
|
||||
}
|
||||
$data['user_albums_list'] = $user_albums_list;
|
||||
|
||||
//判断是否关注
|
||||
$uid_follow = db::name('user_follow')->where(['uid' => $uid, 'follow_uid' => $from_id])->find();
|
||||
$from_follow = db::name('user_follow')->where(['uid' => $from_id, 'follow_uid' => $uid])->find();
|
||||
$data['is_follow'] = 1; //是否已关注关注
|
||||
$data['is_befollow'] = 1; //是否被关注
|
||||
if (!empty($uid_follow)) {
|
||||
$data['is_follow'] = 2;
|
||||
}
|
||||
if (!empty($from_follow)) {
|
||||
$data['is_befollow'] = 2;
|
||||
}
|
||||
|
||||
//cp数量
|
||||
$data['cp_num'] = 0;
|
||||
//CP信息
|
||||
$user_cp_info = model('Coupling')->user_coupling_info($from_id);
|
||||
if($user_cp_info['data']['is_have_cp'] == 1){
|
||||
$data['cp_num'] = 1;
|
||||
}
|
||||
//是否已被我拉黑
|
||||
$is_black = Db::name('user_black')->where(['uid'=>$uid,'receive_uid'=>$from_id])->find();
|
||||
$data['is_black'] = $is_black?1:0;
|
||||
|
||||
//加入的公会
|
||||
$is_join_guild = 2;
|
||||
$data['is_join_guild'] = 2;
|
||||
$data['guild_info'] = (object)[];
|
||||
$join_guild = db::name('user_guild')->where(['uid'=>$from_id,'status'=>1,'is_delete'=>1])->find();
|
||||
if(!empty($join_guild)){
|
||||
$guild_info = db::name('guild')
|
||||
->alias('g')
|
||||
->join('yy_user u','u.uid = g.uid')
|
||||
->where(['g.id'=>$join_guild['guild_id'],'g.is_delete'=>1,'g.is_show'=>1])
|
||||
->field('g.*,u.head_pic as ghz_head_pic,u.base64_nick_name as ghz_nick_name')
|
||||
->find();
|
||||
if(!empty($guild_info)){
|
||||
$guild_info['guild_name'] = mb_convert_encoding(base64_decode($guild_info['base64_guild_name']), 'UTF-8', 'UTF-8');
|
||||
$guild_info['cover'] = localpath_to_netpath($guild_info['cover']);
|
||||
|
||||
$guild_info['ghz_nick_name'] = mb_convert_encoding(base64_decode($guild_info['ghz_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$guild_info['ghz_head_pic'] = localpath_to_netpath($guild_info['ghz_head_pic']);
|
||||
$data['guild_info'] = $guild_info;
|
||||
$data['is_join_guild'] = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//获取实名认证状态
|
||||
public function get_player_real_status($uid)
|
||||
{
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if ($user_info['is_real'] == 1) {
|
||||
return ['code' => 200, 'msg' => '已实名', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '未实名', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//实名信息提交
|
||||
public function real_name_authentication($uid, $real_name, $card_id, $identity1, $identity2)
|
||||
{
|
||||
|
||||
if (empty($real_name)) {
|
||||
return ['code' => 201, 'msg' => '真实姓名必须', 'data' => null];
|
||||
}
|
||||
if (empty($card_id)) {
|
||||
return ['code' => 201, 'msg' => '身份证号必须', 'data' => null];
|
||||
}
|
||||
|
||||
// if (empty($identity1)) {
|
||||
// return ['code' => 201, 'msg' => '身份证正面必须', 'data' => null];
|
||||
// }
|
||||
|
||||
// if (empty($identity2)) {
|
||||
// return ['code' => 201, 'msg' => '身份证反面必须', 'data' => null];
|
||||
// }
|
||||
$map = [];
|
||||
$map[] = ['card_id', '=', $card_id];
|
||||
|
||||
$user_count = db::name('user')->where($map)->count();
|
||||
if($user_count > 2) {
|
||||
return ['code' => 201, 'msg' => '该身份证已认证两个账号,不能再认证', 'data' => null];
|
||||
}
|
||||
// if (!empty($user_info) && $user_info['uid'] != $uid) {
|
||||
// // return ['code' => 201, 'msg' => '该身份证号已被使用', 'data' => null];
|
||||
// }
|
||||
$month_time = strtotime(date("Y-m-01"));
|
||||
$real_month_time = 0;
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if ($user_info['is_real'] == 1) {
|
||||
if($month_time == $user_info['real_month_time']){
|
||||
return ['code' => 201, 'msg' => '本月无法再次换绑身份证号', 'data' => null];
|
||||
}
|
||||
$real_month_time = $month_time;
|
||||
}
|
||||
|
||||
if ($user_info['is_real'] == 3) {
|
||||
return ['code' => 201, 'msg' => '实名审核中,请勿重复提交', 'data' => null];
|
||||
}
|
||||
|
||||
$age = getAgeId($card_id);
|
||||
if(!$age){
|
||||
return ['code' => 201, 'msg' => '该身份证号未满18岁', 'data' => null];
|
||||
}
|
||||
|
||||
//调用第三方实名认证接口
|
||||
$reslut = model('api/AliRealNameVerify')->real_name_verify($real_name, $card_id);
|
||||
if($reslut['code'] == 201){
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_real', '=', 2];
|
||||
$data = [];
|
||||
$data['is_real'] = 1;
|
||||
$data['real_name'] = $real_name;
|
||||
$data['card_id'] = $card_id;
|
||||
$data['identity1'] = $identity1;
|
||||
$data['identity2'] = $identity2;
|
||||
$data['real_month_time'] = $real_month_time;
|
||||
$data['update_time'] = time();
|
||||
|
||||
// 启动事务
|
||||
Db::startTrans();
|
||||
try {
|
||||
//提交认证
|
||||
$reslut = db::name('user')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '提交失败', 'data' => null];
|
||||
}
|
||||
|
||||
//是否已创建过房间
|
||||
$room_info = db::name('room')->where('room_owner_uid', $uid)->find();
|
||||
if(empty($room_info)){
|
||||
//创建房间
|
||||
$cate_id = 18;
|
||||
$room_password = '';
|
||||
$room_cover = '/uploads/head_pic/head_pic.png';
|
||||
$room_intro = '本房间严禁刷屏,禁止非法广告及宣传,禁止引战、地域黑、言语攻击等。';
|
||||
$room_background_id = db::name('room_background')->where(['is_delete' => 1,'status' => 1])->order('bid asc')->value('bid');
|
||||
$room_create = model('room')->user_create_room($uid, $user_info['nick_name'], $cate_id, $user_info['head_pic'], $room_password, $room_intro, $room_background_id);
|
||||
if($room_create['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $room_create['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//如果已申请、加入工会 更新工会信息
|
||||
$guild_list = Db::name('user_guild')->where(['status' => [1,2], 'is_delete' => 1, 'rid' => 0, 'uid' => $uid])->select();
|
||||
if($guild_list) {
|
||||
$rid = Db::name('room')->where(['room_owner_uid' => $uid])->value('rid');
|
||||
$result = Db::name('user_guild')->where(['status' => [1,2], 'is_delete' => 1, 'rid' => 0, 'uid' => $uid])->update(['rid' => $rid, 'card_id' => $card_id]);
|
||||
if(!$result) {
|
||||
return ['code' => 201, 'msg' => '创建失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '开启成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '提交失败', 'data' => null];
|
||||
}
|
||||
|
||||
// $reslut = db::name('user')->where($map)->update($data);
|
||||
// if ($reslut) {
|
||||
// return ['code' => 200, 'msg' => '提交成功', 'data' => null];
|
||||
// } else {
|
||||
// return ['code' => 201, 'msg' => '提交失败', 'data' => null];
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
//申请陪玩
|
||||
public function apply_play_game($uid, $gid, $lid, $price, $skill_image, $cover_image, $sound, $sound_duration, $introduction)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$palyer_info = db::name('user_player')->where($map)->find();
|
||||
if (!empty($palyer_info)) {
|
||||
return ['code' => 201, 'msg' => '该游戏陪玩您已申请', 'data' => null];
|
||||
}
|
||||
$game_info = db::name('game')->find($gid);
|
||||
if (empty($game_info)) {
|
||||
return ['code' => 201, 'msg' => '陪玩游戏不存在', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['lid', '=', $lid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$game_skill_level_info = db::name('game_skill_level')->where($map)->find();
|
||||
if (empty($game_skill_level_info)) {
|
||||
return ['code' => 201, 'msg' => '陪玩游戏等级不存在', 'data' => null];
|
||||
}
|
||||
if (empty($skill_image)) {
|
||||
return ['code' => 201, 'msg' => '陪玩技能图不能为空', 'data' => null];
|
||||
}
|
||||
if (empty($cover_image)) {
|
||||
return ['code' => 201, 'msg' => '封面图不能为空', 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['gid'] = $gid;
|
||||
$data['lid'] = $lid;
|
||||
$data['price'] = $price;
|
||||
$data['skill_image'] = $skill_image;
|
||||
$data['cover_image'] = $cover_image;
|
||||
$data['sound'] = $sound;
|
||||
$data['sound_duration'] = $sound_duration;
|
||||
$data['introduction'] = $introduction;
|
||||
$data['is_business'] = 1; //默认接单中
|
||||
$data['status'] = 1; //默认审核中
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$validate = validate('admin/UserPlayer');
|
||||
$reslut = $validate->scene('apiAdd')->check($data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
}
|
||||
$reslut = model('admin/UserPlayer')->save($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '提交成功,请等待审核', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '提交失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//修改 陪玩信息
|
||||
public function edit_play_game($uid, $gid, $lid, $price, $skill_image, $cover_image, $sound, $sound_duration, $introduction)
|
||||
{
|
||||
|
||||
$game_info = db::name('game')->find($gid);
|
||||
if (empty($game_info)) {
|
||||
return ['code' => 201, 'msg' => '陪玩游戏不存在', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['lid', '=', $lid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$game_skill_level_info = db::name('game_skill_level')->where($map)->find();
|
||||
if (empty($game_skill_level_info)) {
|
||||
return ['code' => 201, 'msg' => '陪玩游戏等级不存在', 'data' => null];
|
||||
}
|
||||
if (empty($skill_image)) {
|
||||
return ['code' => 201, 'msg' => '陪玩技能图不能为空', 'data' => null];
|
||||
}
|
||||
if (empty($cover_image)) {
|
||||
return ['code' => 201, 'msg' => '封面图不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$pid = db::name('user_player')->where($map)->value('pid');
|
||||
if (empty($pid)) {
|
||||
return ['code' => 201, 'msg' => '陪玩信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['lid'] = $lid;
|
||||
$data['price'] = $price;
|
||||
$data['skill_image'] = $skill_image;
|
||||
$data['cover_image'] = $cover_image;
|
||||
$data['sound'] = $sound;
|
||||
$data['sound_duration'] = $sound_duration;
|
||||
$data['introduction'] = $introduction;
|
||||
$data['is_business'] = 1; //默认接单中
|
||||
$data['status'] = 1; //默认审核中
|
||||
$data['update_time'] = time();
|
||||
$validate = validate('admin/UserPlayer');
|
||||
$reslut = $validate->scene('apiEdit')->check($data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
}
|
||||
$reslut = db::name('user_player')->where(['pid' => $pid])->update($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '提交成功,请等待审核', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '提交失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_player_game_list($uid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = db::name('game')->field('gid,game_name,game_ico,game_ico1,game_ico2,sort')->where($map)->order('sort desc')->select();
|
||||
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['status'] = 0;
|
||||
$v['game_ico'] = localpath_to_netpath($v['game_ico']);
|
||||
$v['game_ico1'] = localpath_to_netpath($v['game_ico1']);
|
||||
$v['game_ico2'] = localpath_to_netpath($v['game_ico2']);
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['gid', '=', $v['gid']];
|
||||
$status = db::name('user_player')->where($map)->value('status');
|
||||
|
||||
if (!empty($status)) {
|
||||
$v['status'] = $status;
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
//获取提交审核状态详情
|
||||
public function get_apply_status($uid, $gid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$palyer_info = db::name('user_player')->field('gid,status,remarks')->where($map)->find();
|
||||
if (empty($palyer_info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $palyer_info];
|
||||
}
|
||||
//获取提交详情
|
||||
public function get_apply_info($uid, $gid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$player_info = db::name('user_player')->field('gid,lid,price,skill_image,cover_image,sound,sound_duration,introduction,status,remarks')->where($map)->find();
|
||||
if (empty($player_info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
$game = db::name('game')->field('game_name,cover_image,skill_image')->where(['gid' => $gid])->find();
|
||||
$player_info['sound'] = localpath_to_netpath($player_info['sound']);
|
||||
$player_info['skill_image'] = localpath_to_netpath($player_info['skill_image']);
|
||||
$player_info['cover_image'] = localpath_to_netpath($player_info['cover_image']);
|
||||
$player_info['game_level_name'] = db::name('game_skill_level')->where(['lid' => $player_info['lid']])->value('game_level_name');
|
||||
$player_info['game_name'] = $game['game_name'];
|
||||
$player_info['game_cover_image'] = localpath_to_netpath($game['cover_image']);
|
||||
$player_info['game_skill_image'] = localpath_to_netpath($game['skill_image']);
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $player_info];
|
||||
}
|
||||
|
||||
//获取陪玩游戏 信息 及列表
|
||||
public function get_player_game_lists($pid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['pid', '=', $pid];
|
||||
$palyer_info = db::name('user_player')->field('pid,uid,gid,price,status')->where($map)->find();
|
||||
$game_name = db::name('game')->where(['gid' => $palyer_info['gid']])->value('game_name');
|
||||
$user_info = db::name('user')->where(['uid' => $palyer_info['uid']])->find();
|
||||
|
||||
$arr1 = [];
|
||||
$arr1['pid'] = $palyer_info['pid'];
|
||||
$arr1['price'] = $palyer_info['price'];
|
||||
$arr1['game_name'] = $game_name;
|
||||
$arr1['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$arr1['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $palyer_info['uid']];
|
||||
$arr2 = db::name('user_player')->alias('a')->join('yy_game b', 'a.gid = b.gid')->field('a.pid,a.price,b.game_name')->where($map)->select();
|
||||
|
||||
if ($user_info['is_real'] != 1 || $palyer_info['status'] != 2) {
|
||||
$data['palyer_game_list'] = [];
|
||||
} else {
|
||||
$data['palyer_game_list'] = $arr2;
|
||||
}
|
||||
$data['palyer_info'] = $arr1;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//首页搜索
|
||||
public function search($uid, $keywords)
|
||||
{
|
||||
if (empty($keywords)) {
|
||||
$data = [];
|
||||
$data['user'] = [];
|
||||
$data['play'] = [];
|
||||
$data['room'] = [];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
//记录所有关键词
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['search_content'] = $keywords;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
db::name('user_search')->insert($data);
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid|nick_name|special_uid', 'like', '%' . $keywords . '%'];
|
||||
$map[] = ['login_status', '<>', 3];
|
||||
$arr1 = db::name('user')->where($map)->field('uid,base64_nick_name,head_pic,special_uid')->limit(0, 30)->select();
|
||||
if (!empty($arr1)) {
|
||||
foreach ($arr1 as $k => &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
unset($v['base64_nick_name']);
|
||||
}
|
||||
}
|
||||
|
||||
// $map = [];
|
||||
// $map[] = ['b.uid|b.nick_name|b.special_uid', 'like', '%' . $keywords . '%'];
|
||||
// $map[] = ['a.status', '=', 2];
|
||||
// $model = Db::name('user_player')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
// $arr2 = $model->where($map)->field('a.pid,a.skill_image,a.cover_image,a.order_count,a.price,b.uid,b.base64_nick_name,b.head_pic,b.special_uid')->limit(0, 30)->select();
|
||||
// if (!empty($arr2)) {
|
||||
// foreach ($arr2 as $k => &$v) {
|
||||
// $v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
// $v['skill_image'] = localpath_to_netpath($v['skill_image']);
|
||||
// $v['cover_image'] = localpath_to_netpath($v['cover_image']);
|
||||
// unset($v['base64_nick_name']);
|
||||
// }
|
||||
// }
|
||||
|
||||
$map = [];
|
||||
$map[] = ['b.uid|b.nick_name|b.special_uid|a.room_name|a.room_number', 'like', '%' . $keywords . '%'];
|
||||
$map[] = ['a.room_status', '=', 1];
|
||||
$map[] = ['b.login_status', '<>', 3];
|
||||
$model = Db::name('room')->alias('a')->join('yy_user b', 'a.room_owner_uid = b.uid');
|
||||
$arr3 = $model->where($map)->field('a.rid,a.room_number,a.room_name,a.room_cover,b.uid,b.base64_nick_name,b.head_pic,b.special_uid')->limit(0, 30)->select();
|
||||
if (!empty($arr3)) {
|
||||
foreach ($arr3 as $k => &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['room_cover'] = localpath_to_netpath($v['room_cover']);
|
||||
unset($v['base64_nick_name']);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['user'] = $arr1;
|
||||
$data['play'] = [];
|
||||
$data['room'] = $arr3;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//申请陪玩可选金额
|
||||
public function get_player_price_list()
|
||||
{
|
||||
$player_unit_price_list = get_system_config('player_unit_price_list');
|
||||
$data = explode(',', $player_unit_price_list);
|
||||
return ajaxReturn(200, '获取成功', $data);
|
||||
}
|
||||
}
|
||||
560
application/api/model/PubRoom.php
Normal file
560
application/api/model/PubRoom.php
Normal file
@@ -0,0 +1,560 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class PubRoom extends Model
|
||||
{
|
||||
|
||||
//麦位到期更新
|
||||
public function close_room_date_micro(){
|
||||
$now_time = time();
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['end_time', '<', $now_time];
|
||||
$room_date_micro_list = db::name('room_date_micro')->field('id,rid,uid,micro_id')->where($map)->select();
|
||||
if(!empty($room_date_micro_list)){
|
||||
foreach ($room_date_micro_list as $k => $v){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$update = [];
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_date_micro')->where('id', $v['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->where('rid', $v['rid'])->field('rid, room_micro,cate_id')->find();
|
||||
// $room_micro_array = explode(',', $room_info['room_micro']);
|
||||
// if($room_micro_array[$v['micro_id']] == $v['uid'] && $room_info['cate_id'] == 19){
|
||||
// model('api/room')->user_down_micro($v['uid'], $v['rid']);
|
||||
// }
|
||||
$room_micro_info = db::name('room_micro')->where('rid', $v['rid'])->where('uid', $v['uid'])->find();
|
||||
if($room_micro_info){
|
||||
if($room_info['cate_id'] == 19){
|
||||
model('api/room')->user_down_micro($v['uid'], $v['rid']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//心愿礼物列表
|
||||
public function get_wish_gift_list($uid, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 1000 ? $page_limit : 1000;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['gift_price', '>', 0];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_wish', '=', 1];
|
||||
$gift_list = db::name('gift')->where($map)->field('gid,gift_type,gift_name,gift_price,base_image,play_image,is_public_screen,is_public_server')->order('sort desc,gift_price asc')->select();
|
||||
foreach ($gift_list as $k => &$v){
|
||||
$v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
// if(empty($v['gift_label'])){
|
||||
// $v['gift_label'] = '';
|
||||
// }
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $gift_list];
|
||||
}
|
||||
|
||||
|
||||
//麦上用户配置心愿礼物
|
||||
public function oprate_user_wish_gift($uid, $rid, $micro_id, $gid){
|
||||
$user_info = db::name('user')->field('uid')->find();
|
||||
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($gid != 0){
|
||||
//该礼物是否存在
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['gift_price', '>', 0];
|
||||
$map[] = ['type', '=', 1];
|
||||
$gift_info = db::name('gift')->where($map)->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '该心愿礼物不存在', 'data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
$micro_id = (int) $micro_id;
|
||||
// $room_micro_array = explode(',', $room_info['room_micro']);
|
||||
$room_micro_array = db::name('room_micro')->where('rid', $rid)->order('micro_id asc')->column('uid');
|
||||
if($room_micro_array[$micro_id] != $uid){
|
||||
return ['code' => 201, 'msg' => '你所在麦位信息错误', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', '=', $micro_id];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_room_date_micro = db::name('room_date_micro')->where($map)->order('id desc')->find();
|
||||
if(!$user_room_date_micro){
|
||||
return ['code' => 201, 'msg' => '你尚未有在该麦位信息', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
//设置心愿礼物
|
||||
$update = [];
|
||||
$update['wish_gid'] = $gid;
|
||||
if($gid != 0){
|
||||
$update['wish_gift_name'] = $gift_info['gift_name'];
|
||||
}else{
|
||||
$update['wish_gift_name'] = '';
|
||||
}
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_date_micro')->where('id', $user_room_date_micro['id'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
model('room')->push_room_micro_data($rid);
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//撩他
|
||||
public function tease_user_send_gift($uid, $rid, $receive_uid){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->field('rid')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息错误', 'data' => null];
|
||||
}
|
||||
|
||||
//用户是否在麦上
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $receive_uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 1];
|
||||
$room_date_micro_info = db::name('room_date_micro')->where($map)->order('id desc')->find();
|
||||
if(!$room_date_micro_info){
|
||||
return ['code' => 201, 'msg' => '该用户暂未在麦上', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有设置撩Ta礼物
|
||||
$config = get_uncache_system_config();
|
||||
if(empty($config['tease_gift_id'])){
|
||||
return ['code' => 201, 'msg' => '暂未设置撩TA礼物,请联系管理', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $config['tease_gift_id']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$gift_info = db::name('gift')->where($map)->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '暂未设置撩TA礼物,请联系管理', 'data' => null];
|
||||
}
|
||||
|
||||
//送礼物
|
||||
$reslut = model('api/Gift')->send_gift($uid, $receive_uid, $rid, $config['tease_gift_id'], 1, 1, 0);
|
||||
if($reslut['code'] == 201){
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$sutain_time = 1;
|
||||
|
||||
//添加记录
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['rid'] = $rid;
|
||||
$insert['receive_uid'] = $receive_uid;
|
||||
$insert['send_gid'] = $config['tease_gift_id'];
|
||||
$insert['sustain_time'] = $sutain_time;
|
||||
$insert['add_time'] = time();
|
||||
$insert['end_time'] = time() + ($sutain_time * 60);
|
||||
db::name('user_tease_log')->insert($insert);
|
||||
|
||||
|
||||
|
||||
$pust_data = [];
|
||||
$pust_data['code'] = 1014;
|
||||
$pust_data['msg'] = '撩他';
|
||||
$push_data1 = [];
|
||||
$push_data1['img'] = 'https://mier-1333389464.cos.ap-chengdu.myqcloud.com/pub/pub.gif';
|
||||
$push_data1['receive_uid'] = $receive_uid;
|
||||
$pust_data['data'] = $push_data1;
|
||||
$push_is_open = model('api/WebSocketPush')->send_to_group($rid, $pust_data);
|
||||
|
||||
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
|
||||
//一键全撩
|
||||
public function tease_all_send_gift($uid, $rid, $to_uid_list){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->field('rid')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息错误', 'data' => null];
|
||||
}
|
||||
|
||||
$to_uid_array = explode(',',trim($to_uid_list,','));
|
||||
|
||||
//用户是否在麦上
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', $to_uid_array];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 1];
|
||||
$room_date_micro_info = db::name('room_date_micro')->where($map)->order('id desc')->select();
|
||||
if(!$room_date_micro_info){
|
||||
return ['code' => 201, 'msg' => '当前无可撩对象', 'data' => null];
|
||||
}
|
||||
|
||||
if(count($to_uid_array) != count($room_date_micro_info)){
|
||||
return ['code' => 201, 'msg' => '当前无可撩对象', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有设置撩Ta礼物
|
||||
$config = get_uncache_system_config();
|
||||
if(empty($config['tease_gift_id'])){
|
||||
return ['code' => 201, 'msg' => '暂未设置撩TA礼物,请联系管理', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['gid', '=', $config['tease_gift_id']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$gift_info = db::name('gift')->where($map)->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '暂未设置撩TA礼物,请联系管理', 'data' => null];
|
||||
}
|
||||
|
||||
//送礼物
|
||||
$reslut = model('api/Gift')->send_gift($uid, $to_uid_list, $rid, $config['tease_gift_id'], 1, 1, 0);
|
||||
if($reslut['code'] == 201){
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$sutain_time = 1;
|
||||
|
||||
//添加记录
|
||||
$insert_data = [];
|
||||
foreach($to_uid_array as $k => $v){
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['rid'] = $rid;
|
||||
$insert['receive_uid'] = $v;
|
||||
$insert['send_gid'] = $config['tease_gift_id'];
|
||||
$insert['sustain_time'] = $sutain_time;
|
||||
$insert['add_time'] = time();
|
||||
$insert['end_time'] = time() + ($sutain_time * 60);
|
||||
$insert_data[] = $insert;
|
||||
}
|
||||
|
||||
db::name('user_tease_log')->insertAll($insert_data);
|
||||
|
||||
|
||||
$pust_data = [];
|
||||
$pust_data['code'] = 1015;
|
||||
$pust_data['msg'] = '一键全撩';
|
||||
$push_data1 = [];
|
||||
$push_data1['img'] = 'https://mier-1333389464.cos.ap-chengdu.myqcloud.com/pub/pub.gif';
|
||||
$push_data1['to_uid_list'] = $to_uid_array;
|
||||
$pust_data['data'] = $push_data1;
|
||||
$push_is_open = model('api/WebSocketPush')->send_to_group($rid, $pust_data);
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
|
||||
}
|
||||
|
||||
//心愿礼物详情
|
||||
public function wish_gift_info($uid, $rid, $receive_uid){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->field('rid,room_micro')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$receive_info = db::name('user')->where('uid', $receive_uid)->find();
|
||||
if(!$receive_uid){
|
||||
return ['code' => 201, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//用户是否在麦上
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $receive_uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 1];
|
||||
$room_date_micro_info = db::name('room_date_micro')->where($map)->order('id desc')->find();
|
||||
if(!$room_date_micro_info){
|
||||
return ['code' => 201, 'msg' => '该用户暂未在麦上', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有设置心愿礼物
|
||||
if(empty($room_date_micro_info['wish_gid'])){
|
||||
return ['code' => 201, 'msg' => '该用户尚未设置心愿礼物', 'data' => null];
|
||||
}
|
||||
|
||||
$gift_info = db::name('Gift')->where('gid', $room_date_micro_info['wish_gid'])->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '该心愿礼物不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $receive_uid;
|
||||
$data['nick_name'] = mb_convert_encoding(base64_decode($receive_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data['head_pic'] = localpath_to_netpath($receive_info['head_pic']);
|
||||
$data['gift_name'] = $gift_info['gift_name'];
|
||||
$data['base_image'] = localpath_to_netpath($gift_info['base_image']);
|
||||
$data['gift_price'] = $gift_info['gift_price'];
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//约TA
|
||||
public function date_user_send_gift($uid, $rid, $receive_uid){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->field('rid,room_micro,room_host_uid')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($room_info['room_host_uid'] == $uid){
|
||||
return ['code' => 201, 'msg' => '主持不可约TA!', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//用户是否在麦上
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $receive_uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 1];
|
||||
$room_date_micro_info = db::name('room_date_micro')->where($map)->order('id desc')->find();
|
||||
if(!$room_date_micro_info){
|
||||
return ['code' => 201, 'msg' => '该用户暂未在麦上', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有设置心愿礼物
|
||||
if(empty($room_date_micro_info['wish_gid'])){
|
||||
return ['code' => 201, 'msg' => '该用户尚未设置心愿礼物', 'data' => null];
|
||||
}
|
||||
$now_time = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
//添加记录
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['rid'] = $rid;
|
||||
$insert['receive_uid'] = $receive_uid;
|
||||
$insert['wish_gid'] = $room_date_micro_info['wish_gid'];
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_blind_date_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户下麦
|
||||
$receive_micro = db::name('room_micro')->where('uid', $receive_uid)->where('rid', $rid)->find();
|
||||
if($receive_micro){
|
||||
$reslut = db::name('room_micro')->where('id', $receive_micro['id'])->update(['uid' => 0, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//清除麦位魅力值
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $receive_uid];
|
||||
// $map[] = ['rid', '=', $rid];
|
||||
$data = [];
|
||||
$data['charm_value'] = 0;
|
||||
$data['update_time'] = time();
|
||||
$info = db::name('room_user_cc')->where($map)->find();
|
||||
if($info){
|
||||
$reslut = db::name('room_user_cc')->where($map)->update($data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$uid_micro = db::name('room_micro')->where('uid', $uid)->where('rid', $rid)->find();
|
||||
if($uid_micro){
|
||||
$reslut = db::name('room_micro')->where('id', $uid_micro['id'])->update(['uid' => 0, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
//清除麦位魅力值
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
// $map[] = ['rid', '=', $rid];
|
||||
$data = [];
|
||||
$data['charm_value'] = 0;
|
||||
$data['update_time'] = time();
|
||||
$info = db::name('room_user_cc')->where($map)->find();
|
||||
if($info){
|
||||
$reslut = db::name('room_user_cc')->where($map)->update($data);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$prid = 0;
|
||||
//是否有空闲的私密小屋
|
||||
$map = [];
|
||||
$map[] = ['is_use', '=', 2];
|
||||
$room_privacy = db::name('room_privacy')->where($map)->find();
|
||||
if(!empty($room_privacy)){
|
||||
$update = [];
|
||||
$update['rid'] = $rid;
|
||||
$update['uid_data'] = $uid.','.$receive_uid;
|
||||
$update['is_use'] = 1;
|
||||
$update['update_time'] = $now_time;
|
||||
$update['end_time'] = $now_time + $config['privacy_room_time'];
|
||||
$reslut = db::name('room_privacy')->where('prid', $room_privacy['prid'])->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
$prid = $room_privacy['prid'];
|
||||
}else{
|
||||
$reslut = model('api/DatingRoom')->create_privacy_room();
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$prid = $reslut['data'];
|
||||
|
||||
$update = [];
|
||||
$update['rid'] = $rid;
|
||||
$update['uid_data'] = $uid.','.$receive_uid;
|
||||
$update['is_use'] = 1;
|
||||
$update['update_time'] = $now_time;
|
||||
$update['end_time'] = $now_time + $config['privacy_room_time'];
|
||||
$reslut = db::name('room_privacy')->where('prid', $prid)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($prid)){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
//送礼物
|
||||
$reslut = model('api/Gift')->send_gift($uid, $receive_uid, $rid, $room_date_micro_info['wish_gid'], 1, 1, 0);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
if(!empty($uid)){
|
||||
$push_send_user_data = [];
|
||||
$push_send_user_data['rid'] = $rid;
|
||||
$push_send_user_data['prid'] = $prid;
|
||||
$push_send_user_data['agora_token'] = model('api/Agora')->agora_token_info($uid, $prid);
|
||||
$push_send_user_data['agora_app_id'] = $config['agora_app_id'];
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 351;
|
||||
$push_data['msg'] = "推送进入私密小屋";
|
||||
$push_data['data'] = $push_send_user_data;
|
||||
model('api/WebSocketPush')->send_to_one($uid, $push_data);
|
||||
}
|
||||
|
||||
if(!empty($receive_uid)){
|
||||
$push_send_receive_data = [];
|
||||
$push_send_receive_data['rid'] = $rid;
|
||||
$push_send_receive_data['prid'] = $prid;
|
||||
$push_send_receive_data['agora_token'] = model('api/Agora')->agora_token_info($receive_uid, $prid);
|
||||
$push_send_receive_data['agora_app_id'] = $config['agora_app_id'];
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 351;
|
||||
$push_data['msg'] = "推送进入私密小屋";
|
||||
$push_data['data'] = $push_send_receive_data;
|
||||
model('api/WebSocketPush')->send_to_one($receive_uid, $push_data);
|
||||
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
258
application/api/model/Rongyun.php
Normal file
258
application/api/model/Rongyun.php
Normal file
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use RongCloud;
|
||||
|
||||
class Rongyun extends Model
|
||||
{
|
||||
|
||||
//融云
|
||||
protected function reg_rongyun($type, $ry_uid, $nickname = '', $headimg = '')
|
||||
{
|
||||
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
$user = [
|
||||
'id' => $ry_uid,
|
||||
'name' => $nickname, //用户名称
|
||||
'portrait' => $headimg //用户头像
|
||||
];
|
||||
if ($type == 1) {
|
||||
$res = $RongSDK->getUser()->register($user);
|
||||
} elseif ($type == 2) {
|
||||
$res = $RongSDK->getUser()->register($user);
|
||||
} else {
|
||||
return ['code' => 0, 'info' => 'not found type'];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
//获取融云黑名单
|
||||
public function get_blacklist($uid){
|
||||
$reslut = $this->reg_blacklist($uid);
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', $reslut['users']];
|
||||
$user_info = db::name('user')->field('uid,base64_nick_name,head_pic')->where($map)->select();
|
||||
foreach ($user_info as $k => &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
}
|
||||
if($reslut['code'] == 200){
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_info];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '获取失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//添加融云黑名单
|
||||
public function add_blacklist($uid,$user_id){
|
||||
$user_id = explode(',',$user_id);
|
||||
$reslut = $this->reg_add_blacklist($uid,$user_id);
|
||||
if($reslut['code'] == 200){
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//删除融云黑名单
|
||||
public function remove_blacklist($uid,$user_id){
|
||||
$user_id = explode(',',$user_id);
|
||||
$reslut = $this->reg_remove_blacklist($uid,$user_id);
|
||||
if($reslut['code'] == 200){
|
||||
return ['code' => 200, 'msg' => '移除成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '移除失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//获取黑名单
|
||||
public function blacklist($uid){
|
||||
$reslut = $this->reg_blacklist($uid);
|
||||
if($reslut['code'] == 200){
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $reslut['users']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '获取失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//融云查询黑名单
|
||||
protected function reg_blacklist($uid){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
$user = [
|
||||
'id' => $uid
|
||||
];
|
||||
|
||||
if($uid){
|
||||
$res = $RongSDK->getUser()->Blacklist()->getList($user);
|
||||
}else{
|
||||
return ['code' => 0, 'info' => 'not found uid'];
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
//融云添加用户黑名单
|
||||
protected function reg_add_blacklist($uid,$user_id){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
$user = [
|
||||
'id' => $uid,
|
||||
'blacklist' => $user_id
|
||||
];
|
||||
|
||||
if($uid){
|
||||
$res = $RongSDK->getUser()->Blacklist()->add($user);
|
||||
}else{
|
||||
return ['code' => 0, 'info' => 'not found uid'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
//融云添加用户黑名单
|
||||
protected function reg_remove_blacklist($uid,$user_id){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
$user = [
|
||||
'id' => $uid,
|
||||
'blacklist' => $user_id
|
||||
];
|
||||
|
||||
if($uid){
|
||||
$res = $RongSDK->getUser()->Blacklist()->remove($user);
|
||||
}else{
|
||||
return ['code' => 0, 'info' => 'not found uid'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
//融云 检查用户在线状态
|
||||
public function checkOnline($id)
|
||||
{
|
||||
|
||||
die();
|
||||
$user = [
|
||||
'id' => $id
|
||||
];
|
||||
require_once Env::get('root_path') . "/vendor/RongCloud/RongCloud.php";
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
$result = $RongSDK->checkuser()->check($user);
|
||||
// $update = $RongSDK->getUser()->update($user);
|
||||
// $res = $RongSDK->getUser()->MuteGroups()->getList(['test1']);
|
||||
return $res;
|
||||
}
|
||||
*/
|
||||
|
||||
//创建融云群组
|
||||
public function create_rongyun_group(){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
|
||||
$group = [
|
||||
'id'=> '7777',//群组 id
|
||||
'name'=> 'admin',//群组名称
|
||||
'members'=>[ //群成员 列表
|
||||
['id'=> '9999']
|
||||
// ['id'=> 'uPj70HUrRSUk-ixtt7iIGc'],['id'=>'Vu-oC0_LQ6kgPqltm_zYtI']
|
||||
]
|
||||
];
|
||||
|
||||
$res = $RongSDK->getGroup()->create($group);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
//获取融云群组信息
|
||||
public function get_rongyun_group(){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
|
||||
$group = [
|
||||
'id'=> '7777',//群组 id
|
||||
];
|
||||
|
||||
$res = $RongSDK->getGroup()->get($group);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
//加入融云群组
|
||||
public function join_rongyun_group($uid){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
|
||||
$group = [
|
||||
'id'=> '7777',//群组 id
|
||||
'name'=> "admin",//群组名称
|
||||
'member'=>['id'=> $uid],//群成员信息
|
||||
];
|
||||
|
||||
if($uid){
|
||||
$res = $RongSDK->getGroup()->joins($group);
|
||||
}else{
|
||||
return ['code' => 0, 'info' => 'not found uid'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
//退出群组
|
||||
public function quit_rongyun_group($uid){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
|
||||
$group = [
|
||||
'id'=> '7777',//群组 id
|
||||
'member'=>['id'=> $uid],//群成员信息
|
||||
];
|
||||
|
||||
if($uid){
|
||||
$res = $RongSDK->getGroup()->quit($group);
|
||||
}else{
|
||||
return ['code' => 0, 'info' => 'not found uid'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
//解散融云群组
|
||||
public function dismiss_rongyun_group(){
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$AppKey = $config['ry_app_key'];
|
||||
$AppSecret = $config['ry_app_secret'];
|
||||
$RongSDK = new \RongCloud\RongCloud($AppKey, $AppSecret);
|
||||
|
||||
$group = [
|
||||
'id'=> '7777',//群组 id
|
||||
'member'=>['id'=> '9999']//管理员信息
|
||||
];
|
||||
|
||||
$res = $RongSDK->getGroup()->dismiss($group);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
4714
application/api/model/Room.php
Normal file
4714
application/api/model/Room.php
Normal file
File diff suppressed because it is too large
Load Diff
864
application/api/model/RoomApplyMicro.php
Normal file
864
application/api/model/RoomApplyMicro.php
Normal file
@@ -0,0 +1,864 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomApplyMicro extends Model
|
||||
{
|
||||
|
||||
//申请上台列表
|
||||
public function apply_room_micro($uid, $rid){
|
||||
$user_info = db::name('user')->field('uid,add_time')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//新人厅,不是新人无法申请
|
||||
if($room_info['cate_id'] == 26){
|
||||
//该用户是否是新人
|
||||
$is_new_time = $user_info['add_time'] + (60*60*24*7);
|
||||
if(time() > $is_new_time){
|
||||
return ['code' => 201, 'msg' => '您不是新人,无法申请', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否已被签约
|
||||
$map = [];
|
||||
$map[] = ['sign_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_contract = db::name('user_sign_contract')->where($map)->find();
|
||||
if($user_contract){
|
||||
return ['code' => 201, 'msg' => '您已签约过,无法再次申请', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($uid == $room_info['room_host_uid']){
|
||||
return ['code' => 201, 'msg' => '您已在主持麦,无法申请', 'data' => null];
|
||||
}
|
||||
|
||||
//用户是否在麦上
|
||||
$room_micro_list = db::name('room_micro')->where('rid', $rid)->order('micro_id asc')->column('uid');
|
||||
$user_room_micro = db::name('room_micro')->where('rid', $rid)->where('uid', $uid)->find();
|
||||
if(in_array($room_info['cate_id'], [27,28])){
|
||||
if(in_array($user_room_micro['micro_id'], [1,2,3,4,9])){
|
||||
return ['code' => 201, 'msg' => '您已在麦上,请勿再次申请', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
if(in_array($uid, $room_micro_list)){
|
||||
return ['code' => 201, 'msg' => '您已在麦上,请勿再次申请', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//是否已申请
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_micro_aisle = db::name('room_micro_aisle')->where($map)->find();
|
||||
if($room_micro_aisle){
|
||||
return ['code' => 201, 'msg' => '您已提交过该申请', 'data' => null];
|
||||
}
|
||||
|
||||
//是否已达申请上限
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['type', '=', 1];
|
||||
$apply_common_count = db::name('room_micro_aisle')->where($map)->count();
|
||||
if($apply_common_count >= 20){
|
||||
return ['code' => 201, 'msg' => '申请人数已达上限,请稍后', 'data' => null];
|
||||
}
|
||||
|
||||
//
|
||||
Db::startTrans();
|
||||
try {
|
||||
//添加申请
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['rid'] = $rid;
|
||||
$insert['type'] = 1;
|
||||
$insert['add_time'] = time();
|
||||
$insert['status'] = 2;
|
||||
$reslut = db::name('room_micro_aisle')->insert($insert);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '申请失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
$this->update_room_micro_aisle($uid, $rid);
|
||||
|
||||
return ['code' => 200, 'msg' => '申请成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '申请失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//取消申请
|
||||
public function unapply_room_micro($uid, $rid, $id){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $id];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$user_room_micro_aisle = db::name('room_micro_aisle')->where($map)->find();
|
||||
if(!$user_room_micro_aisle){
|
||||
return ['code' => 201, 'msg' => '该申请不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_room_micro_aisle['is_delete'] == 2 || $user_room_micro_aisle['status'] != 2){
|
||||
return ['code' => 201, 'msg' => '该申请已被处理', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$update = [];
|
||||
$update['user_id'] = $uid;
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_aisle')->where('id', $id)->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '取消失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
$this->update_room_micro_aisle($uid, $rid);
|
||||
return ['code' => 200, 'msg' => '取消成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '取消失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//取消用户通道
|
||||
public function quit_user_room_micro_aisle($uid, $rid){
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_micro_aisle = db::name('room_micro_aisle')->where($map)->find();
|
||||
if($room_micro_aisle){
|
||||
$update = [];
|
||||
$update['user_id'] = $uid;
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
db::name('room_micro_aisle')->where('id', $room_micro_aisle['id'])->update($update);
|
||||
}
|
||||
$this->update_room_micro_aisle($uid, $rid);
|
||||
return ['code' => 200, 'msg' => '取消成功', 'data' => null];
|
||||
}
|
||||
|
||||
//更新通道信息
|
||||
public function update_room_micro_aisle($uid, $rid){
|
||||
$room_info = db::name('room')->field('rid')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 361;
|
||||
$push_data['msg'] = "更新通道信息";
|
||||
$data = $this->get_room_micro_list($uid, $rid);
|
||||
$push_data['data'] = $data['data'];
|
||||
// dump($push_data);exit;
|
||||
model('api/WebSocketPush')->send_to_group($rid, $push_data);
|
||||
}
|
||||
|
||||
//等待上台列表
|
||||
public function get_room_micro_list($uid, $rid){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->field('rid,help_micro_gid')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$gid = 0;
|
||||
$gift_name = '';
|
||||
$base_image = '';
|
||||
if(!empty($room_info['help_micro_gid'])){
|
||||
$gift_info = db::name('gift')->find($room_info['help_micro_gid']);
|
||||
$gid = $room_info['help_micro_gid'];
|
||||
$gift_name = $gift_info['gift_name'];
|
||||
$base_image = localpath_to_netpath($gift_info['base_image']);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['priority_aisle'] = [];
|
||||
$data['priority_count'] = 0;
|
||||
$data['priority_total_count'] = 20;
|
||||
$data['common_aisle'] = [];
|
||||
$data['common_count'] = 0;
|
||||
$data['common_total_count'] = 20;
|
||||
$data['gid'] = $gid;
|
||||
$data['gift_name'] = $gift_name;
|
||||
$data['base_image'] = $base_image;
|
||||
|
||||
//普通通道列表
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.type', '=', 1];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$map[] = ['a.status', '=', 2];
|
||||
$common_aisle = db::name('room_micro_aisle')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.id,a.uid,a.rid,a.type,a.rank_value,b.nick_name,b.base64_nick_name,b.head_pic')->where($map)->order('a.id asc')->select();
|
||||
foreach ($common_aisle as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
}
|
||||
if(!empty($common_aisle)){
|
||||
$data['common_aisle'] = $common_aisle;
|
||||
$data['common_count'] = count($common_aisle);
|
||||
}
|
||||
|
||||
//优先通道列表
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.type', '=', 2];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$map[] = ['a.status', '=', 2];
|
||||
$priority_aisle = db::name('room_micro_aisle')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.id,a.uid,a.rid,a.type,a.rank_value,b.nick_name,b.base64_nick_name,b.head_pic')->where($map)->order('a.rank_value desc')->select();
|
||||
foreach ($priority_aisle as $a => &$b){
|
||||
$b['nick_name'] = mb_convert_encoding(base64_decode($b['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$b['head_pic'] = localpath_to_netpath($b['head_pic']);
|
||||
}
|
||||
if(!empty($priority_aisle)){
|
||||
$data['priority_aisle'] = $priority_aisle;
|
||||
$data['priority_count'] = count($priority_aisle);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//清空上台列表
|
||||
public function clears_room_micro_list($uid, $rid){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
// $room_admin_uid_arr = explode(',', $room_info['room_admin_uid']);
|
||||
$room_admin_uid_arr = db::name('room_admin')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
$room_host_uid_arr = db::name('room_host')->where('rid', $rid)->column('uid');
|
||||
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr) && !in_array($uid, $room_host_uid_arr)) {
|
||||
// if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr)) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['type', 'in', [1,2]];
|
||||
$room_micro_aisle_list = db::name('room_micro_aisle')->where($map)->find();
|
||||
if(empty($room_micro_aisle_list)){
|
||||
return ['code' => 201, 'msg' => '当前尚未有申请上台用户', 'data' => null];
|
||||
}
|
||||
|
||||
$update = [];
|
||||
$update['user_id'] = $uid;
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_aisle')->where($map)->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '清空失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
$this->update_room_micro_aisle($uid, $rid);
|
||||
return ['code' => 200, 'msg' => '清空成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '清空失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//同意、拒绝上台
|
||||
public function operate_user_micro($uid, $rid, $id, $type, $seat, $time){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $id];
|
||||
$user_room_micro_aisle = db::name('room_micro_aisle')->where($map)->find();
|
||||
if(!$user_room_micro_aisle){
|
||||
return ['code' => 201, 'msg' => '该申请不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$receive_user_info = db::name('user')->where('uid', $user_room_micro_aisle['uid'])->field('uid, sex')->find();
|
||||
|
||||
|
||||
if(!in_array($type, [1,2])){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
// $room_admin_uid_arr = explode(',', $room_info['room_admin_uid']);
|
||||
$room_admin_uid_arr = db::name('room_admin')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
$room_host_uid_arr = db::name('room_host')->where('rid', $rid)->column('uid');
|
||||
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr) && !in_array($uid, $room_host_uid_arr)) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
//用户是否在麦上
|
||||
// $room_micro_list = db::name('room_micro')->where('rid', $rid)->order('micro_id asc')->column('uid');
|
||||
// if(in_array($user_room_micro_aisle['uid'], $room_micro_list)){
|
||||
// return ['code' => 201, 'msg' => '该用户已在麦上', 'data' => null];
|
||||
// }
|
||||
if($room_info['room_host_uid'] == $user_room_micro_aisle['uid']){
|
||||
return ['code' => 201, 'msg' => '该用户已在主持麦上', 'data' => null];
|
||||
}
|
||||
|
||||
$user_room_micro_info = db::name('room_micro')->where('rid', $rid)->where('uid', $user_room_micro_aisle['uid'])->find();
|
||||
if($user_room_micro_info){
|
||||
if(!in_array($room_info['cate_id'], [27,28])){
|
||||
return ['code' => 201, 'msg' => '该用户已在麦上', 'data' => null];
|
||||
}else{
|
||||
if(!in_array($user_room_micro_info['micro_id'],[5,6,7,8])){
|
||||
return ['code' => 201, 'msg' => '该用户已在麦上', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($room_info['cate_id'] == 29 && $type == 1){
|
||||
$room_dating_log = db::name('room_dating_log')->where('rid', $rid)->where('is_delete', 1)->find();
|
||||
if($room_dating_log){
|
||||
return ['code' => 201, 'msg' => '当前心动连线已开始无法同意上麦', 'data' => null];
|
||||
}
|
||||
$is_path = db::name('room_privacy')->whereRaw('FIND_IN_SET('.$user_room_micro_aisle['uid'].',uid_data)')->field('prid')->find();
|
||||
if(!empty($is_path)){
|
||||
return ['code' => 201, 'msg' => '该用户正在私密小屋,无法同意上麦', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if($room_info['cate_id'] == 27 && $type == 1){
|
||||
$activity_info = db::name('room_song_log')->where('rid', $rid)->where('is_delete', 1)->find();
|
||||
if(!empty($activity_info)){
|
||||
$uid_array = explode(',', trim($activity_info['uid_array'], ','));
|
||||
if(in_array($user_room_micro_aisle['uid'], $uid_array)){
|
||||
return ['code' => 201, 'msg' => '活动进行中,无法同意上麦', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if(in_array($room_info['cate_id'],[36,37]) && $type == 1){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// $time = strtotime(date("Y-m-d"));
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($type == 1){//同意
|
||||
$room_micro_data = db::name('room_micro')->where('rid', $rid)->order('micro_id asc')->column('uid');
|
||||
// dump($room_micro_data);
|
||||
$update = [];
|
||||
$update['user_id'] = $uid;
|
||||
$update['status'] = 1;
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_aisle')->where('id', $id)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
|
||||
$micro_id = 0;
|
||||
//上麦,变更麦位
|
||||
|
||||
|
||||
$user_micro_id = $this->user_room_micro_id($room_info['cate_id'], $room_micro_data, $seat,$receive_user_info['sex']);
|
||||
if($user_micro_id['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $user_micro_id['msg'], 'data' => null];
|
||||
}
|
||||
$micro_id = $user_micro_id['data'] - 1;
|
||||
|
||||
|
||||
|
||||
if($room_info['cate_id'] == 19 && ($micro_id != 6)){
|
||||
if($time < 1){
|
||||
return ['code' => 201, 'msg' => '上麦时间不能小于一分钟', 'data' => null];
|
||||
}
|
||||
//清除之前在麦状态
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $receive_user_info['uid']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$update = [];
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$info = db::name('room_date_micro')->where($map)->find();
|
||||
if($info){
|
||||
$reslut = db::name('room_date_micro')->where($map)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//添加在麦时间记录
|
||||
$insert = [];
|
||||
$insert['user_id'] = $uid;
|
||||
$insert['uid'] = $receive_user_info['uid'];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['micro_id'] = $micro_id;
|
||||
$insert['sustain_time'] = $time;
|
||||
$insert['add_time'] = time();
|
||||
$insert['end_time'] = time() + ($time * 60);
|
||||
$reslut = db::name('room_date_micro')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$reslut = model('room')->user_up_micro($receive_user_info['uid'], $rid, $micro_id, 2);
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
if($room_info['cate_id'] == 28){
|
||||
//清除之前拍卖信息
|
||||
$infos = db::name('room_auction_log')->where('rid', $rid)->where('is_delete', 1)->find();
|
||||
if(!empty($infos)){
|
||||
db::name('room_auction_log')->where('rid', $rid)->where('is_delete', 1)->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
}
|
||||
//用户上拍卖麦位添加拍卖信息
|
||||
// $paimai_long_time = get_uncache_system_config('paimai_long_time');
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['uid'] = $receive_user_info['uid'];
|
||||
$insert['add_time'] = time();
|
||||
// $insert['paimai_long_time'] = $paimai_long_time;
|
||||
$reslut = db::name('room_auction_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}else if($type == 2){//拒绝
|
||||
$update = [];
|
||||
$update['user_id'] = $uid;
|
||||
$update['status'] = 3;
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_aisle')->where('id', $id)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
$this->update_room_micro_aisle($uid, $rid);
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//获取用户可上麦位ID
|
||||
public function user_room_micro_id($catd_id, $room_micro_data, $seat,$sex=0){
|
||||
|
||||
if ($catd_id == 26) {//新人
|
||||
$max_micro_num = 1;
|
||||
} elseif ($catd_id == 27) {//K歌
|
||||
$max_micro_num = 8;
|
||||
} elseif ($catd_id == 28) {//拍卖
|
||||
$max_micro_num = 1;
|
||||
} elseif ($catd_id == 29) {//交友
|
||||
$max_micro_num = 6;
|
||||
}elseif (in_array($catd_id,[36,37])) {//交友
|
||||
$max_micro_num = 8;
|
||||
} else {//常规房间
|
||||
$max_micro_num = 8;
|
||||
}
|
||||
|
||||
$micro_id = 0;
|
||||
if($catd_id == 29 && !empty($seat)){
|
||||
if($seat == 1){//左边
|
||||
if($room_micro_data[0] == 0){
|
||||
$micro_id = 1;
|
||||
}else if($room_micro_data[2] == 0){
|
||||
$micro_id = 3;
|
||||
}else if($room_micro_data[4] == 0){
|
||||
$micro_id = 5;
|
||||
}
|
||||
}else if($seat == 2){//右边
|
||||
if($room_micro_data[1] == 0){
|
||||
$micro_id = 2;
|
||||
}else if($room_micro_data[3] == 0){
|
||||
$micro_id = 4;
|
||||
}else if($room_micro_data[5] == 0){
|
||||
$micro_id = 6;
|
||||
}
|
||||
}
|
||||
}elseif($catd_id==36){ //男生
|
||||
if($sex==1){
|
||||
if($room_micro_data[6] == 0){
|
||||
$micro_id = 7;
|
||||
}else if($room_micro_data[7] == 0){
|
||||
$micro_id = 8;
|
||||
}
|
||||
}elseif($sex==2 || $sex==0){
|
||||
if($room_micro_data[0] == 0){
|
||||
$micro_id = 1;
|
||||
}else if($room_micro_data[1] == 0){
|
||||
$micro_id = 2;
|
||||
}else if($room_micro_data[2] == 0){
|
||||
$micro_id = 3;
|
||||
}else if($room_micro_data[3] == 0){
|
||||
$micro_id = 4;
|
||||
}else if($room_micro_data[4] == 0){
|
||||
$micro_id = 5;
|
||||
}else if($room_micro_data[5] == 0){
|
||||
$micro_id = 6;
|
||||
}else if($room_micro_data[7] == 0){
|
||||
$micro_id = 8;
|
||||
}
|
||||
}else{
|
||||
if($room_micro_data[7] == 0){
|
||||
$micro_id = 8;
|
||||
}
|
||||
}
|
||||
}elseif($catd_id==37){ //女生
|
||||
if($sex==1){
|
||||
if($room_micro_data[0] == 0){
|
||||
$micro_id = 1;
|
||||
}else if($room_micro_data[1] == 0){
|
||||
$micro_id = 2;
|
||||
}else if($room_micro_data[2] == 0){
|
||||
$micro_id = 3;
|
||||
}else if($room_micro_data[3] == 0){
|
||||
$micro_id = 4;
|
||||
}else if($room_micro_data[4] == 0){
|
||||
$micro_id = 5;
|
||||
}else if($room_micro_data[5] == 0){
|
||||
$micro_id = 6;
|
||||
}else if($room_micro_data[7] == 0){
|
||||
$micro_id = 8;
|
||||
}
|
||||
}elseif($sex==2 || $sex==0){
|
||||
if($room_micro_data[6] == 0){
|
||||
$micro_id = 7;
|
||||
}else if($room_micro_data[7] == 0){
|
||||
$micro_id = 8;
|
||||
}
|
||||
}else{
|
||||
if($room_micro_data[7] == 0){
|
||||
$micro_id = 8;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for ($i = 0; $i <= ($max_micro_num - 1); $i++){
|
||||
if($room_micro_data[$i] == 0){
|
||||
$micro_id = $i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($micro_id == 0){
|
||||
return ['code' => 201, 'msg' => '当前没有空麦位', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $micro_id];
|
||||
}
|
||||
}
|
||||
|
||||
//送礼物更新通道状态
|
||||
public function send_gift_micro_aisle_update($uid, $rid, $change_value, $user_id = 0){
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 2];
|
||||
$user_room_micro_aisle = db::name('room_micro_aisle')->where($map)->find();
|
||||
if($user_room_micro_aisle){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_aisle')->where('id', $user_room_micro_aisle['id'])->inc('rank_value', $change_value)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败1', 'data' => null];
|
||||
}
|
||||
|
||||
//更新通道排名
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['rank_value', '>', 0];
|
||||
$room_priority_aisle_array = db::name('room_micro_aisle')->where($map)->order('rank_value desc')->limit(20)->column('id');
|
||||
if(!empty($room_priority_aisle_array)){
|
||||
$map = [];
|
||||
$map[] = ['id', 'in', $room_priority_aisle_array];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 2];
|
||||
$info = db::name('room_micro_aisle')->where($map)->select();
|
||||
if(!empty($info)){
|
||||
$update = [];
|
||||
$update['type'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_aisle')->where($map)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败2', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['id', 'not in', $room_priority_aisle_array];
|
||||
$map[] = ['type', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['status', '=', 2];
|
||||
$infos = db::name('room_micro_aisle')->where($map)->select();
|
||||
if(!empty($infos)){
|
||||
$update = [];
|
||||
$update['type'] = 1;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_aisle')->where($map)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败3', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($user_id)){
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
$map[] = ['pid', '=', $user_room_micro_aisle['id']];
|
||||
$help_dating_micro_info = db::name('room_micro_help_log')->where($map)->find();
|
||||
if($help_dating_micro_info){
|
||||
$update = [];
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro_help_log')->where('id', $help_dating_micro_info['id'])->inc('rank_value', $change_value)->update($update);
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['uid'] = $user_id;
|
||||
$insert['pid'] = $user_room_micro_aisle['id'];
|
||||
$insert['rank_value'] = $change_value;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('room_micro_help_log')->insert($insert);
|
||||
}
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败4', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
$this->update_room_micro_aisle($uid, $rid);
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//助力礼物列表
|
||||
public function get_help_gift_list($uid, $page = 1, $page_limit = 20){
|
||||
$config = get_uncache_system_config();
|
||||
$map = [];
|
||||
$map[] = ['type', 'in', [1,2]];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
if(!empty($config['cp_gift_id'])){
|
||||
$map[] = ['gid', 'neq', $config['cp_gift_id']];
|
||||
}
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$gift_list = db::name('gift')->where($map)->field('gid, gift_name, base_image, gift_price')->order('gift_price asc')->page($page, $page_limit)->select();
|
||||
foreach($gift_list as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $gift_list];
|
||||
}
|
||||
|
||||
//设置房间助力礼物
|
||||
public function operate_room_help_gift($uid, $rid, $gid){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->field('rid,room_owner_uid, room_admin_uid, help_micro_gid')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
// $room_admin_uid_arr = explode(',', $room_info['room_admin_uid']);
|
||||
$room_admin_uid_arr = db::name('room_admin')->where('rid', $rid)->where('is_delete', 1)->column('uid');
|
||||
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr)) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['type', 'in', [1,2]];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
$map[] = ['is_can_buy', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$gift_info = db::name('gift')->where($map)->find();
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '该礼物不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$update = [];
|
||||
$update['help_micro_gid'] = $gid;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
||||
if($reslut){
|
||||
$this->update_room_micro_aisle($uid, $rid);
|
||||
return ['code' => 200, 'msg' => '设置成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '设置失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//助力送礼
|
||||
public function send_gift_user_micro_help($uid, $rid, $help_uid, $gid, $num){
|
||||
$user_info = db::name('user')->field('uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->field('rid, room_host_uid,help_micro_gid')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($room_info['room_host_uid'])){
|
||||
return ['code' => 201, 'msg' => '当前尚无主持,无法助力', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($room_info['help_micro_gid'])){
|
||||
return ['code' => 201, 'msg' => '当前房间尚未设置助力礼物', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($gid)){
|
||||
return ['code' => 201, 'msg' => '该礼物不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($gid != $room_info['help_micro_gid']){
|
||||
return ['code' => 201, 'msg' => '赠送礼物与助力礼物不匹配', 'data' => null];
|
||||
}
|
||||
|
||||
if($num < 1){
|
||||
return ['code' => 201, 'msg' => '助力礼物数量不能小于1', 'data' => null];
|
||||
}
|
||||
|
||||
$help_user_info = db::name('user')->field('uid')->find($help_uid);
|
||||
if(!$help_user_info){
|
||||
return ['code' => 201, 'msg' => '助力用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$gift_info = db::name('gift')->find($gid);
|
||||
if(!$gift_info){
|
||||
return ['code' => 201, 'msg' => '该礼物不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$total_gift_price = $gift_info['gift_price'] * $num;
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$reslut = model('gift')->send_gift($uid, $room_info['room_host_uid'], $rid, $gid, $num, 1, 0);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = $this->send_gift_micro_aisle_update($help_uid, $rid, $total_gift_price, $uid);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
99
application/api/model/RoomBossMicro.php
Normal file
99
application/api/model/RoomBossMicro.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomBossMicro extends Model
|
||||
{
|
||||
|
||||
//更新房间在线用户财富值
|
||||
public function update_room_visitor_value($uid, $rid, $change_value){
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$room_visitor_info = db::name('room_visitor')->where($map)->find();
|
||||
if($room_visitor_info){
|
||||
$reslut = db::name('room_visitor')->where('vid', $room_visitor_info['vid'])->inc('change_value', $change_value)->update(['update_time' => time()]);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
$cate_id = db::name('room')->where('rid', $rid)->value('cate_id');
|
||||
|
||||
// if(in_array($cate_id, [27,28])){
|
||||
// //更新老板麦信息
|
||||
// $this->update_room_boss_micro($rid);
|
||||
// }
|
||||
|
||||
//拍卖房不需要更新老板麦
|
||||
if(in_array($cate_id, [27])){
|
||||
//更新老板麦信息
|
||||
$this->update_room_boss_micro($rid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//更新老板麦
|
||||
public function update_room_boss_micro($rid){
|
||||
//当前房间麦位用户
|
||||
// $map = [];
|
||||
// $map[] = ['rid', '=', $rid];
|
||||
// $map[] = ['micro_id', 'in', [1,2,3,4,9]];
|
||||
// $map[] = ['uid', '>', 0];
|
||||
// $room_micro_arr = db::name('room_micro')->where($map)->column('uid');
|
||||
|
||||
//当前房间主持用户
|
||||
// $room_host_uid = db::name('room')->where('rid', $rid)->value('room_host_uid');
|
||||
// if($room_host_uid > 0){
|
||||
// $room_micro_arr[] = $room_host_uid;
|
||||
// $room_micro_arr = array_values($room_micro_arr);
|
||||
// }
|
||||
|
||||
//当前老板麦用户信息
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [5,6,7,8]];
|
||||
$room_boss_micro_arr = db::name('room_micro')->where($map)->order('micro_id asc')->column('uid');
|
||||
|
||||
//获取当前房间在线贡献前四用户
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
// $map[] = ['uid', 'not in', $room_micro_arr];
|
||||
$map[] = ['change_value', '>', 0];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_visitor_list = db::name('room_visitor')->where($map)->find();
|
||||
if(!empty($room_visitor_list)){
|
||||
$room_visitor_arr = db::name('room_visitor')->where($map)->order('change_value desc')->limit(4)->column('uid');
|
||||
if($room_visitor_arr != $room_boss_micro_arr){
|
||||
foreach ($room_visitor_arr as $k => $v){
|
||||
if($v != $room_boss_micro_arr[$k]){
|
||||
//是否有在其他麦位
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['micro_id', 'in', [5,6,7,8]];
|
||||
$map[] = ['uid', '=', $v];
|
||||
$info = db::name('room_micro')->where($map)->find();
|
||||
if($info){
|
||||
db::name('room_micro')->where('id', $info['id'])->update(['uid' => 0, 'frame_gid' => 0, 'centre_gid' => 0, 'above_gid' => 0, 'below_gid' => 0, 'left_gid'=> 0, 'right_gid' => 0, 'update_time' => time()]);
|
||||
}
|
||||
//变更麦位信息
|
||||
$micro_id = $k + 5;
|
||||
db::name('room_micro')->where('rid', $rid)->where('micro_id', $micro_id)->update(['uid' => $v, 'update_time' => time()]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
41
application/api/model/RoomEmoji.php
Normal file
41
application/api/model/RoomEmoji.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomEmoji extends Model
|
||||
{
|
||||
public function get_emoji_list()
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['show_status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['pid', '=', 0];
|
||||
$list = Db::name('room_emoji')->field('eid,name,image')->order('sort desc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['music_url'] = localpath_to_netpath($v['music_url']);
|
||||
}
|
||||
return ['code' => 201, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
public function send_emoji($uid, $rid, $eid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['', 'EXP', Db::raw("FIND_IN_SET($uid,room_micro)")];
|
||||
$room_info = db::name('room')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '非麦位用户禁止发送', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['pid', '=', $eid];
|
||||
$map[] = ['show_status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$emoji_list = Db::name('room_emoji')->field('eid,type,name,image,second')->select();
|
||||
$emoji = $emoji_list[array_rand($emoji_list, 1)];
|
||||
//发送表情到websocket
|
||||
|
||||
}
|
||||
}
|
||||
316
application/api/model/RoomHost.php
Normal file
316
application/api/model/RoomHost.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomHost extends Model
|
||||
{
|
||||
|
||||
//设置主持
|
||||
public function set_room_host($uid, $rid, $user_id){
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
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];
|
||||
}
|
||||
|
||||
$host_info = db::name('user')->where('uid', $user_id)->find();
|
||||
if(!$host_info){
|
||||
return ['code' => 201, 'msg' => '指定用户信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '无权限设置', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_id == $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '无法设置房主为主持', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否已在别的厅为主持
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_host_info = db::name('room_host')->where($map)->find();
|
||||
if($room_host_info){
|
||||
if($room_host_info['rid'] == $rid){
|
||||
return ['code' => 201, 'msg' => '该用户已经是主持', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '该用户已经是别的房间主持', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 2];
|
||||
$info = db::name('room_host')->where($map)->find();
|
||||
if($info){
|
||||
$reslut = db::name('room_host')->where('id', $info['id'])->update(['is_delete' => 1, 'ratio' => 0, 'add_time' => time()]);
|
||||
}else{
|
||||
$insert = [];
|
||||
$insert['uid'] = $user_id;
|
||||
$insert['rid'] = $rid;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('room_host')->insert($insert);
|
||||
}
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '设置成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '设置失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//取消主持
|
||||
public function unset_room_host($uid, $rid, $user_id){
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
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];
|
||||
}
|
||||
|
||||
$host_info = db::name('user')->where('uid', $user_id)->find();
|
||||
if(!$host_info){
|
||||
return ['code' => 201, 'msg' => '指定用户信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '无权限取消', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否已在别的厅为主持
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_host_info = db::name('room_host')->where($map)->find();
|
||||
if(!$room_host_info){
|
||||
return ['code' => 201, 'msg' => '该用户当前不是本房主持', 'data' => null];
|
||||
}
|
||||
|
||||
$update = [];
|
||||
$update['is_delete'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_host')->where('id', $room_host_info['id'])->update($update);
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//房间主持列表
|
||||
public function get_room_host_list($uid, $rid){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//当前房间主持列表
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$room_host_list = db::name('room_host')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.uid,b.nick_name,b.base64_nick_name,b.head_pic')->where($map)->order('a.add_time asc')->select();
|
||||
foreach ($room_host_list as $k => &$v) {
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_host_uid = db::name('room_host')->where($map)->column('uid');
|
||||
$room_visitor = db::name('room_visitor')->where('rid', $rid)->column('uid');
|
||||
|
||||
//游客信息
|
||||
$where = [];
|
||||
$where[] = ['uid', 'in', $room_visitor];
|
||||
$where[] = ['uid', 'not in', $room_host_uid];
|
||||
$room_visitor_list = db::name('user')->where($where)->field('uid, nick_name, base64_nick_name, head_pic')->select();
|
||||
foreach ($room_visitor_list as $a => &$b){
|
||||
$b['nick_name'] = mb_convert_encoding(base64_decode($b['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$b['head_pic'] = localpath_to_netpath($b['head_pic']);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['room_host_list'] = $room_host_list;
|
||||
$data['room_visitor_list'] = $room_visitor_list;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//房间主持列表
|
||||
public function get_room_host_info($uid, $rid){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$room_host_list = db::name('room_host')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.id, b.uid, b.nick_name, b.base64_nick_name, b.head_pic, a.ratio')->where($map)->order('a.id desc')->select();
|
||||
foreach ($room_host_list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['room_owner_ratio'] = round((1 - $v['ratio']),2) * 100;
|
||||
$v['ratio'] = $v['ratio'] * 100;
|
||||
//今日收益
|
||||
$v['today_profit'] = db::name('user_room_profit_day')->where('rid', $rid)->where('uid', $v['uid'])->whereTime('add_time', 'today')->sum('amount');
|
||||
//今日主持时长
|
||||
$v['today_host_time'] = db::name('room_host_online_time_log')->where('uid', $v['uid'])->where('rid', $rid)->whereTime('add_time', 'today')->sum('online_time');
|
||||
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $room_host_list];
|
||||
}
|
||||
|
||||
//设置主持比例
|
||||
public function update_room_host_ratio($uid, $rid, $user_id, $ratio){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '无权限设置', 'data' => null];
|
||||
}
|
||||
|
||||
if($ratio < 0){
|
||||
return ['code' => 201, 'msg' => '设置主持比例不能小于0', 'data' => null];
|
||||
}
|
||||
|
||||
if(ceil($ratio) != $ratio){
|
||||
return ['code' => 201, 'msg' => '设置比例必须为整数', 'data' => null];
|
||||
}
|
||||
|
||||
if($ratio > 100){
|
||||
return ['code' => 201, 'msg' => '设置主持比例最大不能超过100%', 'data' => null];
|
||||
}
|
||||
|
||||
//该主持是否存在
|
||||
$room_host_info = db::name('room_host')->where('rid', $rid)->where('uid', $user_id)->where('is_delete', 1)->find();
|
||||
if(!$room_host_info){
|
||||
return ['code' => 201, 'msg' => '该主持不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//修改主持比例
|
||||
$update = [];
|
||||
$update['ratio'] = $ratio * 0.01;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_host')->where('id', $room_host_info['id'])->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '设置失败', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 200, 'msg' => '设置成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//用户所在房间权限列表
|
||||
public function get_user_room_power_list($uid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$list = [];
|
||||
|
||||
//是否是房主
|
||||
$room_owner_list = db::name('room')->where('room_owner_uid', $uid)->find();
|
||||
if($room_owner_list){
|
||||
$data = [];
|
||||
$data['rid'] = $room_owner_list['rid'];
|
||||
$data['room_number'] = $room_owner_list['room_number'];
|
||||
$data['room_name'] = mb_convert_encoding(base64_decode($room_owner_list['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$data['room_cover'] = localpath_to_netpath($room_owner_list['room_cover']);
|
||||
$data['user_type'] = 1;
|
||||
$list[] = $data;
|
||||
}
|
||||
|
||||
//是否有主持
|
||||
$room_host_list = db::name('room_host')->alias('a')->join('yy_room b', 'a.rid = b.rid')->field('a.*, b.base64_room_name, b.room_cover, b.room_number')->where('a.uid', $uid)->where('a.is_delete', 1)->select();
|
||||
foreach ($room_host_list as $k => $v){
|
||||
$data = [];
|
||||
$data['rid'] = $v['rid'];
|
||||
$data['room_number'] = $v['room_number'];
|
||||
$data['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$data['room_cover'] = localpath_to_netpath($v['room_cover']);
|
||||
$data['user_type'] = 3;
|
||||
$list[] = $data;
|
||||
}
|
||||
|
||||
//是否有管理
|
||||
$room_admin_list = db::name('room_admin')->alias('a')->join('yy_room b', 'a.rid = b.rid')->field('a.*, b.room_number, b.base64_room_name, b.room_cover')->where('a.uid', $uid)->where('a.is_delete', 1)->select();
|
||||
foreach ($room_admin_list as $k => $v){
|
||||
$data = [];
|
||||
$data['rid'] = $v['rid'];
|
||||
$data['room_number'] = $v['room_number'];
|
||||
$data['room_name'] = mb_convert_encoding(base64_decode($v['base64_room_name']), 'UTF-8', 'UTF-8');
|
||||
$data['room_cover'] = localpath_to_netpath($v['room_cover']);
|
||||
$data['user_type'] = 2;
|
||||
$list[] = $data;
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//辞退房间职位
|
||||
public function user_retire_room_power($uid, $rid, $user_type){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if(!in_array($user_type, [2,3])){
|
||||
return ['code' => 201, 'msg' => '辞退职位信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_type == 2){
|
||||
//是否是该房间管理
|
||||
$user_room_admin_info = db::name('room_admin')->where('rid', $rid)->where('uid', $uid)->where('is_delete', 1)->find();
|
||||
if(!$user_room_admin_info){
|
||||
return ['code' => 201, 'msg' => '你当前不是该房间管理', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('room_admin')->where('id', $user_room_admin_info['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
|
||||
}else if($user_type == 3){
|
||||
//是否是该房间主持
|
||||
$user_room_host_info = db::name('room_host')->where('rid', $rid)->where('uid', $uid)->where('is_delete', 1)->find();
|
||||
if(!$user_room_host_info){
|
||||
return ['code' => 201, 'msg' => '你当前不是该房间主持', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('room_host')->where('id', $user_room_host_info['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '辞退职位信息不存在', 'data' => null];
|
||||
}
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '辞退成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '辞退失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
159
application/api/model/RoomMcQueue.php
Normal file
159
application/api/model/RoomMcQueue.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\DB;
|
||||
use think\Model;
|
||||
|
||||
class RoomMcQueue extends Model
|
||||
{
|
||||
//用户进入排麦列表
|
||||
public function enter_room_mc_queue($uid, $rid, $guard_type)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_info = db::name('room')->field('rid,tid,room_micro,room_owner_uid,room_admin_uid,room_host_uid')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
if (empty($room_info['room_host_uid'])) {
|
||||
return ['code' => 201, 'msg' => '主持麦位暂无用户', 'data' => null];
|
||||
}
|
||||
$gid = 0;
|
||||
//电台厅 麦位必传
|
||||
if ($room_info['tid'] == 1) {
|
||||
//guard_type //1黄金守护 2白银守护 3青铜守护
|
||||
|
||||
if ($guard_type == 1) {
|
||||
$gid = 1;
|
||||
} elseif ($guard_type == 2) {
|
||||
$gid = 2;
|
||||
} elseif ($guard_type == 3) {
|
||||
$gid = 3;
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '排队麦位不存在', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['guard_rid', '=', $room_info['rid']];
|
||||
$map[] = ['guard_uid', '=', $room_info['room_host_uid']];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$user_guard_info = db::name('user_guard')->field('gid,over_time')->where($map)->find();
|
||||
if (empty($user_guard_info)) {
|
||||
return ['code' => 202, 'msg' => '守护身份不存在', 'data' => null];
|
||||
}
|
||||
if ($user_guard_info['over_time'] < time()) {
|
||||
return ['code' => 202, 'msg' => '您的守护已过期', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$this->quit_room_mc_queue($uid); //取消用户所有排麦
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['guard_rid'] = $room_info['rid'];
|
||||
$data['guard_uid'] = $room_info['room_host_uid'];
|
||||
$data['gid'] = $gid;
|
||||
$data['status'] = 1;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('room_mc_queue')->insert($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '排麦成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '排麦失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
//取消用户排麦
|
||||
public function quit_room_mc_queue($uid)
|
||||
{
|
||||
//取消用户其他排位
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = [];
|
||||
$data['status'] = 3;
|
||||
$data['update_time'] = time();
|
||||
db::name('room_mc_queue')->where($map)->update($data);
|
||||
return ['code' => 200, 'msg' => '取消排麦成功', 'data' => null];
|
||||
}
|
||||
//获取是否在排麦队列中
|
||||
public function get_user_mc_queue_status($uid, $rid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_info = db::name('room')->field('rid,tid,room_micro,room_owner_uid,room_admin_uid,room_host_uid')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['guard_rid', '=', $room_info['rid']];
|
||||
$map[] = ['guard_uid', '=', $room_info['room_host_uid']];
|
||||
$map[] = ['status', '=', 1];
|
||||
$info = db::name('room_mc_queue')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 200, 'msg' => '已在排麦中', 'data' => ['in_mc_queue' => 1]];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '未在排麦中', 'data' => ['in_mc_queue' => 2]];
|
||||
}
|
||||
}
|
||||
//获取房间排麦列表
|
||||
public function get_room_mc_queue_list($uid, $rid, $guard_type)
|
||||
{
|
||||
$map = [];
|
||||
$map['rid'] = $rid;
|
||||
$map['is_delete'] = 1;
|
||||
$room_info = db::name('room')->field('rid,tid,room_micro,room_owner_uid,room_admin_uid,room_host_uid')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$room_admin_uid_arr = explode(',', $room_info['room_admin_uid']);
|
||||
if ($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_uid_arr)) {
|
||||
//return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$model = Db::name('room_mc_queue')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$map = [];
|
||||
$map[] = ['a.status', '=', 1];
|
||||
$map[] = ['a.guard_rid', '=', $rid];
|
||||
|
||||
//1黄金守护 2白银守护 3青铜守护
|
||||
if ($guard_type == 1) {
|
||||
$map[] = ['a.gid', '=', 1];
|
||||
} elseif ($guard_type == 2) {
|
||||
$map[] = ['a.gid', '=', 2];
|
||||
} elseif ($guard_type == 3) {
|
||||
$map[] = ['a.gid', '=', 3];
|
||||
}
|
||||
|
||||
$model = $model->where($map);
|
||||
$list = $model->field('a.qid,a.gid,b.base64_nick_name,b.uid,b.special_uid,b.sex,b.head_pic')->order('a.qid asc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['guard_type'] = $v['gid'];
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
//设置用户上麦
|
||||
|
||||
public function set_user_up_mcrio($uid, $rid)
|
||||
{
|
||||
//取消用户其他排位
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['guard_rid', '=', $rid];
|
||||
$map[] = ['status', '=', 1];
|
||||
$data = [];
|
||||
$data['status'] = 2;
|
||||
$data['update_time'] = time();
|
||||
db::name('room_mc_queue')->where($map)->update($data);
|
||||
return ['code' => 201, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
147
application/api/model/RoomMicro.php
Normal file
147
application/api/model/RoomMicro.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomMicro extends Model
|
||||
{
|
||||
|
||||
//创建房间麦位
|
||||
public function create_room_micro($rid){
|
||||
$micro_num = 12;
|
||||
$insert_all = [];
|
||||
for ($i = 0; $i < $micro_num; $i++){
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['micro_id'] = $i + 1;
|
||||
$insert['update_time'] = time();
|
||||
$insert_all[] = $insert;
|
||||
}
|
||||
|
||||
$reslut = db::name('room_micro')->insertAll($insert_all);
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '创建成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '创建失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//麦位魅力值明细
|
||||
public function get_room_micro_charm_list($uid, $rid, $user_id){
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', '=', $user_id];
|
||||
$info = db::name('room_user_cc')->where($map)->find();
|
||||
if(!$info){
|
||||
$data = [];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['cid', '=', $info['cid']];
|
||||
$map[] = ['change_value', '>', 0];
|
||||
$list = db::name('room_user_micro_charm_log')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.id, a.uid, b.nick_name, b.base64_nick_name, b.head_pic,a.change_value')->where($map)->order('change_value desc')->limit(20)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$user_level_info = model('api/User')->get_user_charm_contribution_info($v['uid']);
|
||||
$v['charm_level_image'] = $user_level_info['data']['charm_level_image'];
|
||||
$v['contribution_level_image'] = $user_level_info['data']['contribution_level_image'];
|
||||
$user_nobility_info = model('api/User')->get_user_nobility_info($v['uid']);
|
||||
$v['nobility_image'] = $user_nobility_info['data']['nobility_image'];
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//定时关闭主持三分钟不在的房间
|
||||
public function close_room_status(){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
// exit;
|
||||
$end_time = time() - 300;
|
||||
$map = [];
|
||||
$map[] = ['room_host_uid', '=', 0];
|
||||
$map[] = ['room_status', '=', 1];
|
||||
$map[] = ['down_up_time', '>', 0];
|
||||
$map[] = ['down_up_time', '<', $end_time];
|
||||
$list = db::name('room')->where($map)->select();
|
||||
if(!empty($list)){
|
||||
foreach($list as $k => $v){
|
||||
|
||||
$is_close = 1;
|
||||
if($v['cate_id'] == 26){
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $v['rid']];
|
||||
$map[] = ['is_stop', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_new_auction_log')->where($map)->find();
|
||||
if($room_auction_info){
|
||||
$is_close = 2;
|
||||
}
|
||||
}
|
||||
if($v['cate_id'] == 27){
|
||||
//当前是否已有进行中的K歌
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $v['rid']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_song_log')->where($map)->find();
|
||||
if($room_auction_info){
|
||||
$is_close = 2;
|
||||
}
|
||||
}
|
||||
if($v['cate_id'] == 28){
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $v['rid']];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_auction_info = db::name('room_auction_log')->where($map)->find();
|
||||
if($room_auction_info){
|
||||
$room_micro_uid = db::name('room_micro')->where('rid', $v['rid'])->where('micro_id', 1)->value('uid');
|
||||
if($room_micro_uid > 0){
|
||||
$is_close = 2;
|
||||
}else{
|
||||
db::name('room_auction_log')->where('rid', $v['rid'])->where('is_delete', 1)->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($v['cate_id'] == 29){
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $v['rid']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_dating_log = db::name('room_dating_log')->where($map)->find();
|
||||
if($room_dating_log){
|
||||
$is_close = 2;
|
||||
}
|
||||
}
|
||||
if($is_close == 1){
|
||||
db::name('room')->where('rid', $v['rid'])->update(['room_status' => 3, 'down_up_time' => 0]);
|
||||
|
||||
//删除房间挂件
|
||||
db::name('room_pendant_gift_log')->where('rid', $v['rid'])->update(['is_show' => 2, 'update_time' => time()]);
|
||||
|
||||
$push_room_data = [];
|
||||
$push_room_data['rid'] = $v['rid'];
|
||||
$push_room_data['type'] = 2;
|
||||
|
||||
$push_data = [];
|
||||
$push_data['code'] = 369;
|
||||
$push_data['msg'] = "房间类型变更推送";
|
||||
$push_data['data'] = $push_room_data;
|
||||
model('api/WebSocketPush')->send_to_group($v['rid'], $push_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').' 执行成功';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
96
application/api/model/RoomMicroGift.php
Normal file
96
application/api/model/RoomMicroGift.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomMicroGift extends Model
|
||||
{
|
||||
|
||||
//麦位礼物变更
|
||||
public function update_room_micro_gift($uid, $user_id, $rid, $gid, $position){
|
||||
//当前用户是否在麦位上
|
||||
$room_info = db::name('room')->find($rid);
|
||||
$room_micro_arr = db::name('room_micro')->where('rid', $rid)->column('uid');
|
||||
|
||||
if($position == 1){
|
||||
$gift_position = 'frame_gid';
|
||||
}else if($position == 2){
|
||||
$gift_position = 'centre_gid';
|
||||
}else if($position == 3){
|
||||
$gift_position = 'above_gid';
|
||||
}else if($position == 4){
|
||||
$gift_position = 'below_gid';
|
||||
}else if($position == 5){
|
||||
$gift_position = 'left_gid';
|
||||
}else if($position == 6){
|
||||
$gift_position = 'right_gid';
|
||||
}
|
||||
|
||||
|
||||
if($user_id == $room_info['room_host_uid']){
|
||||
$update = [];
|
||||
$update[$gift_position] = $gid;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}else if(in_array($user_id, $room_micro_arr)){
|
||||
|
||||
$update = [];
|
||||
$update[$gift_position] = $gid;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro')->where('rid', $rid)->where('uid', $user_id)->update($update);
|
||||
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
|
||||
}
|
||||
|
||||
//下麦删除麦位礼物
|
||||
public function down_micro_del_position_gift($uid, $rid){
|
||||
//当前用户是否在麦位上
|
||||
$room_info = db::name('room')->find($rid);
|
||||
$room_micro_arr = db::name('room_micro')->where('rid', $rid)->column('uid');
|
||||
|
||||
if($uid == $room_info['room_host_uid']){
|
||||
$update = [];
|
||||
$update['frame_gid'] = 0;
|
||||
$update['centre_gid'] = 0;
|
||||
$update['above_gid'] = 0;
|
||||
$update['below_gid'] = 0;
|
||||
$update['left_gid'] = 0;
|
||||
$update['right_gid'] = 0;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room')->where('rid', $rid)->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}else if(in_array($uid, $room_micro_arr)){
|
||||
$update = [];
|
||||
$update['frame_gid'] = 0;
|
||||
$update['centre_gid'] = 0;
|
||||
$update['above_gid'] = 0;
|
||||
$update['below_gid'] = 0;
|
||||
$update['left_gid'] = 0;
|
||||
$update['right_gid'] = 0;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_micro')->where('rid', $rid)->where('uid', $uid)->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
712
application/api/model/RoomSubsidy.php
Normal file
712
application/api/model/RoomSubsidy.php
Normal file
@@ -0,0 +1,712 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomSubsidy extends Model
|
||||
{
|
||||
|
||||
//该房间是否有收益
|
||||
public function get_room_is_earnings_info($uid, $rid){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['is_earnings'] = $room_info['is_earnings'];
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => $data];
|
||||
}
|
||||
|
||||
|
||||
//房间补贴信息
|
||||
public function room_subsidy_info($uid, $rid){
|
||||
$config = get_uncache_system_config();
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//房间上周流水
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', 1];
|
||||
$last_week_income = db::name('user_charm_count_day')->where($map)->whereTime('add_time', 'last week')->sum('amount');
|
||||
$last_week_incomes = $last_week_income / $config['exchange_rate'];
|
||||
|
||||
//房间本周流水
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', 1];
|
||||
$week_income = db::name('user_charm_count_day')->where($map)->whereTime('add_time', 'week')->sum('amount');
|
||||
$week_incomes = $week_income / $config['exchange_rate'];
|
||||
|
||||
//房间补贴信息
|
||||
$room_subsidy_info = db::name('room_subsidy')->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
|
||||
//上周补贴奖励金额
|
||||
$subsidy_money = 0;
|
||||
foreach ($room_subsidy_info as $k => &$v){
|
||||
$money = $v['money'];
|
||||
if($v['total_gift_price'] > $last_week_income){
|
||||
break;
|
||||
}else{
|
||||
if($v['type'] == 1){
|
||||
$subsidy_money = $v['money'];
|
||||
}else{
|
||||
$subsidy_money = $last_week_income * $money * 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($room_subsidy_info as $a => &$b){
|
||||
if($b['type'] == 2){
|
||||
$b['money'] = $b['money'].'%';
|
||||
}
|
||||
$b['total_gift_price'] = $b['total_gift_price']/10;
|
||||
}
|
||||
|
||||
if($room_info['room_owner_uid'] != $uid || $room_info['is_earnings'] == 2){
|
||||
$data = [];
|
||||
$data['last_week_income'] = 0;
|
||||
$data['last_week_subsidy_money'] = 0;
|
||||
$data['week_income'] = 0;
|
||||
$data['room_subsidy_info'] = $room_subsidy_info;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['last_week_income'] = $last_week_incomes;
|
||||
$data['last_week_subsidy_money'] = $subsidy_money;
|
||||
$data['week_income'] = $week_incomes;
|
||||
$data['room_subsidy_info'] = $room_subsidy_info;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//幸运房间补贴信息
|
||||
public function room_lucky_subsidy_info($uid, $rid){
|
||||
$config = get_uncache_system_config();
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//房间上周流水
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', 2];
|
||||
$last_week_income = db::name('user_charm_count_day')->where($map)->whereTime('add_time', 'last week')->sum('amount');
|
||||
$last_week_incomes = $last_week_income / $config['exchange_rate'];
|
||||
|
||||
//房间本周流水
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', 2];
|
||||
$week_income = db::name('user_charm_count_day')->where($map)->whereTime('add_time', 'week')->sum('amount');
|
||||
$week_incomes = $week_income / $config['exchange_rate'];
|
||||
|
||||
//房间补贴信息
|
||||
$room_subsidy_info = db::name('room_subsidy_lucky')->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
|
||||
//本周补贴奖励金额
|
||||
$subsidy_money = 0;
|
||||
foreach ($room_subsidy_info as $k => &$v){
|
||||
$money = $v['money'];
|
||||
|
||||
if($v['total_gift_price'] > $last_week_income){
|
||||
break;
|
||||
}else{
|
||||
if($v['type'] == 1){
|
||||
$subsidy_money = $v['money'];
|
||||
}else{
|
||||
$subsidy_money = $last_week_income * $money * 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($room_subsidy_info as $a => &$b){
|
||||
if($b['type'] == 2){
|
||||
$b['money'] = $b['money'].'%';
|
||||
}
|
||||
$b['total_gift_price'] = $b['total_gift_price']/10;
|
||||
}
|
||||
|
||||
if($room_info['room_owner_uid'] != $uid || $room_info['is_earnings'] == 2){
|
||||
$data = [];
|
||||
$data['last_week_income'] = 0;
|
||||
$data['last_week_subsidy_money'] = 0;
|
||||
$data['week_income'] = 0;
|
||||
$data['room_subsidy_info'] = $room_subsidy_info;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['last_week_income'] = $last_week_incomes;
|
||||
$data['last_week_subsidy_money'] = $subsidy_money;
|
||||
$data['week_income'] = $week_incomes;
|
||||
$data['room_subsidy_info'] = $room_subsidy_info;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//用户搜索
|
||||
public function user_search($uid, $rid, $keywords, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 20 ? $page_limit : 20;
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($keywords)){
|
||||
$data = [];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
if(is_numeric($keywords)){//为纯数字
|
||||
$map[] = ['uid|special_uid', '=', $keywords];
|
||||
}else{//不是纯数字
|
||||
$map[] = ['nick_name', 'like', '%'.$keywords.'%'];
|
||||
}
|
||||
$map[] = ['login_status', '=', 1];
|
||||
$list = db::name('user')->where($map)->field('uid, nick_name, base64_nick_name, head_pic')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//房间补贴用户列表
|
||||
public function get_room_user_subsidy_list($uid, $rid){
|
||||
$config = get_uncache_system_config();
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//房间上周流水
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', 1];
|
||||
$last_week_income = db::name('user_charm_count_day')->where($map)->whereTime('add_time', 'last week')->sum('amount');
|
||||
$last_week_incomes = $last_week_income / $config['exchange_rate'];
|
||||
|
||||
//房间补贴信息
|
||||
$room_subsidy_info = db::name('room_subsidy')->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
|
||||
//上周补贴奖励金额
|
||||
$subsidy_money = 0;
|
||||
foreach ($room_subsidy_info as $k => &$v){
|
||||
$money = $v['money'];
|
||||
if($v['total_gift_price'] > $last_week_income){
|
||||
break;
|
||||
}else{
|
||||
if($v['type'] == 1){
|
||||
$subsidy_money = $v['money'];
|
||||
}else{
|
||||
$subsidy_money = $last_week_income * $money * 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$owner_info = db::name('user')->find($room_info['room_owner_uid']);
|
||||
|
||||
$room_owner_info['uid'] = $room_info['room_owner_uid'];
|
||||
$room_owner_info['nick_name'] = mb_convert_encoding(base64_decode($owner_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$room_owner_info['head_pic'] = localpath_to_netpath($owner_info['head_pic']);
|
||||
|
||||
$assigned_ratio = 0;
|
||||
$room_subsidy_list = db::name('room_user_subsidy')->alias('a')->join('yy_user b', 'a.uid = b.uid')->field('a.id,a.uid,a.rid,b.nick_name,b.base64_nick_name, b.head_pic, a.ratio')->where('a.rid', $rid)->where('a.is_delete', 1)->select();
|
||||
foreach ($room_subsidy_list as $k => &$v){
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['subsidy_money'] = $subsidy_money * $v['ratio'] * 0.01;
|
||||
$assigned_ratio += $v['ratio'];
|
||||
}
|
||||
|
||||
$surplus_ratio = 100 - $assigned_ratio;
|
||||
$owner_subsidy_money = $subsidy_money * $surplus_ratio * 0.01;
|
||||
$room_owner_info['ratio'] = $surplus_ratio;
|
||||
$room_owner_info['subsidy_money'] = $owner_subsidy_money;
|
||||
|
||||
$data = [];
|
||||
$data['room_owner_info'] = $room_owner_info;
|
||||
$data['room_subsidy_list'] = $room_subsidy_list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//添加房间补贴用户
|
||||
public function add_room_user_subsidy($uid, $rid, $user_id, $ratio){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '无权限添加', 'data' => null];
|
||||
}
|
||||
if($room_info['is_earnings'] == 2){
|
||||
return ['code' => 201, 'msg' => '当前房间暂未开放收益,请联系管理人员', 'data' => null];
|
||||
}
|
||||
|
||||
if($ratio < 0){
|
||||
return ['code' => 201, 'msg' => '设置主持比例不能小于0', 'data' => null];
|
||||
}
|
||||
|
||||
if(ceil($ratio) != $ratio){
|
||||
return ['code' => 201, 'msg' => '设置比例必须为整数', 'data' => null];
|
||||
}
|
||||
|
||||
if(!empty($ratio) && $ratio > 100){
|
||||
return ['code' => 201, 'msg' => '设置主持比例最大不能超过100%', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = db::name('user')->find($user_id);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '该用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//是否互为好友
|
||||
$fans_info = db::name('user_follow')->where('uid', $uid)->where('follow_uid', $user_id)->find();
|
||||
if(!$fans_info){
|
||||
return ['code' => 201, 'msg' => '你和该用户没有互相关注', 'data' => null];
|
||||
}
|
||||
$follow_info = db::name('user_follow')->where('follow_uid', $uid)->where('uid', $user_id)->find();
|
||||
if(!$follow_info){
|
||||
return ['code' => 201, 'msg' => '你和该用户没有互相关注', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否已被添加
|
||||
$info = db::name('room_user_subsidy')->where('rid', $rid)->where('uid', $user_id)->where('is_delete', 1)->find();
|
||||
if($info){
|
||||
return ['code' => 201, 'msg' => '该用户已被添加过', 'data' => null];
|
||||
}
|
||||
|
||||
//当前剩余可用比例
|
||||
$subsidy_money = db::name('room_user_subsidy')->where('rid', $rid)->where('is_delete', 1)->sum('ratio');
|
||||
if($subsidy_money + $ratio > 100){
|
||||
return ['code' => 201, 'msg' => '设置比例已达上限', 'data' => null];
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
$insert['rid'] = $rid;
|
||||
$insert['uid'] = $user_id;
|
||||
$insert['ratio'] = $ratio;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('room_user_subsidy')->insert($insert);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//设置当前房间用户补贴
|
||||
public function update_room_user_subsidy($uid, $rid, $user_id, $ratio){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '无权限编辑', 'data' => null];
|
||||
}
|
||||
|
||||
$now_week = date('w');
|
||||
if($now_week != 1){
|
||||
return ['code' => 201, 'msg' => '只有周一可设置补贴比例', 'data' => null];
|
||||
}
|
||||
|
||||
if($ratio < 0){
|
||||
return ['code' => 201, 'msg' => '设置主持比例不能小于0', 'data' => null];
|
||||
}
|
||||
|
||||
if(ceil($ratio) != $ratio){
|
||||
return ['code' => 201, 'msg' => '设置比例必须为整数', 'data' => null];
|
||||
}
|
||||
|
||||
if(!empty($ratio) && $ratio > 100){
|
||||
return ['code' => 201, 'msg' => '设置主持比例最大不能超过100%', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = db::name('user')->find($user_id);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '该用户不存在', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否已被添加
|
||||
$info = db::name('room_user_subsidy')->where('rid', $rid)->where('uid', $user_id)->where('is_delete', 1)->find();
|
||||
if(!$info){
|
||||
return ['code' => 201, 'msg' => '当前信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$next_update_time = time() - $info['update_time'];
|
||||
if($next_update_time < (60*60)){
|
||||
return ['code' => 201, 'msg' => '编辑间隔不能小于60分钟', 'data' => null];
|
||||
}
|
||||
|
||||
//当前剩余可用比例
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['uid', 'neq', $user_id];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$subsidy_money = db::name('room_user_subsidy')->where($map)->sum('ratio');
|
||||
if($subsidy_money + $ratio > 100){
|
||||
return ['code' => 201, 'msg' => '设置比例已达上限', 'data' => null];
|
||||
}
|
||||
|
||||
$update = [];
|
||||
$update['ratio'] = $ratio;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('room_user_subsidy')->where('id', $info['id'])->update($update);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '编辑失败', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 200, 'msg' => '编辑成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//删除房间用户补贴
|
||||
public function del_room_user_subsidy($uid, $id, $rid){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($uid != $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '无权限删除', 'data' => null];
|
||||
}
|
||||
|
||||
//该用户是否存在
|
||||
$info = db::name('room_user_subsidy')->where('id', $id)->where('is_delete', 1)->find();
|
||||
if(!$info){
|
||||
return ['code' => 201, 'msg' => '当前信息不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('room_user_subsidy')->where('id', $id)->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '删除失败', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 200, 'msg' => '删除成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//获取当前类型的随机房间ID
|
||||
public function now_room_category($uid, $cate_id){
|
||||
if(empty($cate_id)){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('room')->where('cate_id', $cate_id)->where('room_status', 1)->orderRaw('rand()')->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 201, 'msg' => '当前类型房间尚不存在', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['rid'] = $room_info['rid'];
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//统计上周房间流水
|
||||
public function statistics_room_last_week_earnings($type){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
//房间补贴信息
|
||||
if($type == 1){
|
||||
$room_subsidy_info = db::name('room_subsidy')->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
}else{
|
||||
$room_subsidy_info = db::name('room_subsidy_lucky')->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
}
|
||||
|
||||
$last_week_time = strtotime('-1 week last sunday', time());
|
||||
|
||||
//获取所有房间上周流水
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$last_week_income = db::name('user_charm_count_day')->where($map)->field('rid,sum(amount) as amount')->whereTime('add_time', 'last week')->group('rid')->select();
|
||||
$insert_all = [];
|
||||
if(!empty($last_week_income)){
|
||||
foreach ($last_week_income as $k => $v){
|
||||
//当前房间是否有收益
|
||||
$room_is_earnings = db::name('room')->where('rid', $v['rid'])->value('is_earnings');
|
||||
if($room_is_earnings == 1){
|
||||
//上周补贴奖励金额
|
||||
$subsidy_money = 0;
|
||||
if($type == 1){
|
||||
foreach ($room_subsidy_info as $a => &$b){
|
||||
$money = $b['money'];
|
||||
if($b['total_gift_price'] > $v['amount']){
|
||||
break;
|
||||
}else{
|
||||
if($b['type'] == 1){
|
||||
$subsidy_money = $b['money'];
|
||||
}else{
|
||||
$subsidy_money = $v['amount'] * $money * 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($room_subsidy_info as $a => &$b){
|
||||
$money = $b['money'];
|
||||
|
||||
if($b['total_gift_price'] > $v['amount']){
|
||||
break;
|
||||
}else{
|
||||
if($b['type'] == 1){
|
||||
$subsidy_money = $b['money'];
|
||||
}else{
|
||||
$subsidy_money = $v['amount'] * $money * 0.001;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//上周是否已添加
|
||||
$where = [];
|
||||
$where[] = ['rid', '=', $v['rid']];
|
||||
$where[] = ['type', '=', $type];
|
||||
$where[] = ['last_week_time', '=', $last_week_time];
|
||||
$info = db::name('room_week_earnings_log')->where($where)->find();
|
||||
if(empty($info)){
|
||||
$insert = [];
|
||||
$insert['rid'] = $v['rid'];
|
||||
$insert['type'] = $type;
|
||||
$insert['change_value'] = $v['amount'];
|
||||
$insert['earnings'] = $subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert_all[] = $insert;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($insert_all)){
|
||||
$reslut = db::name('room_week_earnings_log')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
echo date('Y-m-d H:i:s').'执行失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
|
||||
}
|
||||
|
||||
//发送用户收益
|
||||
public function give_user_room_week_earnings($type){
|
||||
exit;
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
$last_week_time = strtotime('-1 week last sunday', time());
|
||||
if($type == 1){
|
||||
$user_money_log = 34;
|
||||
$remarks = '房间补贴收益';
|
||||
}else{
|
||||
$user_money_log = 35;
|
||||
$remarks = '幸运补贴收益';
|
||||
}
|
||||
//获取未发送的房间上周收益
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['last_week_time', '=', $last_week_time];
|
||||
$list = db::name('room_week_earnings_log')->where($map)->select();
|
||||
if(!empty($list)){
|
||||
foreach ($list as $k => $v){
|
||||
if($v['earnings'] > 0){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$insert_all = [];
|
||||
$assigned_ratio = 0;
|
||||
//获取房间补贴用户
|
||||
$where = [];
|
||||
$where[] = ['rid', '=', $v['rid']];
|
||||
$where[] = ['ratio', '>', 0];
|
||||
$where[] = ['is_delete', '=', 1];
|
||||
$room_subsidy_list = db::name('room_user_subsidy')->where($where)->select();
|
||||
foreach ($room_subsidy_list as $a => $b){
|
||||
//增加收益
|
||||
$user_subsidy_money = $v['earnings'] * $b['ratio'] * 0.01;
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($b['uid'], $user_subsidy_money, 1, $user_money_log, $remarks, $b['uid'], 0, $v['rid']);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$assigned_ratio += $b['ratio'];
|
||||
|
||||
$insert = [];
|
||||
$insert['type'] = $type;
|
||||
$insert['user_type'] = 2;
|
||||
$insert['rid'] = $v['rid'];
|
||||
$insert['uid'] = $b['uid'];
|
||||
$insert['ratio'] = $b['ratio'];
|
||||
$insert['change_value'] = $v['change_value'];
|
||||
$insert['room_earnings'] = $v['earnings'];
|
||||
$insert['user_earnings'] = $user_subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['is_delete'] = 2;
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert_all[] = $insert;
|
||||
}
|
||||
|
||||
//房主获取房间补贴
|
||||
$room_owner_uid = db::name('room')->where('rid', $v['rid'])->value('room_owner_uid');
|
||||
$surplus_ratio = 100 - $assigned_ratio;
|
||||
$owner_subsidy_money = $v['earnings'] * $surplus_ratio * 0.01;
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($room_owner_uid, $owner_subsidy_money, 1, $user_money_log, $remarks, $room_owner_uid, 0, $v['rid']);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$insert = [];
|
||||
$insert['type'] = $type;
|
||||
$insert['user_type'] = 1;
|
||||
$insert['rid'] = $v['rid'];
|
||||
$insert['uid'] = $room_owner_uid;
|
||||
$insert['ratio'] = $surplus_ratio;
|
||||
$insert['change_value'] = $v['change_value'];
|
||||
$insert['room_earnings'] = $v['earnings'];
|
||||
$insert['user_earnings'] = $owner_subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['is_delete'] = 2;
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert_all[] = $insert;
|
||||
$reslut = db::name('user_room_week_earnings')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('room_week_earnings_log')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
}
|
||||
}else{
|
||||
db::name('room_week_earnings_log')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
}
|
||||
|
||||
//统计用户收益
|
||||
public function gives_user_room_week_earnings($type){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
$last_week_time = strtotime('-1 week last sunday', time());
|
||||
|
||||
//获取未发送的房间上周收益
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['last_week_time', '=', $last_week_time];
|
||||
$list = db::name('room_week_earnings_log')->where($map)->select();
|
||||
if(!empty($list)){
|
||||
foreach ($list as $k => $v){
|
||||
if($v['earnings'] > 0){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$insert_all = [];
|
||||
$assigned_ratio = 0;
|
||||
//获取房间补贴用户
|
||||
$where = [];
|
||||
$where[] = ['rid', '=', $v['rid']];
|
||||
$where[] = ['ratio', '>', 0];
|
||||
$where[] = ['is_delete', '=', 1];
|
||||
$room_subsidy_list = db::name('room_user_subsidy')->where($where)->select();
|
||||
foreach ($room_subsidy_list as $a => $b){
|
||||
//增加收益
|
||||
$user_subsidy_money = $v['earnings'] * $b['ratio'] * 0.01;
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($b['uid'], $user_subsidy_money, 1, $user_money_log, $remarks, $b['uid'], 0, $v['rid']);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
$assigned_ratio += $b['ratio'];
|
||||
|
||||
$insert = [];
|
||||
$insert['type'] = $type;
|
||||
$insert['user_type'] = 2;
|
||||
$insert['rid'] = $v['rid'];
|
||||
$insert['uid'] = $b['uid'];
|
||||
$insert['ratio'] = $b['ratio'];
|
||||
$insert['change_value'] = $v['change_value'];
|
||||
$insert['room_earnings'] = $v['earnings'];
|
||||
$insert['user_earnings'] = $user_subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['is_delete'] = 1;
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert_all[] = $insert;
|
||||
}
|
||||
|
||||
//房主获取房间补贴
|
||||
$room_owner_uid = db::name('room')->where('rid', $v['rid'])->value('room_owner_uid');
|
||||
$surplus_ratio = 100 - $assigned_ratio;
|
||||
$owner_subsidy_money = $v['earnings'] * $surplus_ratio * 0.01;
|
||||
// $reslut = model('admin/User')->change_user_money_by_uid($room_owner_uid, $owner_subsidy_money, 1, $user_money_log, $remarks, $room_owner_uid, 0, $v['rid']);
|
||||
// if ($reslut['code'] == 201) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// }
|
||||
$insert = [];
|
||||
$insert['type'] = $type;
|
||||
$insert['user_type'] = 1;
|
||||
$insert['rid'] = $v['rid'];
|
||||
$insert['uid'] = $room_owner_uid;
|
||||
$insert['ratio'] = $surplus_ratio;
|
||||
$insert['change_value'] = $v['change_value'];
|
||||
$insert['room_earnings'] = $v['earnings'];
|
||||
$insert['user_earnings'] = $owner_subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['is_delete'] = 1;
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert_all[] = $insert;
|
||||
$reslut = db::name('user_room_week_earnings')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = db::name('room_week_earnings_log')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
}
|
||||
}else{
|
||||
db::name('room_week_earnings_log')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
}
|
||||
|
||||
}
|
||||
72
application/api/model/RoomVisitor.php
Normal file
72
application/api/model/RoomVisitor.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomVisitor extends Model
|
||||
{
|
||||
public function user_is_in_room($uid, $rid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
|
||||
$info = db::name('room_visitor')->where($map)->find();
|
||||
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '用户已不在房间', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '用户在房间中', 'data' => null];
|
||||
}
|
||||
}
|
||||
//用户游客列表
|
||||
public function get_room_visitor_list($uid, $rid, $visitor_uid)
|
||||
{
|
||||
$map = [];
|
||||
$map['rid'] = $rid;
|
||||
$map['is_delete'] = 1;
|
||||
$room_info = db::name('room')->field('rid,tid,uid,room_micro,room_owner_uid')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
if ($room_info['uid'] != $uid) {
|
||||
return ['code' => 201, 'msg' => '权限不足', 'data' => null];
|
||||
}
|
||||
|
||||
$model = Db::name('room_visitor')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$map = [];
|
||||
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$model = $model->where($map);
|
||||
if (!empty($visitor_uid)) {
|
||||
$map[] = ['b.uid', '=', $visitor_uid];
|
||||
}
|
||||
$list = $model->field('a.vid,a.lid,b.base64_nick_name,b.sex,b.heac_pic')->order('a.vid asc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['heac_pic'] = localpath_to_netpath($v['heac_pic']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//更新到期游客记录
|
||||
public function close_room_visitor(){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 2];
|
||||
$map[] = ['end_time', '<', time()];
|
||||
$room_visitor_list = db::name('room_visitor')->where($map)->select();
|
||||
if(!empty($room_visitor_list)){
|
||||
db::name('room_visitor')->where($map)->delete();
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').'更新到期游客记录 执行成功';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
315
application/api/model/RoomWages.php
Normal file
315
application/api/model/RoomWages.php
Normal file
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Log;
|
||||
class RoomWages extends Model
|
||||
{
|
||||
|
||||
|
||||
//上周房间流水 结算
|
||||
public function statistics_room_last_week_earnings($type){
|
||||
$type = 1;
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
//房间补贴信息
|
||||
$room_subsidy_info = db::name('room_subsidy')->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
|
||||
|
||||
$last_week_time = strtotime('-1 week last sunday', time());
|
||||
$week_start = date('Y-m-d', strtotime("last week Monday"));
|
||||
$week_end = date('Y-m-d', strtotime("last week Sunday"));
|
||||
$belong_week = $week_start.'-'.$week_end;
|
||||
|
||||
|
||||
|
||||
// $last_week_time = strtotime('-1 week last sunday', time());
|
||||
// $week_start = date('Y-m-d', strtotime("this week Monday"));
|
||||
// $week_end = date('Y-m-d', strtotime("this week Sunday"));
|
||||
// $belong_week = $week_start.'-'.$week_end;
|
||||
|
||||
|
||||
|
||||
|
||||
//获取所有房间上周流水
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$last_week_income = db::name('user_charm_count_day')->where($map)->field('rid,sum(amount) as amount')->whereTime('add_time', 'last week')->group('rid')->select();
|
||||
|
||||
// $last_week_income = db::name('user_charm_count_day')->where($map)->field('rid,sum(amount) as amount')->whereTime('add_time', 'week')->group('rid')->select();
|
||||
|
||||
|
||||
|
||||
|
||||
$insert_all = [];
|
||||
if(!empty($last_week_income)){
|
||||
foreach ($last_week_income as $k => $v){
|
||||
//当前房间是否有收益
|
||||
$room_info = db::name('room')->where('rid', $v['rid'])->field('room_owner_uid,rid,is_earnings')->find();
|
||||
$room_is_earnings = $room_info['is_earnings'];
|
||||
|
||||
if($room_is_earnings == 1){
|
||||
//上周补贴奖励金额
|
||||
$subsidy_money = 0;
|
||||
foreach ($room_subsidy_info as $a => &$b){
|
||||
$money = $b['money'];
|
||||
if($b['total_gift_price'] > $v['amount']){
|
||||
break;
|
||||
}else{
|
||||
$subsidy_money = $v['amount'] * $money * 0.001;
|
||||
}
|
||||
}
|
||||
|
||||
//上周是否已添加
|
||||
$where = [];
|
||||
$where[] = ['rid', '=', $v['rid']];
|
||||
$where[] = ['type', '=', $type];
|
||||
$where[] = ['belong_week', '=', $belong_week];
|
||||
$info = db::name('room_week_earnings_log')->where($where)->find();
|
||||
if(empty($info)){
|
||||
$insert = [];
|
||||
$insert['rid'] = $v['rid'];
|
||||
$insert['type'] = $type;
|
||||
$insert['change_value'] = $v['amount'];
|
||||
$insert['earnings'] = $subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert['belong_week'] = $belong_week;
|
||||
$insert['owner_uid'] = $room_info['room_owner_uid'];
|
||||
$insert_all[] = $insert;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($insert_all)){
|
||||
$reslut = db::name('room_week_earnings_log')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
echo date('Y-m-d H:i:s').'执行失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//批量结算
|
||||
public function batch_give_room_subsidy($belong_week=""){
|
||||
$redis = connectionRedis();
|
||||
$belong_week = $redis->lPop('balance_room_wages_date');
|
||||
if (empty($belong_week)) {
|
||||
return ['code' => 201, 'msg' => "没有要结算的工资日期", 'data' => null];
|
||||
}
|
||||
|
||||
//已经审核通过未发放的
|
||||
$is_had_deal = db::name('room_week_earnings_log')->where(['is_delete'=>2,'belong_week'=>$belong_week,'is_fa'=>2,'apply_status' => 2])->find();
|
||||
if(empty($is_had_deal)){
|
||||
Log::write('没有要结算的工资'.$belong_week,'room_wages');
|
||||
return ['code' => 201, 'msg' => "没有要发放的工资", 'data' => null];
|
||||
}
|
||||
|
||||
try {
|
||||
Db::startTrans();
|
||||
//已经审核通过未发放的
|
||||
$list = db::name('room_week_earnings_log')->where(['is_delete'=>2,'belong_week'=>$belong_week,'is_fa'=>2,'apply_status'=>2])->order(['id'=>'asc'])->select();
|
||||
if(!empty($list)){
|
||||
foreach ($list as $k => $v){
|
||||
if($v['earnings'] > 0){
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($v['owner_uid'], $v['earnings'], 1, 34, '房间补贴收益', $v['owner_uid'], 0, $v['rid']);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'工资结算失败','result'=>$reslut],'room_wages');
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
db::name('room_week_earnings_log')->where('id', $v['id'])->update(['is_fa' => 1, 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
Log::write(['msg'=>'工资结算成功','result'=>null],'room_wages');
|
||||
return ['code' => 200, 'msg' => "发放成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
Log::write(['e'=>$e],'room_wages');
|
||||
return ['code' => 201, 'msg' => "发放失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------公会相关业务----------------------
|
||||
|
||||
//上周房间流水 结算
|
||||
public function statistics_guild_last_week_earnings($type){
|
||||
|
||||
$type = 1;
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
|
||||
$week_start = date('Y-m-d', strtotime("last week Monday"));
|
||||
$week_end = date('Y-m-d', strtotime("last week Sunday"));
|
||||
$belong_week = $week_start.'-'.$week_end;
|
||||
$last_week_time = strtotime('-1 week last sunday', time());
|
||||
|
||||
|
||||
//调试
|
||||
// $week_start = date('Y-m-d', strtotime("this week Monday"));
|
||||
// $week_end = date('Y-m-d', strtotime("this week Sunday"));
|
||||
// $belong_week = $week_start.'-'.$week_end;
|
||||
// $last_week_time = strtotime('-1 week last sunday', time());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//获取所有有效工会
|
||||
$guild_ids = db::name('guild')->where(['is_delete'=>1,'is_show'=>1])->column('id');
|
||||
if(empty($guild_ids)){
|
||||
return ['code' => 201, 'msg' => "公会不存在!", 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//公会补贴信息
|
||||
$guild_subsidy_info = db::name('room_subsidy_lucky')->field('id,type,level_name,total_gift_price,money')->where('is_delete', 1)->order('id asc')->select();
|
||||
|
||||
|
||||
|
||||
//获取所有房间上周流水
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['guild_id', 'in', $guild_ids];
|
||||
$last_week_income = db::name('room_guild_charm_count_day')->field('guild_id,sum(amount) as amount')->where($map)->whereTime('add_time', 'last week')->group('guild_id')->select();
|
||||
|
||||
//调试
|
||||
// $last_week_income = db::name('room_guild_charm_count_day')->field('guild_id,sum(amount) as amount')->where($map)->whereTime('add_time', 'week')->group('guild_id')->select();
|
||||
|
||||
|
||||
|
||||
$insert_all = [];
|
||||
if(!empty($last_week_income)){
|
||||
foreach ($last_week_income as $k => $v){
|
||||
//上周补贴奖励金额
|
||||
$subsidy_money = 0;
|
||||
foreach ($guild_subsidy_info as $a => &$b){
|
||||
$money = $b['money'];
|
||||
if($b['total_gift_price'] > $v['amount']){
|
||||
break;
|
||||
}else{
|
||||
$subsidy_money = $v['amount'] * $money * 0.001;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//上周是否已添加
|
||||
$where = [];
|
||||
$where[] = ['guild_id', '=', $v['guild_id']];
|
||||
$where[] = ['type', '=', $type];
|
||||
$where[] = ['belong_week', '=', $belong_week];
|
||||
$info = db::name('guild_week_earnings_log')->where($where)->find();
|
||||
|
||||
|
||||
//获取公会信息
|
||||
$guild_info = db::name('guild')->where(['id'=>$v['guild_id']])->find();
|
||||
if(empty($info)){
|
||||
$insert = [];
|
||||
$insert['guild_id'] = $v['guild_id'];
|
||||
$insert['guild_uid_id'] = $guild_info['uid'];
|
||||
$insert['type'] = 1;
|
||||
$insert['change_value'] = $v['amount'];
|
||||
$insert['earnings'] = $subsidy_money;
|
||||
$insert['add_time'] = time();
|
||||
$insert['update_time'] = time();
|
||||
$insert['last_week_time'] = $last_week_time;
|
||||
$insert['belong_week'] = $belong_week;
|
||||
$insert['is_fa'] = 2;
|
||||
$insert['is_delete'] = 1;
|
||||
$insert_all[] = $insert;
|
||||
}
|
||||
}
|
||||
if(!empty($insert_all)){
|
||||
$reslut = db::name('guild_week_earnings_log')->insertAll($insert_all);
|
||||
if(!$reslut){
|
||||
echo date('Y-m-d H:i:s').'执行失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//批量结算
|
||||
public function batch_give_guild_subsidy(){
|
||||
$redis = connectionRedis();
|
||||
$belong_week = $redis->lPop('balance_guild_wages_date');
|
||||
if (empty($belong_week)) {
|
||||
// Log::write('公会工资日期未监控到','guild_wages');
|
||||
return ['code' => 201, 'msg' => "没有要结算的工资日期", 'data' => null];
|
||||
}
|
||||
|
||||
$is_had_deal = db::name('guild_week_earnings_log')->where(['is_delete'=>2,'belong_week'=>$belong_week,'is_fa'=>2])->find();
|
||||
if(empty($is_had_deal)){
|
||||
Log::write('没有要结算的工资'.$belong_week,'guild_wages');
|
||||
return ['code' => 201, 'msg' => "没有要结算的工资", 'data' => null];
|
||||
}
|
||||
try {
|
||||
Db::startTrans();
|
||||
//标记已处理
|
||||
$list = db::name('guild_week_earnings_log')->where(['is_delete'=>2,'belong_week'=>$belong_week,'is_fa'=>2])->order(['id'=>'asc'])->select();
|
||||
|
||||
if(!empty($list)){
|
||||
foreach ($list as $k => $v){
|
||||
if($v['earnings'] > 0){
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($v['guild_uid_id'], $v['earnings'], 1, 39, '公会补贴收益', $v['guild_uid_id'], 0, 0);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'结算失败1','result'=>$reslut],'guild_wages');
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
db::name('guild_week_earnings_log')->where('id', $v['id'])->update(['is_fa' => 1, 'update_time' => time(), 'fa_time' => time()]);
|
||||
}
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
Log::write('发放成功'.$belong_week,'guild_wages');
|
||||
return ['code' => 200, 'msg' => "发放成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
Log::write(['msg'=>'程序异常','e'=>$e],'guild_wages');
|
||||
return ['code' => 201, 'msg' => "发放失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
456
application/api/model/Sms.php
Normal file
456
application/api/model/Sms.php
Normal file
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Sms extends Model
|
||||
{
|
||||
public function send_sms($mobile, $type)
|
||||
{
|
||||
if (empty($mobile)) {
|
||||
return ['code' => 201, 'msg' => '手机号不能为空', 'data' => null];
|
||||
}
|
||||
if (!in_array($type, [1, 2])) {
|
||||
return ['code' => 201, 'msg' => '短信类型非法', 'data' => null];
|
||||
}
|
||||
|
||||
if(!ctype_digit($mobile)){
|
||||
return ['code' => 201, 'msg' => '手机号格式不正确', 'data' => null];
|
||||
}
|
||||
|
||||
//type 1 其他时候用 2注册
|
||||
$map = [];
|
||||
$map[] = ['user_name', '=', $mobile];
|
||||
$user_info = db::name('user')->where($map)->find();
|
||||
if ($type == 1) {
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '手机号不存在', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
// if (!empty($user_info)) {
|
||||
// return ['code' => 201, 'msg' => '手机号已存在', 'data' => null];
|
||||
// }
|
||||
}
|
||||
$config = get_system_config();
|
||||
|
||||
$today = strtotime(date('Y-m-d'));
|
||||
$map = [];
|
||||
$map[] = ['add_time', '>', $today];
|
||||
$map[] = ['mobile', '=', $mobile];
|
||||
$map[] = ['module', '=', 1];
|
||||
$count = db::name('sms')->where($map)->count();
|
||||
if ($count >= $config['sms_every_day_send_limit']) {
|
||||
return ['code' => 201, 'msg' => '超过今日验证码接收限制', 'data' => null];
|
||||
}
|
||||
$code = mt_rand(1000, 9999);
|
||||
$limit_minute = 3;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['mobile', '=', $mobile];
|
||||
$map[] = ['module', '=', 1];
|
||||
$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 . '。如非本人操作,请忽略本短信';
|
||||
// $content = '【西安星亦文化】您好!验证码是:' . $code . ',短信有效期为' . $limit_minute . '分钟。';d4Zr5meI
|
||||
$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();
|
||||
$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];
|
||||
}
|
||||
}
|
||||
|
||||
private function send_smsbao_msg($mobile, $content){
|
||||
$config = get_system_config();
|
||||
//短信宝
|
||||
// $url = "https://dx.ipyy.net/smsJson.aspx?action=send&userid=&account=" . $config['huaxin_account'] . "&password=" . $config['huaxin_password'] . "&mobile=" . $mobile . "&content=" . urlencode($content) . "&sendTime=&extno=";
|
||||
$url = "https://api.smsbao.com/sms?u=".$config['smsbao_account']."&p=".md5($config['smsbao_password'])."&m=".$mobile."&c=".urlencode($content) ."&g=";
|
||||
$result = myCurl($url);
|
||||
$result_arr = json_decode($result, true);
|
||||
if ($result_arr == 0) {
|
||||
return ['code' => 200, 'msg' => '发送成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '发送失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
private function send_huaxin_msg($mobile, $content)
|
||||
{
|
||||
$config = get_system_config();
|
||||
//华信
|
||||
$url = "https://dx.ipyy.net/smsJson.aspx?action=send&userid=&account=" . $config['huaxin_account'] . "&password=" . $config['huaxin_password'] . "&mobile=" . $mobile . "&content=" . urlencode($content) . "&sendTime=&extno=";
|
||||
$result = myCurl($url);
|
||||
$result_arr = json_decode($result, true);
|
||||
if ($result_arr['returnstatus'] == 'Success') {
|
||||
return ['code' => 200, 'msg' => '发送成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '发送失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function verification_code($mobile, $code)
|
||||
{
|
||||
$key_name = "api:sms:verification_code:" . $mobile;
|
||||
redis_lock_exit($key_name);
|
||||
$map = [];
|
||||
$map[] = ['status', '=', 2];
|
||||
$map[] = ['mobile', '=', $mobile];
|
||||
$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);
|
||||
|
||||
return ['code' => 200, 'msg' => '验证成功', 'data' => null];
|
||||
// if ($reslut) {
|
||||
// return ['code' => 200, 'msg' => '验证成功', 'data' => null];
|
||||
// } else {
|
||||
// return ['code' => 201, '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 = 'JmwJGSqX4';
|
||||
$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 = '【西安星亦文化】您的验证码是'.$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];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1534
application/api/model/Sprite.php
Normal file
1534
application/api/model/Sprite.php
Normal file
File diff suppressed because it is too large
Load Diff
205
application/api/model/Statistics.php
Normal file
205
application/api/model/Statistics.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Statistics extends Model
|
||||
{
|
||||
//统计每日贡献值
|
||||
public function day_contribution($uid, $rid, $amount, $type = 1)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', $type];
|
||||
$day_time = strtotime(date('Ymd'));
|
||||
$map[] = ['add_time', '>=', $day_time];
|
||||
$info = Db::name('user_contribution_count_day')->where($map)->find();
|
||||
if($info) {
|
||||
Db::name('user_contribution_count_day')->where('sid', $info['sid'])->inc('amount', $amount)->update(['update_time' => time()]);
|
||||
} else {
|
||||
$insert_data = [
|
||||
'uid' => $uid,
|
||||
'rid' => $rid,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('user_contribution_count_day')->insert($insert_data);
|
||||
}
|
||||
}
|
||||
|
||||
//统计用户每日收益
|
||||
public function day_charm($uid, $rid, $amount, $type = 1)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', $type];
|
||||
$day_time = strtotime(date('Ymd'));
|
||||
$map[] = ['add_time', '>=', $day_time];
|
||||
$info = Db::name('user_charm_count_day')->where($map)->find();
|
||||
if($info) {
|
||||
Db::name('user_charm_count_day')->where('sid', $info['sid'])->inc('amount', $amount)->update(['update_time' => time()]);
|
||||
} else {
|
||||
$insert_data = [
|
||||
'uid' => $uid,
|
||||
'rid' => $rid,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('user_charm_count_day')->insert($insert_data);
|
||||
}
|
||||
}
|
||||
|
||||
//统计收益带公会
|
||||
public function day_guild_charm($uid, $rid, $guild_id, $amount, $type = 1)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['guild_id', '=', $guild_id];
|
||||
$map[] = ['type', '=', $type];
|
||||
$day_time = strtotime(date('Ymd'));
|
||||
$map[] = ['add_time', '>=', $day_time];
|
||||
$info = Db::name('user_guild_charm_count_day')->where($map)->find();
|
||||
if($info) {
|
||||
Db::name('user_guild_charm_count_day')->where('sid', $info['sid'])->inc('amount', $amount)->update(['update_time' => time()]);
|
||||
} else {
|
||||
$insert_data = [
|
||||
'uid' => $uid,
|
||||
'rid' => $rid,
|
||||
'type' => $type,
|
||||
'guild_id' => $guild_id,
|
||||
'amount' => $amount,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('user_guild_charm_count_day')->insert($insert_data);
|
||||
}
|
||||
}
|
||||
|
||||
//统计房间收益带公会
|
||||
public function day_room_guild_charm($uid, $rid, $guild_id, $amount, $type = 1)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['guild_id', '=', $guild_id];
|
||||
$day_time = strtotime(date('Ymd'));
|
||||
$map[] = ['add_time', '>=', $day_time];
|
||||
$info = Db::name('room_guild_charm_count_day')->where($map)->find();
|
||||
if($info) {
|
||||
Db::name('room_guild_charm_count_day')->where('sid', $info['sid'])->inc('amount', $amount)->update(['update_time' => time()]);
|
||||
} else {
|
||||
$insert_data = [
|
||||
'uid' => $uid,
|
||||
'rid' => $rid,
|
||||
'type' => $type,
|
||||
'guild_id' => $guild_id,
|
||||
'amount' => $amount,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('room_guild_charm_count_day')->insert($insert_data);
|
||||
}
|
||||
}
|
||||
|
||||
//统计用户cp值记录
|
||||
public function day_cp_value($uid, $receive_uid, $amount){
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid|receive_uid', '=', $uid];
|
||||
$map[] = ['uid|receive_uid', '=', $receive_uid];
|
||||
//是否互相为cp
|
||||
$cp_info = db::name('user_coupling')->where($map)->where('is_delete', 1)->find();
|
||||
if(empty($cp_info)){
|
||||
return true;
|
||||
}
|
||||
|
||||
$day_time = strtotime(date('Ymd'));
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $cp_info['uid']];
|
||||
$map[] = ['receive_uid', '=', $cp_info['receive_uid']];
|
||||
$map[] = ['add_time', '>=', $day_time];
|
||||
$info = db::name('user_cp_count_day')->where($map)->find();
|
||||
if($info){
|
||||
db::name('user_cp_count_day')->where('sid', $info['sid'])->inc('amount', $amount)->update(['update_time' => time()]);
|
||||
}else{
|
||||
$insert_data = [
|
||||
'uid' => $cp_info['uid'],
|
||||
'receive_uid' => $cp_info['receive_uid'],
|
||||
'amount' => $amount,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('user_cp_count_day')->insert($insert_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//统计用户房间收益记录
|
||||
public function day_room_profit($uid, $rid, $amount, $type){
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['type', '=', $type];
|
||||
$day_time = strtotime(date('Ymd'));
|
||||
$map[] = ['add_time', '>=', $day_time];
|
||||
$info = db::name('user_room_profit_day')->where($map)->find();
|
||||
if($info){
|
||||
db::name('user_room_profit_day')->where('sid', $info['sid'])->inc('amount', $amount)->update(['update_time' => time()]);
|
||||
}else{
|
||||
$insert_data = [
|
||||
'uid' => $uid,
|
||||
'rid' => $rid,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
Db::name('user_room_profit_day')->insert($insert_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//主持在线时长统计
|
||||
public function room_host_online_time($uid, $rid, $type){
|
||||
$day_time = strtotime(date('Ymd'));
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['add_time', '>=', $day_time];
|
||||
$info = db::name('room_host_online_time_log')->where($map)->find();
|
||||
if($type == 1){//上麦
|
||||
if($info){
|
||||
db::name('room_host_online_time_log')->where('id', $info['id'])->update(['start_time' => time(), 'end_time' => 0, 'update_time' => time()]);
|
||||
}else{
|
||||
$insert_data = [
|
||||
'uid' => $uid,
|
||||
'rid' => $rid,
|
||||
'add_time' => time(),
|
||||
'start_time' => time(),
|
||||
];
|
||||
Db::name('room_host_online_time_log')->insert($insert_data);
|
||||
}
|
||||
}else{//下麦
|
||||
if($info){
|
||||
//计算时间
|
||||
$end_time = time();
|
||||
$online_time = (int)(($end_time - $info['start_time'])/60);
|
||||
if($online_time > 0){
|
||||
db::name('room_host_online_time_log')->where('id', $info['id'])->inc('online_time', $online_time)->update(['end_time' => time(), 'update_time' => time()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
application/api/model/Suggest.php
Normal file
26
application/api/model/Suggest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Suggest extends Model
|
||||
{
|
||||
public function create_suggest($uid, $image, $content)
|
||||
{
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['image'] = $image;
|
||||
$data['content'] = $content;
|
||||
$data['is_deal'] = 1;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('suggest')->insert($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '反馈成 功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '反馈失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
386
application/api/model/Tencent.php
Normal file
386
application/api/model/Tencent.php
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
// use Tencent\TLSSigAPI;
|
||||
use Tencent\TLSSigAPIv2;
|
||||
|
||||
class Tencent extends Model
|
||||
{
|
||||
|
||||
//获取腾讯IM UserSig信息
|
||||
public function tencent_user_sig_info($uid){
|
||||
// $config = model('admin/Config')->get_system_config();
|
||||
// $tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
// $tencentyun_im_public_key = $config['tencentyun_im_public_key'];
|
||||
// $tencentyun_im_private_key = $config['tencentyun_im_private_key'];
|
||||
// $tencent = new \Tencent\TLSSigAPI();
|
||||
// $tencent->SetAppid($tencentyun_im_appid);
|
||||
// $tencent->SetPrivateKey($tencentyun_im_private_key);
|
||||
// $user_sig = $tencent->genSig($uid);
|
||||
// return $user_sig;
|
||||
$config = model('admin/Config')->get_uncache_system_config();
|
||||
$tencentyun_im_appid = $config['tencentyun_im_appid'];
|
||||
$tencentyun_im_key = $config['tencentyun_im_key'];
|
||||
$tencent = new \Tencent\TLSSigAPIv2($tencentyun_im_appid, $tencentyun_im_key);
|
||||
$user_sig = $tencent->genUserSig($uid);
|
||||
return $user_sig;
|
||||
}
|
||||
|
||||
//查询账号
|
||||
public function account_check($uid){
|
||||
$config = model('admin/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' => $uid, //用户id
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
dump($reslut);exit;
|
||||
}
|
||||
|
||||
//拉入黑名单
|
||||
public function black_list_add($uid, $receive_uid){
|
||||
$config = model('admin/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);
|
||||
|
||||
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 = model('admin/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){
|
||||
$config = model('admin/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);
|
||||
}
|
||||
|
||||
//发送群内普通消息
|
||||
public function send_group_msg($rid, $message_data){
|
||||
|
||||
$config = model('admin/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,
|
||||
'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($rid){
|
||||
$config = model('admin/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';
|
||||
|
||||
$curlPost = array(
|
||||
// 'Owner_Account' => 'administrator',
|
||||
'Type' => 'AVChatRoom',
|
||||
'GroupId' => strval($rid),
|
||||
'Name' => strval($rid)
|
||||
);
|
||||
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ErrorCode'] == 10021){
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}
|
||||
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//指定用户发送消息给注册用户
|
||||
public function user_sendmsg($uid, $receive_uid, $message, $machine_type = 2){
|
||||
$config = model('admin/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' => '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 = model('admin/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 = model('admin/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 = model('admin/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 content_moderation($type_name, $content){
|
||||
return ['code' => 200, 'msg' => '通过审核', 'data' => null];
|
||||
$config = model('admin/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' => 200, 'msg' => '通过审核', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '该内容不过审', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
// $txt = date('Y-m-d H:i:s').'测试';
|
||||
// error_log($txt, 3, 'a.txt');
|
||||
// return $reslut;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
2342
application/api/model/User.php
Normal file
2342
application/api/model/User.php
Normal file
File diff suppressed because it is too large
Load Diff
95
application/api/model/UserCollectRoom.php
Normal file
95
application/api/model/UserCollectRoom.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\DB;
|
||||
use think\Model;
|
||||
|
||||
class UserCollectRoom extends Model
|
||||
{
|
||||
public function is_collect_room($uid, $rid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$reslut = db::name('user_collect_room')->where($map)->find();
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '房间已收藏', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '房间未收藏', 'data' => null];
|
||||
}
|
||||
}
|
||||
public function collect_room($uid, $rid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$room_info = db::name('room')->field('rid,tid,room_micro,room_owner_uid,room_admin_uid')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['rid'] = $rid;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_collect_room')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '收藏失败', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map['rid'] = $rid;
|
||||
$reslut = db::name('room')->where($map)->setInc('collect_num', 1);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '收藏失败', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "收藏成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
//取消收藏
|
||||
public function un_collect_room($uid, $rid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
|
||||
$room_info = db::name('room')->field('rid,tid,room_micro,room_owner_uid,room_admin_uid')->where($map)->find();
|
||||
if (empty($room_info)) {
|
||||
return ['code' => 201, 'msg' => '房间信息不存在', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$reslut = db::name('user_collect_room')->where($map)->delete();
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '收藏失败', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map['rid'] = $rid;
|
||||
$reslut = db::name('room')->where($map)->setDec('collect_num', 1);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '收藏失败', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "收藏成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
328
application/api/model/UserDecorate.php
Normal file
328
application/api/model/UserDecorate.php
Normal file
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class UserDecorate extends Model
|
||||
{
|
||||
public function get_user_decorate_list($uid, $type, $page, $page_limit)
|
||||
{
|
||||
if (!in_array($type, [1, 2, 3, 4, 5, 6, 7])) {
|
||||
return ['code' => 201, 'msg' => '装扮类型参数非法', 'data' => null];
|
||||
}
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
$map = [];
|
||||
$map[] = ['a.end_time', '>', time()];
|
||||
$map[] = ['b.show_status', '=', 1];
|
||||
$map[] = ['b.is_delete', '=', 1];
|
||||
$map[] = ['a.type', '=', $type];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$model = Db::name('user_decorate')->alias('a')->join('yy_decorate b', 'a.did = b.did');
|
||||
$model = $model->where($map);
|
||||
$list = $model->field('a.udid,b.base_image,b.play_image,b.title,b.type,a.is_using,a.end_time')->order('udid desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
$v['play_image'] = localpath_to_netpath($v['play_image']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
//设置装扮
|
||||
public function set_user_decorate($uid, $udid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['udid', '=', $udid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$info = Db::name('user_decorate')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '装扮不存在', 'data' => null];
|
||||
}
|
||||
if ($info['end_time'] < time()) {
|
||||
return ['code' => 201, 'msg' => '装扮已过期', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//清理该类型装扮使用状态
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['type', '=', $info['type']];
|
||||
$data = [];
|
||||
$data['is_using'] = 2;
|
||||
$data['update_time'] = time();
|
||||
$reslut = Db::name('user_decorate')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "设置失败", 'data' => null];
|
||||
}
|
||||
//设置使用中状态
|
||||
$map = [];
|
||||
$map[] = ['udid', '=', $udid];
|
||||
$data = [];
|
||||
$data['is_using'] = 1;
|
||||
$data['update_time'] = time();
|
||||
$reslut = Db::name('user_decorate')->where($map)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "设置失败", 'data' => null];
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "设置成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "设置失败", 'data' => null];
|
||||
}
|
||||
}
|
||||
//取消装扮
|
||||
public function cancel_user_decorate($uid, $udid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['udid', '=', $udid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$data = [];
|
||||
$data['is_using'] = 2;
|
||||
$data['update_time'] = time();
|
||||
$reslut = Db::name('user_decorate')->where($map)->update($data);
|
||||
|
||||
return ['code' => 200, 'msg' => "取消成功", 'data' => null];
|
||||
}
|
||||
|
||||
//当前装扮列表
|
||||
public function get_decorate_list(){
|
||||
//当前装扮信息
|
||||
$decorate_array = [];
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$decorate_list = db::name('decorate')->where($map)->order('did asc')->select();
|
||||
foreach ($decorate_list as $a => &$b){
|
||||
$decorate_array[$b['did']] = $b;
|
||||
}
|
||||
|
||||
$level_decorate_array = [];
|
||||
//等级列表
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$map[] = ['type', '=', 2];
|
||||
$level_list = db::name('user_level')->where($map)->order('level asc')->select();
|
||||
foreach ($level_list as $k => &$v){
|
||||
$level_decorate_data = [];
|
||||
$level_decorate_data['level'] = $v['level'] - 1;
|
||||
$level_decorate_data['level_image'] = localpath_to_netpath($v['image']);
|
||||
if(!empty($v['head_decorate_id'])){
|
||||
$data = [];
|
||||
// $data['level'] = $v['level'];
|
||||
$data['title'] = $decorate_array[$v['head_decorate_id']]['title'];
|
||||
$data['base_image'] = localpath_to_netpath($decorate_array[$v['head_decorate_id']]['base_image']);
|
||||
$data['play_image'] = localpath_to_netpath($decorate_array[$v['head_decorate_id']]['play_image']);
|
||||
$level_decorate_data['head_decorate'] = $data;
|
||||
}
|
||||
|
||||
if(!empty($v['mount_decorate_id'])){
|
||||
$data = [];
|
||||
// $data['level'] = $v['level'];
|
||||
$data['title'] = $decorate_array[$v['mount_decorate_id']]['title'];
|
||||
$data['base_image'] = localpath_to_netpath($decorate_array[$v['mount_decorate_id']]['base_image']);
|
||||
$data['play_image'] = localpath_to_netpath($decorate_array[$v['mount_decorate_id']]['play_image']);
|
||||
$level_decorate_data['mount_decorate'] = $data;
|
||||
}
|
||||
|
||||
if(!empty($v['head_decorate_id']) || !empty($v['mount_decorate_id'])){
|
||||
$level_decorate_array[] = $level_decorate_data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// $data_array = [];
|
||||
// $data_array['head_decorate_array'] = $head_decorate_array;
|
||||
// $data_array['mount_decorate_array'] = $mount_decorate_array;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $level_decorate_array];
|
||||
}
|
||||
|
||||
|
||||
//用户装扮列表
|
||||
public function user_decorate_list($uid, $type, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$user_info = db::name('user')->field('uid, sex, nick_name, base64_nick_name, head_pic, special_uid')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
$user_info['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_info['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$map[] = ['a.type', '=', $type];
|
||||
$map[] = ['a.end_time', '>=', time()];
|
||||
$user_decorate_data = db::name('user_decorate')->alias('a')->join('yy_decorate b', 'a.did = b.did')->where($map)->field('a.udid, a.did, a.uid, b.type, b.title, b.base_image, a.end_time, a.is_using')->order('udid asc')->page($page, $page_limit)->select();
|
||||
foreach ($user_decorate_data as $k => &$v){
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['user_info'] = $user_info;
|
||||
$data['list'] = $user_decorate_data;
|
||||
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $data];
|
||||
}
|
||||
|
||||
//获取用户头像框详情
|
||||
public function get_user_avatar_info($uid)
|
||||
{
|
||||
$data = [];
|
||||
//获取用户头像框
|
||||
$map = [];
|
||||
$map[] = ['a.is_using', '=', 1];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$map[] = ['a.end_time', '>', time()];
|
||||
$map[] = ['a.type', '=', 1];
|
||||
$map[] = ['b.show_status', '=', 1];
|
||||
$map[] = ['b.is_delete', '=', 1];
|
||||
$model = Db::name('user_decorate')->alias('a')->join('yy_decorate b', 'a.did = b.did');
|
||||
$user_decorate_info = $model->field('b.base_image,b.play_image,b.title,a.uid')->where($map)->find();
|
||||
$data['avatar_play_image'] = '';
|
||||
if (!empty($user_decorate_info)) {
|
||||
$data['avatar_play_image'] = localpath_to_netpath($user_decorate_info['play_image']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//使用、放弃使用装扮
|
||||
public function user_use_decorate($uid, $udid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
//是否有该装扮
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['udid', '=', $udid];
|
||||
$user_decorate_info = db::name('user_decorate')->where($map)->find();
|
||||
if(!$user_decorate_info){
|
||||
return ['code' => 201, 'msg' => '用户没有该装扮', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_decorate_info['end_time'] < time()){
|
||||
return ['code' => 201, 'msg' => '该装扮已过期', 'data' => null];
|
||||
}
|
||||
|
||||
$decorate_info = db::name('decorate')->find($user_decorate_info['did']);
|
||||
if(!$decorate_info){
|
||||
return ['code' => 201, 'msg' => '该装扮不存在', 'data' => null];
|
||||
}
|
||||
$rid = 0;
|
||||
if($decorate_info['type'] == 7) {
|
||||
$rid = Db::name('room')->where('room_owner_uid', $uid)->where('is_delete', 1)->value('rid');
|
||||
if(empty($rid)) {
|
||||
return ['code' => 201, 'msg' => '没有房间不能设置房间靓号', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($user_decorate_info['is_using'] == 1) {//如果使用中则放弃使用
|
||||
|
||||
$is_using = 2;
|
||||
$update = [];
|
||||
$update['is_using'] = 2;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user_decorate')->where('udid', $udid)->update($update);
|
||||
if($user_decorate_info['type'] == 6) {
|
||||
Db::name('user')->where('uid', $uid)->update(['special_uid' => 0]);
|
||||
}
|
||||
if($user_decorate_info['type'] == 7) {
|
||||
if($user_decorate_info['rid'] > 0) {
|
||||
Db::name('user')->where('rid', $user_decorate_info['rid'])->update(['pretty_room_number' => 0]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$is_using = 1;
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['type', '=', $user_decorate_info['type']];
|
||||
$map[] = ['is_using', '=', 1];
|
||||
$user_decorate_data = db::name('user_decorate')->where($map)->find();
|
||||
if($user_decorate_data){
|
||||
$update = [];
|
||||
$update['is_using'] = 2;
|
||||
$update['update_time'] = time();
|
||||
if($user_decorate_data['type'] == 7 && $user_decorate_data['rid'] > 0) {
|
||||
$update['rid'] = 0;
|
||||
}
|
||||
$reslut = db::name('user_decorate')->where($map)->update($update);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试2', 'data' => null];
|
||||
}
|
||||
}
|
||||
$update_date = [];
|
||||
$update_date['is_using'] = 1;
|
||||
$update_date['update_time'] = time();
|
||||
if($user_decorate_info['type'] == 7) {
|
||||
$update_date['rid'] = $rid;
|
||||
|
||||
}
|
||||
$reslut = db::name('user_decorate')->where('udid', $udid)->update($update_date);
|
||||
}
|
||||
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试1', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['udid'] = $udid;
|
||||
$data['is_using'] = $is_using;
|
||||
if($user_decorate_info['type'] == 7) {
|
||||
Db::name('room')->where('rid', $rid)->update(['pretty_room_number' => $user_decorate_info['special_num']]);
|
||||
}
|
||||
if($user_decorate_info['type'] == 6) {
|
||||
Db::name('user')->where('uid', $uid)->update(['special_uid' => $user_decorate_info['special_num']]);
|
||||
}
|
||||
Db::name('user_decorate')->where('udid', $user_decorate_info['udid'])->update($data);
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "操作成功", 'data' => $data];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//购买装扮记录
|
||||
public function user_pay_decorate_log($uid, $page, $page_limit){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$map[] = ['a.from_type', '=', 2];
|
||||
$list = db::name('user_decorate_log')->alias('a')->join('yy_decorate b', 'a.did = b.did')->field('a.udid, a.uid, a.type, a.did, b.title, a.add_time,a.pay_price')->where($map)->order('a.udid desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v){
|
||||
$type_name = '';
|
||||
if($v['type'] == 1){
|
||||
$type_name = '头像框';
|
||||
}else if($v['type'] == 3){
|
||||
$type_name = '坐骑';
|
||||
}else if($v['type'] == 2){
|
||||
$type_name = '气泡';
|
||||
}else if($v['type'] == 4){
|
||||
$type_name = '光圈';
|
||||
}
|
||||
$v['content'] = $v['title'] . '-' . $type_name;
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
113
application/api/model/UserGiftPack.php
Normal file
113
application/api/model/UserGiftPack.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserGiftPack extends Model
|
||||
{
|
||||
public function get_gift_pack_list($uid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$map[] = ['a.is_use_give','=',1];
|
||||
$model = Db::name('user_gift_pack')->alias('a')->join('yy_gift b', 'a.gid = b.gid');
|
||||
$model = $model->where($map);
|
||||
|
||||
$list = $model->field('a.num,b.gid,b.gift_name,b.base_image,b.gift_price,b.sort')->order('b.sort desc')->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['base_image'] = localpath_to_netpath($v['base_image']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//num 可以为负数 减少对应背包礼物
|
||||
public function change_user_gift_pack($uid, $gid, $num = 0, $type, $remarks = '')
|
||||
{
|
||||
$TypeLable = model('admin/UserGiftPackLog')->TypeLable();
|
||||
if (!in_array($type, array_keys($TypeLable))) {
|
||||
return ['code' => 201, 'msg' => 'type参数非法', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($num != 0) {
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['gid', '=', $gid];
|
||||
$user_gift_pack_info = db::name('user_gift_pack')->where($map)->find();
|
||||
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$is_tester = db::name('user')->cache(10)->where($map)->value('is_tester');
|
||||
if (empty($user_gift_pack_info)) {
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['gid'] = $gid;
|
||||
$data['total_num'] = $num;
|
||||
$data['num'] = $num;
|
||||
$data['is_tester'] = $is_tester;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_gift_pack')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
if ($num > 0) {
|
||||
$map = [];
|
||||
$map[] = ['pid', '=', $user_gift_pack_info['pid']];
|
||||
$reslut = db::name('user_gift_pack')->where($map)->inc('total_num', $num)->inc('num', $num)->update(['update_time' => time()]);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
} elseif ($num < 0) {
|
||||
if (-$num > $user_gift_pack_info['num']) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '礼物数量不足', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['pid', '=', $user_gift_pack_info['pid']];
|
||||
$map[] = ['num', '>=', -$num];
|
||||
$reslut = db::name('user_gift_pack')->where($map)->inc('num', $num)->update();
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '无效礼物数量', 'data' => null];
|
||||
}
|
||||
}
|
||||
//写入背包日志
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['type'] = $type;
|
||||
$data['gid'] = $gid;
|
||||
$data['change_num'] = $num;
|
||||
$data['after_num'] = $user_gift_pack_info['num'] + $num;
|
||||
$data['is_tester'] = $is_tester;
|
||||
$data['remarks'] = $remarks;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_gift_pack_log')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
} else {
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
34
application/api/model/UserGuard.php
Normal file
34
application/api/model/UserGuard.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserGuard extends Model
|
||||
{
|
||||
//判断用户守护身份是否有效
|
||||
public function get_user_guard_info($uid, $guard_rid, $guard_uid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['guard_rid', '=', $guard_rid];
|
||||
$map[] = ['guard_uid', '=', $guard_uid];
|
||||
$info = db::name('user_guard')->field('gid,over_time')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '守护身份不存在', 'data' => null];
|
||||
}
|
||||
return ['code' => 200, 'msg' => '守护中', 'data' => $info];
|
||||
}
|
||||
//判断用户守护身份是否有效
|
||||
public function is_guard_by_info($guard_info)
|
||||
{
|
||||
if (empty($guard_info)) {
|
||||
return ['code' => 201, 'msg' => '您不是该房间守护', 'data' => null];
|
||||
}
|
||||
if ($guard_info['over_time'] < time()) {
|
||||
return ['code' => 201, 'msg' => '您的守护已过期', 'data' => null];
|
||||
}
|
||||
return ['code' => 200, 'msg' => '守护中', 'data' => $guard_info];
|
||||
}
|
||||
}
|
||||
60
application/api/model/UserLevel.php
Normal file
60
application/api/model/UserLevel.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\DB;
|
||||
use think\Model;
|
||||
|
||||
class UserLevel extends Model
|
||||
{
|
||||
public function get_user_level_info($type, $level)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['level', '=', $level];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$info = db::name('user_level')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
$info['image'] = localpath_to_netpath($info['image']);
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function get_level_list($uid, $type)
|
||||
{
|
||||
$user_info = db::name('user')->field('uid, nick_name, base64_nick_name, head_pic')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '用户信息不存在', 'data' => null];
|
||||
}
|
||||
$user_info['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_info['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$user_level_image = model('user')->get_user_charm_contribution_info($uid);
|
||||
$user_info['charm_level_image'] = $user_level_image['data']['charm_level_image'];
|
||||
$user_info['contribution_level_image'] = $user_level_image['data']['contribution_level_image'];
|
||||
|
||||
|
||||
if($type == 1){
|
||||
$user_level = model('api/user')->get_user_charm_level_info($uid);
|
||||
}else if($type == 2){
|
||||
$user_level = model('api/user')->get_user_contribution_info($uid);
|
||||
}
|
||||
$user_level_info = $user_level['data'];
|
||||
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = Db::name('user_level')->where($map)->field('level, number,image')->order('level', 'asc')->select();
|
||||
foreach($list as &$val) {
|
||||
$val['image'] = localpath_to_netpath($val['image']);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['user_info'] = $user_info;
|
||||
$data['user_level_info'] = $user_level_info;
|
||||
$data['level_list'] = $list;
|
||||
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $data];
|
||||
}
|
||||
|
||||
}
|
||||
555
application/api/model/UserLogin.php
Normal file
555
application/api/model/UserLogin.php
Normal file
@@ -0,0 +1,555 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
|
||||
class UserLogin extends Model
|
||||
{
|
||||
//注册
|
||||
public function user_reg($user_name, $password, $reg_code)
|
||||
{
|
||||
$pid = 0;
|
||||
$path = '0';
|
||||
if (!empty($reg_code)) {
|
||||
$map = [];
|
||||
$map[] = ['reg_code', '=', $reg_code];
|
||||
$p_user_info = Db::name('user')->where($map)->find();
|
||||
if (empty($p_user_info)) {
|
||||
return ['code' => 201, 'msg' => '邀请码不存在', 'data' => null];
|
||||
}
|
||||
$pid = $p_user_info['uid'];
|
||||
$path = $p_user_info['path'];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['user_name', '=', $user_name];
|
||||
$user_info = db::name('user')->where($map)->find();
|
||||
if (!empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '用户名已存在', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$uid = $this->get_available_uid(); //获取自增用户id 过滤靓号
|
||||
$data['uid'] = $uid;
|
||||
$data['user_name'] = $user_name;
|
||||
// $nick_name = model('admin/User')->get_rand_nick_name();
|
||||
$nick_name = '游客'.$uid;
|
||||
$data['nick_name'] = $nick_name;
|
||||
$data['base64_nick_name'] = base64_encode($nick_name);
|
||||
$data['password'] = $password;
|
||||
$data['pid'] = $pid;
|
||||
$reg_ip = request()->ip();
|
||||
$data['reg_ip'] = $reg_ip;
|
||||
$position = ip_to_position($reg_ip);
|
||||
$data['country'] = $position['country'];
|
||||
$data['province'] = $position['province'];
|
||||
$data['city'] = $position['city'];
|
||||
$birthday = date('Y-m-d');
|
||||
$data['birthday'] = $birthday;
|
||||
$constellation = model('user')->get_user_constellation($birthday);
|
||||
$data['constellation'] = $constellation['data'];
|
||||
$data['head_pic'] = 'head_pic/head_pic.png';
|
||||
$data['autograph'] = '这个人很懒,什么都没写';
|
||||
$data['hobby'] = '暂无';
|
||||
$validate = validate('admin/user');
|
||||
$reslut = $validate->scene('apiAdd')->check($data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$User = model('admin/user');
|
||||
$reslut = $User->save($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '注册失败', 'data' => null];
|
||||
};
|
||||
/*********** 腾讯云IM ********/
|
||||
$user_sig = model('Tencent')->tencent_user_sig_info($uid);
|
||||
if(empty($user_sig)){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['path'] = $path . ',' . $uid;
|
||||
$data['user_sig'] = $user_sig;
|
||||
$data['is_first_login'] = 1;
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user')->where(['uid' => $uid])->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '注册失败', 'data' => null];
|
||||
}
|
||||
model('api/UserWallet')->create_data($uid);
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '注册成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
// dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '注册失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//账号登录
|
||||
public function user_login($user_name, $password, $last_login_device, $system)
|
||||
{
|
||||
if (empty($user_name)) {
|
||||
return ['code' => 201, 'msg' => '用户名不能为空', 'data' => null];
|
||||
}
|
||||
if (empty($password)) {
|
||||
return ['code' => 201, 'msg' => '密码不能为空', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['user_name', '=', $user_name];
|
||||
$user_info = db::name('user')->where($map)->find();
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '用户名不存在', 'data' => null];
|
||||
}
|
||||
if (md5($password) != $user_info['password']) {
|
||||
return ['code' => 201, 'msg' => '密码错误', 'data' => null];
|
||||
}
|
||||
if ($user_info['login_status'] != 1) {
|
||||
return ['code' => 201, 'msg' => '用户已被封禁', 'data' => null];
|
||||
}
|
||||
|
||||
$configs = get_uncache_system_config();
|
||||
if($configs['open_verify_token'] == 1){
|
||||
if(!empty($user_info['login_token'])){
|
||||
return ['code' => 201, 'msg' => '用户已在线,无法重复登录', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//该设备号是否已被封禁
|
||||
$config = get_system_config();
|
||||
// if(!empty($config['ban_device'])){
|
||||
// $ban_device = trim($config['ban_device'],',');
|
||||
// $ban_device = explode(',',$ban_device);
|
||||
// if (in_array($last_login_device,$ban_device)) {
|
||||
// return ['code' => 201, 'msg' => '该设备已被封禁', 'data' => null];
|
||||
// }
|
||||
// }
|
||||
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['type_text', '=', $last_login_device];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$block_device = db::name('block')->where($map)->find();
|
||||
if($block_device){
|
||||
return ['code' => 201, 'msg' => '当前设备号已被封禁。', 'data' => null];
|
||||
}
|
||||
|
||||
//该ip是否被封禁
|
||||
$login_ip = request()->ip();
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 3];
|
||||
$map[] = ['type_text', '=', $login_ip];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$block_ip = db::name('block')->where($map)->find();
|
||||
if($block_ip){
|
||||
return ['code' => 201, 'msg' => '当前IP地址已被封禁。', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $user_info['uid'];
|
||||
$login_token_string = md5($user_info['uid'] . date('YmdHis') . generateRandom(32));
|
||||
// if (!empty($user_info['login_token'])) {
|
||||
// $login_token_string = $user_info['login_token'];
|
||||
// }
|
||||
$rid = 0;
|
||||
if($user_info['is_first_login'] == 1){
|
||||
$data['is_first_login'] = 2;
|
||||
$rid_array = db::name('room')->where('room_status', 1)->where('cate_id', 26)->order('today_hot_value desc')->limit(4)->column('rid');
|
||||
if(!empty($rid_array)){
|
||||
$rid = $rid_array[array_rand($rid_array,1)];
|
||||
}
|
||||
}
|
||||
|
||||
$user_sigs = $user_info['user_sig'];
|
||||
if(empty($user_info['user_sig'])){
|
||||
$user_sig = model('Tencent')->tencent_user_sig_info($user_info['uid']);
|
||||
if(empty($user_sig)){
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
}
|
||||
$data['user_sig'] = $user_sig;
|
||||
$user_sigs = $user_sig;
|
||||
}
|
||||
$data['system'] = $system;
|
||||
$data['login_token'] = $login_token_string;
|
||||
$data['last_login_time'] = time();
|
||||
$data['last_login_device'] = $last_login_device;
|
||||
$data['login_ip'] = request()->ip();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user')->update($data);
|
||||
|
||||
$return_res = [];
|
||||
$return_res['uid'] = $user_info['uid'];
|
||||
$return_res['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$return_res['user_name'] = $user_name;
|
||||
$return_res['login_token'] = $login_token_string;
|
||||
$return_res['user_sig'] = $user_sigs;
|
||||
$return_res['rid'] = $rid;
|
||||
$return_res['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
} else {
|
||||
$this->add_user_login_log($user_info['uid'], request()->ip(), $last_login_device, 1);
|
||||
return ['code' => 200, 'msg' => '登录成功', 'data' => $return_res];
|
||||
}
|
||||
}
|
||||
|
||||
//过滤靓号
|
||||
private function get_available_uid($uid = 0)
|
||||
{
|
||||
if (empty($uid)) {
|
||||
$uid = db::name('user')->order('uid desc')->value('uid');
|
||||
if(empty($uid)){
|
||||
$uid = 300001;
|
||||
}
|
||||
}
|
||||
$uid = $uid + mt_rand(1, 10);
|
||||
$config = get_system_config();
|
||||
$filter_uid_arr = explode(",", $config['filter_uid']);
|
||||
if (in_array($uid, $filter_uid_arr)) {
|
||||
return $this->get_available_uid();
|
||||
}
|
||||
$user_info = db::name('user')->field('uid')->where('uid', $uid)->find();
|
||||
if (!empty($user_info)) {
|
||||
return $this->get_available_uid($user_info['uid']);
|
||||
} else {
|
||||
return $uid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//验证码登录
|
||||
public function phone_verification_code_log($user_name, $last_login_device, $system)
|
||||
{
|
||||
if (empty($user_name)) {
|
||||
return ['code' => 201, 'msg' => '用户名不能为空', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['user_name', '=', $user_name];
|
||||
$user_info = db::name('user')->where($map)->find();
|
||||
|
||||
$configs = get_uncache_system_config();
|
||||
|
||||
//该设备号是否已被封禁
|
||||
$config = get_system_config();
|
||||
// if(!empty($config['ban_device'])){
|
||||
// $ban_device = trim($config['ban_device'],',');
|
||||
// $ban_device = explode(',',$ban_device);
|
||||
// if (in_array($last_login_device,$ban_device)) {
|
||||
// return ['code' => 201, 'msg' => '该设备已被封禁', 'data' => null];
|
||||
// }
|
||||
// }
|
||||
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['type_text', '=', $last_login_device];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$block_device = db::name('block')->where($map)->find();
|
||||
if($block_device){
|
||||
return ['code' => 201, 'msg' => '当前设备号已被封禁。', 'data' => null];
|
||||
}
|
||||
|
||||
//该ip是否被封禁
|
||||
$login_ip = request()->ip();
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 3];
|
||||
$map[] = ['type_text', '=', $login_ip];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$block_ip = db::name('block')->where($map)->find();
|
||||
if($block_ip){
|
||||
return ['code' => 201, 'msg' => '当前IP地址已被封禁。', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
if($user_info){//登录
|
||||
if ($user_info['login_status'] != 1) {
|
||||
return ['code' => 201, 'msg' => '用户已被封禁', 'data' => null];
|
||||
}
|
||||
|
||||
if($configs['open_verify_token'] == 1){
|
||||
if(!empty($user_info['login_token'])){
|
||||
return ['code' => 201, 'msg' => '用户已在线,无法重复登录', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $user_info['uid'];
|
||||
$login_token_string = md5($user_info['uid'] . date('YmdHis') . generateRandom(32));
|
||||
|
||||
$user_sigs = $user_info['user_sig'];
|
||||
if(empty($user_info['user_sig'])){
|
||||
$user_sig = model('Tencent')->tencent_user_sig_info($user_info['uid']);
|
||||
if(empty($user_sig)){
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
}
|
||||
$data['user_sig'] = $user_sig;
|
||||
$user_sigs = $user_sig;
|
||||
}
|
||||
|
||||
$data['system'] = $system;
|
||||
$data['login_token'] = $login_token_string;
|
||||
$data['last_login_time'] = time();
|
||||
$data['last_login_device'] = $last_login_device;
|
||||
$data['login_ip'] = request()->ip();
|
||||
$data['update_time'] = time();
|
||||
// $data['is_online'] = 1;
|
||||
$reslut = db::name('user')->update($data);
|
||||
|
||||
$return_res = [];
|
||||
$return_res['uid'] = $user_info['uid'];
|
||||
$return_res['head_pic'] = localpath_to_netpath($user_info['head_pic']);
|
||||
$return_res['user_name'] = $user_name;
|
||||
$return_res['login_token'] = $login_token_string;
|
||||
$return_res['user_sig'] = $user_sigs;
|
||||
$return_res['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$return_res['is_reg'] = 2;
|
||||
$return_res['rid'] = 0;
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
}
|
||||
$uid = $user_info['uid'];
|
||||
}else{//注册
|
||||
$path = '0';
|
||||
$data = [];
|
||||
$uid = $this->get_available_uid(); //获取自增用户id 过滤靓号
|
||||
$data['uid'] = $uid;
|
||||
$data['user_name'] = $user_name;
|
||||
// $nick_name = model('admin/User')->get_rand_nick_name();
|
||||
$nick_name = '游客'.$uid;
|
||||
$data['nick_name'] = $nick_name;
|
||||
$data['base64_nick_name'] = $base64_nick_name = base64_encode($nick_name);
|
||||
// $data['password'] = $password;
|
||||
// $data['pid'] = $pid;
|
||||
$reg_ip = request()->ip();
|
||||
$data['reg_ip'] = $reg_ip;
|
||||
$position = ip_to_position($reg_ip);
|
||||
$data['country'] = $position['country'];
|
||||
$data['province'] = $position['province'];
|
||||
$data['city'] = $position['city'];
|
||||
$birthday = date('Y-m-d');
|
||||
$data['birthday'] = $birthday;
|
||||
$constellation = model('user')->get_user_constellation($birthday);
|
||||
$data['constellation'] = $constellation['data'];
|
||||
// $head_pic = 'head_pic/bc6053e1-0b93-4d9f-b130-cd336397f8e0.png';
|
||||
$data['head_pic'] = 'head_pic/head_pic.png';
|
||||
$data['autograph'] = '这个人很懒,什么都没写';
|
||||
$data['hobby'] = '暂无';
|
||||
$data['system'] = $system;
|
||||
// $validate = validate('admin/user');
|
||||
// $reslut = $validate->scene('apiAdd')->check($data);
|
||||
// if ($reslut !== true) {
|
||||
// return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
// }
|
||||
$data['is_online'] = 1;
|
||||
$User = model('admin/user');
|
||||
$reslut = $User->save($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
};
|
||||
$head_pic = localpath_to_netpath($data['head_pic']);
|
||||
/*********** 腾讯云IM ********/
|
||||
$user_sig = model('Tencent')->tencent_user_sig_info($uid);
|
||||
if(empty($user_sig)){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['path'] = $path . ',' . $uid;
|
||||
$data['user_sig'] = $user_sig;
|
||||
$data['last_login_time'] = time();
|
||||
$data['last_login_device'] = $last_login_device;
|
||||
$data['is_first_login'] = 2;
|
||||
$data['login_ip'] = request()->ip();
|
||||
$data['login_token'] = $login_token_string = md5($uid . date('YmdHis') . generateRandom(32));
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user')->where(['uid' => $uid])->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
$rid = 0;
|
||||
$rid_array = db::name('room')->where('room_status', 1)->where('cate_id', 26)->order('today_hot_value desc')->limit(4)->column('rid');
|
||||
if(!empty($rid_array)){
|
||||
$rid = $rid_array[array_rand($rid_array,1)];
|
||||
}
|
||||
|
||||
|
||||
$return_res = [];
|
||||
$return_res['uid'] = $uid;
|
||||
$return_res['head_pic'] = $head_pic;
|
||||
$return_res['user_name'] = '';
|
||||
$return_res['login_token'] = $login_token_string;
|
||||
$return_res['user_sig'] = $user_sig;
|
||||
$return_res['nick_name'] = mb_convert_encoding(base64_decode($base64_nick_name), 'UTF-8', 'UTF-8');
|
||||
$return_res['is_reg'] = 1;
|
||||
$return_res['rid'] = $rid;
|
||||
model('api/UserWallet')->create_data($uid);
|
||||
}
|
||||
$this->add_user_login_log($uid, $login_ip, $last_login_device, 2);
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '登录成功', 'data' => $return_res];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '登录失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//修正
|
||||
public function batch_create_test_account(){
|
||||
$num = 20;
|
||||
for($i=1;$i<=$num;$i++){
|
||||
$data_result = $this->create_test_account();
|
||||
}
|
||||
return ['code' => 200, 'msg' => '操作成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//单个生成账号
|
||||
public function create_test_account(){
|
||||
|
||||
|
||||
$pid = 0;
|
||||
$path = '0';
|
||||
$map = [];
|
||||
//根据号段生成账号
|
||||
$user_name = $this->hao_duan_create();
|
||||
if($user_name === false){
|
||||
return ['code' => 201, 'msg' => '注册失败0', 'data' => null];
|
||||
}
|
||||
|
||||
//随机生成秘钥信息
|
||||
$pwd = generateRandom(6);
|
||||
|
||||
$password = md5($pwd);
|
||||
$data = [];
|
||||
$uid = $this->get_available_uid(); //获取自增用户id 过滤靓号
|
||||
|
||||
$data['uid'] = $uid;
|
||||
$data['user_name'] = $user_name;
|
||||
$nick_name = model('admin/User')->get_rand_nick_name();
|
||||
// $nick_name = '游客'.$uid;
|
||||
$data['nick_name'] = $nick_name;
|
||||
$data['base64_nick_name'] = base64_encode($nick_name);
|
||||
$data['password'] = $password;
|
||||
$data['pid'] = $pid;
|
||||
|
||||
// $reg_ip = request()->ip();
|
||||
// $data['reg_ip'] = $reg_ip;
|
||||
// $position = ip_to_position($reg_ip);
|
||||
// $data['country'] = $position['country'];
|
||||
// $data['province'] = $position['province'];
|
||||
// $data['city'] = $position['city'];
|
||||
$birthday = date('Y-m-d');
|
||||
$data['birthday'] = $birthday;
|
||||
$constellation = model('api/user')->get_user_constellation($birthday);
|
||||
$data['constellation'] = $constellation['data'];
|
||||
$sex = mt_rand(1,2);
|
||||
$data['sex'] = $sex;
|
||||
$data['is_tester'] = 2;
|
||||
|
||||
$rand_num = rand(1,16);
|
||||
$head_pic = "r_head_pic/head_pic{$rand_num}.jpg";
|
||||
// $head_pic = 'head_pic/head_pic.png';
|
||||
$data['head_pic'] = $head_pic;
|
||||
$data['autograph'] = '这个人很懒,什么都没写';
|
||||
$data['hobby'] = '暂无';
|
||||
$data['is_sys_tester'] = 1;
|
||||
$data['login_status'] = 1;
|
||||
$data['charm_level'] = 1;
|
||||
$data['contribution_level'] = 1;
|
||||
$data['is_real'] = 2;
|
||||
$data['is_can_recharge'] = 2;
|
||||
$data['real_name'] = '';
|
||||
$data['is_sign'] = 1;
|
||||
$data['path'] = $path . ',' . $uid;
|
||||
$data['add_time'] = time();
|
||||
$user_sig = model('api/Tencent')->tencent_user_sig_info($uid);
|
||||
$data['user_sig'] = $user_sig;
|
||||
|
||||
try {
|
||||
Db::startTrans();
|
||||
db::name('user')->insert($data);
|
||||
|
||||
$data1 = [
|
||||
'uid' => $uid,
|
||||
'pwd' => $pwd,
|
||||
'add_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
db::name('user_lu_pwd')->insert($data1);
|
||||
model('api/UserWallet')->create_data($uid);
|
||||
Db::commit();
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
halt($e);
|
||||
return ['code' => 201, 'msg' => '操作失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//虚拟号段
|
||||
public function hao_duan_create(){
|
||||
$user_name = generateRandomPhoneNumber();
|
||||
$user_name_exist = db::name('user')->where('user_name','=',$user_name)->field('uid')->find();
|
||||
if(!empty($user_name_exist)){
|
||||
// return $this->hao_duan_create();
|
||||
return false;
|
||||
}
|
||||
return $user_name;
|
||||
}
|
||||
|
||||
|
||||
//登录记录表
|
||||
public function add_user_login_log($uid, $login_ip, $login_device, $type = 1){
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['type'] = $type;
|
||||
$insert['login_ip'] = $login_ip;
|
||||
$insert['login_device'] = $login_device;
|
||||
$insert['add_time'] = time();
|
||||
db::name('user_login_log')->insert($insert);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
149
application/api/model/UserMessage.php
Normal file
149
application/api/model/UserMessage.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class UserMessage extends Model
|
||||
{
|
||||
|
||||
//发送消息
|
||||
public function send_message($uid, $type, $id, $title, $content)
|
||||
{
|
||||
$UserMessage = model('admin/UserMessage')->TypeLable();
|
||||
if (empty($UserMessage[$type])) {
|
||||
return ['code' => 201, 'msg' => '非法消息类型', 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['type'] = $type;
|
||||
$data['id'] = $id;
|
||||
$data['title'] = $title;
|
||||
$data['content'] = $content;
|
||||
$data['is_read'] = 1;
|
||||
$data['read_time'] = 0;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = Db::name('user_message')->insert($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '发送成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '发送失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
//系统封面消息接口
|
||||
public function get_user_message_cover_info($uid)
|
||||
{
|
||||
//获取系统消息
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_read', '=', 1];
|
||||
$map[] = ['type', '=', 1];
|
||||
$system_no_read_count = db::name('user_message')->where($map)->count();
|
||||
//获取最后一条未读系统消息
|
||||
$system_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
||||
|
||||
//获取订单消息
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_read', '=', 1];
|
||||
$map[] = ['type', '=', 2];
|
||||
$order_no_read_count = db::name('user_message')->where($map)->count();
|
||||
//获取最后一条未读系统消息
|
||||
$order_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
||||
//获取互动消息未处理数量
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_read', '=', 1];
|
||||
$map[] = ['type', '=', 3];
|
||||
$relation_no_read_count = db::name('user_message')->where($map)->count();
|
||||
//获取最后一条未读系统消息
|
||||
$relation_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_read', '=', 1];
|
||||
$map[] = ['type', '=',4];
|
||||
$zone_no_read_count = db::name('user_message')->where($map)->count();
|
||||
//获取最后一条未读系统消息
|
||||
$zone_last_message = db::name('user_message')->field('title,add_time')->where($map)->order('mid desc')->find();
|
||||
|
||||
$data = [];
|
||||
$data['system_no_read_count'] = $system_no_read_count;
|
||||
$data['system_last_message'] = $system_last_message;
|
||||
$data['order_no_read_count'] = $order_no_read_count;
|
||||
$data['order_last_message'] = $order_last_message;
|
||||
$data['relation_no_read_count'] = $relation_no_read_count;
|
||||
$data['relation_last_message'] = $relation_last_message;
|
||||
$data['zone_no_read_count'] = $zone_no_read_count;
|
||||
$data['zone_last_message'] = $zone_last_message;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
//消息列表接口
|
||||
public function get_user_message_list($uid, $type, $page, $page_limit)
|
||||
{
|
||||
if (!in_array($type, [1, 2, 3])) {
|
||||
return ['code' => 201, 'msg' => 'type非法参数', 'data' => null];
|
||||
}
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 30 ? $page_limit : 30;
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['is_show', '=', 1];
|
||||
|
||||
//设置消息已读
|
||||
$data = [];
|
||||
$data['is_read'] = 2;
|
||||
$data['read_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
db::name('user_message')->where($map)->update($data);
|
||||
|
||||
//获取最后一条未读系统消息
|
||||
$list = db::name('user_message')->field('mid,title,type,content,id,is_read,add_time')->where($map)->order('mid desc')->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
|
||||
|
||||
switch ($v['type']) {
|
||||
case '2':
|
||||
$map = [];
|
||||
$map[] = ['oid', '=', $v['id']];
|
||||
$play_order_info = db::name('user_player_order')->field('oid,order_sn,uid,player_uid,status,add_time,receive_time,complete_time,is_over,over_close_time')->where($map)->find();
|
||||
if (!empty($play_order_info)) {
|
||||
$play_order_info['is_player']=1;//非陪玩
|
||||
if($uid==$play_order_info['player_uid']){
|
||||
$play_order_info['is_player']=2;//陪玩
|
||||
}
|
||||
$v['data'] = $play_order_info;
|
||||
}
|
||||
break;
|
||||
|
||||
case '3':
|
||||
$map = [];
|
||||
$map[] = ['aid', '=', $v['id']];
|
||||
$user_relation_apply_info = db::name('user_relation_apply')->field('aid,type,uid,recived_uid,status,deal_time')->where($map)->find();
|
||||
if (!empty($user_relation_apply_info)) {
|
||||
$v['data'] = $user_relation_apply_info;
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
$map = [];
|
||||
$map[] = ['cid', '=', $v['id']];
|
||||
$user_zone_comment_info = db::name('user_zone_comment')->field('cid,uid,recived_uid,content,add_time')->where($map)->find();
|
||||
if (!empty($user_zone_comment_info)) {
|
||||
$v['data'] = $user_zone_comment_info;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$v['data'] = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
}
|
||||
89
application/api/model/UserMode.php
Normal file
89
application/api/model/UserMode.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
class UserMode extends Model{
|
||||
|
||||
//开启、修改青少年模式
|
||||
public function open_teen_mode($uid, $type, $password, $again_password){
|
||||
$user_info = db::name('user')->where('uid',$uid)->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($password != $again_password){
|
||||
return ['code' => 201, 'msg' => '两次密码不一致', 'data' => null];
|
||||
}
|
||||
if($user_info['is_real']!=1){
|
||||
return ['code' => 201, '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' => 201, 'msg' => '青少年模式尚未开启', 'data' => null];
|
||||
}
|
||||
$msg = '修改';
|
||||
$data['teenager_password'] = md5($password);
|
||||
$data['update_time'] = time();
|
||||
}
|
||||
|
||||
$reslut = db::name('user')->where('uid', $uid)->update($data);
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => $msg.'成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $msg.'失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//关闭、修改青少年模式
|
||||
public function close_teen_mode($uid, $type, $password){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info['is_teenager'] == 2){
|
||||
return ['code' => 201, 'msg' => '青少年模式尚未开启', 'data' => null];
|
||||
}
|
||||
|
||||
if(md5($password) != $user_info['teenager_password']){
|
||||
return ['code' => 201, 'msg' => '密码不正确', 'data' => null];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if($type == 1){//关闭
|
||||
$msg = '关闭';
|
||||
$data['is_teenager'] = 2;
|
||||
$reslut = db::name('user')->where('uid', $uid)->update($data);
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => $msg.'成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => $msg.'失败', 'data' => null];
|
||||
}
|
||||
}else if($type == 2){//确认密码
|
||||
return ['code' => 200, 'msg' => '密码正确', 'data' => null];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 申诉身份验证
|
||||
* @return void
|
||||
*/
|
||||
public function edit_teen_mode($uid, $card_id, $real_name)
|
||||
{
|
||||
if (!$card_id || !$real_name) return ['code' => 201, 'msg' => '缺少必要参数失败', 'data' => null];
|
||||
$user_info = Db::name('user')->where('uid', $uid)->find();
|
||||
if (!$user_info) return ['code' => 201, 'msg' => '用户已被删除或不存在', 'data' => null];
|
||||
if($card_id==$user_info['card_id']&&$real_name==$user_info['real_name']){
|
||||
return ['code' => 200, 'msg' => '验证成功', 'data' => $user_info];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '验证失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
400
application/api/model/UserPlayerOrder.php
Normal file
400
application/api/model/UserPlayerOrder.php
Normal file
@@ -0,0 +1,400 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserPlayerOrder extends Model
|
||||
{
|
||||
//陪玩下单
|
||||
public function create_player_order($uid, $pid, $buy_num, $trade_password)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['pid', '=', $pid];
|
||||
$player_info = db::name('user_player')->field('uid,gid,lid,price,skill_image,cover_image,sound,sound_duration,introduction,status,remarks')->where($map)->find();
|
||||
if (empty($player_info)) {
|
||||
return ['code' => 201, 'msg' => '陪玩不存在', 'data' => null];
|
||||
}
|
||||
if ($player_info['status'] != 2) {
|
||||
return ['code' => 201, 'msg' => '该陪玩暂无法接单', 'data' => null];
|
||||
}
|
||||
if (!is_int($buy_num * 1)) {
|
||||
return ['code' => 201, 'msg' => '下单数量非法', 'data' => null];
|
||||
}
|
||||
if ($buy_num < 1) {
|
||||
return ['code' => 201, 'msg' => '下单数量必须大于0', 'data' => null];
|
||||
}
|
||||
// $user_trade_password = db::name('user')->where(['uid'=>$uid])->value('trade_password');
|
||||
// if(empty($user_trade_password)){
|
||||
// return ['code' => 201, 'msg' => '请设置二级密码', 'data' => null];
|
||||
// }
|
||||
|
||||
// if($user_trade_password!=md5($trade_password)){
|
||||
// return ['code' => 201, 'msg' => '二级密码有误', 'data' => null];
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$total_amount = $player_info['price'] * $buy_num;
|
||||
$order_sn = $this->create_play_order_sn();
|
||||
$order_data = [];
|
||||
$order_data['order_sn'] = $order_sn;
|
||||
$order_data['uid'] = $uid;
|
||||
$order_data['pid'] = $pid;
|
||||
$order_data['gid'] = $player_info['gid'];
|
||||
$order_data['player_uid'] = $player_info['uid'];
|
||||
$order_data['price'] = $player_info['price'];
|
||||
$order_data['num'] = $buy_num;
|
||||
$order_data['total_amount'] = $total_amount;
|
||||
$order_data['status'] = 1;
|
||||
$order_data['receive_time'] = 0;
|
||||
$order_data['complete_time'] = 0;
|
||||
$order_data['is_over'] = 1;
|
||||
$order_data['over_close_time'] = 0;
|
||||
$order_data['service_rate'] = 0;
|
||||
$order_data['service_comment'] = '';
|
||||
$order_data['add_time'] = time();
|
||||
$order_data['comment_time'] = 0;
|
||||
$order_data['update_time'] = 0;
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//创建订单
|
||||
$oid = db::name('user_player_order')->insertGetId($order_data);
|
||||
if (!$oid) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
//扣除账户积分
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$total_amount, 2, 2, "陪玩订单:" . $order_sn, $uid, $oid);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '余额不足', 'data' => null];
|
||||
}
|
||||
//发送短信提醒
|
||||
/*
|
||||
$player_mobile = db::name('user')->where('uid', $player_info['uid'])->value('user_name');
|
||||
model('sms')->sms_player_order($player_mobile, $order_sn);
|
||||
*/
|
||||
$content = "您有新的陪玩订单,请及时接单";
|
||||
$data = [];
|
||||
$data['code'] = 1002;
|
||||
$data['data'] = ['oid' => $oid,'play_order_identity_type'=>1];
|
||||
model('admin/Jpush')->push_notification_message($player_info['uid'], '陪玩订单提醒', $content, $data);
|
||||
|
||||
$reslut=model('api/UserMessage')->send_message($player_info['uid'], 2, $oid, "陪玩订单提醒", $content);
|
||||
if ($reslut['code']!=200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "处理失败", 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
//下单成功返回订单号
|
||||
return ['code' => 200, 'msg' => "下单成功", 'data' => $oid];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//获取我的陪玩下单订单
|
||||
public function get_user_order($uid, $status, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
if (!empty($status)) {
|
||||
$map[] = ['status', '=', $status];
|
||||
}
|
||||
$list = db::name('user_player_order')->field('oid,gid,pid,order_sn,price,num,total_amount,status,add_time,is_over')->where($map)->page($page, $page_limit)->select();
|
||||
|
||||
foreach ($list as $k => &$v) {
|
||||
$game_info = model('game')->get_game_info($v['gid']);
|
||||
$v['game_name'] = $game_info['data']['game_name'];
|
||||
$player_info = model('player')->get_player_info($v['pid']);
|
||||
$v['player_nick_name'] = $player_info['data']['nick_name'];
|
||||
$v['player_head_pic'] = localpath_to_netpath($player_info['data']['head_pic']);
|
||||
$v['player_cover_image'] = localpath_to_netpath($player_info['data']['cover_image']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $list];
|
||||
}
|
||||
//我的 下单订单详情
|
||||
public function get_user_order_info($uid, $oid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['oid', '=', $oid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$info = db::name('user_player_order')->field('oid,gid,pid,uid,player_uid,order_sn,price,num,total_amount,status,receive_time,complete_time,is_over,over_close_time,service_rate,service_comment,comment_time,add_time,kf_uid')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => "订单不存在", 'data' => null];
|
||||
}
|
||||
|
||||
$game_info = model('game')->get_game_info($info['gid']);
|
||||
$info['game_name'] = $game_info['data']['game_name'];
|
||||
$player_info = model('player')->get_player_info($info['pid']);
|
||||
$info['player_nick_name'] = $player_info['data']['nick_name'];
|
||||
$info['uid_nickname'] = db::name('user')->where(['uid' => $info['uid']])->value('nick_name');
|
||||
$info['is_qx'] = 2; //1 可以取消 2不可取消
|
||||
$time = $info['add_time'] + 600;
|
||||
if ($time > time() && $info['is_over'] != 3) {
|
||||
$info['is_qx'] = 1;
|
||||
}
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $info];
|
||||
}
|
||||
//获取我的陪玩 接单订单
|
||||
public function get_player_order($uid, $time, $status, $page, $page_limit)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
|
||||
$map[] = ['player_uid', '=', $uid];
|
||||
if (!empty($status)) {
|
||||
$map[] = ['status', '=', $status];
|
||||
}
|
||||
$list = db::name('user_player_order')->field('oid,gid,pid,uid,player_uid,order_sn,price,num,total_amount,status,receive_time,complete_time,is_over,over_close_time,service_rate,service_comment,comment_time,add_time')->where($map)->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$game_info = model('game')->get_game_info($v['gid']);
|
||||
|
||||
$v['game_name'] = $game_info['data']['game_name'];
|
||||
$v['game_ico'] = $game_info['data']['game_ico'];
|
||||
$user_info = model('user')->get_user_info($v['uid']);
|
||||
$v['user_nick_name'] = $user_info['data']['nick_name']; //下单用户昵称
|
||||
$v['user_head_pic'] = localpath_to_netpath($user_info['data']['head_pic']); //下单用户头像
|
||||
$player_info = model('player')->get_player_info($v['pid']);
|
||||
$v['player_cover_image'] = localpath_to_netpath($player_info['data']['cover_image']); //陪玩封面
|
||||
}
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $list];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//接单详情
|
||||
public function get_player_order_info($uid, $oid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['oid', '=', $oid];
|
||||
$map[] = ['player_uid', '=', $uid];
|
||||
$info = db::name('user_player_order')->field('oid,gid,pid,uid,player_uid,order_sn,price,num,total_amount,status,receive_time,complete_time,is_over,over_close_time,service_rate,service_comment,comment_time,add_time,kf_uid')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => "订单不存在", 'data' => null];
|
||||
}
|
||||
|
||||
$game_info = model('game')->get_game_info($info['gid']);
|
||||
$info['game_name'] = $game_info['data']['game_name'];
|
||||
|
||||
$user_info = model('user')->get_user_info($info['uid']);
|
||||
$info['user_nick_name'] = $user_info['data']['nick_name'];
|
||||
$uid_nickname = db::name('user')->where(['uid' => $info['uid']])->value('base64_nick_name');
|
||||
$info['uid_nickname'] = mb_convert_encoding(base64_decode($uid_nickname), 'UTF-8', 'UTF-8');
|
||||
|
||||
$player_nickname = db::name('user')->where(['uid' => $info['player_uid']])->value('base64_nick_name');
|
||||
$info['player_nick_name'] = mb_convert_encoding(base64_decode($player_nickname), 'UTF-8', 'UTF-8');;
|
||||
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $info];
|
||||
}
|
||||
|
||||
//我的钱包 订单收入明细
|
||||
public function get_wallet_order($uid, $time, $page, $page_limit)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
switch ($time) {
|
||||
case '1': //日
|
||||
$times1 = strtotime(date('Y-m-d'));
|
||||
$times2 = strtotime(date('Y-m-d H:i:s'));
|
||||
$map[] = ['complete_time', 'between', [$times1, $times2]];
|
||||
break;
|
||||
case '2': //周
|
||||
$times1 = strtotime(date('Y-m-d H:i:s', strtotime('-7 day')));
|
||||
$times2 = strtotime(date('Y-m-d H:i:s'));
|
||||
$map[] = ['complete_time', 'between', [$times1, $times2]];
|
||||
break;
|
||||
case '3': //月
|
||||
$times1 = strtotime(date('Y-m-d H:i:s', strtotime('-30 day')));
|
||||
$times2 = strtotime(date('Y-m-d H:i:s'));
|
||||
$map[] = ['complete_time', 'between', [$times1, $times2]];
|
||||
break;
|
||||
case '0': //全部
|
||||
break;
|
||||
}
|
||||
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map[] = ['player_uid', '=', $uid];
|
||||
$map[] = ['status', '=', 3];
|
||||
$map[] = ['is_over', '=', 1];
|
||||
$list = db::name('user_player_order')->field('oid,gid,total_amount,status,complete_time')->where($map)->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$game_info = model('game')->get_game_info($v['gid']);
|
||||
$v['game_name'] = $game_info['data']['game_name'];
|
||||
$v['game_ico'] = $game_info['data']['game_ico'];
|
||||
$v['complete_time'] = date('Y-m-d H:i', $v['complete_time']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => "获取成功", 'data' => $list];
|
||||
}
|
||||
|
||||
//陪玩接单
|
||||
public function take_player_order($uid, $oid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['oid', '=', $oid];
|
||||
$map[] = ['player_uid', '=', $uid];
|
||||
$info = db::name('user_player_order')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 200, 'msg' => "订单不存在", 'data' => null];
|
||||
}
|
||||
if ($info['status'] != 1) {
|
||||
return ['code' => 200, 'msg' => "该订单状态无法操作", 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['oid'] = $oid;
|
||||
$data['receive_time'] = time();
|
||||
$data['status'] = 2;
|
||||
$reslut = db::name('user_player_order')->update($data, ['oid' => $oid]);
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => "接单失败", 'data' => null];
|
||||
}
|
||||
|
||||
$content = "您的陪玩订单已接单";
|
||||
$data = [];
|
||||
$data['code'] = 1002;
|
||||
$data['data'] = ['oid' => $oid,'play_order_identity_type'=>2];
|
||||
model('admin/Jpush')->push_notification_message($info['uid'], '陪玩订单提醒', $content, $data);
|
||||
|
||||
$reslut=model('api/UserMessage')->send_message($info['uid'], 2, $oid, "陪玩订单提醒", $content);
|
||||
if ($reslut['code']!=200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "处理失败", 'data' => null];
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => "接单成功", 'data' => null];
|
||||
}
|
||||
//下单人确认陪玩订单
|
||||
public function confirm_palyer_order($uid, $oid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['oid', '=', $oid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$info = db::name('user_player_order')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => "订单不存在", 'data' => null];
|
||||
}
|
||||
if ($info['status'] != 2) {
|
||||
return ['code' => 201, 'msg' => "该订单状态无法操作", 'data' => null];
|
||||
}
|
||||
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$exchange_rate = $config['exchange_rate']; //平台虚拟币兑换比例
|
||||
$player_order_platform_commission = $config['player_order_platform_commission']; //陪玩平台抽佣
|
||||
Db::startTrans();
|
||||
try {
|
||||
$change_money = $info['total_amount'] / $exchange_rate * (1 - $player_order_platform_commission);
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($info['player_uid'], $change_money, 1, 5, "陪玩订单完成:" . $info['order_sn'], $info['uid'], $info['oid']);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['oid'] = $oid;
|
||||
$data['complete_time'] = time();
|
||||
$data['status'] = 3;
|
||||
$data['is_over'] = 1;
|
||||
$reslut = db::name('user_player_order')->update($data, ['oid' => $oid]);
|
||||
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
//更新陪玩用户表数据
|
||||
$reslut = db::name('user')->where('uid', $uid)->inc('palyer_order_count', 1)->update($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
$content = "您的陪玩订单已确认完成";
|
||||
$data = [];
|
||||
$data['code'] = 1002;
|
||||
$data['data'] = ['oid' => $oid,'play_order_identity_type'=>1];
|
||||
model('admin/Jpush')->push_notification_message($info['player_uid'], '陪玩订单提醒', $content, $data);
|
||||
|
||||
$reslut=model('api/UserMessage')->send_message($info['player_uid'], 2, $oid, "陪玩订单提醒", $content);
|
||||
if ($reslut['code']!=200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "处理失败", 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "确认成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//下单人取消陪玩订单
|
||||
public function cancel_order($uid, $oid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['oid', '=', $oid];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$info = db::name('user_player_order')->where($map)->find();
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => "订单不存在", 'data' => null];
|
||||
}
|
||||
if ($info['status'] != 1) {
|
||||
return ['code' => 201, 'msg' => "该订单状态无法操作", 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$update = db::name('user_player_order')->where($map)->update(['status' => 3, 'is_over' => 3, 'complete_time' => time(), 'update_time' => time()]);
|
||||
if (!$update) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, $info['total_amount'], 2, 10, "陪玩取消订单退款:" . $info['order_sn'], $uid, $info['oid']);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$content = "您的陪玩订单已被取消";
|
||||
$data = [];
|
||||
$data['code'] = 1002;
|
||||
$data['data'] = ['oid' => $oid,'play_order_identity_type'=>1];
|
||||
model('admin/Jpush')->push_notification_message($info['player_uid'], '陪玩订单提醒', $content, $data);
|
||||
|
||||
$reslut=model('api/UserMessage')->send_message($info['player_uid'], 2, $oid, "陪玩订单提醒", $content);
|
||||
if ($reslut['code']!=200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "处理失败", 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "取消成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
private function create_play_order_sn()
|
||||
{
|
||||
$order_sn = 'PW' . date('YmdHis') . mt_rand(10000, 99999);
|
||||
$map = [];
|
||||
$map[] = ['order_sn', '=', $order_sn];
|
||||
$reslut = db::name('user_player_order')->where($map)->find();
|
||||
if (empty($reslut)) {
|
||||
return $order_sn;
|
||||
} else {
|
||||
$this->create_play_order_sn();
|
||||
}
|
||||
}
|
||||
}
|
||||
833
application/api/model/UserRecharge.php
Normal file
833
application/api/model/UserRecharge.php
Normal file
@@ -0,0 +1,833 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use think\facade\Env;
|
||||
|
||||
class UserRecharge extends Model
|
||||
{
|
||||
|
||||
//用户充值
|
||||
public function create_pay_order($uid, $crid, $pay_type, $custom_amount)
|
||||
{
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
}
|
||||
if($user_info['is_real'] != 1){
|
||||
return ['code' => 201, 'msg' => '请先实名认证', 'data' => null];
|
||||
}
|
||||
$pay_money = 0;
|
||||
$give_integral = 0;
|
||||
|
||||
if (!in_array($pay_type, [1, 2, 21])) {
|
||||
return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//2:原生微信支付
|
||||
if($pay_type==2){
|
||||
$app_ys_wx_recharge = get_system_config('app_ys_wx_recharge');
|
||||
if($app_ys_wx_recharge != 1){
|
||||
return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//20:支付宝原生支付开关
|
||||
|
||||
if($pay_type==1){
|
||||
$app_ys_zfb_recharge = get_system_config('app_ys_zfb_recharge');
|
||||
if($app_ys_zfb_recharge != 1){
|
||||
return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ($pay_type == 21) {
|
||||
$zfbh5_huifu_recharge = get_system_config('zfbh5_huifu_recharge');
|
||||
if($zfbh5_huifu_recharge != 1){
|
||||
return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!empty($crid)) {
|
||||
$map = [];
|
||||
$map[] = ['crid', '=', $crid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$can_recharge_info = Db::name('can_recharge')->where($map)->find();
|
||||
if (empty($can_recharge_info)) {
|
||||
return ['code' => 201, 'msg' => '充值金额不存在', 'data' => null];
|
||||
}
|
||||
if ($can_recharge_info['money'] <= 0) {
|
||||
return ['code' => 201, 'msg' => '充值金额参数非法', 'data' => null];
|
||||
}
|
||||
$pay_money = $can_recharge_info['money'];
|
||||
$give_integral = $can_recharge_info['integral'];
|
||||
} else {
|
||||
if (intval($custom_amount) != $custom_amount) {
|
||||
return ['code' => 201, 'msg' => '充值金额必须为整数', 'data' => null];
|
||||
}
|
||||
if ($custom_amount < 1) {
|
||||
return ['code' => 201, 'msg' => '充值金额最少1元', 'data' => null];
|
||||
}
|
||||
$exchange_rate = get_system_config('exchange_rate');
|
||||
$pay_money = $custom_amount;
|
||||
$give_integral = $custom_amount * $exchange_rate;
|
||||
}
|
||||
|
||||
|
||||
$order_sn = $this->create_recharge_order_sn(1);
|
||||
// $pay_money = 0.01;
|
||||
$data = [];
|
||||
$data['order_sn'] = $order_sn;
|
||||
$data['order_type'] = 1;
|
||||
$data['money'] = $pay_money;
|
||||
$data['integral'] = $give_integral;
|
||||
$data['pay_type'] = $pay_type;
|
||||
$data['uid'] = $uid;
|
||||
$data['pay_status'] = 1;
|
||||
$data['pay_time'] = 0;
|
||||
$data['remarke'] = '';
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$data['carry_money'] = $pay_money;
|
||||
$data['is_carray_finish'] = 2;
|
||||
$status = Db::name('user_recharge')->insert($data);
|
||||
$data = [];
|
||||
if ($status) {
|
||||
|
||||
if ($pay_type == 1) {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 922);
|
||||
$data = $this->alipayHand($order_sn, $pay_money);
|
||||
} elseif($pay_type == 21){
|
||||
// $data = model('api/AdaPay')->create_order($order_sn, $pay_money, $uid);
|
||||
// if($data['code'] != 200){
|
||||
// return ['code' => 201, 'msg' => '支付失败', 'data' => null];
|
||||
// }
|
||||
// $result = $data['result'];
|
||||
// if(isset($result['status']) && ($result['status'] == "succeeded")){
|
||||
// $payment_id = $result['id'];
|
||||
// $map = [];
|
||||
// $map[] = ['order_sn', '=', $order_sn];
|
||||
// $order_info = Db::name('user_recharge')->where($map)->update(['payment_id'=>$payment_id]);
|
||||
// }
|
||||
|
||||
$data = model('HuiFu1')->ali_h5($order_sn, $pay_money);
|
||||
if(!empty($data['data']['qr_code'])){
|
||||
return ['code' => 200, 'msg' => '请求成功', 'data' => ['pay_info'=>'alipays://platformapi/startapp?saId=10000007&qrcode='.$data['data']['qr_code']]];
|
||||
// return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '支付失败', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 921);
|
||||
$data = $this->wxpayHand($order_sn, $pay_money);
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']];
|
||||
}
|
||||
|
||||
|
||||
//购买会员
|
||||
public function pay_vip_order($uid, $vid, $pay_type)
|
||||
{
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
}
|
||||
$pay_money = 0;
|
||||
$give_integral = 0;
|
||||
|
||||
if (!in_array($pay_type, [1, 2])) {
|
||||
return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null];
|
||||
}
|
||||
|
||||
if(!empty($vid)){
|
||||
$map = [];
|
||||
$map[] = ['vid', '=', $vid];
|
||||
$vip_info = db::name('vip')->where($map)->find();
|
||||
if(empty($vip_info)){
|
||||
return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null];
|
||||
}
|
||||
if ($vip_info['price'] <= 0) {
|
||||
return ['code' => 201, 'msg' => '会员卡购买金额参数非法', 'data' => null];
|
||||
}
|
||||
$pay_money = $vip_info['price'];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$order_sn = $this->create_recharge_order_sn(2);
|
||||
// $pay_money = 0.01;
|
||||
$data = [];
|
||||
$data['order_sn'] = $order_sn;
|
||||
$data['order_type'] = 2;
|
||||
$data['vid'] = $vid;
|
||||
$data['money'] = $pay_money;
|
||||
$data['integral'] = $give_integral;
|
||||
$data['pay_type'] = $pay_type;
|
||||
$data['uid'] = $uid;
|
||||
$data['pay_status'] = 1;
|
||||
$data['pay_time'] = 0;
|
||||
$data['remarke'] = '';
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$status = Db::name('user_recharge')->insert($data);
|
||||
$data = [];
|
||||
if ($status) {
|
||||
|
||||
if ($pay_type == 1) {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 922);
|
||||
$data = $this->alipayHand($order_sn, $pay_money);
|
||||
} else {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 921);
|
||||
$data = $this->wxpayHand($order_sn, $pay_money);
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']];
|
||||
}
|
||||
|
||||
//更换邀请人
|
||||
public function update_user_inviter($uid, $user_id, $sms_code, $pay_type)
|
||||
{
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info['user_name'] == $uid){
|
||||
return ['code' => 201, 'msg' => '该用户尚未绑定手机号', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = model('sms')->verification_code($user_info['user_name'], $sms_code);
|
||||
if ($reslut['code'] == 201) {
|
||||
return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
$pay_money = 0;
|
||||
$give_integral = 0;
|
||||
|
||||
$inviter_info = db::name('user')->where('uid', $user_id)->find();
|
||||
if(!$inviter_info){
|
||||
return ['code' => 201, 'msg' => '更换邀请人不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($inviter_info['vid'])){
|
||||
return ['code' => 201, 'msg' => '更换邀请人不是会员', 'data' => null];
|
||||
}
|
||||
|
||||
if($inviter_info['vip_end_time'] - time() < (60*60*24*30)){
|
||||
return ['code' => 201, 'msg' => '更换邀请人会员少于30天', 'data' => null];
|
||||
}
|
||||
|
||||
if (!in_array($pay_type, [1, 2])) {
|
||||
return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($config['update_inviter_price']) && $config['update_inviter_price'] < 0){
|
||||
return ['code' => 201, 'msg' => '换绑支付金额不能为空且不能小于0', 'data' => null];
|
||||
}
|
||||
|
||||
$pay_money = $config['update_inviter_price'];
|
||||
|
||||
|
||||
$order_sn = $this->create_recharge_order_sn(3);
|
||||
// $pay_money = 0.01;
|
||||
$data = [];
|
||||
$data['order_sn'] = $order_sn;
|
||||
$data['order_type'] = 3;
|
||||
$data['invite_uid'] = $user_id;
|
||||
$data['money'] = $pay_money;
|
||||
$data['integral'] = $give_integral;
|
||||
$data['pay_type'] = $pay_type;
|
||||
$data['uid'] = $uid;
|
||||
$data['pay_status'] = 1;
|
||||
$data['pay_time'] = 0;
|
||||
$data['remarke'] = '';
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$status = Db::name('user_recharge')->insert($data);
|
||||
$data = [];
|
||||
if ($status) {
|
||||
|
||||
if ($pay_type == 1) {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 922);
|
||||
$data = $this->alipayHand($order_sn, $pay_money);
|
||||
} else {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 921);
|
||||
$data = $this->wxpayHand($order_sn, $pay_money);
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']];
|
||||
}
|
||||
|
||||
public function threePayFromPost( $pay_orderid='', $pay_amount=0, $pay_bankcode='921'){
|
||||
$pay_memberid = "210879796"; //商户后台API管理获取
|
||||
//$pay_orderid = 'E'.date("YmdHis").rand(100000,999999); //订单号
|
||||
//$pay_amount = 10; //交易金额
|
||||
$pay_applydate = date("Y-m-d H:i:s"); //订单时间
|
||||
$pay_notifyurl = "http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/three_pay_notify"; //服务端返回地址
|
||||
$pay_callbackurl = "http://" . $_SERVER['HTTP_HOST']; //页面跳转返回地址
|
||||
$Md5key = "lsn75mdcbhuy0h913blni0wxycpcq2dk"; //商户后台API管理获取
|
||||
$tjurl = "https://guohongpay.com//Pay_Index.html"; //提交地址
|
||||
//$pay_bankcode = "921"; //922 支付宝 921 微信 //商户后台通道费率页 获取银行编码
|
||||
$native = array(
|
||||
"pay_memberid" => $pay_memberid,
|
||||
"pay_orderid" => $pay_orderid,
|
||||
"pay_amount" => $pay_amount,
|
||||
"pay_applydate" => $pay_applydate,
|
||||
"pay_bankcode" => $pay_bankcode,
|
||||
"pay_notifyurl" => $pay_notifyurl,
|
||||
"pay_callbackurl" => $pay_callbackurl,
|
||||
);
|
||||
ksort($native);
|
||||
$md5str = "";
|
||||
foreach ($native as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
|
||||
//echo($md5str . "key=" . $Md5key);
|
||||
$sign = strtoupper(md5($md5str . "key=" . $Md5key));
|
||||
$native["pay_md5sign"] = $sign;
|
||||
$native['pay_attach'] = "1234|456";
|
||||
$native['pay_productname'] ='团购商品';
|
||||
|
||||
$html='<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body><form class="form-inline" method="post" id="myForm" action="'.$tjurl.'" style="display:none">';
|
||||
|
||||
foreach ($native as $key => $val) {
|
||||
$html.='<input type="hidden" name="'.$key.'" value="'.$val.'">';
|
||||
}
|
||||
|
||||
$html.='</form><script>window.onload = function(){document.getElementById("myForm").submit();}</script></body>
|
||||
</html>';
|
||||
//<script>window.onload = function(){document.getElementById("myForm").submit();}</script>
|
||||
echo $html;
|
||||
|
||||
}
|
||||
|
||||
//支付宝异步回调
|
||||
public function three_pay_notify($data)
|
||||
{
|
||||
$returnArray = array( // 返回字段
|
||||
"memberid" => $data["memberid"], // 商户ID
|
||||
"orderid" => $data["orderid"], // 订单号
|
||||
"amount" => $data["amount"], // 交易金额
|
||||
"datetime" => $data["datetime"], // 交易时间
|
||||
"transaction_id" => $data["transaction_id"], // 支付流水号
|
||||
"returncode" => $data["returncode"],
|
||||
);
|
||||
$md5key = "lsn75mdcbhuy0h913blni0wxycpcq2dk";
|
||||
ksort($returnArray);
|
||||
reset($returnArray);
|
||||
$md5str = "";
|
||||
foreach ($returnArray as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
$sign = strtoupper(md5($md5str . "key=" . $md5key));
|
||||
if ($sign == $data["sign"]) {
|
||||
if ($data["returncode"] == "00") {
|
||||
$order_sn = $data['orderid'];
|
||||
$pay_amount = $data['amount'];
|
||||
$data = $this->pay_notify_success($order_sn, $pay_amount);
|
||||
if ($data['code'] == 200) {
|
||||
exit('OK');
|
||||
} else {
|
||||
exit('FAIL');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function payh5alipay($order_sn='', $money='', $title='订单支付'){
|
||||
require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/AopClient.php';
|
||||
require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/request/AlipayTradeWapPayRequest.php';
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$prv=$config['merchant_private_key'];
|
||||
$pov=$config['alipay_public_key'];
|
||||
//vendor('alipay.aop.AopSdk.AopClient');
|
||||
//include_once ROOT_PATH . '/extend/alipay/aop/AopClient.php';
|
||||
$aop = new \AopClient();
|
||||
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
|
||||
$aop->appId = $config['ali_appid'];
|
||||
$aop->rsaPrivateKey = $prv;
|
||||
$aop->format = "json";
|
||||
$aop->charset = "UTF-8";
|
||||
$aop->signType = "RSA2";
|
||||
$aop->alipayrsaPublicKey = $pov;
|
||||
$aop->apiVersion = '1.0';
|
||||
|
||||
|
||||
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
|
||||
$request = new \AlipayTradeWapPayRequest();
|
||||
|
||||
// 异步通知地址
|
||||
$notify_url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/api/pay_notify/ali_pay_notify';
|
||||
//error_log(json_encode($notify_url), 3, 'pn.log');
|
||||
$quit_url= $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/';
|
||||
// 订单标题
|
||||
$subject = $title;
|
||||
// 订单详情
|
||||
$body = $title;
|
||||
// 订单号,示例代码使用时间值作为唯一的订单ID号
|
||||
$out_trade_no = $order_sn;
|
||||
|
||||
$total = floatval($money);
|
||||
|
||||
//SDK已经封装掉了公共参数,这里只需要传入业务参数
|
||||
$bizcontent = "{\"body\":\"".$body."\","
|
||||
. "\"subject\": \"".$subject."\","
|
||||
. "\"quit_url\": \"".$quit_url."\","
|
||||
. "\"out_trade_no\": \"".$out_trade_no."\","
|
||||
. "\"timeout_express\": \"600m\","
|
||||
. "\"total_amount\": \"".$total."\","
|
||||
. "\"product_code\":\"QUICK_WAP_WAY\""
|
||||
. "}";
|
||||
$request->setNotifyUrl($notify_url);
|
||||
$request->setBizContent($bizcontent);
|
||||
|
||||
//这里和普通的接口调用不同,使用的是sdkExecute
|
||||
$response = $aop->pageExecute($request);
|
||||
// $data = '<div style=display:none>'.$response.'</div>';
|
||||
// return ['code' => 200, 'msg' => '成功', 'data' => $data];
|
||||
// 注意:这里不需要使用htmlspecialchars进行转义,直接返回即可
|
||||
echo '<div style=display:none>'.$response.'</div>';
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
//支付宝支付
|
||||
private function alipayHand($order_sn, $pay_amount)
|
||||
{
|
||||
require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/AopClient.php';
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$aop = new \AopClient();
|
||||
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
|
||||
$aop->appId = $config['ali_appid'];
|
||||
$aop->alipayrsaPublicKey = $config['alipay_public_key'];
|
||||
$aop->rsaPrivateKey = $config['merchant_private_key'];
|
||||
$aop->format = "json";
|
||||
$aop->charset = "UTF-8";
|
||||
$aop->signType = "RSA2";
|
||||
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
|
||||
require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/request/AlipayTradeAppPayRequest.php';
|
||||
///app/Packages/alipay/aop/request
|
||||
$request = new \AlipayTradeAppPayRequest();
|
||||
//SDK已经封装掉了公共参数,这里只需要传入业务参数
|
||||
$arr['body'] = "购买商品";
|
||||
$arr['subject'] = "购买商品";
|
||||
$arr['out_trade_no'] = $order_sn;
|
||||
$arr['timeout_express'] = "30m";
|
||||
$arr['total_amount'] = $pay_amount;
|
||||
$arr['product_code'] = "QUICK_MSECURITY_PAY";
|
||||
|
||||
$bizcontent = json_encode($arr, JSON_UNESCAPED_UNICODE);
|
||||
// $request->setNotifyUrl("http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/ali_pay_notify");
|
||||
$request->setNotifyUrl("http://119.45.115.72:621/api/pay_notify/ali_pay_notify");
|
||||
$request->setBizContent($bizcontent);
|
||||
//这里和普通的接口调用不同,使用的是sdkExecute
|
||||
$response = $aop->sdkExecute($request);
|
||||
return ['code' => 201, 'msg' => '', 'data' => $response];
|
||||
}
|
||||
|
||||
|
||||
//微信支付
|
||||
private function wxpayHand($order_sn, $pay_amount)
|
||||
{
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
require_once Env::get('root_path') . 'extend/wxPay/WxPay.php';
|
||||
$WxPay = new \WxPay($config['wx_appid'], $config['wx_mch_id'], $config['wx_key']);
|
||||
$params['body'] = '购买商品'; //商品描述
|
||||
$params['out_trade_no'] = $order_sn; //自定义的订单号
|
||||
$params['total_fee'] = $pay_amount * 100; //订单金额 只能为整数 单位为分
|
||||
$params['trade_type'] = 'APP'; //交易类型 JSAPI | NATIVE | APP | WAP
|
||||
$params['attach'] = '123'; //附加参数
|
||||
// $params['notify_url'] = "http://" . $_SERVER['HTTP_HOST'] . "/api/pay_notify/wx_pay_notify";
|
||||
$params['notify_url'] = "http://119.45.115.72:621/api/pay_notify/wx_pay_notify";
|
||||
$result = $WxPay->unifiedOrder($params);
|
||||
// dump($result);die;
|
||||
if ($result['prepay_id']) {
|
||||
$data = $WxPay->getOrder($result['prepay_id']);
|
||||
return ['code' => 200, 'msg' => '请求成功', 'data' => $data];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '请求失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
//支付宝回调
|
||||
public function wxPayNotify($xmlData)
|
||||
{
|
||||
require_once Env::get('root_path') . 'extend/wxPay/WxPay.php';
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$WxPay = new \WxPay($config['wx_appid'], $config['wx_mch_id'], $config['wx_key']);
|
||||
//接收微信返回的数据数据,返回的xml格式
|
||||
// $xmlData = file_get_contents('php://input');
|
||||
$data = $WxPay->xml_to_data($xmlData);
|
||||
$sign = $data['sign'];
|
||||
unset($data['sign']);
|
||||
if ($sign == $WxPay->MakeSign($data)) {
|
||||
//签名验证成功后,判断返回微信返回的
|
||||
if ($data['result_code'] == 'SUCCESS') {
|
||||
//处理交易完成或者支付成功的通知
|
||||
$order_sn = $data['out_trade_no'];
|
||||
$pay_amount = $data['total_fee'] * 0.01;
|
||||
$data = $this->pay_notify_success($order_sn, $pay_amount);
|
||||
if ($data['code'] == 200) {
|
||||
exit('SUCCESS');
|
||||
} else {
|
||||
exit('FAIL');
|
||||
}
|
||||
} else {
|
||||
exit('FAIL');
|
||||
}
|
||||
} else {
|
||||
|
||||
exit('FAIL');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//支付宝异步回调
|
||||
public function ali_pay_notify($data)
|
||||
{
|
||||
require_once Env::get('root_path') . 'extend/alipay-sdk-PHP-4.9.2/aop/AopClient.php';
|
||||
$aop = new \AopClient();
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$aop->alipayrsaPublicKey = $config['alipay_public_key'];
|
||||
if ($data['app_id'] == $config['ali_appid'] && $data['sign_type'] == 'RSA2') {
|
||||
//处理业务,并从$_POST中提取需要的参数内容
|
||||
if ($data['trade_status'] == 'TRADE_SUCCESS') {
|
||||
//处理交易完成或者支付成功的通知
|
||||
$order_sn = $data['out_trade_no'];
|
||||
$pay_amount = $data['total_amount'];
|
||||
$data = $this->pay_notify_success($order_sn, $pay_amount);
|
||||
if ($data['code'] == 200) {
|
||||
exit('SUCCESS');
|
||||
} else {
|
||||
exit('FAIL');
|
||||
}
|
||||
} else {
|
||||
exit('FAIL');
|
||||
}
|
||||
} else {
|
||||
exit('FAIL');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//支付回调验证成功
|
||||
public function pay_notify_success($order_sn, $pay_amount)
|
||||
{
|
||||
$redis = connectionRedis();
|
||||
$key_name = "api:user_recharge:pay_notify_success:order_sn".$order_sn;
|
||||
$redis_order_sn = redis_lock_exits($key_name,1,5);
|
||||
if($redis_order_sn){
|
||||
$map = [];
|
||||
$map[] = ['order_sn', '=', $order_sn];
|
||||
$order_info = Db::name('user_recharge')->where($map)->find();
|
||||
if (empty($order_info)) {
|
||||
return ['code' => 201, 'msg' => '订单不存在', 'data' => null];
|
||||
}
|
||||
if ($order_info['pay_status'] != 1) {
|
||||
return ['code' => 201, 'msg' => '订单已支付', 'data' => null];
|
||||
}
|
||||
if (bcmul($order_info['money'], 100, 2) != bcmul($pay_amount, 100, 2)) {
|
||||
return ['code' => 201, 'msg' => '充值金额异常', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
//更改订单状态
|
||||
$data = [];
|
||||
$data['pay_status'] = 2;
|
||||
$data['pay_time'] = time();
|
||||
Db::name('user_recharge')->where('rid', $order_info['rid'])->update($data);
|
||||
if($order_info['order_type'] == 1){
|
||||
//增加用户余额及充值记录
|
||||
$result = model('admin/User')->change_user_money_by_uid($order_info['uid'], $order_info['integral'], 2, 9, "用户充值:" . $order_info['order_sn'], $order_info['uid'], $order_info['rid']);
|
||||
if($result['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '充值金额异常', 'data' => null];
|
||||
}
|
||||
//会员邀请收益
|
||||
model('api/Vip')->vip_invite_earnings($order_info['uid'], $order_info['money'], $order_info['integral']);
|
||||
}elseif($order_info['order_type'] == 4) {
|
||||
$result = model('admin/User')->change_user_money_by_uid($order_info['uid'], $order_info['integral'], 2, 44, "用户购买爵位:" . $order_info['order_sn'], $order_info['uid'], $order_info['rid']);
|
||||
if($result['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '充值金额异常', 'data' => null];
|
||||
}
|
||||
$type_params = json_decode($order_info['type_params'], true);
|
||||
$result = model('api/Nobility')->user_pay_nobility_value($order_info['uid'], $type_params);
|
||||
if($result['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '充值金额异常', 'data' => null];
|
||||
}
|
||||
}
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败5", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => 'success', 'data' => null];
|
||||
}
|
||||
|
||||
//生成充值唯一单号
|
||||
// private function create_recharge_order_sn()
|
||||
// {
|
||||
// $order_sn = 'CZ' . date('YmdHis') . mt_rand(10000, 99999);
|
||||
// $map = [];
|
||||
// $map[] = ['order_sn', '=', $order_sn];
|
||||
// $reslut = db::name('user_recharge')->where($map)->find();
|
||||
// if (empty($reslut)) {
|
||||
// return $order_sn;
|
||||
// } else {
|
||||
// $this->create_recharge_order_sn();
|
||||
// }
|
||||
// }
|
||||
private function create_recharge_order_sn($type)
|
||||
{
|
||||
if($type == 1){
|
||||
$order_type = 'CZ';
|
||||
}else if($type == 2){
|
||||
$order_type = 'HY';
|
||||
}elseif($type == 4){
|
||||
$order_type = 'JW';
|
||||
}else {
|
||||
$order_type = 'JC';
|
||||
}
|
||||
$order_sn = $order_type . date('YmdHis') . mt_rand(10000, 99999);
|
||||
$map = [];
|
||||
$map[] = ['order_sn', '=', $order_sn];
|
||||
$reslut = db::name('user_recharge')->where($map)->find();
|
||||
if (empty($reslut)) {
|
||||
return $order_sn;
|
||||
} else {
|
||||
return $this->create_recharge_order_sn($type);
|
||||
}
|
||||
}
|
||||
|
||||
//购买会员
|
||||
public function pay_nobility_order($uid, $lid, $pay_type)
|
||||
{
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
}
|
||||
$pay_money = 0;
|
||||
$give_integral = 0;
|
||||
|
||||
if (!in_array($pay_type, [1, 2, 21])) {
|
||||
return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null];
|
||||
}
|
||||
|
||||
// if ($pay_type == 21) {
|
||||
// return ['code' => 201, 'msg' => '系统维护中', 'data' => null];
|
||||
// }
|
||||
|
||||
|
||||
|
||||
if($pay_type==2){
|
||||
$app_ys_wx_recharge = get_system_config('app_ys_wx_recharge');
|
||||
if($app_ys_wx_recharge != 1){
|
||||
return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($pay_type==1){
|
||||
$app_ys_zfb_recharge = get_system_config('app_ys_zfb_recharge');
|
||||
if($app_ys_zfb_recharge != 1){
|
||||
return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($pay_type == 21) {
|
||||
$zfbh5_huifu_recharge = get_system_config('zfbh5_huifu_recharge');
|
||||
if($zfbh5_huifu_recharge != 1){
|
||||
return ['code' => 201, 'msg' => '系统维护中,马上回来!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$type_params = [];
|
||||
if(!empty($lid)){
|
||||
if($user_info['nobility_id'] > $lid) {
|
||||
return ['code' => 201, 'msg' => '不能购买低等级会员', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['lid', '=', $lid];
|
||||
$nobility_info = db::name('nobility')->where($map)->find();
|
||||
if(empty($nobility_info)){
|
||||
return ['code' => 201, 'msg' => '购买爵位等级不存在', 'data' => null];
|
||||
}
|
||||
if($user_info['nobility_id'] == $lid) {
|
||||
$pay_money = $nobility_info['renew_price'];
|
||||
$give_integral = $nobility_info['renew_coin'];
|
||||
$is_renew = 1;
|
||||
} else {
|
||||
$pay_money = $nobility_info['pay_price'];
|
||||
$give_integral = $nobility_info['pay_coin'];
|
||||
$is_renew = 2;
|
||||
}
|
||||
$type_params['pay_money'] = $pay_money;
|
||||
$type_params['pay_coin'] = $give_integral;
|
||||
$type_params['day_num'] = $nobility_info['day_num'];
|
||||
$type_params['is_renew'] = $is_renew;
|
||||
$type_params['lid'] = $lid;
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$order_sn = $this->create_recharge_order_sn(4);
|
||||
// $pay_money = 0.01;
|
||||
$data = [];
|
||||
$data['order_sn'] = $order_sn;
|
||||
$data['order_type'] = 4;
|
||||
$data['money'] = $pay_money;
|
||||
$data['integral'] = $give_integral;
|
||||
$data['pay_type'] = $pay_type;
|
||||
$data['uid'] = $uid;
|
||||
$data['pay_status'] = 1;
|
||||
$data['pay_time'] = 0;
|
||||
$data['remarke'] = '';
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$data['type_params'] = json_encode($type_params);
|
||||
$data['type_id'] = $lid;
|
||||
$data['carry_money'] = $pay_money;
|
||||
$data['is_carray_finish'] = 2;
|
||||
|
||||
$status = Db::name('user_recharge')->insert($data);
|
||||
$data = [];
|
||||
if ($status) {
|
||||
// return $this->pay_notify_success($order_sn, $pay_money);
|
||||
if ($pay_type == 1) {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 922);
|
||||
$data = $this->alipayHand($order_sn, $pay_money);
|
||||
} elseif($pay_type == 21){
|
||||
// $data = model('api/AdaPay')->create_order($order_sn, $pay_money, $uid);
|
||||
// if($data['code'] != 200){
|
||||
// return ['code' => 201, 'msg' => '支付失败', 'data' => null];
|
||||
// }
|
||||
|
||||
// $result = $data['result'];
|
||||
// if(isset($result['status']) && ($result['status'] == "succeeded")){
|
||||
// $payment_id = $result['id'];
|
||||
// $map = [];
|
||||
// $map[] = ['order_sn', '=', $order_sn];
|
||||
// $order_info = Db::name('user_recharge')->where($map)->update(['payment_id'=>$payment_id]);
|
||||
// }
|
||||
|
||||
$data = model('HuiFu1')->ali_h5($order_sn, $pay_money);
|
||||
if(!empty($data['data']['qr_code'])){
|
||||
return ['code' => 200, 'msg' => '请求成功', 'data' => ['pay_info'=>'alipays://platformapi/startapp?saId=10000007&qrcode='.$data['data']['qr_code']]];
|
||||
// return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '支付失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// $data = $this->threePayFromPost($order_sn, $pay_money, 921);
|
||||
$data = $this->wxpayHand($order_sn, $pay_money);
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => '请求成功', 'data' => $data['data']];
|
||||
}
|
||||
|
||||
public function ada_ali_pay_notify($data, $sign)
|
||||
{
|
||||
// $data_str = json_encode($data,JSON_UNESCAPED_UNICODE);
|
||||
// $data = array (
|
||||
// 'created_time' => '1721980908',
|
||||
// 'data' => '{"app_id":"app_260e8610-8ee2-498a-8fec-66fa866bb072","business_mode":"00","created_time":"20240726160148","description":"description","end_time":"20240726160351","expend":{"buyer_logon_id":"187****3623","cashPayAmt":"0.10","sub_open_id":"2088812171930646"},"fee_amt":"0.00","id":"002212024072616014810662820123835744256","order_no":"1721980920","out_trans_id":"2024072622001430641404087500","party_order_id":"02212407265770824408339","pay_amt":"0.10","pay_channel":"alipay","real_amt":"0.10","share_eq":"Y","status":"succeeded","trans_response_add_info":"{\\"fund_bill_list\\":[{\\"amount\\":\\"0.10\\",\\"fund_channel\\":\\"ALIPAYACCOUNT\\"}]}"}',
|
||||
// 'prod_mode' => 'true',
|
||||
// 'sign' => 'rvOfQUFTJf72dhYqQjplF9p7+jMvGYFfThJ/miFwOT2ATYc9h8Mexr8wh2ED2eetVTAeo7NLgpa+z3j0wgL8uLvC3DCUYTegZ5039nag58DVIXVEtpPrke16vlfDk7psA9xbau4BbXRVrTl9POrnhQqd+cq87hnsvj3wxd+c7o8=',
|
||||
// 'id' => '002210662820643004702720',
|
||||
// 'type' => 'payment.succeeded',
|
||||
// 'app_id' => 'app_260e8610-8ee2-498a-8fec-66fa866bb072',
|
||||
// 'object' => 'payment',
|
||||
// );
|
||||
|
||||
$post_data = $data;
|
||||
$data_str = json_encode($data,JSON_UNESCAPED_UNICODE);
|
||||
$result = model('api/AdaPay')->verify_sign($data_str, $sign);
|
||||
if($result['code'] != 200) {
|
||||
exit('FAIL');
|
||||
}
|
||||
if($post_data['status'] == 'succeeded') {
|
||||
$order_sn = $post_data['order_no'];
|
||||
$pay_amount = $post_data['pay_amt'];
|
||||
$data = $this->pay_notify_success($order_sn, $pay_amount);
|
||||
if ($data['code'] == 200) {
|
||||
exit('SUCCESS');
|
||||
} else {
|
||||
exit('FAIL');
|
||||
}
|
||||
}
|
||||
exit('FAIL');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function hui_fu_pay_notify($data)
|
||||
{
|
||||
|
||||
if($data['resp_code'] == '00000000') {
|
||||
$resp_data = $data['resp_data'];
|
||||
$resp_data_arr = json_decode($resp_data, true);
|
||||
$huifu_id = $resp_data_arr['huifu_id'];
|
||||
$sign = $data['sign'];
|
||||
$verify_sign = model('HuiFu1')->wx_verify_sign($resp_data, $sign, $huifu_id);
|
||||
if(!$verify_sign) {
|
||||
return '';
|
||||
}
|
||||
if($resp_data_arr['resp_code'] == '00000000' && $resp_data_arr['trans_stat'] == 'S') {
|
||||
$pay_amount = bcmul($resp_data_arr['trans_amt'], 1, 2);
|
||||
$order_sn = $resp_data_arr['mer_ord_id'];
|
||||
$result = $this->pay_notify_success($order_sn, $pay_amount);
|
||||
if($result['code'] == 200) {
|
||||
exit("RECV_ORD_ID_" . $resp_data_arr['out_trans_id']) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
234
application/api/model/UserRelation.php
Normal file
234
application/api/model/UserRelation.php
Normal file
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class UserRelation extends Model
|
||||
{
|
||||
//提交申请用户关系
|
||||
public function apply_user_relation($uid, $recived_uid, $type)
|
||||
{
|
||||
|
||||
if ($uid == $recived_uid) {
|
||||
return ['code' => 201, 'msg' => '不能对自己发起申请', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['recived_uid', '=', $recived_uid];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['status', '=', 1];
|
||||
$user_relation_apply_info = db::name('user_relation_apply')->where($map)->find();
|
||||
if (!empty($user_relation_apply_info)) {
|
||||
return ['code' => 201, 'msg' => '您已发送申请', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['recived_uid', '=', $recived_uid];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation_info = db::name('user_relation')->where($map)->find();
|
||||
if (!empty($user_relation_info)) {
|
||||
return ['code' => 200, 'msg' => '你们已经存在当前关系', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $recived_uid];
|
||||
$recived_user_info = Db::name('user')->where($map)->find();
|
||||
if (empty($recived_user_info)) {
|
||||
return ['code' => 201, 'msg' => '用户信息不存在', 'data' => null];
|
||||
}
|
||||
$recived_user_info['nick_name'] = mb_convert_encoding(base64_decode($recived_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['recived_uid'] = $recived_uid;
|
||||
$data['type'] = $type;
|
||||
$data['status'] = 1;
|
||||
$validate = validate('admin/UserRelationApply');
|
||||
$reslut = $validate->scene('apiAdd')->check($data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
}
|
||||
$model = model('admin/UserRelationApply');
|
||||
$reslut = $model->save($data);
|
||||
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '发送失败', 'data' => null];
|
||||
} else {
|
||||
//通知被邀请人
|
||||
$data = [];
|
||||
$data['code'] = 1000;
|
||||
$data['data'] = ['aid' => $model->aid];
|
||||
|
||||
model('admin/Jpush')->push_notification_message($recived_uid, '消息提醒', "有人邀请您建立关系,快来看看吧", $data);
|
||||
|
||||
$type_desc = model('admin/UserRelation')->get_relation_type_lable($type);
|
||||
$content = $recived_user_info['nick_name'] . "申请与你建立" . $type_desc . "关系";
|
||||
model('api/user_message')->send_message($recived_uid, 3, $model->aid, "我的关系", $content);
|
||||
return ['code' => 200, 'msg' => '已发送申请', 'data' => null];
|
||||
}
|
||||
}
|
||||
//获取用户关系
|
||||
public function get_apply_user_relation_info($uid, $aid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['aid', '=', $aid];
|
||||
$map[] = ['uid|recived_uid', '=', $uid];
|
||||
$user_relation_info = db::name('user_relation_apply')->where($map)->find();
|
||||
if (empty($user_relation_info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', [$user_relation_info['uid'], $user_relation_info['recived_uid']]];
|
||||
$user_data = db::name('user')->where($map)->column('*', 'uid');
|
||||
$user_relation_info['user_info']['uid'] = $user_data[$user_relation_info['uid']]['uid'];
|
||||
$user_relation_info['user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_data[$user_relation_info['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_relation_info['user_info']['head_pic'] = localpath_to_netpath($user_data[$user_relation_info['uid']]['head_pic']);
|
||||
$user_relation_info['reciveduser_info']['uid'] = $user_data[$user_relation_info['uid']]['uid'];
|
||||
$user_relation_info['reciveduser_info']['nick_name'] = mb_convert_encoding(base64_decode($user_data[$user_relation_info['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$user_relation_info['reciveduser_info']['head_pic'] = localpath_to_netpath($user_data[$user_relation_info['uid']]['head_pic']);
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_relation_info];
|
||||
}
|
||||
//申请关系处理
|
||||
public function deal_user_relation_apply($uid, $aid, $status)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['aid', '=', $aid];
|
||||
$user_relation_apply_info = db::name('user_relation_apply')->where($map)->find();
|
||||
if (empty($user_relation_apply_info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
if ($user_relation_apply_info['recived_uid'] != $uid) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
if ($user_relation_apply_info['status'] != 1) {
|
||||
return ['code' => 201, 'msg' => '该申请已处理', 'data' => null];
|
||||
}
|
||||
$update_data = [];
|
||||
$update_data['aid'] = $aid;
|
||||
$update_data['status'] = $status;
|
||||
$validate = validate('admin/UserRelationApply');
|
||||
$reslut = $validate->scene('apiEdit')->check($update_data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
}
|
||||
|
||||
if ($user_relation_apply_info['type'] == 2) {
|
||||
//判断是否存在
|
||||
$map = [];
|
||||
$map[] = ['uid|recived_uid', '=', $uid];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation_info = db::name('user_relation')->where($map)->find();
|
||||
if (!empty($user_relation_info)) {
|
||||
return ['code' => 200, 'msg' => '同时只能与一人建立情缘', 'data' => null];
|
||||
}
|
||||
} elseif ($user_relation_apply_info['type'] == 3) {
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['type', '=', 2];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation_info = db::name('user_relation')->where($map)->find();
|
||||
if (!empty($user_relation_info)) {
|
||||
|
||||
return ['code' => 200, 'msg' => '同时只能与一人拜师', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$user_info = db::name('user')->where('uid', $user_relation_apply_info['uid'])->find();
|
||||
$user_info['nick_name'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$type_desc = model('admin/UserRelation')->get_relation_type_lable($user_relation_apply_info['type']);
|
||||
if ($status == 2) {
|
||||
//添加关系
|
||||
$data = [];
|
||||
$data['type'] = $user_relation_apply_info['type'];
|
||||
$data['uid'] = $user_relation_apply_info['uid'];
|
||||
$data['recived_uid'] = $user_relation_apply_info['recived_uid'];
|
||||
model('admin/UserRelation')->save($data);
|
||||
|
||||
$content = $user_info['nick_name'] . "对方已与你建立{$type_desc}关系";
|
||||
$data = [];
|
||||
$data['code'] = 1000;
|
||||
$data['data'] = ['aid' => $user_relation_apply_info['aid']];
|
||||
model('admin/Jpush')->push_notification_message($user_relation_apply_info['uid'], '消息提醒', $content, $data);
|
||||
model('api/user_message')->send_message($user_relation_apply_info['uid'], 3, $user_relation_apply_info['aid'], "我的关系", $content);
|
||||
} elseif ($status == 3) {
|
||||
$content = $user_info['nick_name'] . "已拒绝与你建立{$type_desc}关系";
|
||||
$data = [];
|
||||
$data['code'] = 1000;
|
||||
$data['data'] = ['aid' => $user_relation_apply_info['aid']];
|
||||
model('admin/Jpush')->push_notification_message($user_relation_apply_info['recived_uid'], '消息提醒', $content, $data);
|
||||
model('api/user_message')->send_message($user_relation_apply_info['uid'], 3, $user_relation_apply_info['aid'], "我的关系", $content);
|
||||
}
|
||||
$reslut = model('admin/UserRelationApply')->isUpdate(true)->save($update_data);
|
||||
//修改申请状态
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '关系建立失败', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 200, 'msg' => '关系建立成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
//删除用户关系
|
||||
public function delete_user_relation($uid, $rid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid|recived_uid', '=', $uid];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation_info = db::name('user_relation')->where($map)->find();
|
||||
if (empty($user_relation_info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
if ($user_relation_info['uid'] != $uid && $user_relation_info['recived_uid'] != $uid) {
|
||||
return ['code' => 201, 'msg' => '无权限操作', 'data' => null];
|
||||
}
|
||||
$reslut = db::name('user_relation')->where('rid', $rid)->delete();
|
||||
if (!$reslut) {
|
||||
return ['code' => 201, 'msg' => '解除失败', 'data' => null];
|
||||
} else {
|
||||
|
||||
// $data = [];
|
||||
// $data['code'] = 1003;
|
||||
// $data['data'] = ['rid' => $user_relation_info['rid']];
|
||||
// if ($uid == $user_relation_info['uid']) {
|
||||
// model('admin/Jpush')->push_notification_message($user_relation_info['recived_uid'], '消息提醒', "已与你解除情缘关系", $data);
|
||||
// } else {
|
||||
// model('admin/Jpush')->push_notification_message($user_relation_info['uid'], '消息提醒', "已与你解除情缘关系", $data);
|
||||
// }
|
||||
|
||||
return ['code' => 200, 'msg' => '解除成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
//获取用户关系列表
|
||||
public function get_user_relation_list($uid, $type, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['uid|recived_uid', '=', $uid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$user_relation_list = db::name('user_relation')->where($map)->page($page, $page_limit)->select();
|
||||
if (empty($user_relation_list)) {
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_relation_list];
|
||||
}
|
||||
$uid_list = array_merge(array_column($user_relation_list, 'uid'), array_column($user_relation_list, 'recived_uid'));
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', $uid_list];
|
||||
$user_data = db::name('user')->where($map)->column('*', 'uid');
|
||||
foreach ($user_relation_list as $k => &$v) {
|
||||
$v['user_info']['uid'] = $user_data[$v['uid']]['uid'];
|
||||
$v['user_info']['nick_name'] = mb_convert_encoding(base64_decode($user_data[$v['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['user_info']['head_pic'] = localpath_to_netpath($user_data[$v['uid']]['head_pic']);
|
||||
$v['reciveduser_info']['uid'] = $user_data[$v['uid']]['uid'];
|
||||
$v['reciveduser_info']['nick_name'] = mb_convert_encoding(base64_decode($user_data[$v['uid']]['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['reciveduser_info']['head_pic'] = localpath_to_netpath($user_data[$v['uid']]['head_pic']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $user_relation_list];
|
||||
}
|
||||
}
|
||||
47
application/api/model/UserReport.php
Normal file
47
application/api/model/UserReport.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserReport extends Model
|
||||
{
|
||||
public function user_report($uid, $to_uid, $type_id, $image, $content)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $type_id];
|
||||
$report_type_info = db::name('report_type')->where($map)->find();
|
||||
if (empty($report_type_info)) {
|
||||
return ['code' => 201, 'msg' => '房间类型异常', 'data' => null];
|
||||
}
|
||||
$user_info = db::name('user')->find($to_uid);
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '举报用户不存在', 'data' => null];
|
||||
}
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['to_uid'] = $to_uid;
|
||||
$data['type_id'] = $type_id;
|
||||
$data['image'] = $image;
|
||||
$data['content'] = $content;
|
||||
$data['status'] = 1;
|
||||
$data['deal_time'] = 0;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_report')->insert($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '提交成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '提交失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
public function report_list(){
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$reslut = db::name('report_type')->field('id,type_name')->where($map)->select();
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $reslut];
|
||||
}
|
||||
|
||||
}
|
||||
203
application/api/model/UserSign.php
Normal file
203
application/api/model/UserSign.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserSign extends Model
|
||||
{
|
||||
//用户签到
|
||||
// public function user_sign($uid)
|
||||
// {
|
||||
// $today = strtotime(date('Y-m-d'));
|
||||
// $map = [];
|
||||
// $map[] = ['add_time', '>', $today];
|
||||
// $map[] = ['uid', '=', $uid];
|
||||
// $info = db::name('user_sign')->where($map)->find();
|
||||
// if (!empty($info)) {
|
||||
// return ['code' => 201, 'msg' => '今日已签到', 'data' => null];
|
||||
// }
|
||||
|
||||
// Db::startTrans();
|
||||
// try {
|
||||
// //写入记录
|
||||
// $sign_reward_gid = get_system_config('sign_reward_gid');
|
||||
|
||||
// $data = [];
|
||||
// $data['uid'] = $uid;
|
||||
// $data['gid'] = $sign_reward_gid;
|
||||
// $data['add_time'] = time();
|
||||
// $reslut = db::name('user_sign')->insert($data);
|
||||
// if (!$reslut) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
// }
|
||||
// //放入背包
|
||||
// $reslut = model('UserGiftPack')->change_user_gift_pack($uid, $sign_reward_gid, 1, 1, '每日签到获得');
|
||||
// if ($reslut['code'] != 200) {
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
// } else {
|
||||
// Db::commit();
|
||||
// return ['code' => 200, 'msg' => '签到成功', 'data' => null];
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// // 回滚事务
|
||||
// Db::rollback();
|
||||
// return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//用户签到
|
||||
public function user_day_sign($uid){
|
||||
$sign_status = get_system_config('sign_status');
|
||||
if($sign_status != 1){
|
||||
return ['code' => 201, 'msg' => '签到维护中!', 'data' => null];
|
||||
}
|
||||
|
||||
$today = date('Y-m-d');
|
||||
$map = [];
|
||||
$map[] = ['sign_date', '>=', $today];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_delete','=',1];
|
||||
$info = db::name('user_sign_every_day')->where($map)->find();
|
||||
if (!empty($info)) {
|
||||
return ['code' => 201, 'msg' => '今日已签到', 'data' => null];
|
||||
}
|
||||
//查询今天是第几天签到
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_delete','=',1];
|
||||
$sign_day_num = db::name('user_sign_every_day')->where($map)->count('sid');
|
||||
if($sign_day_num > 6){
|
||||
return ['code' => 201, 'msg' => '签到异常,请联系客户!', 'data' => null];
|
||||
}
|
||||
//发放7日奖励
|
||||
if($sign_day_num + 1 == 7){
|
||||
//写入记录
|
||||
$sign_reward = get_system_config('sign_reward7');
|
||||
$desc = "签到连续7日奖励";
|
||||
}else{
|
||||
$sign_reward = get_system_config('sign_reward');
|
||||
$desc = "签到奖励";
|
||||
}
|
||||
|
||||
if($sign_reward <= 0){
|
||||
return ['code' => 201, 'msg' => '签到奖励异常', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
Db::startTrans();
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['sign_award'] = $sign_reward;
|
||||
$data['sign_date'] = $today;
|
||||
$data['add_time'] = time();
|
||||
$data['is_delete'] = 1;
|
||||
$reslut = db::name('user_sign_every_day')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, $sign_reward, 2, 62, $desc, $uid, 0, 0);
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '奖励领取失败!', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '签到成功!', 'data' => ['award'=>$sign_reward]];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function user_day_sign_log($uid){
|
||||
|
||||
$today = date('Y-m-d');
|
||||
$map = [];
|
||||
$map[] = ['sign_date', '>=', $today];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_delete','=',1];
|
||||
$today_sign = db::name('user_sign_every_day')->where($map)->find();
|
||||
if(!empty($today_sign)){
|
||||
$today_sign = 1;
|
||||
}else{
|
||||
$today_sign = 2;
|
||||
}
|
||||
|
||||
|
||||
$sign_reward7 = get_system_config('sign_reward7');
|
||||
$sign_reward = get_system_config('sign_reward');
|
||||
$today = date('Y-m-d');
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['is_delete','=',1];
|
||||
$info_num = db::name('user_sign_every_day')->where($map)->count('sid');
|
||||
$sign_log = [];
|
||||
for($i=1;$i<=7;$i++){
|
||||
if($i <= $info_num){
|
||||
$sign_log[] = ['is_sign'=>1,'award'=>($i==7)?$sign_reward7:$sign_reward];
|
||||
}else{
|
||||
$sign_log[] = ['is_sign'=>2,'award'=>($i==7)?$sign_reward7:$sign_reward];
|
||||
}
|
||||
}
|
||||
return ['code' => 200, 'msg' => 'success', 'data' => ['sign_log'=>$sign_log,'sign_num'=>$info_num,'today_sign'=>$today_sign]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function del_user_day_sign_log(){
|
||||
$today = date('Y-m-d');
|
||||
// //签到超过7天的删除
|
||||
$uid2_sign = db::name('user_sign_every_day')->field("uid,count('sid') as sign_num")->where(['is_delete'=>1])->group('uid')->having("sign_num >= 7")->select();
|
||||
if(!empty($uid2_sign)){
|
||||
$uid2_sign = array_column($uid2_sign,'uid');
|
||||
db::name('user_sign_every_day')
|
||||
->where(['is_delete'=>1])
|
||||
->where('uid','in',$uid2_sign)
|
||||
->update(['is_delete'=>2,'update_time'=>time()]);
|
||||
}
|
||||
|
||||
|
||||
//今日未签到的删除
|
||||
$uid1_sign = db::name('user_sign_every_day')->where(['is_delete'=>1,'sign_date'=>$today])->column('uid');
|
||||
db::name('user_sign_every_day')
|
||||
->where(['is_delete'=>1])
|
||||
->where("uid",'not in',$uid1_sign)
|
||||
->update(['is_delete'=>2,'update_time'=>time()]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
120
application/api/model/UserSignContract.php
Normal file
120
application/api/model/UserSignContract.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserSignContract extends Model
|
||||
{
|
||||
|
||||
//签约是否结束
|
||||
public function close_user_sign_contract(){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
$config = get_uncache_system_config();
|
||||
$now_time = time();
|
||||
|
||||
$map = [];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$list = db::name('user_sign_contract')->where($map)->select();
|
||||
foreach ($list as $k => $v){
|
||||
$user_info = db::name('user')->field('base64_nick_name')->find($v['uid']);
|
||||
$sign_user_info = db::name('user')->field('base64_nick_name')->find($v['sign_uid']);
|
||||
$nick_name = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$sign_nick_name = mb_convert_encoding(base64_decode($sign_user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
|
||||
//是否到了提醒一次
|
||||
$first_message_time = $v['end_time'] - (60*60*24*2);
|
||||
if($now_time > $first_message_time && $v['send_message_num'] == 0){
|
||||
//续约通知
|
||||
$title = '签约到期通知';
|
||||
$content = '您与艺人'.$sign_nick_name.'的签约即将到期,请及时续约!';
|
||||
model('api/UserMessage')->send_message($v['uid'], 1, $v['id'], $title, $content);
|
||||
$content_1 = '您与制作人'.$nick_name.'的签约即将到期!';
|
||||
model('api/UserMessage')->send_message($v['sign_uid'], 1, $v['id'], $title, $content);
|
||||
|
||||
//记录提醒次数
|
||||
db::name('user_sign_contract')->where('id', $v['id'])->update(['send_message_num' => 1, 'update_time' => $now_time]);
|
||||
|
||||
}
|
||||
|
||||
//是否到了提醒二次
|
||||
$second_message_time = $v['end_time'] - (60*60*24);
|
||||
if($now_time > $second_message_time && $v['send_message_num'] == 1){
|
||||
//续约通知
|
||||
$title = '签约到期通知';
|
||||
$content = '您与艺人'.$sign_nick_name.'的签约即将到期,请及时续约!';
|
||||
model('api/UserMessage')->send_message($v['uid'], 1, $v['id'], $title, $content);
|
||||
$content_1 = '您与制作人'.$nick_name.'的签约即将到期!';
|
||||
model('api/UserMessage')->send_message($v['sign_uid'], 1, $v['id'], $title, $content);
|
||||
|
||||
//记录提醒次数
|
||||
db::name('user_sign_contract')->where('id', $v['id'])->update(['send_message_num' => 2, 'update_time' => $now_time]);
|
||||
}
|
||||
|
||||
//是否解约
|
||||
if($now_time > $v['end_time']){
|
||||
//解约通知
|
||||
$title = '解约通知';
|
||||
$content = '您与艺人'.$sign_nick_name.'的签约已经到期,尚未续约,已进行解约!';
|
||||
model('api/UserMessage')->send_message($v['uid'], 1, $v['id'], $title, $content);
|
||||
$content_1 = '您与制作人'.$nick_name.'的签约已经到期,尚未续约,已进行解约!';
|
||||
model('api/UserMessage')->send_message($v['sign_uid'], 1, $v['id'], $title, $content);
|
||||
|
||||
//记录提醒次数
|
||||
db::name('user_sign_contract')->where('id', $v['id'])->update(['is_delete' => 2, 'update_time' => $now_time]);
|
||||
}
|
||||
|
||||
}
|
||||
echo date('Y-m-d H:i:s').'签约定时任务执行成功';
|
||||
}
|
||||
|
||||
//解约用户每天降低身价
|
||||
public function relieve_user_sign_contract(){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
//身价大于70金币的
|
||||
$map = [];
|
||||
$map[] = ['social', '>', 70];
|
||||
$user_list = db::name('user')->where($map)->select();
|
||||
if(!empty($user_list)){
|
||||
foreach ($user_list as $k => &$v){
|
||||
//当前是否未签约
|
||||
$user_sign_contract = db::name('user_sign_contract')->where('sign_uid', $v['uid'])->where('is_delete', 1)->find();
|
||||
if(empty($user_sign_contract)){
|
||||
//没有签约的扣除百分之二十身价
|
||||
$surplus_social = (int)($v['social'] * 0.8);
|
||||
if($surplus_social < 70){
|
||||
$surplus_social = 70;
|
||||
}
|
||||
|
||||
$reslut = db::name('user')->where('uid', $v['uid'])->update(['social' => $surplus_social, 'update_time' => time()]);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
$insert = [];
|
||||
$insert['uid'] = $v['uid'];
|
||||
$insert['last_social'] = $v['social'];
|
||||
$insert['now_social'] = $surplus_social;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_relieve_social_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').'解约用户每天降低身价执行成功';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
455
application/api/model/UserTencent.php
Normal file
455
application/api/model/UserTencent.php
Normal file
@@ -0,0 +1,455 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use think\facade\Log;
|
||||
class UserTencent extends Model
|
||||
{
|
||||
//获取黑名单
|
||||
public function get_blacklist_list($uid, $rid, $page = 1, $page_limit = 20){
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 999 ? $page_limit : 999;
|
||||
|
||||
$data = [];
|
||||
$data['room_black_list'] = [];
|
||||
$data['room_visitor_list'] = [];
|
||||
$type = 1;
|
||||
if(!empty($rid)){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(empty($room_info)){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
$type = 2;
|
||||
$uid = $room_info['room_owner_uid'];
|
||||
}
|
||||
|
||||
//黑名单列表
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
if($type == 1){
|
||||
$map[] = ['a.uid', '=', $uid];
|
||||
$user_black_list = db::name('user_black')->where('uid', $uid)->column('receive_uid');
|
||||
}else{
|
||||
$map[] = ['a.rid', '=', $rid];
|
||||
$user_black_list = db::name('user_black')->where('rid', $rid)->column('receive_uid');
|
||||
}
|
||||
$user_black = db::name('user_black')->alias('a')->join('yy_user b', 'a.receive_uid = b.uid')->field('a.receive_uid as uid, b.nick_name, b.special_uid, b.base64_nick_name,b.head_pic,b.sex')->where($map)->select();
|
||||
foreach ($user_black as $k => &$v) {
|
||||
// $user_nobility_level_info = model('User')->get_user_nobility_level_info($v['uid']);
|
||||
// if($user_nobility_level_info['code'] == 200){
|
||||
// $v['user_level_info'] = $user_nobility_level_info['data'];
|
||||
// }
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$data['room_black_list'][] = $v;
|
||||
}
|
||||
|
||||
|
||||
//房间在线人数
|
||||
if(!empty($rid)){
|
||||
$map = [];
|
||||
$map[] = ['rid', '=', $rid];
|
||||
$user_id_list = db::name('room_visitor')->where($map)->column('uid');
|
||||
if (!empty($user_id_list)) {
|
||||
$map = [];
|
||||
$map[] = ['uid', 'in', $user_id_list];
|
||||
$map[] = ['uid', 'not in', $user_black_list];
|
||||
$user_list = db::name('user')->field('uid,base64_nick_name,head_pic,sex,special_uid')->where($map)->page($page, $page_limit)->select();
|
||||
foreach ($user_list as $k => &$v) {
|
||||
// $user_nobility_level_info = model('User')->get_user_nobility_level_info($v['uid']);
|
||||
// if($user_nobility_level_info['code'] == 200){
|
||||
// $v['user_level_info'] = $user_nobility_level_info['data'];
|
||||
// }
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$data['room_visitor_list'][] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//添加腾讯IM黑名单
|
||||
public function add_blacklist($uid, $rid, $user_id){
|
||||
$type = 1;
|
||||
if(!empty($rid)){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(empty($room_info)){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
$room_admin_array = explode(',', $room_info['room_admin_uid']);
|
||||
if($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_array)){
|
||||
return ['code' => 201, 'msg' => '无权限拉黑', 'data' => null];
|
||||
}
|
||||
$type = 2;
|
||||
if($user_id == $room_info['room_owner_uid']){
|
||||
return ['code' => 201, 'msg' => '不能拉黑房主', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_id == $room_info['room_host_uid']){
|
||||
return ['code' => 201, 'msg' => '不能拉黑主持', 'data' => null];
|
||||
}
|
||||
|
||||
// $uid = $room_info['room_owner_uid'];
|
||||
}
|
||||
|
||||
if($uid == $user_id){
|
||||
return ['code' => 201, 'msg' => '拉黑用户不能为自己', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
if($type == 1){
|
||||
$map[] = ['uid', '=', $uid];
|
||||
}else{
|
||||
$map[] = ['rid', '=', $rid];
|
||||
}
|
||||
$map[] = ['receive_uid', '=', $user_id];
|
||||
$user_black_info = db::name('user_black')->where($map)->find();
|
||||
if($user_black_info){
|
||||
return ['code' => 201, 'msg' => '该用户已被加入黑名单', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
//添加到黑名单
|
||||
$insert = [];
|
||||
$insert['type'] = $type;
|
||||
if($type == 1){
|
||||
$insert['uid'] = $uid;
|
||||
}else{
|
||||
$insert['rid'] = $rid;
|
||||
}
|
||||
$insert['receive_uid'] = $user_id;
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_black')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
||||
}
|
||||
|
||||
if($type == 1){
|
||||
//添加腾讯IM
|
||||
$user_id = explode(',',$user_id);
|
||||
$uid = strval($uid);
|
||||
$reslut = model('Tencent')->black_list_add($uid,$user_id);
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '添加失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//删除腾讯IM黑名单
|
||||
public function remove_blacklist($uid, $rid, $user_id){
|
||||
$type = 1;
|
||||
if(!empty($rid)){
|
||||
$room_info = db::name('room')->find($rid);
|
||||
if(empty($room_info)){
|
||||
return ['code' => 201, 'msg' => '该房间不存在', 'data' => null];
|
||||
}
|
||||
$room_admin_array = explode(',', $room_info['room_admin_uid']);
|
||||
if($uid != $room_info['room_owner_uid'] && !in_array($uid, $room_admin_array)){
|
||||
return ['code' => 201, 'msg' => '无权限拉黑', 'data' => null];
|
||||
}
|
||||
$type = 2;
|
||||
// $uid = $room_info['room_owner_uid'];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
if($type == 1){
|
||||
$map[] = ['uid', '=', $uid];
|
||||
}else{
|
||||
$map[] = ['rid', '=', $rid];
|
||||
}
|
||||
$map[] = ['receive_uid', '=', $user_id];
|
||||
$user_black_info = db::name('user_black')->where($map)->find();
|
||||
if(!$user_black_info){
|
||||
return ['code' => 201, 'msg' => '该用户没有被加入黑名单', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//删除腾讯IM黑名单
|
||||
$reslut = db::name('user_black')->where('id', $user_black_info['id'])->delete();
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '移除失败', 'data' => null];
|
||||
}
|
||||
|
||||
if($type == 1){
|
||||
$user_id = explode(',',$user_id);
|
||||
$uid = strval($uid);
|
||||
$reslut = model('Tencent')->black_list_delete($uid,$user_id);
|
||||
if($reslut['code'] != 200){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => '移除成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '移除失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//腾讯IM回调
|
||||
public function tencent_call_back($data,$sign_data){
|
||||
//回调鉴权
|
||||
// $token = '2k1j90av9rtl2ozbnbqxzyrtuj4a4oy5';
|
||||
// $sign = sha256($token.$sign_data['RequestTime']);
|
||||
// // $datas = json_encode($data);
|
||||
// // error_log($datas, 3, '1.txt');
|
||||
// // $sign_datas = json_encode($sign_data);
|
||||
// if($sign != $sign_data['Sign']){
|
||||
// return ['ActionStatus' => 'FAIL', 'ErrorInfo' => '', 'ErrorCode' => 1];
|
||||
// }
|
||||
// dump($data);exit;
|
||||
//加入群聊
|
||||
if($data['CallbackCommand'] == 'Group.CallbackAfterNewMemberJoin'){
|
||||
$rid = $data['GroupId'];
|
||||
$member_list = $data['NewMemberList'];
|
||||
$reslut = $this->tencent_group_join_call_back($rid, $member_list[0]['Member_Account']);
|
||||
}
|
||||
|
||||
//退出群聊
|
||||
if($data['CallbackCommand'] == 'Group.CallbackAfterMemberExit'){
|
||||
|
||||
|
||||
|
||||
$rid = $data['GroupId'];
|
||||
$member_list = $data['ExitMemberList'];
|
||||
$reslut = $this->tencent_group_quit_call_back($rid, $member_list[0]['Member_Account']);
|
||||
}
|
||||
|
||||
//在线状态更新
|
||||
if($data['CallbackCommand'] == 'State.StateChange'){
|
||||
$info = $data['Info'];
|
||||
$reslut = $this->tencent_member_status_change($info);
|
||||
}
|
||||
|
||||
if(isset($data['CallbackCommand']) && ($data['CallbackCommand'] == 'C2C.CallbackBeforeSendMsg')) {
|
||||
|
||||
$from_uid = $data['From_Account'];
|
||||
$to_uid = $data['To_Account'];
|
||||
if($data['MsgBody'][0]['MsgType'] == 'TIMCustomElem') {
|
||||
$send_data = $data['MsgBody'][0]['MsgContent']['Data'];
|
||||
$white_data = ['700001', '700002','700003','700004','700005','700006','700007','700008','700009'];
|
||||
// if(in_array($send_data, $white_data)) {
|
||||
return ['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0];
|
||||
// }
|
||||
}
|
||||
|
||||
//是否有权限私聊
|
||||
$reslut = $this->user_tencent_message_logs($from_uid);
|
||||
if($reslut['code'] == 201){
|
||||
return ['ActionStatus' => 'OK', 'ErrorInfo' => $reslut['msg'], 'ErrorCode' => 120001];
|
||||
}
|
||||
return ['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//群聊消息发送前的回调
|
||||
if(isset($data['CallbackCommand']) && ($data['CallbackCommand'] == 'Group.CallbackBeforeSendMsg')) {
|
||||
// $send_message_type = $data['MsgBody'][0]['MsgType'];
|
||||
// $rid = $data['GroupId'];
|
||||
// $from_uid = $data['From_Account'];
|
||||
// Log::write($data,'chat');
|
||||
|
||||
|
||||
// //普通群组监控
|
||||
// if($send_message_type == 'TIMCustomElem'){
|
||||
// //是否有权限私聊
|
||||
// $reslut = $this->user_tencent_message_logs($from_uid);
|
||||
// if($reslut['code'] == 201){
|
||||
// return ['ActionStatus' => 'OK', 'ErrorInfo' => $reslut['msg'], 'ErrorCode' => 120001];
|
||||
// }
|
||||
// }
|
||||
|
||||
return ['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return ['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0];
|
||||
}
|
||||
|
||||
//腾讯IM监控加入群聊
|
||||
public function tencent_group_join_call_back($rid, $uid){
|
||||
//进入房间
|
||||
$in_room = db::name('room_visitor')->where(['uid' => $uid, 'rid' => $rid])->find();
|
||||
$rid_strlen = strlen($rid);
|
||||
if(empty($in_room) && $rid_strlen < 7) {
|
||||
$insert_vistor_room_data = [
|
||||
'uid' => $uid,
|
||||
'rid' => $rid,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
db::name('room_visitor')->insert($insert_vistor_room_data);
|
||||
}else{
|
||||
db::name('room_visitor')->where('vid', $in_room['vid'])->update(['is_delete' => 1, 'end_time' => 0, 'update_time' => time()]);
|
||||
}
|
||||
//该用户是否在该房间麦上
|
||||
$room_micro = db::name('room_micro')->where('rid',$rid)->where('uid', $uid)->find();
|
||||
if(!empty($room_micro)){
|
||||
db::name('room_micro')->where('id', $room_micro['id'])->update(['is_online' => 1, 'update_time' => time()]);
|
||||
}
|
||||
$count = Db::name('room_visitor')->where('rid', $rid)->count();
|
||||
|
||||
//获取房间机器人数
|
||||
$robot_num = Db::name('room')->where('rid',$rid)->value('robot_num');
|
||||
$count = $robot_num + $count;
|
||||
|
||||
$data = [
|
||||
'onilne_num' => $count,
|
||||
];
|
||||
$push_data = [];
|
||||
$push_data['code'] = 210;
|
||||
$push_data['msg'] = "用户进入房间";
|
||||
$push_data['data'] = $data;
|
||||
|
||||
$result = model('WebSocketPush')->send_to_group($rid, $push_data);
|
||||
|
||||
model('api/room')->is_visitor_room($uid,$rid);
|
||||
model('api/room')->push_room_micro_data($rid);
|
||||
}
|
||||
|
||||
//腾讯IM监控退出群聊
|
||||
public function tencent_group_quit_call_back($rid, $uid){
|
||||
model('api/room')->quit_room($uid, $rid);
|
||||
$count = Db::name('room_visitor')->where('rid', $rid)->count();
|
||||
|
||||
//获取房间机器人数
|
||||
$robot_num = Db::name('room')->where('rid',$rid)->value('robot_num');
|
||||
$count = $robot_num + $count;
|
||||
|
||||
$data = [
|
||||
'onilne_num' => $count,
|
||||
];
|
||||
$push_data = [];
|
||||
$push_data['code'] = 210;
|
||||
$push_data['msg'] = "用户退出房间";
|
||||
$push_data['data'] = $data;
|
||||
$result = model('WebSocketPush')->send_to_group($rid, $push_data);
|
||||
}
|
||||
|
||||
//腾讯IM监控在线状态更新
|
||||
public function tencent_member_status_change($info){
|
||||
$uid = $info['To_Account'];
|
||||
$action = $info['Action'];
|
||||
|
||||
if($action == 'Disconnect') {
|
||||
Db::name('user')->where('uid', $uid)->update(['is_online' => 2, 'update_time' => time()]);
|
||||
$quit_room = Db::name('room_visitor')->where('uid', $uid)->order('vid', 'asc')->select();
|
||||
|
||||
if($quit_room) {
|
||||
foreach ($quit_room as $k => $v){
|
||||
model('room')->quit_room($uid, $v['rid']);
|
||||
$count = Db::name('room_visitor')->where('rid', $v['rid'])->count();
|
||||
//获取房间机器人数
|
||||
$robot_num = Db::name('room')->where('rid',$v['rid'])->value('robot_num');
|
||||
$count = $robot_num + $count;
|
||||
|
||||
|
||||
$data = [
|
||||
'onilne_num' => $count,
|
||||
];
|
||||
$push_data = [];
|
||||
$push_data['code'] = 210;
|
||||
$push_data['msg'] = "用户退出房间";
|
||||
$push_data['data'] = $data;
|
||||
$result = model('WebSocketPush')->send_to_group($v['rid'], $push_data);
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($action == 'Login') {
|
||||
|
||||
Db::name('user')->where('uid', $uid)->update(['is_online' => 1, 'update_time' => time()]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function user_tencent_message_logs($uid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
|
||||
if($user_info['login_status'] != 1) {
|
||||
return ['code' => 201, 'msg' => '已被封禁!', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
// 用户IP是否被封禁
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 3];
|
||||
$map[] = ['type_text', '=', $user_info['login_ip']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$block_ip = db::name('block')->where($map)->find();
|
||||
// dump($block_ip);
|
||||
if($block_ip){
|
||||
return ['code' => 201, 'msg' => '当前IP地址已被封禁。', 'data' => null];
|
||||
}
|
||||
|
||||
//用户设备号是否被封禁
|
||||
$map = [];
|
||||
$map[] = ['type', '=', 1];
|
||||
$map[] = ['type_text', '=', $user_info['last_login_device']];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$block_device = db::name('block')->where($map)->find();
|
||||
// dump($block_device);
|
||||
if($block_device){
|
||||
return ['code' => 201, 'msg' => '当前设备号已被封禁。', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info['is_real'] != 1) {
|
||||
return ['code' => 201, 'msg' => '未实名不能发送消息。', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
//查询总消费是否达标
|
||||
$pay_money = Db::name('user_recharge')->where(['uid'=>$uid,'pay_status'=>2])->sum('money');
|
||||
$chate_money = get_system_config('chate_money');
|
||||
if($pay_money < $chate_money){
|
||||
return ['code' => 201, 'msg' => "充值大于{$chate_money}元可私聊", 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
152
application/api/model/UserTopLine.php
Normal file
152
application/api/model/UserTopLine.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserTopLine extends Model
|
||||
{
|
||||
//获取最大头条输入金额
|
||||
public function get_top_line_integral($uid)
|
||||
{
|
||||
$key_title_arr = ['top_line_min_price', 'top_line_step_price', 'top_line_sustain_time','top_line_reset_price_time'];
|
||||
$config = Db::name('config')->where('key_title', 'in', $key_title_arr)->column('key_value', 'key_title');
|
||||
$map = [];
|
||||
$info = Db::name('user_top_line')->where($map)->order('add_time', 'desc')->find();
|
||||
$pay_integral = $config['top_line_min_price'];
|
||||
if(!empty($info)) {
|
||||
if($info['add_time'] + $config['top_line_reset_price_time'] > time()) {
|
||||
$pay_integral = $info['pay_integral'] + $config['top_line_step_price'];
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'pay_integral' => $pay_integral,
|
||||
'step_integral' => $config['top_line_step_price']
|
||||
];
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $data];
|
||||
}
|
||||
//发布头条
|
||||
public function publish_top_line($uid, $pay_integral, $content, $rid)
|
||||
{
|
||||
//维禁判断
|
||||
if(!empty($content)) {
|
||||
$result = model('Tencent')->content_moderation('Text', $content);
|
||||
if($result['code'] != 200) {
|
||||
return ['code' => 201, 'msg' => '内容存在违禁词!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
$user_info = Db::name('user')->field('uid,integral,contribution_level')->where('uid', $uid)->find();
|
||||
if(empty($user_info)) {
|
||||
return ['code' => 201, 'msg' => '用户信息不存在', 'data' => null];
|
||||
}
|
||||
if($pay_integral <= 0) {
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
if($user_info['integral'] < $pay_integral) {
|
||||
return ['code' => 201, 'msg' => '钻石不足', 'data' => null];
|
||||
}
|
||||
|
||||
//持续时间
|
||||
$key_title_arr = ['top_line_min_price', 'top_line_step_price', 'top_line_sustain_time','top_line_reset_price_time'];
|
||||
$config = Db::name('config')->where('key_title', 'in', $key_title_arr)->column('key_value', 'key_title');
|
||||
|
||||
$last_user_top_line_info = Db::name('user_top_line')->order('add_time', 'desc')->find();
|
||||
if($last_user_top_line_info) {
|
||||
if(($last_user_top_line_info['add_time'] + $config['top_line_reset_price_time']) >= time()) {
|
||||
if($pay_integral <= $last_user_top_line_info['pay_integral']) {
|
||||
return ['code' => 201, 'msg' => '抢头条金额不能小于上一次', 'data' => null];
|
||||
}
|
||||
} else {
|
||||
$pay_integral = $config['top_line_min_price'];
|
||||
}
|
||||
}
|
||||
$top_line_sustain_time = $config['top_line_sustain_time'];
|
||||
Db::startTrans();
|
||||
try {
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$pay_integral, 2, 52, "抢头条", $uid, 0);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
$data = [
|
||||
'uid' => $uid,
|
||||
'pay_integral' => $pay_integral,
|
||||
'base64_content' => base64_encode($content),
|
||||
'over_time' => time() + $top_line_sustain_time,
|
||||
'add_time' => time(),
|
||||
'update_time' => time(),
|
||||
'rid' => $rid
|
||||
];
|
||||
Db::name('user_top_line')->insert($data);
|
||||
|
||||
Db::commit();
|
||||
$list = $this->_get_user_top_line_list();
|
||||
$push_data = [];
|
||||
$push_data['code'] = 323;
|
||||
$push_data['msg'] = "抢头条";
|
||||
$push_data['data'] = $list;
|
||||
model('api/WebSocketPush')->send_to_all($push_data);
|
||||
return ['code' => 200, 'msg' => '开启成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
// 回滚事务
|
||||
dump($e);
|
||||
return ['code' => 201, 'msg' => '开启失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//获取表白墙列表
|
||||
public function get_user_top_line_list($page, $page_limit)
|
||||
{
|
||||
$list = $this->_get_user_top_line_list();
|
||||
return ['code' => 200, 'msg' => '获取数据成功', 'data' => $list];
|
||||
|
||||
}
|
||||
|
||||
private function _get_user_top_line_list()
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['a.over_time', '>=', time()];
|
||||
$info = Db::name('user_top_line')->alias('a')
|
||||
->join('user b', 'a.uid = b.uid', 'left')
|
||||
->where($map)
|
||||
->field('a.base64_content,a.uid,b.base64_nick_name,b.head_pic,b.sex,a.rid,a.pay_integral,a.over_time')
|
||||
->order('id', 'desc')->find();
|
||||
if(empty($info)) {
|
||||
$info['uid'] = 0;
|
||||
$info['content'] = '';
|
||||
$info['head_pic'] = '';
|
||||
$info['over_time'] = 0;
|
||||
$info['nick_name'] = '';
|
||||
$info['pay_integral'] = '';
|
||||
} else {
|
||||
$info['nick_name'] = mb_convert_encoding(base64_decode($info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$info['head_pic'] = localpath_to_netpath($info['head_pic']);
|
||||
$info['content'] = mb_convert_encoding(base64_decode($info['base64_content']), 'UTF-8', 'UTF-8');
|
||||
$info['over_time'] = $info['over_time'] - time();
|
||||
}
|
||||
// $level_list = Db::name('user_level')->field('image,type,level')->where(['is_delete' => 1])->select();
|
||||
// $charm_level_arr = [];
|
||||
// $contribution_level_arr = [];
|
||||
// foreach($level_list as $val) {
|
||||
// $image = localpath_to_netpath($val['image']);
|
||||
// $level = $val['level'];
|
||||
// $type = $val['type'];
|
||||
// if($type == 1) {
|
||||
// $charm_level_arr[$level] = $image;
|
||||
// }elseif($type == 2) {
|
||||
// $contribution_level_arr[$level] = $image;
|
||||
// }
|
||||
// }
|
||||
// foreach($list as &$val) {
|
||||
// $val['nick_name'] = mb_convert_encoding(base64_decode($val['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $val['head_pic'] = localpath_to_netpath($val['head_pic']);
|
||||
// $val['charm_level_image'] = $charm_level_arr[$val['charm_level']] ?? '';
|
||||
// $val['contribution_level_image'] = $contribution_level_arr[$val['contribution_level']] ?? '';
|
||||
// $val['content'] = mb_convert_encoding(base64_decode($val['base64_content']), 'UTF-8', 'UTF-8');
|
||||
// }
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
49
application/api/model/UserWallet.php
Normal file
49
application/api/model/UserWallet.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
|
||||
class UserWallet extends Model
|
||||
{
|
||||
public function create_data($uid)
|
||||
{
|
||||
$insert_data = ['uid' => $uid];
|
||||
return Db::name('user_wallet')->insert($insert_data);
|
||||
}
|
||||
|
||||
//获取用户钱包数据
|
||||
public function get_user_wallet($uid, $money, $integral)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$wallet_info = Db::name('user_wallet')->where('uid', $uid)->find();
|
||||
if($wallet_info) {
|
||||
if($wallet_info['user_integral'] != $integral) {
|
||||
return ['code' => 201, 'msg' =>'请联系客服!', 'data' => null];
|
||||
}
|
||||
if($wallet_info['user_money'] != $money) {
|
||||
return ['code' => 201, 'msg' =>'请联系客服!', 'data' => null];
|
||||
}
|
||||
return ['code' => 200, 'msg' =>'验证通过', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' =>'请联系客服!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public function tong_bu_user()
|
||||
// {
|
||||
// $user_list = Db::name('user')->field('uid,money,integral')->select();
|
||||
// foreach($user_list as $v) {
|
||||
// $info = Db::name('user_wallet')->where('uid', $v['uid'])->find();
|
||||
// if(empty($info)) {
|
||||
// $insert_data = ['uid' => $v['uid'], 'user_integral' => $v['integral'], 'user_money' => $v['money']];
|
||||
// Db::name('user_wallet')->insert($insert_data);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
493
application/api/model/UserZone.php
Normal file
493
application/api/model/UserZone.php
Normal file
@@ -0,0 +1,493 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class UserZone extends Model
|
||||
{
|
||||
//获取社区动态
|
||||
public function get_zone_list($uid, $is_recommend, $is_follow, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map = [];
|
||||
$map[] = ['a.show_status', '=', 2];
|
||||
$map[] = ['a.is_delete','=',1];
|
||||
if (!empty($is_recommend)) {
|
||||
$map[] = ['a.is_recommend', '=', $is_recommend];
|
||||
}
|
||||
|
||||
$order_string = 'a.zid desc'; //排序规则
|
||||
|
||||
$model = Db::name('UserZone')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$model = $model->where($map);
|
||||
if (!empty($is_follow)) {
|
||||
$model = $model->where("a.uid in (select follow_uid from yy_user_follow where uid = :uid)", ['uid' => $uid]);
|
||||
}
|
||||
$list = $model->field('a.zid,a.uid,a.images,a.sound,a.sound_duration,a.video,a.content,a.base64_content,a.praise_num,a.read_num,a.share_num,a.comment_num,a.is_recommend,a.add_time,b.base64_nick_name,b.sex,b.head_pic,a.show_status')->order($order_string)->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
|
||||
// if (!empty($v['images'])) {
|
||||
// $images_data = json_decode($v['images'], true);
|
||||
// $images_data = explode(',', $images_data);
|
||||
|
||||
// $images = [];
|
||||
// foreach ($images_data as $m => $n) {
|
||||
// $images[localpath_to_netpath($n)] = localpath_to_netpath($n);
|
||||
// }
|
||||
// $images = array_values($images);
|
||||
// $v['images'] = implode(',', $images);
|
||||
// } else {
|
||||
// $v['images'] = '';
|
||||
// }
|
||||
if(!empty($v['images'])){
|
||||
$images_data = explode(',', $v['images']);
|
||||
foreach ($images_data as $m => &$n) {
|
||||
$n = localpath_to_netpath($n);
|
||||
}
|
||||
$v['images']=$images_data;
|
||||
}else{
|
||||
$v['images']=[];
|
||||
}
|
||||
$v['content'] = mb_convert_encoding(base64_decode($v['base64_content']), 'UTF-8', 'UTF-8');
|
||||
$v['sound'] = localpath_to_netpath($v['sound']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['video'] = localpath_to_netpath($v['video']);
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['is_praise'] = 0; //是否点赞
|
||||
$praise = db::name('user_zone_praise')->where(['zid' => $v['zid'], 'uid' => $uid])->find();
|
||||
if (!empty($praise)) {
|
||||
$v['is_praise'] = 1;
|
||||
}
|
||||
$v['is_follow'] = 0; //是否关注
|
||||
$follow = db::name('user_follow')->where(['follow_uid' => $v['uid'], 'uid' => $uid])->find();
|
||||
if (!empty($follow)) {
|
||||
$v['is_follow'] = 1;
|
||||
}
|
||||
$v['is_collect'] = 1; //是否收藏
|
||||
$v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//获取社区动态
|
||||
public function get_user_zone_list($uid, $from_id, $is_recommend, $is_follow, $page, $page_limit)
|
||||
{
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
|
||||
$from_id_user = db::name('user')->where('uid',$from_id)->find();
|
||||
if(!$from_id_user){
|
||||
return ['code' => 201, 'msg' => '无该用户信息', 'data' => null];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.show_status', '=', 2];
|
||||
if (!empty($is_recommend)) {
|
||||
$map[] = ['a.is_recommend', '=', $is_recommend];
|
||||
}
|
||||
$map[] = ['a.uid', '=', $from_id];
|
||||
$order_string = 'a.zid desc'; //排序规则
|
||||
|
||||
$model = Db::name('UserZone')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$model = $model->where($map);
|
||||
if (!empty($is_follow)) {
|
||||
$model = $model->where("a.uid in (select follow_uid from yy_user_follow where uid = :uid)", ['uid' => $uid]);
|
||||
}
|
||||
$list = $model->field('a.zid,a.uid,a.images,a.sound,a.sound_duration,a.video,a.content,a.base64_content,a.praise_num,a.read_num,a.share_num,a.comment_num,a.is_recommend,a.add_time,b.base64_nick_name,b.sex,b.head_pic,a.show_status')->order($order_string)->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
|
||||
// if (!empty($v['images'])) {
|
||||
// $images_data = json_decode($v['images'], true);
|
||||
// $images_data = explode(',', $images_data);
|
||||
|
||||
// $images = [];
|
||||
// foreach ($images_data as $m => $n) {
|
||||
// $images[localpath_to_netpath($n)] = localpath_to_netpath($n);
|
||||
// }
|
||||
// $images = array_values($images);
|
||||
// $v['images'] = implode(',', $images);
|
||||
// } else {
|
||||
// $v['images'] = '';
|
||||
// }
|
||||
if(!empty($v['images'])){
|
||||
$images_data = explode(',', $v['images']);
|
||||
foreach ($images_data as $m => &$n) {
|
||||
$n = localpath_to_netpath($n);
|
||||
}
|
||||
$v['images']=$images_data;
|
||||
}else{
|
||||
$v['images']=[];
|
||||
}
|
||||
$v['content'] = mb_convert_encoding(base64_decode($v['base64_content']), 'UTF-8', 'UTF-8');
|
||||
$v['sound'] = localpath_to_netpath($v['sound']);
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['video'] = localpath_to_netpath($v['video']);
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
$v['is_praise'] = 0; //是否点赞
|
||||
$praise = db::name('user_zone_praise')->where(['zid' => $v['zid'], 'uid' => $uid])->find();
|
||||
if (!empty($praise)) {
|
||||
$v['is_praise'] = 1;
|
||||
}
|
||||
$v['is_follow'] = 0; //是否关注
|
||||
$follow = db::name('user_follow')->where(['follow_uid' => $v['uid'], 'uid' => $uid])->find();
|
||||
if (!empty($follow)) {
|
||||
$v['is_follow'] = 1;
|
||||
}
|
||||
$v['is_collect'] = 1; //是否收藏
|
||||
$v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//发布动态
|
||||
public function publish_zone($uid, $images, $sound, $sound_duration, $video, $content)
|
||||
{
|
||||
|
||||
$images_data = explode(',', $images);
|
||||
foreach ($images_data as $k => $v) {
|
||||
if(!empty($v)){
|
||||
//过滤网络文件地址
|
||||
if (!preg_match("/user_upload\/\d{8}\/\S{32}\.(png|jpg|gif|jpeg)/", $v)) {
|
||||
return ['code' => 201, 'msg' => '上传图片参数格式非法', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($sound)){
|
||||
if (!preg_match("/user_upload\/\d{8}\/\S{32}\.(mp3)/", $sound)) {
|
||||
return ['code' => 201, 'msg' => '上传音频参数格式非法', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($video)){
|
||||
if (!preg_match("/user_upload\/\d{8}\/\S{32}\.(mp4)/", $video)) {
|
||||
return ['code' => 201, 'msg' => '上传视频参数格式非法', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($images_data) && empty($sound) && empty($content) && empty($video)) {
|
||||
return ['code' => 201, 'msg' => '发布内容不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
//维禁判断
|
||||
if(!empty($content)) {
|
||||
$result = model('Tencent')->content_moderation('Text', $content);
|
||||
if($result['code'] != 200) {
|
||||
return ['code' => 201, 'msg' => '内容存在违禁词!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['images'] = $images;
|
||||
$data['sound'] = $sound;
|
||||
$data['sound_duration'] = $sound_duration;
|
||||
$data['video'] = $video;
|
||||
$data['content'] = $content;
|
||||
$data['show_status'] = 2;
|
||||
$data['base64_content'] = base64_encode($content);
|
||||
$validate = validate('admin/UserZone');
|
||||
$reslut = $validate->scene('apiAdd')->check($data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
}
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = model('user_zone')->save($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '发布成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '发布失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//动态 收藏 取消收藏
|
||||
public function praise_collect($uid, $cid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['cid', '=', $cid];
|
||||
$info = db::name('user_zone_collect')->where($map)->find();
|
||||
if (!empty($info)) {
|
||||
$del = db::name('user_zone_collect')->where($map)->delete();
|
||||
if ($del) {
|
||||
return ['code' => 200, 'msg' => '取消收藏成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['cid'] = $cid;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_zone_collect')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "收藏成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
public function get_zone_info($uid, $zid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['a.zid', '=', $zid];
|
||||
$map[] = ['a.show_status', '=', 2];
|
||||
$map[] = ['a.is_delete', '=', 1];
|
||||
$model = Db::name('UserZone')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$model = $model->where($map);
|
||||
$info = $model->field('a.zid,a.uid,a.images,a.sound,a.sound_duration,a.video,a.content,a.base64_content,a.praise_num,a.read_num,a.share_num,a.comment_num,a.is_recommend,a.add_time,b.base64_nick_name,b.sex,b.head_pic,a.show_status')->find();
|
||||
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
if (!empty($info['images'])) {
|
||||
$images_data = explode(',', $info['images']);
|
||||
foreach ($images_data as $m => &$n) {
|
||||
$n = localpath_to_netpath($n);
|
||||
}
|
||||
$info['images'] = $images_data;
|
||||
} else {
|
||||
$info['images'] = [];
|
||||
}
|
||||
$info['content'] = mb_convert_encoding(base64_decode($info['base64_content']), 'UTF-8', 'UTF-8');
|
||||
$info['sound'] = localpath_to_netpath($info['sound']);
|
||||
$info['nick_name'] = mb_convert_encoding(base64_decode($info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$info['video'] = localpath_to_netpath($info['video']);
|
||||
$info['head_pic'] = localpath_to_netpath($info['head_pic']);
|
||||
$info['is_praise'] = 0; //是否点赞
|
||||
$praise = db::name('user_zone_praise')->where(['zid' => $info['zid'], 'uid' => $uid])->find();
|
||||
if (!empty($praise)) {
|
||||
$info['is_praise'] = 1;
|
||||
}
|
||||
$info['is_follow'] = 0; //是否关注
|
||||
$follow = db::name('user_follow')->where(['follow_uid' => $info['uid'], 'uid' => $uid])->find();
|
||||
if (!empty($follow)) {
|
||||
$info['is_follow'] = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $info];
|
||||
}
|
||||
|
||||
//点赞 取消点赞
|
||||
public function praise_zone($uid, $zid)
|
||||
{
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['zid', '=', $zid];
|
||||
$info = db::name('user_zone_praise')->where($map)->find();
|
||||
if (!empty($info)) {
|
||||
$where = [];
|
||||
$where[] = ['zid', '=', $zid];
|
||||
db::name('user_zone')->where($where)->setDec('praise_num', 1);
|
||||
$del = db::name('user_zone_praise')->where($map)->delete();
|
||||
if ($del) {
|
||||
return ['code' => 200, 'msg' => '取消点赞成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['zid'] = $zid;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_zone_praise')->insertGetId($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
//增加点赞数量
|
||||
$map = [];
|
||||
$map[] = ['zid', '=', $zid];
|
||||
$reslut = db::name('user_zone')->where($map)->setInc('praise_num', 1);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "点赞成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
public function comment_zone($uid, $zid, $content)
|
||||
{
|
||||
$info = db::name('user_zone')->find($zid);
|
||||
if (empty($info)) {
|
||||
return ['code' => 201, 'msg' => "评论动态不存在", 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = [];
|
||||
$data['zid'] = $zid;
|
||||
$data['uid'] = $uid;
|
||||
$data['receive_uid'] = $info['uid'];
|
||||
$data['content'] = $content;
|
||||
$data['base64_content'] = base64_encode($content);
|
||||
$data['praise_num'] = 0;
|
||||
$data['is_show'] = 1;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$validate = validate('admin/UserZoneComment');
|
||||
$reslut = $validate->scene('apiAdd')->check($data);
|
||||
if ($reslut !== true) {
|
||||
return ['code' => 201, 'msg' => $validate->getError(), 'data' => null];
|
||||
}
|
||||
$reslut = db::name('user_zone_comment')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
//增加评论数量
|
||||
$map = [];
|
||||
$map[] = ['zid', '=', $zid];
|
||||
$reslut = db::name('user_zone')->where($map)->setInc('comment_num', 1);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
//提醒说说动态发布人有人评论
|
||||
$map=[];
|
||||
$map[]=['uid','=',$uid];
|
||||
$user_info=db::name('user')->where($map)->find();
|
||||
$content = $user_info['nick_name'] . "评论了您的动态";
|
||||
model('api/user_message')->send_message($info['uid'], 4,$info['zid'], "我的动态", $content);
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "评论成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
public function praise_comment($uid, $cid, $content)
|
||||
{
|
||||
$info = db::name('user_zone_comment')->find($cid);
|
||||
if (empty($info)) {
|
||||
return ['code' => 200, 'msg' => '评论信息不存在', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['cid', '=', $cid];
|
||||
$info = db::name('user_zone_comment_praise')->where($map)->find();
|
||||
if (!empty($info)) {
|
||||
return ['code' => 200, 'msg' => '点赞成功', 'data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['cid'] = $cid;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$reslut = db::name('user_zone_comment_praise')->insert($data);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
//增加点赞数量
|
||||
$map = [];
|
||||
$map[] = ['cid', '=', $cid];
|
||||
$reslut = db::name('user_zone_comment')->where($map)->setInc('praise_num', 1);
|
||||
if (!$reslut) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '请重试', 'data' => null];
|
||||
}
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "点赞成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
// public function get_comment_list($zid, $page, $page_limit)
|
||||
// {
|
||||
|
||||
// $page = intval($page);
|
||||
// $page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
// $map = [];
|
||||
// $map[] = ['a.show_status', '=', 1];
|
||||
// $map[] = ['a.zid', '=', $zid];
|
||||
// $order_string = 'a.praise_num desc'; //排序规则
|
||||
// $model = Db::name('user_zone')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
// $model = $model->where($map);
|
||||
// $list = $model->field('a.zid,a.content,a.praise_num,b.base64_nick_name,b.sex,b.head_pic')->order($order_string)->page($page, $page_limit)->select();
|
||||
// foreach ($list as $k => &$v) {
|
||||
// $v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
// $v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
// }
|
||||
// return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
// }
|
||||
|
||||
public function get_comment_list($zid, $page, $page_limit)
|
||||
{
|
||||
|
||||
$page = intval($page);
|
||||
$page_limit = $page_limit < 10 ? $page_limit : 10;
|
||||
$map = [];
|
||||
$map[] = ['a.is_show', '=', 1];
|
||||
$map[] = ['a.zid', '=', $zid];
|
||||
$order_string = 'a.praise_num desc'; //排序规则
|
||||
$model = Db::name('user_zone_comment')->alias('a')->join('yy_user b', 'a.uid = b.uid');
|
||||
$model = $model->where($map);
|
||||
$list = $model->field('a.zid,a.content,a.base64_content,a.praise_num,a.add_time,a.uid,b.base64_nick_name,b.sex,b.head_pic')->order($order_string)->page($page, $page_limit)->select();
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['content'] = mb_convert_encoding(base64_decode($v['base64_content']), 'UTF-8', 'UTF-8');
|
||||
$v['nick_name'] = mb_convert_encoding(base64_decode($v['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
$v['head_pic'] = localpath_to_netpath($v['head_pic']);
|
||||
unset($v['base64_nick_name']);
|
||||
}
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//删除动态
|
||||
public function delete_zone($uid, $zid)
|
||||
{
|
||||
|
||||
$map = [];
|
||||
$map[] = ['uid', '=', $uid];
|
||||
$map[] = ['zid', '=', $zid];
|
||||
$map[] = ['is_delete', '=', 1];
|
||||
$zone_info = db::name('user_zone')->where($map)->find();
|
||||
if (empty($zone_info)) {
|
||||
return ['code' => 201, 'msg' => '信息不存在', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['zid', '=', $zone_info['zid']];
|
||||
|
||||
$data = [];
|
||||
$data['is_delete'] = 2;
|
||||
$data['delete_time'] = time();
|
||||
$reslut = db::name('user_zone')->where($map)->update($data);
|
||||
if ($reslut) {
|
||||
return ['code' => 200, 'msg' => '删除成功', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 201, 'msg' => '删除失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
47
application/api/model/Version.php
Normal file
47
application/api/model/Version.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
use think\db;
|
||||
|
||||
class Version extends Model
|
||||
{
|
||||
public function get_app_version($type)
|
||||
{
|
||||
if (!in_array($type, [1, 2])) {
|
||||
return ['code' => 201, 'msg' => 'type非法参数', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$info = Db::name('version')->field('version,down_url,note,is_force_update')->where($map)->order('vid desc')->find();
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $info];
|
||||
}
|
||||
|
||||
|
||||
public function get_update_app_version($type, $version)
|
||||
{
|
||||
if (!in_array($type, [1, 2])) {
|
||||
return ['code' => 201, 'msg' => 'type非法参数', 'data' => null];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['type', '=', $type];
|
||||
$map[] = ['version', '>', $version];
|
||||
$info = Db::name('version')->field('version,down_url,note,is_force_update')->where($map)->order('vid desc')->find();
|
||||
if(empty($info)) {
|
||||
$info['version'] = '';
|
||||
$info['down_url'] = '';
|
||||
$info['note'] = '';
|
||||
$info['is_force_update'] = 0;
|
||||
} else {
|
||||
$domain = Db::name('config')->where('key_title', 'version_update_domain')->value('key_value');
|
||||
if($type == 1){
|
||||
$info['down_url'] = $domain . $info['down_url'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $info];
|
||||
}
|
||||
|
||||
}
|
||||
340
application/api/model/Vip.php
Normal file
340
application/api/model/Vip.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Vip extends Model
|
||||
{
|
||||
|
||||
//会员类型列表
|
||||
public function get_vip_list($uid){
|
||||
$config = get_uncache_system_config();
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info['vid'] > 0){
|
||||
$is_vip = 1;
|
||||
}else{
|
||||
$is_vip = 2;
|
||||
}
|
||||
|
||||
$vip_list = db::name('vip')->field('vid,name,day,price')->order('day asc')->select();
|
||||
|
||||
$data = [];
|
||||
$data['is_vip'] = $is_vip;
|
||||
$data['vip_end_time'] = $user_info['vip_end_time'];
|
||||
$data['user_vid'] = $user_info['vid'];
|
||||
$data['vip_list'] = $vip_list;
|
||||
$data['update_inviter_price'] = $config['update_inviter_price'];
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//购买会员
|
||||
public function pay_vip_order($uid, $vid){
|
||||
$user_info = db::name('user')->find($uid);
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
}
|
||||
$pay_money = 0;
|
||||
$give_integral = 0;
|
||||
|
||||
// if (!in_array($pay_type, [1, 2])) {
|
||||
// return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null];
|
||||
// }
|
||||
|
||||
if(!empty($vid)){
|
||||
$map = [];
|
||||
$map[] = ['vid', '=', $vid];
|
||||
$vip_info = db::name('vip')->where($map)->find();
|
||||
if(empty($vip_info)){
|
||||
return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null];
|
||||
}
|
||||
if ($vip_info['price'] <= 0) {
|
||||
return ['code' => 201, 'msg' => '会员卡购买金额参数非法', 'data' => null];
|
||||
}
|
||||
$pay_money = $vip_info['price'];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '会员卡类型不存在', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$pay_integral = $pay_money;
|
||||
|
||||
if($user_info['integral'] < $pay_integral){
|
||||
return ['code' => 201, 'msg' => '当前金币不足', 'data' => null];
|
||||
}
|
||||
//扣除对应金币
|
||||
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$pay_integral, 2, 36, '购买会员消费金币', $uid, 0, 0);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//增加用户会员
|
||||
$reslut = model('api/Vip')->add_user_vip($uid, $vid);
|
||||
if($reslut['code'] == 201){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//增加用户会员
|
||||
public function add_user_vip($uid, $vid){
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$vip_info = db::name('vip')->where('vid', $vid)->find();
|
||||
if(!$vip_info){
|
||||
return ['code' => 201, 'msg' => '该会员类型不存在', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//当前用户是否有会员
|
||||
if(empty($user_info['vid'])){
|
||||
$update = [];
|
||||
$update['vid'] = $vid;
|
||||
$update['vip_end_time'] = time() + (60*60*24*$vip_info['day']);
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user')->where('uid', $uid)->update($update);
|
||||
|
||||
}else{
|
||||
$update = [];
|
||||
$update['vid'] = $vid;
|
||||
if($user_info['vip_end_time'] > time()){
|
||||
$vip_end_time = $user_info['vip_end_time'] + (60*60*24*$vip_info['day']);
|
||||
}else{
|
||||
$vip_end_time = time() + (60*60*24*$vip_info['day']);
|
||||
}
|
||||
$update['vip_end_time'] = $vip_end_time;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user')->where('uid', $uid)->update($update);
|
||||
|
||||
}
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
//记录
|
||||
$insert = [];
|
||||
$insert['uid'] = $uid;
|
||||
$insert['vid'] = $vid;
|
||||
$insert['day'] = $vip_info['day'];
|
||||
$insert['price'] = $vip_info['price'];
|
||||
$insert['add_time'] = time();
|
||||
$reslut = db::name('user_vip_log')->insert($insert);
|
||||
if(!$reslut){
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
dump($e);
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//会员邀请收益
|
||||
public function vip_invite_earnings($uid, $money, $integral){
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//是否有上级
|
||||
if(!empty($user_info['pid'])){
|
||||
//上级是否是会员
|
||||
$pid_info = db::name('user')->where('uid', $user_info['pid'])->find();
|
||||
if(!empty($pid_info)){
|
||||
$send_money = $money * 0.009;
|
||||
if($send_money > 0){
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($user_info['pid'], $send_money, 1, 22, "会员邀请收益", $uid, 0);
|
||||
if ($reslut['code'] != 200) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//会员换绑回调
|
||||
public function user_update_inviter($uid, $invite_uid){
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$inviter_info = db::name('user')->where('uid', $invite_uid)->find();
|
||||
if(!$inviter_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$path = $inviter_info['path'].','.$uid;
|
||||
$update = [];
|
||||
$update['pid'] = $invite_uid;
|
||||
$update['path'] = $path;
|
||||
$update['update_time'] = time();
|
||||
$reslut = db::name('user')->where('uid', $uid)->update($update);
|
||||
if($reslut){
|
||||
return ['code' => 200, 'msg' => '成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 201, 'msg' => '失败', 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//换绑信息
|
||||
public function get_update_invite_info($uid){
|
||||
$config = get_uncache_system_config();
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
|
||||
$inviter_nick_name = '';
|
||||
if(!empty($user_info['pid'])){
|
||||
$inviter_info = db::name('user')->where('uid', $user_info['pid'])->find();
|
||||
$inviter_nick_name = mb_convert_encoding(base64_decode($inviter_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
|
||||
|
||||
$data = [];
|
||||
$data['update_inviter_price'] = $config['update_inviter_price'];
|
||||
$data['invite_uid'] = $user_info['pid'];
|
||||
$data['inviter_nick_name'] = $inviter_nick_name;
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $data];
|
||||
}
|
||||
|
||||
//更换邀请人
|
||||
public function update_user_inviter($uid, $user_id, $sms_code){
|
||||
$config = get_uncache_system_config();
|
||||
|
||||
$user_info = db::name('user')->where('uid', $uid)->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 201, 'msg' => '参数错误', 'data' => null];
|
||||
}
|
||||
if($user_info['is_teenager'] == 1){
|
||||
return ['code' => 201, 'msg' => '已开启青少年模式', 'data' => null];
|
||||
}
|
||||
|
||||
if($user_info['user_name'] == $uid){
|
||||
return ['code' => 201, 'msg' => '该用户尚未绑定手机号', 'data' => null];
|
||||
}
|
||||
|
||||
$reslut = model('sms')->verification_code($user_info['user_name'], $sms_code);
|
||||
if ($reslut['code'] == 201) {
|
||||
return ajaxReturn($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
$pay_money = 0;
|
||||
$give_integral = 0;
|
||||
|
||||
$inviter_info = db::name('user')->where('uid', $user_id)->find();
|
||||
if(!$inviter_info){
|
||||
return ['code' => 201, 'msg' => '更换邀请人不存在', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($inviter_info['vid'])){
|
||||
return ['code' => 201, 'msg' => '更换邀请人不是会员', 'data' => null];
|
||||
}
|
||||
|
||||
if($inviter_info['vip_end_time'] - time() < (60*60*24*30)){
|
||||
return ['code' => 201, 'msg' => '更换邀请人会员少于30天', 'data' => null];
|
||||
}
|
||||
|
||||
// if (!in_array($pay_type, [1, 2])) {
|
||||
// return ['code' => 201, 'msg' => '充值方式参数非法', 'data' => null];
|
||||
// }
|
||||
|
||||
if(empty($config['update_inviter_price']) && $config['update_inviter_price'] < 0){
|
||||
return ['code' => 201, 'msg' => '换绑支付金额不能为空且不能小于0', 'data' => null];
|
||||
}
|
||||
|
||||
$pay_money = $config['update_inviter_price'];
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
//扣除对应金币
|
||||
$pay_integral = $pay_money;
|
||||
if($user_info['integral'] < $pay_integral){
|
||||
return ['code' => 201, 'msg' => '当前金币不足', 'data' => null];
|
||||
}
|
||||
$reslut = model('admin/User')->change_user_money_by_uid($uid, -$pay_integral, 2, 37, '更换邀请人消费金币', $uid, 0, 0);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
//更换邀请人
|
||||
$reslut = model('api/Vip')->user_update_inviter($uid, $user_id);
|
||||
if ($reslut['code'] == 201) {
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => $reslut['msg'], 'data' => null];
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 200, 'msg' => "成功", 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
//回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 201, 'msg' => "失败", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//清除到期用户vip
|
||||
public function close_user_vip(){
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1024M');
|
||||
|
||||
$map = [];
|
||||
$map[] = ['vid', '>', 0];
|
||||
$map[] = ['vip_end_time', '<', time()];
|
||||
$vip_list = db::name('user')->where($map)->select();
|
||||
if(!empty($vip_list)){
|
||||
db::name('user')->where($map)->update(['vid' => 0, 'vip_end_time' => 0, 'update_time' => 0]);
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s').'执行成功';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
221
application/api/model/WebSocketPush.php
Normal file
221
application/api/model/WebSocketPush.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use think\facade\Log;
|
||||
class WebSocketPush
|
||||
{
|
||||
public $websocket_api_address;
|
||||
public $websocket_api_key;
|
||||
//声网
|
||||
public $customer_key; //声网key
|
||||
public $customer_secret; //声网secret
|
||||
public $app_id; //声网appid
|
||||
public $app_certificate;
|
||||
public $channel_name = '123456789'; //频道
|
||||
public $header_arr = []; //请求头
|
||||
public $base_url = 'https://api.agora.io/dev/v2/project/';
|
||||
// public $base_url = 'https://api.agora.io/dev/v1/projects';
|
||||
public $request_url;
|
||||
public $uid;
|
||||
public $token;
|
||||
public $credentials;
|
||||
/*
|
||||
200 通用数据
|
||||
|
||||
房间PK
|
||||
220 推送PK当前结果数据
|
||||
|
||||
300
|
||||
用户进入房间推送消息
|
||||
301
|
||||
房间麦位信息
|
||||
302
|
||||
房间赠送礼物推送数据
|
||||
303
|
||||
开宝箱房间播报数据
|
||||
304
|
||||
开宝箱全服播报数据
|
||||
400
|
||||
房间相亲数据
|
||||
|
||||
355
|
||||
挂件推送
|
||||
|
||||
369
|
||||
清理房间用户推送
|
||||
|
||||
3001
|
||||
竞拍前三名信息
|
||||
3002
|
||||
签约成功推送
|
||||
|
||||
3005
|
||||
绑定关系成功推送
|
||||
|
||||
3010
|
||||
自己签约的艺人被拍卖
|
||||
|
||||
*/
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$config = model('admin/Config')->get_uncache_system_config();
|
||||
// $this->websocket_api_address = $config['websocket_api_address'];
|
||||
// $this->websocket_api_key = $config['websocket_api_key'];
|
||||
// $this->uid = 99999999966;
|
||||
// $this->token = $token;
|
||||
|
||||
$this->app_id = $config['agora_app_id'];
|
||||
$this->customer_key = $config['agora_app_key'];
|
||||
$this->customer_secret = $config['agora_app_secret'];
|
||||
// $this->app_certificate = $config['agora_app_certificate'];
|
||||
// $this->token = model('agora')->agora_rtm_token_info($this->uid);
|
||||
$this->credentials = $this->customer_key . ':' . $this->customer_secret;
|
||||
// dump($this->customer_key);
|
||||
// dump($this->customer_secret);die;
|
||||
$base64Credentials = base64_encode($this->credentials);
|
||||
$this->header_arr = [
|
||||
// 'x-agora-uid: ' . $this->uid,
|
||||
// "x-agora-token: " . $this->token,
|
||||
'Authorization: Basic ' . $base64Credentials,
|
||||
'Content-Type: application/json'
|
||||
];
|
||||
}
|
||||
|
||||
//发送消息给个人
|
||||
// public function send_to_one($uid, $content)
|
||||
// {
|
||||
// $post_data = [];
|
||||
// // $post_data['action'] = 'send_to_one';
|
||||
// // $post_data['key'] = $this->websocket_api_key;
|
||||
// if (is_array($content)) {
|
||||
// $post_data['content'] = json_encode($content);
|
||||
// } else {
|
||||
// $post_data['content'] = $content;
|
||||
// }
|
||||
// $post_data['uid'] = $uid;
|
||||
|
||||
// $content = $this->curlPost($this->websocket_api_address, $post_data);
|
||||
|
||||
// return $content;
|
||||
// }
|
||||
//发送消息给个人
|
||||
public function send_to_one($uid, $content)
|
||||
{
|
||||
$post_data = [];
|
||||
// $post_data['action'] = 'send_to_one';
|
||||
// $post_data['key'] = $this->websocket_api_key;
|
||||
if (is_array($content)) {
|
||||
// $post_data['content'] = json_encode($content);
|
||||
$post_data['content'] = $content;
|
||||
} else {
|
||||
$post_data['content'] = $content;
|
||||
}
|
||||
// $post_data['uid'] = $uid;
|
||||
|
||||
// $content = $this->curlPost($this->websocket_api_address, $post_data);
|
||||
$this->request_url = $this->base_url . $this->app_id . '/rtm/users/8889987154254/peer_messages';
|
||||
$data['payload'] = json_encode($post_data);
|
||||
$data['destination'] = strval($uid);
|
||||
$data['enable_historical_messaging'] = false;
|
||||
$data = json_encode($data);
|
||||
$content = $this->curlPost($this->request_url, $data, $this->header_arr);
|
||||
|
||||
return $content;
|
||||
}
|
||||
//发送消息到指定房间
|
||||
public function send_to_group($rid, $content)
|
||||
{
|
||||
|
||||
$post_data = [];
|
||||
|
||||
// $post_data['action'] = 'send_to_group';
|
||||
// $post_data['key'] = $this->websocket_api_key;
|
||||
// if (is_array($content)) {
|
||||
// $post_data['content'] = json_encode($content);
|
||||
// } else {
|
||||
// $post_data['content'] = $content;
|
||||
// }
|
||||
$post_data['content'] = $content;
|
||||
$post_data['hid'] = $rid;
|
||||
$data['channel_name'] = strval($rid);
|
||||
$data['payload'] = json_encode($post_data);
|
||||
$data['enable_historical_messaging'] = false;
|
||||
$data = json_encode($data);
|
||||
|
||||
// $this->request_url = $this->base_url . $this->app_id . '/rtm/users/' . $this->uid . '/channel_messages';
|
||||
// $this->request_url = $this->base_url;
|
||||
$this->request_url = $this->base_url . $this->app_id . '/rtm/users/8889987154254/channel_messages';
|
||||
// dump($data);
|
||||
$content = $this->curlPost($this->request_url, $data ,$this->header_arr);
|
||||
// dump($content);die;
|
||||
return $content;
|
||||
}
|
||||
//发送群体消息
|
||||
public function send_to_all($content)
|
||||
{
|
||||
$post_data = [];
|
||||
|
||||
// $post_data['action'] = 'send_to_group';
|
||||
// $post_data['key'] = $this->websocket_api_key;
|
||||
// if (is_array($content)) {
|
||||
// $post_data['content'] = json_encode($content);
|
||||
// } else {
|
||||
// $post_data['content'] = $content;
|
||||
// }
|
||||
$post_data['content'] = $content;
|
||||
|
||||
$data['channel_name'] = $this->channel_name;
|
||||
$data['payload'] = json_encode($post_data);
|
||||
$data['enable_historical_messaging'] = false;
|
||||
$data = json_encode($data);
|
||||
|
||||
$this->request_url = $this->base_url . $this->app_id . '/rtm/users/8889987154254/channel_messages';
|
||||
// dump($this->request_url);die;
|
||||
$content = $this->curlPost($this->request_url, $data,$this->header_arr);
|
||||
|
||||
// dump($content);die;
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getallclients()
|
||||
{
|
||||
$post_data = [];
|
||||
$post_data['action'] = 'getallclients';
|
||||
$post_data['key'] = $this->websocket_api_key;
|
||||
$content = $this->curlPost($this->websocket_api_address, $post_data);
|
||||
return $content;
|
||||
}
|
||||
|
||||
//参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
|
||||
// public function myCurl($url, $post_data = array(), $header = array(), $cookie = "")
|
||||
// {
|
||||
// // $url = 'http://paysystem.local.com/index/apip/cc';
|
||||
// // dump($url);
|
||||
// curlPost($url)
|
||||
// }
|
||||
|
||||
public function curlPost($url, $data = [], $header = [])
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT , 0);
|
||||
curl_setopt($curl, CURLOPT_MAXREDIRS , 10);
|
||||
curl_setopt($curl, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
if (!empty($data)) {
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
if (!empty($header)) {
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
120
application/api/model/WebSocketPush1.php
Normal file
120
application/api/model/WebSocketPush1.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
class WebSocketPush
|
||||
{
|
||||
public $websocket_api_address;
|
||||
public $websocket_api_key;
|
||||
/*
|
||||
200 通用数据
|
||||
|
||||
房间PK
|
||||
220 推送PK当前结果数据
|
||||
|
||||
300
|
||||
用户进入房间推送消息
|
||||
301
|
||||
房间麦位信息
|
||||
302
|
||||
房间赠送礼物推送数据
|
||||
303
|
||||
开宝箱房间播报数据
|
||||
304
|
||||
开宝箱全服播报数据
|
||||
400
|
||||
房间相亲数据
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$config = model('admin/Config')->get_system_config();
|
||||
$this->websocket_api_address = $config['websocket_api_address'];
|
||||
$this->websocket_api_key = $config['websocket_api_key'];
|
||||
}
|
||||
|
||||
//发送消息给个人
|
||||
public function send_to_one($uid, $content)
|
||||
{
|
||||
$post_data = [];
|
||||
$post_data['action'] = 'send_to_one';
|
||||
$post_data['key'] = $this->websocket_api_key;
|
||||
if (is_array($content)) {
|
||||
$post_data['content'] = json_encode($content);
|
||||
} else {
|
||||
$post_data['content'] = $content;
|
||||
}
|
||||
$post_data['uid'] = $uid;
|
||||
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
||||
return $content;
|
||||
}
|
||||
//发送消息到指定房间
|
||||
public function send_to_group($rid, $content)
|
||||
{
|
||||
$post_data = [];
|
||||
$post_data['action'] = 'send_to_group';
|
||||
$post_data['key'] = $this->websocket_api_key;
|
||||
if (is_array($content)) {
|
||||
$post_data['content'] = json_encode($content);
|
||||
} else {
|
||||
$post_data['content'] = $content;
|
||||
}
|
||||
$post_data['hid'] = $rid;
|
||||
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
||||
return $content;
|
||||
}
|
||||
//发送群体消息
|
||||
public function send_to_all($content)
|
||||
{
|
||||
$post_data = [];
|
||||
$post_data['action'] = 'send_to_all';
|
||||
$post_data['key'] = $this->websocket_api_key;
|
||||
if (is_array($content)) {
|
||||
$post_data['content'] = json_encode($content);
|
||||
} else {
|
||||
$post_data['content'] = $content;
|
||||
}
|
||||
// dump($post_data);
|
||||
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getallclients()
|
||||
{
|
||||
$post_data = [];
|
||||
$post_data['action'] = 'getallclients';
|
||||
$post_data['key'] = $this->websocket_api_key;
|
||||
$content = $this->myCurl($this->websocket_api_address, $post_data);
|
||||
return $content;
|
||||
}
|
||||
|
||||
//参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
|
||||
public function myCurl($url, $post_data = array(), $header = array(), $cookie = "")
|
||||
{
|
||||
// $url = 'http://paysystem.local.com/index/apip/cc';
|
||||
// dump($url);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果把这行注释掉的话,就会直接输出
|
||||
$curl_header = array();
|
||||
if (!empty($header)) {
|
||||
foreach ($header as $k => $v) {
|
||||
$curl_header[] = "$k:$v";
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header);
|
||||
}
|
||||
|
||||
if (!empty($post_data)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
|
||||
}
|
||||
if (!empty($cookie)) {
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
61
application/api/model/Week.php
Normal file
61
application/api/model/Week.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class Week extends Model
|
||||
{
|
||||
|
||||
public function serial_index($user_id, $type){
|
||||
|
||||
$user_info = db::name('user')->where('uid', $user_id)->field('uid,base64_nick_name,head_pic')->find();
|
||||
$user_info['nickname'] = mb_convert_encoding(base64_decode($user_info['base64_nick_name']), 'UTF-8', 'UTF-8');
|
||||
if(!isset($user_info['uid'])){
|
||||
return ajaxReturn(201, '该用户不存在', null);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = db::name('user_send_gift')
|
||||
->where('room_uid', $user_id)
|
||||
->order('add_time desc');
|
||||
|
||||
|
||||
if($type==2){
|
||||
$query = $query->whereTime('add_time', 'last week');
|
||||
}else if($type==3){
|
||||
$query = $query->whereTime('add_time', 'month');
|
||||
}else if($type==4){
|
||||
$query = $query->whereTime('add_time', 'last month');
|
||||
}else{
|
||||
$query = $query->whereTime('add_time', 'week');
|
||||
}
|
||||
$list = $query->select();
|
||||
|
||||
// $_list = collection($list)->toArray();
|
||||
$_list = $list;
|
||||
$list=[];
|
||||
$total=0;
|
||||
foreach($_list as $val){
|
||||
$t=date("Y-m-d", $val['add_time']);
|
||||
if(isset($list[$t])){
|
||||
$list[$t]['total_price'] += $val['gift_total_price'];
|
||||
}else{
|
||||
$list[$t]['total_price'] = $val['gift_total_price'];
|
||||
$list[$t]['ct'] = $t;
|
||||
$list[$t]['box_price'] = $t;
|
||||
}
|
||||
$total += $val['gift_total_price'];
|
||||
}
|
||||
|
||||
$list = array_values($list);
|
||||
|
||||
$result = array("rows" => $list, 'total'=>$total,'userinfo'=>$user_info);
|
||||
|
||||
return ['code' => 200, 'msg' => '获取成功', 'data' => $result];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1117
application/api/model/XqRoom.php
Normal file
1117
application/api/model/XqRoom.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user