Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 026559ecaa | |||
| 54ca0e0207 | |||
| dc0a271adf | |||
| a4858d47fc | |||
| e73091cdf3 | |||
| c8773c8c45 | |||
| 598302925b | |||
| 1870f3d9b6 | |||
| 58fd97511e | |||
| c826edcbc1 | |||
| ea07b49995 | |||
| aa05ca0043 | |||
| 1c5a3b2c08 | |||
| 3a2e51027f | |||
| 9671f2e37f | |||
| 330e2772a9 | |||
| 9f6892f973 | |||
| f09db7aa97 | |||
| 7c8d5432ba | |||
| 5b61c68811 | |||
| 4d09418cfd | |||
| 9991a4bdd8 | |||
| 266c90cd09 | |||
| 7f7dca16c0 | |||
| ccf52a6623 | |||
| 5e798e7f05 | |||
| 28fbc40f70 | |||
| ea881adbd2 | |||
| 314e519937 | |||
| 3fc247e8e5 | |||
| ebdfd04105 | |||
| 4fc571e5e2 | |||
| 3957e831f9 | |||
| eef23f6bba | |||
| c7fb6078a9 | |||
| a0ea15ef2a | |||
| f635515d61 | |||
| a3b3bd04ef | |||
| f9d9a1bf5c | |||
| 06c5df0207 | |||
| 917d95f5f3 | |||
| 89e6c023db | |||
| d2baceadea | |||
| 93d75a4ef3 | |||
| 07d631a7bb | |||
| c232caf2f0 | |||
| 20a6ecffa6 | |||
| 08cc1dabd8 | |||
| 3741278825 | |||
| 4a77c59baf | |||
| 96f236a433 | |||
| fca4eb5fd1 | |||
| 92a63551c6 | |||
| 11ada68d54 | |||
| d3003db0f8 | |||
| e233c814e7 |
21
.env
21
.env
@@ -10,15 +10,23 @@ trace = false
|
||||
; hostport = 3306
|
||||
; prefix = fa_
|
||||
|
||||
hostname = 81.70.45.221
|
||||
database = super_chat
|
||||
username = super_chat
|
||||
password = c7NXx8KMPaTX4N5W
|
||||
|
||||
hostname = 1.13.181.248
|
||||
database = midi
|
||||
username = midi
|
||||
password = 5B2zwShhTi5L7t2w
|
||||
hostport = 3306
|
||||
prefix = fa_
|
||||
|
||||
#hostname = 62.234.12.147
|
||||
#database = midi
|
||||
#username = midi
|
||||
#password = EC6cak6fzXdXnERz
|
||||
#hostport = 3306
|
||||
#prefix = fa_
|
||||
|
||||
[mqtt]
|
||||
mqtt_server = 81.70.45.221
|
||||
mqtt_server = 1.13.181.248
|
||||
mqtt_port = 1883
|
||||
mqtt_username = admin
|
||||
mqtt_password = public
|
||||
@@ -27,11 +35,12 @@ mqtt_password = public
|
||||
[smsbao]
|
||||
dxb_name = xqgy1818
|
||||
dxb_pwd = "xqgy1818!"
|
||||
dxb_temp = "【羽声语音】您的验证码是{code}。如非本人操作,请忽略本短信"
|
||||
dxb_temp = "【西安熙晟文化传媒】您的验证码是{code}。如非本人操作,请忽略本短信"
|
||||
|
||||
[wechatpay]
|
||||
mch_id = 1719907761
|
||||
appid = wxc7681513be9f926b
|
||||
#下面具体是V2秘钥
|
||||
api_v3_key = "5826Qxhs456453614dsjkfhdsf53g4op"
|
||||
serial_no = "51FAD3F779271A865040771BEC14A825638E9484"
|
||||
private_key = "epay/certs/apiclient_key.pem"
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,4 +2,4 @@
|
||||
/public/uploads/*
|
||||
.idea
|
||||
*.log
|
||||
|
||||
.env
|
||||
|
||||
@@ -40,8 +40,9 @@ class Activities extends adminApi
|
||||
public function first_charge_lists(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$activities_id = input('activities_id', 1);
|
||||
$where = [];
|
||||
$where['activities_id'] = 1;
|
||||
$where['activities_id'] = $activities_id;
|
||||
$where['delete_time'] = 0;
|
||||
$count = db($this->table)->where($where)->count();
|
||||
$lists = db($this->table)->where($where)->page($page, $page_limit)->select();
|
||||
@@ -76,11 +77,12 @@ class Activities extends adminApi
|
||||
$title1 = input('title1', '');
|
||||
$title2 = input('title2', '');
|
||||
$money = input('money', '');
|
||||
$activities_id = input('activities_id', 1);
|
||||
$return_data = [
|
||||
'name' => $name,
|
||||
'title' => $title,
|
||||
'status' => $status,
|
||||
'activities_id' => 1,
|
||||
'activities_id' => $activities_id,
|
||||
];
|
||||
$ext = [
|
||||
'title1' => $title1,
|
||||
@@ -167,11 +169,12 @@ class Activities extends adminApi
|
||||
$page_limit = input('page_limit', 30);
|
||||
$user_id = input('user_id', '');
|
||||
$gift_bag_id = input('gift_bag_id', '');
|
||||
$activities_id = input('activities_id', 1);
|
||||
$where = [];
|
||||
if($user_id){
|
||||
$where['user_id'] = $user_id;
|
||||
}
|
||||
$gift_bag = db('vs_gift_bag')->where(['activities_id'=>1,'delete_time'=>0])->select();
|
||||
$gift_bag = db('vs_gift_bag')->where(['activities_id'=>$activities_id,'delete_time'=>0])->select();
|
||||
|
||||
if($gift_bag_id){
|
||||
$where['gift_bag_id'] = $gift_bag_id;
|
||||
@@ -360,6 +363,7 @@ class Activities extends adminApi
|
||||
'foreign_id' => $gift_id,
|
||||
'name' => $gift['gift_name'],
|
||||
'quantity' => $num,
|
||||
'gold' => $gift['gift_price'],
|
||||
];
|
||||
} elseif($type == 3){
|
||||
$decorate_price = DB::name('vs_decorate_price')->where(['id'=>$gift_id])->find();
|
||||
@@ -373,6 +377,7 @@ class Activities extends adminApi
|
||||
'foreign_id' => $gift_id,
|
||||
'name' => $gift['title'],
|
||||
'days' => $decorate_price['day'],
|
||||
'gold' => $decorate_price['price'],
|
||||
];
|
||||
} elseif($type == 4){
|
||||
$data = [
|
||||
@@ -419,6 +424,7 @@ class Activities extends adminApi
|
||||
'money' => $ext['money'],
|
||||
'money_str' => $ext['money_str'],
|
||||
'diamond' => $ext['diamond'],
|
||||
'activity_end_time' => $ext['activity_end_time'],
|
||||
];
|
||||
return V(1,"成功",$data);
|
||||
}
|
||||
@@ -433,17 +439,20 @@ class Activities extends adminApi
|
||||
$money = input('money', '');
|
||||
$money_str = input('money_str', '');
|
||||
$diamond = input('diamond', '');
|
||||
$activity_end_time = input('activity_end_time', '');
|
||||
$id = input('id', 6);
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'title' => $title,
|
||||
'status' => $status
|
||||
'status' => $status,
|
||||
'money' => $money,
|
||||
];
|
||||
$ext = [
|
||||
'counter' => $counter,
|
||||
'money_str' => $money_str,
|
||||
'diamond' => $diamond,
|
||||
'money' => $money
|
||||
'money' => $money,
|
||||
'activity_end_time' => $activity_end_time
|
||||
];
|
||||
$data['ext'] = json_encode($ext);
|
||||
$res = db::name($this->table)->where(['id'=>$id])->update($data);
|
||||
@@ -498,6 +507,7 @@ class Activities extends adminApi
|
||||
$meet = input('meet','');
|
||||
$num = input('num', 0);
|
||||
$content = input('content', 0);
|
||||
$title = input('title', "");
|
||||
if($gift_bag_id==""){
|
||||
return V(0,"请选择礼包类型");
|
||||
}
|
||||
@@ -516,6 +526,7 @@ class Activities extends adminApi
|
||||
'num' => $num
|
||||
];
|
||||
$data['ext'] = json_encode($ext);
|
||||
$data['title'] = $title;
|
||||
$res = db::name($this->table)->where(['id'=>$gift_bag_id])->update($data);
|
||||
if(!$res){
|
||||
return V(0,"失败");
|
||||
@@ -591,10 +602,10 @@ class Activities extends adminApi
|
||||
$lists[$key]['gift_id'] = $value['foreign_id'];
|
||||
$lists[$key]['gift_name'] = $value['name'];
|
||||
$gift_data = db::name('vs_gift')->where(['gid' => $value['foreign_id']])->find();
|
||||
$lists[$key]['base_image'] = $gift_data['base_image'];
|
||||
$lists[$key]['base_image'] = $gift_data['base_image']??"";
|
||||
$lists[$key]['quantity'] = $value['quantity'];
|
||||
$lists[$key]['quantity_str'] = $value['quantity']."个";
|
||||
$lists[$key]['gift_price'] = $gift_data['gift_price'];
|
||||
$lists[$key]['gift_price'] = $gift_data['gift_price']?? "";
|
||||
}elseif ($value['type'] == 3){
|
||||
$lists[$key]['gift_id'] = $value['foreign_id'];
|
||||
$lists[$key]['gift_name'] = $value['name'];
|
||||
|
||||
@@ -168,7 +168,7 @@ class Admin extends adminApi
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post();
|
||||
$group = $params['group'];
|
||||
$group = $params['group']?? [];
|
||||
unset($params['group']);
|
||||
unset($params['__token__']);
|
||||
if ($params) {
|
||||
@@ -196,21 +196,21 @@ class Admin extends adminApi
|
||||
return V(0,"失败", []);
|
||||
}
|
||||
|
||||
// 先移除所有权限
|
||||
model('admin/AuthGroupAccess')->where('uid', $params['id'])->delete();
|
||||
if(!empty($group)){
|
||||
// 先移除所有权限
|
||||
model('admin/AuthGroupAccess')->where('uid', $params['id'])->delete();
|
||||
// 过滤不允许的组别,避免越权
|
||||
$group = array_intersect($this->childrenGroupIds, $group);
|
||||
if (!$group) {
|
||||
return V(0,"失败", []);
|
||||
}
|
||||
|
||||
|
||||
// 过滤不允许的组别,避免越权
|
||||
$group = array_intersect($this->childrenGroupIds, $group);
|
||||
if (!$group) {
|
||||
return V(0,"失败", []);
|
||||
$dataset = [];
|
||||
foreach ($group as $value) {
|
||||
$dataset[] = ['uid' => $params['id'], 'group_id' => $value];
|
||||
}
|
||||
model('admin/AuthGroupAccess')->saveAll($dataset);
|
||||
}
|
||||
|
||||
$dataset = [];
|
||||
foreach ($group as $value) {
|
||||
$dataset[] = ['uid' => $params['id'], 'group_id' => $value];
|
||||
}
|
||||
model('admin/AuthGroupAccess')->saveAll($dataset);
|
||||
Db::commit();
|
||||
return V(1,"成功", []);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -52,10 +52,10 @@ class Adminlog extends adminApi
|
||||
$where['createtime'] = ['>=', strtotime($search_stime)];
|
||||
}
|
||||
if ($search_etime) {
|
||||
$where['createtime'] = ['<=', strtotime($search_etime.' 23:59:59')];
|
||||
$where['createtime'] = ['<=', strtotime($search_etime)];
|
||||
}
|
||||
if(!empty($search_stime) && !empty($search_etime)){
|
||||
$where['createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime)]];
|
||||
}
|
||||
|
||||
$list_data = $this->model->where($where)->where('admin_id', 'in', $this->childrenAdminIds)->order('createtime', 'desc')->paginate($page_limit, false, ['page' => $page]);
|
||||
|
||||
@@ -151,7 +151,7 @@ class Banner extends adminApi
|
||||
$image = input('image', '');
|
||||
$show_status = input('show_status', '');
|
||||
$remarks = input('remarks', '');
|
||||
$content = input('content', '');
|
||||
$content =$_POST['content']??"";
|
||||
if (!$id){
|
||||
return V(0,"ID不能为空");
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use think\Db;
|
||||
use think\Hook;
|
||||
use think\Session;
|
||||
use think\Validate;
|
||||
use think\Cache;
|
||||
|
||||
/**
|
||||
* 盲盒
|
||||
@@ -18,7 +19,7 @@ class BlindBox extends adminApi
|
||||
{
|
||||
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedRight = ['blind_box_type','blind_box_gifts'];
|
||||
protected $noNeedRight = ['blind_box_type','blind_box_gifts','xunlehui_rule_detail','xunlehui_set_rule','blind_box_turntable_lists','blind_box_turntable_open_record','xlh_lock_record'];
|
||||
|
||||
protected $table = 'vs_gift_bag_detail';
|
||||
|
||||
@@ -40,7 +41,8 @@ class BlindBox extends adminApi
|
||||
if(empty($gift_bag_id)){
|
||||
return V(0,"请选择盲盒类型");
|
||||
}
|
||||
$bag_list = db::name("vs_gift_bag")->field('id,name')->where(['activities_id'=>4,'status'=>1])->select();
|
||||
$bag_data = db::name("vs_gift_bag")->find($gift_bag_id);
|
||||
$bag_list = db::name("vs_gift_bag")->field('id,name')->where(['activities_id'=>$bag_data['activities_id'],'status'=>1])->select();
|
||||
foreach ($bag_list as &$v) {
|
||||
$v['default'] = $gift_bag_id == $v['id'] ? 1 : 0;
|
||||
}
|
||||
@@ -60,15 +62,24 @@ class BlindBox extends adminApi
|
||||
$lists[$key]['gift_id'] = $value['foreign_id'];
|
||||
$lists[$key]['gift_name'] = $value['name'];
|
||||
$gift_data = db::name('vs_gift')->where(['gid'=>$value['foreign_id']])->find();
|
||||
if(empty($gift_data)){
|
||||
continue;
|
||||
}
|
||||
$lists[$key]['base_image'] = $gift_data['base_image'];
|
||||
$lists[$key]['gift_price'] = $gift_data['gift_price'];
|
||||
$lists[$key]['quantity'] = $value['quantity'];
|
||||
$lists[$key]['remaining_number'] = $value['remaining_number'];
|
||||
$lists[$key]['is_public_screen'] = $gift_data['is_public_screen'];
|
||||
$lists[$key]['is_public_server'] = $gift_data['is_public_server'];
|
||||
$lists[$key]['is_world_show'] = $value['is_world_show'];
|
||||
$lists[$key]['weight'] = $value['weight'];
|
||||
$lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
|
||||
}
|
||||
//$lists 按gift_price 降序排序
|
||||
usort($lists, function($a, $b) {
|
||||
return $b['gift_price'] - $a['gift_price'];
|
||||
});
|
||||
//统计
|
||||
$total_data = [];
|
||||
//每期总次数
|
||||
@@ -83,9 +94,14 @@ class BlindBox extends adminApi
|
||||
//每期总抽奖花费(支出)
|
||||
$bag_data = db::name("vs_gift_bag")->field('id,name,ext')->where(['id'=>$gift_bag_id])->find();
|
||||
$ext = json_decode($bag_data['ext'],true);
|
||||
$c_gift_id = $ext['gift_id'];
|
||||
$c_gift_data = db::name('vs_gift')->where(['gid'=>$c_gift_id])->find();
|
||||
$gift_price = $c_gift_data['gift_price']??0;
|
||||
|
||||
if($gift_bag_id == 13){
|
||||
$gift_price = $ext['xlh_box_price']??0;
|
||||
}else{
|
||||
$c_gift_id = $ext['gift_id'];
|
||||
$c_gift_data = db::name('vs_gift')->where(['gid'=>$c_gift_id])->find();
|
||||
$gift_price = $c_gift_data['gift_price']??0;
|
||||
}
|
||||
$total_cost = $total_count * $gift_price;
|
||||
//每期统计(收入/支出)
|
||||
if($total_cost==0 || $total_price==0){
|
||||
@@ -131,6 +147,8 @@ class BlindBox extends adminApi
|
||||
$gift_id = input('gift_id', '');
|
||||
$gift_bag_id = input('gift_bag_id', '');
|
||||
$quantity = input('quantity', 0);
|
||||
$weight = input('weight', 0);
|
||||
$is_world_show = input('is_world_show', 0);
|
||||
if(empty($gift_id)){
|
||||
return V(0,"请选择礼物");
|
||||
}
|
||||
@@ -153,6 +171,9 @@ class BlindBox extends adminApi
|
||||
$data['quantity'] = $quantity;
|
||||
$data['remaining_number'] = $quantity;
|
||||
$data['createtime'] = time();
|
||||
$data['weight'] = $weight;
|
||||
$data['is_world_show'] = $is_world_show;
|
||||
|
||||
$res = db::name($this->table)->insert($data);
|
||||
if($res){
|
||||
return V(1,"成功");
|
||||
@@ -165,7 +186,15 @@ class BlindBox extends adminApi
|
||||
*/
|
||||
public function blind_box_gifts(){
|
||||
$type = input('type', 2);
|
||||
$list = db::name("vs_gift")->where(['type'=>$type,'delete_time'=>0])->order('sort','asc')->select();
|
||||
$label = input('label', 0);
|
||||
$where['delete_time'] = 0;
|
||||
if($type){
|
||||
$where['type'] = $type;
|
||||
}
|
||||
if($label){
|
||||
$where['label'] = $label;
|
||||
}
|
||||
$list = db::name("vs_gift")->where($where)->order('sort','asc')->select();
|
||||
$list_data = [];
|
||||
foreach ($list as $k=>$v){
|
||||
$list_data[$k]['gid'] = $v['gid'];
|
||||
@@ -181,9 +210,12 @@ class BlindBox extends adminApi
|
||||
public function blind_box_edit(){
|
||||
$id = input('id', '');
|
||||
$quantity = input('quantity', 0);
|
||||
$is_world_show = input('is_world_show', 0);
|
||||
$gift_id = input('gift_id', 0);
|
||||
if(empty($id)){
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
$weight = input('weight', 0);
|
||||
$gift_bag = db::name($this->table)->where('id',$id)->find();
|
||||
// if($gift_bag['remaining_number']>0){
|
||||
// return V(0,"该礼包已开售");
|
||||
@@ -191,6 +223,13 @@ class BlindBox extends adminApi
|
||||
$data = [];
|
||||
$data['quantity'] = $quantity;
|
||||
$data['remaining_number'] = $quantity;
|
||||
$data['is_world_show'] = $is_world_show;
|
||||
$data['weight'] = $weight;
|
||||
if(!empty($gift_id)){
|
||||
$gift = db::name('vs_gift')->where(['gid'=>$gift_id])->find();
|
||||
$data['foreign_id'] = $gift_id;
|
||||
$data['name'] = $gift['gift_name'];
|
||||
}
|
||||
$res = db::name($this->table)->where(['id'=>$id])->update($data);
|
||||
if($res){
|
||||
return V(1,"成功");
|
||||
@@ -217,18 +256,105 @@ class BlindBox extends adminApi
|
||||
*/
|
||||
public function reset_set(){
|
||||
$gift_bag_id = input('gift_bag_id', 0);
|
||||
$room_id = input('room_id', 0);
|
||||
if(empty($gift_bag_id)){
|
||||
return V(0,"请选择盲盒类型");
|
||||
}
|
||||
$gift_bag_detail = db::name($this->table)->where(['gift_bag_id'=>$gift_bag_id])->select();
|
||||
// if(in_array($gift_bag_id,[10,11,12,13])){
|
||||
// $periods = 1;
|
||||
// $target_room_ids = [];
|
||||
// if(!empty($room_id)){
|
||||
// // 处理单个房间
|
||||
// $room_pan_detail = db::name('vs_room_pan')
|
||||
// ->where(['gift_bag_id'=>$gift_bag_id,'room_id'=>$room_id])
|
||||
// ->order('id desc')
|
||||
// ->find();
|
||||
//
|
||||
// if($room_pan_detail){
|
||||
// $periods = $room_pan_detail['periods'];
|
||||
// }
|
||||
// // 删除指定房间的数据
|
||||
// db::name('vs_room_pan')
|
||||
// ->where(['room_id'=>$room_id,'gift_bag_id'=>$gift_bag_id])
|
||||
// ->delete();
|
||||
//
|
||||
// $target_room_ids = [$room_id];
|
||||
// }else{
|
||||
// // 处理所有房间
|
||||
// db::name('vs_room_pan')
|
||||
// ->where(['gift_bag_id'=>$gift_bag_id])
|
||||
// ->delete();
|
||||
//
|
||||
// $target_room_ids = db::name('vs_room')
|
||||
// ->where(['is_open_blind_box_turntable'=>1,'room_status'=>1])
|
||||
// ->column('id');
|
||||
// }
|
||||
// // 批量插入数据
|
||||
// $insert_data = [];
|
||||
// $update_data = [];
|
||||
// foreach ($gift_bag_detail as $v){
|
||||
// if(!empty($room_id)) {
|
||||
// // 单个房间更新或插入
|
||||
// $existing = db::name('vs_room_pan')
|
||||
// ->where([
|
||||
// 'room_id' => $room_id,
|
||||
// 'gift_bag_detail_id' => $v['id']
|
||||
// ])
|
||||
// ->find();
|
||||
//
|
||||
// if($existing) {
|
||||
// $update_data[] = [
|
||||
// 'id' => $existing['id'],
|
||||
// 'remaining_number' => $v['quantity'],
|
||||
// 'periods' => $periods
|
||||
// ];
|
||||
// } else {
|
||||
// $insert_data[] = [
|
||||
// 'room_id' => $room_id,
|
||||
// 'gift_bag_id' => $gift_bag_id,
|
||||
// 'gift_bag_detail_id' => $v['id'],
|
||||
// 'remaining_number' => $v['quantity'],
|
||||
// 'periods' => $periods,
|
||||
// 'createtime' => time(),
|
||||
// ];
|
||||
// }
|
||||
// } else {
|
||||
// // 多个房间批量插入
|
||||
// foreach ($target_room_ids as $mid){
|
||||
// $insert_data[] = [
|
||||
// 'room_id' => $mid,
|
||||
// 'gift_bag_id' => $gift_bag_id,
|
||||
// 'gift_bag_detail_id' => $v['id'],
|
||||
// 'remaining_number' => $v['quantity'],
|
||||
// 'periods' => $periods,
|
||||
// 'createtime' => time(),
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 执行批量插入
|
||||
// if(!empty($insert_data)) {
|
||||
// db::name('vs_room_pan')->insertAll($insert_data);
|
||||
// }
|
||||
// // 执行批量更新
|
||||
// if(!empty($update_data)) {
|
||||
// foreach($update_data as $update_item) {
|
||||
// db::name('vs_room_pan')
|
||||
// ->where(['id' => $update_item['id']])
|
||||
// ->update([
|
||||
// 'remaining_number' => $update_item['remaining_number'],
|
||||
// 'periods' => $update_item['periods']
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// 更新盲盒详情的剩余数量
|
||||
foreach ($gift_bag_detail as $k=>$v){
|
||||
$bag_data = db::name($this->table)->where(['id'=>$v['id']])->update(['remaining_number'=>$v['quantity']]);
|
||||
}
|
||||
if($bag_data){
|
||||
return V(1,"成功");
|
||||
}else{
|
||||
return V(0,"失败");
|
||||
}
|
||||
return V(1,"成功");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -309,6 +435,8 @@ class BlindBox extends adminApi
|
||||
}
|
||||
if($gift_bag_id){
|
||||
$where['gift_bag_id'] = $gift_bag_id;
|
||||
}else{
|
||||
$where['gift_bag_id'] = ['in',[7,8,9]];
|
||||
}
|
||||
if($periods){
|
||||
$where['periods'] = $periods;
|
||||
@@ -401,5 +529,383 @@ class BlindBox extends adminApi
|
||||
$bag_list = db::name("vs_gift_bag")->field('id,name')->where(['activities_id'=>$activities_id,'status'=>1])->select();
|
||||
return V(1,"成功", $bag_list);
|
||||
}
|
||||
//--------------------------盲盒转盘与巡乐会-------------------------------------------------------
|
||||
|
||||
/*
|
||||
* 巡乐会规则详情
|
||||
*/
|
||||
public function xunlehui_rule_detail(){
|
||||
$gift_bag_id = 13;
|
||||
$gift_bag = db::name('vs_gift_bag')->where(['id'=>$gift_bag_id])->find();
|
||||
$ext_data = json_decode($gift_bag['ext'],true);
|
||||
$ext_data['introd'] = stripcslashes($ext_data['introd']);
|
||||
$bag_list = db::name("vs_gift_bag")->field('id,name')->where(['activities_id'=>5,'status'=>1])->select();
|
||||
foreach ($bag_list as &$value) {
|
||||
$value['is_default'] = 0;
|
||||
if($value['id'] == $ext_data['inlet_bag_id']){
|
||||
$value['is_default'] = 1;
|
||||
}
|
||||
}
|
||||
$ext_data['bag_list'] = $bag_list;
|
||||
if($gift_bag){
|
||||
return V(1,"成功",$ext_data);
|
||||
}else{
|
||||
return V(0,"失败");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 巡乐会规则设置
|
||||
*/
|
||||
public function xunlehui_set_rule(){
|
||||
$gift_bag_id = 13;
|
||||
$inlet_bag_id = input('inlet_bag_id', '');
|
||||
$waiting_start_num = input('waiting_start_num', '');
|
||||
$start_num = input('start_num', '');
|
||||
$selected_gift_id = input('selected_gift_id', '');
|
||||
$locking_gift_id = input('locking_gift_id', '');
|
||||
$give_homeowner_gift_id = input('give_homeowner_gift_id', '');
|
||||
$end_time = input('end_time', '');
|
||||
$tow_no_locking_time = input('tow_no_locking_time', '');
|
||||
$next_time = input('next_time', '');
|
||||
$introd =$_POST['introd']??"";
|
||||
$price = input('price', '');
|
||||
if(empty($inlet_bag_id)){
|
||||
return V(0,"请选择巡乐会绑定入口");
|
||||
}
|
||||
$ext =[
|
||||
'inlet_bag_id' => $inlet_bag_id,
|
||||
'gift_id' => $selected_gift_id,
|
||||
'xlh_box_price' => $price,
|
||||
'open_condition' => [
|
||||
'waiting_start_num' => $waiting_start_num,
|
||||
'start_num' => $start_num,
|
||||
],
|
||||
'locking_condition' => [
|
||||
'selected_gift_id' => $selected_gift_id,
|
||||
'locking_gift_id' => $locking_gift_id,
|
||||
'give_homeowner_gift_id' => $give_homeowner_gift_id,
|
||||
],
|
||||
'locking_time' => [
|
||||
'end_time' => $end_time,
|
||||
'tow_no_locking_time' => $tow_no_locking_time,
|
||||
'next_time' => $next_time,
|
||||
],
|
||||
'introd' => $introd,
|
||||
];
|
||||
$ext = json_encode($ext);
|
||||
$res = db::name('vs_gift_bag')->where(['id'=>$gift_bag_id])->update(['ext'=>$ext]);
|
||||
if($res){
|
||||
//删除缓存
|
||||
$cacheKey = "xlh_config_13";
|
||||
cache::rm($cacheKey);
|
||||
return V(1,"成功");
|
||||
}else{
|
||||
return V(0,"失败");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 盲盒转盘统计
|
||||
*
|
||||
*/
|
||||
public function blind_box_turntable_lists(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$gift_id = input('gift_id', '');
|
||||
$gift_name = input('gift_name', '');
|
||||
$gift_bag_id = input('gift_bag_id', 10);
|
||||
$room_id = input('room_id', '');
|
||||
if(empty($gift_bag_id)){
|
||||
return V(0,"请选择盲盒类型");
|
||||
}
|
||||
$room = db::name('vs_room')->where(['id'=>$room_id])->find();
|
||||
if(empty($room)){
|
||||
return V(0,"房间不存在");
|
||||
}
|
||||
if($room['is_open_blind_box_turntable'] !=1){
|
||||
return V(0,"该房间未开启盲盒转盘");
|
||||
}
|
||||
$bag_data = db::name("vs_gift_bag")->find($gift_bag_id);
|
||||
$bag_list = db::name("vs_gift_bag")->field('id,name')->where(['activities_id'=>$bag_data['activities_id'],'status'=>1])->select();
|
||||
foreach ($bag_list as &$v) {
|
||||
$v['default'] = $gift_bag_id == $v['id'] ? 1 : 0;
|
||||
}
|
||||
$where=[];
|
||||
$where['gift_bag_id'] = $gift_bag_id;
|
||||
if($gift_id!==''){
|
||||
$where['foreign_id'] =$gift_id;
|
||||
}
|
||||
if($gift_name!==''){
|
||||
$where['name'] = ['like', '%'.$gift_name.'%'];
|
||||
}
|
||||
$count = db::name($this->table)->where($where)->count();
|
||||
$lists_data = db::name($this->table)->where($where)->page($page, $page_limit)->order("id desc")->select();
|
||||
$lists = [];
|
||||
$periods =1;
|
||||
foreach ($lists_data as $key => $value) {
|
||||
$lists[$key]['id'] = $value['id'];
|
||||
$lists[$key]['gift_id'] = $value['foreign_id'];
|
||||
$lists[$key]['gift_name'] = $value['name'];
|
||||
$gift_data = db::name('vs_gift')->where(['gid'=>$value['foreign_id']])->find();
|
||||
$lists[$key]['base_image'] = $gift_data['base_image'];
|
||||
$lists[$key]['gift_price'] = $gift_data['gift_price'];
|
||||
$lists[$key]['quantity'] = $value['quantity'];
|
||||
$room_pan = db::name('vs_room_pan')->where(['room_id'=>$room_id,'gift_bag_detail_id'=>$value['id']])->find();
|
||||
$lists[$key]['remaining_number'] = $room_pan['remaining_number'] ?? 0;
|
||||
$lists[$key]['is_public_screen'] = $gift_data['is_public_screen'];
|
||||
$lists[$key]['is_public_server'] = $gift_data['is_public_server'];
|
||||
$lists[$key]['is_world_show'] = $value['is_world_show'];
|
||||
$lists[$key]['weight'] = $value['weight'];
|
||||
$lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
$periods = $room_pan['periods']??1;
|
||||
}
|
||||
//统计
|
||||
$total_data = [];
|
||||
//每期总次数
|
||||
$total_count = db::name($this->table)->where(['gift_bag_id'=>$gift_bag_id])->sum('quantity');
|
||||
//每期总礼物价值
|
||||
$total_price_data = db::name($this->table)->alias('a')
|
||||
->field('a.quantity,b.gift_price,b.gift_price * a.quantity as total_price')
|
||||
->join('vs_gift b','a.foreign_id = b.gid')
|
||||
->where(['a.gift_bag_id'=>$gift_bag_id])
|
||||
->select();
|
||||
$total_price = array_sum(array_column($total_price_data,'total_price'));
|
||||
//每期总抽奖花费(支出)
|
||||
$bag_data = db::name("vs_gift_bag")->field('id,name,ext')->where(['id'=>$gift_bag_id])->find();
|
||||
$ext = json_decode($bag_data['ext'],true);
|
||||
$c_gift_id = $ext['gift_id'];
|
||||
$c_gift_data = db::name('vs_gift')->where(['gid'=>$c_gift_id])->find();
|
||||
$gift_price = $c_gift_data['gift_price']??0;
|
||||
$total_cost = $total_count * $gift_price;
|
||||
//每期统计(收入/支出)
|
||||
if($total_cost==0 || $total_price==0){
|
||||
$profit_loss_ratio = 0;
|
||||
}else{
|
||||
$profit_loss_ratio =round(($total_price / $total_cost ),2);
|
||||
}
|
||||
//今天抽奖人数
|
||||
$today_count_user = db::name('vs_gift_bag_receive_log')
|
||||
->where(['gift_bag_id'=>$gift_bag_id,'createtime'=>['between',[strtotime(date('Y-m-d')),time()]]])
|
||||
->group('user_id')
|
||||
->count();
|
||||
//今日抽奖总次数
|
||||
$today_total_count = db::name('vs_gift_bag_receive_log')
|
||||
->where(['gift_bag_id'=>$gift_bag_id,'createtime'=>['between',[strtotime(date('Y-m-d')),time()]]])
|
||||
->count();
|
||||
//今日抽奖收入
|
||||
$today_total_price = db::name('vs_gift_bag_receive_log')
|
||||
->where(['gift_bag_id'=>$gift_bag_id,'createtime'=>['between',[strtotime(date('Y-m-d')),time()]]])
|
||||
->sum('bag_price');
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
'bag_list' => $bag_list,
|
||||
'total_data' => [
|
||||
'blind_box_turntable_periods' => $periods, //当前期数
|
||||
'remaining_number' => db::name('vs_room_pan')->where(['room_id'=>$room_id,'gift_bag_id'=>$gift_bag_id])->sum('remaining_number')??'0',
|
||||
'total_count' => $total_count,
|
||||
'total_price' => $total_price,
|
||||
'total_cost' => $total_cost,
|
||||
'profit_loss_ratio' => $profit_loss_ratio,
|
||||
'today_count_user' => $today_count_user,
|
||||
'today_total_count' => $today_total_count,
|
||||
'today_total_price' => $today_total_price,
|
||||
]
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
/*
|
||||
* 盲盒转盘开奖记录
|
||||
*
|
||||
*/
|
||||
public function blind_box_turntable_open_record(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$gift_id = input('gift_id', '');
|
||||
$user_id = input('user_id', '');
|
||||
$room_id = input('room_id', '');
|
||||
$gift_bag_id = input('gift_bag_id', '');
|
||||
$periods = input('periods', '');
|
||||
$stime = input('stime', '');
|
||||
$etime = input('etime', '');
|
||||
$where = [];
|
||||
if($room_id){
|
||||
$where['room_id'] = $room_id;
|
||||
}
|
||||
if($gift_id){
|
||||
$where['gift_id'] = $gift_id;
|
||||
}
|
||||
if($user_id){
|
||||
$user_id = db::name('user')->where('user_code', $user_id)->value('id');
|
||||
$where['user_id'] = $user_id;
|
||||
}
|
||||
if($gift_bag_id){
|
||||
$where['gift_bag_id'] = $gift_bag_id;
|
||||
}else{
|
||||
$where['gift_bag_id'] = ['in',[10,11,12]];
|
||||
}
|
||||
if($periods){
|
||||
$where['periods'] = $periods;
|
||||
}
|
||||
if($stime!==""){
|
||||
$where['createtime'] = ['>=', strtotime($stime)];
|
||||
}
|
||||
if($etime!==""){
|
||||
$where['createtime'] = ['<=', strtotime($etime.'23:59:59')];
|
||||
}
|
||||
if($stime!=="" && $etime!==""){
|
||||
$where['createtime'] = ['between', [strtotime($stime), strtotime($etime.'23:59:59')]];
|
||||
}
|
||||
$count = db::name('vs_gift_bag_receive_pan_log')->where($where)->count();
|
||||
$lists_data = db::name('vs_gift_bag_receive_pan_log')->where($where)->page($page, $page_limit)->order("id desc")->select();
|
||||
$lists = [];
|
||||
foreach ($lists_data as $key => $value) {
|
||||
$lists[$key]['id'] = $value['id'];
|
||||
$lists[$key]['user_id'] = $value['user_id'];
|
||||
$user = db::name('user')->where('id',$value['user_id'])->find();
|
||||
$lists[$key]['user_name'] = "";
|
||||
if($user){
|
||||
$lists[$key]['user_name'] = $user['user_code'].'-'.$user['nickname'];
|
||||
}
|
||||
|
||||
$lists[$key]['gift_user_id'] = $value['gift_user_id'];
|
||||
$gift_user = db::name('user')->where('id',$value['gift_user_id'])->find();
|
||||
$lists[$key]['gift_user_name'] = "";
|
||||
if($gift_user){
|
||||
$lists[$key]['gift_user_name'] = $gift_user['user_code'].'-'.$gift_user['nickname'];
|
||||
}
|
||||
$lists[$key]['gift_bag_type'] = db::name('vs_gift_bag')->where('id',$value['gift_bag_id'])->value('name');
|
||||
$lists[$key]['periods'] = $value['periods'];
|
||||
$room = db::name('vs_room')->where('id',$value['room_id'])->find();
|
||||
$lists[$key]['room_name'] = "";
|
||||
if($room){
|
||||
$lists[$key]['room_name'] = $room['room_number']."-".$room['room_name'];
|
||||
}
|
||||
$lists[$key]['bag_price'] = $value['bag_price']*$value['num'];
|
||||
$lists[$key]['gift_id'] = $value['gift_id'];
|
||||
$lists[$key]['gift_name'] = db::name('vs_gift')->where('gid',$value['gift_id'])->value('gift_name');
|
||||
$lists[$key]['gift_price'] = $value['gift_price'];
|
||||
$lists[$key]['gift_num'] = $value['num'];
|
||||
$lists[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
||||
}
|
||||
$all_lists_data = db::name('vs_gift_bag_receive_pan_log')->where($where)->order("id desc")->select();
|
||||
$total =0;
|
||||
$total_gift_money = 0;
|
||||
$total_money = 0;
|
||||
foreach ($all_lists_data as $key => $value) {
|
||||
$total += $value['num'];//总抽奖次数
|
||||
$total_gift_money += $value['gift_price'] * $value['num']; //总礼物价值(收入)
|
||||
$total_money += $value['bag_price'] * $value['num']; //总抽奖金额(支出)
|
||||
}
|
||||
//统计
|
||||
if($total_gift_money==0 || $total_money==0){
|
||||
$ratio = 0;
|
||||
}else{
|
||||
$ratio =round(($total_gift_money / $total_money),3);
|
||||
}
|
||||
//用户盈亏
|
||||
$profit_loss = $total_gift_money - $total_money;
|
||||
//平台盈亏
|
||||
$platform_profit_loss = $total_money - $total_gift_money;
|
||||
if($profit_loss==0 || $total_money==0){
|
||||
$profit_loss_ratio = 0;
|
||||
$platform_profit_loss_ratio = 0;
|
||||
}else{
|
||||
// 盈亏比
|
||||
$profit_loss_ratio = round(($profit_loss / $total_money),3);
|
||||
//平台盈亏比
|
||||
$platform_profit_loss_ratio = round(($platform_profit_loss / $total_money),3);
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
'total_data' => [
|
||||
'total' => $total,
|
||||
'total_money' => $total_money,
|
||||
'total_gift_money' => $total_gift_money,
|
||||
'ratio' => $ratio,
|
||||
'profit_loss' => $profit_loss,
|
||||
'profit_loss_ratio' => $profit_loss_ratio,
|
||||
'platform_profit_loss' => $platform_profit_loss,
|
||||
'platform_profit_loss_ratio' => $platform_profit_loss_ratio,
|
||||
]
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
/*
|
||||
* 寻乐会锁定记录
|
||||
*
|
||||
*/
|
||||
public function xlh_lock_record(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$gift_id = input('gift_id', '');
|
||||
$user_id = input('user_id', '');
|
||||
$room_id = input('room_id', 0);
|
||||
$periods = input('periods', '');
|
||||
$where = [];
|
||||
if($room_id){
|
||||
$where['b.room_id'] = $room_id;
|
||||
}
|
||||
if($gift_id){
|
||||
$where['b.gift_id'] = $gift_id;
|
||||
}
|
||||
if($user_id){
|
||||
$user_id = db::name('user')->where('user_code', $user_id)->value('id');
|
||||
$where['b.user_id'] = $user_id;
|
||||
}
|
||||
if($periods){
|
||||
$where['b.periods'] = $periods;
|
||||
}
|
||||
|
||||
$count = db::name('vs_room_pan_xlh_log')->alias('a')
|
||||
->join('vs_room_pan_xlh b', 'a.xlh_id = b.id')
|
||||
->where($where)->count();
|
||||
$lists_data = db::name('vs_room_pan_xlh_log')->alias('a')
|
||||
->join('vs_room_pan_xlh b', 'a.xlh_id = b.id')
|
||||
->field('a.id,b.periods as periods,a.user_id,a.createtime,b.user_id,b.room_id,b.gift_id,b.num,a.is_send,b.pay_price,b.locking_gift_id')
|
||||
->where($where)
|
||||
->page($page, $page_limit)
|
||||
->order("id desc")
|
||||
->select();
|
||||
$lists = [];
|
||||
foreach ($lists_data as $key => $value) {
|
||||
$lists[$key]['id'] = $value['id'];
|
||||
$lists[$key]['periods'] = $value['periods'];
|
||||
$user = db::name('user')->field('user_code,nickname')->where('id',$value['user_id'])->find();
|
||||
$lists[$key]['user'] = $user['user_code']."-".$user['nickname'];
|
||||
//支付价格
|
||||
$lists[$key]['pay_price'] = $value['pay_price'];
|
||||
$gift = db::name('vs_gift')->field('gid,gift_name,gift_price')->where('gid',$value['locking_gift_id'])->find();
|
||||
$lists[$key]['gift_id'] = $value['locking_gift_id'];
|
||||
$lists[$key]['gift_name'] = $gift['gift_name']??"";
|
||||
$lists[$key]['gift_price'] = $gift['gift_price']??0;
|
||||
$lists[$key]['locking_num'] = $value['num'];
|
||||
$lists[$key]['is_send'] = $value['is_send'];
|
||||
$lists[$key]['is_send_str'] = $value['is_send']==1?"是":"否";
|
||||
$lists[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
||||
$room = db::name('vs_room')->where('id',$value['room_id'])->find();
|
||||
$lists[$key]['room_name'] = "";
|
||||
if($room){
|
||||
$lists[$key]['room_name'] = $room['room_number']."-".$room['room_name'];
|
||||
}
|
||||
}
|
||||
//今日锁定礼物数量
|
||||
$today = strtotime(date('Y-m-d'));
|
||||
$locking_num = db::name('vs_room_pan_xlh_log')->alias('a')
|
||||
->join('vs_room_pan_xlh b', 'a.xlh_id = b.id')
|
||||
->where('a.createtime','>=',$today)->where(['a.is_send'=>1,'b.room_id'=>$room_id])->sum('a.num');
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $lists,
|
||||
'locking_num' => $locking_num
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class Decorate extends adminApi
|
||||
$return_list[$k]['type_str'] = model('api/Decorate')->TypeArray[$v['type']];
|
||||
$return_list[$k]['base_image'] = $v['base_image'];
|
||||
$return_list[$k]['file_type'] = $v['file_type'];
|
||||
$return_list[$k]['file_type_str'] = $v['file_type'] ? "SVGA" : "MP4";
|
||||
$return_list[$k]['file_type_str'] = $v['file_type']==1 ? "SVGA" : "MP4";
|
||||
$return_list[$k]['play_image'] = $v['play_image'];
|
||||
$return_list[$k]['show_status'] = $v['show_status'];
|
||||
$return_list[$k]['is_buy'] = $v['is_buy'];
|
||||
@@ -327,6 +327,7 @@ class Decorate extends adminApi
|
||||
$type = input('type', '');
|
||||
$where = [];
|
||||
if($user_id!=""){
|
||||
$user_id = db::name('user')->where('user_code', $user_id)->value('id');
|
||||
$where['user_id'] = $user_id;
|
||||
}
|
||||
if($did!=""){
|
||||
@@ -340,7 +341,8 @@ class Decorate extends adminApi
|
||||
$return_list = [];
|
||||
foreach ($lists as $k=>$v){
|
||||
$return_list[$k]['id'] = $v['udid'];
|
||||
$return_list[$k]['user_name'] = $v['user_id']."-".db::name('user')->where(['id'=>$v['user_id']])->value('nickname');
|
||||
$user_data = db::name('user')->where(['id'=>$v['user_id']])->find();
|
||||
$return_list[$k]['user_name'] = $user_data['user_code']."-".db::name('user')->where(['id'=>$v['user_id']])->value('nickname');
|
||||
$return_list[$k]['type'] = model('api/Decorate')->TypeArray[$v['type']];
|
||||
if($v['type'] >= 6){
|
||||
$return_list[$k]['name'] = $v['special_num'];
|
||||
@@ -374,10 +376,11 @@ class Decorate extends adminApi
|
||||
$user_id = input('user_id', '');
|
||||
$decorate_id = input('decorate_id', '');
|
||||
$day = input('day', '');
|
||||
$user = db::name('user')->where(['id'=>$user_id])->find();
|
||||
$user = db::name('user')->where(['user_code'=>$user_id])->find();
|
||||
if(!$user){
|
||||
return V(0,"用户不存在");
|
||||
}
|
||||
$user_id = $user['id'];
|
||||
$decorate = db::name('vs_decorate')->where(['did'=>$decorate_id])->find();
|
||||
if(!$decorate){
|
||||
return V(0,"装扮不存在");
|
||||
|
||||
@@ -44,7 +44,12 @@ class Gift extends adminApi
|
||||
}
|
||||
}
|
||||
if($type == 2){
|
||||
$giftTypeData = db::name('vs_gift_label')->where('delete_time',0)->order("sort asc,id desc")->select();
|
||||
$type_id = input('type_id', 0);
|
||||
$where['delete_time'] = 0;
|
||||
if(!empty($type_id)){
|
||||
$where['tid'] = $type_id;
|
||||
}
|
||||
$giftTypeData = db::name('vs_gift_label')->where($where)->order("sort asc,id desc")->select();
|
||||
foreach ($giftTypeData as $key => $value) {
|
||||
$giftType[$key]['id'] = $value['id'];
|
||||
$giftType[$key]['name'] = $value['name'];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller;
|
||||
|
||||
ini_set('memory_limit', '512M'); // 临时增加到512MB
|
||||
use app\common\controller\adminApi;
|
||||
use think\Db;
|
||||
|
||||
@@ -54,12 +54,14 @@ class GiveGift extends adminApi
|
||||
$where['from'] = $from;
|
||||
}
|
||||
// 时间筛选优化
|
||||
if(!empty($start_time) && !empty($end_time)){
|
||||
$where['createtime'] = ['between', [strtotime($start_time), strtotime($end_time.' 23:59:59')]];
|
||||
} elseif(!empty($start_time)){
|
||||
$where['createtime'] = ['>=', strtotime($start_time)];
|
||||
} elseif(!empty($end_time)){
|
||||
$where['createtime'] = ['<=', strtotime($end_time.' 23:59:59')];
|
||||
if (!empty($start_time) || !empty($end_time)) {
|
||||
if (!empty($start_time) && !empty($end_time)) {
|
||||
$where['createtime'] = ['between', [strtotime($start_time), strtotime($end_time)]];
|
||||
} elseif (!empty($start_time)) {
|
||||
$where['createtime'] = ['>=', strtotime($start_time)];
|
||||
} elseif (!empty($end_time)) {
|
||||
$where['createtime'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
}
|
||||
//礼物总数
|
||||
$gift_num = db::name('vs_give_gift')->where($where)->sum('number');
|
||||
@@ -73,24 +75,32 @@ class GiveGift extends adminApi
|
||||
$room_owner_earning = 0;
|
||||
|
||||
// 获取所有送礼记录
|
||||
$list = db::name('vs_give_gift')->where($where)->order('id', 'desc')->select();
|
||||
$gift_ids = array_column($list, 'id');
|
||||
if (!empty($gift_ids)) {
|
||||
$lists = db::name('vs_give_gift')->where($where)->order('id', 'desc')->page($page, $page_limit)->select();
|
||||
$count = db::name('vs_give_gift')->where($where)->count();
|
||||
$earning_list = [];
|
||||
if(!empty($where)){
|
||||
$gift_ids = db::name('vs_give_gift')->where($where)->column('id');
|
||||
if (!empty($gift_ids)) {
|
||||
// 批量获取所有收益记录
|
||||
$earning_list = db::name('vs_give_gift_ratio_log')
|
||||
->field('app_earning,gift_user_earning,room_owner_earning')
|
||||
->where('give_gift_id', 'in', $gift_ids)
|
||||
->order('id', 'desc')
|
||||
->select();
|
||||
}
|
||||
}else{
|
||||
// 批量获取所有收益记录
|
||||
$earning_list = db::name('vs_give_gift_ratio_log')
|
||||
->where('give_gift_id', 'in', $gift_ids)
|
||||
->field('app_earning,gift_user_earning,room_owner_earning')
|
||||
->order('id', 'desc')
|
||||
->select();
|
||||
|
||||
// 计算总收益
|
||||
foreach ($earning_list as $earning) {
|
||||
$app_earning += $earning['app_earning'];
|
||||
$receive_earning += $earning['gift_user_earning'];
|
||||
$room_owner_earning += $earning['room_owner_earning'];
|
||||
}
|
||||
}
|
||||
$count = count($list);
|
||||
$lists = $this->array_pagination($list, $page, $page_limit);
|
||||
// 计算总收益
|
||||
foreach ($earning_list as $earning) {
|
||||
$app_earning += $earning['app_earning'];
|
||||
$receive_earning += $earning['gift_user_earning'];
|
||||
$room_owner_earning += $earning['room_owner_earning'];
|
||||
}
|
||||
|
||||
// 提取所有需要关联查询的ID
|
||||
$user_ids = array_merge(
|
||||
|
||||
@@ -88,7 +88,7 @@ class Guild extends adminApi
|
||||
$list[$k]['status_str'] = $v['status'] == 1 ? '正常' : '解散';
|
||||
$list[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
$list[$k]['updatetime'] = date('Y-m-d H:i:s',$v['updatetime']);
|
||||
$list[$k]['user_id'] = $user['user_code'];
|
||||
$list[$k]['user_id'] = $user['user_code']??"";
|
||||
$list[$k]['intro'] = $v['intro'];
|
||||
}
|
||||
// 数组按today_money 排序
|
||||
@@ -170,7 +170,13 @@ class Guild extends adminApi
|
||||
}
|
||||
//会长是否有房间
|
||||
$rid = 0;
|
||||
$room_info = db::name('vs_room')->where('user_id', $user_id)->find();
|
||||
$where = [
|
||||
'user_id' => $user_id,
|
||||
'delete_time' => 0
|
||||
];
|
||||
$where['apply_status'] = 2;//1待审核 2审核通过 3审核失败
|
||||
$where['type_id'] = ['<>',6];
|
||||
$room_info = db::name('vs_room')->where($where)->find();
|
||||
if($room_info){
|
||||
$rid = $room_info['id'];
|
||||
}
|
||||
@@ -288,9 +294,9 @@ class Guild extends adminApi
|
||||
$res = model('Guild')->edit(['id'=>$id],['status'=>2,'delete_time'=>time()]);
|
||||
|
||||
if($res){
|
||||
db('vs_guild_user')->where(['guild_id'=>$id,'quit_type'=>0])->update(['quit_type'=>3,'quit_time'=>time()]);
|
||||
db('vs_guild_user')->where(['guild_id'=>$id,'quit_type'=>0])->update(['quit_type'=>3,'quit_time'=>time(),'delete_time'=>time()]);
|
||||
//解散群
|
||||
model('Tencent')->delete_group('g'.$id);
|
||||
model('api/Tencent')->delete_group('g'.$id);
|
||||
return V(1,"解散成功");
|
||||
}else{
|
||||
return V(0,"解散失败");
|
||||
@@ -336,9 +342,9 @@ class Guild extends adminApi
|
||||
$rum_lists[$k]['id']=$v['id'];
|
||||
$rum_lists[$k]['user_id']=$v['user_id'];
|
||||
$rum_lists[$k]['user_code']=model('api/Decorate')->user_decorate_detail($v['user_id'],6);
|
||||
$rum_lists[$k]['nickname']=$user_info['nickname'];
|
||||
$rum_lists[$k]['charm_level']=$user_info['charm_level'];
|
||||
$rum_lists[$k]['wealth_level']=$user_info['wealth_level'];
|
||||
$rum_lists[$k]['nickname']=$user_info['nickname']?? '';
|
||||
$rum_lists[$k]['charm_level']=$user_info['charm_level']??0;
|
||||
$rum_lists[$k]['wealth_level']=$user_info['wealth_level']??0;
|
||||
//用户流水
|
||||
$consumption_sql = db::name('vs_user_money_log')
|
||||
->whereIn('change_type',$coin_consumption_type_array)
|
||||
@@ -390,15 +396,28 @@ class Guild extends adminApi
|
||||
}
|
||||
$count = db::name($this->table_guild_user)->alias('a')
|
||||
->join('vs_room b', 'a.room_id = b.id', 'left')
|
||||
->where(['a.guild_id'=>$guild_id,'a.quit_type'=>['in',[0,3]]])->where($where)->count();
|
||||
->where(['a.guild_id'=>$guild_id])->where($where)->count();
|
||||
$list = db::name($this->table_guild_user)->alias('a')
|
||||
->join('vs_room b', 'a.room_id = b.id', 'left')
|
||||
->where(['a.guild_id'=>$guild_id,'a.quit_type'=>['in',[0,3]]])->where($where)->page($page, $page_limit)->select();
|
||||
->where(['a.guild_id'=>$guild_id])->where($where)->page($page, $page_limit)->select();
|
||||
if(!$list){
|
||||
return V(0,"暂无数据");
|
||||
}
|
||||
$rum_lists = [];
|
||||
foreach ($list as $k=>$v){
|
||||
if($search_stime!="" && $v['createtime'] < strtotime($search_stime)){
|
||||
$search_stime = $search_stime;
|
||||
}else{
|
||||
$search_stime = date('Y-m-d H:i:s',$v['createtime']) ;
|
||||
}
|
||||
if($v['quit_time']){
|
||||
if($search_etime!="" && $v['quit_time'] > strtotime($search_etime)){
|
||||
$search_etime = $search_etime;
|
||||
}else{
|
||||
$search_etime = date('Y-m-d H:i:s',$v['quit_time']);
|
||||
}
|
||||
}
|
||||
|
||||
$room_info = db::name('vs_room')->where(['id'=>$v['room_id']])->find();
|
||||
$rum_lists[$k]['id']=$v['id'];
|
||||
$rum_lists[$k]['room_id']=$v['room_id'];
|
||||
@@ -617,12 +636,14 @@ class Guild extends adminApi
|
||||
$search_status_time = input('search_status_time', '');
|
||||
$search_end_time = input('search_end_time', '');
|
||||
$search_status = input('search_status', '');
|
||||
$where = ['b.delete_time'=>0];
|
||||
// $where = ['b.delete_time'=>0];
|
||||
$where = [];
|
||||
if($search_user_id){
|
||||
$where['b.user_id'] = $search_user_id;
|
||||
}
|
||||
if($search_guild_id){
|
||||
$where['a.guild_id'] = $search_guild_id;
|
||||
//$where['a.guild_id'] = $search_guild_id;
|
||||
$where['b.guild_special_id'] = $search_guild_id;
|
||||
}
|
||||
if($search_status_time){
|
||||
$where['a.start_time'] = ['>=', $search_status_time];
|
||||
|
||||
@@ -54,6 +54,15 @@ class Index extends adminApi
|
||||
//总待付款笔数
|
||||
$return_data['all_wait_pay_num'] = db::name('vs_user_recharge')->where('pay_status',1)->count();
|
||||
|
||||
//周实时收入金额
|
||||
$return_data['week_money'] = db::name('vs_user_recharge')->where('pay_status',2)->whereTime('pay_time', 'week')->sum('money');
|
||||
//上周收入金额
|
||||
$return_data['last_week_money'] = db::name('vs_user_recharge')->where('pay_status',2)->whereTime('pay_time', 'last week')->sum('money');
|
||||
//月收入金额
|
||||
$return_data['month_money'] = db::name('vs_user_recharge')->where('pay_status',2)->whereTime('pay_time', 'month')->sum('money');
|
||||
//上月收入金额
|
||||
$return_data['last_month_money'] = db::name('vs_user_recharge')->where('pay_status',2)->whereTime('pay_time', 'last month')->sum('money');
|
||||
|
||||
//待办事项
|
||||
//房间审核数
|
||||
$return_data['room_audit_num'] = db::name('vs_room')->where('apply_status',1)->count();
|
||||
@@ -114,17 +123,27 @@ class Index extends adminApi
|
||||
$return_data['register_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->whereTime('createtime', 'today')->count();
|
||||
//充值会员数
|
||||
$return_data['recharge_count'] = db::name('vs_user_recharge')->where('pay_status',2)->group('user_id')->count();
|
||||
//充值会员百分比
|
||||
$return_data['recharge_count_percent'] = round(($return_data['recharge_count'] / $return_data['member_count']) * 100);
|
||||
//未充值会员数
|
||||
$return_data['no_recharge_count'] = $return_data['member_count'] - $return_data['recharge_count'];
|
||||
$return_data['no_recharge_count_percent'] = round(($return_data['no_recharge_count'] / $return_data['member_count']) * 100);
|
||||
//IOS用户数
|
||||
$return_data['ios_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->where('system', 'iOS')->count();
|
||||
$return_data['ios_count_percent'] = round(($return_data['ios_count'] / $return_data['member_count']) * 100);
|
||||
//安卓用户数
|
||||
$return_data['android_count'] = $return_data['member_count']-$return_data['ios_count'];
|
||||
$return_data['android_count_percent'] = round(($return_data['android_count'] / $return_data['member_count']) * 100);
|
||||
if(empty($return_data['member_count'])){
|
||||
$return_data['recharge_count_percent'] = 0;
|
||||
$return_data['no_recharge_count'] = 0;
|
||||
$return_data['no_recharge_count_percent'] = 0;
|
||||
$return_data['no_recharge_count'] = 0;
|
||||
$return_data['ios_count_percent'] = 0;
|
||||
$return_data['android_count'] = 0;
|
||||
$return_data['android_count_percent'] = 0;
|
||||
}else{
|
||||
//充值会员百分比
|
||||
$return_data['recharge_count_percent'] = round(($return_data['recharge_count'] / $return_data['member_count']) * 100);
|
||||
//未充值会员数
|
||||
$return_data['no_recharge_count'] = $return_data['member_count'] - $return_data['recharge_count'];
|
||||
$return_data['no_recharge_count_percent'] = round(($return_data['no_recharge_count'] / $return_data['member_count']) * 100);
|
||||
//IOS用户数
|
||||
$return_data['ios_count'] = db::name('user')->where('status', 1)->where('is_robot', 0)->where('system', 'iOS')->count();
|
||||
$return_data['ios_count_percent'] = round(($return_data['ios_count'] / $return_data['member_count']) * 100);
|
||||
//安卓用户数
|
||||
$return_data['android_count'] = $return_data['member_count']-$return_data['ios_count'];
|
||||
$return_data['android_count_percent'] = round(($return_data['android_count'] / $return_data['member_count']) * 100);
|
||||
}
|
||||
|
||||
//礼物打赏实时统计
|
||||
//一个月内的礼物打赏
|
||||
|
||||
@@ -93,18 +93,19 @@ class Level extends adminApi
|
||||
if(!$level_id){
|
||||
return V(0,"添加失败");
|
||||
}
|
||||
//等级特权
|
||||
$decorate = db::name("vs_decorate")->where(['did' => $gift_id, 'delete_time' => 0])->find();
|
||||
if(empty($decorate)){
|
||||
return V(0,"请选择等级特权");
|
||||
}
|
||||
if($gift_id){
|
||||
if(!empty($gift_id)){
|
||||
//等级特权
|
||||
$decorate = db::name("vs_decorate")->where(['did' => $gift_id, 'delete_time' => 0])->find();
|
||||
if(empty($decorate)){
|
||||
return V(0,"请选择等级特权");
|
||||
}
|
||||
db::name('vs_wealth_level_rights')->insert([
|
||||
'level_id' => $level_id,
|
||||
'gift_id' => $gift_id,
|
||||
'createtime' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
return V(1,"成功", ['id'=>$level]);
|
||||
}
|
||||
/*
|
||||
@@ -163,6 +164,8 @@ class Level extends adminApi
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
db::name('vs_wealth_level_rights')->where(['level_id'=>$id])->delete();
|
||||
}
|
||||
$result = db::name($this->table_wealth_level)->where(['id'=>$id])->update($level_data);
|
||||
if(!$result){
|
||||
|
||||
@@ -186,7 +186,7 @@ class Room extends adminApi
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$search_name = input('search_name', '');
|
||||
$where=[];
|
||||
$where['deletetime'] = 0;
|
||||
//标签名称
|
||||
if($search_name!==''){
|
||||
$where['label_name'] = ['like', '%'.$search_name.'%'];
|
||||
@@ -237,7 +237,7 @@ class Room extends adminApi
|
||||
if(!$type_data){
|
||||
return V(0,"房间类型不存在");
|
||||
}
|
||||
$result = db::name($this->table_room_type)->where(['id'=>$type_id])->delete();
|
||||
$result = db::name($this->table_room_type)->where(['id'=>$type_id])->update(['deletetime'=>time()]);
|
||||
if(!$result){
|
||||
return V(0,"删除失败");
|
||||
}
|
||||
@@ -425,6 +425,12 @@ class Room extends adminApi
|
||||
$search_room_id = input('search_room_id', '');
|
||||
$search_user_id = input('search_user_id', '');
|
||||
$search_status = input('search_status', '');
|
||||
$type_id = input('type_id', '');
|
||||
$label_id = input('label_id', '');
|
||||
$is_hot = input('is_hot', '');
|
||||
$is_top = input('is_top', '');
|
||||
$is_recommend = input('is_recommend', '');
|
||||
|
||||
$where=[];
|
||||
//房间号
|
||||
if($search_room_id!==''){
|
||||
@@ -437,6 +443,21 @@ class Room extends adminApi
|
||||
if($search_status!==''){
|
||||
$where['room_status'] = $search_status;
|
||||
}
|
||||
if($type_id!==''){
|
||||
$where['type_id'] = $type_id;
|
||||
}
|
||||
if($label_id!==''){
|
||||
$where['label_id'] = $label_id;
|
||||
}
|
||||
if($is_hot!==''){
|
||||
$where['is_hot'] = $is_hot;
|
||||
}
|
||||
if($is_top!==''){
|
||||
$where['is_top'] = $is_top;
|
||||
}
|
||||
if($is_recommend!==''){
|
||||
$where['is_recommend'] = $is_recommend;
|
||||
}
|
||||
//房间列表只展示 审核通过的房间
|
||||
$where['apply_status'] = 2;//1待审核 2审核通过 3审核失败
|
||||
$where['type_id'] = ['<>',6];
|
||||
@@ -468,6 +489,8 @@ class Room extends adminApi
|
||||
$lists[$key]['guild_name'] = !empty($guild) ? $guild['guild_name'] : "";
|
||||
$lists[$key]['room_status_str'] = model('Room')->room_status[$value['room_status']];
|
||||
$lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
$lists[$key]['is_robot_num'] = $value['robot_num']==0 ? 1 : 2;
|
||||
$lists[$key]['is_open_blind_box_turntable_str'] = $value['is_open_blind_box_turntable'] == 1 ? '是' : '否';
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
@@ -516,6 +539,7 @@ class Room extends adminApi
|
||||
$room_data['room_type_str'] = db::name('vs_room_type')->where(['id'=>$room_data['type_id']])->value('type_name');
|
||||
$room_data['liang'] = model('api/Decorate')->user_decorate_detail($room_data['id'],7);
|
||||
$room_data['owner'] = db::name('user')->where(['id'=>$room_data['user_id']])->value('nickname');
|
||||
$room_data['is_robot_num'] = $room_data['robot_num']==0 ? 2 : 1;
|
||||
$room_data['guild_name'] = '';
|
||||
$guild_id = db::name('vs_guild_user')->where('user_id',$room_data['user_id'])->value('guild_id');
|
||||
if($guild_id){
|
||||
@@ -653,8 +677,8 @@ class Room extends adminApi
|
||||
}
|
||||
elseif ($type == 3){
|
||||
//周流水
|
||||
//周一
|
||||
$begin_time = strtotime(date('Y-m-d 24:00:00',strtotime('-'.date('w').'days')));
|
||||
//本周一
|
||||
$begin_time = strtotime(date('Y-m-d 00:00:00', strtotime('this week')));
|
||||
$end_time = time();
|
||||
$where['a.createtime'] = ['between', [$begin_time, $end_time]];
|
||||
}
|
||||
@@ -818,11 +842,16 @@ class Room extends adminApi
|
||||
//在用户表里找 $robot_num 个机器人 进入到房间
|
||||
$user_list = db::name('user')->field('id')->where('is_robot',1)->limit($robot_num)->orderRaw('rand()')->select();
|
||||
if($user_list){
|
||||
if(count($user_list) != $robot_num){
|
||||
return V(0,"机器人数量不足");
|
||||
}
|
||||
foreach ($user_list as $v){
|
||||
model('api/Room')->join_room($v['id'],$room_id,$room_password);
|
||||
}
|
||||
}else{
|
||||
return V(0,"没有可用机器人");
|
||||
}
|
||||
}elseif ($is_robot_num == 2 && $robot_num == 0){
|
||||
}elseif ($is_robot_num == 2 || $robot_num == 0){
|
||||
$data['robot_num'] = 0;
|
||||
//查询在房间中的机器人 并退出
|
||||
$user_list = db::name('vs_room_visitor')->alias('a')->join('user b','a.user_id = b.id','left')
|
||||
@@ -836,7 +865,16 @@ class Room extends adminApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$is_open_blind_box_turntable = input('is_open_blind_box_turntable', '');//是否开启盲盒转盘:0 否 1是
|
||||
if($is_open_blind_box_turntable !== ""){
|
||||
$data['is_open_blind_box_turntable'] = $is_open_blind_box_turntable;
|
||||
if($is_open_blind_box_turntable == 1){
|
||||
$room_data = db::name('vs_room')->find($room_id);
|
||||
if($room_data['is_open_blind_box_turntable'] == 0){
|
||||
model('Room')->bindPan($room_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = db::name('vs_room')->where('id',$room_id)->update($data);
|
||||
if($res){
|
||||
return V(1,"成功");
|
||||
@@ -909,9 +947,22 @@ class Room extends adminApi
|
||||
if($status){
|
||||
$data['status'] = $status;
|
||||
}
|
||||
$bg_url = db::name('vs_room_background')->where('id',$id)->value('image_url');
|
||||
|
||||
$res = db::name('vs_room_background')->where('id',$id)->update($data);
|
||||
if($res){
|
||||
if($bg_url != $image_url){
|
||||
//查询使用默认背景的房间
|
||||
$room_list = db::name('vs_room')->field('id,room_background')->where(['room_status' => ['<>',3]])->select();
|
||||
if($room_list){
|
||||
foreach ($room_list as $v){
|
||||
//判断是否使用默认背景,room_background 字段值是否是以 get_system_config_value('web_site') 开头
|
||||
if(strpos($v['room_background'],get_system_config_value('web_site')) !== FALSE){
|
||||
db::name('vs_room')->where('id',$v['id'])->update(['room_background' => $image_url]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return V(1,"成功");
|
||||
}
|
||||
else{
|
||||
@@ -962,6 +1013,10 @@ class Room extends adminApi
|
||||
$search_room_number = input('search_room_number', '');
|
||||
$search_onwer_number = input('search_onwer_number', '');
|
||||
$room_status = input('room_status', '');
|
||||
//开始 时间
|
||||
$start_time = input('start_time', '');
|
||||
//结束 时间
|
||||
$end_time = input('end_time', '');
|
||||
|
||||
if($search_room_number!==''){
|
||||
$where['room_number'] = $search_room_number;
|
||||
@@ -972,12 +1027,36 @@ class Room extends adminApi
|
||||
if($room_status!==''){
|
||||
$where['room_status'] = $room_status;
|
||||
}
|
||||
|
||||
// 检查并转换时间格式为时间戳
|
||||
if($start_time !== '' && $end_time !== ''){
|
||||
// 同时有开始和结束时间
|
||||
$startTime = strtotime($start_time);
|
||||
$endTime = strtotime($end_time);
|
||||
if($startTime !== false && $endTime !== false){
|
||||
$where['createtime'] = ['between', [$startTime, $endTime]];
|
||||
}
|
||||
}elseif($start_time !== ''){
|
||||
// 只有开始时间
|
||||
$startTime = strtotime($start_time);
|
||||
if($startTime !== false){
|
||||
$where['createtime'] = ['>=', $startTime];
|
||||
}
|
||||
}elseif($end_time !== ''){
|
||||
// 只有结束时间
|
||||
$endTime = strtotime($end_time);
|
||||
if($endTime !== false){
|
||||
$where['createtime'] = ['<=', $endTime];
|
||||
}
|
||||
}
|
||||
|
||||
$where['type_id'] = 6;
|
||||
$count = db::name('vs_room')->where($where)->count();
|
||||
$lists = db::name('vs_room')->field('id,room_name,room_cover,room_number,user_id,room_status,createtime')
|
||||
->where($where)
|
||||
->order('id desc')
|
||||
->page($page, $page_limit)->select();
|
||||
|
||||
foreach ($lists as &$value) {
|
||||
$guild = model('Guild')->getGuildByUserId($value['user_id']);
|
||||
$value['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
@@ -988,7 +1067,27 @@ class Room extends adminApi
|
||||
$value['room_code'] = model('api/Decorate')->user_decorate_detail($value['id'], 7);
|
||||
//房间状态1正常2封禁3关闭
|
||||
$value['room_status_str'] = $value['room_status'] ==1 ? "正常" : ($value['room_status'] ==2 ? "封禁" : "关闭");
|
||||
|
||||
$cpRoom = db::name('vs_room_cp_movie')->where('room_id',$value['id'])->find();
|
||||
if($cpRoom){
|
||||
if($cpRoom['user_id'] == $value['user_id']){
|
||||
$value['cp_nickname'] = db::name('user')->where('id', $cpRoom['user_id1'])->value('nickname');
|
||||
$value['cp_user_id'] = db::name('user')->where('id', $cpRoom['user_id1'])->value('user_code');
|
||||
}
|
||||
if($cpRoom['user_id1'] == $value['user_id']){
|
||||
$value['cp_nickname'] = db::name('user')->where('id', $cpRoom['user_id'])->value('nickname');
|
||||
$value['cp_user_id'] = db::name('user')->where('id', $cpRoom['user_id'])->value('user_code');
|
||||
}
|
||||
}
|
||||
|
||||
// 流水计算也应使用相同的时间范围
|
||||
$liushuiWhere = ['from_id' => $value['id']];
|
||||
if(isset($where['createtime'])){
|
||||
$liushuiWhere['createtime'] = $where['createtime'];
|
||||
}
|
||||
$value['liushui'] = db::name('vs_give_gift')->where($liushuiWhere)->sum('total_price') * get_system_config_value('coin_charm_exp');
|
||||
}
|
||||
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
@@ -998,6 +1097,7 @@ class Room extends adminApi
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
|
||||
|
||||
//Cp电影房封禁
|
||||
public function cp_movie_room_forbid()
|
||||
{
|
||||
@@ -1211,7 +1311,7 @@ class Room extends adminApi
|
||||
if($apply_status!==''){
|
||||
$where['apply_status'] = $apply_status;
|
||||
}else{
|
||||
$where['apply_status'] = ['<>',2];
|
||||
$where['apply_status'] = 1;
|
||||
}
|
||||
|
||||
$count = db::name($this->table)->where($where)->count();
|
||||
@@ -1238,6 +1338,7 @@ class Room extends adminApi
|
||||
//房间审核
|
||||
public function room_audit(){
|
||||
$id = input('id', '');
|
||||
$remark = input('remark', '');
|
||||
if($id == ''){
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
@@ -1245,10 +1346,40 @@ class Room extends adminApi
|
||||
if($apply_status == ''){
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
$result = db::name('vs_room')->where(['id'=>$id])->update(['apply_status'=>$apply_status]);
|
||||
$room_data = db::name('vs_room')->where(['id'=>$id])->find();
|
||||
if(!$room_data){
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
$result = db::name('vs_room')->where(['id'=>$id])->update([
|
||||
'apply_status'=>$apply_status,
|
||||
'is_open_blind_box_turntable'=>1,
|
||||
'updatetime'=>time(),
|
||||
]);
|
||||
if(!$result){
|
||||
return V(0,"修改失败");
|
||||
}
|
||||
|
||||
//发系统信息
|
||||
if($apply_status ==2){
|
||||
$deal_content = '审核通过';
|
||||
}elseif($apply_status ==3){
|
||||
$deal_content = '审核未通过';
|
||||
}
|
||||
if(!empty($remark)){
|
||||
$deal_content .= ',原因:'.$remark;
|
||||
}
|
||||
db::name('system_message')->insert([
|
||||
'title' => '房间审核结果',
|
||||
'content' => '您创建的房间'.$room_data['room_name'].$deal_content,
|
||||
'type' => 1,
|
||||
'admin_id' => Session::get('admin_id'),
|
||||
'receiving_id' => $room_data['user_id'],
|
||||
'createtime' => time(),
|
||||
]);
|
||||
|
||||
//房间绑定盘
|
||||
model('Room')->bindPan($id);
|
||||
|
||||
return V(1,"成功");
|
||||
}
|
||||
|
||||
@@ -1404,10 +1535,10 @@ class Room extends adminApi
|
||||
$where['createtime'] = ['>=',strtotime($stime)];
|
||||
}
|
||||
if(!empty($etime)){
|
||||
$where['createtime'] = ['<=',strtotime($etime.' 23:59:59')];
|
||||
$where['createtime'] = ['<=',strtotime($etime)];
|
||||
}
|
||||
if(!empty($stime) && !empty($etime)){
|
||||
$where['createtime'] = ['between',[strtotime($stime),strtotime($etime.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($stime),strtotime($etime)]];
|
||||
}
|
||||
$room_log_lists = db::name($this->table_room_log)->where($where)->order('id desc')->page($page, $page_limit)->select();
|
||||
$count = db::name($this->table_room_log)->where($where)->count();
|
||||
@@ -1575,4 +1706,183 @@ class Room extends adminApi
|
||||
return V(1,"成功", $result);
|
||||
}
|
||||
|
||||
// 房间红包列表
|
||||
public function room_redpacket_list(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 30);
|
||||
$room_id = input('room_id', '');
|
||||
//红包状态
|
||||
$status = input('status', '');
|
||||
//发红包的时间
|
||||
$stime = input('stime', '');
|
||||
$etime = input('etime', '');
|
||||
$where = [];
|
||||
if($room_id){
|
||||
$where['room_id'] = $room_id;
|
||||
}
|
||||
if($status){
|
||||
$where['status'] = $status;
|
||||
}
|
||||
if($stime){
|
||||
$where['createtime'] = ['>=',strtotime($stime)];
|
||||
}
|
||||
if($etime){
|
||||
$where['createtime'] = ['<=',strtotime($etime)];
|
||||
}
|
||||
$count = db::name("redpacket")->where($where)->count();
|
||||
$room_redpacket_lists = db::name("redpacket")->where($where)->page($page, $page_limit)->order('id desc')->select();
|
||||
//循环数据 获取发红的昵称和头像 时间格式化 状态:0=未开始,1=进行中,2=已结束,3=已退回' 币种(coin_type):1=金币,2=钻石',红包类型(type):1=普通红包,2=口令红包'
|
||||
//多选条件(逗号分隔存值)(conditions) 0=无,1=收藏,2=在麦上
|
||||
if($room_redpacket_lists){
|
||||
foreach ($room_redpacket_lists as $key => $value){
|
||||
$room_redpacket_lists[$key]['nickname'] = db::name('user')->where(['id'=>$value['user_id']])->value('nickname');
|
||||
$room_redpacket_lists[$key]['avatar'] = db::name('user')->where(['id'=>$value['user_id']])->value('avatar');
|
||||
$room_redpacket_lists[$key]['user_code'] = db::name('user')->where(['id'=>$value['user_id']])->value('user_code');
|
||||
$room_redpacket_lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
$room_redpacket_lists[$key]['status_text'] = $value['status'] == 0 ? '未开始' : ($value['status'] == 1 ? '进行中' : ($value['status'] == 2 ? '已结束' : '已退回'));
|
||||
$room_redpacket_lists[$key]['coin_type_text'] = $value['coin_type'] == 1 ? '金币' : ($value['coin_type'] == 2 ? '钻石' : '未知');
|
||||
$room_redpacket_lists[$key]['type_text'] = $value['type'] == 1 ? '普通红包' : ($value['type'] == 2 ? '口令红包' : '未知');
|
||||
|
||||
// 多选条件处理:0=无(不能和其他条件共存),1=收藏,2=在麦上
|
||||
// 可以同时存在,也可以单独存在,同时存在时用逗号分隔
|
||||
$conditions = explode(',',$value['conditions']);
|
||||
// 过滤掉空值元素
|
||||
$conditions = array_filter($conditions, function($item) {
|
||||
return $item !== '' && $item !== null;
|
||||
});
|
||||
// 去除重复的条件
|
||||
$conditions = array_unique($conditions);
|
||||
// 重新索引数组,确保索引连续
|
||||
$conditions = array_values($conditions);
|
||||
|
||||
// 特殊处理:如果包含条件0(无条件),则只保留这一项
|
||||
if (in_array('0', $conditions)) {
|
||||
$room_redpacket_lists[$key]['conditions'] = ['无条件'];
|
||||
} else {
|
||||
// 将数字条件转换为对应的中文描述
|
||||
$conditions_text = array_map(function($item){
|
||||
// 0=无条件,1=收藏,2=在麦上
|
||||
switch($item) {
|
||||
case '0':
|
||||
return '无条件';
|
||||
case '1':
|
||||
return '收藏';
|
||||
case '2':
|
||||
return '在麦上';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}, $conditions);
|
||||
$room_redpacket_lists[$key]['conditions'] = $conditions_text;
|
||||
}
|
||||
//房间名称
|
||||
$room_redpacket_lists[$key]['room_name'] = db::name('vs_room')->where(['id'=>$value['room_id']])->value('room_name');
|
||||
}
|
||||
}
|
||||
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $room_redpacket_lists
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
|
||||
// 获取房间红包详情
|
||||
public function room_redpacket_detail(){
|
||||
// 红包ID
|
||||
$redpacket_id = input('redpacket_id', '');
|
||||
if(empty($redpacket_id)){
|
||||
return V(0, "红包ID不能为空");
|
||||
}
|
||||
|
||||
// 获取红包基本信息
|
||||
$redpacket_info = db::name("redpacket")->where(['id'=>$redpacket_id])->find();
|
||||
if(!$redpacket_info){
|
||||
return V(0, "红包不存在");
|
||||
}
|
||||
|
||||
// 获取发红包用户信息
|
||||
$redpacket_info['nickname'] = db::name('user')->where(['id'=>$redpacket_info['user_id']])->value('nickname');
|
||||
$redpacket_info['avatar'] = db::name('user')->where(['id'=>$redpacket_info['user_id']])->value('avatar');
|
||||
$redpacket_info['user_code'] = db::name('user')->where(['id'=>$redpacket_info['user_id']])->value('user_code');
|
||||
$redpacket_info['createtime_text'] = date('Y-m-d H:i:s', $redpacket_info['createtime']);
|
||||
$redpacket_info['start_time_text'] = date('Y-m-d H:i:s', $redpacket_info['start_time']);
|
||||
$redpacket_info['end_time_text'] = date('Y-m-d H:i:s', $redpacket_info['end_time']);
|
||||
//房间名称
|
||||
$redpacket_info['room_name'] = db::name('vs_room')->where(['id'=>$redpacket_info['room_id']])->value('room_name');
|
||||
|
||||
// 红包状态文字描述
|
||||
$status_map = [
|
||||
0 => '未开始',
|
||||
1 => '进行中',
|
||||
2 => '已结束',
|
||||
3 => '已退回'
|
||||
];
|
||||
$redpacket_info['status_text'] = $status_map[$redpacket_info['status']] ?? '未知';
|
||||
|
||||
// 币种文字描述
|
||||
$coin_type_map = [
|
||||
1 => '金币',
|
||||
2 => '钻石'
|
||||
];
|
||||
$redpacket_info['coin_type_text'] = $coin_type_map[$redpacket_info['coin_type']] ?? '未知';
|
||||
|
||||
// 红包类型文字描述
|
||||
$type_map = [
|
||||
1 => '普通红包',
|
||||
2 => '口令红包'
|
||||
];
|
||||
$redpacket_info['type_text'] = $type_map[$redpacket_info['type']] ?? '未知';
|
||||
|
||||
// 领取条件处理
|
||||
$conditions = explode(',',$redpacket_info['conditions']);
|
||||
$conditions = array_filter($conditions, function($item) {
|
||||
return $item !== '' && $item !== null;
|
||||
});
|
||||
$conditions = array_unique($conditions);
|
||||
$conditions = array_values($conditions);
|
||||
|
||||
// 特殊处理:如果包含条件0(无条件),则只保留这一项
|
||||
if (in_array('0', $conditions)) {
|
||||
$redpacket_info['conditions_text'] = ['无条件'];
|
||||
} else {
|
||||
// 将数字条件转换为对应的中文描述
|
||||
$conditions_text = array_map(function($item){
|
||||
switch($item) {
|
||||
case '0':
|
||||
return '无条件';
|
||||
case '1':
|
||||
return '收藏';
|
||||
case '2':
|
||||
return '在麦上';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}, $conditions);
|
||||
$redpacket_info['conditions_text'] = $conditions_text;
|
||||
}
|
||||
|
||||
// 领取详情 redpacket_record 表里面的数据
|
||||
// 外键redpacket_id redpacket表的ID,user_id 外键user表的ID amount 抢到的金额 createtime抢红包的时间
|
||||
// 红包领取详情 谁在什么时候 抢红包 抢了多少钱
|
||||
$redpacket_record_lists = db::name("redpacket_record")->where(['redpacket_id'=>$redpacket_id])->order('createtime asc')->select();
|
||||
if($redpacket_record_lists){
|
||||
foreach ($redpacket_record_lists as $key => $value){
|
||||
$redpacket_record_lists[$key]['nickname'] = db::name('user')->where(['id'=>$value['user_id']])->value('nickname');
|
||||
$redpacket_record_lists[$key]['avatar'] = db::name('user')->where(['id'=>$value['user_id']])->value('avatar');
|
||||
$redpacket_record_lists[$key]['user_code'] = db::name('user')->where(['id'=>$value['user_id']])->value('user_code');
|
||||
$redpacket_record_lists[$key]['createtime_text'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
}
|
||||
}
|
||||
|
||||
$return_data = [
|
||||
'redpacket_info' => $redpacket_info,
|
||||
'record_lists' => $redpacket_record_lists
|
||||
];
|
||||
|
||||
return V(1, "成功", $return_data);
|
||||
}
|
||||
|
||||
}
|
||||
371
application/adminapi/controller/RoomHourRanking.php
Normal file
371
application/adminapi/controller/RoomHourRanking.php
Normal file
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class RoomHourRanking
|
||||
{
|
||||
public static function withdraw_status (){
|
||||
return [
|
||||
// [25 => '全时段'],
|
||||
[0 => '00:00-01:00'],
|
||||
[1 => '01:00-02:00'],
|
||||
[2 => '02:00-03:00'],
|
||||
[3 => '03:00-04:00'],
|
||||
[4 => '04:00-05:00'],
|
||||
[5 => '05:00-06:00'],
|
||||
[6 => '06:00-07:00'],
|
||||
[7 => '07:00-08:00'],
|
||||
[8 => '08:00-09:00'],
|
||||
[9 => '09:00-10:00'],
|
||||
[10 => '10:00-11:00'],
|
||||
[11 => '11:00-12:00'],
|
||||
[12 => '12:00-13:00'],
|
||||
[13 => '13:00-14:00'],
|
||||
[14 => '14:00-15:00'],
|
||||
[15 => '15:00-16:00'],
|
||||
[16 => '16:00-17:00'],
|
||||
[17 => '17:00-18:00'],
|
||||
[18 => '18:00-19:00'],
|
||||
[19 => '19:00-20:00'],
|
||||
[20 => '20:00-21:00'],
|
||||
[21 => '21:00-22:00'],
|
||||
[22 => '22:00-23:00'],
|
||||
[23 => '23:00-00:00'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
//房间小时榜列表
|
||||
public function room_hour_ranking()
|
||||
{
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 20);
|
||||
$search_ranking = input('search_ranking', '');
|
||||
$search_stime = input('search_stime', '');
|
||||
$search_etime = input('search_etime', '');
|
||||
$where = [];
|
||||
if ($search_ranking) {
|
||||
$where[] = ['room_name', 'like', '%' . $search_ranking . '%'];
|
||||
}
|
||||
if ($search_stime) {
|
||||
$where[] = ['stime', '>=', $search_stime];
|
||||
}
|
||||
if ($search_etime) {
|
||||
$where[] = ['etime', '<=', $search_etime];
|
||||
}
|
||||
$count = db::name('vs_hour_ranking')->where($where)->count();
|
||||
$list = db::name('vs_hour_ranking')->where($where)->page($page, $page_limit)->order('id desc')->select();
|
||||
if($list){
|
||||
foreach ($list as &$v){
|
||||
$v['room_name'] = db::name('vs_room')->where(['id'=>$v['room_id']])->value('room_name');
|
||||
$v['user_id'] = db::name('vs_room')->where(['id'=>$v['room_id']])->value('user_id');
|
||||
if($v['user_id']){
|
||||
$v['nickname'] = db::name('user')->where(['id'=>$v['user_id']])->value('nickname');
|
||||
}
|
||||
$v['stime'] = date('Y-m-d H:i', $v['stime']);
|
||||
$v['etime'] = date('Y-m-d H:i', $v['etime']);
|
||||
|
||||
}
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'lists' => $list
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
|
||||
//房间小时榜配置
|
||||
public function room_hour_ranking_config()
|
||||
{
|
||||
$list = db::name('vs_hour_ranking_config')->where('id', '1')->find();
|
||||
if($list){
|
||||
//open_time 字段转化为2025-09-30 07:00 的格式
|
||||
$list['open_time'] = $list['open_time'] ? date('Y-m-d H:i', $list['open_time']) : 0;
|
||||
}
|
||||
return V(1,"成功", $list);
|
||||
}
|
||||
|
||||
//房间小时榜配置修改
|
||||
public function room_hour_ranking_config_edit()
|
||||
{
|
||||
$id = input('id');
|
||||
$data['is_open_red_pack'] = 0;//暂时不开启
|
||||
$data['is_public_server'] = input('is_public_server');
|
||||
$data['broadcast_times'] = input('broadcast_times');
|
||||
$data['is_open_xlh'] = input('is_open_xlh');
|
||||
$data['min_price'] = input('min_price');
|
||||
$open_time = input('open_time');
|
||||
$data['open_time'] = $open_time ? strtotime($open_time) : 0;
|
||||
$data['createtime'] = time();
|
||||
$data['updatetime'] = time();
|
||||
|
||||
$timeSlots = json_decode(input('timeJson'), true);
|
||||
|
||||
$timePeriods = $this->withdraw_status();
|
||||
|
||||
// 构建正确的时间映射关系
|
||||
$timeMap = [];
|
||||
foreach($timePeriods as $period) {
|
||||
foreach($period as $key => $value) {
|
||||
$timeMap[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
//$timeMap 里面 键值互换
|
||||
$timeMap = array_flip($timeMap);
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
if($timeSlots){
|
||||
$insertData = [];
|
||||
foreach ($timeSlots as $timeSlot) {
|
||||
// $timeRange = ;
|
||||
$timeRange = $timeMap[$timeSlot['time']] ?? '99';
|
||||
|
||||
foreach ($timeSlot['reward'] as $rewardItem) {
|
||||
$hasReward = !empty($rewardItem['content']);
|
||||
|
||||
if ($hasReward) {
|
||||
// 有奖励内容:为每个奖励内容创建一条记录
|
||||
foreach ($rewardItem['content'] as $rewardContent) {
|
||||
if($rewardContent['type'] == 0){
|
||||
$coin = $rewardContent['value'];
|
||||
$gift_id = 0;
|
||||
$gift_name = '';
|
||||
}else{
|
||||
$coin = 0;
|
||||
$gift_id = $rewardContent['value'];
|
||||
$gift_name = $rewardContent['name'];
|
||||
}
|
||||
$insertData[] = [
|
||||
'time_id' => $timeRange,
|
||||
'ranking' => $rewardItem['index'],
|
||||
// 'rank_name' => $rewardItem['name'],
|
||||
'gift_type' => $rewardContent['type'],
|
||||
'gift_id' => $gift_id,
|
||||
'coin' => $coin,
|
||||
'name' => $gift_name,
|
||||
'createtime' => time()
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// 无奖励内容:插入一条空奖励记录
|
||||
$insertData[] = [
|
||||
'time_id' => $timeRange,
|
||||
'ranking' => $rewardItem['index'],
|
||||
// 'rank_name' => $rewardItem['name'],
|
||||
'gift_type' => 0,
|
||||
'gift_id' => 0,
|
||||
'coin' => 0,
|
||||
'name' => '',
|
||||
'createtime' => time(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量插入
|
||||
if (!empty($insertData)) {
|
||||
$del = db::name('vs_hour_ranking_gift_config')->where('id','>',0)->delete();
|
||||
$ins = db::name('vs_hour_ranking_gift_config')->insertAll($insertData);
|
||||
}else{
|
||||
$ins = false;
|
||||
$del = false;
|
||||
}
|
||||
|
||||
}else{
|
||||
$del = true;
|
||||
$ins = true;
|
||||
}
|
||||
|
||||
// $res = db::name('vs_hour_ranking_config')->where('id', $id)->update($data);
|
||||
$res = db::name('vs_hour_ranking_config')->where('id', $id)->update($data);
|
||||
// if ($del && $ins && $res) {
|
||||
if ($ins) {
|
||||
db::commit();
|
||||
return V(1, "成功");
|
||||
} else {
|
||||
db::rollback();
|
||||
return V(0, "失败");
|
||||
}
|
||||
}
|
||||
|
||||
//时间段对应关系
|
||||
public function time_period_correspondence()
|
||||
{
|
||||
$list = $this->withdraw_status();
|
||||
$timePeriods = $this->withdraw_status();
|
||||
$timeMap = [];
|
||||
foreach($timePeriods as $period) {
|
||||
foreach($period as $key => $value) {
|
||||
$timeMap[$key] = $value;
|
||||
}
|
||||
}
|
||||
return V(1,"成功", $timeMap);
|
||||
}
|
||||
|
||||
|
||||
//添加核心配置
|
||||
public function add_core_config()
|
||||
{
|
||||
$data['is_public_server'] = input('is_public_server');
|
||||
$data['createtime'] = time();
|
||||
$data['updatetime'] = time();
|
||||
|
||||
|
||||
$res = db::name('vs_hour_ranking_config')->insert($data);
|
||||
}
|
||||
|
||||
//核心配置列表
|
||||
public function core_config_list()
|
||||
{
|
||||
$timePeriods = $this->withdraw_status();
|
||||
|
||||
// 构建正确的时间映射关系
|
||||
$timeMap = [];
|
||||
foreach($timePeriods as $period) {
|
||||
foreach($period as $key => $value) {
|
||||
$timeMap[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// 先按时间段和排名索引分组查询
|
||||
$timeRanges = db::name('vs_hour_ranking_gift_config')->distinct(true)
|
||||
->order('time_id')
|
||||
->column('time_id');
|
||||
|
||||
$result = [];
|
||||
foreach ($timeRanges as $timeRange) {
|
||||
// 查询该时间段的所有数据
|
||||
$rewards = db::name('vs_hour_ranking_gift_config')->where('time_id', $timeRange)
|
||||
->field('ranking, gift_type, gift_id,coin,name')
|
||||
->order('ranking')
|
||||
->select();
|
||||
|
||||
$rewardMap = [];
|
||||
foreach ($rewards as $reward) {
|
||||
$rankIndex = $reward['ranking'];
|
||||
|
||||
if (!isset($rewardMap[$rankIndex])) {
|
||||
$rewardMap[$rankIndex] = [
|
||||
'index' => $rankIndex,
|
||||
// 'name' => $reward['rank_name'],
|
||||
'content' => []
|
||||
];
|
||||
}
|
||||
|
||||
// 添加奖励内容到content数组
|
||||
if ($reward['gift_id'] != 0 || $reward['coin'] != 0) {
|
||||
if($reward['gift_id'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['gift_id'],
|
||||
// 'coin' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
if($reward['coin'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 按index排序
|
||||
ksort($rewardMap);
|
||||
|
||||
$result[] = [
|
||||
'time' => $timeMap[$timeRange],
|
||||
'reward' => array_values($rewardMap)
|
||||
];
|
||||
}
|
||||
|
||||
return V(1, "成功", $result);
|
||||
|
||||
}
|
||||
|
||||
// public function core_config_lists()
|
||||
// {
|
||||
// $list = db::name('vs_hour_ranking_gift_config')->select();
|
||||
// $data = [];
|
||||
//
|
||||
// // 按 time_id 和 ranking 重组数据
|
||||
// $reorganizedData = [];
|
||||
// $timePeriods = $this->withdraw_status();
|
||||
//
|
||||
// // 构建正确的时间映射关系
|
||||
// $timeMap = [];
|
||||
// foreach($timePeriods as $period) {
|
||||
// foreach($period as $key => $value) {
|
||||
// $timeMap[$key] = $value;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// foreach ($list as $item) {
|
||||
//// $timeId = $item['time_id'];
|
||||
// $timeId = $timeMap[$item['time_id']] ?? '未知时间段';
|
||||
// $ranking = $item['ranking'];
|
||||
//
|
||||
// $gift_name = '';
|
||||
// if (!isset($reorganizedData[$timeId])) {
|
||||
// $reorganizedData[$timeId] = [];
|
||||
// }
|
||||
// if (!isset($reorganizedData[$timeId][$ranking])) {
|
||||
// $reorganizedData[$timeId][$ranking] = [];
|
||||
// }
|
||||
// if($item['gift_id']){
|
||||
// if($item['gift_type'] == 2){
|
||||
// $gift_name = db::name('vs_gift')->where(['gid'=>$item['gift_id']])->value('gift_name');
|
||||
// }
|
||||
// if($item['gift_type'] == 3 || $item['gift_type'] == 4){
|
||||
// $gift_name = db::name('vs_decorate')->where(['did'=>$item['gift_id']])->value('title');
|
||||
// }
|
||||
//
|
||||
// }else{
|
||||
// $gift_name = '';
|
||||
// }
|
||||
// $reorganizedData[$timeId][$ranking][] = [
|
||||
// 'gift_type' => $item['gift_type'],
|
||||
// 'gift_id' => $item['gift_id'],
|
||||
// 'gift_name' => $gift_name,
|
||||
// 'coin' => $item['coin']
|
||||
// ];
|
||||
// }
|
||||
//
|
||||
// // 输出重组后的数据
|
||||
// print_r($reorganizedData);
|
||||
// return V(1, "成功", $data);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,10 +37,10 @@ class Statistical extends adminApi
|
||||
$where['createtime'] = ['>=', strtotime($begin_time)];
|
||||
}
|
||||
if($end_time !== ''){
|
||||
$where['createtime'] = ['<=', strtotime($end_time.' 23:59:59')];
|
||||
$where['createtime'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
if(!empty($begin_time) && !empty($end_time)){
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time)]];
|
||||
}
|
||||
|
||||
$where['pay_status'] = 2;//1待支付,2已支付
|
||||
@@ -112,10 +112,10 @@ class Statistical extends adminApi
|
||||
$where['createtime'] = ['>=', strtotime($begin_time)];
|
||||
}
|
||||
if($end_time !== ''){
|
||||
$where['createtime'] = ['<=', strtotime($end_time.' 23:59:59')];
|
||||
$where['createtime'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
if(!empty($begin_time) && !empty($end_time)){
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time)]];
|
||||
}
|
||||
$count = db::name('vs_give_gift')
|
||||
->where($where)
|
||||
@@ -177,10 +177,10 @@ class Statistical extends adminApi
|
||||
$where['createtime'] = ['>=', strtotime($begin_time)];
|
||||
}
|
||||
if($end_time !== ''){
|
||||
$where['createtime'] = ['<=', strtotime($end_time.' 23:59:59')];
|
||||
$where['createtime'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
if(!empty($begin_time) && !empty($end_time)){
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time)]];
|
||||
}
|
||||
// 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
|
||||
// 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
|
||||
@@ -239,10 +239,10 @@ class Statistical extends adminApi
|
||||
$where['createtime'] = ['>=', strtotime($begin_time)];
|
||||
}
|
||||
if($end_time !== ''){
|
||||
$where['createtime'] = ['<=', strtotime($end_time.' 23:59:59')];
|
||||
$where['createtime'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
if(!empty($begin_time) && !empty($end_time)){
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($begin_time),strtotime($end_time)]];
|
||||
}
|
||||
//不为空
|
||||
$where['from'] = 2;
|
||||
@@ -259,9 +259,14 @@ class Statistical extends adminApi
|
||||
->select();
|
||||
foreach ($lists as $key => $value) {
|
||||
$room = db::name('vs_room')->where('id', $value['from_id'])->find();
|
||||
if($room){
|
||||
$lists[$key]['room_name'] = $room['room_name'].'-'.$room['room_number'];
|
||||
$lists[$key]['room_number'] = $room['room_number'];
|
||||
}else{
|
||||
$lists[$key]['room_name'] = "--";
|
||||
$lists[$key]['room_number'] = "--";
|
||||
}
|
||||
$lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
$lists[$key]['room_name'] = $room['room_name'].'-'.$room['room_number'];
|
||||
$lists[$key]['room_number'] = $room['room_number'];
|
||||
$lists[$key]['room_cover'] = db::name('vs_room')->where('id', $value['from_id'])->value('room_cover');
|
||||
$label = db::name('vs_room')->where('id', $value['from_id'])->value('label_id');
|
||||
$lists[$key]['label'] = db::name('vs_room_label')->where('id', $label)->value('label_name');
|
||||
@@ -302,10 +307,10 @@ class Statistical extends adminApi
|
||||
$where['createtime'] = ['>=', strtotime($pay_stime)];
|
||||
}
|
||||
if($pay_etime !== ''){
|
||||
$where['createtime'] = ['<=', strtotime($pay_etime.' 23:59:59')];
|
||||
$where['createtime'] = ['<=', strtotime($pay_etime)];
|
||||
}
|
||||
if(!empty($pay_stime) && !empty($pay_etime)){
|
||||
$where['createtime'] = ['between',[strtotime($pay_stime),strtotime($pay_etime.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($pay_stime),strtotime($pay_etime)]];
|
||||
}
|
||||
if($pay_status !== ''){
|
||||
$where['pay_status'] = $pay_status;
|
||||
@@ -325,7 +330,7 @@ class Statistical extends adminApi
|
||||
}
|
||||
|
||||
$count = db::name('vs_user_recharge')->where($where)->count();
|
||||
$lists = db::name('vs_user_recharge')->where($where)->page($page, $page_limit)->select();
|
||||
$lists = db::name('vs_user_recharge')->where($where)->order('rid desc')->page($page, $page_limit)->select();
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['createtime'] = date('Y-m-d H:i:s', $value['createtime']);
|
||||
$lists[$key]['user_name'] = db::name('user')->where('id', $value['user_id'])->value('nickname').'-'.
|
||||
@@ -346,19 +351,21 @@ class Statistical extends adminApi
|
||||
];
|
||||
//总收入
|
||||
$wherew=[];
|
||||
$return_data['total_money'] = db::name('vs_user_recharge')->sum('money');
|
||||
unset($where['pay_status']);
|
||||
unset($where['pay_type']);
|
||||
$return_data['total_money'] = db::name('vs_user_recharge')->where($where)->sum('money');
|
||||
//未支付
|
||||
$return_data['unpaid_money'] = db::name('vs_user_recharge')->where('pay_status',1)->sum('money');
|
||||
$return_data['unpaid_money'] = db::name('vs_user_recharge')->where($where)->where('pay_status',1)->sum('money');
|
||||
//已支付
|
||||
$return_data['paid_money'] = db::name('vs_user_recharge')->where('pay_status',2)->sum('money');
|
||||
$return_data['paid_money'] = db::name('vs_user_recharge')->where($where)->where('pay_status',2)->sum('money');
|
||||
//微信支付
|
||||
$wherew['pay_type'] = ['in', [1,4]];
|
||||
$return_data['wx_money'] = db::name('vs_user_recharge')->where('pay_status',2)->where($wherew)->sum('money');
|
||||
$return_data['wx_money'] = db::name('vs_user_recharge')->where($where)->where('pay_status',2)->where($wherew)->sum('money');
|
||||
//支付宝支付
|
||||
$wherez['pay_type'] = ['in', [2,3]];
|
||||
$return_data['ali_money'] = db::name('vs_user_recharge')->where('pay_status',2)->where($wherez)->sum('money');
|
||||
$return_data['ali_money'] = db::name('vs_user_recharge')->where($where)->where('pay_status',2)->where($wherez)->sum('money');
|
||||
//金币数量
|
||||
$return_data['gold_num'] = db::name('vs_user_recharge')->where('pay_status',2)->sum('coin');
|
||||
$return_data['gold_num'] = db::name('vs_user_recharge')->where($where)->where('pay_status',2)->sum('coin');
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
|
||||
@@ -383,15 +390,16 @@ class Statistical extends adminApi
|
||||
$where['a.createtime'] = ['>=', strtotime($start_time)];
|
||||
}
|
||||
if($end_time !== ''){
|
||||
$where['a.createtime'] = ['<=', strtotime($end_time.' 23:59:59')];
|
||||
$where['a.createtime'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
if($start_time !== '' && $end_time !== ''){
|
||||
$where['a.createtime'] = ['between', [strtotime($start_time), strtotime($end_time.' 23:59:59')]];
|
||||
$where['a.createtime'] = ['between', [strtotime($start_time), strtotime($end_time)]];
|
||||
}
|
||||
|
||||
$count = db::name('user_exchange')->where($where)->alias('a')->join('user b', 'a.user_id = b.id')->count();
|
||||
$lists = db::name('user_exchange')->where($where)->alias('a')->join('user b', 'a.user_id = b.id')
|
||||
->field('a.*,b.nickname,b.user_code')
|
||||
->order('a.id desc')
|
||||
->page($page, $page_limit)->select();
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['user_name'] = $value['nickname'].'-'.$value['user_code'];
|
||||
@@ -428,10 +436,10 @@ class Statistical extends adminApi
|
||||
$where['a.createtime'] = ['>=', strtotime($start_time)];
|
||||
}
|
||||
if($end_time !== ''){
|
||||
$where['a.createtime'] = ['<=', strtotime($end_time.' 23:59:59')];
|
||||
$where['a.createtime'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
if($start_time !== '' && $end_time !== ''){
|
||||
$where['a.createtime'] = ['between', [strtotime($start_time), strtotime($end_time.' 23:59:59')]];
|
||||
$where['a.createtime'] = ['between', [strtotime($start_time), strtotime($end_time)]];
|
||||
}
|
||||
$count = db::name('vs_admin_recharge_log')
|
||||
->alias('a')->join('user b', 'a.user_id = b.id')
|
||||
|
||||
@@ -33,6 +33,7 @@ class SysSet extends adminApi
|
||||
'8' => '房间配置',
|
||||
'9' => '弹窗内容设置',
|
||||
'10' => '邀请奖励',
|
||||
'11' => '二级密码',
|
||||
];
|
||||
|
||||
public function _initialize()
|
||||
|
||||
@@ -44,6 +44,10 @@ class Theme extends adminApi
|
||||
}
|
||||
$list = db::name($this->table)->where($where)->page($page, $page_limit)->select();
|
||||
$count = db::name($this->table)->where($where)->count();
|
||||
foreach ($list as &$value) {
|
||||
$value['begin_time'] = date('Y-m-d H:i:s',$value['begin_time']);
|
||||
$value['end_time'] = date('Y-m-d H:i:s',$value['end_time']);
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
@@ -62,6 +66,10 @@ class Theme extends adminApi
|
||||
$auxiliary_color = input('auxiliary_color', '');
|
||||
$file_url = input('file_url', '');
|
||||
$is_active = input('is_active', '');
|
||||
$begin_time = input('begin_time', '');
|
||||
$end_time = input('end_time', '');
|
||||
$begin_time = !empty($begin_time) ? strtotime($begin_time) : 0;
|
||||
$end_time = !empty($end_time) ? strtotime($end_time) : 0;
|
||||
$data = [
|
||||
'theme_name' => $theme_name,
|
||||
'theme_color' => $theme_color,
|
||||
@@ -69,7 +77,9 @@ class Theme extends adminApi
|
||||
'file_url' => $file_url,
|
||||
'is_active' => $is_active,
|
||||
'admin_id' => $admin_id,
|
||||
'createtime' => time()
|
||||
'createtime' => time(),
|
||||
'begin_time' => $begin_time,
|
||||
'end_time' => $end_time,
|
||||
];
|
||||
$res = db::name($this->table)->insert($data);
|
||||
if($res){
|
||||
@@ -87,6 +97,10 @@ class Theme extends adminApi
|
||||
$auxiliary_color = input('auxiliary_color', '');
|
||||
$file_url = input('file_url', '');
|
||||
$is_active = input('is_active', '');
|
||||
$begin_time = input('begin_time', '');
|
||||
$end_time = input('end_time', '');
|
||||
$begin_time = !empty($begin_time) ? strtotime($begin_time) : 0;
|
||||
$end_time = !empty($end_time) ? strtotime($end_time) : 0;
|
||||
$id = input('id', '');
|
||||
$data = [
|
||||
'theme_name' => $theme_name,
|
||||
@@ -94,7 +108,9 @@ class Theme extends adminApi
|
||||
'auxiliary_color' => $auxiliary_color,
|
||||
'file_url' => $file_url,
|
||||
'is_active' => $is_active,
|
||||
'updatetime' => time()
|
||||
'updatetime' => time(),
|
||||
'begin_time' => $begin_time,
|
||||
'end_time' => $end_time,
|
||||
];
|
||||
$res = db::name($this->table)->where(['id'=>$id])->update($data);
|
||||
if($res){
|
||||
|
||||
@@ -159,7 +159,7 @@ class Underage extends adminApi
|
||||
*/
|
||||
public function content_List(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('pageSize', 30);
|
||||
$page_limit = input('page_limit', 10);
|
||||
$search_name = input('search_name', '');
|
||||
$where = [];
|
||||
if($search_name){
|
||||
@@ -167,6 +167,7 @@ class Underage extends adminApi
|
||||
}
|
||||
$list = DB::name('vs_underage_mode_content')->where($where)->order('sort,id', 'asc')->page($page, $page_limit)->select();
|
||||
$count = DB::name('vs_underage_mode_content')->where($where)->count();
|
||||
$return_lists = [];
|
||||
foreach ($list as $key => $value) {
|
||||
$return_lists[$key]['id'] = $value['id'];
|
||||
$return_lists[$key]['type_id'] = $value['type_id'];
|
||||
@@ -266,7 +267,7 @@ class Underage extends adminApi
|
||||
$type_id = input('type_id', '');
|
||||
$title = input('title', '');
|
||||
$introduced = input('introduced', '');
|
||||
$content = input('content', '');
|
||||
$content = $_POST['content']??"";
|
||||
$url = input('url', '');
|
||||
$img = input('img', '');
|
||||
$from = input('from', 1);
|
||||
@@ -303,9 +304,6 @@ class Underage extends adminApi
|
||||
$data['content'] = $content;
|
||||
}
|
||||
$result = db::name('vs_underage_mode_content')->where(['id'=>$id])->update($data);
|
||||
if(!$result){
|
||||
return V(0,"修改失败");
|
||||
}
|
||||
return V(1,"成功", ['id'=>$id]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace app\adminapi\controller;
|
||||
|
||||
use app\admin\model\AdminLog;
|
||||
use app\common\controller\Upload;
|
||||
use Overtrue\Pinyin\Pinyin;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
@@ -32,7 +33,25 @@ class UploadFile extends Upload
|
||||
try {
|
||||
// 获取临时路径和原始文件名
|
||||
$filePath = $file->getRealPath();
|
||||
$objectName = $file->getInfo('name');
|
||||
$originalName = $file->getInfo('name');
|
||||
|
||||
// 提取文件扩展名
|
||||
$extension = pathinfo($originalName, PATHINFO_EXTENSION);
|
||||
|
||||
// 处理文件名(中文转拼音) 移除扩展名(如果有的话)
|
||||
$fileName = pathinfo($originalName, PATHINFO_FILENAME);
|
||||
if (preg_match('/[\x{4e00}-\x{9fa5}]+/u', $fileName)) {
|
||||
$pinyin = new Pinyin();
|
||||
$fileName = $pinyin->permalink($fileName, ''); // 转换为无分隔符的拼音
|
||||
}
|
||||
|
||||
// 去除文件名中的空格
|
||||
$fileName = str_replace(' ', '', $fileName);
|
||||
|
||||
// 添加唯一标识符(时间戳+随机数)
|
||||
$uniqueId = time() . mt_rand(1000, 9999);
|
||||
$objectName = $fileName . '_' . $uniqueId . '.' . $extension;
|
||||
|
||||
// 调用父类方法上传到 OSS
|
||||
$result = $this->uploadFile($objectName, $filePath);
|
||||
if (!$result) {
|
||||
|
||||
@@ -74,8 +74,8 @@ class User extends adminApi
|
||||
}elseif($v=='coin2'){
|
||||
$where['c.coin'] = ['<=',$input_data];
|
||||
}elseif($v=='createtime'){
|
||||
$where['a.createtime'] = ['>=',strtotime($input_data.' 00:00:00')];
|
||||
$where['a.createtime'] = ['<=',strtotime($input_data.' 23:59:59')];
|
||||
$where['a.createtime'] = ['>=',strtotime($input_data)];
|
||||
$where['a.createtime'] = ['<=',strtotime($input_data)];
|
||||
}else{
|
||||
$where['a.'.$v] = $input_data;
|
||||
}
|
||||
@@ -231,7 +231,8 @@ class User extends adminApi
|
||||
'type' => $type,
|
||||
'type_text' => $type_text,
|
||||
];
|
||||
$res = Db::name('block')->where($map)->delete();
|
||||
Db::name('block')->where($map)->delete();
|
||||
Db::name('sms_error')->where(['mobile' => $user_info['mobile']])->delete();
|
||||
}
|
||||
return V(1,"成功", null);
|
||||
}
|
||||
@@ -735,7 +736,12 @@ class User extends adminApi
|
||||
* 用户列表
|
||||
*/
|
||||
public function get_user_list(){
|
||||
$user = db::name('user')->field('id,nickname,avatar')->where(['status'=>1,'is_robot'=>0,'delete_time'=>0])->select();
|
||||
$user_code = input('user_code', 0);
|
||||
$where = [];
|
||||
if($user_code){
|
||||
$where['user_code'] = $user_code;
|
||||
}
|
||||
$user = db::name('user')->field('id,nickname,avatar')->where($where)->where(['status'=>1,'is_robot'=>0,'delete_time'=>0])->select();
|
||||
return V(1,"操作成功", $user);
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class Version extends adminApi
|
||||
$version = input('version', '');
|
||||
$type = input('type', '');
|
||||
$downloadurl = input('downloadurl', '');
|
||||
$content = input('content', '');
|
||||
$content = $_POST['content'] ?? '';
|
||||
$enforce = input('enforce', '');
|
||||
$version_code = input('version_code', '');
|
||||
$status = input('status', 1);
|
||||
@@ -101,7 +101,7 @@ class Version extends adminApi
|
||||
$version = input('version', '');
|
||||
$type = input('type', '');
|
||||
$downloadurl = input('downloadurl', '');
|
||||
$content = input('content', '');
|
||||
$content = $_POST['content'] ?? '';
|
||||
$enforce = input('enforce', '');
|
||||
$version_code = input('version_code', '');
|
||||
$status = input('status', 1);
|
||||
|
||||
@@ -60,10 +60,10 @@ class Withdrawal extends adminApi
|
||||
$where['a.createtime'] = ['>=', strtotime($search_stime)];
|
||||
}
|
||||
if($search_etime !== ''){
|
||||
$where['a.createtime'] = ['<=', strtotime($search_etime.' 23:59:59')];
|
||||
$where['a.createtime'] = ['<=', strtotime($search_etime)];
|
||||
}
|
||||
if(!empty($search_stime) && !empty($search_etime)){
|
||||
$where['a.createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime.' 23:59:59')]];
|
||||
$where['a.createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime)]];
|
||||
}
|
||||
$count = db::name('vs_user_withdrawal')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id', 'left')
|
||||
@@ -75,6 +75,7 @@ class Withdrawal extends adminApi
|
||||
->field('a.*,b.nickname,b.user_code')
|
||||
->order('a.createtime desc')
|
||||
->where($where)
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$data_lists = [];
|
||||
foreach ($lists as $key => $value) {
|
||||
@@ -255,19 +256,23 @@ class Withdrawal extends adminApi
|
||||
//查询该用户云账户提现金额
|
||||
$had_money = db::name('vs_user_withdrawal')->where(['user_id'=>$withdraw_info['user_id'],'deal_type'=>2,'status'=>6])->where('pay_time','month')->sum('general_money');
|
||||
$max_month_money = 98000;
|
||||
if(($had_money+$withdraw_info['general_money']) >= 98000){
|
||||
if(($had_money+$withdraw_info['general_money']) >= $max_month_money){
|
||||
return ['code' => 0, 'msg' => '单人单月云账户提现金额最大为98000元!', 'data' => null];
|
||||
}
|
||||
//查询该用户信息
|
||||
$user_info = model('api/user')->get_user_info($withdraw_info['user_id']);
|
||||
$user_info = model('api/user')->get_user_info($withdraw_info['user_id'], ['user','user_auth']);
|
||||
if(empty($user_info)){
|
||||
return ['code' => 0, 'msg' => '用户信息错误!', 'data' => null];
|
||||
}
|
||||
|
||||
$real_name = $user_info['real_name'];
|
||||
$id_card = $user_info['card_id'];
|
||||
$order_id = $withdraw_info['order_sn'];
|
||||
$order_amount = $withdraw_info['general_money'];
|
||||
$phone = $user_info['mobile'];
|
||||
if(empty($phone)) {
|
||||
return ['code' => 0, 'msg' => '请先绑定手机号', 'data' => null];
|
||||
}
|
||||
if (empty($real_name) || empty($id_card)) {
|
||||
return ['code' => 0, 'msg' => '请先实名认证', 'data' => null];
|
||||
}
|
||||
@@ -281,7 +286,11 @@ class Withdrawal extends adminApi
|
||||
}
|
||||
$card_no = $user_info['alipay_account'];
|
||||
$yun_pay = new YunPay($order_id, $real_name, $id_card, $card_no, $order_amount,$phone);
|
||||
$result = $yun_pay->alipay();
|
||||
$user_data = [
|
||||
'nickname' => $user_info['nickname'],
|
||||
'user_id' => $withdraw_info['user_id'],
|
||||
];
|
||||
$result = $yun_pay->alipay($user_data);
|
||||
} elseif ($withdraw_info['type'] == 3) {
|
||||
if(empty($user_info['bank_card_number'])){
|
||||
return ['code' => 0, 'msg' => '请先绑定银行卡号', 'data' => null];
|
||||
|
||||
@@ -85,7 +85,7 @@ class Guild extends Model
|
||||
->alias('g')
|
||||
->join('vs_guild gg','g.guild_id = gg.id')
|
||||
->field('gg.*')
|
||||
->where(['g.user_id' => $user_id])
|
||||
->where(['g.user_id' => $user_id,'g.status' => 1,'g.delete_time' => 0])
|
||||
->find();
|
||||
return $guild;
|
||||
}
|
||||
@@ -95,31 +95,29 @@ class Guild extends Model
|
||||
*工会当日流水
|
||||
*/
|
||||
public function getTodayMoney($guild_id,$stoday="",$etoday=""){
|
||||
$where = [];
|
||||
if(empty($stoday) && empty($etoday)){
|
||||
$stoday = strtotime(date('Y-m-d 00:00:00'));
|
||||
$etoday = strtotime(date('Y-m-d 23:59:59'));
|
||||
$where['createtime'] = ['between', [$stoday, $etoday]];
|
||||
}else{
|
||||
if(!empty($stoday)){
|
||||
$where['createtime'] = ['>=', strtotime($stoday."00:00:00")];
|
||||
}
|
||||
if(!empty($etoday)){
|
||||
$where['createtime'] = ['<=', strtotime($etoday." 23:59:59")];
|
||||
}
|
||||
if(!empty($stoday) && !empty($etoday)){
|
||||
$where['createtime'] = ['between', [strtotime($stoday." 00:00:00"), strtotime($etoday." 23:59:59")]];
|
||||
}
|
||||
}
|
||||
|
||||
//获取所有工会房间ID
|
||||
$room_ids = db::name('vs_guild_user')->where('guild_id', $guild_id)->field('room_id')->select();
|
||||
$room_ids = array_column($room_ids, 'room_id');
|
||||
$transaction = db::name('vs_give_gift')
|
||||
->whereIn('from_id',$room_ids)
|
||||
->where(['from'=>['in',[2,3,6]]])
|
||||
->where($where)
|
||||
->sum('total_price');
|
||||
$guild_user_data = db::name('vs_guild_user')->where('guild_id', $guild_id)->field('room_id,createtime,quit_time')->select();
|
||||
$transaction = 0;
|
||||
foreach ($guild_user_data as $k => $v) {
|
||||
if(empty($stoday) && empty($etoday)){
|
||||
$stoday_seach = strtotime(date('Y-m-d 00:00:00',time()));
|
||||
$etoday_seach = strtotime(date('Y-m-d 23:59:59',time()));
|
||||
}else{
|
||||
$stoday_seach = strtotime($stoday);
|
||||
$etoday_seach = strtotime($etoday);
|
||||
}
|
||||
if($v['createtime'] && $stoday_seach < $v['createtime']){
|
||||
$stoday_seach = $v['createtime'];
|
||||
}
|
||||
if($v['quit_time'] && ($etoday > $v['quit_time'])){
|
||||
$etoday_seach = $v['quit_time'];
|
||||
}
|
||||
$transaction_one = db::name('vs_give_gift')
|
||||
->where('from_id',$v['room_id'])
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$stoday_seach, $etoday_seach]]])
|
||||
->sum('total_price');
|
||||
$transaction += $transaction_one;
|
||||
}
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,19 +75,37 @@ class Room extends Model
|
||||
$give_where['from_id'] = $room_id;
|
||||
$give_where['from'] = ["in",[2,3,6]];
|
||||
if(!empty($stime)){
|
||||
$give_where['createtime'] = ['>=',strtotime($stime.' 00:00:00')];
|
||||
$give_where['createtime'] = ['>=',strtotime($stime)];
|
||||
}
|
||||
if(!empty($etime)){
|
||||
$give_where['createtime'] = ['<=',strtotime($etime.' 23:59:59')];
|
||||
$give_where['createtime'] = ['<=',strtotime($etime)];
|
||||
}
|
||||
if(!empty($stime) && !empty($etime)){
|
||||
$give_where['createtime'] = ['between',[strtotime($stime.' 00:00:00'),strtotime($etime.' 23:59:59')]];
|
||||
$give_where['createtime'] = ['between',[strtotime($stime),strtotime($etime)]];
|
||||
}
|
||||
$total_price = db::name('vs_give_gift')->where($give_where)
|
||||
->sum('total_price');
|
||||
return $total_price;
|
||||
}
|
||||
|
||||
/*
|
||||
* 房间绑定盘
|
||||
*/
|
||||
public function bindPan($room_id){
|
||||
db::name('vs_room_pan')->where(['room_id'=>$room_id])->delete();
|
||||
$gift_bag = db::name('vs_gift_bag_detail')->where(['gift_bag_id'=>['in',[10,11,12,13]]])->select();
|
||||
foreach ($gift_bag as $k=>$v){
|
||||
$data = [
|
||||
'room_id'=>$room_id,
|
||||
'gift_bag_id'=>$v['gift_bag_id'],
|
||||
'gift_bag_detail_id'=>$v['id'],
|
||||
'remaining_number'=>$v['quantity'],
|
||||
'createtime'=>time()
|
||||
];
|
||||
db::name('vs_room_pan')->insert($data);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class Activities extends BaseCom
|
||||
$data['name'] = $activities_title??"";
|
||||
$data['gift_bag'] = [];
|
||||
foreach ($gift_bag as $k=>$v){
|
||||
$data['gift_bag'][$k]['gift_bag_id'] = $v['id']??0;
|
||||
$data['gift_bag'][$k]['name'] = $v['title']??"";
|
||||
$ext = json_decode($v['ext'],true);
|
||||
$data['gift_bag'][$k]['title1'] = $ext['title1']??"";
|
||||
@@ -49,11 +50,13 @@ class Activities extends BaseCom
|
||||
$list[$kk]['base_image'] = localpath_to_netpath("static/image/icon/gold.png");
|
||||
}elseif ($vv['type'] == 2) {
|
||||
$gift = DB::name('vs_gift')->where(['gid'=>$vv['foreign_id']])->find();
|
||||
$list[$kk]['gift_name'] = $gift['gift_name'];
|
||||
$list[$kk]['num'] = $vv['quantity'];
|
||||
$list[$kk]['gift_price'] = $gift['gift_price'];
|
||||
$list[$kk]['type'] =2;
|
||||
$list[$kk]['base_image'] = $gift['base_image'];
|
||||
if($gift){
|
||||
$list[$kk]['gift_name'] = $gift['gift_name'];
|
||||
$list[$kk]['num'] = $vv['quantity'];
|
||||
$list[$kk]['gift_price'] = $gift['gift_price'];
|
||||
$list[$kk]['type'] =2;
|
||||
$list[$kk]['base_image'] = $gift['base_image'];
|
||||
}
|
||||
} elseif ($vv['type'] == 3) {
|
||||
$decorate_price = DB::name('vs_decorate_price')->where(['id'=>$vv['foreign_id']])->find();
|
||||
if($decorate_price){
|
||||
@@ -85,8 +88,8 @@ class Activities extends BaseCom
|
||||
$uid = input('uid',$this->uid);
|
||||
$permission_status = 1;
|
||||
//查询是否首充
|
||||
$is_first_charge = db::name('vs_user_money_log')->where('user_id',$uid)->where('change_type',2)->where('money_type',1)->count();
|
||||
$permission = DB::name('vs_activities_receive')->where(['activities_id'=>$activities_id,'user_id'=>$uid])->find();
|
||||
$is_first_charge = db::name('vs_user_money_log')->where('user_id',$uid)->where('change_type',2)->where('money_type',1)->where(['createtime'=>['>=',"1760666400"]])->count();
|
||||
$permission = DB::name('vs_activities_receive')->where(['activities_id'=>$activities_id,'user_id'=>$uid])->where(['createtime'=>['>=',"1760666400"]])->find();
|
||||
$system = request()->header('system');
|
||||
$app_version = request()->header('App-Version');
|
||||
if(!$app_version){
|
||||
@@ -127,46 +130,51 @@ class Activities extends BaseCom
|
||||
//礼包
|
||||
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->find();
|
||||
$data = [];
|
||||
$data['gift_bag_id'] = $gift_bag['id']??0;
|
||||
$data['name'] = $activities['title']??"";
|
||||
$data['bag_name'] = $gift_bag['title']??"";
|
||||
$data['effective_time'] = $activities['effective_time']??"";
|
||||
//规则
|
||||
$data['rule'] = get_system_config_value('web_site')."/api/Page/page_show?id=13";
|
||||
$ext = json_decode($gift_bag['ext'],true);
|
||||
$data['money'] = $ext['money'];
|
||||
$data['counter']['counter'] = $ext['counter'];
|
||||
$data['counter']['money'] = $ext['money_str'];
|
||||
$data['counter']['diamond'] = $ext['diamond'];
|
||||
$data['money'] = $gift_bag['money'];
|
||||
$data['counter'] = $ext['counter'];
|
||||
$data['money_str'] = $ext['money_str'];
|
||||
$data['diamond'] = $ext['diamond'];
|
||||
$data['effective_time'] = $ext['activity_end_time']??"";
|
||||
if(strtotime($ext['activity_end_time']) < time()){
|
||||
return V(0,'活动已结束!',null);
|
||||
}
|
||||
$detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag['id']])->select();
|
||||
$data['gift_list'] = [];
|
||||
foreach ($detail as $k=>$v){
|
||||
if($v['type'] == 1){
|
||||
$list[$k]['name'] = "金币";
|
||||
$list[$k]['gift_name'] = "金币";
|
||||
$list[$k]['num'] = $v['gold'];
|
||||
$list[$k]['gold'] = $v['gold'];
|
||||
$list[$k]['gift_price'] = $v['gold'];
|
||||
$list[$k]['type'] = 1;
|
||||
$list[$k]['icon'] = localpath_to_netpath("static/image/icon/gold.png");
|
||||
$list[$k]['base_image'] = localpath_to_netpath("static/image/icon/gold.png");
|
||||
}elseif($v['type'] == 2) {
|
||||
$gift = DB::name('vs_gift')->where(['gid'=>$v['foreign_id']])->find();
|
||||
$list[$k]['name'] = $gift['gift_name'];
|
||||
$list[$k]['gift_name'] = $gift['gift_name'];
|
||||
$list[$k]['num'] = $v['quantity'];
|
||||
$list[$k]['gold'] = $gift['gift_price'];
|
||||
$list[$k]['gift_price'] = $gift['gift_price'];
|
||||
$list[$k]['type'] =2;
|
||||
$list[$k]['icon'] = $gift['play_image'];
|
||||
$list[$k]['base_image'] = $gift['base_image'];
|
||||
} elseif($v['type'] == 3) {
|
||||
$decorate_price = DB::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
||||
$gift = DB::name('vs_decorate')->where(['did'=>$decorate_price['did']])->find();
|
||||
$list[$k]['name'] = $gift['title']; //装扮名称
|
||||
$list[$k]['gift_name'] = $gift['title']; //装扮名称
|
||||
$list[$k]['num'] = $decorate_price['day']; //天数
|
||||
$list[$k]['gold'] = $decorate_price['price']; //价格
|
||||
$list[$k]['gift_price'] = $decorate_price['price']; //价格
|
||||
$list[$k]['type'] =3;
|
||||
$list[$k]['icon'] = $gift['base_image'];
|
||||
$list[$k]['base_image'] = $gift['base_image'];
|
||||
}elseif($v['type'] == 4) {
|
||||
$list[$k]['name'] = "钻石";
|
||||
$list[$k]['gift_name'] = "钻石";
|
||||
$list[$k]['num'] = $v['quantity'];
|
||||
$list[$k]['gold'] = $v['gold'];
|
||||
$list[$k]['gift_price'] = $v['gold'];
|
||||
$list[$k]['type'] = 4;
|
||||
$list[$k]['icon'] = localpath_to_netpath("static/image/icon/gold.png");
|
||||
$list[$k]['base_image'] = localpath_to_netpath("static/image/icon/gold.png");
|
||||
}
|
||||
}
|
||||
$data['gift_list'] = $list;
|
||||
@@ -177,20 +185,183 @@ class Activities extends BaseCom
|
||||
{
|
||||
$activities_id = 3;//天降好礼
|
||||
$uid = input('uid',$this->uid);
|
||||
$permission = DB::name('vs_activities_receive')->where(['activities_id'=>$activities_id,'user_id'=>$uid])->find();
|
||||
if($permission){
|
||||
return V(1,'操作成功', ['permission'=>0]);
|
||||
}else{
|
||||
return V(1,'操作成功', ['permission'=>1]);
|
||||
//礼包
|
||||
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>3,'status'=>1])->find();
|
||||
$permission = 0;
|
||||
if($gift_bag){
|
||||
$ext = json_decode($gift_bag['ext'],true);
|
||||
if($ext['activity_end_time'] <= time()){
|
||||
$permission = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return V(1,'操作成功', ['permission'=>$permission]);
|
||||
}
|
||||
//天降好礼发放
|
||||
public function drop_gift_send()
|
||||
{
|
||||
$uid = input('uid',$this->uid);
|
||||
$reslut = model('Activities')->drop_gift_send($uid);
|
||||
$reslut = model('Activities')->drop_gift_send($uid,16);
|
||||
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//新人好礼
|
||||
public function new_charge_gift()
|
||||
{
|
||||
//活动信息
|
||||
$activities_id = 7;
|
||||
$activities_title = DB::name('vs_activities')->where(['id'=>$activities_id,'status'=>1,'delete_time'=>0])->value('title');
|
||||
//礼包
|
||||
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->select();
|
||||
$data = [];
|
||||
$data['name'] = $activities_title??"";
|
||||
$data['gift_bag'] = [];
|
||||
//一键领取
|
||||
$bag_receive_all = DB::name('vs_gift_bag_receive_log')->where(['gift_bag_id'=>17,'user_id'=>$this->uid])->find();
|
||||
foreach ($gift_bag as $k=>$v){
|
||||
$data['gift_bag'][$k]['gift_bag_id'] = $v['id']??0;
|
||||
$data['gift_bag'][$k]['name'] = $v['title']??"";
|
||||
$ext = json_decode($v['ext'],true);
|
||||
$data['gift_bag'][$k]['title1'] = $ext['title1']??"";
|
||||
$data['gift_bag'][$k]['title2'] = $ext['title2']??"";
|
||||
$data['gift_bag'][$k]['money'] = $ext['money'];
|
||||
$data['gift_bag'][$k]['gift_list'] = [];
|
||||
$detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$v['id']])->select();
|
||||
$list = [];
|
||||
foreach ($detail as $kk=>$vv){
|
||||
if($vv['type'] == 1){
|
||||
$list[$kk]['gift_name'] = "金币";
|
||||
$list[$kk]['num'] = $vv['quantity'];
|
||||
$list[$kk]['gift_price'] = $vv['gold'];
|
||||
$list[$kk]['type'] = 1;
|
||||
$list[$kk]['base_image'] = localpath_to_netpath("static/image/icon/gold.png");
|
||||
}elseif ($vv['type'] == 2) {
|
||||
$gift = DB::name('vs_gift')->where(['gid'=>$vv['foreign_id']])->find();
|
||||
if($gift){
|
||||
$list[$kk]['gift_name'] = $gift['gift_name'];
|
||||
$list[$kk]['num'] = $vv['quantity'];
|
||||
$list[$kk]['gift_price'] = $gift['gift_price'];
|
||||
$list[$kk]['type'] =2;
|
||||
$list[$kk]['base_image'] = $gift['base_image'];
|
||||
}
|
||||
} elseif ($vv['type'] == 3) {
|
||||
$decorate_price = DB::name('vs_decorate_price')->where(['id'=>$vv['foreign_id']])->find();
|
||||
if($decorate_price){
|
||||
$gift = DB::name('vs_decorate')->where(['did'=>$decorate_price['did']])->find();
|
||||
$list[$kk]['gift_name'] = $gift['title']??""; //装扮名称
|
||||
$list[$kk]['num'] = $decorate_price['day']??0; //天数
|
||||
$list[$kk]['gift_price'] = $decorate_price['price']??0; //价格
|
||||
$list[$kk]['type'] =3;
|
||||
$list[$kk]['base_image'] = $gift['base_image'] ?? "";
|
||||
}
|
||||
|
||||
}elseif ($vv['type'] == 4) {
|
||||
$list[$kk]['gift_name'] = "钻石";
|
||||
$list[$kk]['num'] = $vv['quantity'];
|
||||
$list[$kk]['gift_price'] = $vv['gold'];
|
||||
$list[$kk]['type'] = 4;
|
||||
$list[$kk]['base_image'] = localpath_to_netpath("static/image/icon/diamond.png");
|
||||
}
|
||||
}
|
||||
$data['gift_bag'][$k]['gift_list'] = array_values($list);
|
||||
if($bag_receive_all){
|
||||
$data['gift_bag'][$k]['status'] = 0;
|
||||
}else{
|
||||
if($v['id']!=17){
|
||||
$bag_receive_log = DB::name('vs_gift_bag_receive_log')->where(['gift_bag_id'=>$v['id'],'user_id'=>$this->uid])->find();
|
||||
if($bag_receive_log){
|
||||
$data['gift_bag'][$k]['status'] = 0;
|
||||
} else {
|
||||
$data['gift_bag'][$k]['status'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return V(1,'操作成功', $data);
|
||||
}
|
||||
|
||||
//新人好礼发放
|
||||
public function new_charge_gift_receive()
|
||||
{
|
||||
$uid = input('uid',$this->uid);
|
||||
$money = input('money',0);
|
||||
$reslut = model('Activities')->new_charge_gift_send($uid,$money);
|
||||
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 活动权限
|
||||
*/
|
||||
public function activities_permission(){
|
||||
$system = request()->header('system');
|
||||
$app_version = request()->header('App-Version');
|
||||
if(!$app_version){
|
||||
$app_version = input('App-Version');
|
||||
}
|
||||
$api_version = 0;
|
||||
if ($system == 'iOS') {
|
||||
$api_versions = db::name('version')->where(['type' => 2, 'status' => 1])->order('id', 'desc')->find();
|
||||
$result = version_compare($api_versions['oldversion'],$app_version);
|
||||
if ($result < 0) {
|
||||
$api_version = 1;
|
||||
}
|
||||
}
|
||||
//首充
|
||||
$activities_id = 1;
|
||||
$uid = input('uid',$this->uid);
|
||||
$first_charge_permission = 1;
|
||||
//查询是否首充
|
||||
$is_first_charge = db::name('vs_user_money_log')->where('user_id',$uid)->where('change_type',2)->where('money_type',1)->where(['createtime'=>['>=',"1760666400"]])->count();
|
||||
$permission = DB::name('vs_activities_receive')->where(['activities_id'=>$activities_id,'user_id'=>$uid])->where(['createtime'=>['>=',"1760666400"]])->find();
|
||||
if($is_first_charge > 0){
|
||||
$first_charge_permission = 0;
|
||||
}
|
||||
if($permission){
|
||||
$first_charge_permission = 0;
|
||||
}
|
||||
|
||||
//天降好礼
|
||||
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>3,'status'=>1])->find();
|
||||
$day_drop_permission = 0;
|
||||
if($gift_bag){
|
||||
$ext = json_decode($gift_bag['ext'],true);
|
||||
if(strtotime($ext['activity_end_time']) >= time()){
|
||||
$day_drop_permission = 1;
|
||||
}
|
||||
}
|
||||
//新人充值好礼
|
||||
$activities = DB::name('vs_activities')->where(['id'=>7,'status'=>1,'delete_time'=>0])->find();
|
||||
if($activities){
|
||||
$effective_time = $activities['effective_time'];
|
||||
}else{
|
||||
$effective_time = 0;
|
||||
}
|
||||
$bag_data = DB::name('vs_gift_bag')->where(['activities_id'=>7,'status'=>1,'delete_time'=>0])->select();
|
||||
$bag_receive_log = DB::name('vs_gift_bag_receive_log')->where(['gift_bag_id'=>['in',array_column($bag_data,'id')],'user_id'=>$uid])->select();
|
||||
$new_permission = 0;
|
||||
$user_info = DB::name('user')->where(['id'=>$uid])->find();
|
||||
if($user_info['createtime']<"1760666400"){
|
||||
$user_info['createtime'] = 1760666400;
|
||||
}
|
||||
if($user_info['createtime'] + $effective_time >= time()){
|
||||
$new_permission = 1;
|
||||
}
|
||||
$gift_bag_log_ids = array_column($bag_receive_log,'gift_bag_id');
|
||||
if(in_array(17,$gift_bag_log_ids)){
|
||||
$new_permission = 0;
|
||||
}else{
|
||||
$gift_bag_log_ids = array_intersect([14,15,16],$gift_bag_log_ids);
|
||||
if(count($gift_bag_log_ids) == 3){
|
||||
$new_permission = 0;
|
||||
}
|
||||
}
|
||||
return V(1,'操作成功',[
|
||||
'first_charge_permission'=>$first_charge_permission,
|
||||
'day_drop_permission'=>$day_drop_permission,
|
||||
'n_people_permission'=>$new_permission
|
||||
],$api_version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
131
application/api/controller/BlindBoxTurntable.php
Normal file
131
application/api/controller/BlindBoxTurntable.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
/*
|
||||
* 盲盒转盘
|
||||
* 2025-08-16
|
||||
*/
|
||||
|
||||
class BlindBoxTurntable extends BaseCom
|
||||
{
|
||||
protected function initialize()
|
||||
{
|
||||
//允许跨域
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取活动奖池礼物列表
|
||||
*/
|
||||
public function get_gift_list(){
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->get_gift_list($gift_bag_id,$room_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 抽奖
|
||||
*
|
||||
*/
|
||||
public function draw_gift(){
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$user_id = $this->uid;
|
||||
$room_id = input('room_id',0);
|
||||
$gift_user_ids = input('gift_user_ids',0);
|
||||
$num = input('num',1);
|
||||
$heart_id = input('heart_id',0);
|
||||
$auction_id = input('auction_id',0);
|
||||
$reslut = model('BlindBoxTurntableGiftDrawWorld')->draw_gift($gift_bag_id, $user_id, $gift_user_ids,$num,$room_id,$heart_id,$auction_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 礼物发放
|
||||
*/
|
||||
public function gift_send(){
|
||||
// $key_name = "api:blind_box_turntable:gift_send:" . $this->uid;
|
||||
// redis_lock_exit($key_name);
|
||||
$send_id = input('send_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->gift_send($send_id);
|
||||
// redis_unlock($key_name);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取我的抽奖记录
|
||||
*/
|
||||
public function get_my_record(){
|
||||
$user_id = $this->uid;
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$reslut = model('BlindBoxTurntableGift')->get_user_record($gift_bag_id,$user_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取全服抽奖记录
|
||||
*/
|
||||
public function get_all_record(){
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$reslut = model('BlindBoxTurntableGift')->get_all_record($gift_bag_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 巡乐会
|
||||
*/
|
||||
public function xlh(){
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_gift_list($room_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会抽奖
|
||||
*/
|
||||
public function xlh_draw_gift(){
|
||||
$user_id = $this->uid;
|
||||
$room_id = input('room_id',0);
|
||||
$num = input('num',1);
|
||||
$reslut = model('BlindBoxTurntableGiftDrawWorld')->xlh_draw_gift($user_id,$num,$room_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 获取我的巡乐会记录
|
||||
*/
|
||||
public function get_xlh_my_record(){
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$user_id = $this->uid;
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_get_user_record($user_id,$room_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 获取全服巡乐会记录(榜单)
|
||||
*/
|
||||
public function get_xlh_all_record(){
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_ranking($room_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会榜单 (以期数显示)
|
||||
*/
|
||||
public function get_xlh_ranking(){
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_ranking_list($room_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,12 @@ use think\Controller;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
class Ceshi extends Controller
|
||||
class Ceshi extends Controllers
|
||||
{
|
||||
//测试 发送各种消息
|
||||
|
||||
//设置白名单ip访问本类接口
|
||||
protected $allowIp = [
|
||||
'113.201.181.82'
|
||||
];
|
||||
|
||||
//发送群组系统消息
|
||||
public function send_group_system_notification()
|
||||
@@ -148,8 +150,15 @@ class Ceshi extends Controller
|
||||
//清空数据 禁用 慎用 !!!!!!
|
||||
//清空数据 禁用 慎用 !!!!!!
|
||||
//清空数据 禁用 慎用 !!!!!!
|
||||
public function clear_data()
|
||||
public function qing_chu_data()
|
||||
{
|
||||
//ip
|
||||
$ip = request()->ip();
|
||||
//白名单
|
||||
$white_list = $this -> allowIp;
|
||||
if (!in_array($ip, $white_list)) {
|
||||
return V(301, '非法访问!');
|
||||
}
|
||||
$i = 0;
|
||||
$res = [];
|
||||
//开启事务
|
||||
@@ -202,17 +211,17 @@ class Ceshi extends Controller
|
||||
|
||||
|
||||
$user = db::name('user')->where('id','>', 0)->select();
|
||||
if($user){
|
||||
foreach ($user as &$v){
|
||||
if($v['id']){
|
||||
$j = 0;
|
||||
$data[$j] = [
|
||||
'UserID' => 'u'.$v['id'],
|
||||
];
|
||||
}
|
||||
model('Tencent')->account_deletes($data);
|
||||
}
|
||||
}
|
||||
// if($user){
|
||||
// foreach ($user as &$v){
|
||||
// if($v['id']){
|
||||
// $j = 0;
|
||||
// $data[$j] = [
|
||||
// 'UserID' => 'u'.$v['id'],
|
||||
// ];
|
||||
// }
|
||||
// // model('Tencent')->account_deletes($data);
|
||||
// }
|
||||
// }
|
||||
|
||||
$reslut9 = db::name('user')->where('id','>', 0)->delete();
|
||||
if($reslut9){
|
||||
@@ -449,9 +458,9 @@ class Ceshi extends Controller
|
||||
|
||||
//删除腾讯房间
|
||||
$room = db::name('vs_room')->select();
|
||||
foreach ($room as &$value){
|
||||
model('Tencent')->delete_group('room'.$value['id']);
|
||||
}
|
||||
// foreach ($room as &$value){
|
||||
// // model('Tencent')->delete_group('room'.$value['id']);
|
||||
// }
|
||||
$reslut35 = db::name('vs_room')->where('id','>', 0)->delete();
|
||||
if($reslut35){
|
||||
$i++ ;
|
||||
@@ -763,7 +772,63 @@ class Ceshi extends Controller
|
||||
//数组末尾添加元素
|
||||
array_push($res, '财富等级日志删除失败!');
|
||||
}
|
||||
$reslut68 = db::name('vs_user_friending')->where('id','>', 0)->delete();
|
||||
if($reslut68){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '用户好友删除失败!');
|
||||
}
|
||||
$reslut69 = db::name('vs_user_friending_heart')->where('id','>', 0)->delete();
|
||||
if($reslut69){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '用户好友心跳删除失败!');
|
||||
}
|
||||
$reslut70 = db::name('vs_room_hot_value_log')->where('id','>', 0)->delete();
|
||||
if($reslut70){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '房间热度值日志删除失败!');
|
||||
}
|
||||
|
||||
$reslut71 = db::name('vs_blind_box_turntable_results_log')->where('id','>', 0)->delete();
|
||||
if($reslut71){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '盲盒转盘结果日志删除失败!');
|
||||
}
|
||||
$reslut72 = db::name('vs_blind_box_turntable_log')->where('id','>', 0)->delete();
|
||||
if($reslut72){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '盲盒转盘日志删除失败!');
|
||||
}
|
||||
$reslut73 = db::name('vs_room_pan_xlh')->where('id','>', 0)->delete();
|
||||
if($reslut73){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '房间寻乐会删除失败!');
|
||||
}
|
||||
$reslut74 = db::name('vs_room_pan_xlh_log')->where('id','>', 0)->delete();
|
||||
if($reslut74){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '房间寻乐会日志删除失败!');
|
||||
}
|
||||
$reslut75 = db::name('vs_room_pan')->where('id','>', 0)->delete();
|
||||
if($reslut75){
|
||||
$i++ ;
|
||||
}else{
|
||||
//数组末尾添加元素
|
||||
array_push($res, '房间盘删除失败!');
|
||||
}
|
||||
|
||||
//数据提交
|
||||
db::commit();
|
||||
|
||||
@@ -24,4 +24,29 @@ class Cron
|
||||
$cron = new \app\cron\controller\TenSeconds();
|
||||
$cron->index();
|
||||
}
|
||||
|
||||
//每天执行
|
||||
public function DaySeconds()
|
||||
{
|
||||
$cron = new \app\cron\controller\DaySeconds();
|
||||
$cron->index();
|
||||
}
|
||||
|
||||
//巡乐会结束 礼物发放
|
||||
public function XlhSend(){
|
||||
$cron = new \app\cron\controller\RoomPan();
|
||||
$cron->index();
|
||||
}
|
||||
|
||||
//交友房结束
|
||||
public function FriendEnd(){
|
||||
$cron = new \app\cron\controller\FriendEnd();
|
||||
$cron->index();
|
||||
}
|
||||
|
||||
//房间小时榜发礼物(每小时执行一次)
|
||||
public function RoomHourRanking(){
|
||||
$cron = new \app\cron\controller\RoomHourRanking();
|
||||
$cron->index();
|
||||
}
|
||||
}
|
||||
65
application/api/controller/Friend.php
Normal file
65
application/api/controller/Friend.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
|
||||
class Friend extends BaseCom
|
||||
{
|
||||
//交友开始
|
||||
public function start_friend(){
|
||||
$key_name = "api:friend:start_friend:" . $this->uid;
|
||||
redis_lock_exits($key_name);
|
||||
$room_id = input('room_id', '');
|
||||
$reslut = model('Friend')->start_friend($this->uid,$room_id);
|
||||
redis_unlocks($key_name);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//交友延时
|
||||
public function delay(){
|
||||
$friend_id = input('friend_id', '');
|
||||
$room_id = input('room_id', '');
|
||||
$delay_times = input('delay_times', '');//分钟
|
||||
|
||||
$reslut = model('Friend')->delay($this->uid,$room_id,$friend_id,$delay_times);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//交友结束
|
||||
public function end_friend(){
|
||||
|
||||
$friend_id = input('friend_id', '');
|
||||
$room_id = input('room_id', '');
|
||||
|
||||
$result = model('Friend')->end_friend($this->uid,$room_id,$friend_id);
|
||||
|
||||
return V($result['code'], $result['msg'], $result['data']);
|
||||
}
|
||||
|
||||
//卡关系 创建关系
|
||||
public function create_relation()
|
||||
{
|
||||
$key_name = "api:friend:create_relation:" . $this->uid;
|
||||
redis_lock_exits($key_name);
|
||||
$room_id = input('room_id', '');
|
||||
$friend_id = input('friend_id', '');
|
||||
$user1_id = input('user1_id', '');
|
||||
$user2_id = input('user2_id', '');
|
||||
$relation_id = input('relation_id', '');
|
||||
$result = model('Friend')->createRelation($this->uid,$room_id,$friend_id,$user1_id,$user2_id,$relation_id);
|
||||
redis_unlocks($key_name);
|
||||
return V($result['code'], $result['msg'], $result['data']);
|
||||
}
|
||||
|
||||
//退出私密小屋
|
||||
public function out_room()
|
||||
{
|
||||
$room_id = input('room_id', '');
|
||||
|
||||
$result = model('Friend')->outRoom($this->uid,$room_id);
|
||||
|
||||
return V($result['code'], $result['msg'], $result['data']);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,8 @@ class Gift extends BaseCom
|
||||
public function get_gift_list()
|
||||
{
|
||||
$label = input('label',0);
|
||||
$reslut = model('Gift')->get_gift_list($label);
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('Gift')->get_gift_list($label,$room_id);
|
||||
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
||||
}
|
||||
//聊天送礼物 (音信)
|
||||
|
||||
@@ -22,7 +22,6 @@ class Guild extends BaseCom
|
||||
public function guild_list()
|
||||
{
|
||||
$page = input('page',1);
|
||||
$page = $page > 0 ? $page : 1;
|
||||
$limit = input('limit',10);
|
||||
$search = input('search_id','');
|
||||
$reslut = model('Guild')->get_guild_list($page,$limit,$search,$this->uid);
|
||||
|
||||
@@ -20,7 +20,7 @@ class Index extends BaseCom
|
||||
$is_top = input('is_top', 0); //1非置顶2置顶
|
||||
$label_id = input('label_id', 0);
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 15);
|
||||
$page_limit = input('page_limit', 20);
|
||||
|
||||
$reslut = model('Room')->room_list($label_id,$is_top, $page, $page_limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data'], $reslut['api_version']);
|
||||
@@ -29,7 +29,7 @@ class Index extends BaseCom
|
||||
//房间类型列表
|
||||
public function room_type_list()
|
||||
{
|
||||
$list = db::name('vs_room_type')->where('status', 1)->field('id,type_name as label_name')->select();
|
||||
$list = db::name('vs_room_type')->where(['status' => 1, 'deletetime' => 0])->field('id,type_name as label_name')->order('sort asc')->select();
|
||||
//给前面添加一组数据
|
||||
array_unshift($list, ['id' => -1, 'label_name' => '热门']);
|
||||
return V(1, '获取成功', $list);
|
||||
|
||||
@@ -49,6 +49,7 @@ class Invited extends BaseCom
|
||||
}
|
||||
$reslut['init_code'] = $init_code ? $init_code:'';
|
||||
$invited_draw = get_system_config_value('invited_draw');
|
||||
$reslut['invited_draw'] = $invited_draw;
|
||||
//说明
|
||||
$reslut['explain'] = '绑定成功后,您每次充值金额的'.$invited_draw.'%'.'将以钻石形式赠送给邀请人,满足提现金额邀请人可以直接提现';
|
||||
return V(1,'操作成功',$reslut);
|
||||
|
||||
@@ -26,18 +26,35 @@ class Payment extends Controller
|
||||
$user_id = input('user_id', 0);
|
||||
$money = input('money', 0);
|
||||
$coin = input('coin', 0);
|
||||
$type_params = input('type_params', 0);
|
||||
$type_id = input('type_id', 0);
|
||||
|
||||
if(!$coin){
|
||||
$coin = $money * get_system_config_value('rmb_coin_ratio');
|
||||
}
|
||||
if (!$user_id) {
|
||||
return V(0, '请选择充值用户', null);
|
||||
}
|
||||
//获取用户的手机号
|
||||
$user_phone = db::name('user')->where(["id" => $user_id])->value('mobile');
|
||||
if(!$user_phone){
|
||||
return V(0, '请先绑定手机号!', null);
|
||||
}
|
||||
//获取用户的实名信息
|
||||
$real_name = db::name('user_auth')->where(["mobile" => $user_phone,'is_real' => 1])->find();
|
||||
if(!$real_name){
|
||||
return V(0, '请先实名认证', null);
|
||||
}
|
||||
//获取用户的年龄
|
||||
if(!getAgeId($real_name['card_id'])){
|
||||
return V(0, '未成年不可充值!', null);
|
||||
}
|
||||
|
||||
if (!is_numeric($money) || floor($money) != $money || $money <= 0 || $money >= 2000) {
|
||||
if (!is_numeric($money) || floor($money) != $money || $money <= 0 || $money > 2000) {
|
||||
return V(0, '请选择正确的充值金额', null);
|
||||
}
|
||||
$user_code = db::name('user')->where(["id" => $user_id])->value('user_code');
|
||||
$title = "APP充值到用户 " . ($user_code ?? "") . " 余额!";
|
||||
$title = "APP充值到用户". ($user_code ?? "") ."余额!";
|
||||
|
||||
$order_number = $this->createOrderSn();
|
||||
$data['order_sn'] = $order_number;
|
||||
@@ -46,7 +63,9 @@ class Payment extends Controller
|
||||
$data['user_id'] = $user_id;
|
||||
$data['pay_type'] = $type;
|
||||
$data['createtime'] = time();
|
||||
$data['remarke'] = '充值到app用户'.($user_code ?? "") ."余额!";;
|
||||
$data['remarke'] = '充值到app用户'.($user_code ?? "") ."余额!";
|
||||
$data['type_params'] = $type_params;
|
||||
$data['type_id'] = $type_id;
|
||||
|
||||
$re = db::name('vs_user_recharge')->insert($data);
|
||||
if (!$re) {
|
||||
@@ -91,6 +110,7 @@ class Payment extends Controller
|
||||
$where['order_sn']=$out_trade_no;
|
||||
$where['order_type']=1;
|
||||
$where['pay_type']=2;
|
||||
$where['pay_status']=1;
|
||||
|
||||
$data=[
|
||||
'trade_no'=>$trade_no
|
||||
@@ -135,6 +155,7 @@ class Payment extends Controller
|
||||
$where['order_sn']=$out_trade_no;
|
||||
$where['order_type']=1;//1 充值
|
||||
$where['pay_type']=1;//1微信2支付宝 3通联支付宝 4通联微信
|
||||
$where['pay_status']=1;
|
||||
|
||||
$data=[
|
||||
'trade_no'=>$transaction_id
|
||||
@@ -190,6 +211,7 @@ class Payment extends Controller
|
||||
$where['order_sn']=$out_trade_no;
|
||||
$where['order_type']=1;//1 充值
|
||||
$where['pay_type']=$pay_type;//1微信2支付宝 3通联支付宝 4通联微信
|
||||
$where['pay_status']=1;
|
||||
|
||||
$data=[
|
||||
'trade_no'=>$trade_no
|
||||
@@ -211,21 +233,26 @@ class Payment extends Controller
|
||||
* 云账户回调(提现)
|
||||
*/
|
||||
public function yun_callback(){
|
||||
$data = input("data", "");
|
||||
$mess = input("mess", "");
|
||||
$timestamp = input("timestamp", "");
|
||||
$sign = input("sign", "");
|
||||
Log::record("云账户回调信息".json_encode($_POST),"info");
|
||||
// $data = input("data", "");
|
||||
// $mess = input("mess", "");
|
||||
// $timestamp = input("timestamp", "");
|
||||
// $sign = input("sign", "");
|
||||
$data = $_POST['data']??"";
|
||||
$mess = $_POST['mess']??"";
|
||||
$timestamp = $_POST['timestamp']?? "";
|
||||
$sign = $_POST['sign']??"";
|
||||
|
||||
write_log_redis("yunzhanghu_huidiao_原始数据",$_POST);
|
||||
$yun_pay = new YunPay();
|
||||
$result = $yun_pay->yun_callback($data,$mess,$timestamp,$sign);
|
||||
if($result['code']==1){
|
||||
$data = $result['data']['data'];
|
||||
$data = $result['data'];
|
||||
if($data){
|
||||
$status = $data['status'];
|
||||
if(!isset($data['status'])){
|
||||
echo 'fail';
|
||||
die;
|
||||
}
|
||||
$status = $data['status'];
|
||||
switch ($status){
|
||||
case "1":
|
||||
// 支付成功(对于支付宝和微信支付是最终状态,对于银行卡大部分情况是终态,小概率会出现"退汇现象",状态由"成功"变为"退汇")
|
||||
|
||||
119
application/api/controller/Redpacket.php
Normal file
119
application/api/controller/Redpacket.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use app\common\service\RedpacketService;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 红包接口
|
||||
*/
|
||||
class Redpacket extends BaseCom
|
||||
{
|
||||
|
||||
/**
|
||||
* 发红包
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
|
||||
$data['user_id'] = $this->uid;
|
||||
|
||||
$service = new RedpacketService();
|
||||
$reslut = $service->create($data);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抢红包
|
||||
*/
|
||||
public function grab()
|
||||
{
|
||||
$redpacketId = input('redpacket_id', 0);
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
// 在抢红包前确保状态正确
|
||||
$service->checkAndUpdateRedpacketStatus($redpacketId);
|
||||
$reslut = $service->grabWithResult($redpacketId, $this->uid);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取抢红包结果
|
||||
*/
|
||||
public function grabResult()
|
||||
{
|
||||
$redpacketId = $this->request->get('redpacket_id');
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
$result = $service->getGrabResult($redpacketId, $this->uid);
|
||||
|
||||
if (!$result) {
|
||||
return V(0, '红包不存在');
|
||||
}
|
||||
|
||||
return V(1, '获取成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 红包详情
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$redpacketId = input('redpacket_id', 0);
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
// 在获取详情前确保状态正确
|
||||
$service->checkAndUpdateRedpacketStatus($redpacketId);
|
||||
$detail = $service->getDetail($redpacketId, $this->uid);
|
||||
|
||||
if (!$detail) {
|
||||
return V(0, '红包不存在');
|
||||
}
|
||||
|
||||
return V(1, '获取成功', $detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取倒计时选项
|
||||
*/
|
||||
public function countdownOptions()
|
||||
{
|
||||
$options = \app\common\model\Redpacket::$countdownOptions;
|
||||
$this->success('获取成功', $options);
|
||||
}
|
||||
|
||||
// 获取房间内红包列表
|
||||
public function roomRedPackets()
|
||||
{
|
||||
$roomId = $this->request->get('room_id');
|
||||
$result = Db::name('redpacket')->where(['room_id' => $roomId, 'status' => ['<=',1]])->select();
|
||||
if($result){
|
||||
foreach ($result as &$item) {
|
||||
$item['redpacket_id'] = $item['id'];
|
||||
$item['redpacket_time'] = get_system_config_value('red_packet_time');//展示时间
|
||||
$item['nickname'] = Db::name('user')->where('id', $item['user_id'])->value('nickname');
|
||||
$item['avatar'] = Db::name('user')->where('id', $item['user_id'])->value('avatar');
|
||||
$is_qiang = Db::name('redpacket_record')->where(['redpacket_id' => $item['id'], 'user_id' => $this->uid])->find();
|
||||
$item['is_qiang'] = $is_qiang ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return V(1, '获取成功', $result);
|
||||
}
|
||||
}
|
||||
@@ -149,14 +149,29 @@ class Room extends BaseCom
|
||||
//直播间送礼
|
||||
public function room_give_gift()
|
||||
{
|
||||
$key_name = "api:room:gift:" . $this->uid;
|
||||
redis_lock_exit($key_name);
|
||||
$room_id = input('room_id', 0);
|
||||
$gift_id = input('gift_id', 0);
|
||||
$gift_num = input('gift_num', 0);
|
||||
$to_uid = input('to_uid', 0);//收礼人ID,逗号隔开的字符串
|
||||
$type = input('type', 1);//1金币购买 2送背包礼物
|
||||
$pit_number = input('pit_number', 0);
|
||||
$heart_id = input('heart_id', 0);
|
||||
|
||||
$reslut = model('Room')->room_gift($this->uid, $to_uid, $gift_id, $gift_num, $type, $room_id, $pit_number);
|
||||
$reslut = model('Room')->room_gift($this->uid, $to_uid, $gift_id, $gift_num, $type, $room_id, $pit_number,$heart_id);
|
||||
redis_unlock($key_name);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//房间送礼 背包一键全清
|
||||
public function room_gift_all_clear()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$to_uid = input('to_uid', 0);//收礼人ID
|
||||
$heart_id = input('heart_id', 0);//交友
|
||||
$auction_id = input('auction_id');//竞拍
|
||||
$reslut = model('Room')->room_gift_all_clear($this->uid, $room_id, $to_uid,$heart_id,$auction_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
@@ -260,7 +275,7 @@ class Room extends BaseCom
|
||||
public function change_room_type()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$type = input('type', 1);//1-点唱,2-拍卖,3-男神,4-女神
|
||||
$type = input('type', 1);//1-点唱,2-拍卖,3-男神,4-女神,7-交友
|
||||
$reslut = model('Room')->change_room_type($this->uid, $room_id, $type);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
@@ -395,4 +410,54 @@ class Room extends BaseCom
|
||||
$reslut = model('Room')->room_online_number($room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
//房间在线列表
|
||||
public function room_online_list_ceshi()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$page = input('page', 1);
|
||||
$limit = input('limit', 50);
|
||||
$reslut = model('Room')->room_online_list($room_id, $page, $limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//房间用户当前魅力值列表
|
||||
public function room_user_charm_list()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$user_id = input('user_id', '');
|
||||
$reslut = model('Room')->room_user_charm_list($room_id, $user_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
// //创建房间
|
||||
// public function create_rooms()
|
||||
// {
|
||||
// //查询所有的房间信息
|
||||
// $room = db::name('vs_room')->field('id,user_id')->where(['room_status' => ['<>',3]])->select();
|
||||
// $i = 0;
|
||||
// foreach ($room as $value) {
|
||||
// $reslut = model('Tencent')->create_group($value['user_id'],'room'.$value['id']);
|
||||
// $i++;
|
||||
// }
|
||||
// return['code' => 1, 'msg' => '成功创建了'.$i.'个房间', 'data' => null];
|
||||
// }
|
||||
|
||||
//用户重连
|
||||
public function user_reconnect()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$reslut = model('Room')->user_reconnect($this->uid, $room_id);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//用户在房间内切后台保留机制
|
||||
public function user_in_room_background()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$type = input('type', 1);//1-切后台,2-切前台
|
||||
$reslut = model('Room')->user_in_room_background($this->uid, $room_id,$type);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
34
application/api/controller/RoomHourRanking.php
Normal file
34
application/api/controller/RoomHourRanking.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use think\Db;
|
||||
|
||||
class RoomHourRanking extends BaseCom
|
||||
{
|
||||
//房间小时榜是否开启
|
||||
public function room_hour_ranking_is_open()
|
||||
{
|
||||
$open_time = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('open_time');
|
||||
return V(1, '获取成功', ['open_time' => $open_time]);
|
||||
}
|
||||
|
||||
//房间小时榜玩法
|
||||
public function room_hour_ranking_play()
|
||||
{
|
||||
$introd = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('introd');
|
||||
return V(1, '获取成功', ['introd' => $introd]);
|
||||
}
|
||||
|
||||
//房间小时榜
|
||||
public function room_hour_ranking()
|
||||
{
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 20);
|
||||
|
||||
$reslut = model('RoomHourRanking')->room_hour_ranking($page, $page_limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ class RoomPit extends BaseCom
|
||||
//申请上麦
|
||||
public function apply_pit()
|
||||
{
|
||||
$key_name = "api:room:apply_pit:" . $this->uid;
|
||||
|
||||
$room_id = input('room_id', 0);
|
||||
$pit_number = input('pit_number', 0);
|
||||
if($room_id == 0){
|
||||
@@ -19,27 +21,19 @@ class RoomPit extends BaseCom
|
||||
if($res['code'] != 1){
|
||||
return V(0, '房间不存在', null);
|
||||
}
|
||||
//查询房间主持麦有人吗
|
||||
$room_host_info = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
|
||||
//房主,管理,主持不受此限制
|
||||
$room_owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $this->uid])->find();
|
||||
//管理
|
||||
$room_manager = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $this->uid,'type' => 2,'delete_time' => null])->find();
|
||||
//主持
|
||||
$room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $this->uid,'type' => 1,'delete_time' => null])->find();
|
||||
if($room_host_info == 0 && !$room_owner && !$room_manager && !$room_host){
|
||||
return V(0, '上麦请联系主持', null);
|
||||
}
|
||||
|
||||
$room_label = $res['data']['label_id'];
|
||||
$room_type = $res['data']['type_id'];
|
||||
|
||||
if(($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4))|| $room_type == 2){
|
||||
redis_lock_exits($key_name);
|
||||
if(($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4 || $room_type == 8))|| $room_type == 2 || $room_type == 7){
|
||||
$reslut = model('RoomPit')->apply_pit($this->uid, $room_id,$pit_number);
|
||||
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4 || $room_type == 8)){
|
||||
$reslut = model('RoomSong')->apply_kpit($this->uid, $room_id,$pit_number);
|
||||
}else{
|
||||
redis_unlocks($key_name);
|
||||
return V(0, '房间不存在', null);
|
||||
}
|
||||
redis_unlocks($key_name);
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($this->uid,$room_id,7,0,$pit_number);
|
||||
|
||||
@@ -113,9 +107,9 @@ class RoomPit extends BaseCom
|
||||
}
|
||||
$room_label = $res['data']['label_id'];
|
||||
$room_type = $res['data']['type_id'];
|
||||
if(($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)) || $room_type == 2){
|
||||
if(($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4 || $room_type == 8)) || $room_type == 2 || $room_type == 7){
|
||||
$reslut = model('RoomPit')->DownPit($this->uid, $room_id,$pit_number);
|
||||
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
}elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4 || $room_type == 8)){
|
||||
$reslut = model('RoomSong')->down_kpit($this->uid, $room_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class RoomSong extends BaseCom
|
||||
public function up_song(){
|
||||
$room_song_id = input('did');
|
||||
$type = input('type');//1上移,2置顶
|
||||
$res = model('RoomSong')->up_song($room_song_id,$type);
|
||||
$res = model('RoomSong')->up_song($this->uid,$room_song_id,$type);
|
||||
return V($res['code'], $res['msg'], $res['data']);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,16 @@ class Search extends BaseCom
|
||||
if(is_numeric($search)){
|
||||
$where = [
|
||||
'room_number' => $search,
|
||||
'apply_status' => 2
|
||||
'apply_status' => 2,
|
||||
'type_id' => ['<>',6],
|
||||
'room_status' => 1
|
||||
];
|
||||
}else{
|
||||
$where = [
|
||||
'room_name' => ['like', '%'.$search . '%'],
|
||||
'apply_status' => 2
|
||||
'apply_status' => 2,
|
||||
'type_id' => ['<>',6],
|
||||
'room_status' => 1
|
||||
];
|
||||
}
|
||||
|
||||
@@ -84,7 +88,7 @@ class Search extends BaseCom
|
||||
$lists[$k]['picture'] = $v['room_cover'];
|
||||
$lists[$k]['code'] = $v['room_number'];
|
||||
$lists[$k]['label_icon'] = db::name('vs_room_label')->where('id', $v['label_id'])->value('label_icon');
|
||||
$lists[$k]['hot_value'] = $v['hot_value'];
|
||||
$lists[$k]['hot_value'] = $v['today_hot_value'];
|
||||
}elseif($type == 3){
|
||||
$lists[$k]['id'] = $v['id'];
|
||||
$lists[$k]['name'] = $v['guild_name'];
|
||||
@@ -96,4 +100,59 @@ class Search extends BaseCom
|
||||
|
||||
return V(1, '获取成功', $lists);
|
||||
}
|
||||
|
||||
|
||||
//搜索
|
||||
public function search_list()
|
||||
{
|
||||
$search = input('search', '');
|
||||
|
||||
if(is_numeric($search)){
|
||||
$where = [
|
||||
'user_code' => $search,
|
||||
'status' => 1
|
||||
];
|
||||
$where1 = [
|
||||
'room_number' => $search,
|
||||
'apply_status' => 2,
|
||||
'type_id' => ['<>',6],
|
||||
'room_status' => 1
|
||||
];
|
||||
}else{
|
||||
$where = [
|
||||
'nickname' => ['like', '%'.$search . '%'],
|
||||
'status' => 1
|
||||
];
|
||||
$where1 = [
|
||||
'room_name' => ['like', '%'.$search . '%'],
|
||||
'apply_status' => 2,
|
||||
'type_id' => ['<>',6],
|
||||
'room_status' => 1
|
||||
];
|
||||
}
|
||||
|
||||
$users = db::name('user')->field('id as user_id,nickname,avatar,user_code,sex')->where($where)->select();
|
||||
|
||||
if(isset($users)){
|
||||
foreach ($users as &$v){
|
||||
$v['room_id'] = 0;
|
||||
//是否在房间
|
||||
$is_room = db::name('vs_room_visitor')->where(['user_id' => $v['user_id'], 'is_delete' => 1])->order('id desc')->value('room_id');
|
||||
if ($is_room) {
|
||||
$v['room_id'] = $is_room;
|
||||
}
|
||||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
||||
$v['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
|
||||
}
|
||||
}
|
||||
|
||||
$rooms = db::name('vs_room')->field('id as room_id,room_name,room_cover,room_number,label_id,today_hot_value')->where($where1)->select();
|
||||
if(isset($rooms)){
|
||||
foreach ($rooms as $vv){
|
||||
$vv['label_icon'] = db::name('vs_room_label')->where('id', $vv['label_id'])->value('label_icon');
|
||||
$vv['hot_value'] = $vv['today_hot_value'];
|
||||
}
|
||||
}
|
||||
return V(1, '获取成功', ['users' => $users, 'rooms' => $rooms]);
|
||||
}
|
||||
}
|
||||
16
application/api/controller/Tencent.php
Normal file
16
application/api/controller/Tencent.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Controller;
|
||||
|
||||
class Tencent extends Controller
|
||||
{
|
||||
public function call_back()
|
||||
{
|
||||
$data = input('post.');
|
||||
$sign_data = input('get.');
|
||||
$reslut = model('Tencent')->tencent_call_back($data,$sign_data);
|
||||
return json($reslut);
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,37 @@ class Theme extends controller
|
||||
}
|
||||
/*
|
||||
* 启动页列表
|
||||
* @return array
|
||||
*
|
||||
* app背景图片 app_bg
|
||||
* 首页选中 home_sel
|
||||
* 首页正常 home_nor
|
||||
* 广场选中 find_sel
|
||||
* 广场正常 find_nor
|
||||
* 消息选中 msg_sel
|
||||
* 消息正常 msg_nor
|
||||
* 我的选中 mine_sel
|
||||
* 我的正常 mine_nor
|
||||
* 主题色 theme_color
|
||||
* 按钮文字颜色 btn_text_color
|
||||
*/
|
||||
public function get_theme_data()
|
||||
{
|
||||
$reslut = DB::name('vs_theme')->where('is_active',1)->where('delete_time',0)->find();
|
||||
$reslut = DB::name('vs_theme')->field('theme_color,file_url,auxiliary_color')
|
||||
->where(['delete_time' => 0 ,'is_active' => 1,'begin_time' => ['<',time()],'end_time' => ['>',time()]])->order('id desc')->find();
|
||||
|
||||
if($reslut){
|
||||
$url = $reslut['file_url'];
|
||||
$reslut['btn_text_color'] = $reslut['auxiliary_color'];
|
||||
$reslut['app_bg'] = get_system_config_value('web_site').'/static/theme/'.$url.'/app_bg.png';
|
||||
$reslut['home_sel'] = get_system_config_value('web_site').'/static/theme/'.$url.'/home_sel.png';
|
||||
$reslut['home_nor'] = get_system_config_value('web_site').'/static/theme/'.$url.'/home_nor.png';
|
||||
$reslut['find_sel'] = get_system_config_value('web_site').'/static/theme/'.$url.'/find_sel.png';
|
||||
$reslut['find_nor'] = get_system_config_value('web_site').'/static/theme/'.$url.'/find_nor.png';
|
||||
$reslut['msg_sel'] = get_system_config_value('web_site').'/static/theme/'.$url.'/msg_sel.png';
|
||||
$reslut['msg_nor'] = get_system_config_value('web_site').'/static/theme/'.$url.'/msg_nor.png';
|
||||
$reslut['mine_sel'] = get_system_config_value('web_site').'/static/theme/'.$url.'/mine_sel.png';
|
||||
$reslut['mine_nor'] = get_system_config_value('web_site').'/static/theme/'.$url.'/mine_nor.png';
|
||||
}
|
||||
|
||||
return V(1,'操作成功', $reslut);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,15 @@ class User extends BaseCom
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//关注房间(红包专用)
|
||||
public function follow_room()
|
||||
{
|
||||
$room_id = input('room_id', 0);
|
||||
$type = input('type', 1);//1-收藏,0-取消收藏
|
||||
$reslut = model('user')->follow_room($this->uid, $room_id,$type);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//用户关系卡(亲密拍)、关系位(真爱拍)
|
||||
public function user_cp_list()
|
||||
{
|
||||
|
||||
@@ -24,13 +24,21 @@ class UserGiftPack extends BaseCom
|
||||
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//获取背包礼物列表总值
|
||||
public function get_gift_pack_list_count()
|
||||
{
|
||||
$user_id = $this->uid;
|
||||
$reslut = model('UserGiftPack')->get_gift_pack_list_count($user_id);
|
||||
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//背包收入
|
||||
public function get_gift_pack_income()
|
||||
{
|
||||
$user_id = $this->uid;
|
||||
$page = input('page',1);
|
||||
$page_limit = input('page_limit',10);
|
||||
$reslut = model('UserGiftPack')->income_user_gift_pack($user_id,$page=1,$page_limit=10);
|
||||
$reslut = model('UserGiftPack')->income_user_gift_pack($user_id,$page,$page_limit);
|
||||
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
@@ -40,7 +48,7 @@ class UserGiftPack extends BaseCom
|
||||
$user_id = $this->uid;
|
||||
$page = input('page',1);
|
||||
$page_limit = input('page_limit',10);
|
||||
$reslut = model('UserGiftPack')->get_gift_pack_outcome($user_id,$page=1,$page_limit=10);
|
||||
$reslut = model('UserGiftPack')->get_gift_pack_outcome($user_id,$page,$page_limit);
|
||||
return V($reslut['code'],$reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
|
||||
39
application/api/controller/Xintiao.php
Normal file
39
application/api/controller/Xintiao.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
|
||||
class Xintiao extends BaseCom
|
||||
{
|
||||
|
||||
|
||||
public function keep_xintiao()
|
||||
{
|
||||
$user_id = $this->uid;
|
||||
$is_xintiao = db::name('vs_xintiao')->where('user_id' , $user_id)->find();
|
||||
if($is_xintiao){
|
||||
db::name('vs_xintiao')->where('user_id' , $user_id)->update(['updatetime' => time()]);
|
||||
}else{
|
||||
db::name('vs_xintiao')->insert([
|
||||
'user_id' => $user_id,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
434
application/api/controller/Xxiaoshi.php
Normal file
434
application/api/controller/Xxiaoshi.php
Normal file
@@ -0,0 +1,434 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
use app\common\controller\Push;
|
||||
|
||||
class Xxiaoshi extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function send_gift()
|
||||
{
|
||||
//获取上一个小时的开始时间和结束时间
|
||||
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
$end_time = strtotime(date('Y-m-d H:00:00'));
|
||||
echo "开始时间:" .$start_time."\n";
|
||||
echo "结束时间:" .$end_time."\n";
|
||||
//当前小时的前一个小时(24小时计时法,0-23)
|
||||
$pre_hour = date('H', strtotime('-1 hour'));
|
||||
echo "上个时间段:" .$pre_hour."\n";
|
||||
$is_open_time = db::name('vs_hour_ranking_config')->where('id', 1)->value('open_time');
|
||||
if ($is_open_time == 0) {
|
||||
echo "未开启时间段:" .$is_open_time."\n";
|
||||
return;
|
||||
}
|
||||
//是否全局飘瓶
|
||||
$is_public_server = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_public_server');
|
||||
if ($is_public_server == 1) {
|
||||
//全局飘瓶时间段
|
||||
$xlh_time_range = db::name('vs_hour_ranking_config')->where('id', 1)->value('broadcast_times');
|
||||
if($xlh_time_range){
|
||||
if($xlh_time_range == 25){
|
||||
$is_piao = 1;
|
||||
}else{
|
||||
|
||||
//当前的前一个小时是否在 $xlh_time_range中
|
||||
if (in_array($pre_hour, explode(',', $xlh_time_range))) {
|
||||
$is_piao = 1;
|
||||
} else {
|
||||
$is_piao = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$is_piao = 0;
|
||||
}
|
||||
}else{
|
||||
$is_piao = 0;
|
||||
}
|
||||
|
||||
//获取上一个时间段的配置
|
||||
// $gift_list = db::name('vs_hour_ranking_gift_config')->where('time_id',$pre_hour)->group('ranking')->order('id', 'desc')->select();
|
||||
$gift_list = $this->get_hour_ranking($pre_hour);
|
||||
// echo "上个时间段的配置:" .json_encode($gift_list)."\n";
|
||||
// 提取所有有奖励的内容
|
||||
$allRewards = $this->extractAllRewards($gift_list);
|
||||
// 按index分组
|
||||
$groupedRewards = $this->groupRewardsByIndex($allRewards);
|
||||
// 按名次顺序分配奖励
|
||||
$distributionResult = $this->distributeByRank($groupedRewards);
|
||||
|
||||
//获取上个数组的个数,从而获取配置了多少个名次
|
||||
$count = count($distributionResult);
|
||||
echo "上个时间段的配置总数:" .$count."\n";
|
||||
//获取前一个小时的 前$count名房间排行
|
||||
$room_list = model('api/RoomHourRanking')->room_hour_ranking(1, $count, $start_time, $end_time);
|
||||
$room_owner = [];
|
||||
if ($room_list['code'] == 1) {
|
||||
//获取房间排行奖励最低值
|
||||
$min_price = db::name('vs_hour_ranking_config')->where('id', 1)->value('min_price');
|
||||
if ($room_list['data']['lists']) {
|
||||
echo "房间列表:" .json_encode($room_list['data']['lists'])."\n";
|
||||
foreach ($room_list['data']['lists'] as $v){
|
||||
if ($v['total_price'] >= $min_price) {
|
||||
$room_owner[] = [
|
||||
'user_id' => $v['user_id'],
|
||||
'room_name' => $v['room_name'],
|
||||
'room_id' => $v['room_id'],
|
||||
'total_price' => $v['total_price']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($distributionResult && $room_owner) {
|
||||
$text_list_new = [];
|
||||
echo "礼物数:" .json_encode($distributionResult)."\n";
|
||||
echo "房主:" .json_encode($room_owner)."\n";
|
||||
foreach ($distributionResult as $k => $value) {
|
||||
//礼物全部给他偷偷放在装扮表及金额 中
|
||||
//有几个用户就发几个
|
||||
if(count($room_owner) > $k){
|
||||
// 为每个房间添加一个标志,表示是否已处理推送信息
|
||||
$hasProcessedPush = false;
|
||||
|
||||
foreach ($value['rewards'] as $v){
|
||||
// if($v['type'] == 0){//1金币2礼物3头像4坐骑
|
||||
// echo "发金币:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
|
||||
// $res = $this->add_coin($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
|
||||
// }elseif ($v['type'] == 1){
|
||||
// echo "发礼物:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
|
||||
// $res = $this->add_gift($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
|
||||
// }elseif ($v['type'] == 2){
|
||||
// $res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,3);
|
||||
// }elseif ($v['type'] == 3){
|
||||
// $res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,4);
|
||||
// }
|
||||
// 只有在第一次处理奖励时添加推送信息,避免重复推送
|
||||
if(!$hasProcessedPush && $is_piao == 1) {
|
||||
$room_name = $room_owner[$k]['room_name'];
|
||||
//推送礼物横幅
|
||||
if ($k == 0) {
|
||||
$text = '新科状元!【' . $room_name . '】独占鳌头!';
|
||||
} elseif ($k == 1) {
|
||||
$text = '金榜榜眼!【' . $room_name . '】才气逼人!';
|
||||
} elseif ($k == 2) {
|
||||
$text = '风采探花!【' . $room_name . '】实力绽放!';
|
||||
}
|
||||
|
||||
$text_list_new[] = [
|
||||
'text' => $text ?? '恭喜【' . $room_name . '】获得礼物!',
|
||||
'room_id' => $room_owner[$k]['room_id'],
|
||||
'room_name' => $room_name,
|
||||
'rank_number' => $k + 1,
|
||||
];
|
||||
|
||||
$hasProcessedPush = true; // 标记已处理推送
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(!empty($text_list_new)){
|
||||
$push = new Push();
|
||||
$push->hourRankingcs($text_list_new);
|
||||
Log::record("小时榜推送:".json_encode($text_list_new),"infos");
|
||||
}
|
||||
}
|
||||
echo "送礼-共" . count($room_owner) . "个房间房主获益\n";
|
||||
}
|
||||
|
||||
//添加金币到钱包
|
||||
// public function add_coin($coin,$user_id,$ranking,$room_id,$total_price,$is_piao){
|
||||
// if($coin > 0){
|
||||
// $data = [
|
||||
// 'user_id' => $user_id,
|
||||
// 'change_value' => $coin,
|
||||
// // 'room_id' => $room_ids,
|
||||
// 'money_type' => 1,
|
||||
// 'change_type' => 27,
|
||||
// 'from_id' => 0,
|
||||
// 'remarks' => '小时榜获得',
|
||||
// 'createtime' => time()
|
||||
// ];
|
||||
|
||||
// //开启事务
|
||||
// Db::startTrans();
|
||||
// $res = Db::name('vs_user_money_log')->insert($data);
|
||||
// if(!$res){
|
||||
// Db::rollback();
|
||||
// }
|
||||
|
||||
// //增加用户金币
|
||||
// $res1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setInc('coin',$coin);
|
||||
// if(!$res1){
|
||||
// Db::rollback();
|
||||
// }
|
||||
|
||||
// //添加到排行表
|
||||
// $start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
// $end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
// $res2 = db::name('vs_hour_ranking')->insert([
|
||||
// 'ranking' => $ranking,
|
||||
// 'room_id' => $room_id,
|
||||
// 'flowing_water' => $total_price,
|
||||
// 'coin' => $coin,
|
||||
// 'time_id' => date('H', strtotime('-1 hour')),
|
||||
// 'stime' => $start_time,
|
||||
// 'etime' => $end_time,
|
||||
// 'createtime' => time(),
|
||||
// 'updatetime' => time(),
|
||||
// 'is_public_server' => $is_piao
|
||||
// ]);
|
||||
// if(!$res2){
|
||||
// Db::rollback();
|
||||
// }
|
||||
// Db::commit();
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// //添加礼物到背包
|
||||
// public function add_gift($gift_id,$user_id,$ranking,$room_id,$total_price,$is_piao){
|
||||
// $res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$gift_id,1,model('UserGiftPack')::HOUR_RANK_GET,"小时榜获得");
|
||||
// if($res['code'] == 0){
|
||||
// Log::record("小时榜获取礼物失败:".$res['msg'],"info");
|
||||
// }
|
||||
|
||||
// //添加到排行表
|
||||
// $start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
// $end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
// $res2 = db::name('vs_hour_ranking')->insert([
|
||||
// 'ranking' => $ranking,
|
||||
// 'room_id' => $room_id,
|
||||
// 'flowing_water' => $total_price,
|
||||
// 'gift_id' => $gift_id,
|
||||
// 'gift_type' => 2,
|
||||
// 'time_id' => date('H', strtotime('-1 hour')),
|
||||
// 'stime' => $start_time,
|
||||
// 'etime' => $end_time,
|
||||
// 'createtime' => time(),
|
||||
// 'updatetime' => time(),
|
||||
// 'is_public_server' => $is_piao
|
||||
// ]);
|
||||
// if(!$res2){
|
||||
// Log::record("小时榜礼物锁定失败","info");
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// //添加装扮到背包
|
||||
// public function add_decorate($avatar_id,$user_id,$ranking,$room_id,$total_price,$is_piao,$type){
|
||||
// $decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$avatar_id])->find();
|
||||
// if(empty($decorate_price_info)){
|
||||
// Log::record("小时榜获取装扮失败:没有找到装扮!".$avatar_id,"info");
|
||||
// }
|
||||
// $res = model('api/Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],2);
|
||||
// if($res['code'] == 0){
|
||||
// Log::record("小时榜获取装扮失败:".$res['msg']."-".$avatar_id,"info");
|
||||
// }
|
||||
// //添加到排行表
|
||||
// $start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
// $end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
// $res2 = db::name('vs_hour_ranking')->insert([
|
||||
// 'ranking' => $ranking,
|
||||
// 'room_id' => $room_id,
|
||||
// 'flowing_water' => $total_price,
|
||||
// 'gift_id' => $avatar_id,
|
||||
// 'gift_type' => $type,
|
||||
// 'time_id' => date('H', strtotime('-1 hour')),
|
||||
// 'stime' => $start_time,
|
||||
// 'etime' => $end_time,
|
||||
// 'createtime' => time(),
|
||||
// 'updatetime' => time(),
|
||||
// 'is_public_server' => $is_piao,
|
||||
// ]);
|
||||
// if(!$res2){
|
||||
// Log::record("小时榜咋装扮锁定失败","info");
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 提取所有有奖励的内容
|
||||
*/
|
||||
private function extractAllRewards($responseData)
|
||||
{
|
||||
$allRewards = [];
|
||||
|
||||
foreach ($responseData as $timeSlot) {
|
||||
foreach ($timeSlot['reward'] as $rewardItem) {
|
||||
$index = $rewardItem['index'];
|
||||
$content = $rewardItem['content'];
|
||||
|
||||
// 只处理有奖励内容的数据
|
||||
if (!empty($content)) {
|
||||
foreach ($content as $rewardContent) {
|
||||
$allRewards[] = [
|
||||
'index' => $index,
|
||||
'type' => $rewardContent['type'],
|
||||
'value' => $rewardContent['value'],
|
||||
'name' => $rewardContent['name'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $allRewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按index分组奖励
|
||||
*/
|
||||
private function groupRewardsByIndex($allRewards)
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($allRewards as $reward) {
|
||||
$index = $reward['index'];
|
||||
if (!isset($grouped[$index])) {
|
||||
$grouped[$index] = [];
|
||||
}
|
||||
$grouped[$index][] = $reward;
|
||||
}
|
||||
|
||||
// 按index排序
|
||||
ksort($grouped);
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按名次顺序分配奖励
|
||||
*/
|
||||
private function distributeByRank($groupedRewards)
|
||||
{
|
||||
$distribution = [];
|
||||
$currentRank = 0; // 从第1名开始
|
||||
|
||||
// 按index顺序分配(index 0 = 第1名,index 1 = 第2名,以此类推)
|
||||
foreach ($groupedRewards as $index => $rewards) {
|
||||
// 确保名次连续,如果有空缺则填充空名次
|
||||
while ($currentRank < $index) {
|
||||
$distribution[] = [
|
||||
'rank' => $currentRank + 1,
|
||||
'rewards' => []
|
||||
];
|
||||
$currentRank++;
|
||||
}
|
||||
|
||||
// 分配当前名次的奖励
|
||||
$distribution[] = [
|
||||
'rank' => $currentRank + 1,
|
||||
'rewards' => $rewards
|
||||
];
|
||||
$currentRank++;
|
||||
}
|
||||
|
||||
return $distribution;
|
||||
}
|
||||
|
||||
public function get_hour_ranking($time){
|
||||
// 先按时间段和排名索引分组查询
|
||||
$timeRanges = db::name('vs_hour_ranking_gift_config')->distinct(true)
|
||||
->where('time_id', '=', $time)
|
||||
->order('time_id')
|
||||
->column('time_id');
|
||||
|
||||
$result = [];
|
||||
foreach ($timeRanges as $timeRange) {
|
||||
// 查询该时间段的所有数据
|
||||
$rewards = db::name('vs_hour_ranking_gift_config')->where('time_id', $timeRange)
|
||||
->field('ranking, gift_type, gift_id,coin,name')
|
||||
->order('ranking')
|
||||
->select();
|
||||
|
||||
$rewardMap = [];
|
||||
foreach ($rewards as $reward) {
|
||||
$rankIndex = $reward['ranking'];
|
||||
|
||||
if (!isset($rewardMap[$rankIndex])) {
|
||||
$rewardMap[$rankIndex] = [
|
||||
'index' => $rankIndex,
|
||||
// 'name' => $reward['rank_name'],
|
||||
'content' => []
|
||||
];
|
||||
}
|
||||
|
||||
// 添加奖励内容到content数组
|
||||
if ($reward['gift_id'] != 0 || $reward['coin'] != 0) {
|
||||
if($reward['gift_id'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['gift_id'],
|
||||
// 'coin' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
if($reward['coin'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 按index排序
|
||||
ksort($rewardMap);
|
||||
|
||||
$result[] = [
|
||||
'time' => $timeRange,
|
||||
'reward' => array_values($rewardMap)
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function give_gifts(){
|
||||
$data = db::name('vs_give_gift')->where('from_id',5483)->select();
|
||||
$num = 0;
|
||||
$i=0;
|
||||
$j = 0;
|
||||
foreach($data as $v){
|
||||
$j += $v['total_price'];
|
||||
$nuu = db::name('vs_give_gift_ratio_log')->where('give_gift_id',$v['id'])->value('room_owner_earning');
|
||||
$id = db::name('vs_give_gift_ratio_log')->where('give_gift_id',$v['id'])->value('id');
|
||||
// echo $id."--".$nuu."\n";
|
||||
$num += $nuu;
|
||||
$i++;
|
||||
}
|
||||
echo $num;
|
||||
echo "==".$i."==".$j;
|
||||
|
||||
// echo db::name()->where(['user_id' => 10857,'money_type' =>2,'change_type' =>18])-sum('change_value');
|
||||
}
|
||||
|
||||
|
||||
public function room_liushui(){
|
||||
// $room = db::name('vs_give_gift')->where(['from_id' => ['<>',5418],'from' => 2])->group('from_id');
|
||||
$dd = db::name('vs_user_gift_pack')->alias('a')->join('vs_gift b','a.gid = b.gid')->field('a.gid,a.num,b.gift_price')->where(['a.num' =>['>',0]])->select();
|
||||
$count = 0;
|
||||
foreach ($dd as $v){
|
||||
$count += $v['gift_price'] * $v['num'];
|
||||
}
|
||||
echo $count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -108,7 +108,7 @@ return [
|
||||
'该装扮天数不存在' => '该装扮天数不存在',
|
||||
'该个人靓号已被购买' => '该个人靓号已被购买',
|
||||
'该房间靓号已被购买' => '该房间靓号已被购买',
|
||||
'该工会靓号已被购买' => '该工会靓号已被购买',
|
||||
'该公会靓号已被购买' => '该公会靓号已被购买',
|
||||
'用户信息错误' => '用户信息错误',
|
||||
'非法资金类型' => '非法资金类型',
|
||||
'当前用户金币已达上限' => '当前用户金币已达上限',
|
||||
|
||||
@@ -25,7 +25,8 @@ class Activities extends Model
|
||||
public static function first_charge_gift_send($user_id,$money=0)
|
||||
{
|
||||
//礼包
|
||||
$gift_bag_id = DB::name('vs_gift_bag')->where(['activities_id'=>1,'status'=>1,'money'=>$money])->value('id');
|
||||
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>1,'status'=>1,'delete_time'=>0,'money'=>['<=',$money]])->order('money desc')->find();
|
||||
$gift_bag_id = $gift_bag['id'] ?? 0;
|
||||
if (!$gift_bag_id) {
|
||||
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
||||
}
|
||||
@@ -36,21 +37,29 @@ class Activities extends Model
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($gift_bag_detail as $k=>$v){
|
||||
$gift_id =0;
|
||||
$gift_price = 0;
|
||||
$gift_num = $v['quantity'];
|
||||
switch ($v['type']) {
|
||||
case 1: //金币 方法1:直接添加到用户钱包
|
||||
$gift_price = $v['quantity'];
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::FIRST_CHARGE,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::FIRST_CHARGE));
|
||||
break;
|
||||
case 2: //礼物 方法2:添加到用户礼物背包
|
||||
$gift_id = $v['foreign_id'];
|
||||
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::FIRST_CHARGE,"首充好礼获得礼物");
|
||||
break;
|
||||
case 3: //坐骑 方法3:添加到用户装扮
|
||||
$gift_id = $v['foreign_id'];
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
||||
if(empty($decorate_price_info)){
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
$gift_price = $decorate_price_info['price'];
|
||||
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],5);
|
||||
break;
|
||||
case 4: //道具 方法5:钻石
|
||||
$gift_price = $v['quantity'];
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::FIRST_CHARGE,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::FIRST_CHARGE));
|
||||
default:
|
||||
break;
|
||||
@@ -59,15 +68,19 @@ class Activities extends Model
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
// 记录日志
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'gift_id'=> $gift_id,
|
||||
'gift_price' => $gift_price,
|
||||
'num' => $gift_num,
|
||||
'bag_price' => $money,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
}
|
||||
// 记录日志
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
// 添加活动记录
|
||||
$reslut = Db::name('vs_activities_receive')->insert([
|
||||
'user_id' => $user_id,
|
||||
@@ -86,14 +99,19 @@ class Activities extends Model
|
||||
/*
|
||||
* 天降好礼发放
|
||||
*/
|
||||
public static function drop_gift_send($user_id)
|
||||
public static function drop_gift_send($user_id,$money=0)
|
||||
{
|
||||
$activities_id = 3;
|
||||
//礼包
|
||||
$gift_bag_id = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->value('id');
|
||||
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->find();
|
||||
$gift_bag_id = $gift_bag['id'] ?? 0;
|
||||
|
||||
if (!$gift_bag_id) {
|
||||
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
||||
}
|
||||
if($money != $gift_bag['money']){
|
||||
return ['code' => 0, 'msg' => '充值金额未命中天降好礼礼包','data' => null];
|
||||
}
|
||||
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select();
|
||||
if (!$gift_bag_detail) {
|
||||
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
||||
@@ -111,7 +129,7 @@ class Activities extends Model
|
||||
case 3: //坐骑 方法3:添加到用户装扮
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
||||
if(empty($decorate_price_info)){
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],6);
|
||||
break;
|
||||
@@ -124,15 +142,20 @@ class Activities extends Model
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
// 记录日志
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'parent_id' => $v['id'],
|
||||
'gift_id'=> $v['foreign_id'],
|
||||
'num' => $v['quantity'],
|
||||
'bag_price' => $gift_bag['money'],
|
||||
'gift_price' => $v['gold'],
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
}
|
||||
// 记录日志
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
// 添加活动记录
|
||||
$reslut = Db::name('vs_activities_receive')->insert([
|
||||
'user_id' => $user_id,
|
||||
@@ -148,4 +171,85 @@ class Activities extends Model
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 新人好礼发放
|
||||
*/
|
||||
public static function new_charge_gift_send($user_id,$money=0)
|
||||
{
|
||||
//礼包
|
||||
$activities_id = 7;
|
||||
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1,'delete_time'=>0,'money'=>$money])->order('money desc')->find();
|
||||
$gift_bag_id = $gift_bag['id'] ?? 0;
|
||||
if (!$gift_bag_id) {
|
||||
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
|
||||
}
|
||||
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select();
|
||||
if (!$gift_bag_detail) {
|
||||
return ['code' => 0, 'msg' => '礼包未配置','data' => null];
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($gift_bag_detail as $k=>$v){
|
||||
$gift_id =0;
|
||||
$gift_price = 0;
|
||||
$gift_num = $v['quantity'];
|
||||
switch ($v['type']) {
|
||||
case 1: //金币 方法1:直接添加到用户钱包
|
||||
$gift_price = $v['quantity'];
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::NEW_USER_CHARGE_GIFT,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::NEW_USER_CHARGE_GIFT));
|
||||
break;
|
||||
case 2: //礼物 方法2:添加到用户礼物背包
|
||||
$gift_id = $v['foreign_id'];
|
||||
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::NEW_CHARGE_GIFT,"新人好礼获得礼物");
|
||||
break;
|
||||
case 3: //坐骑 方法3:添加到用户装扮
|
||||
$gift_id = $v['foreign_id'];
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
|
||||
if(empty($decorate_price_info)){
|
||||
break;
|
||||
}
|
||||
$gift_price = $decorate_price_info['price'];
|
||||
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],8);
|
||||
break;
|
||||
case 4: //道具 方法5:钻石
|
||||
$gift_price = $v['quantity'];
|
||||
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::NEW_USER_CHARGE_GIFT,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::NEW_USER_CHARGE_GIFT));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ($res['code'] != 1) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
|
||||
}
|
||||
// 记录日志
|
||||
//添加礼盒记录
|
||||
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'parent_id' => $v['id'],
|
||||
'gift_id'=> $v['foreign_id'],
|
||||
'num' => $v['quantity'],
|
||||
'bag_price' => $gift_bag['money'],
|
||||
'gift_price' => $v['gold'],
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
}
|
||||
// 添加活动记录
|
||||
$reslut = Db::name('vs_activities_receive')->insert([
|
||||
'user_id' => $user_id,
|
||||
'activities_id' => 1,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => null];
|
||||
}catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => "请重试", 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ class Banner extends Model
|
||||
{
|
||||
protected $table = 'fa_vs_banner';
|
||||
public $ShowType = [
|
||||
// 1 => '引导页',
|
||||
// 2 => '启动页',
|
||||
1 => '引导页',
|
||||
2 => '启动页',
|
||||
3 => '首页轮播图',
|
||||
4 => '工会',
|
||||
5 => '帮助反馈'
|
||||
4 => '房间首页',
|
||||
5 => '工会列表页广告位'
|
||||
];
|
||||
//1纯展示 2文章 3房间 4个人主页 5外站'
|
||||
public $Type = [
|
||||
|
||||
416
application/api/model/BlindBoxTurntableGift.php
Normal file
416
application/api/model/BlindBoxTurntableGift.php
Normal file
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
use app\common\controller\Push;
|
||||
use think\Cache;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use think\Session;
|
||||
/*
|
||||
* 盲盒转盘
|
||||
* 2025-08-16
|
||||
*/
|
||||
class BlindBoxTurntableGift extends Model
|
||||
{
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = true;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $table = 'fa_vs_gift';
|
||||
|
||||
//获取奖池礼物列表
|
||||
public function get_gift_list($gift_bag_id,$room_id)
|
||||
{
|
||||
$box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$gifts = db::name('vs_gift_bag_detail')->where('gift_bag_id',$gift_bag_id)->order("id desc")->select();
|
||||
$gift_list = [];
|
||||
foreach ($gifts as $key => $value) {
|
||||
$gift_data = db::name('vs_gift')->where('gid',$value['foreign_id'])->where('delete_time',0)->find();
|
||||
if($gift_data){
|
||||
$gift_list[$key]['number'] = $key;
|
||||
$gift_list[$key]['gift_id'] = $gift_data['gid'];
|
||||
$gift_list[$key]['gift_name'] = $gift_data['gift_name'];
|
||||
$gift_list[$key]['base_image'] = $gift_data['base_image'];
|
||||
$gift_list[$key]['play_image'] = $gift_data['play_image'];
|
||||
$gift_list[$key]['gift_price'] = $gift_data['gift_price'];
|
||||
}
|
||||
}
|
||||
$ext = json_decode($box['ext'],true);
|
||||
$box_gift = Db::name('vs_gift')->where('gid',$ext['gift_id'])->find();
|
||||
|
||||
//巡乐会
|
||||
$is_xlh = 0;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',13)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$xlh = [];
|
||||
if($xlh_ext['inlet_bag_id'] == $box['id']){
|
||||
$is_xlh = 1;
|
||||
$xlh['waiting_start_num'] = $xlh_ext['open_condition']['waiting_start_num'];//等待开奖次数
|
||||
$xlh['start_num'] = $xlh_ext['open_condition']['start_num'];//开始开奖次数
|
||||
//当前抽奖次数
|
||||
$xlh['current_num'] = Cache::get("xlh_periods_num") ?? 0;
|
||||
//状态
|
||||
if($xlh['current_num'] >= $xlh_ext['open_condition']['start_num']){
|
||||
$xlh['status'] = 1;//状态 1:巡乐会开始 2:即将开始开始 0:等待开始
|
||||
} elseif($xlh['current_num'] >= $xlh_ext['open_condition']['waiting_start_num'] && $xlh['current_num'] < $xlh_ext['open_condition']['start_num']){
|
||||
$xlh['status'] = 2;//状态 1:巡乐会开始 2:即将开始开始 0:等待开始
|
||||
}else{
|
||||
$xlh['status'] = 0;
|
||||
}
|
||||
}
|
||||
$result_data = [
|
||||
'title' => $box['name'],
|
||||
'rule_url' => get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$box["id"],
|
||||
'box_price' => $box_gift['gift_price'],
|
||||
'is_xlh' => $is_xlh,
|
||||
'xlh_data' => $xlh,
|
||||
'gift_list' => $gift_list,
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $result_data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 礼物特效播放
|
||||
*/
|
||||
public function gift_send($send_id){
|
||||
try{
|
||||
$blind_box_turntable = db('vs_blind_box_turntable_log')->where(['id'=>$send_id,'is_sued'=>0])->find();
|
||||
if(!$blind_box_turntable){
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
$room_id = $blind_box_turntable['room_id'];
|
||||
$blind_box_turntable_log = db('vs_blind_box_turntable_results_log')->where(['tid'=>$send_id])->select();
|
||||
if(!$blind_box_turntable_log){
|
||||
return ['code' => 0, 'msg' => '数据不存在','data' => null];
|
||||
}
|
||||
$room_name = Db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->value('room_name');
|
||||
$FromUserInfo = Db::name('user')->where(['id'=>$blind_box_turntable['user_id']])->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($blind_box_turntable['user_id']);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($blind_box_turntable['user_id']);//魅力图标
|
||||
$user_nickname = $FromUserInfo['nickname'];
|
||||
$textMessage = $user_nickname;
|
||||
$text_message = [];
|
||||
foreach ($blind_box_turntable_log as $key => $value) {
|
||||
$ToUserInfo = Db::name('user')->where(['id' => $value['gift_user_id']])->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$draw_gift = Db::name('vs_gift')->where(['gid'=>$value['gift_id']])->find();
|
||||
$textMessage = $textMessage . ' 送给 ' . $ToUserInfo['nickname']. ' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$value['count']."\n";
|
||||
$play_image[] = $draw_gift['play_image'];
|
||||
$gift_names[] = $draw_gift['gift_name'];
|
||||
|
||||
$text_message = $user_nickname . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $value['count']."\n";
|
||||
if($draw_gift['is_public_server'] == 1) {
|
||||
$text_list_new[] = [
|
||||
'text' => $text_message,
|
||||
'gift_picture' => $draw_gift['base_image'],
|
||||
'room_id' => $room_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $draw_gift['gift_name'],
|
||||
'roomId' => $room_id,
|
||||
'number' => $value['count'],
|
||||
];
|
||||
}
|
||||
$ToUserInfosList[$value['gift_user_id']] = $ToUserInfo;
|
||||
|
||||
}
|
||||
foreach($ToUserInfosList as &$userInfo) {
|
||||
$userInfo['icon'][0] = model('UserData')->user_wealth_icon($userInfo['user_id']);//财富图标
|
||||
$userInfo['icon'][1] = model('UserData')->user_charm_icon($userInfo['user_id']);//魅力图标
|
||||
$userInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $userInfo['user_id'],'room_id' => $room_id])->value('charm');//魅力
|
||||
$ToUserInfos[] = $userInfo;
|
||||
}
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfos' => $ToUserInfos,
|
||||
'GiftInfo' => [
|
||||
'play_image' => implode(',',$play_image),
|
||||
'gift_name' => implode(',',$gift_names),
|
||||
],
|
||||
'text' => rtrim($textMessage, "\n")
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1005,$room_id,$text);
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $room_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $room_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $room_id,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$room_id,$text1);
|
||||
}else{
|
||||
if(!empty($text_list_new)){
|
||||
//推送礼物横幅
|
||||
$push = new Push($blind_box_turntable['user_id'], $room_id);
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
}
|
||||
db::name('vs_blind_box_turntable_log')->where('id', $send_id)->update(['is_sued' => 1, 'updatetime' => time()]);
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => null];
|
||||
} catch (\Exception $e) {
|
||||
return ['code' => 0, 'msg' => "网络请求错误,请重试!", 'data' => null];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取用户抽奖记录
|
||||
*/
|
||||
public function get_user_record($gift_bag_id,$user_id=0,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['b.gift_bag_id'] = $gift_bag_id;
|
||||
if($user_id > 0){
|
||||
$where['b.user_id'] = $user_id;
|
||||
}
|
||||
$list = db('vs_blind_box_turntable_results_log')
|
||||
->alias('a')
|
||||
->join('vs_blind_box_turntable_log b','b.id = a.tid','left')
|
||||
->join('user c','a.gift_user_id = c.id','left')
|
||||
->join('vs_gift d','d.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.count,a.gift_user_id,a.createtime,c.nickname,d.gift_name as gift_name,d.base_image')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
/*
|
||||
* 获取全服抽奖记录
|
||||
*/
|
||||
public function get_all_record($gift_bag_id,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['b.gift_bag_id'] = $gift_bag_id;
|
||||
$where['d.gift_bag_id'] = $gift_bag_id;
|
||||
$where['d.is_world_show'] = 1;
|
||||
$list = db('vs_blind_box_turntable_results_log')
|
||||
->alias('a')
|
||||
->join('vs_blind_box_turntable_log b','b.id = a.tid','left')
|
||||
->join('user c','b.user_id = c.id','left')
|
||||
->join('vs_gift_bag_detail d','d.foreign_id = a.gift_id','left')
|
||||
->join('vs_gift e','e.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.count,b.user_id,a.createtime,c.nickname,d.name as gift_name,e.base_image')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
/*
|
||||
* 巡乐会
|
||||
*/
|
||||
public function xlh_gift_list($room_id){
|
||||
$gift_bag_id = 13;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$gifts = db::name('vs_gift_bag_detail')->where('gift_bag_id',$gift_bag_id)->order("id desc")->select();
|
||||
$gift_list = [];
|
||||
foreach ($gifts as $key => $value) {
|
||||
$gift_data = db::name('vs_gift')->where('gid',$value['foreign_id'])->where('delete_time',0)->find();
|
||||
if($gift_data){
|
||||
$gift_list[$key]['number'] = $key;
|
||||
$gift_list[$key]['gift_id'] = $gift_data['gid'];
|
||||
$gift_list[$key]['gift_name'] = $gift_data['gift_name'];
|
||||
$gift_list[$key]['base_image'] = $gift_data['base_image'];
|
||||
$gift_list[$key]['play_image'] = $gift_data['play_image'];
|
||||
$gift_list[$key]['gift_price'] = $gift_data['gift_price'];
|
||||
}
|
||||
}
|
||||
//房主信息
|
||||
// $room_user = db::name('user')->where('id',$room_data['user_id'])->find();
|
||||
//房主礼物
|
||||
$room_user_gift = db::name('vs_gift')->where('gid',$xlh_ext['locking_condition']['give_homeowner_gift_id'])->find();
|
||||
//巡乐会主礼物
|
||||
$xlh_main_gift = db::name('vs_gift')->where('gid',$xlh_ext['locking_condition']['locking_gift_id'])->find();
|
||||
//中奖用户
|
||||
$pan_xlh = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'end_time'=>['>',time()]])->order('id desc')->find();
|
||||
$xlh_periods_num = Cache::get("xlh_periods_num") ?? 0;
|
||||
if(empty($pan_xlh)){
|
||||
if($xlh_periods_num >= $xlh_ext['open_condition']['start_num']){
|
||||
$xlh_periods = Cache::get("this_xlh_periods") ?? 0;
|
||||
$pan_xlh_id = db::name('vs_room_pan_xlh')->insertGetId([
|
||||
'room_id' => $room_id,
|
||||
'gift_id' => $xlh_ext['locking_condition']['locking_gift_id'],
|
||||
'homeowner_gift_id' => $xlh_ext['locking_condition']['give_homeowner_gift_id'],
|
||||
'periods' => $xlh_periods+1,
|
||||
'num' => 0,
|
||||
'end_time' => time() + $xlh_ext['locking_time']['end_time'] * 60,
|
||||
'createtime' => time()
|
||||
]);
|
||||
Cache::set("this_xlh_periods", $xlh_periods+1, 0);//修改巡乐会期数
|
||||
$pan_xlh = db::name('vs_room_pan_xlh')->where(['id'=>$pan_xlh_id])->find();
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '巡乐会已结束', 'data' => null];
|
||||
}
|
||||
}
|
||||
$xlh_user_data= null;
|
||||
$room_user_data = null;
|
||||
if($pan_xlh && $pan_xlh['user_id']){
|
||||
$xlh_user = db::name('user')->where('id',$pan_xlh['user_id'])->find();
|
||||
$xlh_user_data = [
|
||||
'user_id' => $xlh_user['id'],
|
||||
'nickname' => $xlh_user['nickname'],
|
||||
'avatar' => $xlh_user['avatar'],
|
||||
];
|
||||
if($pan_xlh['room_id']){
|
||||
$room_data = db::name('vs_room')->field('xlh_periods,xlh_periods_num,user_id')-> where('id',$pan_xlh['room_id'])->find();
|
||||
$room_user = db::name('user')->where('id',$room_data['user_id'])->find();
|
||||
$room_user_data = [
|
||||
'user_id' => $room_user['id'],
|
||||
'nickname' => $room_user['nickname'],
|
||||
'avatar' => $room_user['avatar'],
|
||||
];
|
||||
}
|
||||
}
|
||||
//$gift_list 按gift_price 升序排序
|
||||
usort($gift_list, function($a, $b) {
|
||||
return $a['gift_price'] - $b['gift_price'];
|
||||
});
|
||||
|
||||
$result_data = [
|
||||
'title' => $xlh_box['name'],
|
||||
'rule_url' => get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$xlh_box["id"],
|
||||
'box_price' => $xlh_ext['xlh_box_price'],
|
||||
'xlh_end_time' =>$pan_xlh['end_time']??0,
|
||||
'give_homeowner_gift' => [
|
||||
'gift_id' => $room_user_gift['gid'],
|
||||
'gift_name' => $room_user_gift['gift_name'],
|
||||
'gift_price' => $room_user_gift['gift_price'],
|
||||
'base_image' => $room_user_gift['base_image'],
|
||||
],
|
||||
'homeowner_user' => $room_user_data,
|
||||
'locking_gift' => [
|
||||
'gift_id' => $xlh_main_gift['gid'],
|
||||
'gift_name' => $xlh_main_gift['gift_name'],
|
||||
'gift_price' => $xlh_main_gift['gift_price'],
|
||||
'base_image' => $xlh_main_gift['base_image'],
|
||||
'gift_num' => $pan_xlh['num']??0
|
||||
],
|
||||
'xlh_user' => $xlh_user_data,
|
||||
'gift_list' => $gift_list,
|
||||
];
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $result_data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会抽奖记录
|
||||
*/
|
||||
public function xlh_get_user_record($user_id,$room_id,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['a.gift_bag_id'] = 13;
|
||||
$where['a.user_id'] = $user_id;
|
||||
$list = db('vs_gift_bag_receive_pan_log')
|
||||
->alias('a')
|
||||
->join('vs_room_pan_xlh b','b.id = a.parent_id','left')
|
||||
->join('vs_gift c','c.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.num as count,a.createtime,c.gift_name as gift_name,c.base_image')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会榜单
|
||||
*/
|
||||
public function xlh_ranking($room_id,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['a.gift_bag_id'] = 13;
|
||||
$where['e.is_world_show'] = 1;
|
||||
$list = db('vs_gift_bag_receive_pan_log')
|
||||
->alias('a')
|
||||
->join('vs_room_pan_xlh b','b.id = a.parent_id','left')
|
||||
->join('vs_gift c','c.gid = a.gift_id','left')
|
||||
->join('fa_user d','d.id = a.user_id','left')
|
||||
->join('vs_gift_bag_detail e','e.foreign_id = a.gift_id','left')
|
||||
->field('a.gift_id,a.num as count,a.createtime,c.gift_name,c.base_image,d.nickname')
|
||||
->where($where)
|
||||
->order('a.createtime desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取用户当前房间的巡乐会信息
|
||||
*/
|
||||
public function get_user_xlh_info($room_id){
|
||||
$gift_bag_id = 13;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$xlh_data = db('vs_room_pan_xlh')->where(["send_time"=>0,"end_time"=>[">",time()]])->field('id,room_id,periods,end_time')->order('periods desc')->find();
|
||||
//寻乐会状态
|
||||
$xlh_status = 0;
|
||||
// 状态
|
||||
$xlh_periods_num = Cache::get("xlh_periods_num") ?? 0;
|
||||
if($xlh_periods_num >= $xlh_ext['open_condition']['start_num']){
|
||||
$xlh_status = 1;//状态 1:巡乐会开始 2:即将开始 0:等待开始
|
||||
} elseif($xlh_periods_num >= $xlh_ext['open_condition']['waiting_start_num'] && $xlh_periods_num < $xlh_ext['open_condition']['start_num']){
|
||||
$xlh_status = 2;//状态 1:巡乐会开始 2:即将开始开始 0:等待开始
|
||||
}else{
|
||||
$xlh_status = 0;//未开始
|
||||
}
|
||||
return [
|
||||
'activities_name' => $xlh_box['name'],
|
||||
'icon' => null,
|
||||
'xlh_status'=>$xlh_status,
|
||||
'end_time'=>$xlh_data['end_time'] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会榜单
|
||||
*
|
||||
*/
|
||||
public function xlh_ranking_list($room_id,$page=1,$page_size=12){
|
||||
$gift_bag_id = 13;
|
||||
$xlh_box = db::name('vs_gift_bag')->where('id',$gift_bag_id)->find();
|
||||
$xlh_ext = json_decode($xlh_box['ext'],true);
|
||||
$pan_xlh = db::name('vs_room_pan_xlh')
|
||||
->order('id desc')
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
$list = [];
|
||||
foreach ($pan_xlh as $key=>$value){
|
||||
$list[$key]['periods'] = "第".$value['periods']."期";
|
||||
if(!empty($value['user_id'])){
|
||||
$list[$key]['nickname'] = db::name('user')->where(['id'=>$value['user_id']])->value('nickname');
|
||||
}else{
|
||||
$list[$key]['nickname'] = "无";
|
||||
}
|
||||
if(!empty($value['gift_id'])){
|
||||
$gift_data = db::name('vs_gift')->field('gift_name,base_image')->where(['gid'=>$value['gift_id']])->find();
|
||||
$list[$key]['gift_name'] = 'x '.$value['num'].' '.$gift_data['gift_name'];
|
||||
$list[$key]['base_image'] = $gift_data['base_image']??"";
|
||||
}else{
|
||||
$gift_data = db::name('vs_gift')->field('gift_name,base_image')->where(['gid'=>$xlh_ext['locking_condition']['locking_gift_id']])->find();
|
||||
$list[$key]['gift_name'] = 'x 0 '.$gift_data['gift_name'];
|
||||
$list[$key]['base_image'] = $gift_data['base_image']??"";
|
||||
}
|
||||
$list[$key]['createtime'] = $value['send_time'] ? date('Y-m-d H:i:s',$value['send_time']) : '' ;
|
||||
}
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '成功',
|
||||
'data' => $list
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
1603
application/api/model/BlindBoxTurntableGiftDraw.php
Normal file
1603
application/api/model/BlindBoxTurntableGiftDraw.php
Normal file
File diff suppressed because it is too large
Load Diff
1528
application/api/model/BlindBoxTurntableGiftDrawWorld.php
Normal file
1528
application/api/model/BlindBoxTurntableGiftDrawWorld.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -89,6 +89,41 @@ class Chat extends Model
|
||||
// RoomAuctionPK = 1037,
|
||||
//送盲盒礼物推送文字消息
|
||||
// RoomGiftBlindBox = 1038,
|
||||
//换麦
|
||||
// RoomChangePit = 1039,
|
||||
|
||||
//交友房间内发送消息
|
||||
//交友房游戏阶段
|
||||
// FriendRoomGameStart = 1049,
|
||||
//交友房延时
|
||||
// FriendRoomDelay = 1050,
|
||||
//交友结束推送是否创建小房间
|
||||
// FriendRoomEnd = 1051,
|
||||
//交友房 私密小屋送礼增加结束时间
|
||||
// FriendRoomGiftBlindBox = 1052,
|
||||
//交友 房间换麦位
|
||||
// FriendRoomChangePit = 1053,
|
||||
//交友 心动值变化
|
||||
// FriendRoomChangeCharm = 1054,
|
||||
//交友 退出小房间
|
||||
// FriendRoomQuit = 1055,
|
||||
|
||||
//盲盒转盘相关推送
|
||||
//巡乐会进度推送
|
||||
// BlindBoxTurnTableProgress = 1056,
|
||||
//巡乐会抽奖结果推送
|
||||
// BlindBoxTurnTableResult = 1057,
|
||||
|
||||
//直播群成员在离线状态变更
|
||||
// RoomMemberOffline = 1058,
|
||||
|
||||
//清空个人魅力
|
||||
// ClearUserCharm = 1059,
|
||||
//发红包
|
||||
// RedPacket = 1060,
|
||||
//红包领完推送
|
||||
// RedPacketComplete = 1061,
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -98,7 +133,7 @@ class Chat extends Model
|
||||
'Text' => $content
|
||||
];
|
||||
|
||||
$data = model('Tencent')->send_group_system_notification('room'.$roomId,json_encode($text));
|
||||
$data = model('api/Tencent')->send_group_system_notification('room'.$roomId,json_encode($text));
|
||||
|
||||
if($data['code'] == 0){
|
||||
Log::record("腾讯发送群消息:".$data['msg'].$type,"info");
|
||||
|
||||
@@ -135,13 +135,13 @@ class DailyTasks extends Model
|
||||
$v['processing_type'] = 2;
|
||||
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
||||
//跳转的房间路径
|
||||
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6]])->orderRaw('rand()')->value('id');
|
||||
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6],'apply_status'=>2])->orderRaw('rand()')->value('id');
|
||||
$v['target_quantity'] = $v['target_quantity'] * 60;
|
||||
$v['is_time'] = 1;
|
||||
}elseif(in_array($v['task_id'],[10])){
|
||||
$v['processing_type'] = 7;
|
||||
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
||||
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6]])->orderRaw('rand()')->value('id');
|
||||
$v['from_id'] = db::name('vs_room')->where(['delete_time'=>0,'room_status'=>1,'type_id'=>['<>',6],'apply_status'=>2])->orderRaw('rand()')->value('id');
|
||||
} else{
|
||||
$v['processing_type'] = 9;
|
||||
$v['processing_type_str'] = $this->processing_type_str[$v['processing_type']];
|
||||
@@ -342,10 +342,10 @@ class DailyTasks extends Model
|
||||
public function gift_bag_receive_list($user_id){
|
||||
//查询每日任务礼盒记录
|
||||
$gift_bag_receive_list = Db::name('vs_gift_bag_receive_log')
|
||||
->field('bag.name as gift_bag_name,de.name as gift_name,re.createtime as createtime,de.quantity,de.type,de.foreign_id,de.days,de.gold')
|
||||
->field('bag.name as gift_bag_name,re.createtime as createtime,de.name as gift_name,de.quantity,de.type,de.foreign_id,de.days,de.gold')
|
||||
->alias('re')
|
||||
->join('vs_gift_bag bag', 'bag.id = re.gift_bag_id', 'LEFT')
|
||||
->join('vs_gift_bag_detail de', 'de.gift_bag_id = re.gift_bag_id','LEFT')
|
||||
->join('vs_gift_bag_detail de', 'de.id = re.parent_id', 'LEFT')
|
||||
->where(['re.user_id'=>$user_id,'bag.activities_id'=>2,'bag.status'=>1])
|
||||
->order('re.createtime desc')
|
||||
->select();
|
||||
|
||||
@@ -15,9 +15,9 @@ class Decorate extends Model
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
// 定义字段类型 1头像框 2坐骑 3麦圈 6个人靓号 7房间靓号 8工会靓号
|
||||
public $TypeArray = [1=>'头像框',2=>'坐骑',3=>'麦圈',6=>'个人靓号',7=>'房间靓号',8=>'工会靓号'];
|
||||
protected $FromType = [1=>'购买',2=>'后台赠送',3=>'礼盒开奖',4=>'好友赠送',5=>'首充赠送',6=>'天降好礼获得',7=>'财富等级特权赠送'];
|
||||
// 定义字段类型 1头像框 2坐骑 3麦圈 6个人靓号 7房间靓号 8公会靓号
|
||||
public $TypeArray = [1=>'头像框',2=>'坐骑',3=>'麦圈',6=>'个人靓号',7=>'房间靓号',8=>'公会靓号'];
|
||||
protected $FromType = [1=>'购买',2=>'后台赠送',3=>'礼盒开奖',4=>'好友赠送',5=>'首充赠送',6=>'天降好礼获得',7=>'财富等级特权赠送',8=>'新人充值好礼'];
|
||||
public function __construct($data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
@@ -125,7 +125,6 @@ class Decorate extends Model
|
||||
$map = [];
|
||||
$map = [
|
||||
'did' => $did,
|
||||
'is_buy' => 1,
|
||||
'delete_time' => 0,
|
||||
];
|
||||
$decorate_info = DB::name($this->table)->where($map)->find();
|
||||
@@ -150,7 +149,7 @@ class Decorate extends Model
|
||||
return ['code' => 0, 'msg' => '该房间靓号已被购买', 'data' => null];
|
||||
}
|
||||
if($decorate_info['type'] == 8 && $decorate_info['is_user_buy'] == 1){
|
||||
return ['code' => 0, 'msg' => '该工会靓号已被购买', 'data' => null];
|
||||
return ['code' => 0, 'msg' => '该公会靓号已被购买', 'data' => null];
|
||||
}
|
||||
$start_time = $now_time = time();
|
||||
Db::startTrans();
|
||||
@@ -207,6 +206,9 @@ class Decorate extends Model
|
||||
if($decorate_price_info['price']<=0 && $user_decorate_data['end_time'] > $now_time + $change_time){
|
||||
return ['code' => 0, 'msg' => '您已购买过此装扮,请勿重复购买', 'data' => null];
|
||||
}
|
||||
if($user_decorate_data['end_time'] < $now_time){
|
||||
$user_decorate_data['end_time'] = 0;
|
||||
}
|
||||
$change_time = $day * 24 * 3600;
|
||||
$update['is_using'] = 2;
|
||||
$update['end_time'] = $user_decorate_data['end_time'] + $change_time;
|
||||
@@ -368,7 +370,7 @@ class Decorate extends Model
|
||||
//用户装扮详情
|
||||
/*
|
||||
* @param $id 对象id
|
||||
* @param $type 装扮类型 1头像框 2坐骑 3麦圈 6个人靓号 7房间靓号 8工会靓号
|
||||
* @param $type 装扮类型 1头像框 2坐骑 3麦圈 6个人靓号 7房间靓号 8公会靓号
|
||||
*/
|
||||
public function user_decorate_detail($id, $type){
|
||||
//根据$type 组装查询条件
|
||||
|
||||
801
application/api/model/Friend.php
Normal file
801
application/api/model/Friend.php
Normal file
@@ -0,0 +1,801 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
|
||||
class Friend extends Model
|
||||
{
|
||||
public function start_friend($user_id, $room_id){
|
||||
// 判断用户是否在主持麦
|
||||
$host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9,'user_id' => $user_id])->find();
|
||||
if(!$host){
|
||||
return ['code' => 0, 'msg' => '没有权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
$room_info = db::name('vs_room')->field('id,step,room_status')->where(['id' => $room_id,'room_status' =>1])->find();
|
||||
if (!$room_info) {
|
||||
return ['code' => 0, 'msg' => '房间不存在!', 'data' => null];
|
||||
}
|
||||
if($room_info['step'] == 2 || $room_info['step'] == 3){
|
||||
return ['code' => 0, 'msg' => '交友正在进行中!', 'data' => null];
|
||||
}
|
||||
//在麦位上的用户
|
||||
$pit_user = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => ['<',7],'user_id' => ['<>',0]])->count();
|
||||
|
||||
if($pit_user >= 2) {
|
||||
$data['room_id'] = $room_id;
|
||||
$data['end_time'] = time() + get_system_config_value('friend_time') * 60;
|
||||
$data['create_time'] = time();
|
||||
$data['status'] = 1;
|
||||
|
||||
$id = db::name('vs_user_friending')->insertGetId($data);
|
||||
|
||||
if (!$id) {
|
||||
return ['code' => 0, 'msg' => '操作失败!', 'data' => null];
|
||||
}
|
||||
//修改房间状态
|
||||
db::name('vs_room')->where(['id' => $room_id])->update(['step' => 2]);
|
||||
//清除房间用户的魅力
|
||||
model('Room')->clear_user_charm($user_id, $room_id);
|
||||
|
||||
//推送给前端消息
|
||||
$text['text'] = '交友开始';
|
||||
$text['step'] = 2;
|
||||
$text['friend_id'] = $id;
|
||||
$text['end_time'] = $data['end_time'];
|
||||
model('api/Chat')->sendMsg(1049,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '操作成功!', 'data' => ['friend_id' => $id]];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '交友麦位至少两位用户才能开始', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//延时
|
||||
public function delay($user_id,$room_id,$id,$delay_times){
|
||||
// 判断用户是否在主持麦
|
||||
$host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9,'user_id' => $user_id])->find();
|
||||
if(!$host){
|
||||
return ['code' => 0, 'msg' => '没有权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
if (!$id || !$room_id) {
|
||||
return ['code' => 0, 'msg' => '参数有误!', 'data' => null];
|
||||
}
|
||||
if($delay_times <= 0){
|
||||
$delay_times = get_system_config_value('friend_delay_times');
|
||||
}
|
||||
//修改结束 时间
|
||||
$res = db::name('vs_user_friending')->where('id', $id)->update([
|
||||
'end_time' => Db::raw('end_time + ' . ($delay_times * 60))
|
||||
]);
|
||||
if(!$res){
|
||||
return ['code' => 0, 'msg' => '操作失败!', 'data' => null];
|
||||
}
|
||||
//推送延时
|
||||
$text['text'] = '延时';
|
||||
$text['friend_id'] = $id;
|
||||
$text['end_time'] = db::name('vs_user_friending')->where('id', $id)->value('end_time');
|
||||
model('api/Chat')->sendMsg(1050,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '操作成功!', 'data' => null];
|
||||
}
|
||||
|
||||
//交友结束(结束牵手良缘)
|
||||
public function end_friend($user_id,$room_id,$id,$is_system = 0){
|
||||
if (!$id || !$room_id) {
|
||||
return ['code' => 0, 'msg' => '参数有误!', 'data' => null];
|
||||
}
|
||||
|
||||
if($is_system == 0){
|
||||
// 判断用户是否在主持麦
|
||||
$host = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9,'user_id' => $user_id])->find();
|
||||
if(!$host){
|
||||
return ['code' => 0, 'msg' => '没有权限操作', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取心动值最高的
|
||||
$originalPairs = db::name('vs_user_friending_heart')
|
||||
->where(['room_id'=>$room_id,'friend_id'=>$id ,'status' =>1])
|
||||
->order('heart_value DESC')->find();
|
||||
$friend_heart_value = get_system_config_value('friend_heart_value');
|
||||
if($originalPairs && $originalPairs['heart_value'] >= $friend_heart_value){
|
||||
$step = 3;//结束进入牵手良缘卡关系
|
||||
//心动值达到伐值 返回用户信息与关系列表
|
||||
$return['user1_id'] =$originalPairs['user1_id'];
|
||||
$return['user1_avatar'] = db::name('user')->where(['id'=>$originalPairs['user1_id']])->value('avatar');
|
||||
$return['user1_nickname'] = db::name('user')->where(['id'=>$originalPairs['user1_id']])->value('nickname');
|
||||
$return['user2_id'] =$originalPairs['user2_id'];
|
||||
$return['user2_avatar'] = db::name('user')->where(['id'=>$originalPairs['user2_id']])->value('avatar');
|
||||
$return['user2_nickname'] = db::name('user')->where(['id'=>$originalPairs['user2_id']])->value('nickname');
|
||||
$return['heart_value'] = $originalPairs['heart_value'];
|
||||
$return['heart_id'] = $originalPairs['id'];
|
||||
$room_updatatime = db::name('vs_room')->where(['id' => $room_id,'step' => $step])->value('updatetime');
|
||||
if($room_updatatime){ //60秒内没操作 则创建关系无
|
||||
if(time() - $room_updatatime > 60){
|
||||
$this->createRelation(0,$room_id,$id,$return['user1_id'],$return['user2_id'],0);
|
||||
return ['code' => 1, 'msg' => '操作成功!', 'data' => $return];
|
||||
}
|
||||
}else{
|
||||
// 修改当前交友阶段
|
||||
db::name('vs_room')->where(['id' => $room_id])->update(['step' => $step,'updatetime' => time()]);
|
||||
}
|
||||
}else{
|
||||
$step = 1;//结束下一轮
|
||||
// 修改当前交友阶段 分开写 放到前面是为了下麦
|
||||
db::name('vs_room')->where(['id' => $room_id])->update(['step' => 1]);
|
||||
//所有人下麦
|
||||
$on_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => ['<',7],'user_id' => ['<>',0]])->select();
|
||||
if($on_pit){
|
||||
foreach ($on_pit as $pit){
|
||||
model('RoomPit')->DownPit($pit['user_id'], $room_id,$pit['pit_number']);
|
||||
}
|
||||
}
|
||||
$return = null;
|
||||
}
|
||||
|
||||
//结束交友游戏
|
||||
if($step == 1){
|
||||
db::name('vs_user_friending')->where(['id' => $id])->update(['status' => 2]);
|
||||
}
|
||||
//推送给前端消息
|
||||
$text['text'] = $step == 1 ? '交友结束' : '牵手良缘';
|
||||
$text['step'] = $step;//1 等待邂逅 2 心动连线 3 牵手良缘
|
||||
$text['friend_user'] = $return;
|
||||
$text['friend_id'] = $id;
|
||||
model('api/Chat')->sendMsg(1049,$room_id,$text);
|
||||
model('Room')->clear_user_charm(db::name('vs_room')->where(['id' => $room_id])->value('user_id'), $room_id);
|
||||
return ['code' => 1, 'msg' => '操作成功!', 'data' => $return];
|
||||
}
|
||||
|
||||
//心动值超过配置值 创建关系
|
||||
public function createRelation($user_id,$room_id,$friend_id,$user1_id,$user2_id,$friending_config_id){
|
||||
|
||||
if (!$user1_id || !$user2_id || !$friend_id || !$room_id) {
|
||||
return ['code' => 0, 'msg' => '参数有误!', 'data' => null];
|
||||
}
|
||||
|
||||
$user1 = min($user1_id, $user2_id);
|
||||
$user2 = max($user1_id, $user2_id);
|
||||
$friending_heart = db::name('vs_user_friending_heart')
|
||||
->where(['room_id'=>$room_id,'friend_id'=>$friend_id ,'user1_id' =>$user1,'user2_id' => $user2])->order('id desc')->find();
|
||||
|
||||
$originalPairs = db::name('vs_user_friending_heart')
|
||||
->where(['id'=>$friending_heart['id']])
|
||||
->update(['status' => 3,'friend_config_id' =>$friending_config_id]);
|
||||
$msg = '';
|
||||
if ($originalPairs) {
|
||||
$relation = db::name('vs_relation')->where('id',$friending_config_id)->value('name');
|
||||
if($friending_heart['heart_value'] >= get_system_config_value('friend_heart_create_room') && $friending_config_id > 0){
|
||||
//创建小房间
|
||||
$room_ids = model('api/Room')->user_create_room($user1,'的电影房',get_system_config_value('web_site').'/data/avatar/head_pic.png','交友房产生的一次性房间',7);
|
||||
if($room_ids['code'] != 1){
|
||||
$msg = 'cp电影房创建失败';
|
||||
}else{
|
||||
//记录小房间
|
||||
$datda = [
|
||||
'room_id' => $room_ids['data'],
|
||||
'relation_id' => $friending_config_id,
|
||||
'user_id' => $user1,
|
||||
'user_id1' => $user2,
|
||||
'time_day' => time() + get_system_config_value('friend_room_timea') * 60,
|
||||
'createtime' => time(),
|
||||
'status' => 1,
|
||||
'type' => 1
|
||||
];
|
||||
db::name('vs_room_cp_movie')->insert($datda);
|
||||
|
||||
if($room_ids['data']){
|
||||
$text['text'] = '交友结束并创建房间';
|
||||
$text['room_id'] = $room_ids['data'];//前端用来让用户跳转的房间id
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$text['text'] = '交友结束未创建房间';
|
||||
}
|
||||
$text['relation_name'] = $relation;
|
||||
$text['user1_id'] = $user1;
|
||||
$text['user2_id'] = $user2;
|
||||
$text['user1_avatar'] = db::name('user')->where(['id'=>$user1])->value('avatar');
|
||||
$text['user1_nickname'] = db::name('user')->where(['id'=>$user1])->value('nickname');
|
||||
$text['user2_avatar'] = db::name('user')->where(['id'=>$user2])->value('avatar');
|
||||
$text['user2_nickname'] = db::name('user')->where(['id'=>$user2])->value('nickname');
|
||||
model('api/Chat')->sendMsg(1051,$room_id,$text);
|
||||
|
||||
// 修改当前交友阶段
|
||||
db::name('vs_room')->where(['id' => $room_id])->update(['step' => 1]);
|
||||
db::name('vs_user_friending')->where(['id' => $friend_id])->update(['status' => 2]);
|
||||
//所有人下麦
|
||||
$on_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => ['<',7],'user_id' => ['<>',0]])->select();
|
||||
if($on_pit){
|
||||
foreach ($on_pit as $pit){
|
||||
model('RoomPit')->DownPit($pit['user_id'], $room_id,$pit['pit_number']);
|
||||
}
|
||||
}
|
||||
|
||||
$shijian = floor($friending_heart['heart_value']/get_system_config_value('friend_heart_value')) * get_system_config_value('friend_heart_times');
|
||||
$friendendtime = time() + $shijian * 3600;
|
||||
|
||||
//更新关系结束时间
|
||||
db::name('vs_user_friending_heart')->where(['id'=>$friending_heart['id']])->update(['contact_end_time' => $friendendtime]);
|
||||
|
||||
//关系增加时间
|
||||
$room_auction = model('RoomAuction')->room_auction_create_or_add($user1_id,$user2_id,$friending_config_id,$shijian*3600,0);
|
||||
|
||||
//推送给前端消息
|
||||
$text['text'] = '交友结束';
|
||||
$text['step'] = 1;//1 等待邂逅 2 心动连线 3 牵手良缘
|
||||
model('api/Chat')->sendMsg(1049,$room_id,$text);
|
||||
|
||||
return ['code' => 1, 'msg' => '创建关系成功!'.$msg, 'data' => null];
|
||||
} else {
|
||||
//推送给前端消息
|
||||
$text['text'] = '交友结束';
|
||||
$text['step'] = 1;//1 等待邂逅 2 心动连线 3 牵手良缘
|
||||
model('api/Chat')->sendMsg(1049,$room_id,$text);
|
||||
db::name('vs_user_friending')->where(['id' => $friend_id])->update(['status' => 2]);
|
||||
return ['code' => 0, 'msg' => '创建关系失败!', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//退出私密房间
|
||||
public function outRoom($user_id,$room_id){
|
||||
//推送给前端消息
|
||||
$text['text'] = '退出私密小屋';
|
||||
model('api/Chat')->sendMsg(1055,$room_id,$text);
|
||||
|
||||
|
||||
// //查询在房间的用户
|
||||
// $users = db::name('vs_room_visitor')->where(['room_id'=>$room_id])->select();
|
||||
// if($users){
|
||||
// //退出房间
|
||||
// foreach ($users as $v){
|
||||
// //退出房间
|
||||
// model('Room')->quit_room($v['user_id'], $room_id,$v['user_id']);
|
||||
// }
|
||||
// }else{
|
||||
// model('Room')->quit_room($user_id, $room_id,$user_id);
|
||||
// }
|
||||
|
||||
//注销房间
|
||||
db::name('vs_room')->where(['id'=>$room_id])->update(['room_status'=>3]);
|
||||
db::name('vs_room_cp_movie')->where(['room_id'=>$room_id])->update(['status'=>4]);
|
||||
model('api/Tencent')->delete_group('room'.$room_id);
|
||||
|
||||
return ['code' => 1, 'msg' => '退出成功!', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//房间内送礼
|
||||
/*
|
||||
* @param $uid 用户id
|
||||
* @param $to_uid 接收用户id组
|
||||
* @param $gift_id 礼物id
|
||||
* @param $gift_num 礼物数量
|
||||
* @param $from_type 来源 1聊天送礼物 2房间语聊送礼 3直播送礼 4动态打赏 5系统任务 6-cp房间送礼
|
||||
* @param $type 1金币购买 2送背包礼物
|
||||
* @param $room_id 房间id
|
||||
* @param $pit_number 坑位
|
||||
*/
|
||||
public function room_give_gift($uid, $to_uid, $gift_id, $gift_num, $from_type, $type, $room_id, $pit_number, $heart_id,$give_gift_ext)
|
||||
{
|
||||
$res = model('GiveGift')->give_gift($uid, $to_uid, $gift_id, $gift_num, $from_type, $type, $room_id, $pit_number,0,$give_gift_ext);
|
||||
if($res['code'] != 1){
|
||||
return $res;
|
||||
}
|
||||
|
||||
//送礼成功后续操作
|
||||
//查看当前时间是否在交友表的创建时间和结束时间段内 用来区分是否要拉取心动值高的用户上麦
|
||||
$friend = db::name('vs_user_friending')->where(['room_id' => $room_id,'status' => 1])->order('id desc')->find();
|
||||
if($friend && time() >= $friend['create_time'] && time() <= $friend['end_time']){
|
||||
$heart_exp = get_system_config_value('coin_charm_exp');//金币与魅力值转换比
|
||||
$sumPrice = $res['data']['gift_total'] * $heart_exp;
|
||||
$user_idd = $to_uid;
|
||||
|
||||
if($heart_id){//有这个值就是助力 不参加抢麦操作
|
||||
db::name('vs_user_friending_heart')->where(['id' => $heart_id])->setInc('heart_value', $sumPrice);
|
||||
$this->pullHeartChange($room_id,$friend['id']);//聊天室心动值变化通知
|
||||
//生成新排名 判断抱上麦 还是换麦
|
||||
$this->pullUserPit($room_id,$friend['id']);
|
||||
}else{
|
||||
//判断送礼人或收礼人里面有主持和嘉宾
|
||||
$host = $this->is_host($uid,$to_uid,$room_id);
|
||||
$user_idd = explode(",", $user_idd); // 将字符串转换为数组
|
||||
//判断是否是主持
|
||||
if($host['is_preside'] == 1){
|
||||
if(!in_array($uid,$host['is_preside_user'])){//主持不是当前送礼人,那就是在收礼人中
|
||||
//从数组中剔除主持人 && $is_preside_user!= UID
|
||||
$user_idd = array_diff($user_idd, $host['is_preside_user']); // 从数组中移除
|
||||
if($user_idd){
|
||||
//插入/更新心动表
|
||||
$this->addUserHeart($uid,$user_idd,$friend['id'],$sumPrice,$room_id,$res['data']['gift_user_data']);
|
||||
//送礼产生心动值并计算 判断拉取用户上麦还是换麦
|
||||
//生成新排名 判断抱上麦 还是换麦
|
||||
$this->pullUserPit($room_id,$friend['id']);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//插入/更新心动表
|
||||
$this->addUserHeart($uid,$user_idd,$friend['id'],$sumPrice,$room_id,$res['data']['gift_user_data']);
|
||||
//送礼产生心动值并计算 判断拉取用户上麦还是换麦
|
||||
//生成新排名 判断抱上麦 还是换麦
|
||||
$this->pullUserPit($room_id,$friend['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['code' => 1, 'msg' => '送礼成功', 'data' => null];
|
||||
}
|
||||
|
||||
//是否主持
|
||||
public function is_host($uid,$to_uid,$room_id){
|
||||
//获取当前主持人和嘉宾
|
||||
$host[] = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => 9])->value('user_id');
|
||||
$host[] = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => 10])->value('user_id');
|
||||
|
||||
$is_preside_user = [];
|
||||
$is_preside = 0;
|
||||
$user_ids = explode(",", $to_uid);
|
||||
foreach ($user_ids as $value) {
|
||||
//判断收礼人是否是主持
|
||||
if (in_array($value, $host)) {
|
||||
$is_preside = 1;
|
||||
$is_preside_user[] = $value;
|
||||
}
|
||||
}
|
||||
//送礼人是主持或嘉宾
|
||||
if (in_array($uid, $host)) {
|
||||
$is_preside = 1;
|
||||
$is_preside_user[] = $uid;
|
||||
}
|
||||
return ['is_preside' =>$is_preside,'is_preside_user' => $is_preside_user];
|
||||
}
|
||||
|
||||
function pullHeartChange($room_id,$friend_id){
|
||||
//聊天室心动值变化通知
|
||||
$newRanking = $this->getRanking($room_id,$friend_id);
|
||||
//心动值和心动表id
|
||||
if(!isset($newRanking[0]['heart_value']) || $newRanking[0]['heart_value'] <= 0){
|
||||
$heart1 = -1;
|
||||
$heartId1 = -1;
|
||||
}else{
|
||||
$heart1 = $newRanking[0]['heart_value'];
|
||||
$heartId1 = $newRanking[0]['id'];
|
||||
}
|
||||
if(!isset($newRanking[1]['heart_value']) || $newRanking[1]['heart_value'] <= 0){
|
||||
$heart2 = -1;
|
||||
$heartId2 = -1;
|
||||
}else{
|
||||
$heart2 = $newRanking[1]['heart_value'];
|
||||
$heartId2 = $newRanking[1]['id'];
|
||||
}
|
||||
if(!isset($newRanking[2]['heart_value']) || $newRanking[2]['heart_value'] <= 0){
|
||||
$heart3 = -1;
|
||||
$heartId3 = -1;
|
||||
}else{
|
||||
$heart3 = $newRanking[2]['heart_value'];
|
||||
$heartId3 = $newRanking[2]['id'];
|
||||
}
|
||||
$heart[0] = [
|
||||
"heartNum" => $heart1,
|
||||
"heartId" => $heartId1,
|
||||
];
|
||||
$heart[1] = [
|
||||
"heartNum" => $heart2,
|
||||
"heartId" => $heartId2,
|
||||
];
|
||||
$heart[2] = [
|
||||
"heartNum" => $heart3,
|
||||
"heartId" => $heartId3,
|
||||
];
|
||||
|
||||
// $push = new Push(0, $this->room_id); //实例化推送类
|
||||
// $push->heartChatRoom($heart);
|
||||
//推送给前端消息
|
||||
$text['text'] = '心动值变化通知';
|
||||
$text['list'] = $heart;
|
||||
model('api/Chat')->sendMsg(1054,$room_id,$text);
|
||||
return $heart;
|
||||
}
|
||||
|
||||
// 获取心跳值排行
|
||||
public function getRanking($room_id,$friend_id) {
|
||||
// 获取有心动值的用户对且不重复
|
||||
$originalPairs = db::name('vs_user_friending_heart')
|
||||
->where(['room_id'=>$room_id,'friend_id'=>$friend_id])
|
||||
->order('heart_value DESC')->select();
|
||||
// 初始化排名数组和已使用用户数组
|
||||
$ranking = [];
|
||||
$usedUsers = [];
|
||||
// 优先选择高价值且无重复用户的对
|
||||
$heart_ids = [];
|
||||
foreach ($originalPairs as &$rel) {
|
||||
// 检查当前用户对是否包含已使用的用户ID
|
||||
if (!in_array($rel['user1_id'], $usedUsers) &&
|
||||
!in_array($rel['user2_id'], $usedUsers)) {
|
||||
// 将符合条件的用户对添加到排名列表中
|
||||
$ranking[] = [
|
||||
'heart_value' => $rel['heart_value'],
|
||||
'id' => $rel['id'],
|
||||
'user1_id' => $rel['user1_id'],
|
||||
'user2_id' => $rel['user2_id'],
|
||||
];
|
||||
// 更新已使用用户列表
|
||||
$usedUsers = array_merge($usedUsers, [$rel['user1_id'], $rel['user2_id']]);
|
||||
$heart_ids[] = $rel['id'];
|
||||
// 如果排名列表达到3对用户,则停止循环
|
||||
if (count($ranking) >= 3) break;
|
||||
}
|
||||
}
|
||||
$ranking1 = [];
|
||||
$ranking2 = [];
|
||||
if(count($ranking)<3){
|
||||
$make_up_num = 3 - count($ranking);
|
||||
$ranking_make_up = db::name('vs_user_friending_heart')
|
||||
->where(['room_id'=>$room_id,'friend_id'=>$friend_id ,'id'=> ['notin',$heart_ids]])
|
||||
->limit($make_up_num)
|
||||
->order('heart_value DESC')->select();
|
||||
foreach ($ranking_make_up as $rel1) {
|
||||
// 如果两个用户都已使用,跳过这条记录
|
||||
if(in_array($rel1['user1_id'], $usedUsers) && in_array($rel1['user2_id'], $usedUsers)){
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果只有user1已使用,将user2加入排名
|
||||
if(in_array($rel1['user1_id'], $usedUsers)){
|
||||
$ranking1[] = [
|
||||
'heart_value' => 0,
|
||||
'id' => $rel1['id'],
|
||||
'user1_id' => -1,
|
||||
'user2_id' => $rel1['user2_id'],
|
||||
];
|
||||
$usedUsers[] = $rel1['user2_id'];
|
||||
$heart_ids[] = $rel1['id'];
|
||||
}
|
||||
// 如果只有user2已使用,将user1加入排名
|
||||
elseif(in_array($rel1['user2_id'], $usedUsers)){
|
||||
$ranking1[] = [
|
||||
'heart_value' => 0,
|
||||
'id' => $rel1['id'],
|
||||
'user1_id' => $rel1['user1_id'],
|
||||
'user2_id' => -1,
|
||||
];
|
||||
$usedUsers[] = $rel1['user1_id'];
|
||||
$heart_ids[] = $rel1['id'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 返回最终的排名列表
|
||||
$ranking_rut = array_merge($ranking, $ranking1);
|
||||
$nnum = count($ranking)*2 + count($ranking1);
|
||||
if($nnum<6){
|
||||
$make_up_num = 6 - $nnum;
|
||||
$ranking_make_up = db::name('vs_user_friending_heart')
|
||||
->where(array('room_id'=>$room_id,'friend_id'=>$friend_id ,'id'=>array('notin',$heart_ids)))
|
||||
->limit($make_up_num)
|
||||
->order('heart_value DESC')->select();
|
||||
if($ranking_make_up){
|
||||
foreach ($ranking_make_up as $rel1) {
|
||||
if(in_array($rel1['user1_id'], $usedUsers) && in_array($rel1['user2_id'], $usedUsers)){
|
||||
continue;
|
||||
}
|
||||
if(in_array($rel1['user1_id'], $usedUsers)){
|
||||
$ranking2[] = [
|
||||
'heart_value' => 0,
|
||||
'id' => $rel1['id'],
|
||||
'user1_id' => -1,
|
||||
'user2_id' => $rel1['user2_id'],
|
||||
];
|
||||
$usedUsers[] = $rel1['user2_id'];
|
||||
}
|
||||
if(in_array($rel1['user2_id'], $usedUsers)){
|
||||
$ranking2[] = [
|
||||
'heart_value' => 0,
|
||||
'id' => $rel1['id'],
|
||||
'user1_id' => $rel1['user1_id'],
|
||||
'user2_id' => -1,
|
||||
];
|
||||
$usedUsers[] = $rel1['user1_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return array_merge($ranking_rut, $ranking2);
|
||||
}
|
||||
|
||||
|
||||
//抱上麦 还是换麦
|
||||
public function pullUserPit($room_id,$friend_id){
|
||||
$friendPlayPit = $this->friendPlayPit($room_id,$friend_id); // 获取实际应该对应的麦位
|
||||
$this->changePitToPosPair($room_id,$friendPlayPit);//换麦,上下麦
|
||||
$this->pullHeartChange($room_id,$friend_id);//聊天室心动值变化通知
|
||||
}
|
||||
|
||||
//交友处理麦位排名
|
||||
public function friendPlayPit($room_id,$friend_id){
|
||||
//查询当前交友心动值表
|
||||
$heart_data = $this->getRanking($room_id,$friend_id);
|
||||
//数组根据里面的heart_value 由大到小进行排序
|
||||
usort($heart_data, function($a, $b) {
|
||||
return $b['heart_value'] - $a['heart_value'];
|
||||
});
|
||||
$pit = [];
|
||||
$pit_number_array = [2=>5,1=>6,3=>4,5=>2,6=>1,4=>3]; //麦位对应关系
|
||||
$pit_number_array_reverse = [0=>2,1=>1,2=>3,3=>4,4=>5,5=>6];
|
||||
if($heart_data){
|
||||
//排麦位
|
||||
$pit_unique = [];
|
||||
$key = 0;
|
||||
foreach($heart_data as $value) {
|
||||
if(count($pit) >= 6){
|
||||
break;
|
||||
}
|
||||
|
||||
// 处理两个用户都存在的情况
|
||||
if($value['user1_id'] != -1 && $value['user2_id'] != -1){
|
||||
if(!in_array($value['user1_id'],$pit_unique)){
|
||||
// 检查目标麦位是否已被占用
|
||||
if(!isset($pit[$pit_number_array_reverse[$key]])) {
|
||||
$pit[$pit_number_array_reverse[$key]] = $value['user1_id'];
|
||||
$pit[$pit_number_array[$pit_number_array_reverse[$key]]] = $value['user2_id'];
|
||||
$pit_unique = array_merge($pit_unique, [$value['user1_id'], $value['user2_id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理只有user2存在的情况
|
||||
elseif($value['user1_id'] == -1 && !in_array($value['user2_id'],$pit_unique)){
|
||||
// 检查该键是否已被使用
|
||||
if(!isset($pit[$pit_number_array_reverse[$key]])) {
|
||||
$pit[$pit_number_array_reverse[$key]] = $value['user2_id'];
|
||||
$pit_unique[] = $value['user2_id'];
|
||||
}
|
||||
}
|
||||
// 处理只有user1存在的情况
|
||||
elseif($value['user2_id'] == -1 && !in_array($value['user1_id'],$pit_unique)){
|
||||
// 检查该键是否已被使用
|
||||
if(!isset($pit[$pit_number_array_reverse[$key]])) {
|
||||
$pit[$pit_number_array_reverse[$key]] = $value['user1_id'];
|
||||
$pit_unique[] = $value['user1_id'];
|
||||
}
|
||||
}
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
return $pit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//换麦
|
||||
public function changePitToPosPairs($room_id,$friendPlayPit){
|
||||
$now_pit_u = array_flip($friendPlayPit);
|
||||
//按照键值排序数组
|
||||
ksort($now_pit_u);
|
||||
//查询现在麦位上有用户的数据 并且重组结果,键为麦位,值为用户,值必须存在,没值则不展示
|
||||
$pit_user = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number'=>['<',7],'user_id' => ['>', 0]])
|
||||
->order('pit_number ASC')
|
||||
->column('pit_number,user_id');
|
||||
//比较两个数组,无论是键的差异还是值的差异,都输出字符串”有差异“否则输出”没有差异“
|
||||
$result = array_diff_assoc($pit_user, $now_pit_u);
|
||||
$result2 = array_diff_assoc($now_pit_u, $pit_user);
|
||||
if(!empty($result) || !empty($result2)){
|
||||
// var_dump('有差异');
|
||||
//获取实际麦位上的用
|
||||
$newPitUser = array_keys($friendPlayPit);
|
||||
//获取当前麦位上的用户
|
||||
$oldPitUser = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number'=>['<',7]])->column('user_id');
|
||||
//获取交集
|
||||
$intersection = array_intersect($newPitUser,$oldPitUser);
|
||||
//取差集
|
||||
$diff = array_diff($newPitUser,$oldPitUser);
|
||||
$changeData = [];
|
||||
if($diff){
|
||||
//推下麦
|
||||
foreach($diff as $key => $value){
|
||||
if(in_array($value,$oldPitUser)){
|
||||
//查询当前空麦位
|
||||
$pit_null = model('api/RoomPit')->getRoomNullPitWithout($room_id, [7,8,9,10]);
|
||||
if($pit_null){
|
||||
// $this->room_pit_model->getOnPit($this->room_id, $value, $pit_null);
|
||||
model('api/RoomPit')->OnPit($value, $room_id, $pit_null);
|
||||
// db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_null])->update(['user_id' => $value]);
|
||||
}else{
|
||||
//下麦
|
||||
$UserRoomPit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $value])->value('pit_number');
|
||||
model('api/RoomPit')->DownPit($value, $room_id, $UserRoomPit);
|
||||
}
|
||||
}
|
||||
|
||||
if(in_array($value,$newPitUser)){
|
||||
//推上麦
|
||||
//获取目标麦位是否有人
|
||||
$getRoomPitUser= db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $friendPlayPit[$value]])->value('user_id');
|
||||
if($getRoomPitUser){
|
||||
//查询当前空麦位
|
||||
$getRoomNullPitss = model('api/RoomPit')->getRoomNullPitWithout($room_id, [7,8,9,10,$friendPlayPit[$value]]);
|
||||
if($getRoomNullPitss){
|
||||
// $this->room_pit_model->getOnPit($this->room_id, $getRoomPitUser, $getRoomNullPitss);
|
||||
db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $getRoomNullPitss])->update(['user_id' => $getRoomPitUser]);
|
||||
}else{
|
||||
model('api/RoomPit')->DownPit($getRoomPitUser, $room_id, $friendPlayPit[$value]);
|
||||
}
|
||||
}
|
||||
model('api/RoomPit')->OnPit($value, $room_id, $friendPlayPit[$value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($intersection){//交换麦位
|
||||
//查询麦上的用户
|
||||
$newPitUserStr = implode(',',$newPitUser);
|
||||
$getRoomPit = db::name('vs_room_pit')->where("room_id=".$room_id." AND user_id in (".$newPitUserStr.")")->column('pit_number');
|
||||
db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => ['in', $getRoomPit]])->update(['user_id' => 0]);
|
||||
$changePitUser = [];
|
||||
foreach ($friendPlayPit as $key => $value){
|
||||
if(empty($value)){
|
||||
$value = model('api/RoomPit')->getRoomNullPitWithout($room_id, [7,8,9,10]);
|
||||
}
|
||||
//获取目标麦位是否有人
|
||||
$isPitHaveUser= db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $value])->value('user_id');
|
||||
if($isPitHaveUser && !in_array($isPitHaveUser,$newPitUser)){
|
||||
$changePitUser[$key]['user_id'] = $isPitHaveUser;
|
||||
$changePitUser[$key]['pit_number'] = $value;
|
||||
}
|
||||
db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $value])->update(['user_id' => $key]);
|
||||
}
|
||||
//处理原麦位上的用户
|
||||
foreach ($changePitUser as $key_change => $value_change){
|
||||
//判断是否在左边 1,,2,,3 麦位上
|
||||
if(in_array($value_change['pit_number'],[1,2,3])){
|
||||
$null_pit = model('api/RoomPit')->getRoomNullPitWithout($room_id, [4,5,6,7,8,9,10]);
|
||||
if(empty($null_pit)){
|
||||
$null_pit = model('api/RoomPit')->getRoomNullPitWithout($room_id, [7,8,9,10]);
|
||||
}
|
||||
}else{
|
||||
$null_pit = model('api/RoomPit')->getRoomNullPitWithout($room_id, [1,2,3,7,8,9,10]);
|
||||
if(empty($null_pit)){
|
||||
$null_pit = model('api/RoomPit')->getRoomNullPitWithout($room_id, [7,8,9,10]);
|
||||
}
|
||||
}
|
||||
db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $null_pit])->update(['user_id' => $value_change['user_id']]);
|
||||
}
|
||||
// $getRoomNullPit = $this->room_pit_model->where(['room_id'=>$room_id,'pit_number'=>['notin',[7,9]]])->select();
|
||||
$getRoomNullPit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => ['<',7]])->select();
|
||||
$data_users = [];
|
||||
foreach($getRoomNullPit as $key_data => $value_data){
|
||||
$data_users[$key_data]['user_id'] = $value_data['user_id'];
|
||||
$data_users[$key_data]['nickname'] = db::name('user')->where('id',$value_data['user_id'])->value('nickname');
|
||||
$data_users[$key_data]['avatar'] = db::name('user')->where('id',$value_data['user_id'])->value('avatar');
|
||||
$data_users[$key_data]['sex'] = db::name('user')->where('id',$value_data['user_id'])->value('sex');
|
||||
//获取用户在此房间今天的魅力值
|
||||
$charm =[];
|
||||
if($value_data['user_id']){
|
||||
$charm = db::name('vs_room_user_charm')->where(['user_id' => $value_data['user_id'],'room_id' => $room_id])->value('charm');
|
||||
}
|
||||
$data_users[$key_data]['dress'] = model('Decorate')->user_decorate_detail($value_data['user_id'],1);
|
||||
$data_users[$key_data]['charm'] = $charm??0;
|
||||
$data_users[$key_data]['pit_number'] = $value_data['pit_number'];
|
||||
}
|
||||
//推送给前端消息
|
||||
$text['text'] = '房间换麦位';
|
||||
$text['list'] = $data_users;
|
||||
model('api/Chat')->sendMsg(1053,$room_id,$text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//换麦
|
||||
public function changePitToPosPair($room_id,$friendPlayPit){
|
||||
$new_pit_u = $friendPlayPit;
|
||||
//按照键值排序数组
|
||||
ksort($new_pit_u);
|
||||
//查询原有麦位上有用户的数据 并且重组结果,键为麦位,值为用户,值必须存在,没值则不展示
|
||||
$pit_users = db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number'=>['<',7],'user_id' => ['>', 0]])
|
||||
->order('pit_number ASC')
|
||||
->field('pit_number,user_id')->select();
|
||||
$pit_user = [];
|
||||
foreach ($pit_users as $value_pit_user){
|
||||
$pit_user[$value_pit_user['pit_number']] = $value_pit_user['user_id'];
|
||||
}
|
||||
//比较两个数组,无论是键的差异还是值的差异,都输出字符串”有差异“否则输出”没有差异“
|
||||
$result = array_diff_assoc($pit_user, $new_pit_u);//第一个数组中存在但其他数组中不存在的键/值对
|
||||
$result2 = array_diff_assoc($new_pit_u, $pit_user);
|
||||
if(!empty($result) || !empty($result2)){//换麦
|
||||
db::name('vs_room_pit')->where(['room_id' => $room_id,'pit_number' => ['<',7]])->update(['user_id' => 0]);
|
||||
//新麦位上的用户
|
||||
foreach ($new_pit_u as $key_result2 => $value_result2){
|
||||
db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $key_result2])->update(['user_id' => $value_result2]);
|
||||
}
|
||||
if($result){//原有麦位上的用户,且不在新麦位上的用户
|
||||
foreach ($result as $key_result => $value_result){
|
||||
$pit_null = model('api/RoomPit')->getRoomNullPitWithout($room_id, [7,8,9,10]);
|
||||
$onPitUser = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $value_result])->find();
|
||||
if($pit_null && !$onPitUser){
|
||||
db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_null])->update(['user_id' => $value_result]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$getRoomNullPit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => ['<',7]])->select();
|
||||
$data_users = [];
|
||||
foreach($getRoomNullPit as $key_data => $value_data){
|
||||
$data_users[$key_data]['user_id'] = $value_data['user_id'];
|
||||
$data_users[$key_data]['nickname'] = db::name('user')->where('id',$value_data['user_id'])->value('nickname');
|
||||
$data_users[$key_data]['avatar'] = db::name('user')->where('id',$value_data['user_id'])->value('avatar');
|
||||
$data_users[$key_data]['sex'] = db::name('user')->where('id',$value_data['user_id'])->value('sex');
|
||||
//获取用户在此房间今天的魅力值
|
||||
$charm =[];
|
||||
if($value_data['user_id']){
|
||||
$charm = db::name('vs_room_user_charm')->where(['user_id' => $value_data['user_id'],'room_id' => $room_id])->value('charm');
|
||||
}
|
||||
$data_users[$key_data]['dress'] = model('Decorate')->user_decorate_detail($value_data['user_id'],1);
|
||||
$data_users[$key_data]['charm'] = $charm??0;
|
||||
$data_users[$key_data]['pit_number'] = $value_data['pit_number'];
|
||||
}
|
||||
//推送给前端消息
|
||||
$text['text'] = '房间换麦位';
|
||||
$text['list'] = $data_users;
|
||||
model('api/Chat')->sendMsg(1053,$room_id,$text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//交友厅游戏开始后送礼后一系列操作
|
||||
//插入/更新心动表
|
||||
public function addUserHeart($uid,$user_id,$friend_id,$value,$room_id,$user_data){
|
||||
//给多个用户送礼
|
||||
//数组重组 下标从0开始
|
||||
$user_ids = array_values($user_id);
|
||||
// $heart_value = $value;//心动值
|
||||
$heart_value = 0;
|
||||
$heart_exp = get_system_config_value('coin_charm_exp');//金币与魅力值转换比
|
||||
for ($i = 0; $i < count($user_ids); $i++) {
|
||||
foreach ($user_data as $cv){
|
||||
if($user_ids[$i] == $cv['user_id']){
|
||||
$heart_value = $cv['gift_price'] * $heart_exp;
|
||||
}
|
||||
}
|
||||
// 处理用户ID顺序
|
||||
$user1 = min($uid, $user_ids[$i]);
|
||||
$user2 = max($uid, $user_ids[$i]);
|
||||
// 更新心动关系表
|
||||
$relation = db::name('vs_user_friending_heart')->where([
|
||||
'user1_id' => $user1,
|
||||
'user2_id' => $user2,
|
||||
'friend_id' => $friend_id
|
||||
])->find();
|
||||
|
||||
if ($relation) {
|
||||
db::name('vs_user_friending_heart')->where([
|
||||
'room_id' => $room_id,
|
||||
'user1_id' => $user1,
|
||||
'user2_id' => $user2,
|
||||
'friend_id' => $friend_id
|
||||
])->setInc('heart_value', $heart_value);
|
||||
} else {
|
||||
$relation['id'] = db::name('vs_user_friending_heart')->insert([
|
||||
'room_id' => $room_id,
|
||||
'user1_id' => $user1,
|
||||
'user2_id' => $user2,
|
||||
'friend_id' => $friend_id,
|
||||
'heart_value' => $heart_value
|
||||
]);
|
||||
}
|
||||
}
|
||||
//修改用户心动连线状态
|
||||
// $relation = db::name('vs_user_friending_heart')->where("(user1_id=".$uid." OR user2_id=".$uid.") AND friend_id=$friend_id AND room_id=$room_id AND status!=3")->order('heart_value desc')->find();
|
||||
// if($relation){
|
||||
// db::name('vs_user_friending_heart')->where("(user1_id=".$uid." OR user2_id=".$uid.") AND friend_id=$friend_id AND room_id=$room_id AND status!=3")->update(['status'=>2]);
|
||||
// db::name('vs_user_friending_heart')->where(['id'=>$relation['id']])->update(['status'=>1]);
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class Gift extends Model
|
||||
//获取礼物类型
|
||||
public function get_gift_label()
|
||||
{
|
||||
$giftTypeData = db::name('vs_gift_label')->where('delete_time',0)->order("sort asc,id desc")->select();
|
||||
$giftTypeData = db::name('vs_gift_label')->where('delete_time',0)->where('tid',1)->order("sort asc,id desc")->select();
|
||||
foreach ($giftTypeData as $key => $value) {
|
||||
$giftType[$key]['id'] = $value['id'];
|
||||
$giftType[$key]['name'] = $value['name'];
|
||||
@@ -28,7 +28,7 @@ class Gift extends Model
|
||||
}
|
||||
|
||||
//拉去礼物列表
|
||||
public function get_gift_list($label=0)
|
||||
public function get_gift_list($label=0,$room_id=0)
|
||||
{
|
||||
$map['delete_time'] = 0;
|
||||
$where['is_show'] = 1;
|
||||
@@ -39,30 +39,42 @@ class Gift extends Model
|
||||
$gift_price = get_system_config_value('room_love_auction_cion');
|
||||
$where['gift_price'] = ['>',$gift_price];
|
||||
}
|
||||
$is_open_blind_box_turntable = 0;
|
||||
if($room_id){
|
||||
$is_open_blind_box_turntable = Db::name('vs_room')->where(['id'=>$room_id])->value('is_open_blind_box_turntable');
|
||||
}
|
||||
$list = $this->field('gid as gift_id,gift_name,base_image,gift_price')->where($map)->where($where)->order('sort asc, gift_price asc')->select();
|
||||
|
||||
if($label==2){
|
||||
$list_data = [];
|
||||
foreach ($list as &$v) {
|
||||
//获取盲盒列表
|
||||
$box_list = Db::name('vs_gift_bag')->where(['status'=>1])->where('activities_id',4)->select();
|
||||
$box_list = Db::name('vs_gift_bag')->where(['status'=>1])->where(['activities_id'=>["in",[4,5]]])->select();
|
||||
foreach ($box_list as $key =>$box) {
|
||||
$ext = json_decode($box['ext'],true);
|
||||
if ($ext['gift_id'] == $v['gift_id']) {
|
||||
$v['gift_bag_name'] = $box['name'];
|
||||
$v['rule'] = $ext['description'];
|
||||
$v['rule_url'] = get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$box["id"];
|
||||
$v['activities_id'] = $box['activities_id'];
|
||||
$v['gift_bag'] = $box['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($list as $gift) {
|
||||
if($is_open_blind_box_turntable == 1){
|
||||
$list_data[] = $gift;
|
||||
}else{
|
||||
if(isset($gift['activities_id']) && $gift['activities_id'] == 4){
|
||||
$list_data[] = $gift;
|
||||
}
|
||||
}
|
||||
}
|
||||
usort($list_data, function($a, $b) {
|
||||
return $a['gift_id'] <=> $b['gift_id'];
|
||||
});
|
||||
$list = $list_data;
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
/*
|
||||
* 盲盒规则链接
|
||||
*/
|
||||
public function get_gift_box_rule($box_id){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +38,15 @@ class GiveGift extends Model
|
||||
* @return array
|
||||
* 用户,在房间中,给谁,送了什么礼物,多少个,来源
|
||||
*/
|
||||
public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0)
|
||||
public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0,$ext = [])
|
||||
{
|
||||
if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1) {
|
||||
$return_pan = $this->give_gift_to_pan($uid, $to_uid, $gid, $num, $from_type, $type, $from_id, $pit_number, $change_type, $ext);
|
||||
return $return_pan;
|
||||
}
|
||||
//送的礼物信息
|
||||
$gift_info = Db::name('vs_gift')->where(['gid'=>$gid])
|
||||
->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_screen')->find();
|
||||
->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_server')->find();
|
||||
if(empty($gift_info)){
|
||||
return ['code' => 0, 'msg' => '礼物不存在', 'data' => null];
|
||||
}
|
||||
@@ -79,24 +83,26 @@ class GiveGift extends Model
|
||||
}
|
||||
//金币购买送礼 1金币购买 2送背包礼物
|
||||
if ($type == 1) {
|
||||
//送给所有人的总价格
|
||||
$all_gift_price = $gift_info['gift_price'] * $num * count($toarray);
|
||||
//判断是否有足够的金币
|
||||
$user_waller = db::name('user_wallet')->where(['user_id'=>$uid])->find();
|
||||
if ($user_waller['coin'] < $all_gift_price) {
|
||||
return ['code' => 0, 'msg' => '用户金币不足', 'data' => null];
|
||||
}
|
||||
//扣除用户金币并记录日志
|
||||
$wallet_update = $this -> change_user_cion_or_earnings_log($uid,$all_gift_price,$from_id,1,10,'用户金币购买礼物');
|
||||
if(!$wallet_update){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '扣除用户金币失败', 'data' => null];
|
||||
}
|
||||
//用户财富等级更新
|
||||
$user_level = model('Level')->user_level_data_update($uid,$all_gift_price,1,$roomId);
|
||||
if(!$user_level){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '用户等级更新失败', 'data' => null];
|
||||
if(!isset($ext['is_draw_gift']) || $ext['is_draw_gift'] != 1){// 非盲盒转盘
|
||||
//送给所有人的总价格
|
||||
$all_gift_price = $gift_info['gift_price'] * $num * count($toarray);
|
||||
//判断是否有足够的金币
|
||||
$user_waller = db::name('user_wallet')->where(['user_id'=>$uid])->find();
|
||||
if ($user_waller['coin'] < $all_gift_price) {
|
||||
return ['code' => 0, 'msg' => '用户金币不足', 'data' => null];
|
||||
}
|
||||
//扣除用户金币并记录日志
|
||||
$wallet_update = $this -> change_user_cion_or_earnings_log($uid,$all_gift_price,$from_id,1,10,'用户金币购买礼物');
|
||||
if(!$wallet_update){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '扣除用户金币失败', 'data' => null];
|
||||
}
|
||||
//用户财富等级更新
|
||||
$user_level = model('Level')->user_level_data_update($uid,$all_gift_price,1,$roomId);
|
||||
if(!$user_level){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '用户等级更新失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//背包礼物是否充足
|
||||
@@ -127,28 +133,43 @@ class GiveGift extends Model
|
||||
//循环送礼
|
||||
$gift_total = 0;
|
||||
$give_gift = 0;
|
||||
foreach ($toarray as $to_id){
|
||||
$gift_user_data = [];
|
||||
foreach ($toarray as $k => $to_id){
|
||||
$gift_user_data[]['user_id'] = $to_id;
|
||||
$gift_box1 = [];
|
||||
$gift_box = [];
|
||||
//查询礼物是否是盲盒
|
||||
if($gift_info['label'] == 2){//趣味礼物(盲盒)
|
||||
$gift_price_box = 0;
|
||||
for($i = 0; $i < $num; $i++){
|
||||
$gift_box1[$i] = $this -> open_box($gid,$uid,$to_id,$from_id);
|
||||
if($gift_box1[$i]['code'] != 1){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '盲盒配置有误请联系管理员'.$gift_box1[$i]['msg'], 'data' => null];
|
||||
}
|
||||
$gift_box[$i] = $gift_box1[$i]['data'];
|
||||
//记录一下收礼记录
|
||||
$give_gift = $this -> change_user_give_gift_log($uid,$gift_box[$i]['gift_id'],$gift_box[$i]['gift_price'],1,$to_id,$from_type,$type,$from_id,$pit_number,2);
|
||||
if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1){
|
||||
//收礼记录行为日志
|
||||
$give_gift = $this -> change_user_give_gift_log($uid,$ext['gift_id'],$ext['all_gift_price'],$ext['count'],$to_id,$from_type,$type,$from_id,$pit_number,2);
|
||||
if(!$give_gift){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
$gift_box[$i]['give_gift_id'] = $give_gift;
|
||||
$gift_price_box += $gift_box[$i]['gift_price'];
|
||||
Log::record("盲盒礼物".json_encode($gift_box1),"info");
|
||||
$gift_price_box = $ext['all_gift_price'];
|
||||
$gift_box[0]['gift_id'] = $ext['gift_id'];
|
||||
$gift_box[0]['gift_price'] = $ext['all_gift_price'];
|
||||
$gift_box[0]['give_gift_id'] = $give_gift;
|
||||
}else{
|
||||
for($i = 0; $i < $num; $i++){
|
||||
$gift_box1[$i] = $this -> open_box($gid,$uid,$to_id,$from_id);
|
||||
if($gift_box1[$i]['code'] != 1){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '盲盒配置有误请联系管理员'.$gift_box1[$i]['msg'], 'data' => null];
|
||||
}
|
||||
$gift_box[$i] = $gift_box1[$i]['data'];
|
||||
//记录一下收礼记录
|
||||
$give_gift = $this -> change_user_give_gift_log($uid,$gift_box[$i]['gift_id'],$gift_box[$i]['gift_price'],1,$to_id,$from_type,$type,$from_id,$pit_number,2);
|
||||
if(!$give_gift){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
$gift_box[$i]['give_gift_id'] = $give_gift;
|
||||
$gift_price_box += $gift_box[$i]['gift_price'];
|
||||
Log::record("盲盒礼物".json_encode($gift_box1),"info");
|
||||
}
|
||||
}
|
||||
$gift_total += $gift_price_box;
|
||||
$gift_price = $gift_price_box;
|
||||
@@ -161,6 +182,7 @@ class GiveGift extends Model
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
$gift_user_data[$k]['gift_price'] = $gift_price;
|
||||
|
||||
//计算收礼人得益
|
||||
$receiver_earnings = $this -> receiver_earnings($to_id,$gift_price,$from_type);
|
||||
@@ -227,14 +249,14 @@ class GiveGift extends Model
|
||||
}else{
|
||||
$room_owner = Db::name('vs_room')->where(['id'=>$from_id,'apply_status'=>2])->value('user_id');
|
||||
//计算房主收益//room_author_ratio
|
||||
$room_owner_earnings = $this -> receiver_earnings($room_owner,$gift_price,99);
|
||||
$room_owner_earnings = $this -> receiver_earnings($room_owner,$gift_price,99);//结果是钻石
|
||||
if($room_owner_earnings > 0){
|
||||
//主持人收益
|
||||
//在主持位的主持人
|
||||
$host_id = Db::name('vs_room_pit')->where(['room_id'=>$from_id,'pit_number'=>9])->value('user_id');
|
||||
if($host_id){
|
||||
//计算主持人收益
|
||||
$host_earnings = $this -> receiver_earnings($host_id,$room_owner_earnings,98,$from_id);
|
||||
$host_earnings = $this -> receiver_earnings($host_id,$room_owner_earnings*get_system_config_value('rmb_coin_ratio'),98,$from_id);
|
||||
if($host_earnings > 0){
|
||||
//增加主持人收益并记录日志
|
||||
$host_earnings_earning = $this -> change_user_cion_or_earnings_log($host_id,$host_earnings,$from_id,2,19,'主持人收益');
|
||||
@@ -244,11 +266,14 @@ class GiveGift extends Model
|
||||
}
|
||||
//增加房主收益并记录日志
|
||||
$room_owner_earningss = $room_owner_earnings - $host_earnings;
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earningss,$from_id,2,18,'房主收益');
|
||||
if(!$room_owner_earning){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
if($room_owner_earningss > 0){
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earningss,$from_id,2,18,'房主收益');
|
||||
if(!$room_owner_earning){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
//增加房主收益并记录日志
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earnings,$from_id,2,18,'房主收益');
|
||||
@@ -257,6 +282,13 @@ class GiveGift extends Model
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//增加房主收益并记录日志
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earnings,$from_id,2,18,'房主收益');
|
||||
if(!$room_owner_earning){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,7 +317,9 @@ class GiveGift extends Model
|
||||
//平台收益 = 总金额 - 收礼人收益 - 房主收益 - 工会长收益
|
||||
$app_ratio = 100 - $ratio - $configs['room_author_ratio'] - $guid_ratio;
|
||||
$app_earning = coin_earning($gv['gift_price'], $app_ratio);
|
||||
$gift_rate = $this->change_give_gift_profit($gv['give_gift_id'], $ratio, $receiver_earnings, $configs['room_author_ratio'], $room_owner_earnings, $app_ratio, $app_earning);
|
||||
$receiver_earningss = $this -> receiver_earnings($to_id,$gv['gift_price'],$from_type);
|
||||
$room_owner_earningss = $this -> receiver_earnings($room_owner,$gv['gift_price'],99);//结果是钻石
|
||||
$gift_rate = $this->change_give_gift_profit($gv['give_gift_id'], $ratio, $receiver_earningss, $configs['room_author_ratio'], $room_owner_earningss, $app_ratio, $app_earning);
|
||||
if (!$gift_rate) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '礼物记录失败', 'data' => null];
|
||||
@@ -365,136 +399,147 @@ class GiveGift extends Model
|
||||
}
|
||||
}
|
||||
//推送礼物特效
|
||||
if($gift_info['label'] == 2){
|
||||
//循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少';
|
||||
if($gift_box){
|
||||
// 统计相同礼物的数量
|
||||
$giftCount = [];
|
||||
foreach ($gift_box as $gv) {
|
||||
if (isset($giftCount[$gv['gift_id']])) {
|
||||
$giftCount[$gv['gift_id']]['count']++;
|
||||
} else {
|
||||
$giftCount[$gv['gift_id']] = [
|
||||
'gift_info' => Db::name('vs_gift')->where(['gid'=>$gv['gift_id']])
|
||||
->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_screen')->find(),
|
||||
'count' => 1
|
||||
];
|
||||
if(!isset($ext['is_draw_gift']) || $ext['is_draw_gift'] != 1){// 非盲盒转盘 推送
|
||||
if($gift_info['label'] == 2){
|
||||
//循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少';
|
||||
if($gift_box){
|
||||
// 统计相同礼物的数量
|
||||
$giftCount = [];
|
||||
foreach ($gift_box as $key=>$gv) {
|
||||
$gift_info = Db::name('vs_gift')->where(['gid'=>$gv['gift_id']])
|
||||
->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_server')->find();
|
||||
if (isset($giftCount[$gv['gift_id']])) {
|
||||
$giftCount[$gv['gift_id']]['count']++;
|
||||
} else {
|
||||
$giftCount[$gv['gift_id']] = [
|
||||
'gift_info' => $gift_info,
|
||||
'count' => 1
|
||||
];
|
||||
}
|
||||
$gift_box[$key]['gift_name'] = $gift_info['gift_name'];
|
||||
}
|
||||
}
|
||||
|
||||
// 构建文字消息内容
|
||||
$giftTextList = [];
|
||||
foreach ($giftCount as $giftData) {
|
||||
$gift_inf = $giftData['gift_info'];
|
||||
$count = $giftData['count'];
|
||||
$giftTextList[] = $gift_inf['gift_name'].' X'.$count;
|
||||
}
|
||||
// 构建文字消息内容
|
||||
$giftTextList = [];
|
||||
foreach ($giftCount as $giftData) {
|
||||
$gift_inf = $giftData['gift_info'];
|
||||
$count = $giftData['count'];
|
||||
$giftTextList[] = $gift_inf['gift_name'].' X'.$count;
|
||||
}
|
||||
|
||||
// 推送文字消息 (格式: 张三 送给 李四 趣味礼物 礼物名1 X2,礼物2 X4)
|
||||
$textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' . implode(',', $giftTextList);
|
||||
$textData = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
// 'ToUserInfo' => $ToUserInfo,
|
||||
// 'GiftInfo' => $gift_info,
|
||||
// 'GiftNum' => $num,
|
||||
'text' => $textMessage
|
||||
];
|
||||
// 聊天室推送文字消息
|
||||
model('Chat')->sendMsg(1038,$from_id,$textData);
|
||||
|
||||
// 循环推送每个礼物的特效消息
|
||||
foreach ($giftCount as $giftId => $giftData) {
|
||||
$gift_inf = $giftData['gift_info'];
|
||||
$count = $giftData['count'];
|
||||
|
||||
// 推送礼物特效消息
|
||||
$effectData = [
|
||||
// 推送文字消息 (格式: 张三 送给 李四 趣味礼物 礼物名1 X2,礼物2 X4)
|
||||
$textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' . implode(',', $giftTextList);
|
||||
$textData = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfo' => $ToUserInfo,
|
||||
'GiftInfo' => $gift_inf,
|
||||
'GiftNum' => $count,
|
||||
'text' => null
|
||||
'GiftInfos' => array_values($gift_box),
|
||||
'GiftNum' => $num,
|
||||
'text' => $textMessage
|
||||
];
|
||||
// 聊天室推送文字消息
|
||||
model('Chat')->sendMsg(1038,$from_id,$textData);
|
||||
|
||||
// 聊天室推送礼物特效消息
|
||||
model('Chat')->sendMsg(1005,$from_id,$effectData);
|
||||
// 循环推送每个礼物的特效消息
|
||||
foreach ($giftCount as $giftId => $giftData) {
|
||||
$gift_inf = $giftData['gift_info'];
|
||||
$count = $giftData['count'];
|
||||
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $from_id,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
// 推送礼物特效消息
|
||||
$effectData = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfo' => $ToUserInfo,
|
||||
'GiftInfo' => $gift_inf,
|
||||
'GiftNum' => $count,
|
||||
'text' => null
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$from_id,$text1);
|
||||
}else{
|
||||
if($gift_inf['is_public_screen'] == 1){
|
||||
//推送礼物横幅
|
||||
$push = new Push(UID, $from_id);
|
||||
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
|
||||
$bannerText = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_inf['gift_name'] . 'X' . $count;
|
||||
$text_list_new = [
|
||||
'text' => $bannerText,
|
||||
'gift_picture' => $gift_inf['base_image'],
|
||||
|
||||
// 聊天室推送礼物特效消息
|
||||
model('Chat')->sendMsg(1005,$from_id,$effectData);
|
||||
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $from_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $gift_inf['gift_name'],
|
||||
'roomId' => $from_id,
|
||||
'number' => $count,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
];
|
||||
$push->giftBanner($text_list_new);
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$from_id,$text1);
|
||||
|
||||
//电影房推送结束时间点
|
||||
$text2 = [
|
||||
'room_id' => $from_id,
|
||||
'end_time' => time() + 60 * 60 * 24 * 7,
|
||||
'text' => '房间结束时间点'
|
||||
];
|
||||
model('Chat')->sendMsg(1042,$from_id,$text2);
|
||||
}else{
|
||||
if($gift_inf['is_public_server'] == 1){
|
||||
//推送礼物横幅
|
||||
$push = new Push(UID, $from_id);
|
||||
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
|
||||
$bannerText = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_inf['gift_name'] . 'X' . $count;
|
||||
$text_list_new[] = [
|
||||
'text' => $bannerText,
|
||||
'gift_picture' => $gift_inf['base_image'],
|
||||
'room_id' => $from_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $gift_inf['gift_name'],
|
||||
'roomId' => $from_id,
|
||||
'number' => $count,
|
||||
];
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$text = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 礼物 ' .$gift_info['gift_name'].' x ' .$num;
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfo' => $ToUserInfo,
|
||||
'GiftInfo' => $gift_info,
|
||||
'GiftNum' => $num,
|
||||
'text' => $text
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1005,$from_id,$text);
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $from_id,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
}else{
|
||||
$text = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 礼物 ' .$gift_info['gift_name'].' x ' .$num;
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfo' => $ToUserInfo,
|
||||
'GiftInfo' => $gift_info,
|
||||
'GiftNum' => $num,
|
||||
'text' => $text
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$from_id,$text1);
|
||||
}else{
|
||||
if($gift_info['is_public_screen'] == 1){
|
||||
//推送礼物横幅
|
||||
$push = new Push(UID, $from_id);
|
||||
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
|
||||
$text = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_info['gift_name'] . 'X' . $num;
|
||||
$text_list_new = [
|
||||
'text' => $text,
|
||||
'gift_picture' => $gift_info['base_image'],
|
||||
model('Chat')->sendMsg(1005,$from_id,$text);
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $from_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $gift_info['gift_name'],
|
||||
'roomId' => $from_id,
|
||||
'number' => $num,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
];
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$from_id,$text1);
|
||||
}else{
|
||||
if($gift_info['is_public_server'] == 1){
|
||||
//推送礼物横幅
|
||||
$push = new Push($uid, $from_id);
|
||||
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
|
||||
$text = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $gift_info['gift_name'] . 'X' . $num;
|
||||
$text_list_new[] = [
|
||||
'text' => $text,
|
||||
'gift_picture' => $gift_info['base_image'],
|
||||
'room_id' => $from_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $gift_info['gift_name'],
|
||||
'roomId' => $from_id,
|
||||
'number' => $num,
|
||||
];
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//直播间送礼物 每日任务
|
||||
@@ -504,10 +549,330 @@ class GiveGift extends Model
|
||||
|
||||
//增加房间火热值hot_value
|
||||
$gift_totalaa = $gift_total * get_system_config_value('coin_charm_exp');
|
||||
Db::name('vs_room')->where(['id'=>$from_id,'apply_status'=>2])->setInc('hot_value',$gift_totalaa);
|
||||
db::name('vs_room')->where(['id' => $from_id])->inc('hot_value', $gift_totalaa)->inc('today_hot_value', $gift_totalaa)->update();
|
||||
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息 交友房创建的私密房 倒计时增加
|
||||
$value = db::name('vs_room_cp_movie')->where('room_id', $from_id)->where('type',1)
|
||||
->value('time_day');
|
||||
if($value){
|
||||
db::name('vs_room_cp_movie')->where('room_id', $from_id)->where('type',1)
|
||||
->setInc('time_day', $gift_total);
|
||||
$text111 = [
|
||||
'room_id' => $from_id,
|
||||
'time_day' => db::name('vs_room_cp_movie')->where('room_id', $from_id)->where('type',1)->value('time_day'),
|
||||
'text' => '房间结束时间变化'
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1052,$from_id,$text111);
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '送礼成功', 'data' => null];
|
||||
return ['code' => 1, 'msg' => '送礼成功', 'data' => ['gift_total' => $gift_total,'gift_user_data' =>$gift_user_data]];
|
||||
}
|
||||
|
||||
/*
|
||||
* 送礼物-盲盒转盘专用
|
||||
* @param int $uid 用户id
|
||||
* @param int $from_id 来源id
|
||||
* @param str $to_uid 接收礼物用户id字符串逗号分隔
|
||||
* @param int $gid 礼物id
|
||||
* @param int $num 礼物数量
|
||||
* @param int $from_type 来源 1聊天送礼物 2房间语聊送礼 3直播送礼 4动态打赏 5系统任务 6-cp房间送礼
|
||||
* @param int $type 金币购买 1金币购买 2送背包礼物
|
||||
* @param int $pit_number 坑位编号
|
||||
* @return array
|
||||
* 用户,在房间中,给谁,送了什么礼物,多少个,来源
|
||||
*/
|
||||
public function give_gift_to_pan($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0,$ext = [])
|
||||
{
|
||||
//送的礼物信息
|
||||
$gift_info = Db::name('vs_gift')->where(['gid'=>$gid])
|
||||
->field('gid as gift_id,gift_name,gift_price,file_type,base_image,play_image,gift_type,label,is_public_server')->find();
|
||||
if(empty($gift_info)){
|
||||
return ['code' => 0, 'msg' => '礼物不存在', 'data' => null];
|
||||
}
|
||||
if(!$to_uid){
|
||||
return ['code' => 0, 'msg' => '请选择收礼人', 'data' => null];
|
||||
}
|
||||
$toarray = explode(',',$to_uid);
|
||||
if(in_array($uid,$toarray)){
|
||||
return ['code' => 0, 'msg' => '收礼人不能包含自己', 'data' => null];
|
||||
}
|
||||
if (ceil($num) != $num) {
|
||||
return ['code' => 0, 'msg' => '打赏礼物数量必须为整数', 'data' => null];
|
||||
}
|
||||
if ($num < 1) {
|
||||
return ['code' => 0, 'msg' => '打赏礼物数量必须大于零', 'data' => null];
|
||||
}
|
||||
$user_info = Db::name('user')->where(['id'=>$uid,'status'=>1])->find();
|
||||
if(empty($user_info)){
|
||||
return ['code' => 301, 'msg' => '当前用户登录失效', 'data' => null];
|
||||
}
|
||||
|
||||
//获取送礼用户昵称
|
||||
$FromUserInfo = db::name('user')->where('id',$uid)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($uid);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($uid);//魅力图标
|
||||
|
||||
//送给一人礼物的总价格(扣除用户的数额)
|
||||
$gift_price = $gift_info['gift_price'] * $num;
|
||||
|
||||
$roomId = 0;
|
||||
if($from_type == 2 || $from_type == 3 || $from_type == 6){
|
||||
$roomId = $from_id;
|
||||
}
|
||||
|
||||
//循环送礼
|
||||
$gift_total = 0;
|
||||
$give_gift = 0;
|
||||
$gift_user_data = [];
|
||||
foreach ($toarray as $k => $to_id){
|
||||
$gift_user_data[]['user_id'] = $to_id;
|
||||
$gift_box1 = [];
|
||||
$gift_box = [];
|
||||
$gift_total += $gift_price;
|
||||
//收礼记录行为日志
|
||||
$give_gift = $this -> change_user_give_gift_log($uid,$gid,$gift_price,$num,$to_id,$from_type,$type,$from_id,$pit_number);
|
||||
if(!$give_gift){
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
$gift_user_data[$k]['gift_price'] = $gift_price;
|
||||
|
||||
//计算收礼人得益
|
||||
$receiver_earnings = $this -> receiver_earnings($to_id,$gift_price,$from_type);
|
||||
if($receiver_earnings <= 0){
|
||||
return ['code' => 0, 'msg' => '收礼人收益配置有误', 'data' => null];
|
||||
}
|
||||
//1聊天送礼物 2房间语聊送礼 3直播送礼 4动态打赏 5系统任务 6-cp房间送礼
|
||||
if($from_type == 1 || $from_type == 2 || $from_type == 3 ||$from_type == 4 || $from_type == 6){
|
||||
//增加收益并记录日志
|
||||
$receiver = $this -> change_user_cion_or_earnings_log($to_id,$receiver_earnings,$from_id,2,11,'收礼增加收益');
|
||||
}elseif($from_type == 5){
|
||||
//增加收益并记录日志
|
||||
$receiver = $this -> change_user_cion_or_earnings_log($to_id,$receiver_earnings,$from_id,1,$change_type,'活动增加金币');
|
||||
}else{
|
||||
$receiver = false;
|
||||
}
|
||||
if(!$receiver){
|
||||
return ['code' => 0, 'msg' => '收礼人收益失败', 'data' => null];
|
||||
}
|
||||
//用户魅力等级更新
|
||||
$user_level = model('Level')->user_level_data_update($to_id,$gift_price,2,$roomId);
|
||||
if(!$user_level){
|
||||
return ['code' => 0, 'msg' => '用户等级更新失败', 'data' => null];
|
||||
}
|
||||
|
||||
$room_owner_earnings = 0;//房主收益
|
||||
$room_owner_earningsg = 0;//公会会长收益
|
||||
//是否在房间
|
||||
if(isset($from_id) && ($from_type == 2 || $from_type == 6)){
|
||||
if($from_type == 6){ //cp电影房
|
||||
//房主有收益
|
||||
if(get_system_config_value('room_cp_room_user_ratio') > 0){
|
||||
$room_owner = Db::name('vs_room')->where(['id'=>$from_id,'apply_status'=>2])->value('user_id');
|
||||
//计算房主收益//room_author_ratio
|
||||
$room_owner_earnings = $this -> receiver_earnings($room_owner,$gift_price,699);
|
||||
if($room_owner_earnings > 0){
|
||||
//增加收益并记录日志
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earnings,$from_id,2,18,'房主收益');
|
||||
if(!$room_owner_earning){
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
//公会长收益
|
||||
if(get_system_config_value('room_cp_guild_user_ratio') > 0){
|
||||
$guild_id = Db::name('vs_guild_user')->where(['user_id'=>$to_uid,'status'=>1])->value('guild_id');
|
||||
if($guild_id){
|
||||
$room_guild = Db::name('vs_guild')->where(['id'=>$guild_id])->value('user_id');
|
||||
//计算会长收益
|
||||
$room_owner_earningsg = $this -> receiver_earnings($room_guild,$gift_price,698);
|
||||
//增加收益并记录日志
|
||||
$room_owner_earningg = $this -> change_user_cion_or_earnings_log($room_guild,$room_owner_earningsg,$from_id,2,21,'工会长收益');
|
||||
if(!$room_owner_earningg){
|
||||
return ['code' => 0, 'msg' => '工会长收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$room_owner = Db::name('vs_room')->where(['id'=>$from_id,'apply_status'=>2])->value('user_id');
|
||||
//计算房主收益//room_author_ratio
|
||||
$room_owner_earnings = $this -> receiver_earnings($room_owner,$gift_price,99);//结果是钻石
|
||||
if($room_owner_earnings > 0){
|
||||
//主持人收益
|
||||
//在主持位的主持人
|
||||
$host_id = Db::name('vs_room_pit')->where(['room_id'=>$from_id,'pit_number'=>9])->value('user_id');
|
||||
if($host_id){
|
||||
//计算主持人收益
|
||||
$host_earnings = $this -> receiver_earnings($host_id,$room_owner_earnings*get_system_config_value('rmb_coin_ratio'),98,$from_id);
|
||||
if($host_earnings > 0){
|
||||
//增加主持人收益并记录日志
|
||||
$host_earnings_earning = $this -> change_user_cion_or_earnings_log($host_id,$host_earnings,$from_id,2,19,'主持人收益');
|
||||
if(!$host_earnings_earning){
|
||||
return ['code' => 0, 'msg' => '主持人收益失败', 'data' => null];
|
||||
}
|
||||
//增加房主收益并记录日志
|
||||
$room_owner_earningss = $room_owner_earnings - $host_earnings;
|
||||
if($room_owner_earningss > 0){
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earningss,$from_id,2,18,'房主收益');
|
||||
if(!$room_owner_earning){
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
//增加房主收益并记录日志
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earnings,$from_id,2,18,'房主收益');
|
||||
if(!$room_owner_earning){
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//增加房主收益并记录日志
|
||||
$room_owner_earning = $this -> change_user_cion_or_earnings_log($room_owner,$room_owner_earnings,$from_id,2,18,'房主收益');
|
||||
if(!$room_owner_earning){
|
||||
return ['code' => 0, 'msg' => '房主收益失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($gift_info['label'] == 2){
|
||||
foreach ($gift_box as $gv) {
|
||||
//记录送礼利率和各方收益
|
||||
//收礼人是否加入公会
|
||||
$configs = get_system_config();
|
||||
$is_join_guild = Db::name('vs_guild_user')->where(['user_id' => $to_uid, 'status' => 1, 'quit_time' => 0])->field('guild_id')->find();
|
||||
//收益增加 加入工会的收益
|
||||
if ($is_join_guild) {
|
||||
$ratiog = $configs['room_gift_guild_ratio'];
|
||||
} else {
|
||||
$ratiog = 0;
|
||||
}
|
||||
//未加入工会的收益
|
||||
$ratiogr = $configs['room_gift_ratio'];
|
||||
//收礼人最终的收益比例
|
||||
$ratio = $ratiogr + $ratiog;
|
||||
//房主收益大于0 就代表有收益 且在房间
|
||||
if ($room_owner_earningsg > 0) {
|
||||
$guid_ratio = $configs['room_cp_guild_user_ratio'];
|
||||
} else {
|
||||
$guid_ratio = 0;
|
||||
}
|
||||
//平台收益 = 总金额 - 收礼人收益 - 房主收益 - 工会长收益
|
||||
$app_ratio = 100 - $ratio - $configs['room_author_ratio'] - $guid_ratio;
|
||||
$app_earning = coin_earning($gv['gift_price'], $app_ratio);
|
||||
$receiver_earningss = $this -> receiver_earnings($to_id,$gv['gift_price'],$from_type);
|
||||
$room_owner_earningss = $this -> receiver_earnings($room_owner,$gv['gift_price'],99);//结果是钻石
|
||||
$gift_rate = $this->change_give_gift_profit($gv['give_gift_id'], $ratio, $receiver_earningss, $configs['room_author_ratio'], $room_owner_earningss, $app_ratio, $app_earning);
|
||||
if (!$gift_rate) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '礼物记录失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//记录送礼利率和各方收益
|
||||
//收礼人是否加入公会
|
||||
$configs = get_system_config();
|
||||
$is_join_guild = Db::name('vs_guild_user')->where(['user_id' => $to_uid, 'status' => 1, 'quit_time' => 0])->field('guild_id')->find();
|
||||
//收益增加 加入工会的收益
|
||||
if ($is_join_guild) {
|
||||
$ratiog = $configs['room_gift_guild_ratio'];
|
||||
} else {
|
||||
$ratiog = 0;
|
||||
}
|
||||
//未加入工会的收益
|
||||
$ratiogr = $configs['room_gift_ratio'];
|
||||
//收礼人最终的收益比例
|
||||
$ratio = $ratiogr + $ratiog;
|
||||
//房主收益大于0 就代表有收益 且在房间
|
||||
if ($room_owner_earningsg > 0) {
|
||||
$guid_ratio = $configs['room_cp_guild_user_ratio'];
|
||||
} else {
|
||||
$guid_ratio = 0;
|
||||
}
|
||||
//平台收益 = 总金额 - 收礼人收益 - 房主收益 - 工会长收益
|
||||
$app_ratio = 100 - $ratio - $configs['room_author_ratio'] - $guid_ratio;
|
||||
$app_earning = coin_earning($gift_price, $app_ratio);
|
||||
$gift_rate = $this->change_give_gift_profit($give_gift, $ratio, $receiver_earnings, $configs['room_author_ratio'], $room_owner_earnings, $app_ratio, $app_earning);
|
||||
if (!$gift_rate) {
|
||||
return ['code' => 0, 'msg' => '礼物记录失败', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ToUserInfo = Db::name('user')->where(['id' => $to_id])->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$ToUserInfo['icon'][0] = model('UserData')->user_wealth_icon($to_id);//财富图标
|
||||
$ToUserInfo['icon'][1] = model('UserData')->user_charm_icon($to_id);//魅力图标
|
||||
$ToUserInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $to_id,'room_id' => $from_id])->value('charm');//魅力
|
||||
|
||||
if(isset($from_id) && ($from_type == 2 || $from_type == 6)){
|
||||
//查询房间是否在PK中 是fa_vs_room_pk 表中的 room_id_a,还是room_id_b
|
||||
$room_pk = Db::name('vs_room_pk')->where(['status' => 3, 'room_id_a' => $from_id])->field('pk_id')->find();
|
||||
if (!empty($room_pk)) {
|
||||
// 当前 room_id 是 room_id_a 修改create_value_a
|
||||
$rooma = Db::name('vs_room_pk')->where('pk_id', $room_pk['pk_id'])->setInc('create_value_a', $gift_price * 10);
|
||||
$roomPKinfo = Db::name('vs_room_pk')->where('pk_id', $room_pk['pk_id'])->find();
|
||||
//推送变化
|
||||
$text = [
|
||||
'room_id_a' => $roomPKinfo['room_id_a'],//发起者房间id
|
||||
'create_value_a' => $roomPKinfo['create_value_a'],//发起者房间值
|
||||
'room_id_b' => $roomPKinfo['room_id_b'],//接受者房间id
|
||||
'receive_value_b' => $roomPKinfo['receive_value_b'],//接受者房间值
|
||||
'text' => ''
|
||||
];
|
||||
model('Chat')->sendMsg(1015,$roomPKinfo['room_id_a'],$text);
|
||||
model('Chat')->sendMsg(1015,$roomPKinfo['room_id_b'],$text);
|
||||
} else {
|
||||
// 当前 room_id 不是 room_id_a,可能是 room_id_b 或者不存在
|
||||
$room_pk_b = Db::name('vs_room_pk')->where(['status' => 3, 'room_id_b' => $from_id])->field('pk_id')->find();
|
||||
if (!empty($room_pk_b)) {
|
||||
// 当前 room_id 是 room_id_b
|
||||
$roomb = Db::name('vs_room_pk')->where('pk_id', $room_pk_b['pk_id'])->setInc('receive_value_b', $gift_price * 10);
|
||||
$roomPKinfo = Db::name('vs_room_pk')->where('pk_id', $room_pk_b['pk_id'])->find();
|
||||
//推送变化
|
||||
$text = [
|
||||
'room_id_a' => $roomPKinfo['room_id_a'],//发起者房间id
|
||||
'create_value_a' => $roomPKinfo['create_value_a'],//发起者房间值
|
||||
'room_id_b' => $roomPKinfo['room_id_b'],//接受者房间id
|
||||
'receive_value_b' => $roomPKinfo['receive_value_b'],//接受者房间值
|
||||
'text' => ''
|
||||
];
|
||||
model('Chat')->sendMsg(1015,$roomPKinfo['room_id_a'],$text);
|
||||
model('Chat')->sendMsg(1015,$roomPKinfo['room_id_b'],$text);
|
||||
}
|
||||
}
|
||||
//直播间送礼物 每日任务
|
||||
model('DailyTasks')->tasks_complete($uid,3);
|
||||
}
|
||||
}
|
||||
|
||||
//增加房间火热值hot_value
|
||||
$gift_totalaa = $gift_total * get_system_config_value('coin_charm_exp');
|
||||
db::name('vs_room')->where(['id' => $from_id])->inc('hot_value', $gift_totalaa)->inc('today_hot_value', $gift_totalaa)->update();
|
||||
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息 交友房创建的私密房 倒计时增加
|
||||
$value = db::name('vs_room_cp_movie')->where('room_id', $from_id)->where('type',1)
|
||||
->value('time_day');
|
||||
if($value){
|
||||
db::name('vs_room_cp_movie')->where('room_id', $from_id)->where('type',1)
|
||||
->setInc('time_day', $gift_total);
|
||||
$text111 = [
|
||||
'room_id' => $from_id,
|
||||
'time_day' => db::name('vs_room_cp_movie')->where('room_id', $from_id)->where('type',1)->value('time_day'),
|
||||
'text' => '房间结束时间变化'
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1052,$from_id,$text111);
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '送礼成功', 'data' => ['gift_total' => $gift_total,'gift_user_data' =>$gift_user_data]];
|
||||
}
|
||||
|
||||
//送礼特效
|
||||
@@ -611,7 +976,7 @@ class GiveGift extends Model
|
||||
}
|
||||
}elseif(in_array($change_type,$out_types)){
|
||||
//减少用户金币
|
||||
$res1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setDec('coin',$money);
|
||||
$res1 = Db::name('user_wallet')->where(['user_id'=>$user_id,'coin'=>['>=',$money]])->setDec('coin',$money);
|
||||
if(!$res1){
|
||||
return false;
|
||||
}
|
||||
@@ -1014,7 +1379,7 @@ class GiveGift extends Model
|
||||
/*
|
||||
* 开盲盒
|
||||
*/
|
||||
public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0){
|
||||
public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0,$gift_bag_id=0){
|
||||
//获取盲盒配置
|
||||
$bag_list = db::name("vs_gift_bag")->field('id,name,ext,periods')->where(['activities_id'=>4,'status'=>1])->select();
|
||||
$gift_bag_id = 0;
|
||||
|
||||
@@ -17,9 +17,9 @@ class Guild extends Model
|
||||
* @param $page
|
||||
* @param $limit
|
||||
*/
|
||||
public function get_guild_list($page,$limit=10,$search='',$user_id=0)
|
||||
public function get_guild_list($page,$page_limit,$search='',$user_id=0)
|
||||
{
|
||||
$where ="1=1";
|
||||
$where =[];
|
||||
if ($search) {
|
||||
$where = ['guild_special_id'=>['like',$search.'%']]; //通过工会ID搜索
|
||||
}
|
||||
@@ -28,8 +28,7 @@ class Guild extends Model
|
||||
->field('id,guild_special_id,user_id,guild_name,cover,num,intro,createtime,income')
|
||||
->where(['is_show'=>1,'delete_time'=>0])
|
||||
->where($where)
|
||||
->order('income desc')
|
||||
->page($page,$limit)
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$count = Db::name('vs_guild')
|
||||
->where(['is_show'=>1,'delete_time'=>0])
|
||||
@@ -62,7 +61,7 @@ class Guild extends Model
|
||||
}
|
||||
$data =[
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'list' => $list
|
||||
];
|
||||
@@ -525,7 +524,7 @@ class Guild extends Model
|
||||
//成员解散
|
||||
db::name('vs_guild_user')->where(['guild_id'=>$guild_id,'status'=>1,'delete_time'=>0])->update(['delete_time'=>time(),'quit_type'=>3,'quit_time'=>time()]);
|
||||
//解散公会
|
||||
db::name('vs_guild')->where('id',$guild_id)->update(['delete_time'=>time(),'is_show'=>2,'num'=>0,'guild_special_id'=>""]);
|
||||
db::name('vs_guild')->where('id',$guild_id)->update(['delete_time'=>time(),'status'=>2]);
|
||||
//解散群
|
||||
model('Tencent')->delete_group('g'.$guild_id);
|
||||
Db::commit();
|
||||
@@ -610,8 +609,8 @@ class Guild extends Model
|
||||
//规则
|
||||
$data['rule'] = get_system_config_value('web_site').'/api/Page/page_show?id=15';
|
||||
//上周流水
|
||||
$week_start = date('Y-m-d', strtotime('last monday'));
|
||||
$week_end = date('Y-m-d', strtotime('last monday +6 days'));
|
||||
$week_start = date('Y-m-d 00:00:00', strtotime('last week Monday'));
|
||||
$week_end = date('Y-m-d 23:59:59', strtotime('last week Monday +6 days'));
|
||||
$guild_subsidy = db::name('vs_guild_subsidy')
|
||||
->where(["guild_id"=>$guild_id,'start_time' => $week_start, 'end_time' => $week_end])
|
||||
->find();
|
||||
@@ -622,18 +621,38 @@ class Guild extends Model
|
||||
$data['list'][0]['status_str'] = isset( $guild_subsidy['status'])&& $guild_subsidy['status']==1 ? "已发放" : "未发放";
|
||||
//本周流水
|
||||
//本周的第一天
|
||||
$week = strtotime(date('Y-m-d', strtotime('this week Monday')));
|
||||
$guild_user = db::name('vs_guild_user')->where(['guild_id' => $guild_id,'status'=>1,"delete_time"=>null])->select();
|
||||
$guild_user_ids = array_column($guild_user,'room_id');
|
||||
$total_transaction = db::name('vs_give_gift')
|
||||
->where(['from'=>2,'from_id' => ['in',$guild_user_ids],'createtime' => ['between', [$week, time()]]])
|
||||
->sum('total_price');
|
||||
$week = strtotime(date('Y-m-d 00:00:00', strtotime('this week Monday')));
|
||||
$guild_user = db::name('vs_guild_user')->where(['guild_id' => $guild_id])->select();
|
||||
$transaction = 0;
|
||||
foreach ($guild_user as $k => $v){
|
||||
$week_start_time_seach = $week;
|
||||
$week_end_time_seach = time();
|
||||
if($v['createtime'] && $week_start_time_seach < $v['createtime']){
|
||||
$week_start_time_seach = $v['createtime'];
|
||||
}
|
||||
if($v['quit_time'] && ($week_end_time_seach > $v['quit_time'])){
|
||||
$week_end_time_seach = $v['quit_time'];
|
||||
}
|
||||
$transaction_one = db::name('vs_give_gift')
|
||||
->whereIn('from_id',$v['room_id'])
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$week_start_time_seach, $week_end_time_seach]]])
|
||||
->sum('total_price');
|
||||
$transaction += $transaction_one;
|
||||
|
||||
}
|
||||
$total_transaction = $transaction;
|
||||
$ss = 0;
|
||||
if($total_transaction){
|
||||
//根据工会流水 获取补贴比例 单位%
|
||||
$subsidy_config = db::name('vs_guild_subsidy_config')->where('start_amount <= '. $total_transaction)
|
||||
->where('end_amount > '. $total_transaction)->getField('subsidy_ratio');
|
||||
$ss = $total_transaction * ($subsidy_config / 100);
|
||||
//获取补贴配置
|
||||
$config = db::name('vs_guild_subsidy_config')->where(['status' => 1])->order('end_amount desc')->select(); //配置查询
|
||||
foreach ($config as $k => $v) {
|
||||
if ($total_transaction >= $v['end_amount']) {
|
||||
$subsidy_ratio = $v['subsidy_ratio'];
|
||||
$ss = ($total_transaction * ($subsidy_ratio / 100)) / get_system_config_value('rmb_coin_ratio');//转为钻石
|
||||
break; // 找到匹配项后提前退出循环
|
||||
}
|
||||
}
|
||||
}
|
||||
//待开发
|
||||
$data['list'][1]['name'] = "本周流水";
|
||||
@@ -651,62 +670,68 @@ class Guild extends Model
|
||||
$coin_consumption_type_array = model('common/UserWallet')->coin_consumption_type_array;
|
||||
$coin_consumption_type_array = array_diff($coin_consumption_type_array, [model('common/UserWallet')::OPERATION_CONSUME]);
|
||||
|
||||
// // 获取所有工会成员的 user_id
|
||||
// $all_guild_users = Db::name('vs_guild_user')
|
||||
// ->where(['guild_id' => $guild_id, 'status' => 1, 'delete_time' => 0])
|
||||
// ->column('user_id');
|
||||
//
|
||||
// // 批量查询总消费
|
||||
// $total_consumption = Db::name('vs_user_money_log')
|
||||
// ->whereIn('change_type', $coin_consumption_type_array)
|
||||
// ->where(['money_type' => 1, 'createtime' => ['between', [$start_time, $end_time]]])
|
||||
// ->whereIn('user_id', $all_guild_users)
|
||||
// ->sum('change_value');
|
||||
//总消费
|
||||
//所有工会成员
|
||||
// 总消费 - 需要按时间限制并只统计加入工会后的消费
|
||||
if (!$start_time || !$end_time) {
|
||||
// 如果没有指定时间范围,则查询所有记录
|
||||
$start_time_filter = 0;
|
||||
$end_time_filter = time();
|
||||
} else {
|
||||
$start_time_filter = strtotime($start_time." 00:00:00");
|
||||
$end_time_filter = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
|
||||
// 所有工会成员
|
||||
$all_guild_user = db::name('vs_guild_user')->where(['guild_id' => $guild_id,'status'=>1,"delete_time"=>0])->select();
|
||||
$total_consumption = 0;
|
||||
foreach ($all_guild_user as $key => $value) {
|
||||
if(!$start_time){
|
||||
$start_time_all = $value['createtime'];
|
||||
$end_time_all = time();
|
||||
}else{
|
||||
$start_time_all = strtotime($start_time." 00:00:00");
|
||||
$end_time_all = strtotime($end_time." 23:59:59");
|
||||
// 计算时间范围:取工会加入时间和指定时间范围的较大值作为开始时间
|
||||
$actual_start_time = max($value['createtime'], $start_time_filter);
|
||||
$actual_end_time = $end_time_filter;
|
||||
|
||||
// 如果开始时间大于结束时间,则跳过该用户
|
||||
if ($actual_start_time > $actual_end_time) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$consumption = db::name('vs_user_money_log')
|
||||
->whereIn('change_type',$coin_consumption_type_array)
|
||||
->where(['money_type'=>1,'user_id' => $value['user_id'],'createtime' => ['between', [$start_time_all, $end_time_all]]])
|
||||
->where(['money_type'=>1,'user_id' => $value['user_id']])
|
||||
->where('createtime', '>=', $actual_start_time)
|
||||
->where('createtime', '<=', $actual_end_time)
|
||||
->sum('change_value');
|
||||
$total_consumption = $total_consumption+$consumption;
|
||||
$total_consumption = $total_consumption + ($consumption ?: 0);
|
||||
}
|
||||
|
||||
if (!$start_time || !$end_time) {
|
||||
$start_time = strtotime('-1 month'); // 默认最近一个月
|
||||
// 如果没有指定时间范围,则查询所有记录
|
||||
$start_time = 0;
|
||||
$end_time = time();
|
||||
}else{
|
||||
$start_time = strtotime($start_time." 00:00:00");
|
||||
$end_time = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
|
||||
// 查询成员列表及各自消费
|
||||
$list = Db::name('vs_guild_user')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime BETWEEN ' . $start_time . ' AND ' . $end_time, 'LEFT')
|
||||
->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime >= a.createtime' . ($start_time ? ' AND c.createtime >= ' . $start_time : '') . ($end_time ? ' AND c.createtime <= ' . $end_time : ''), 'LEFT')
|
||||
->field('a.id, a.user_id, a.guild_id, a.room_id, a.status, a.is_deacon, b.nickname, b.avatar, b.user_code, a.createtime, a.apply_time, SUM(c.change_value) AS total_consumption')
|
||||
->where(['a.guild_id' => $guild_id, 'a.status' => 1,'a.delete_time' => 0])
|
||||
->group('a.user_id')
|
||||
->order('a.id asc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
|
||||
$count = Db::name('vs_guild_user')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime BETWEEN ' . $start_time . ' AND ' . $end_time, 'LEFT')
|
||||
->join('vs_user_money_log c', 'a.user_id = c.user_id AND c.money_type = 1 AND c.change_type IN (' . implode(',', $coin_consumption_type_array) . ') AND c.createtime >= a.createtime' . ($start_time ? ' AND c.createtime >= ' . $start_time : '') . ($end_time ? ' AND c.createtime <= ' . $end_time : ''), 'LEFT')
|
||||
->field('a.id, a.user_id, a.guild_id, a.room_id, a.status, a.is_deacon, b.nickname, b.avatar, b.user_code, a.createtime, a.apply_time, SUM(c.change_value) AS total_consumption')
|
||||
->where(['a.guild_id' => $guild_id, 'a.status' => 1,'a.delete_time' => 0])
|
||||
->group('a.user_id')
|
||||
->count();
|
||||
|
||||
$data = [];
|
||||
foreach ($list as $k => $v) {
|
||||
$data[$k]['id'] = $v['id'];
|
||||
@@ -748,9 +773,15 @@ class Guild extends Model
|
||||
$start_time_all = strtotime($start_time." 00:00:00");
|
||||
$end_time_all = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
if($value['createtime'] && $start_time_all < $value['createtime']){
|
||||
$start_time_all = $value['createtime'];
|
||||
}
|
||||
if($value['quit_time'] && ($end_time_all > $value['quit_time'])){
|
||||
$end_time_all = $value['quit_time'];
|
||||
}
|
||||
$transaction = db::name('vs_give_gift')
|
||||
->where('from_id',$value['room_id'])
|
||||
->where(['from'=>2,'createtime' => ['between', [$start_time_all, $end_time_all]]])
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$start_time_all, $end_time_all]]])
|
||||
->sum('total_price');
|
||||
$total_transaction = $total_transaction+$transaction;
|
||||
}
|
||||
@@ -765,11 +796,17 @@ class Guild extends Model
|
||||
$i=0;
|
||||
foreach ($list as $k=>$v){
|
||||
if(!$start_time){
|
||||
$start_time = $v['createtime'];
|
||||
$end_time = time();
|
||||
$start_time_seach = $value['createtime'];
|
||||
$end_time_seach = time();
|
||||
}else{
|
||||
$start_time = strtotime($start_time." 00:00:00");
|
||||
$end_time = strtotime($end_time." 23:59:59");
|
||||
$start_time_seach = strtotime($start_time." 00:00:00");
|
||||
$end_time_seach = strtotime($end_time." 23:59:59");
|
||||
}
|
||||
if($value['createtime'] && $start_time_all < $value['createtime']){
|
||||
$start_time_seach = $value['createtime'];
|
||||
}
|
||||
if($value['quit_time'] && ($end_time_all > $value['quit_time'])){
|
||||
$end_time_seach = $value['quit_time'];
|
||||
}
|
||||
$room_info = db::name('vs_room')->where(['id'=>$v['room_id'],'room_status'=>1,'delete_time'=>0])->find();
|
||||
if($room_info){
|
||||
@@ -779,7 +816,7 @@ class Guild extends Model
|
||||
$room_data[$i]['room_cover'] = localpath_to_netpath($room_info['room_cover']);
|
||||
$room_data[$i]['total_price'] = db::name('vs_give_gift')
|
||||
->where('from_id',$v['room_id'])
|
||||
->where(['from'=>2,'createtime' => ['between', [$start_time, $end_time]]])
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$start_time_seach, $end_time_seach]]])
|
||||
->sum('total_price');
|
||||
$i++;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ class Invited extends Model
|
||||
$invited_draw_conf = get_system_config_value('invited_draw');//分成比例
|
||||
$invited_draw = $invited_draw_conf / 100;
|
||||
$invited_draw_money = $money * $invited_draw;
|
||||
$invited_draw_money = $invited_draw_money / intval(get_system_config_value('rmb_coin_ratio')); //金币换算成钻石
|
||||
//修改用户资金
|
||||
$reslut = model('common/UserWallet')->change_user_money($invited_user_id, $invited_draw_money, model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::OPERATION_INVITE_REBATE, '邀请用户充值返利');
|
||||
if($reslut['code'] == 1){
|
||||
@@ -103,7 +104,7 @@ class Invited extends Model
|
||||
//查询用户昵称
|
||||
$v['nickname'] = model('User')->where('id', $v['sub_user_id'])->value('nickname');
|
||||
$v['coin'] = intval($v['coin']);
|
||||
$v['earnings'] = intval($v['earnings']);
|
||||
$v['earnings'] = number_format($v['earnings'], 2, '.', ''); // 保留两位小数
|
||||
$v['proportion'] = intval($v['proportion']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
|
||||
@@ -27,6 +27,7 @@ class Level extends Model
|
||||
{
|
||||
//规则
|
||||
$return['rule_url'] = get_system_config_value('web_site')."/api/Page/page_show?id=10";
|
||||
$return['coin_charm_exp'] = get_system_config_value('coin_charm_exp');
|
||||
//用户信息
|
||||
$user = model('User')->get_user_info($uid);
|
||||
//用户头像
|
||||
@@ -53,14 +54,15 @@ class Level extends Model
|
||||
//距离下个等级需要的经验
|
||||
$return['user']['next_level'] = $user['charm_level']+1;
|
||||
$return['user']['next_level_str'] = 'Lv.'.$return['user']['next_level'];
|
||||
$return['user']['next_exp'] = $user_level['next_level_exp'] - $user['wealth_exp'];
|
||||
$next_exp = $user_level['next_level_exp'] - $user['charm_exp'];
|
||||
$return['user']['next_exp'] = $next_exp <= 0 ? 0 : $next_exp;
|
||||
$return['user']['next_rights_icon'] = $user_level['next_rights_icon'];
|
||||
}
|
||||
|
||||
//获取等级
|
||||
// 获取用户当前等级
|
||||
$currentUserLevel = $user['charm_level'];
|
||||
if($currentUserLevel == 0){
|
||||
if($currentUserLevel == 1){
|
||||
$level = Db::name('vs_charm_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'asc')
|
||||
@@ -89,7 +91,7 @@ class Level extends Model
|
||||
$return['level'][$key]['name'] = $value['name'];
|
||||
$return['level'][$key]['change_value'] = $value['change_value'];
|
||||
//当前用户距离当前段位的距离
|
||||
$return['level'][$key]['distance'] = $value['change_value'] - $user['wealth_exp'];
|
||||
$return['level'][$key]['distance'] = $value['change_value'] - $user['charm_exp'];
|
||||
$return['level'][$key]['rights_icon'] = $value['rights_icon'];
|
||||
}
|
||||
}
|
||||
@@ -107,6 +109,7 @@ class Level extends Model
|
||||
{
|
||||
//规则
|
||||
$return['rule_url'] = get_system_config_value('web_site')."/api/Page/page_show?id=11";
|
||||
$return['coin_wealth_exp'] = get_system_config_value('coin_wealth_exp');
|
||||
//用户信息
|
||||
$user = model('User')->get_user_info($uid);
|
||||
//用户头像
|
||||
@@ -142,13 +145,14 @@ class Level extends Model
|
||||
//距离下个等级需要的经验
|
||||
$return['user']['next_level'] = $user['wealth_level']+1;
|
||||
$return['user']['next_level_str'] = 'Lv.'.$return['user']['next_level'];
|
||||
$return['user']['next_exp'] = $user_level['next_level_exp'] - $user['wealth_exp'];
|
||||
$next_exp = $user_level['next_level_exp'] - $user['wealth_exp'];
|
||||
$return['user']['next_exp'] = $next_exp <= 0 ? 0 : $next_exp;
|
||||
$return['user']['next_coins'] = $user_level['next_coins'];
|
||||
}
|
||||
//获取等级
|
||||
// 获取用户当前等级
|
||||
$currentUserLevel = $user['wealth_level'];
|
||||
if($currentUserLevel == 0){
|
||||
if($currentUserLevel == 1){
|
||||
$level = Db::name('vs_wealth_level')
|
||||
->where('status', 1)
|
||||
->order('level', 'asc')
|
||||
@@ -226,11 +230,11 @@ class Level extends Model
|
||||
$return['next_level_icon'] = $next_level_data['image'];
|
||||
$return['next_coins'] = $next_level_data['coins'];
|
||||
}else{
|
||||
$return['next_level'] = 0;
|
||||
$return['next_level_name'] = '';
|
||||
$return['next_level_exp'] = 0;
|
||||
$return['next_level_icon'] = '';
|
||||
$return['next_coins'] = 0;
|
||||
$return['next_level'] = $level_data['level'];
|
||||
$return['next_level_name'] = $level_data['name'];
|
||||
$return['next_level_exp'] = $level_data['change_value'];
|
||||
$return['next_level_icon'] = $level_data['image'];
|
||||
$return['next_coins'] = $level_data['coins'];
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
@@ -264,11 +268,11 @@ class Level extends Model
|
||||
$return['next_level_icon'] = $next_level_data['image'];
|
||||
$return['next_rights_icon'] = $next_level_data['rights_icon'];
|
||||
}else{
|
||||
$return['next_level'] = 0;
|
||||
$return['next_level_name'] = '';
|
||||
$return['next_level_exp'] = 0;
|
||||
$return['next_level_icon'] = '';
|
||||
$return['next_rights_icon'] = "";
|
||||
$return['next_level'] = $level_data['level'];
|
||||
$return['next_level_name'] = $level_data['name'];
|
||||
$return['next_level_exp'] = $level_data['change_value'];
|
||||
$return['next_level_icon'] = $level_data['image'];
|
||||
$return['next_rights_icon'] = $level_data['rights_icon'];
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
@@ -289,10 +293,11 @@ class Level extends Model
|
||||
$user_wealth_level = $user['wealth_level'];
|
||||
$user_wealth_exp = $user['wealth_exp'] + $wealth_exp;
|
||||
//判断是否达到下一级别
|
||||
$user_wealth = $this->get_wealth_level_to_level($user_wealth_level);
|
||||
if($user_wealth_exp>= $user_wealth['exp']){
|
||||
$user_wealth_level= $user_wealth['next_level'];
|
||||
}
|
||||
$user_wealth = $this->get_wealth_level_to_level_vlue($user_wealth_exp);
|
||||
// if($user_wealth_level>= $user_wealth['level']){
|
||||
// $user_wealth_level= $user_wealth['level'];
|
||||
// }
|
||||
$user_wealth_level= $user_wealth['level'];
|
||||
$update_data = [];
|
||||
$update_data['wealth_level'] = $user_wealth_level;
|
||||
$update_data['wealth_exp'] = $user_wealth_exp;
|
||||
@@ -319,10 +324,11 @@ class Level extends Model
|
||||
$user_charm_level = $user['charm_level'];
|
||||
$user_charm_exp = $user['charm_exp'] + $charm_exp;
|
||||
//判断是否达到下一级别
|
||||
$user_charm = $this->get_charm_level_to_level($user_charm_level);
|
||||
if($user_charm_exp>= $user_charm['exp']){
|
||||
$user_charm_level= $user_charm['next_level'];
|
||||
}
|
||||
$user_charm = $this->get_charm_level_to_level_vlue($user_charm_exp);
|
||||
// if($user_charm_level != $user_charm['level']){
|
||||
// $user_charm_level = $user_charm['level'];
|
||||
// }
|
||||
$user_charm_level = $user_charm['level'];
|
||||
$update_data = [];
|
||||
$update_data['charm_level'] = $user_charm_level;
|
||||
$update_data['charm_exp'] = $user_charm_exp;
|
||||
@@ -412,4 +418,45 @@ class Level extends Model
|
||||
}
|
||||
return ['code' => 1, 'msg' => "成功", 'data' => null];
|
||||
}
|
||||
|
||||
/*
|
||||
* 通过魅力值获取对应等级
|
||||
*/
|
||||
public function get_charm_level_to_level_vlue($charm_level){
|
||||
$return = [];
|
||||
$level_data = Db::name('vs_charm_level')->where(["change_value"=>['<',$charm_level]])->order('change_value','desc')->find();
|
||||
if($level_data){
|
||||
$return['level'] = $level_data['level'];
|
||||
$return['level_name'] = $level_data['name'];
|
||||
$return['exp'] = $level_data['change_value'];
|
||||
$return['level_icon'] = $level_data['image'];
|
||||
}else{
|
||||
$return['level'] = 0;
|
||||
$return['level_name'] = '';
|
||||
$return['exp'] = 0;
|
||||
$return['level_icon'] = '';
|
||||
$return['rights_icon'] = "";
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
/*
|
||||
* 通过财富值获取对应等级
|
||||
*/
|
||||
public function get_wealth_level_to_level_vlue($wealth_level){
|
||||
$return = [];
|
||||
$level_data = Db::name('vs_wealth_level')->where(["change_value"=>['<',$wealth_level]])->order('change_value','desc')->find();
|
||||
if($level_data){
|
||||
$return['level'] = $level_data['level'];
|
||||
$return['level_name'] = $level_data['name'];
|
||||
$return['exp'] = $level_data['change_value'];
|
||||
$return['level_icon'] = $level_data['image'];
|
||||
}else{
|
||||
$return['level'] = 0;
|
||||
$return['level_name'] = '';
|
||||
$return['exp'] = 0;
|
||||
$return['level_icon'] = '';
|
||||
$return['rights_icon'] = "";
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,16 +107,44 @@ class Login extends Model
|
||||
$block = db::name('block')->where(['type_text' => $user_info['id'],'type' => 1])->find();
|
||||
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => '用户已被封禁', 'data' => null];
|
||||
if($block['block_time'] != 0 && $block['block_time'] <= time()){
|
||||
db('block')->where(['id' => $block['id']])->delete();
|
||||
$sms_error = db::name('sms_error')->where(['mobile' => $user_info['mobile']])->find();
|
||||
if($sms_error){
|
||||
db::name('sms_error')->where(['mobile' => $user_info['mobile']])->delete();
|
||||
}
|
||||
}else{
|
||||
if($block['block_time'] == 0){
|
||||
return ['code' => 301, 'msg' => '用户已被永久封禁', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 301, 'msg' => '用户已被封禁,解封时间:'.date('Y-m-d H:i:s',$block['block_time']), 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
$block = db::name('block')->where(['type_text' => $login_device,'type' => 2])->find();
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => '设备已被封禁', 'data' => null];
|
||||
if($block['block_time'] != 0 && $block['block_time'] <= time()){
|
||||
db('block')->where(['id' => $block['id']])->delete();
|
||||
}else{
|
||||
if($block['block_time'] == 0){
|
||||
return ['code' => 301, 'msg' => '设备已被永久封禁', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 301, 'msg' => '设备已被封禁,解封时间:'.date('Y-m-d H:i:s',$block['block_time']), 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
$ip = request()->ip();
|
||||
$block = db::name('block')->where(['type_text' => $ip,'type' => 3])->find();
|
||||
if ($block) {
|
||||
return ['code' => 0, 'msg' => 'ip已被封禁', 'data' => null];
|
||||
if($block['block_time'] != 0 && $block['block_time'] <= time()){
|
||||
db('block')->where(['id' => $block['id']])->delete();
|
||||
}else{
|
||||
if($block['block_time'] == 0){
|
||||
return ['code' => 301, 'msg' => 'ip已被永久封禁', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 301, 'msg' => 'ip已被封禁,解封时间:'.date('Y-m-d H:i:s',$block['block_time']), 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$save_data = [];
|
||||
@@ -135,7 +163,7 @@ class Login extends Model
|
||||
$return_res[$key]['tencent_im'] = '';
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '用户获取成功', 'data' => $return_res];
|
||||
return ['code' => 1, 'msg' => '用户获取成功!~', 'data' => $return_res];
|
||||
}else{
|
||||
$user_info = $phone_user['data'][0];
|
||||
}
|
||||
@@ -181,6 +209,17 @@ class Login extends Model
|
||||
}
|
||||
$return_res[0]['auth'] = $isAuth;
|
||||
|
||||
//是否可以发布动态
|
||||
$user_rechange = db::name('vs_user_recharge')->field('sum(money) as money')->where(['user_id' => $user_info['id'],'pay_status' => 2])->find();
|
||||
//系统配置
|
||||
$config_money = get_system_config_value('private_chat_recharge_money');
|
||||
if(($config_money > 0) && ($user_rechange['money'] < $config_money)){
|
||||
$return_res[0]['is_can_chat'] = 0;
|
||||
}else{
|
||||
$return_res[0]['is_can_chat'] = 1;
|
||||
}
|
||||
$return_res[0]['can_chat_money'] = $config_money;
|
||||
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $return_res];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '登录失败,账号失效', 'data' => null];
|
||||
@@ -254,28 +293,52 @@ class Login extends Model
|
||||
return ['code' => 0, 'msg' => '密码不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = model('User')->where(['mobile' => $user_name,'status'=>1])->find();
|
||||
$user_info = model('User')->where(['mobile' => $user_name,'status'=>['<>',0]])->find();
|
||||
if (empty($user_info)) {
|
||||
return ['code' => 0, 'msg' => '用户不存在', 'data' => null];
|
||||
}
|
||||
//今天误次数
|
||||
$sms_count = db::name('sms_error')->where(['mobile' => $user_name,'createtime' => ['between', [strtotime(date('Y-m-d')), time()]]])->count();
|
||||
|
||||
if (md5($password) != $user_info['password']) {
|
||||
return ['code' => 0, 'msg' => '密码错误', 'data' => null];
|
||||
}
|
||||
$multi_user = [];
|
||||
//查询手机号绑定的账号
|
||||
$phone_user = $this->phone_login_query($user_name);
|
||||
if($phone_user['code'] == 1){
|
||||
//获取返回数据的长度
|
||||
if(count($phone_user['data']) >= 2){
|
||||
$multi_user = $phone_user['data'];
|
||||
if ($sms_count >= 5) {
|
||||
$user_id = db::name('user')->where('mobile', $user_name)->value('id');
|
||||
$block_num = db::name('block')->where(['type' => 1, 'type_text' => $user_id])->find();
|
||||
if(!$block_num){
|
||||
//封禁账号
|
||||
$error_data = [
|
||||
'type' => 1,
|
||||
'type_text' => $user_id,
|
||||
'block_time' => time() + 60 * 60 * 24,
|
||||
'block_note' => '账号登录异常被封禁24小时',
|
||||
'createtime'=> time(),
|
||||
];
|
||||
db::name('block')->insert($error_data);
|
||||
db::name('user')->where('id', $user_id)->update(['status' => 2]);
|
||||
}
|
||||
|
||||
return ['code' => 0, 'msg' => '登录错误次数过多,账号已被封禁,请联系管理员处理','data' =>null];
|
||||
}
|
||||
|
||||
$login = $this->login($user_info,$system,$login_device,$multi_user);
|
||||
$count_sms = max(5 - $sms_count, 0);
|
||||
if (md5($password) != $user_info['password']) {
|
||||
$data = [
|
||||
'mobile' => $user_name,
|
||||
'type' => 2,
|
||||
'sms' => $password,
|
||||
'createtime'=> time(),
|
||||
];
|
||||
db::name('sms_error')->insert($data);
|
||||
return ['code' => 0, 'msg' => '密码错误,'.$count_sms.'次后账号将被封禁24小时', 'data' => null];
|
||||
}
|
||||
|
||||
$login = $this->login($user_info,$system,$login_device);
|
||||
if($login['code'] != 1){
|
||||
return $login;
|
||||
}
|
||||
|
||||
//登陆成功后 把所有的登录错误删除掉
|
||||
db::name('sms_error')->where(['mobile' => $user_name])->delete();
|
||||
|
||||
return ['code' => 1, 'msg' => '登录成功', 'data' => $login['data']];
|
||||
}
|
||||
|
||||
@@ -300,12 +363,24 @@ class Login extends Model
|
||||
if($type == 'wx'){
|
||||
$openid = $userinfo['openid'];
|
||||
$user_info_data = model('UserData')->where(['wx_openid' => $openid,'deletetime'=>0])->find();
|
||||
$config_time = get_system_config_value('cancel_to_reset_reg');
|
||||
if(isset($user_info_data) && $user_info_data['deletetime'] != 0 && time() - $user_info_data['deletetime'] < 86400 * $config_time){
|
||||
return ['code' => 0, 'msg' => '注销后需等待'.$config_time.'天才能重新注册', 'data' => null];
|
||||
}
|
||||
}elseif ($type == 'ali'){
|
||||
$ali_userid = $userinfo['open_id'];
|
||||
$user_info_data = model('UserData')->where(['ali_userid' => $ali_userid,'deletetime'=>0])->find();
|
||||
$config_time = get_system_config_value('cancel_to_reset_reg');
|
||||
if(isset($user_info_data) && $user_info_data['deletetime'] != 0 && time() - $user_info_data['deletetime'] < 86400 * $config_time){
|
||||
return ['code' => 0, 'msg' => '注销后需等待'.$config_time.'天才能重新注册', 'data' => null];
|
||||
}
|
||||
}elseif ($type == 'ios'){
|
||||
$apple_id = $userinfo;
|
||||
$user_info_data = model('UserData')->where(['apple_id' => $userinfo,'deletetime'=>0])->find();
|
||||
$config_time = get_system_config_value('cancel_to_reset_reg');
|
||||
if(isset($user_info_data) && $user_info_data['deletetime'] != 0 && time() - $user_info_data['deletetime'] < 86400 * $config_time){
|
||||
return ['code' => 0, 'msg' => '注销后需等待'.$config_time.'天才能重新注册', 'data' => null];
|
||||
}
|
||||
}
|
||||
else{
|
||||
return ['code' => 0, 'msg' => '登录类型错误', 'data' => null];
|
||||
@@ -371,10 +446,23 @@ class Login extends Model
|
||||
//注销
|
||||
public function cancel($token){
|
||||
$user_info = model('UserToken')->where('token', $token)->find();
|
||||
//用户注册时间
|
||||
$register_time = db::name('user')->where('id', $user_info['user_id'])->value('createtime');
|
||||
$config_time = get_system_config_value('reg_to_cancel');
|
||||
if(time() - $register_time < 86400 * $config_time){
|
||||
return ['code' => 0, 'msg' => '注册'.$config_time.'天内不能注销!', 'data' => null];
|
||||
}
|
||||
if($user_info){
|
||||
model('UserToken')->where('id', $user_info['id'])->update(['token' => 1]);
|
||||
$isstatus = model('User')->where('id', $user_info['user_id'])->update(['status' => 0]);
|
||||
if($isstatus){
|
||||
//查询用户所在房间
|
||||
$room_list = db::name('vs_room_visitor')->where('user_id', $user_info['user_id'])->select();
|
||||
if($room_list){
|
||||
foreach ($room_list as &$value) {
|
||||
model('Room')->quit_room($user_info['user_id'], $value['room_id'],$user_info['user_id']);
|
||||
}
|
||||
}
|
||||
//删除用户
|
||||
// model('Tencent')->account_delete($user_info['user_id']);
|
||||
model('User')->where('id', $user_info['user_id'])->update(['delete_time' => time()]);
|
||||
@@ -387,25 +475,16 @@ class Login extends Model
|
||||
db::name('vs_room')->where('id', $value['id'])->update(['room_status' => 3]);
|
||||
}
|
||||
}
|
||||
//查询用户所在房间
|
||||
$room_list = db::name('vs_room_visitor')->where('user_id', $user_info['user_id'])->select();
|
||||
if($room_list){
|
||||
foreach ($room_list as &$value) {
|
||||
model('Room')->quit_room($user_info['user_id'], $value['room_id'],$user_info['user_id']);
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => '注销失败', 'data' => null];
|
||||
}
|
||||
|
||||
//查询绑定的手机号
|
||||
$mob = db::name('user')->where('id', $user_info['user_id'])->value('mobile');
|
||||
$mobile = db::name('user')->where('mobile', $mob)->select();
|
||||
$mobile = db::name('user')->where(['mobile' => $mob,'status' => ['<>',0]])->select();
|
||||
if(isset($mobile) && count($mobile) < 2){
|
||||
$user_auth = db::name('user_auth')->where('mobile', $mobile[0]['mobile'])->find();
|
||||
if($user_auth){
|
||||
db::name('user_auth')->where('id', $user_auth['id'])->delete();
|
||||
}
|
||||
db::name('user_auth')->where('mobile', $mob)->delete();
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '注销成功', 'data' => null];
|
||||
|
||||
@@ -40,26 +40,7 @@ class Ranking extends Model
|
||||
//财富、魅力榜
|
||||
public function ranking($ranking_type)
|
||||
{
|
||||
if($ranking_type == 1){//1财富榜,2魅力榜
|
||||
$field = 'a.user_id,b.user_code,b.nickname,b.avatar,sum(a.total_wealth) as total';
|
||||
$order = 'total desc';
|
||||
$where['a.total_wealth'] = ['>', 0];
|
||||
}else{
|
||||
$field = 'a.user_id,b.user_code,b.nickname,b.avatar,sum(a.total_charm) as total';
|
||||
$order = 'total desc';
|
||||
$where['a.total_charm'] = ['>', 0];
|
||||
}
|
||||
$where['a.updatetime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
|
||||
$lists = db::name('vs_room_user_charm')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->field($field)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->group('a.user_id')
|
||||
->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
|
||||
$where['a.createtime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
$my_ranking = db::name('user')
|
||||
->field('user_code,avatar,nickname,id as user_id,user_code,sex')
|
||||
->where('id',$this->user_id)->find();
|
||||
@@ -67,45 +48,109 @@ class Ranking extends Model
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = 0;
|
||||
if($lists){
|
||||
foreach ($lists as $key => &$value) {
|
||||
$lists[$key]['icon'][0] = model('UserData')->user_wealth_icon($value['user_id']);//财富图标
|
||||
$lists[$key]['icon'][1] = model('UserData')->user_charm_icon($value['user_id']);//魅力图标
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
if ($this->user_id == $value['user_id']) {
|
||||
$my_ranking = $lists[$key];
|
||||
$my_ranking['diff'] = $key == 0 ? 0 : ($lists[$key - 1]['total'] - $value['total']);
|
||||
if($ranking_type == 1){//1财富榜,2魅力榜
|
||||
$lists = db::name('vs_give_gift')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->field('a.user_id,b.nickname,b.avatar,b.user_code,sum(a.total_price) * 10 as total')
|
||||
->where($where)
|
||||
->order('total desc')
|
||||
->group('a.user_id')
|
||||
// ->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
|
||||
if($lists){
|
||||
foreach ($lists as $key => &$value) {
|
||||
$lists[$key]['icon'][0] = model('UserData')->user_wealth_icon($value['user_id']);//财富图标
|
||||
$lists[$key]['icon'][1] = model('UserData')->user_charm_icon($value['user_id']);//魅力图标
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
if ($this->user_id == $value['user_id']) {
|
||||
$my_ranking = $lists[$key];
|
||||
$my_ranking['diff'] = $key == 0 ? 0 : ($lists[$key - 1]['total'] - $value['total']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$my_ranking && $lists && defined('UID')) {
|
||||
$my_ranking_data = db::name('vs_give_gift')->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->field('a.user_id,b.nickname,b.avatar,b.user_code,sum(a.total_price) * 10 as total')
|
||||
->where($where)
|
||||
->where('a.user_id',$this->user_id)
|
||||
->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
$my_ranking_data['icon'][0] = model('UserData')->user_wealth_icon($my_ranking_data['user_id']);//财富图标
|
||||
$my_ranking_data['icon'][1] = model('UserData')->user_charm_icon($my_ranking_data['user_id']);//魅力图标
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
|
||||
if (!isset($my_ranking_data['user_id']) || !$my_ranking_data['user_id']) {
|
||||
$my_ranking = db::name('user')
|
||||
->field('user_code,avatar,nickname,id as user_id,user_code,sex')
|
||||
->where('id',$this->user_id)->find();
|
||||
$my_ranking['icon'][0] = model('UserData')->user_wealth_icon($my_ranking['user_id']);//财富图标
|
||||
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
} else {
|
||||
$my_ranking = $my_ranking_data;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = numberFormat($my_ranking['total']);
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number - ($my_ranking_data['total'] ?: 0));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$lists = db::name('vs_give_gift')->alias('a')
|
||||
->join('user b', 'a.gift_user = b.id')
|
||||
->field('a.gift_user as user_id,b.nickname,b.avatar,b.user_code,sum(a.total_price) * 10 as total')
|
||||
->where($where)
|
||||
->order('total desc')
|
||||
->group('a.gift_user')
|
||||
// ->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
|
||||
if($lists){
|
||||
foreach ($lists as $key => &$value) {
|
||||
$lists[$key]['icon'][0] = model('UserData')->user_wealth_icon($value['user_id']);//财富图标
|
||||
$lists[$key]['icon'][1] = model('UserData')->user_charm_icon($value['user_id']);//魅力图标
|
||||
$lists[$key]['rank'] = $key + 1;
|
||||
if ($this->user_id == $value['user_id']) {
|
||||
$my_ranking = $lists[$key];
|
||||
$my_ranking['diff'] = $key == 0 ? 0 : ($lists[$key - 1]['total'] - $value['total']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$my_ranking && $lists && defined('UID')) {
|
||||
$my_ranking_data = db::name('vs_give_gift')->alias('a')
|
||||
->join('user b', 'a.gift_user = b.id')
|
||||
->field('a.gift_user as user_id,b.nickname,b.avatar,b.user_code,sum(a.total_price) * 10 as total')
|
||||
->where($where)
|
||||
->where('a.gift_user',$this->user_id)
|
||||
->select();
|
||||
|
||||
$my_ranking_data['icon'][0] = model('UserData')->user_wealth_icon($my_ranking_data['user_id']);//财富图标
|
||||
$my_ranking_data['icon'][1] = model('UserData')->user_charm_icon($my_ranking_data['user_id']);//魅力图标
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
|
||||
if (!isset($my_ranking_data['user_id']) || !$my_ranking_data['user_id']) {
|
||||
$my_ranking = db::name('user')
|
||||
->field('user_code,avatar,nickname,id as user_id,user_code,sex')
|
||||
->where('id',$this->user_id)->find();
|
||||
$my_ranking['icon'][0] = model('UserData')->user_wealth_icon($my_ranking['user_id']);//财富图标
|
||||
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
} else {
|
||||
$my_ranking = $my_ranking_data;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = numberFormat($my_ranking['total']);
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number - ($my_ranking_data['total'] ?: 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$my_ranking && $lists && defined('UID')) {
|
||||
$my_ranking_data = db::name('vs_room_user_charm')->alias('a')
|
||||
->join('user b','a.user_id = b.id')
|
||||
->where($where)
|
||||
->where('a.user_id',$this->user_id)
|
||||
->field($field)
|
||||
->find();
|
||||
$my_ranking_data['icon'][0] = model('UserData')->user_wealth_icon($my_ranking_data['user_id']);//财富图标
|
||||
$my_ranking_data['icon'][1] = model('UserData')->user_charm_icon($my_ranking_data['user_id']);//魅力图标
|
||||
$lists_last_number = $lists[count($lists) - 1]['total'] ?? 0;
|
||||
|
||||
if (!isset($my_ranking_data['user_id']) || !$my_ranking_data['user_id']) {
|
||||
$my_ranking = db::name('user')
|
||||
->field('user_code,avatar,nickname,id as user_id,user_code,sex')
|
||||
->where('id',$this->user_id)->find();
|
||||
$my_ranking['icon'][0] = model('UserData')->user_wealth_icon($my_ranking['user_id']);//财富图标
|
||||
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number);
|
||||
} else {
|
||||
$my_ranking = $my_ranking_data;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['total'] = numberFormat($my_ranking['total']);
|
||||
$my_ranking['diff'] = numberFormat($lists_last_number - ($my_ranking_data['total'] ?: 0));
|
||||
}
|
||||
}
|
||||
//截取20条
|
||||
$lists = array_slice($lists,0,20);
|
||||
$data = [
|
||||
'my_ranking' => $my_ranking,
|
||||
'lists' => $lists
|
||||
@@ -117,15 +162,17 @@ class Ranking extends Model
|
||||
//房间榜
|
||||
public function room_ranking()
|
||||
{
|
||||
//金币与魅力比例
|
||||
$ratio = get_system_config_value('coin_charm_exp');
|
||||
$where['a.createtime'] = ['between', [$this->begin_time, $this->end_time]];
|
||||
$where['b.type_id'] = ['<>', 6];
|
||||
$where['b.room_status'] = 1;
|
||||
$field = ['sum(a.total_price) as total,b.room_name,a.from_id as room_id,b.room_cover,b.room_number'];
|
||||
$field = ['sum(a.total_price) *'.$ratio.' as total,b.room_name,a.from_id as room_id,b.room_cover,b.room_number'];
|
||||
$lists = db::name('vs_give_gift')->alias('a')
|
||||
->join('vs_room b','a.from_id = b.id','left')
|
||||
->where($where)->field($field)->group('a.from_id')
|
||||
->order('total desc')
|
||||
->page($this->page, $this->page_limit)
|
||||
// ->page($this->page, $this->page_limit)
|
||||
->select();
|
||||
$my_ranking = null;
|
||||
if($lists){
|
||||
@@ -196,6 +243,8 @@ class Ranking extends Model
|
||||
$my_ranking['room_name'] = $myRoom['room_name'];
|
||||
$my_ranking['room_cover'] = $myRoom['room_cover'];
|
||||
}
|
||||
//截取20条
|
||||
$lists = array_slice($lists,0,20);
|
||||
$data = [
|
||||
'my_ranking' => $my_ranking,
|
||||
'lists' => $lists
|
||||
@@ -234,7 +283,12 @@ class Ranking extends Model
|
||||
}
|
||||
|
||||
$lists = $guilds ;
|
||||
$my_ranking = null;
|
||||
// $my_ranking = null;
|
||||
$my_ranking['guild_name'] = '';
|
||||
$my_ranking['cover'] = '';
|
||||
$my_ranking['total'] = 0;
|
||||
$my_ranking['rank'] = -1;
|
||||
$my_ranking['diff'] = 0;
|
||||
if($lists){
|
||||
//获取当前用户的工会
|
||||
$myGuild = db::name('vs_guild_user')->where(['user_id' => UID])->find();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@ class RoomAuction extends Model
|
||||
//房间关系列表
|
||||
public function room_relation_list($type_id)
|
||||
{
|
||||
$list = db::name('vs_relation')->field('id as relation_id,name,type,icon')->where('type',$type_id)->select();
|
||||
$list = db::name('vs_relation')->field('id as relation_id,name,type,icon')->where(['type' => $type_id,'delete_time' => 0])->select();
|
||||
return ['code' => 1, 'msg' => '操作成功','data' => $list];
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ class RoomAuction extends Model
|
||||
|
||||
|
||||
//参与竞拍
|
||||
public function room_auction_join($auction_id,$user_id,$gift_id,$num,$type)
|
||||
public function room_auction_join($auction_id,$user_id,$gift_id,$num,$type,$ext=[])
|
||||
{
|
||||
if(!$auction_id){
|
||||
return ['code' => 0, 'msg' => '拍卖已经结束','data' => null];
|
||||
@@ -127,7 +127,7 @@ class RoomAuction extends Model
|
||||
}
|
||||
|
||||
//走送礼流程
|
||||
$ree = model('GiveGift')->give_gift($user_id,$auction['user_id'],$gift_id,$num,2,$type,$auction['room_id'],0,0);
|
||||
$ree = model('GiveGift')->give_gift($user_id,$auction['user_id'],$gift_id,$num,2,$type,$auction['room_id'],0,0,$ext);
|
||||
if($ree['code'] != 1){
|
||||
return ['code' => $ree['code'], 'msg' => $ree['msg'],'data' => null];
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class RoomAuction extends Model
|
||||
'auction_id' => $auction_id,
|
||||
'user_id' => $user_id,
|
||||
'gift_id' => $gift_id,
|
||||
'gift_price' => $num * $gift_price,
|
||||
'gift_price' => $ree['data']['gift_total'],
|
||||
'createtime' => time()
|
||||
]);
|
||||
if(!$res){
|
||||
@@ -167,7 +167,7 @@ class RoomAuction extends Model
|
||||
->where(['auction_id' => $auction_id])
|
||||
->group('user_id')
|
||||
->having('gift_prices >= ' . $auction['gift_price'])
|
||||
->order('gift_prices DESC')
|
||||
->order('gift_prices DESC, id ASC')
|
||||
->limit(6)
|
||||
->select();
|
||||
if($list){
|
||||
@@ -292,9 +292,11 @@ class RoomAuction extends Model
|
||||
//查询是否有电影房
|
||||
$cp_movie = $this->movie_room_create_or_add($list['user_id'],$res['user_id'],$res['relation_id'],$res['time_day']);
|
||||
if($cp_movie['code'] != 1){
|
||||
return ['code' => 0, 'msg'=>$cp_movie['msg'], 'data'=>$cp_movie['data']];
|
||||
// return ['code' => 0, 'msg'=>$cp_movie['msg'], 'data'=>$cp_movie['data']];
|
||||
}else{
|
||||
$cp_room_id = $cp_movie['data']['cp_room_id'];
|
||||
}
|
||||
$cp_room_id = $cp_movie['data']['cp_room_id'];
|
||||
|
||||
}
|
||||
$texts = '恭喜'.$auction['nickname'].' 和 '.$recipient['nickname'].',获得'.$auction['relation_name'].' 关系'.$auction['time_day'].'小时';
|
||||
}else{//拍得无关系
|
||||
|
||||
73
application/api/model/RoomHourRanking.php
Normal file
73
application/api/model/RoomHourRanking.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class RoomHourRanking extends Model
|
||||
{
|
||||
//房间小时榜
|
||||
public function room_hour_ranking($page, $page_limit,$start_time = null, $end_time = null)
|
||||
{
|
||||
//当前小时开始时间
|
||||
if($start_time == null){
|
||||
$start_time = strtotime(date('Y-m-d H:00:00'));
|
||||
}
|
||||
|
||||
//结束时间
|
||||
if($end_time == null){
|
||||
$end_time = strtotime(date('Y-m-d H:59:59'));
|
||||
}
|
||||
|
||||
//判断是否开启
|
||||
$open_time = db::name('vs_hour_ranking_config')->where('id', 1)->value('open_time');
|
||||
if ($open_time == 0) {
|
||||
return ['code' => 0, 'msg' => '排行榜暂未开启', 'data' => null];
|
||||
}
|
||||
|
||||
//是否开启巡乐会
|
||||
$is_open_xlh = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_open_xlh');
|
||||
|
||||
// 更进一步的优化版本:
|
||||
$subQuery = Db::name('vs_give_gift')
|
||||
->where('from', 2)
|
||||
->whereBetween('createtime', [$start_time, $end_time])
|
||||
->buildSql();
|
||||
|
||||
$profit = db::name('vs_room')->alias('a')
|
||||
->join([$subQuery => 'b'], 'a.id = b.from_id', 'left')
|
||||
->join('vs_room_label c', 'a.label_id = c.id','left')
|
||||
->field('a.id as room_id,a.user_id,a.room_name,a.label_id,a.room_cover,IFNULL(SUM(b.total_price), 0) as total_price,c.label_icon')
|
||||
->where('a.room_status', 1)
|
||||
->where('a.apply_status', 2)
|
||||
->where('a.type_id', '<>', 6)
|
||||
->group('a.id')
|
||||
->order('total_price', 'desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
|
||||
if($profit){
|
||||
foreach ($profit as &$v) {
|
||||
$v['total_price'] = $v['total_price'] * get_system_config_value('coin_charm_exp');
|
||||
if($v['room_id'] > 0 && $is_open_xlh == 1){
|
||||
$xlh_status = model('BlindBoxTurntableGift')->get_user_xlh_info($v['room_id']);
|
||||
$v['xlh_status'] = $xlh_status['xlh_status'];
|
||||
}else{
|
||||
$v['xlh_status'] = 0;
|
||||
}
|
||||
//查询房间是否有红包
|
||||
if($v['room_id'] > 0){
|
||||
$red_pack_status = Db::name('redpacket')->where(['room_id' => $v['room_id'], 'status' => ['<=',1]])->count();
|
||||
$v['redpacket_status'] = $red_pack_status;
|
||||
}else{
|
||||
$v['redpacket_status'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
//当前小时开始时间 和结束时间 00:00-00:59 这样的格式
|
||||
$time_range = date('H:') . '00-' . date('H:'). '59';
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => ['time_range' => $time_range, 'lists' =>$profit]];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,6 +98,16 @@ class RoomPit extends Model
|
||||
];
|
||||
model('Tencent')->batchsendmsg($remind_user,json_encode($content));
|
||||
}
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $user_id, 'room_id' => $room_id, 'status' => 0])->delete();
|
||||
if($reslut){
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息(数据重置)
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
|
||||
@@ -126,6 +136,10 @@ class RoomPit extends Model
|
||||
if($is_pk > 0 && $pit_number == 9){
|
||||
return ['code' => 0, 'msg' => '当前房间正在pk中', 'data' => null];
|
||||
}
|
||||
$step = db::name('vs_room')->where(['id' => $room_id, 'type_id' => 7])->value('step');
|
||||
if($step && $step != 1 && $pit_number < 9){
|
||||
return ['code' => 0, 'msg' => '交友房 此阶段不可操作', 'data' => null];
|
||||
}
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
@@ -170,7 +184,7 @@ class RoomPit extends Model
|
||||
return ['code' => 0, 'msg' => '请选择房间', 'data' => null];
|
||||
}
|
||||
//查询房间状态
|
||||
$room_info = db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->field('id,room_status,room_up_pit_type,label_id')->find();
|
||||
$room_info = db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->field('id,room_status,room_up_pit_type,label_id,step')->find();
|
||||
if(!$room_info){
|
||||
return ['code' => 0, 'msg' => '房间不存在', 'data' => null];
|
||||
}
|
||||
@@ -178,19 +192,39 @@ class RoomPit extends Model
|
||||
return ['code' => 0, 'msg' => '房间违规或关闭', 'data' => null];
|
||||
}
|
||||
|
||||
if($pit_number == 9){
|
||||
//检查用户是否是房主或主持
|
||||
$is_room_owner =db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$is_room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->field('id')->find();
|
||||
if(!$is_room_owner && !$is_room_host){
|
||||
return ['code' => 0, 'msg' => '没有权限', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if($pit_number == 10){
|
||||
return ['code' => 0, 'msg' => '请等待主持抱麦', 'data' => null];
|
||||
}
|
||||
|
||||
//检查是否在坑位上
|
||||
$pit_infos = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $user_id])->field('id,pit_number')->find();
|
||||
if($pit_infos){
|
||||
return ['code' => 0, 'msg' => '您已上麦', 'data' => null];
|
||||
|
||||
if($room_info['label_id'] == 5 && $room_info['step'] != 1 && $pit_number < 9){
|
||||
return ['code' => 0, 'msg' => '互娱房 此阶段不可此操作', 'data' => null];
|
||||
}
|
||||
|
||||
//自由麦
|
||||
if($room_info['room_up_pit_type'] == 2){
|
||||
if($pit_number > 0){
|
||||
if($room_info['label_id'] == 5){//交友(互娱)
|
||||
if($pit_number == 7 || $pit_number == 8){
|
||||
return ['code' => 0, 'msg' => '该麦位已锁定了', 'data' => null];
|
||||
}
|
||||
if($pit_number == 9){
|
||||
if($pit_infos){
|
||||
return ['code' => 0, 'msg' => '您已上麦', 'data' => null];
|
||||
}
|
||||
}
|
||||
}
|
||||
//查询当前麦位是否有人
|
||||
$pit_info = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_number])->field('id,user_id,is_lock')->find();
|
||||
if($pit_info['user_id'] > 0){
|
||||
@@ -200,106 +234,118 @@ class RoomPit extends Model
|
||||
if($pit_info['is_lock'] == 1){
|
||||
return ['code' => 0, 'msg' => '该麦位被锁定', 'data' => null];
|
||||
}
|
||||
if($pit_number ==9){
|
||||
//检查用户是否是房主或主持
|
||||
$is_room_owner =db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$is_room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->field('id')->find();
|
||||
if(!$is_room_owner && !$is_room_host){
|
||||
return ['code' => 0, 'msg' => '您还不是房间主持人', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
// if($room_info['label_id'] == 2){
|
||||
if($room_info['label_id'] == 5){//交友
|
||||
$pit_number = $this->getRoomNullPitWithout($room_id, [7,8,9,10]);
|
||||
}else{
|
||||
$pit_number = $this->getRoomNullPitWithout($room_id, [9, 10]);
|
||||
// }else{
|
||||
// $pit_number = $this->getRoomNullPitWithout($room_id, [9, 10, 11,12,13,14,15,16,17,18,19,20,21,22]);
|
||||
// }
|
||||
}
|
||||
|
||||
if(!$pit_number){
|
||||
return ['code' => 0, 'msg' => '当前房间没有空麦位', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//换麦使用
|
||||
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
|
||||
//下麦
|
||||
$dow = $this ->DownPit($user_id,$room_id,$pit_infos['pit_number']);
|
||||
if($dow['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
$exchange1 = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_infos['pit_number']])->update([ 'user_id' => 0]);
|
||||
$exchange = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_number])->update([ 'user_id' => $user_id]);
|
||||
if(!$exchange || !$exchange1){
|
||||
return ['code' => 0, 'msg' => '换麦失败', 'data' => null];
|
||||
}
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($user_id,1);
|
||||
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $user_id,'room_id' => $room_id])->value('charm');
|
||||
if($pit_number == 9){
|
||||
$pit_text = '主持麦';
|
||||
}elseif ($pit_number == 10) {
|
||||
$pit_text = '嘉宾麦';
|
||||
}else{
|
||||
$pit_text = $pit_number . '号麦';
|
||||
}
|
||||
$text['text'] = $FromUserInfo['nickname'].' 换到 ' . $pit_text;
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['from_pit_number'] = $pit_infos['pit_number'];
|
||||
$text['to_pit_number'] = $pit_number;
|
||||
model('Chat')->sendMsg(1039,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}else{
|
||||
$ompit = $this->OnPit($user_id,$room_id,$pit_number);//用户上了这个房间的几号麦位
|
||||
if($ompit['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
$ompit = $this->OnPit($user_id,$room_id,$pit_number);//用户上了这个房间的几号麦位
|
||||
if($ompit['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}else{
|
||||
}else{//排麦
|
||||
if($pit_number == 9){
|
||||
//检查用户是否是房主或主持
|
||||
$is_room_owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$is_room_host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->field('id')->find();
|
||||
//查看主持坑9坑
|
||||
$host_pit = $this->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
|
||||
if(($is_room_owner || $is_room_host) && $host_pit == 0){
|
||||
//查询用户是否在麦位上
|
||||
$is_on = $this->where(['room_id' => $room_id, 'user_id' => $user_id])->value('pit_number');
|
||||
if($is_on){
|
||||
//下麦
|
||||
$dow = $this ->DownPit($user_id,$room_id,$is_on);
|
||||
if($dow['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '操作失败', 'data' => null];
|
||||
if ($host_pit > 0) {
|
||||
if ($host_pit == $user_id) {
|
||||
return ['code' => 0, 'msg' => '您已在主持麦位', 'data' => null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '该麦位有人', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
|
||||
$exchange1 = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_infos['pit_number']])->update([ 'user_id' => 0]);
|
||||
$exchange = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => $pit_number])->update([ 'user_id' => $user_id]);
|
||||
if(!$exchange || !$exchange1){
|
||||
return ['code' => 0, 'msg' => '换麦失败', 'data' => null];
|
||||
}
|
||||
$FromUserInfo = db::name('user')->where('id',$user_id)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($user_id);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($user_id);//魅力图标
|
||||
$FromUserInfo['dress'] = model('Decorate')->user_decorate_detail($user_id,1);
|
||||
$FromUserInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $user_id,'room_id' => $room_id])->value('charm');
|
||||
|
||||
$text['text'] = $FromUserInfo['nickname'].' 换到主持麦 ';
|
||||
$text['FromUserInfo'] = $FromUserInfo;
|
||||
$text['from_pit_number'] = $pit_infos['pit_number'];
|
||||
$text['to_pit_number'] = $pit_number;
|
||||
model('Chat')->sendMsg(1039,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}else{
|
||||
//直接上主持麦
|
||||
$ont = $this->OnPit($user_id,$room_id,$pit_number);//用户上了这个房间的几号麦位
|
||||
if($ont['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
//直接上主持麦
|
||||
$ont = $this->OnPit($user_id,$room_id,9);//用户上了这个房间的几号麦位
|
||||
if($ont['code'] != 1){
|
||||
return ['code' => 0, 'msg' => '上麦失败', 'data' => null];
|
||||
}
|
||||
//查找是否在申请列表里
|
||||
$apply_pit = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->find();
|
||||
if($apply_pit){
|
||||
$this->clear_apply_pit_list($user_id, $room_id, $user_id);
|
||||
// db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id])->delete();
|
||||
// $count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
// //申请上麦推送消息
|
||||
// $text = [
|
||||
// 'text' => '申请上麦',
|
||||
// 'count' => $count
|
||||
// ];
|
||||
// model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
//检查用户是否已经申请
|
||||
$apply_pit_info = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id,'apply_type' =>1])->field('id')->find();
|
||||
if($apply_pit_info){
|
||||
return ['code' => 0, 'msg' => '请勿重复申请', 'data' => null];
|
||||
}
|
||||
}else{
|
||||
//检查用户是否已经申请
|
||||
$apply_pit_info = db::name('vs_room_pit_apply')->where(['room_id' => $room_id, 'user_id' => $user_id,'apply_type' =>1])->field('id')->find();
|
||||
if($apply_pit_info){
|
||||
return ['code' => 0, 'msg' => '请勿重复申请', 'data' => null];
|
||||
}
|
||||
|
||||
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
|
||||
return ['code' => 0, 'msg' => '用户已在麦上,请先下麦后再申请', 'data' => null];
|
||||
}
|
||||
if(isset($pit_infos) && $pit_infos['pit_number'] > 0){
|
||||
return ['code' => 0, 'msg' => '用户已在麦上,请先下麦后再申请', 'data' => null];
|
||||
}
|
||||
|
||||
//放入等待区
|
||||
$data = [
|
||||
'room_id' => $room_id,
|
||||
'user_id' => $user_id,
|
||||
'status' => 0,
|
||||
'apply_type' => 1
|
||||
];
|
||||
$reslut = db::name('vs_room_pit_apply')->insert($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '申请失败', 'data' => null];
|
||||
//放入等待区
|
||||
$data = [
|
||||
'room_id' => $room_id,
|
||||
'user_id' => $user_id,
|
||||
'status' => 0,
|
||||
'apply_type' => 1
|
||||
];
|
||||
$reslut = db::name('vs_room_pit_apply')->insert($data);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '申请失败', 'data' => null];
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '申请成功,请等待房主审核', 'data' => null];
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '申请成功,请等待房主审核', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,15 +361,6 @@ class RoomPit extends Model
|
||||
'a.status' => 0,
|
||||
];
|
||||
|
||||
// $res = model('Room')->get_room_label($room_id);
|
||||
// $room_label = $res['data']['label_id'];
|
||||
// $room_type = $res['data']['type_id'];
|
||||
// if($room_label == 1 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $where['a.apply_type'] = 1;
|
||||
// }elseif ($room_label == 2 && ($room_type == 1 || $room_type == 3 || $room_type == 4)){
|
||||
// $where['a.apply_type'] = 2;
|
||||
// }
|
||||
|
||||
$list['regular'] = db::name('vs_room_pit_apply')->alias('a')->join('user b','a.user_id = b.id')
|
||||
->where($where)->where('a.type',0)->field('a.user_id,a.rank_value,b.nickname,b.avatar')
|
||||
->order('a.rank_value desc')->select();
|
||||
@@ -432,6 +469,8 @@ class RoomPit extends Model
|
||||
$apply_type = 2;//K歌
|
||||
}elseif($room_type == 2){
|
||||
$apply_type = 3;//拍卖
|
||||
}elseif($room_type == 7){
|
||||
$apply_type = 7;//交友
|
||||
}else{
|
||||
$apply_type = 1;//聊天
|
||||
}
|
||||
@@ -469,7 +508,7 @@ class RoomPit extends Model
|
||||
continue;
|
||||
}
|
||||
//删除他的申请上麦
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0,'apply_type' => 1])->delete();
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete();
|
||||
if (!$reslut) {
|
||||
continue;
|
||||
}
|
||||
@@ -499,7 +538,7 @@ class RoomPit extends Model
|
||||
break;
|
||||
}
|
||||
//删除他的申请上麦
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0,'apply_type' => 2])->delete();
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete();
|
||||
if (!$reslut) {
|
||||
continue;
|
||||
}
|
||||
@@ -534,14 +573,30 @@ class RoomPit extends Model
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}elseif($apply_type == 3){
|
||||
$i = 0;
|
||||
foreach ($to_user as &$value) {
|
||||
$i++;
|
||||
if(count($to_user) >= 2){
|
||||
return ['code' => 0, 'msg' => '拍卖模式下只能一个人上麦', 'data' => null];
|
||||
}
|
||||
//拍卖房当前到哪一步了
|
||||
$step = db::name('vs_room_auction')->where(['room_id' => $room_id])->order('auction_id desc')->value('status');
|
||||
if($step == 2){
|
||||
return ['code' => 0, 'msg' => '拍卖已经开始', 'data' => null];
|
||||
}
|
||||
//拍卖位上有人吗
|
||||
$paimai_user = Cache::get('auction_user_'.$room_id);
|
||||
if($paimai_user){
|
||||
//有人就让他下麦
|
||||
return ['code' => 0, 'msg' => '拍卖位上已有人,请先抱对方下麦', 'data' => null];
|
||||
}
|
||||
// $i = 0;
|
||||
// foreach ($to_user as &$value) {
|
||||
// $i++;
|
||||
$value = $to_user[0];
|
||||
//删除他的申请上麦
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete();
|
||||
if (!$reslut) {
|
||||
continue;
|
||||
}
|
||||
// if (!$reslut) {
|
||||
// continue;
|
||||
// }
|
||||
Cache::set('auction_user_'.$room_id,$value);
|
||||
//聊天室推送系统消息
|
||||
$FromUserInfo = db::name('user')->where('id',$value)->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($value);//财富图标
|
||||
@@ -552,13 +607,13 @@ class RoomPit extends Model
|
||||
$text['pit_number'] = 888;
|
||||
$text['type'] = 1 ;
|
||||
model('Chat')->sendMsg(1022,$room_id,$text);
|
||||
Cache::set('auction_user_'.$room_id,$value);
|
||||
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($user_id,$room_id,8,$value);
|
||||
if($i >= 1){
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if($i >= 1){
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息
|
||||
$text = [
|
||||
@@ -567,6 +622,41 @@ class RoomPit extends Model
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => '上麦成功', 'data' => null];
|
||||
}elseif($apply_type == 7) {
|
||||
$i = 0;
|
||||
foreach ($to_user as &$value) {
|
||||
//查询当前空麦位
|
||||
$empty_pit = $this->getRoomNullPitWithout($room_id, [7,8,9,10]);
|
||||
if (!$empty_pit) {
|
||||
//退出循环 并终止循环
|
||||
break;
|
||||
}
|
||||
//查询是否已经上麦
|
||||
$is_on_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'user_id' => $value])->field('id')->find();
|
||||
if ($is_on_pit) {
|
||||
continue;
|
||||
}
|
||||
//删除他的申请上麦
|
||||
$reslut = db::name('vs_room_pit_apply')->where(['user_id' => $value, 'room_id' => $room_id, 'status' => 0])->delete();
|
||||
if (!$reslut) {
|
||||
continue;
|
||||
}
|
||||
$on = $this->OnPit($value, $room_id, $empty_pit);//用户上了这个房间的几号麦位
|
||||
if ($on['code'] != 1) {
|
||||
continue;
|
||||
}
|
||||
$i++;
|
||||
//1-禁麦位,2-清空消息,3-清空魅力值,4-加入黑名单,5-踢出房间,6-关闭麦克风,7-申请上麦,8-同意上麦,9-拒绝上麦,10-点歌,11-开启PK',
|
||||
model('Room')->room_operation_record($user_id,$room_id,8,$value,$empty_pit);
|
||||
}
|
||||
$count = db::name('vs_room_pit_apply')->where(['room_id' => $room_id,'status' => 0])->count();
|
||||
//申请上麦推送消息(数据重置)
|
||||
$text = [
|
||||
'text' => '申请上麦',
|
||||
'count' => $count
|
||||
];
|
||||
model('Chat')->sendMsg(1034,$room_id,$text);
|
||||
return ['code' => 1, 'msg' => $i . '位用户上麦成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
return ['code' => 0, 'msg' => '请选择申请上麦的用户', 'data' => null];
|
||||
@@ -724,10 +814,19 @@ class RoomPit extends Model
|
||||
}
|
||||
|
||||
if($type == 1){//抱麦
|
||||
$on_9_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
|
||||
if($on_9_pit <= 0){
|
||||
return ['code' => 0, 'msg' => '您暂未上主持麦位,请先上麦', 'data' => null];
|
||||
if($pit_number == 10){
|
||||
$on_9_pit = db::name('vs_room_pit')->where(['room_id' => $room_id, 'pit_number' => 9])->value('user_id');
|
||||
if($on_9_pit != $user_id){
|
||||
return ['code' => 0, 'msg' => '请等待麦上主持抱麦', 'data' => null];
|
||||
}
|
||||
}
|
||||
//房主
|
||||
$owner = db::name('vs_room')->where(['id' => $room_id, 'user_id' => $user_id])->field('id')->find();
|
||||
$host = db::name('vs_room_host')->where(['room_id' => $room_id, 'user_id' => $user_id,'delete_time' => null])->find();
|
||||
if(!$owner && !$host){
|
||||
return ['code' => 0, 'msg' => '没有权限操作', 'data' => null];
|
||||
}
|
||||
|
||||
if(!$pit_number){
|
||||
$room_type = db::name('vs_room')->where(['id' => $room_id])->value('type_id');
|
||||
if($room_type == 2){
|
||||
@@ -812,7 +911,7 @@ class RoomPit extends Model
|
||||
|
||||
if(!$pit_number || $pit_number == 888){
|
||||
$roomInfo = db::name('vs_room')->where('id',$room_id)->field('label_id,type_id')->find();
|
||||
if($roomInfo['type_id'] == 2){//拍卖
|
||||
if($roomInfo['type_id'] == 2 || Cache::get('auction_user_'.$room_id)){//拍卖
|
||||
//查询当前是否处于拍卖中
|
||||
$auctioning = db::name('vs_room_auction')
|
||||
->where(['room_id' => $room_id, 'status' => 2, 'user_id' => $accept_user_id])->find();
|
||||
@@ -842,6 +941,10 @@ class RoomPit extends Model
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$step = db::name('vs_room')->where(['id' => $room_id, 'type_id' => 7])->value('step');
|
||||
if($step && $step != 1 && $pit_number < 9){
|
||||
return ['code' => 0, 'msg' => '交友房 此阶段不可操作', 'data' => null];
|
||||
}
|
||||
$where['room_id'] = $room_id;
|
||||
$where['pit_number'] = $pit_number;
|
||||
$where['user_id'] = $accept_user_id;
|
||||
|
||||
@@ -285,9 +285,14 @@ class RoomSong extends Model
|
||||
|
||||
|
||||
//上移歌 $type 1上移 2置顶
|
||||
public function up_song($room_song_id,$type=1){
|
||||
public function up_song($user_id,$room_song_id,$type=1){
|
||||
//查询当前数据的信息
|
||||
$sort = db::name('vs_room_song')->where('did',$room_song_id)->field('room_id,sort,times')->find();
|
||||
//查询当前用户是否是在9号麦的主持
|
||||
$is_host = db::name('vs_room_pit')->where(['user_id' => $user_id,'room_id' => $sort['room_id'],'pit_number' =>9])->find();
|
||||
if(!$is_host){
|
||||
return ['code'=>0,'msg'=>'您没有权限操作','data'=>null];
|
||||
}
|
||||
//根据房间ID查询当前房间中正在排序的歌曲 并获取当前排序的前一位的ID
|
||||
$sort_up = db::name('vs_room_song')->where(['room_id' => $sort['room_id'],'status' => 1,'times' =>$sort['times'],'times_status' => 1])->field('did')->order('sort desc')->select();
|
||||
if($sort_up[0]['did'] == $room_song_id){
|
||||
|
||||
@@ -20,23 +20,55 @@ class Sms extends Model
|
||||
if (!checkMobile($mobile)) {
|
||||
return ['code' => 0, 'msg' => '手机号不正确','data' =>null];
|
||||
}
|
||||
|
||||
//今天验证码错误次数
|
||||
$sms_count = db::name('sms_error')->where(['mobile' => $mobile,'createtime' => ['between', [strtotime(date('Y-m-d')), time()]]])->count();
|
||||
if ($sms_count >= 5) {
|
||||
$user_id = db::name('user')->where('mobile', $mobile)->value('id');
|
||||
$block_num = db::name('block')->where(['type' => 1, 'type_text' => $user_id])->find();
|
||||
if(!$block_num){
|
||||
//封禁账号
|
||||
$error_data = [
|
||||
'type' => 1,
|
||||
'type_text' => $user_id,
|
||||
'block_time' => time() + 60 * 60 * 24,
|
||||
'block_note' => '账号登录异常被封禁24小时',
|
||||
'createtime'=> time(),
|
||||
];
|
||||
db::name('block')->insert($error_data);
|
||||
db::name('user')->where('id', $user_id)->update(['status' => 2]);
|
||||
}
|
||||
|
||||
return ['code' => 0, 'msg' => '验证码错误次数过多,账号已被封禁,请联系管理员处理','data' =>null];
|
||||
}
|
||||
|
||||
$is_code = db::name('sms')->where(['mobile' => $mobile, 'event' => $type])->order('id desc')->find();
|
||||
if ($is_code && $is_code['code'] == $code) {
|
||||
//验证码正确
|
||||
if($type == 1 || $type == 2){
|
||||
//查询手机号绑定的数量
|
||||
$map = [];
|
||||
$map[] = ['mobile', '=', $mobile];
|
||||
$map[] = ['status', '=', 1];
|
||||
$map['mobile'] = $mobile;
|
||||
$map['status'] = 1;
|
||||
$user_info = db::name('user')->where($map)->count();
|
||||
if($user_info >= 4){
|
||||
return ['code' => 0, 'msg' => '该手机号已达绑定上线','data' =>null];
|
||||
}
|
||||
}
|
||||
db::name('sms')->where(['mobile' => $mobile, 'event' => $type])->delete();
|
||||
//登陆成功后 把所有的登录错误删除掉
|
||||
db::name('sms_error')->where(['mobile' => $mobile])->delete();
|
||||
return ['code' =>1, 'msg' =>'验证码正确','data' =>null];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '验证码错误','data' =>null];
|
||||
//验证码错误次数
|
||||
$count_sms = max(5 - $sms_count, 0);
|
||||
$data = [
|
||||
'mobile' => $mobile,
|
||||
'sms' => $code,
|
||||
'createtime'=> time(),
|
||||
];
|
||||
db::name('sms_error')->insert($data);
|
||||
return ['code' => 0, 'msg' => '验证码错误,'.$count_sms.'次后账号将被封禁24小时','data' =>null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ use fast\Http;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
use fast\Tencentst;
|
||||
|
||||
class Tencent extends Model
|
||||
@@ -154,7 +153,7 @@ class Tencent extends Model
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("腾讯用户拉入黑名单".json_encode($reslut),"infos");
|
||||
// Log::record("腾讯用户拉入黑名单".json_encode($reslut),"infos");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 200, 'msg' => '添加成功', 'data' => null];
|
||||
}else{
|
||||
@@ -206,7 +205,7 @@ class Tencent extends Model
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("腾讯群内系统消息发送结果".json_encode($reslut),"info");
|
||||
// Log::record("腾讯群内系统消息发送结果".json_encode($reslut),"info");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '发送成功', 'data' => $reslut];
|
||||
}else{
|
||||
@@ -242,9 +241,9 @@ class Tencent extends Model
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("广播消息信息".json_encode($reslut),"info");
|
||||
Log::record("广播消息信息3".json_encode($admin_sig),"info");
|
||||
Log::record("广播消息信息2".$admin_sig,"info");
|
||||
// Log::record("广播消息信息".json_encode($reslut),"info");
|
||||
// Log::record("广播消息信息3".json_encode($admin_sig),"info");
|
||||
// Log::record("广播消息信息2".$admin_sig,"info");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '发送成功', 'data' => $reslut];
|
||||
}else{
|
||||
@@ -365,7 +364,7 @@ class Tencent extends Model
|
||||
);
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("腾讯群内删除成员结果".json_encode($reslut),"info");
|
||||
// Log::record("腾讯群内删除成员结果".json_encode($reslut),"info");
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}else{
|
||||
@@ -420,11 +419,11 @@ class Tencent extends Model
|
||||
if($OnlineOnlyFlag == 1){
|
||||
$curlPost['OnlineOnlyFlag'] = 1;
|
||||
}
|
||||
Log::record("xitong消息信息1:".$admin_sig,"info");
|
||||
// Log::record("xitong消息信息1:".$admin_sig,"info");
|
||||
$curlPost = json_encode($curlPost);
|
||||
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
Log::record("xitong消息信息2:".$reslut,"info");
|
||||
// Log::record("xitong消息信息2:".$reslut,"info");
|
||||
return $reslut;
|
||||
}
|
||||
|
||||
@@ -726,6 +725,35 @@ class Tencent extends Model
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//修改用户信息
|
||||
public function modify_user_infos($member_id, $member_name = '', $member_face_url = '')
|
||||
{
|
||||
$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/profile/portrait_set?sdkappid='.$tencentyun_im_appid.'&identifier='.$im_admin.'&usersig='.$admin_sig.'&random='.$rand.'&contenttype=json';
|
||||
$curlPost['From_Account'] = 'u'.$member_id;
|
||||
$curlPost['ProfileItem'] = [
|
||||
[
|
||||
'Tag' => 'Tag_Profile_IM_Nick',
|
||||
'Value' => $member_name
|
||||
],
|
||||
[
|
||||
'Tag' => 'Tag_Profile_IM_Image',
|
||||
'Value' => $member_face_url
|
||||
]
|
||||
];
|
||||
$curlPost = json_encode($curlPost);
|
||||
$reslut = $this->tencent_post_url($postUrl, $curlPost);
|
||||
if($reslut['ActionStatus'] == 'OK'){
|
||||
return ['code' => 1, 'msg' => '操作成功', 'data' => null];
|
||||
}else{
|
||||
return ['code' => 0, 'msg' => $reslut['ErrorCode'], 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
//====新写的↓=====上面的 能用则用=============================================================================================================
|
||||
|
||||
@@ -810,7 +838,13 @@ class Tencent extends Model
|
||||
|
||||
// 处理响应
|
||||
if ($httpCode == 200) {
|
||||
return json_decode($response, true)['result']['faceId'];
|
||||
$red = json_decode($response, true);
|
||||
if ($red['code'] == 0) {
|
||||
return $red['result']['faceId'];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => $red['msg'], 'data' => null];
|
||||
}
|
||||
// return json_decode($response, true)['result']['faceId'];
|
||||
} else {
|
||||
return ['code' => $httpCode, 'msg' => '接口请求失败'];
|
||||
}
|
||||
@@ -858,5 +892,188 @@ class Tencent extends Model
|
||||
}
|
||||
}
|
||||
|
||||
//腾讯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'] == 'State.StateChange'){
|
||||
$info = $data['Info'];
|
||||
$reslut = $this->tencent_member_status_change($info);
|
||||
}
|
||||
return ['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0];
|
||||
}
|
||||
|
||||
//腾讯IM监控在线状态更新
|
||||
public function tencent_member_status_changeee($info){
|
||||
$uid = substr($info['To_Account'],1);
|
||||
$action = $info['Action'];
|
||||
|
||||
if($action == 'Disconnect') {
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 0, 'updatetime' => time()]);
|
||||
$quit_room = Db::name('vs_room_visitor')->where('user_id', $uid)->select();
|
||||
Log::record("腾讯离线推送,房间信息".json_encode($quit_room),"infos");
|
||||
if($quit_room) {
|
||||
foreach ($quit_room as &$v){
|
||||
if(isset($v['room_id'])){
|
||||
$room_type = db::name('vs_room')->where(['id' => $v['room_id']])->field('step,type_id,label_id')->find();
|
||||
Log::record("腾讯离线推送,房间类型".json_encode($room_type),"infos");
|
||||
if($room_type['label_id'] == 1 && ($room_type['type_id'] == 1 || $room_type['type_id'] == 8)){
|
||||
Log::record("腾讯离线推送,我是二卡八","infos");
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 1, 'updatetime' => time()]);
|
||||
}else{
|
||||
if(isset($room_type) && ($room_type['type_id'] == 7 && ($room_type['step'] == 2 ||$room_type['step'] == 3)) || $room_type == 2){
|
||||
$text['text'] = '掉线!';
|
||||
$text['user_id'] = $uid;
|
||||
$text['type'] = 2;
|
||||
model('Chat')->sendMsg(1058,$v['room_id'],$text);
|
||||
}else {
|
||||
//查询是否有切后台的操作
|
||||
$bg_room = db::name('vs_user_in_room_bg')->where(['room_id' => $v['room_id'],'user_id' => $v['user_id']])->find();
|
||||
if(!$bg_room){
|
||||
Log::record("腾讯离线推送,要踢你","infos");
|
||||
model('Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$room_type = null;
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($action == 'Login') {
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 1, 'updatetime' => time()]);
|
||||
$room = Db::name('vs_room_visitor')->where('user_id', $uid)->order('id desc')->value('room_id');
|
||||
|
||||
$text['text'] = '重新上线!';
|
||||
$text['user_id'] = $uid;
|
||||
$text['type'] = 1;
|
||||
model('Chat')->sendMsg(1058,$room,$text);
|
||||
}elseif ($action == 'Logout'){
|
||||
// Db::name('user')->where('id', $uid)->update(['is_online' => 0, 'updatetime' => time()]);
|
||||
// $room = Db::name('vs_room_visitor')->where('user_id', $uid)->order('id desc')->value('room_id');
|
||||
// $text['text'] = '掉线!';
|
||||
// $text['user_id'] = $uid;
|
||||
// $text['type'] = 2;
|
||||
// model('Chat')->sendMsg(1058,$room,$text);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//腾讯IM监控在线状态更新
|
||||
public function tencent_member_status_change($info){
|
||||
$uid = substr($info['To_Account'],1);
|
||||
$action = $info['Action'];
|
||||
|
||||
if($action == 'Disconnect') {
|
||||
$is_keep = 1;
|
||||
$keep = db::name('vs_xintiao')->where('user_id' , $uid)->find();
|
||||
if(isset($keep)){
|
||||
if(time() - $keep['updatetime'] >= 60){
|
||||
$is_keep = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//判断保活用户是否安卓用户
|
||||
$user_system = db::name('user')->where('id' , $uid)->value('system');
|
||||
if($user_system == 'android'){
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 0, 'updatetime' => time()]);
|
||||
$quit_room = Db::name('vs_room_visitor')->where('user_id', $uid)->select();
|
||||
Log::record("腾讯离线推送,用户安卓所在房间信息".json_encode($quit_room),"infos");
|
||||
if($quit_room) {
|
||||
foreach ($quit_room as &$v){
|
||||
if(isset($v['room_id'])){
|
||||
$room_type = db::name('vs_room')->where(['id' => $v['room_id']])->field('step,type_id,label_id')->find();
|
||||
// Log::record("腾讯离线推送,房间类型".json_encode($room_type),"infos");
|
||||
if($room_type['label_id'] == 1 && ($room_type['type_id'] == 1 || $room_type['type_id'] == 8)){
|
||||
// Log::record("腾讯离线推送,我是二卡八","infos");
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 1, 'updatetime' => time()]);
|
||||
}else{
|
||||
if(isset($room_type) && ($room_type['type_id'] == 7 && ($room_type['step'] == 2 ||$room_type['step'] == 3)) || $room_type == 2){
|
||||
$text['text'] = '掉线!';
|
||||
$text['user_id'] = $uid;
|
||||
$text['type'] = 2;
|
||||
model('Chat')->sendMsg(1058,$v['room_id'],$text);
|
||||
}else {
|
||||
//查询是否有切后台的操作
|
||||
// $bg_room = db::name('vs_user_in_room_bg')->where(['room_id' => $v['room_id'],'user_id' => $v['user_id']])->find();
|
||||
// if(!$bg_room){
|
||||
// // Log::record("腾讯离线推送,要踢你","infos");
|
||||
// model('Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2);
|
||||
// }
|
||||
Log::record("腾讯离线推送,判断心跳".$is_keep,"infos");
|
||||
if($is_keep == 0){
|
||||
model('Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$room_type = null;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 0, 'updatetime' => time()]);
|
||||
$quit_room = Db::name('vs_room_visitor')->where('user_id', $uid)->select();
|
||||
// Log::record("腾讯离线推送,房间信息".json_encode($quit_room),"infos");
|
||||
if($quit_room) {
|
||||
foreach ($quit_room as &$v){
|
||||
if(isset($v['room_id'])){
|
||||
$room_type = db::name('vs_room')->where(['id' => $v['room_id']])->field('step,type_id,label_id')->find();
|
||||
// Log::record("腾讯离线推送,房间类型".json_encode($room_type),"infos");
|
||||
if($room_type['label_id'] == 1 && ($room_type['type_id'] == 1 || $room_type['type_id'] == 8)){
|
||||
// Log::record("腾讯离线推送,我是二卡八","infos");
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 1, 'updatetime' => time()]);
|
||||
}else{
|
||||
if(isset($room_type) && ($room_type['type_id'] == 7 && ($room_type['step'] == 2 ||$room_type['step'] == 3)) || $room_type == 2){
|
||||
$text['text'] = '掉线!';
|
||||
$text['user_id'] = $uid;
|
||||
$text['type'] = 2;
|
||||
model('Chat')->sendMsg(1058,$v['room_id'],$text);
|
||||
}else {
|
||||
//查询是否有切后台的操作
|
||||
$bg_room = db::name('vs_user_in_room_bg')->where(['room_id' => $v['room_id'],'user_id' => $v['user_id']])->find();
|
||||
if(!$bg_room){
|
||||
// Log::record("腾讯离线推送,要踢你","infos");
|
||||
model('Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$room_type = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} elseif ($action == 'Login') {
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 1, 'updatetime' => time()]);
|
||||
$room = Db::name('vs_room_visitor')->where('user_id', $uid)->order('id desc')->value('room_id');
|
||||
|
||||
$text['text'] = '重新上线!';
|
||||
$text['user_id'] = $uid;
|
||||
$text['type'] = 1;
|
||||
model('Chat')->sendMsg(1058,$room,$text);
|
||||
}elseif ($action == 'Logout'){
|
||||
// Db::name('user')->where('id', $uid)->update(['is_online' => 0, 'updatetime' => time()]);
|
||||
// $room = Db::name('vs_room_visitor')->where('user_id', $uid)->order('id desc')->value('room_id');
|
||||
// $text['text'] = '掉线!';
|
||||
// $text['user_id'] = $uid;
|
||||
// $text['type'] = 2;
|
||||
// model('Chat')->sendMsg(1058,$room,$text);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class Topic extends Model
|
||||
if($list){
|
||||
foreach ($list as &$item){
|
||||
$item['content'] = $this->where(['id'=>$item['topic_id']])->value('content');
|
||||
$item['pic'] = $this->where(['id'=>$item['topic_id']])->value('pic');
|
||||
$item['pic'] = $this->where(['id'=>$item['topic_id']])->value('pic') ?? get_system_config_value('web_site').'/data/avatar/head_pic.png';;
|
||||
$item['title'] = $this->where(['id'=>$item['topic_id']])->value('title');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,17 @@ class User extends Model
|
||||
$user_info['dress'] = model('Decorate')->user_decorate_detail($user_info['user_id'],1);
|
||||
$user_info['auth'] = db::name('user_auth')->where(['mobile' => $user_info['mobile'],'is_real' => 1])->find() ? 1 : 0;
|
||||
|
||||
//是否可以发布动态
|
||||
$user_rechange = db::name('vs_user_recharge')->field('sum(money) as money')->where(['user_id' => $uid,'pay_status' => 2])->find();
|
||||
//系统配置
|
||||
$config_money = get_system_config_value('private_chat_recharge_money');
|
||||
if(($config_money > 0) && ($user_rechange['money'] < $config_money)){
|
||||
$user_info['is_can_chat'] = 0;
|
||||
}else{
|
||||
$user_info['is_can_chat'] = 1;
|
||||
}
|
||||
$user_info['can_chat_money'] = $config_money;
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $user_info];
|
||||
}
|
||||
|
||||
@@ -278,7 +289,7 @@ class User extends Model
|
||||
public function get_user_home($from_uid,$uid)
|
||||
{
|
||||
$user_info = db::name('user')->alias('u')->join('user_data ud', 'u.id = ud.user_id')
|
||||
->field('u.id as user_id,u.nickname,u.user_code,u.avatar,u.sex,u.birthday,u.profile,ud.tag_id,ud.home_bgimages')
|
||||
->field('u.id as user_id,u.nickname,u.user_code,u.avatar,u.sex,u.birthday,u.profile,ud.tag_id,ud.home_bgimages,u.is_online')
|
||||
->where(['u.id' => $uid,'u.status' => ['<>',0]])->find();
|
||||
if(!$user_info){
|
||||
return ['code' => 0, 'msg' => '用户不存在或已注销', 'data' => null];
|
||||
@@ -320,6 +331,14 @@ class User extends Model
|
||||
if($from_uid != $uid){
|
||||
$this->add_user_visit_log(1,$from_uid, $uid);
|
||||
}
|
||||
|
||||
//用户所属工会
|
||||
$guild_id = Db::name('vs_guild_user')->where(['user_id'=>$uid,'status'=>1,'delete_time'=>0])->value('guild_id');
|
||||
if($guild_id){
|
||||
$user_info['guild'] = Db::name('vs_guild')->where('id' ,$guild_id)->value('guild_name');
|
||||
}else{
|
||||
$user_info['guild'] = '';
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $user_info];
|
||||
}
|
||||
|
||||
@@ -331,10 +350,11 @@ class User extends Model
|
||||
public function get_user_gift_wall_info($uid)
|
||||
{
|
||||
//查询用户礼物墙 以gift_id,send_user_id分组 同一用户送的同一礼物相加
|
||||
$result = db::name('vs_give_gift')
|
||||
->where(['gift_user' => $uid])
|
||||
->field('gift_id,user_id,sum(number) as total')
|
||||
->group('gift_id,user_id')
|
||||
$result = db::name('vs_give_gift')->alias('a')
|
||||
->join('vs_gift g', 'a.gift_id = g.gid')
|
||||
->where(['a.gift_user' => $uid,'g.label'=>['<>',2]])
|
||||
->field('a.gift_id,a.user_id,sum(a.number) as total')
|
||||
->group('a.gift_id,a.user_id')
|
||||
->order('total desc')
|
||||
->select();
|
||||
// var_dump($result);exit;
|
||||
@@ -383,7 +403,7 @@ class User extends Model
|
||||
}
|
||||
$data = array_values($data);
|
||||
//查询所有的礼物
|
||||
$gift_list = db::name('vs_gift')->field('gid as gift_id,gift_name,base_image,gift_price')->where(['delete_time' => 0,'is_show' => 1])->select();
|
||||
$gift_list = db::name('vs_gift')->field('gid as gift_id,gift_name,base_image,gift_price')->where(['delete_time' => 0,'label'=>['<>',2]])->select();
|
||||
//对比去除$data 里面的礼物
|
||||
$gift_list = array_filter((array)$gift_list, function ($item) use ($data) {
|
||||
return !in_array($item['gift_id'], array_column($data, 'gift_id'));
|
||||
@@ -549,7 +569,7 @@ class User extends Model
|
||||
//移动相册图片
|
||||
public function move_album_images($user_id,$id,$album_id){
|
||||
if(empty($id)){
|
||||
return ['code' => 0, 'msg' => '强选择想要移动的图片', 'data' => null];
|
||||
return ['code' => 0, 'msg' => '请选择想要移动的图片', 'data' => null];
|
||||
}
|
||||
|
||||
if(empty($album_id)){
|
||||
@@ -653,7 +673,13 @@ class User extends Model
|
||||
if(!empty($nickname)){
|
||||
//名称中不能有 系统管理 等关键字
|
||||
if(!nickname_filter($nickname)){
|
||||
return ['code' => 0, 'msg' => '名称中不能有 系统管理 等相关字', 'data' => null];
|
||||
return ['code' => 0, 'msg' => '名称中不能有 系统、管理、官方 等相关字', 'data' => null];
|
||||
}
|
||||
$nick_name_info = db::name('user')->where(['nickname' => $nickname,'status' => ['<>',0]])->find();
|
||||
if(!empty($nick_name_info)){
|
||||
if($user_id != $nick_name_info['id']){
|
||||
return['code' => 0, 'msg' => '该昵称已被占用','data' =>null];
|
||||
}
|
||||
}
|
||||
$data['nickname'] = $nickname;
|
||||
}
|
||||
@@ -713,6 +739,12 @@ class User extends Model
|
||||
$text['text'] = '用户 ' . $text['FromUserInfo']['nickname'] .' 修改了信息';
|
||||
model('Chat')->sendMsg(1035,$room_id,$text,$user_id);
|
||||
}
|
||||
|
||||
//给腾讯同步用户信息
|
||||
$member_name = db::name('user')->where('id' , $user_id)->value('nickname');
|
||||
$member_face_url = db::name('user')->where('id' , $user_id)->value('avatar');
|
||||
model('Tencent')->modify_user_infos($user_id, $member_name, $member_face_url);
|
||||
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => null];
|
||||
}
|
||||
catch(\Exception $e){
|
||||
@@ -809,8 +841,41 @@ class User extends Model
|
||||
}
|
||||
|
||||
|
||||
//关注房间(红包专用)
|
||||
public function follow_room($user_id,$room_id,$type){
|
||||
if(empty($room_id)){
|
||||
return ['code' => 0, 'msg' => '房间ID不能为空', 'data' => null];
|
||||
}
|
||||
if($type == 0){
|
||||
//取消关注
|
||||
$re = db::name('user_follow')->where(['user_id' => $user_id,'follow_id' => $room_id,'type' => 2])->delete();
|
||||
if(!$re){
|
||||
return ['code' => 0, 'msg' => '取消关注失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '取消关注成功', 'data' => null];
|
||||
}else{
|
||||
//关注
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'follow_id' => $room_id,
|
||||
'type' => 2,
|
||||
'createtime' => time()
|
||||
];
|
||||
$re = db::name('user_follow')->insert($data);
|
||||
if(!$re){
|
||||
return ['code' => 0, 'msg' => '关注失败', 'data' => null];
|
||||
}
|
||||
return ['code' => 1, 'msg' => '关注成功', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//更新用户ip
|
||||
public function update_user_ip($user_id,$ip){
|
||||
//判断$ip是否是汉字
|
||||
if(preg_match('/[\x{4e00}-\x{9fa5}]+/u', $ip)){
|
||||
$ip = '未知';
|
||||
}
|
||||
$data = [
|
||||
'address_ip' => $ip
|
||||
];
|
||||
|
||||
@@ -49,7 +49,7 @@ class UserData extends Model
|
||||
$data['id'] = $uid;
|
||||
if (!empty($nick_name)) {
|
||||
$data['nickname'] = $nick_name;
|
||||
$nick_name_info = db::name('user')->where('nickname', $nick_name)->find();
|
||||
$nick_name_info = db::name('user')->where(['nickname' => $nick_name,'status' => ['<>',0]])->find();
|
||||
if(!empty($nick_name_info)){
|
||||
if($uid != $nick_name_info['id']){
|
||||
return['code' => 0, 'msg' => '该昵称已被占用','data' =>null];
|
||||
@@ -58,6 +58,10 @@ class UserData extends Model
|
||||
if(mb_strlen($nick_name) > 24){
|
||||
return['code' => 0, 'msg' => '昵称长度不能超过24个字符','data' =>null];
|
||||
}
|
||||
//名称中不能有 系统管理 等关键字
|
||||
if(!nickname_filter($nick_name)){
|
||||
return ['code' => 0, 'msg' => '名称中不能有 系统、管理、官方 等相关字', 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($birthday)) {
|
||||
@@ -82,7 +86,10 @@ class UserData extends Model
|
||||
$reslut = model('User')->update($data);
|
||||
if ($reslut) {
|
||||
$user_info = model('User')->where('id', $uid)->field('id,nickname,avatar,user_code')->find();
|
||||
|
||||
//给腾讯同步用户信息
|
||||
$member_name = $user_info['nickname'];
|
||||
$member_face_url = $user_info['avatar'];
|
||||
model('Tencent')->modify_user_infos($uid, $member_name, $member_face_url);
|
||||
return ['code' => 1, 'msg' => '修改成功', 'data' => $user_info];
|
||||
} else {
|
||||
return ['code' => 0, 'msg' => '修改失败,','data' =>null];
|
||||
@@ -130,8 +137,7 @@ class UserData extends Model
|
||||
$data['uid'] = $uid;
|
||||
if (!empty($nick_name)) {
|
||||
$data['nick_name'] = $nick_name;
|
||||
$data['base64_nick_name'] = base64_encode($nick_name);
|
||||
$nick_name_info = db::name('user')->where('base64_nick_name', $data['base64_nick_name'])->find();
|
||||
$nick_name_info = db::name('user')->where(['nickname' => $nick_name,'status' => ['<>',0]])->find();
|
||||
if(!empty($nick_name_info)){
|
||||
if($uid != $nick_name_info['uid']){
|
||||
return['code' => 0, 'msg' => '该昵称已被占用','data' =>null];
|
||||
@@ -251,8 +257,13 @@ class UserData extends Model
|
||||
//修改手机号
|
||||
public function modify_mobile($new_mobile,$user_id)
|
||||
{
|
||||
//查询新手机号绑定的数量
|
||||
$new_mobile_num = db::name('user')->where(['username' => $new_mobile,'status' => ['neq', 0]])->count();
|
||||
if ($new_mobile_num >= 3) {
|
||||
return ['code' => 0, 'msg' => '该手机号已达绑定上限','data' =>null];
|
||||
}
|
||||
//查询旧手机号
|
||||
$mobile = db::name('user')->where(['id' => $user_id])->value('user_name');
|
||||
$mobile = db::name('user')->where(['id' => $user_id])->value('username');
|
||||
//查询是否实名
|
||||
$is_real = db::name('user_auth')->where(['mobile' => $mobile,'is_real' => 1])->find();
|
||||
if($is_real){
|
||||
@@ -260,7 +271,7 @@ class UserData extends Model
|
||||
db::startTrans();
|
||||
//修改实名手机号
|
||||
$red = db::name('user_auth')->where(['id' => $is_real['id']])->update(['mobile' => $new_mobile]);
|
||||
$reslut = db::name('user')->where(['id' => $user_id])->update(['user_name' => $new_mobile]);
|
||||
$reslut = db::name('user')->where(['id' => $user_id])->update(['username' => $new_mobile,'mobile' => $new_mobile]);
|
||||
if ($reslut && $red) {
|
||||
Db::commit();
|
||||
return ['code' => 1, 'msg' => '修改成功','data' =>null];
|
||||
@@ -269,7 +280,7 @@ class UserData extends Model
|
||||
return ['code' => 0, 'msg' => '修改失败','data' =>null];
|
||||
}
|
||||
}else{
|
||||
$reslut = db::name('user')->where(['id' => $user_id])->update(['user_name' => $new_mobile]);
|
||||
$reslut = db::name('user')->where(['id' => $user_id])->update(['username' => $new_mobile,'mobile' => $new_mobile]);
|
||||
if ($reslut) {
|
||||
return ['code' => 1, 'msg' => '修改成功','data' =>null];
|
||||
}
|
||||
@@ -284,6 +295,16 @@ class UserData extends Model
|
||||
if(empty($user_mobile)){
|
||||
return ['code' => 0, 'msg' => '请先绑定手机号','data' =>null];
|
||||
}
|
||||
$card_id_count = db::name('user_auth')->where(['card_id' => $id_card,'is_real' => 1])->count();
|
||||
if($card_id_count >= 3){
|
||||
return ['code' => 0, 'msg' => '该身份证实名已达上限!','data' =>null];
|
||||
}
|
||||
//查询是否已经提交过数据了
|
||||
$is_real = db::name('user_auth')->where(['card_id' => $id_card,'is_real' => 1,'mobile' =>$user_mobile])->find();
|
||||
if($is_real){
|
||||
return ['code' => 0, 'msg' => '已经审核通过!请勿重复提交!','data' =>null];
|
||||
}
|
||||
|
||||
$auth = [
|
||||
'mobile' => $user_mobile,
|
||||
'real_name' => $real_name,
|
||||
@@ -318,6 +339,9 @@ class UserData extends Model
|
||||
$sign = model('Tencent')->getSign($user_id,$nonceStr,$sign_ticket,$config['tencent_app_id']);
|
||||
//生成faceId
|
||||
$faceId = model('Tencent')->getFaceId($orderNo,$real_name,$id_card,$sign,$user_id,$config['tencent_app_id'],$nonceStr);
|
||||
if(isset($faceId['code'])){
|
||||
return ['code' => 0, 'msg' => $faceId['msg'],'data' =>null];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'userid' => 'u'.$user_id,
|
||||
@@ -336,11 +360,21 @@ class UserData extends Model
|
||||
public function real_name_result($user_id,$orderNo)
|
||||
{
|
||||
$user_mobile = db::name('user')->where(['id' => $user_id,'status'=>1])->value('mobile');
|
||||
$id = db::name('user_auth')->where(['mobile' => $user_mobile,'is_real' => 3])->value('id');
|
||||
if($id){
|
||||
$res = db::name('user_auth')->where(['id' => ['<>',$id],'mobile' => $user_mobile])->select();
|
||||
if($res){
|
||||
foreach ($res as $key => $value) {
|
||||
db::name('user_auth')->where('id' , $value['id'])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
//修改状态
|
||||
$reslut = db::name('user_auth')->where('mobile' , $user_mobile)->update(['is_real' => 1]);
|
||||
$reslut = db::name('user_auth')->where('id' , $id)->update(['is_real' => 1]);
|
||||
if(!$reslut){
|
||||
return ['code' => 0, 'msg' => '实名失败','data' =>null];
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '实名成功','data' =>null];
|
||||
}
|
||||
|
||||
@@ -393,7 +427,7 @@ class UserData extends Model
|
||||
//房间历史足迹
|
||||
public function user_room_history_list($uid,$page,$page_limit){
|
||||
$list = db::name('user_visit_log')->alias('a')->join('fa_vs_room b','a.to_id = b.id')
|
||||
->field('b.id as room_id,b.room_number,b.room_name,b.room_cover,b.room_intro,b.label_id,b.room_password,b.is_show_room,b.hot_value')
|
||||
->field('b.id as room_id,b.room_number,b.room_name,b.room_cover,b.room_intro,b.label_id,b.room_password,b.is_show_room,b.today_hot_value as hot_value')
|
||||
->where('a.from_uid',$uid)
|
||||
->where('a.type',2)
|
||||
->where('b.type_id','<>',6)
|
||||
@@ -553,12 +587,23 @@ class UserData extends Model
|
||||
//绑定的详情
|
||||
public function bind_xinxi_detail($user_id,$type)
|
||||
{
|
||||
$data = null;
|
||||
if($type == 2){
|
||||
$data = db::name('user_data')->where('user_id',$user_id)->field('id,alipay_name,alipay_account')->find();
|
||||
}
|
||||
if($type == 3){
|
||||
$data = db::name('user_data')->where('user_id',$user_id)->field('id,bank_card_number,bank_user_name,bank_card,open_bank')->find();
|
||||
}
|
||||
if($data['bank_card_number']==0){
|
||||
$data['bank_card_number'] = '';
|
||||
}
|
||||
if($data['bank_card']==0){
|
||||
$data['bank_card'] = '';
|
||||
}
|
||||
if($data['open_bank']==0){
|
||||
$data['open_bank'] = '';
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '获取成功','data' =>$data];
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,12 @@ class UserGiftPack extends Model
|
||||
const FIRST_CHARGE = 6;
|
||||
//天降好礼
|
||||
const DRAW_GIFT = 7;
|
||||
//巡乐会抽奖所得
|
||||
const XLH_DRAW_GIFT_GET = 8;
|
||||
//小时榜获得
|
||||
const HOUR_RANK_GET = 9;
|
||||
//新人充值好礼
|
||||
const NEW_CHARGE_GIFT = 10;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
@@ -48,7 +54,10 @@ class UserGiftPack extends Model
|
||||
self::SYSTEM_DEDUCTION => '系统扣除',
|
||||
self::GIFT_USE => '礼物使用',
|
||||
self::FIRST_CHARGE => '首充获得',
|
||||
self::DRAW_GIFT => '天降好礼获得'
|
||||
self::DRAW_GIFT => '天降好礼获得',
|
||||
self::XLH_DRAW_GIFT_GET => '巡乐会抽奖所得',
|
||||
self::HOUR_RANK_GET => '小时榜获得',
|
||||
self::NEW_CHARGE_GIFT => '新人充值好礼'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -68,6 +77,25 @@ class UserGiftPack extends Model
|
||||
}
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $return_data];
|
||||
}
|
||||
|
||||
|
||||
//现有背包礼物总值
|
||||
public function get_gift_pack_list_count($uid)
|
||||
{
|
||||
$list = Db::name('vs_user_gift_pack')->alias('a')
|
||||
->join('fa_vs_gift b', 'a.gid = b.gid')
|
||||
->where(['a.user_id'=>$uid,'a.is_use_give'=>1,'a.num'=>['>',0]])
|
||||
->field('a.num,b.gift_price')
|
||||
->select();
|
||||
|
||||
$data = 0;
|
||||
foreach ($list as $v) {
|
||||
$data += $v['num'] * $v['gift_price'];
|
||||
}
|
||||
$count['count'] = $data;
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' =>$count ];
|
||||
}
|
||||
|
||||
//背包收入
|
||||
public function income_user_gift_pack($uid,$page=1,$page_limit=10)
|
||||
{
|
||||
@@ -76,7 +104,10 @@ class UserGiftPack extends Model
|
||||
self::GIFT_PACK_GET,
|
||||
// self::GIFT_SEND,
|
||||
self::FIRST_CHARGE,
|
||||
self::DRAW_GIFT
|
||||
self::DRAW_GIFT,
|
||||
self::XLH_DRAW_GIFT_GET
|
||||
,self::HOUR_RANK_GET
|
||||
,self::NEW_CHARGE_GIFT
|
||||
];
|
||||
//获取背包日志列表
|
||||
$log_model = Db::name('vs_user_gift_pack_log')->where(['user_id'=>$uid])->whereIn('type', $type)
|
||||
@@ -84,14 +115,14 @@ class UserGiftPack extends Model
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
if (empty($log_model)) {
|
||||
return ['code' => 0, 'msg' => '没有数据', 'data' => null];
|
||||
return ['code' => 0, 'msg' => ' ', 'data' => null];
|
||||
}
|
||||
$list = [];
|
||||
foreach ($log_model as $k => $v){
|
||||
$gift_info = db::name('vs_gift')->where(['gid'=>$v['gid']])->find();
|
||||
$list[$k]['remarks'] = $v['remarks'];
|
||||
$list[$k]['gift_num'] = $v['change_num'];
|
||||
$list[$k]['gift_name'] = "X".$v['change_num'].$gift_info['gift_name'];
|
||||
$list[$k]['gift_name'] = $gift_info['gift_name']." X ".$v['change_num'];
|
||||
$list[$k]['gift_image'] = $gift_info['play_image'];
|
||||
$list[$k]['time'] = date('Y-m-d H:i:s', $v['createtime']);
|
||||
}
|
||||
@@ -111,14 +142,14 @@ class UserGiftPack extends Model
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
if (empty($log_model)) {
|
||||
return ['code' => 0, 'msg' => '没有数据', 'data' => null];
|
||||
return ['code' => 0, 'msg' => ' ', 'data' => null];
|
||||
}
|
||||
$list = [];
|
||||
foreach ($log_model as $k => $v){
|
||||
$gift_info = db::name('vs_gift')->where(['gid'=>$v['gid']])->find();
|
||||
$list[$k]['remarks'] = $v['remarks'];
|
||||
$list[$k]['gift_num'] = $v['change_num'];
|
||||
$list[$k]['gift_name'] = "-".$v['change_num'].$gift_info['gift_name'];
|
||||
$list[$k]['gift_name'] = $gift_info['gift_name']." - ".$v['change_num'];
|
||||
$list[$k]['gift_image'] = $gift_info['play_image'];
|
||||
$list[$k]['time'] = date('Y-m-d H:i:s', $v['createtime']);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ class UserMessage extends Model
|
||||
|
||||
$system_no_read_count = $system_message - $user_read_message;
|
||||
$system_last_message = db::name('system_message')
|
||||
->field('id,type,title,content,url')
|
||||
->where('type', 1)//1系统消息 3公告下的房间推荐,4公告下的活动'
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->order('id desc')
|
||||
@@ -77,6 +78,7 @@ class UserMessage extends Model
|
||||
$announcement_read_count = count($system_message1) - count($user_read_message1);
|
||||
unset($map['user_id']);
|
||||
$announcement_last_message = db::name('system_message')
|
||||
->field('id,type,title,content,url')
|
||||
->where($map)
|
||||
->where('FIND_IN_SET(:user_id, receiving_id)', ['user_id' => $uid])
|
||||
->order('id desc')
|
||||
|
||||
@@ -10,14 +10,14 @@ class UserToken extends Model
|
||||
public function check_login_token($token)
|
||||
{
|
||||
if (empty($token)) {
|
||||
return ['code' => 301, 'msg' => '登录失效', 'data' =>null];
|
||||
return ['code' => 301, 'msg' => '登录失效!', 'data' =>null];
|
||||
}
|
||||
$user_token = $this->where('token', $token)->find();
|
||||
if (empty($user_token)) {
|
||||
return ['code' => 301, 'msg' => '登录失效', 'data' => null];
|
||||
return ['code' => 301, 'msg' => '登录失效!!', 'data' => null];
|
||||
}
|
||||
if ($user_token['expiretime'] < time()) {
|
||||
return ['code' => 301, 'msg'=> '登录失效', 'data' => null];
|
||||
return ['code' => 301, 'msg'=> '登录失效!!!', 'data' => null];
|
||||
}
|
||||
|
||||
$block1 = db::name('block')->where(['type' => 1,'type_text' => $user_token['user_id']])->find();
|
||||
|
||||
@@ -50,17 +50,18 @@ class UserWallet extends Model
|
||||
// 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
|
||||
// 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
|
||||
// 15.首充 16.天降好礼充值 17.退出工会扣款 18.房主收益 19.主持人收益,20.发布头条扣除余额,21.公会长收益,22.提现驳回或提现失败返还,23.财富等级奖励金币领取,24.删除关系扣金币
|
||||
//27.小时榜获得,28-新人充值好礼,32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) 33-红包剩余退回(金币),34-红包剩余退回(钻石)
|
||||
if($gift_type == 1){ //1金币,2收益(钻石)
|
||||
if($in_out_type == 1){//1收入
|
||||
$in_out_types = [2,5,6,8,13,14,15,16,22,23,26];
|
||||
$in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27,30,28,33];
|
||||
}elseif($in_out_type == 2){//2支出
|
||||
$in_out_types = [4,7,10,17,20,24,25];
|
||||
$in_out_types = [4,7,10,17,20,24,25,32];
|
||||
}
|
||||
}elseif($gift_type == 2){ //1金币,2收益(钻石)
|
||||
if($in_out_type == 1){//1收入
|
||||
$in_out_types = [6,9,11,12,18,19,21];
|
||||
$in_out_types = [6,9,11,12,18,19,21,22,31,28,34];
|
||||
}elseif($in_out_type == 2){//2支出
|
||||
$in_out_types = [3,14];
|
||||
$in_out_types = [3,14,29];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,10 +107,11 @@ class UserWallet extends Model
|
||||
return ['code' => 0, 'msg' => '钻石数量不足', 'data' => null];
|
||||
}
|
||||
|
||||
$ear_exchange_coin = get_system_config_value('coin_exchange_rate');
|
||||
$data = [
|
||||
'user_id' => $uid,
|
||||
'earnings_num' => $earnings_num,
|
||||
'coin_num' => $earnings_num * 10,
|
||||
'coin_num' => $earnings_num * $ear_exchange_coin,
|
||||
'createtime' => time(),
|
||||
];
|
||||
//开启事务
|
||||
@@ -130,7 +132,7 @@ class UserWallet extends Model
|
||||
$account_log[] = [
|
||||
'user_id' => $uid,
|
||||
'money_type' => 1,
|
||||
'change_value' => $earnings_num * 10,
|
||||
'change_value' => $earnings_num * $ear_exchange_coin,
|
||||
'remarks' => '收益兑换',
|
||||
'change_type' => 14,
|
||||
'createtime' => time(),
|
||||
@@ -138,7 +140,7 @@ class UserWallet extends Model
|
||||
];
|
||||
$re = db::name('vs_user_money_log')->insertAll($account_log);
|
||||
$re1 = db::name('user_wallet')->where('user_id',$uid)->setDec('earnings',$earnings_num);
|
||||
$re2 = db::name('user_wallet')->where('user_id',$uid)->setInc('coin',$earnings_num * 10);
|
||||
$re2 = db::name('user_wallet')->where('user_id',$uid)->setInc('coin',$earnings_num * $ear_exchange_coin);
|
||||
if($re && $re1 && $re2){
|
||||
db::commit();
|
||||
return ['code' => 1, 'msg' => '兑换成功', 'data' => null];
|
||||
|
||||
@@ -43,6 +43,13 @@ class UserWithdrawal extends Model
|
||||
if(!$age){
|
||||
return ['code' => 0, 'msg' => '该身份证号未满18岁', 'data' => null];
|
||||
}
|
||||
if(empty($type)){
|
||||
return ['code' => 0, 'msg' => '请选择提现方式', 'data' => null];
|
||||
}
|
||||
//提现不能有小数
|
||||
if($number != floor($number)){
|
||||
return ['code' => 0, 'msg' => '提现不能有小数!', 'data' => null];
|
||||
}
|
||||
//判断用户是否签约云账户
|
||||
$yun_pay = new YunPay();
|
||||
$sign_status = $yun_pay->getApiUserSignStatus($user_info['real_name'],$user_info['card_id']);
|
||||
@@ -192,10 +199,10 @@ class UserWithdrawal extends Model
|
||||
$where['createtime'] = ['>=',strtotime($search_stime)];
|
||||
}
|
||||
if($search_etime){
|
||||
$where['createtime'] = ['<=',strtotime($search_etime.' 23:59:59')];
|
||||
$where['createtime'] = ['<=',strtotime($search_etime)];
|
||||
}
|
||||
if(!empty($search_stime) && !empty($search_etime)){
|
||||
$where['createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime.' 23:59:59')]];
|
||||
$where['createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime)]];
|
||||
}
|
||||
$withdraw_list = db::name('vs_user_withdrawal')
|
||||
->where($where)
|
||||
@@ -207,6 +214,26 @@ class UserWithdrawal extends Model
|
||||
$return_data[$key]['money'] = $value['money'];
|
||||
$return_data[$key]['status'] = $value['status'];
|
||||
$return_data[$key]['status_str'] = $this->withdraw_status[$value['status']];
|
||||
//手续费
|
||||
$return_data[$key]['withdraw_fee'] = $value['server_money'] ?? 0;
|
||||
$return_data[$key]['personal_tax_rate'] = $value['personal_tax_rate'] ?? 0; //税率
|
||||
$return_data[$key]['received_tax_amount'] = $value['received_tax_amount'] ?? 0; //税费
|
||||
//预计到账金额
|
||||
//1待处理2已通过3已拒绝 4打款中[云账户]5打款失败[云账户]6已打款[云账户]
|
||||
if($value['status'] == 1 || $value['status'] == 2 || $value['status'] ==4){
|
||||
$surplus_money = $value['money'] - $value['server_money'];
|
||||
$return_data[$key]['received_tax_amount'] = 0;
|
||||
}elseif($value['status'] == 3 || $value['status'] ==5){
|
||||
$surplus_money = $value['money'];
|
||||
$return_data[$key]['withdraw_fee'] = 0;
|
||||
$return_data[$key]['received_tax_amount'] = 0;
|
||||
}elseif($value['status'] == 6){
|
||||
$surplus_money = $value['money'] - $value['server_money'] - $value['received_tax_amount'];
|
||||
}else{
|
||||
$surplus_money = $value['money'];
|
||||
}
|
||||
$return_data[$key]['surplus_money'] = round($surplus_money,2);
|
||||
|
||||
$return_data[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $return_data];
|
||||
|
||||
@@ -122,7 +122,7 @@ class UserZone extends Model
|
||||
//查询房主此时是否在聊天室
|
||||
$room_id = db::name('vs_room_visitor')->where(['user_id' => $v['user_id'], 'is_delete' => 1])->value('room_id');
|
||||
if ($room_id) {
|
||||
$room = db::name('vs_room')->where(['id' => $room_id, 'room_status' => 1])->field('id,room_name,room_number,room_cover,room_intro,hot_value,type_id')->find();
|
||||
$room = db::name('vs_room')->where(['id' => $room_id, 'room_status' => 1])->field('id,room_name,room_number,room_cover,room_intro,today_hot_value as hot_value,type_id')->find();
|
||||
$v['room_id'] = $room['id'];
|
||||
$v['room_cover'] = $room['room_cover'];
|
||||
$v['room_type'] = db::name('vs_room_type')->where(['id' => $room['type_id'], 'status' => 1])->field('type_name');
|
||||
@@ -301,13 +301,13 @@ class UserZone extends Model
|
||||
return ['code' => 0, 'msg' => '请重试,', 'data' => null];
|
||||
}
|
||||
//评论別人的帖子- 每天第一条奖励【完成任务】
|
||||
if($info['user_id'] != $uid){
|
||||
// if($info['user_id'] != $uid){
|
||||
//今天的第一条评论奖励
|
||||
$first_comment = db::name('user_zone_comment')->where(['user_id' => $uid, 'createtime' => ['between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]])->count();
|
||||
if ($first_comment ==1) {
|
||||
model('DailyTasks')->tasks_complete($uid,5);
|
||||
}
|
||||
}
|
||||
// }
|
||||
//增加评论数量
|
||||
$reslut = db::name('user_zone')->where('id', $zid)->setInc('comment_num', 1);
|
||||
if (!$reslut) {
|
||||
@@ -548,6 +548,12 @@ class UserZone extends Model
|
||||
$data['is_delete'] = 2;
|
||||
$data['delete_time'] = time();
|
||||
$reslut = db::name('user_zone')->where('id', $zid)->update($data);
|
||||
$top_zone = db::name('user_zone_topic')->where('zone_id',$zid)->select();
|
||||
if($top_zone){
|
||||
foreach ($top_zone as $v){
|
||||
db::name('user_zone_topic')->where('id',$v['id'])->delete();
|
||||
}
|
||||
}
|
||||
if ($reslut) {
|
||||
return ['code' => 1, 'msg' => '删除成功', 'data' => null];
|
||||
} else {
|
||||
@@ -635,7 +641,10 @@ class UserZone extends Model
|
||||
//获取字符串的长度和 判断字符串里面是否有,
|
||||
if((mb_strlen($v['loginip'], 'utf-8') > 8 && mb_strpos($v['loginip'], ',') !== false)){
|
||||
$ipd = explode(',', $v['loginip']);
|
||||
$v['loginip'] = $ipd[0].' · '.$ipd[1];//省·市
|
||||
// $v['loginip'] = $ipd[0].' · '.$ipd[1];//省·市
|
||||
$sheng = $ipd[0] =='(null)' ? '' : $ipd[0];
|
||||
$shi = $ipd[1] ?? '';
|
||||
$v['loginip'] = $sheng.' '.$shi;//省·市
|
||||
}else{
|
||||
$v['loginip'] = '未知';
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\Log;
|
||||
use think\Response;
|
||||
|
||||
if (!function_exists('__')) {
|
||||
@@ -625,7 +626,7 @@ function nickname_filter($username) {
|
||||
// 定义敏感词数组(包含常见变体)
|
||||
$sensitiveWords = [
|
||||
// 核心敏感词
|
||||
'系统管理员', '管理员', '系统管理', '系统', '管理',
|
||||
'系统管理员', '管理员', '系统管理', '系统', '管理','官方',
|
||||
|
||||
// 繁体中文
|
||||
'系統管理員', '管理員', '系統管理', '系統',
|
||||
@@ -804,7 +805,7 @@ function redis_lock_exit($key, $value = 1, $time = 5)
|
||||
$redis = \think\Cache::store('redis')->handler();
|
||||
$is_lock = $redis->setnx($key, $value);
|
||||
if (!$is_lock) {
|
||||
return V(0, '访问频繁,请稍后重试');
|
||||
return V(0, '您的手速太快了!');
|
||||
} else {
|
||||
$redis->setex($key, $time, $value);
|
||||
return true;
|
||||
@@ -826,7 +827,7 @@ function redis_lock_exits($key, $value = 1, $time = 5)
|
||||
// 尝试加锁(设置一个带过期时间的 key,仅当 key 不存在时才设置成功)
|
||||
$is_lock = Cache::has($key);
|
||||
if ($is_lock) {
|
||||
return V(0, '访问频繁,请稍后重试');
|
||||
return V(0, '您的手速太快了!');
|
||||
} else {
|
||||
Cache::set($key, $value, $time);
|
||||
return true;
|
||||
@@ -879,7 +880,7 @@ function generateRandom($num = 0)
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
function generateRandoms($length = 4)
|
||||
function generateRandoms($length = 6)
|
||||
{
|
||||
$min = pow(10, $length - 1);
|
||||
$max = pow(10, $length) - 1;
|
||||
@@ -940,12 +941,130 @@ function get_user_constellation($birthday)
|
||||
}
|
||||
|
||||
//数字格式话
|
||||
function numberFormat($number) {
|
||||
$num = round($number / 10000, 2);
|
||||
if ($num > 1) {
|
||||
$number = $num . 'w';
|
||||
//function numberFormat($number) {
|
||||
// $num = round($number / 10000, 2);
|
||||
// if ($num > 1) {
|
||||
// $number = $num . 'w';
|
||||
// }
|
||||
// return $number;
|
||||
//}
|
||||
|
||||
/**
|
||||
* 数字格式化方法
|
||||
* @param int|float $number 需要格式化的数字
|
||||
* @param string $format 格式类型: 'short'(默认简写), 'thousand'(千分位), 'custom'(自定义)
|
||||
* @param int $decimals 小数位数
|
||||
* @param array $options 其他选项
|
||||
* @return string 格式化后的数字字符串
|
||||
*/
|
||||
function numberFormat($number, $format = 'short', $decimals = 2, $options = []) {
|
||||
|
||||
// 确保输入是数字
|
||||
if (!is_numeric($number)) {
|
||||
return '0';
|
||||
}
|
||||
return $number;
|
||||
|
||||
switch ($format) {
|
||||
case 'short':
|
||||
return formatShortNumber($number, $decimals);
|
||||
|
||||
case 'thousand':
|
||||
return formatThousandNumber($number, $decimals);
|
||||
|
||||
case 'custom':
|
||||
return formatCustomNumber($number, $options);
|
||||
|
||||
default:
|
||||
return formatShortNumber($number, $decimals);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 简写格式化数字 (如: 1.23w, 2.56亿)
|
||||
*/
|
||||
function formatShortNumber($number, $decimals = 2) {
|
||||
$units = ['', 'w', '亿', '万亿'];
|
||||
$unit_index = 0;
|
||||
|
||||
// 处理负数
|
||||
$is_negative = $number < 0;
|
||||
$number = abs($number);
|
||||
|
||||
// 根据数值大小选择合适的单位
|
||||
while ($number >= 10000 && $unit_index < count($units) - 1) {
|
||||
$number /= 10000;
|
||||
$unit_index++;
|
||||
}
|
||||
|
||||
// 格式化数字
|
||||
$formatted = round($number, $decimals);
|
||||
|
||||
// 如果是整数且小数部分为0,则不显示小数
|
||||
if ($decimals > 0 && floor($formatted) == $formatted) {
|
||||
$formatted = number_format($formatted, 0);
|
||||
} else {
|
||||
$formatted = number_format($formatted, $decimals, '.', '');
|
||||
}
|
||||
|
||||
return ($is_negative ? '-' : '') . $formatted . $units[$unit_index];
|
||||
}
|
||||
|
||||
/**
|
||||
* 千分位格式化数字 (如: 1,234,567.89)
|
||||
*/
|
||||
function formatThousandNumber($number, $decimals = 2) {
|
||||
return number_format($number, $decimals, '.', ',');
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义格式化数字
|
||||
*/
|
||||
function formatCustomNumber($number, $options = []) {
|
||||
$defaults = [
|
||||
'decimals' => 2,
|
||||
'decimal_point' => '.',
|
||||
'thousands_sep' => ',',
|
||||
'suffix' => '',
|
||||
'prefix' => ''
|
||||
];
|
||||
|
||||
$options = array_merge($defaults, $options);
|
||||
|
||||
$formatted = number_format($number, $options['decimals'], $options['decimal_point'], $options['thousands_sep']);
|
||||
|
||||
return $options['prefix'] . $formatted . $options['suffix'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 简化版本的数字格式化 (改进原方法)
|
||||
* @param int|float $number 需要格式化的数字
|
||||
* @param int $decimals 小数位数
|
||||
* @return string 格式化后的数字字符串
|
||||
*/
|
||||
function simpleNumberFormat($number, $decimals = 2) {
|
||||
if (!is_numeric($number)) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
// 处理负数
|
||||
$is_negative = $number < 0;
|
||||
$number = abs($number);
|
||||
|
||||
if ($number >= 100000000) { // 1亿以上
|
||||
$result = round($number / 100000000, $decimals) . '亿';
|
||||
} elseif ($number >= 10000) { // 1万以上
|
||||
$result = round($number / 10000, $decimals) . 'w';
|
||||
} elseif ($number >= 1000) { // 1千以上
|
||||
$result = round($number / 1000, $decimals) . 'k';
|
||||
} else {
|
||||
$result = round($number, $decimals);
|
||||
// 如果是整数且小数部分为0,则不显示小数
|
||||
if (floor($result) == $result) {
|
||||
$result = (int)$result;
|
||||
}
|
||||
}
|
||||
|
||||
return ($is_negative ? '-' : '') . $result;
|
||||
}
|
||||
|
||||
function generateRandomRoomName() {
|
||||
@@ -1051,7 +1170,7 @@ function handelCharge($where,$data){
|
||||
return 0;
|
||||
}
|
||||
//查询是否首充
|
||||
$is_first_charge = db::name('vs_user_money_log')->where('user_id',$orderModel['user_id'])->where('change_type',2)->where('money_type',1)->count();
|
||||
$is_first_charge = db::name('vs_user_money_log')->where('user_id',$orderModel['user_id'])->where('change_type',2)->where('money_type',1)->where(['createtime'=>['>=',"1760666400"]])->count();
|
||||
//添加充值记录
|
||||
$res2 = db::name('vs_user_money_log')->insert([
|
||||
'user_id' => $orderModel['user_id'],
|
||||
@@ -1066,14 +1185,6 @@ function handelCharge($where,$data){
|
||||
db::rollback();
|
||||
return 0;
|
||||
}
|
||||
//首充
|
||||
if($is_first_charge == 0){
|
||||
$first_recharge = model('Activities')->first_charge_gift_send($orderModel['user_id'],$orderModel['money']);
|
||||
// if($first_recharge['code'] != 1){
|
||||
// db::rollback();
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
|
||||
//给上级返佣
|
||||
//获取上级
|
||||
@@ -1085,9 +1196,29 @@ function handelCharge($where,$data){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
db::commit();
|
||||
|
||||
//活动
|
||||
//首充
|
||||
if($is_first_charge == 0){
|
||||
model('Activities')->first_charge_gift_send($orderModel['user_id'],$orderModel['money']);
|
||||
}
|
||||
//活动
|
||||
if($orderModel['type_id'] == 6){
|
||||
$orderModel['type_params'] = 2;
|
||||
}elseif(in_array($orderModel['type_id'],[14,15,16])){
|
||||
$orderModel['type_params'] = 3;
|
||||
}
|
||||
switch ($orderModel['type_params']){
|
||||
case 2:
|
||||
//天降好礼
|
||||
model('Activities')->drop_gift_send($orderModel['user_id'],$orderModel['money']);
|
||||
break;
|
||||
case 3:
|
||||
//新人好礼
|
||||
model('Activities')->new_charge_gift_send($orderModel['user_id'],$orderModel['money']);
|
||||
}
|
||||
|
||||
return 1;
|
||||
} catch (\Exception $e){
|
||||
db::rollback();
|
||||
@@ -1102,7 +1233,9 @@ function handelCharge($where,$data){
|
||||
function coin_earning($all_gift_price,$ratio){
|
||||
//rmb_coin_ratio 人民币转换金币的比例
|
||||
//金币转换人民币
|
||||
return $all_gift_price * $ratio / 100 / get_system_config_value('rmb_coin_ratio');
|
||||
//小数点保留4位
|
||||
$result = $all_gift_price * $ratio / 100 / get_system_config_value('rmb_coin_ratio');
|
||||
return round($result, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1160,6 +1293,22 @@ function getMillisecond() {
|
||||
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* 写入日志到redis
|
||||
* @param string $key 日志key
|
||||
* @param array $logData 日志数据
|
||||
*/
|
||||
function write_log_redis($key = 'log',$logData = [],$time = 7){
|
||||
$redis = new \Redis();
|
||||
// 连接到Redis服务器
|
||||
$redis->connect(config('redis.host'), config('redis.port')); // 根据实际配置调整主机和端口
|
||||
// 选择数据库2
|
||||
$redis->select(2);
|
||||
$key = $key.'_'.date('Y-m-d-H-i-s');
|
||||
$expire = 86400 * $time;
|
||||
$redis->setex($key, $expire, json_encode($logData));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\common\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
|
||||
class BaseCom extends Controller
|
||||
@@ -19,27 +20,67 @@ class BaseCom extends Controller
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
|
||||
//检测系统是否维护中
|
||||
// $config = get_system_config();
|
||||
$is_maintenance = get_system_config_value('is_maintenance');
|
||||
if($is_maintenance == 2){
|
||||
return V(203, '系统维护中');
|
||||
return V(0, '系统维护中');
|
||||
}
|
||||
$token = input('token', '');
|
||||
if (empty($token)) {
|
||||
$token = request()->header('token');
|
||||
if(empty($token)){
|
||||
return V(301, '登录失效');
|
||||
}
|
||||
//检测是什么系统
|
||||
$system = input('system','');
|
||||
if(empty($system)){
|
||||
$system = request()->header('system');
|
||||
}
|
||||
//版本号
|
||||
$version = input('App-Version','');
|
||||
if(empty($version)){
|
||||
$version = request()->header('App-Version');
|
||||
}
|
||||
$zhenshi_version = db::name('version')->where('type', 2)->value('oldversion');
|
||||
$result = version_compare($version,$zhenshi_version);
|
||||
//请求的接口
|
||||
$api = request()->controller().'/'.request()->action();
|
||||
if($system == 'iOS' && $result > 0){
|
||||
if($api == 'Index/index_banner' || $api == 'Index/room_type_list' || $api == 'Index/room_list' || $api == 'UserZone/expand_zone' || $api == 'UserZone/zone_list' || $api == 'UserZone/topic_list' || $api == 'UserZone/get_zone_topic'){
|
||||
$this->uid = 0;
|
||||
//定义一个常量
|
||||
define('UID', $this->uid);
|
||||
}else{
|
||||
$token = request()->header('token');
|
||||
if (empty($token)) {
|
||||
$token = input('token', '');
|
||||
if(empty($token)){
|
||||
return V(301, '登录失效');
|
||||
}
|
||||
}
|
||||
|
||||
$reslut = model('UserToken')->check_login_token($token);
|
||||
if($reslut['code'] != 1) {
|
||||
model('UserToken')->where('token', $token)->update(['token' => 1]);
|
||||
return V($reslut['code'], $reslut['msg'],$reslut['data']);
|
||||
} else {
|
||||
$this->uid = $reslut['data'];
|
||||
//定义一个常量
|
||||
define('UID', $this->uid);
|
||||
$reslut = model('UserToken')->check_login_token($token);
|
||||
if($reslut['code'] != 1) {
|
||||
model('UserToken')->where('token', $token)->update(['token' => 1]);
|
||||
return V($reslut['code'], $reslut['msg'],$reslut['data']);
|
||||
} else {
|
||||
$this->uid = $reslut['data'];
|
||||
//定义一个常量
|
||||
define('UID', $this->uid);
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$token = request()->header('token');
|
||||
if (empty($token)) {
|
||||
$token = input('token', '');
|
||||
if(empty($token)){
|
||||
return V(301, '登录失效');
|
||||
}
|
||||
}
|
||||
|
||||
$reslut = model('UserToken')->check_login_token($token);
|
||||
if($reslut['code'] != 1) {
|
||||
model('UserToken')->where('token', $token)->update(['token' => 1]);
|
||||
return V($reslut['code'], $reslut['msg'],$reslut['data']);
|
||||
} else {
|
||||
$this->uid = $reslut['data'];
|
||||
//定义一个常量
|
||||
define('UID', $this->uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,14 @@ class Push
|
||||
//推送系统消息
|
||||
const PUSH_SYSTEM_MESSAGE = 7000;//推送系统消息
|
||||
|
||||
//房间盘推送
|
||||
//巡乐会推送开启进度推送
|
||||
const PUSH_ROOM_PAN_XLH_PROGRESS = 8000;
|
||||
//小时榜
|
||||
const PUSH_ROOM_PAN_HOUR_PROGRESS = 8001;
|
||||
//红包
|
||||
const PUSH_ROOM_PAN_RED_PROGRESS = 8002;
|
||||
|
||||
public $user_id, $room_id, $topic_room, $topic_client;
|
||||
|
||||
public function __construct($user_id = 0, $room_id = 0)
|
||||
@@ -269,12 +277,14 @@ class Push
|
||||
|
||||
|
||||
// =======================================================================================================
|
||||
// ========================================羽声使用开始=====================================================================
|
||||
// ========================================秘地使用开始=====================================================================
|
||||
|
||||
//横幅礼物通知
|
||||
public function giftBanner($gift_list)
|
||||
{
|
||||
$topic = 'qx_room_topic';
|
||||
//数组重组下标从0开始
|
||||
$gift_list = array_values($gift_list);
|
||||
$data = ['room_id' => $this->room_id, 'list' => $gift_list];
|
||||
$this->push(self::PUSH_GIFT_BANNER, $topic, $data);
|
||||
}
|
||||
@@ -287,10 +297,27 @@ class Push
|
||||
$this->push(self::PUSH_SYSTEM_MESSAGE, $topic, $data);
|
||||
}
|
||||
|
||||
//巡乐会推送
|
||||
public function xunlehui($data){
|
||||
$topic = 'qx_xunlehui';
|
||||
$this->push(self::PUSH_ROOM_PAN_XLH_PROGRESS, $topic, $data);
|
||||
}
|
||||
|
||||
//小时榜推送
|
||||
public function hourRanking($data){
|
||||
$topic = 'qx_hour_ranking';
|
||||
$this->push(self::PUSH_ROOM_PAN_HOUR_PROGRESS, $topic, $data);
|
||||
}
|
||||
|
||||
//红包来了
|
||||
public function redpacketArrive($data){
|
||||
$topic = 'qx_redpacket_arrive';
|
||||
$this->push(self::PUSH_ROOM_PAN_RED_PROGRESS, $topic, $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =========================================羽声使用结束=====================================================
|
||||
// =========================================秘地使用结束=====================================================
|
||||
// =============================================================================================================
|
||||
|
||||
|
||||
|
||||
@@ -163,10 +163,10 @@ class adminApi extends Controller
|
||||
// 判断是否需要验证权限
|
||||
if (!$this->auth->match($this->noNeedRight)) {
|
||||
// 判断控制器和方法是否有对应权限
|
||||
if (!$this->auth->check($path)) {
|
||||
Hook::listen('admin_nopermission', $this);
|
||||
return V(302,"你没有权限访问", url('index/login', []));
|
||||
}
|
||||
// if (!$this->auth->check($path)) {
|
||||
// Hook::listen('admin_nopermission', $this);
|
||||
// return V(302,"你没有权限访问", url('index/login', []));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
114
application/common/library/RedpacketLua.php
Normal file
114
application/common/library/RedpacketLua.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
class RedpacketLua
|
||||
{
|
||||
/**
|
||||
* 抢红包Lua脚本
|
||||
* 保证原子性操作,防止超抢
|
||||
*/
|
||||
public static function grabRedpacketScript()
|
||||
{
|
||||
return <<<LUA
|
||||
-- KEYS[1]: 红包key, KEYS[2]: 用户集合key, KEYS[3]: 用户ID
|
||||
-- ARGV[1]: 当前时间
|
||||
|
||||
local redpacketKey = KEYS[1]
|
||||
local userSetKey = KEYS[2]
|
||||
local userId = KEYS[3]
|
||||
local currentTime = tonumber(ARGV[1])
|
||||
|
||||
-- 检查红包是否存在
|
||||
local redpacketData = redis.call('HGETALL', redpacketKey)
|
||||
if not redpacketData or #redpacketData == 0 then
|
||||
return {0, "红包不存在", 0}
|
||||
end
|
||||
|
||||
-- 将哈希数据转为table
|
||||
local redpacket = {}
|
||||
for i = 1, #redpacketData, 2 do
|
||||
redpacket[redpacketData[i]] = redpacketData[i + 1]
|
||||
end
|
||||
|
||||
-- 检查红包状态
|
||||
local status = tonumber(redpacket['status'])
|
||||
local startTime = tonumber(redpacket['start_time'])
|
||||
local endTime = tonumber(redpacket['end_time'])
|
||||
|
||||
if status == 0 then
|
||||
if currentTime < startTime then
|
||||
return {0, "红包还未开始", 0}
|
||||
else
|
||||
-- 更新状态为进行中(1)
|
||||
redis.call('HSET', redpacketKey, 'status', 1)
|
||||
status = 1
|
||||
end
|
||||
end
|
||||
|
||||
if status ~= 1 then
|
||||
return {0, "红包已结束", 0}
|
||||
end
|
||||
|
||||
if currentTime > endTime then
|
||||
redis.call('HSET', redpacketKey, 'status', 2)
|
||||
return {0, "红包已结束", 0}
|
||||
end
|
||||
|
||||
-- 检查是否已经抢过
|
||||
local hasGrabbed = redis.call('SISMEMBER', userSetKey, userId)
|
||||
if hasGrabbed == 1 then
|
||||
return {0, "已经抢过该红包", 0}
|
||||
end
|
||||
|
||||
-- 检查是否还有剩余
|
||||
local leftAmount = tonumber(redpacket['left_amount'])
|
||||
local leftCount = tonumber(redpacket['left_count'])
|
||||
|
||||
if leftCount <= 0 or leftAmount <= 0 then
|
||||
return {0, "红包已抢完", 0}
|
||||
end
|
||||
|
||||
-- 计算红包金额
|
||||
local amount = 0
|
||||
local isFinished = 0
|
||||
|
||||
if leftCount == 1 then
|
||||
-- 最后一个红包,获得剩余所有金额
|
||||
amount = leftAmount
|
||||
isFinished = 1
|
||||
else
|
||||
-- 随机算法:二倍均值法,保证公平性
|
||||
local maxAmount = leftAmount / leftCount * 2
|
||||
amount = math.random(1, math.floor(maxAmount))
|
||||
-- 确保金额不会超过剩余金额
|
||||
if amount > leftAmount then
|
||||
amount = leftAmount
|
||||
end
|
||||
-- 检查是否是最后一个(由于浮点数计算可能有误差)
|
||||
if leftCount == 1 or (leftAmount - amount) < 0.01 then
|
||||
isFinished = 1
|
||||
end
|
||||
end
|
||||
|
||||
-- 更新红包数据
|
||||
local newLeftAmount = leftAmount - amount
|
||||
local newLeftCount = leftCount - 1
|
||||
|
||||
redis.call('HSET', redpacketKey, 'left_amount', newLeftAmount)
|
||||
redis.call('HSET', redpacketKey, 'left_count', newLeftCount)
|
||||
|
||||
-- 标记用户已抢
|
||||
redis.call('SADD', userSetKey, userId)
|
||||
|
||||
-- 如果抢完了,更新状态为已结束(2)
|
||||
if isFinished == 1 then
|
||||
redis.call('HSET', redpacketKey, 'status', 2)
|
||||
end
|
||||
|
||||
return {1, tostring(amount), isFinished}
|
||||
LUA;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
171
application/common/model/Redpacket.php
Normal file
171
application/common/model/Redpacket.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\controller\Push;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class Redpacket extends Model
|
||||
{
|
||||
// 红包状态
|
||||
const STATUS_PENDING = 0; // 未开始
|
||||
const STATUS_ACTIVE = 1; // 进行中
|
||||
const STATUS_FINISHED = 2; // 已结束
|
||||
const STATUS_REFUNDED = 3; // 已退回
|
||||
|
||||
// 红包类型
|
||||
const TYPE_NORMAL = 1; // 普通红包
|
||||
const TYPE_PASSWORD = 2; // 口令红包
|
||||
|
||||
// 币种类型
|
||||
const COIN_GOLD = 1; // 金币
|
||||
const COIN_DIAMOND = 2; // 钻石
|
||||
|
||||
// 倒计时选项
|
||||
public static $countdownOptions = [
|
||||
0 => '立刻',
|
||||
60 => '1分钟',
|
||||
120 => '2分钟',
|
||||
300 => '5分钟',
|
||||
600 => '10分钟'
|
||||
];
|
||||
|
||||
// 领取条件
|
||||
const CONDITION_NONE = 0;
|
||||
const CONDITION_COLLECT_ROOM = 1;
|
||||
const CONDITION_MIC_USER = 2;
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
|
||||
/**
|
||||
* 发红包
|
||||
*/
|
||||
public function createRedpacket($data)
|
||||
{
|
||||
// var_dump($data);exit;
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 验证用户余额
|
||||
$wallet = Db::name('user_wallet')->where('user_id', $data['user_id'])->find();
|
||||
|
||||
$coinField = $data['coin_type'] == self::COIN_GOLD ? 'coin' : 'earnings';
|
||||
if ($wallet[$coinField] < $data['total_amount']) {
|
||||
return ['code' => 0, 'msg' => '余额不足', 'data' => null];
|
||||
}
|
||||
|
||||
// 扣除余额
|
||||
$delres = Db::name('user_wallet')
|
||||
->where('user_id', $data['user_id'])
|
||||
->dec($coinField, $data['total_amount'])
|
||||
->update();
|
||||
//记录日志 32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石)
|
||||
//记录用户金币日志
|
||||
$data_log = [
|
||||
'user_id' => $data['user_id'],
|
||||
'change_value' => $data['total_amount'],
|
||||
'room_id' => $data['room_id'],
|
||||
'money_type' => $data['coin_type'],
|
||||
'change_type' => $data['coin_type'] == self::COIN_GOLD ? 32 : 29,
|
||||
'from_id' => $data['room_id'],
|
||||
'remarks' => $data['coin_type'] == self::COIN_GOLD ? '金币(发红包)' : '钻石(发红包)',
|
||||
'createtime' => time()
|
||||
];
|
||||
|
||||
$res = Db::name('vs_user_money_log')->insert($data_log);
|
||||
if(!$res || !$delres){
|
||||
Db::rollback();
|
||||
}
|
||||
// 计算开始时间
|
||||
$startTime = $data['countdown'] > 0 ? (time() + $data['countdown']) : time();
|
||||
//获取配置项 红包没有抢完所展示时间
|
||||
$endTime = $startTime + get_system_config_value('red_packet_time') ?? 120; // 默认2分钟后结束
|
||||
|
||||
// 创建红包
|
||||
$redpacketData = [
|
||||
'user_id' => $data['user_id'],
|
||||
'room_id' => $data['room_id'],
|
||||
'type' => $data['type'],
|
||||
'password' => $data['password'] ?? '',
|
||||
'countdown' => $data['countdown'],
|
||||
'coin_type' => $data['coin_type'],
|
||||
'total_amount' => $data['total_amount'],
|
||||
'total_count' => $data['total_count'],
|
||||
'left_amount' => $data['total_amount'],
|
||||
'left_count' => $data['total_count'],
|
||||
'conditions' => $data['conditions'] ?? '',
|
||||
'status' => $data['countdown'] > 0 ? self::STATUS_PENDING : self::STATUS_ACTIVE,
|
||||
'start_time' => $startTime,
|
||||
'end_time' => $endTime,
|
||||
'createtime' => time(),
|
||||
'remark' => (!empty($data['remark']) && trim($data['remark']) !== '') ? trim($data['remark']) : '大吉大利,红包拿来啦!'
|
||||
];
|
||||
|
||||
$redpacketId = $this->insertGetId($redpacketData);
|
||||
|
||||
// 设置Redis缓存
|
||||
$redis = \think\Cache::store('redis')->handler();
|
||||
$redisKey = "redpacket:{$redpacketId}";
|
||||
$redis->hMSet($redisKey, [
|
||||
'total_amount' => $data['total_amount'],
|
||||
'left_amount' => $data['total_amount'],
|
||||
'total_count' => $data['total_count'],
|
||||
'left_count' => $data['total_count'],
|
||||
'status' => $redpacketData['status'],
|
||||
'start_time' => $startTime,
|
||||
'end_time' => $endTime
|
||||
]);
|
||||
|
||||
// 设置过期时间
|
||||
$redis->expireAt($redisKey, $endTime + 3600); // 结束后保留1小时
|
||||
Db::commit();
|
||||
|
||||
//给前端推送信息
|
||||
$data['nickname'] = Db::name('user')->where('id', $data['user_id'])->value('nickname');
|
||||
$data['avatar'] = Db::name('user')->where('id', $data['user_id'])->value('avatar');
|
||||
$data['redpacket_id'] = $redpacketId;
|
||||
$data['start_time'] = $startTime;//红包开抢时间
|
||||
$data['redpacket_time'] = get_system_config_value('red_packet_time');//展示时间
|
||||
$data['room_name'] = Db::name('vs_room')->where('id', $data['room_id'])->value('room_name');
|
||||
$text = [
|
||||
'redpacketInfo' => $data,
|
||||
'text' => ''
|
||||
];
|
||||
model('api/Chat')->sendMsg(1060,$data['room_id'],$text);
|
||||
$push = new Push(UID, $data['room_id']);
|
||||
$texts = [
|
||||
'room_id' => $data['room_id'],
|
||||
'text' => $data['nickname'].'在'.$data['room_name'].'房间发了一个红包!',
|
||||
'room_name' => $data['room_name'],
|
||||
'nickname' => $data['nickname']
|
||||
];
|
||||
$push->redpacketArrive($texts);
|
||||
|
||||
return ['code' => 1, 'msg' => '发红包成功', 'data' => $redpacketId];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => $e->getMessage(), 'data' => null];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取红包信息
|
||||
*/
|
||||
public function getRedpacketInfo($id)
|
||||
{
|
||||
$redpacket = $this->find($id);
|
||||
if (!$redpacket) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$redpacket = $redpacket->toArray();
|
||||
$redpacket['nickname'] = Db::name('user')->where('id', $redpacket['user_id'])->value('nickname');
|
||||
$redpacket['avatar'] = Db::name('user')->where('id', $redpacket['user_id'])->value('avatar');
|
||||
$redpacket['redpacket_id'] = $redpacket['id'];
|
||||
|
||||
return $redpacket;
|
||||
}
|
||||
}
|
||||
12
application/common/model/RedpacketRecord.php
Normal file
12
application/common/model/RedpacketRecord.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class RedpacketRecord extends Model
|
||||
{
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = false;
|
||||
}
|
||||
@@ -73,7 +73,23 @@ class UserWallet extends Model
|
||||
const TRANSFER_COIN = 25;
|
||||
//好友转赠所得金币
|
||||
const RECEIVE_COIN = 26;
|
||||
//小时榜获得金币
|
||||
const HOUR_RANK_COIN = 27;
|
||||
//新人充值好礼
|
||||
const NEW_USER_CHARGE_GIFT = 28;
|
||||
|
||||
//发红包(金币)
|
||||
const RED_PACKET_COIN = 32;
|
||||
//发红包(钻石)
|
||||
const RED_PACKET_DIAMOND = 29;
|
||||
//抢红包(金币)
|
||||
const RED_PACKET_COIN_RECEIVE = 30;
|
||||
//抢红包(钻石)
|
||||
const RED_PACKET_DIAMOND_RECEIVE = 31;
|
||||
//红包剩余退回(金币),34-红包剩余退回(钻石)
|
||||
const RED_PACKET_LEFT_COIN = 33;
|
||||
//红包剩余退回(钻石)
|
||||
const RED_PACKET_LEFT_DIAMOND = 34;
|
||||
|
||||
//金币支出类型数组
|
||||
public $coin_consumption_type_array = [
|
||||
@@ -82,12 +98,14 @@ class UserWallet extends Model
|
||||
self::OPERATION_GIFT,
|
||||
self::GUILD_EXIT,
|
||||
self::HEADLINE_REWARD,
|
||||
self::TRANSFER_COIN
|
||||
self::TRANSFER_COIN,
|
||||
self::RED_PACKET_COIN,
|
||||
];
|
||||
//钻石支出类型数组
|
||||
public $diamond_consumption_type_array = [
|
||||
self::OPERATION_WITHDRAW,
|
||||
self::MONEY_CONVERSION
|
||||
self::MONEY_CONVERSION,
|
||||
self::RED_PACKET_DIAMOND
|
||||
];
|
||||
|
||||
|
||||
@@ -135,7 +153,15 @@ class UserWallet extends Model
|
||||
self::FINANCE_LEVEL_REWARD => '财富等级奖励金币领取',
|
||||
self::DELETE_RELATION_COIN => '删除关系扣金币',
|
||||
self::TRANSFER_COIN => '赠送好友金币',
|
||||
self::RECEIVE_COIN => '好友转赠所得金币'
|
||||
self::RECEIVE_COIN => '好友转赠所得金币',
|
||||
self::HOUR_RANK_COIN => '小时榜获得金币',
|
||||
self::NEW_USER_CHARGE_GIFT => '新人充值好礼',
|
||||
self::RED_PACKET_COIN => '发红包(金币)',
|
||||
self::RED_PACKET_DIAMOND => '发红包(钻石)',
|
||||
self::RED_PACKET_COIN_RECEIVE => '抢红包(金币)',
|
||||
self::RED_PACKET_DIAMOND_RECEIVE => '抢红包(钻石)',
|
||||
self::RED_PACKET_LEFT_COIN => '红包剩余退回(金币)',
|
||||
self::RED_PACKET_LEFT_DIAMOND => '红包剩余退回(钻石)',
|
||||
];
|
||||
return $status[$type] ?? '';
|
||||
}
|
||||
|
||||
707
application/common/service/RedpacketService.php
Normal file
707
application/common/service/RedpacketService.php
Normal file
@@ -0,0 +1,707 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use think\Db;
|
||||
use think\Cache;
|
||||
use app\common\model\Redpacket;
|
||||
use app\common\model\RedpacketRecord;
|
||||
use app\common\model\UserWallet;
|
||||
use app\common\library\RedpacketLua;
|
||||
|
||||
class RedpacketService
|
||||
{
|
||||
/**
|
||||
* 发红包
|
||||
*/
|
||||
public function create($data)
|
||||
{
|
||||
// 验证数据
|
||||
$res = $this->validateCreateData($data);
|
||||
if ($res['code'] == 0) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
$redpacketModel = new Redpacket();
|
||||
return $redpacketModel->createRedpacket($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 抢红包并返回详细结果
|
||||
*/
|
||||
public function grabWithResult($redpacketId, $userId)
|
||||
{
|
||||
$redpacketModel = new Redpacket();
|
||||
$redpacket = $redpacketModel->getRedpacketInfo($redpacketId);
|
||||
|
||||
if (!$redpacket) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '红包不存在',
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
|
||||
// 验证领取条件
|
||||
$conditionCheck = $this->checkConditionsWithResult($redpacket, $userId);
|
||||
if ($conditionCheck['code'] != 1) {
|
||||
return $conditionCheck;
|
||||
}
|
||||
|
||||
// 检查红包状态
|
||||
$statusCheck = $this->checkRedpacketStatus($redpacket);
|
||||
if ($statusCheck['code'] != 1) {
|
||||
return $statusCheck;
|
||||
}
|
||||
|
||||
// 检查是否已经抢过
|
||||
if ($this->hasUserGrabbed($redpacketId, $userId)) {
|
||||
// $detail = $this->getGrabResult($redpacketId, $userId);
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '已经抢过该红包',
|
||||
'data' => ['code' => 2] //1-抢到了,2-已经抢过红包,3-没有抢到
|
||||
];
|
||||
}
|
||||
|
||||
// 使用Redis+Lua保证原子性操作
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$script = RedpacketLua::grabRedpacketScript();
|
||||
|
||||
$redpacketKey = "redpacket:{$redpacketId}";
|
||||
$userSetKey = "redpacket_users:{$redpacketId}";
|
||||
|
||||
$result = $redis->eval($script, [
|
||||
$redpacketKey,
|
||||
$userSetKey,
|
||||
$userId,
|
||||
time()
|
||||
], 3);
|
||||
|
||||
if ($result[0] == 0) {
|
||||
$message = $result[1];
|
||||
if ($message == '红包已抢完') {
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '手慢了,红包已抢完',
|
||||
'data' => ['code' => 3] //1-抢到了,2-已经抢过红包,3-没有抢到
|
||||
];
|
||||
} elseif ($message == '已经抢过该红包') {
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '已经抢过该红包',
|
||||
'data' => ['code' => 2] //1-抢到了,2-已经抢过红包,3-没有抢到
|
||||
];
|
||||
}elseif ($message == '红包已结束') {
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '手慢了,红包已抢完',
|
||||
'data' => ['code' => 3] //1-抢到了,2-已经抢过红包,3-没有抢到
|
||||
];
|
||||
}
|
||||
else{
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => $message,
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$amount = floatval($result[1]);
|
||||
$isFinished = $result[2] == 1; // Lua脚本返回是否抢完
|
||||
//给前端推送销毁这个红包
|
||||
// redis 记录该红包是否已经推送过了 只推送一次
|
||||
if($isFinished){
|
||||
$redisKey = "redpacket:{$redpacketId}:is_finished";
|
||||
if (!Cache::get($redisKey)) {
|
||||
Cache::set($redisKey, 1, $redpacket['countdown']+get_system_config_value('red_packet_time')+60);
|
||||
$text = [
|
||||
'redpacket_id' => $redpacketId,
|
||||
'text' => '抢完了,请销毁该红包'
|
||||
];
|
||||
model('api/Chat')->sendMsg(1061,$redpacket['room_id'],$text);
|
||||
}
|
||||
}
|
||||
|
||||
// Lua脚本执行成功,记录到数据库
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 创建领取记录
|
||||
$recordData = [
|
||||
'redpacket_id' => $redpacketId,
|
||||
'user_id' => $userId,
|
||||
'amount' => $amount
|
||||
];
|
||||
|
||||
$recordModel = new RedpacketRecord();
|
||||
$recordModel->save($recordData);
|
||||
|
||||
// 更新用户钱包
|
||||
$coinField = $redpacket['coin_type'] == 1 ? 'coin' : 'earnings';
|
||||
//增加余额
|
||||
$addres = Db::name('user_wallet')
|
||||
->where('user_id', $userId)
|
||||
->inc($coinField, $amount)
|
||||
->update();
|
||||
//记录用户金币日志
|
||||
$data = [
|
||||
'user_id' => $userId,
|
||||
'change_value' => $amount,
|
||||
'room_id' => $redpacket['room_id'],
|
||||
'money_type' => $redpacket['coin_type'],
|
||||
//记录日志 32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石)
|
||||
'change_type' => $redpacket['coin_type'] == 1 ? 30 : 31,
|
||||
'from_id' => $redpacket['room_id'],
|
||||
'remarks' => '抢红包收入',
|
||||
'createtime' => time()
|
||||
];
|
||||
|
||||
$res = Db::name('vs_user_money_log')->insert($data);
|
||||
if(!$res || !$addres){
|
||||
Db::rollback();
|
||||
}
|
||||
|
||||
// 更新红包剩余数量和金额,如果抢完了更新状态
|
||||
$updateData = [
|
||||
'left_amount' => Db::raw('left_amount - ' . $amount),
|
||||
'left_count' => Db::raw('left_count - 1'),
|
||||
'updatetime' => time()
|
||||
];
|
||||
|
||||
if ($isFinished) {
|
||||
$updateData['status'] = Redpacket::STATUS_FINISHED;
|
||||
}
|
||||
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacketId)
|
||||
->update($updateData);
|
||||
|
||||
Db::commit();
|
||||
|
||||
// 获取抢红包结果详情
|
||||
$grabResult = $this->getGrabResult($redpacketId, $userId);
|
||||
unset($grabResult['previous_records']);//前端不要
|
||||
unset($grabResult['all_records']);//前端不要
|
||||
unset($grabResult['statistics']);//前端不要
|
||||
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '抢红包成功',
|
||||
// 'data' => $grabResult
|
||||
// 'data' => null
|
||||
'data' => ['code' => 1] //1-抢到了,2-已经抢过红包,3-没有抢到
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
// 回滚Redis操作
|
||||
$redis->hIncrByFloat($redpacketKey, 'left_amount', $amount);
|
||||
$redis->hIncrBy($redpacketKey, 'left_count', 1);
|
||||
$redis->sRem($userSetKey, $userId);
|
||||
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '系统错误,请重试'.$e->getMessage(),
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取抢红包结果详情
|
||||
*/
|
||||
public function getGrabResult($redpacketId, $userId)
|
||||
{
|
||||
// 获取红包基本信息
|
||||
$redpacket = Db::name('redpacket')
|
||||
->where('id', $redpacketId)
|
||||
->find();
|
||||
|
||||
if (!$redpacket) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取当前用户的领取记录
|
||||
$myRecord = Db::name('redpacket_record')
|
||||
->alias('r')
|
||||
->field('r.*, u.nickname, u.avatar')
|
||||
->join('user u', 'u.id = r.user_id')
|
||||
->where('r.redpacket_id', $redpacketId)
|
||||
->where('r.user_id', $userId)
|
||||
->find();
|
||||
|
||||
// 获取在我之前抢到的用户记录
|
||||
$previousRecords = [];
|
||||
if ($myRecord) {
|
||||
$previousRecords = Db::name('redpacket_record')
|
||||
->alias('r')
|
||||
->field('r.*, u.nickname, u.avatar')
|
||||
->join('user u', 'u.id = r.user_id')
|
||||
->where('r.redpacket_id', $redpacketId)
|
||||
->where('r.createtime', '<', $myRecord['createtime'])
|
||||
->order('r.createtime ASC')
|
||||
->select();
|
||||
}
|
||||
|
||||
// 获取所有记录用于统计
|
||||
$allRecords = Db::name('redpacket_record')
|
||||
->alias('r')
|
||||
->field('r.*, u.nickname, u.avatar')
|
||||
->join('user u', 'u.id = r.user_id')
|
||||
->where('r.redpacket_id', $redpacketId)
|
||||
->order('r.createtime ASC')
|
||||
->select();
|
||||
|
||||
// 统计信息
|
||||
$totalGrabbed = count($allRecords);
|
||||
$totalAmount = array_sum(array_column($allRecords, 'amount'));
|
||||
|
||||
// 手气最佳
|
||||
$bestRecord = null;
|
||||
if ($allRecords) {
|
||||
$maxAmount = max(array_column($allRecords, 'amount'));
|
||||
foreach ($allRecords as $record) {
|
||||
if ($record['amount'] == $maxAmount) {
|
||||
$bestRecord = $record;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'redpacket_info' => [
|
||||
'id' => $redpacket['id'],
|
||||
'total_amount' => $redpacket['total_amount'],
|
||||
'total_count' => $redpacket['total_count'],
|
||||
'left_amount' => $redpacket['left_amount'],
|
||||
'left_count' => $redpacket['left_count'],
|
||||
'coin_type' => $redpacket['coin_type'],
|
||||
'status' => $redpacket['status'],
|
||||
'nickname' => Db::name('user')->where('id', $redpacket['user_id'])->value('nickname')
|
||||
],
|
||||
'my_record' => $myRecord ? [
|
||||
'amount' => $myRecord['amount'],
|
||||
'createtime' => $myRecord['createtime'],
|
||||
'nickname' => $myRecord['nickname'],
|
||||
'avatar' => $myRecord['avatar']
|
||||
] : null,
|
||||
'previous_records' => $previousRecords,
|
||||
'all_records' => $allRecords,
|
||||
'statistics' => [
|
||||
'total_grabbed' => $totalGrabbed,
|
||||
'total_amount_grabbed' => $totalAmount,
|
||||
'best_luck' => $bestRecord ? [
|
||||
'nickname' => $bestRecord['nickname'],
|
||||
'avatar' => $bestRecord['avatar'],
|
||||
'amount' => $bestRecord['amount']
|
||||
] : null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查红包状态
|
||||
*/
|
||||
private function checkRedpacketStatus($redpacket)
|
||||
{
|
||||
$now = time();
|
||||
|
||||
if ($redpacket['status'] == Redpacket::STATUS_PENDING) {
|
||||
if ($now < $redpacket['start_time']) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '红包还未开始',
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// if ($redpacket['status'] == Redpacket::STATUS_FINISHED ||
|
||||
// $redpacket['status'] == Redpacket::STATUS_REFUNDED) {
|
||||
// return [
|
||||
// 'code' => 0,
|
||||
// 'msg' => '红包已结束',
|
||||
// 'data' => null
|
||||
// ];
|
||||
// }
|
||||
//
|
||||
// if ($now > $redpacket['end_time']) {
|
||||
// return [
|
||||
// 'code' => 0,
|
||||
// 'msg' => '红包已结束',
|
||||
// 'data' => null
|
||||
// ];
|
||||
// }
|
||||
|
||||
return ['code' => 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否已经抢过
|
||||
*/
|
||||
private function hasUserGrabbed($redpacketId, $userId)
|
||||
{
|
||||
$record = Db::name('redpacket_record')
|
||||
->where('redpacket_id', $redpacketId)
|
||||
->where('user_id', $userId)
|
||||
->find();
|
||||
|
||||
return !empty($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查领取条件(返回结果格式)
|
||||
*/
|
||||
private function checkConditionsWithResult($redpacket, $userId)
|
||||
{
|
||||
$conditions = $redpacket['conditions'] ? explode(',', $redpacket['conditions']): [];
|
||||
|
||||
if (empty($conditions)) {
|
||||
return ['code' => 1];
|
||||
}
|
||||
|
||||
if (in_array(Redpacket::CONDITION_NONE, $conditions)) {
|
||||
return ['code' => 1];
|
||||
}
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
switch ($condition) {
|
||||
case Redpacket::CONDITION_COLLECT_ROOM:
|
||||
if (!$this->checkUserCollectedRoom($userId, $redpacket['room_id'])) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '不满足收藏房间条件',
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
break;
|
||||
|
||||
case Redpacket::CONDITION_MIC_USER:
|
||||
if (!$this->checkUserOnMic($userId, $redpacket['room_id'])) {
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => '您不是麦上用户',
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取红包详情和领取记录
|
||||
*/
|
||||
public function getDetail($redpacketId, $currentUserId = 0)
|
||||
{
|
||||
$redpacketModel = new Redpacket();
|
||||
$redpacket['redpacket_info'] = $redpacketModel->getRedpacketInfo($redpacketId);
|
||||
|
||||
if (!$redpacket) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取领取记录
|
||||
$records = Db::name('redpacket_record')
|
||||
->alias('r')
|
||||
->field('r.*, u.nickname, u.avatar')
|
||||
->join('user u', 'u.id = r.user_id')
|
||||
->where('r.redpacket_id', $redpacketId)
|
||||
->order('r.createtime ASC')
|
||||
->select();
|
||||
//处理createtime 字段
|
||||
$records = array_map(function ($record) {
|
||||
$record['createtime'] = date('Y-m-d H:i:s', $record['createtime']);
|
||||
return $record;
|
||||
}, $records);
|
||||
|
||||
$redpacket['records'] = $records;
|
||||
|
||||
// 检查当前用户是否已抢
|
||||
$redpacket['has_grabbed'] = false;
|
||||
$redpacket['my_record'] = null;
|
||||
|
||||
if ($currentUserId > 0) {
|
||||
foreach ($records as $record) {
|
||||
if ($record['user_id'] == $currentUserId) {
|
||||
$redpacket['has_grabbed'] = true;
|
||||
$redpacket['my_record'] = $record;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $redpacket;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理过期红包退款
|
||||
*/
|
||||
public function processExpiredRedpackets()
|
||||
{
|
||||
$now = time();
|
||||
$redpacketModel = new Redpacket();
|
||||
|
||||
// 查找已结束但未退款的红包
|
||||
$expiredRedpackets = Db::name('redpacket')
|
||||
->where('status', Redpacket::STATUS_ACTIVE)
|
||||
->where('end_time', '<', $now)
|
||||
->where('left_count', '>', 0)
|
||||
->select();
|
||||
|
||||
foreach ($expiredRedpackets as $redpacket) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 退款给发红包用户
|
||||
if ($redpacket['left_amount'] > 0) {
|
||||
$walletModel = new UserWallet();
|
||||
$walletModel->increaseBalance(
|
||||
$redpacket['user_id'],
|
||||
$redpacket['coin_type'],
|
||||
$redpacket['left_amount']
|
||||
);
|
||||
}
|
||||
|
||||
// 更新红包状态
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacket['id'])
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_REFUNDED,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 清理Redis缓存
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$redisKey = "redpacket:{$redpacket['id']}";
|
||||
$redis->del($redisKey);
|
||||
|
||||
Db::commit();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
// 记录日志
|
||||
\think\Log::error("红包退款失败: {$redpacket['id']}, 错误: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证创建红包数据
|
||||
*/
|
||||
private function validateCreateData($data)
|
||||
{
|
||||
if (empty($data['user_id'])) {
|
||||
return ['code' => 0, 'msg' => '用户ID不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
if (empty($data['room_id'])) {
|
||||
return ['code' => 0, 'msg' => '房间ID不能为空', 'data' => null];
|
||||
}
|
||||
|
||||
if (!in_array($data['type'], [Redpacket::TYPE_NORMAL, Redpacket::TYPE_PASSWORD])) {
|
||||
return ['code' => 0, 'msg' => '红包类型错误', 'data' => null];
|
||||
}
|
||||
|
||||
if ($data['type'] == Redpacket::TYPE_PASSWORD && empty($data['password'])) {
|
||||
return ['code' => 0, 'msg' => '口令红包必须设置口令', 'data' => null];
|
||||
}
|
||||
|
||||
if (!in_array($data['coin_type'], [Redpacket::COIN_GOLD, Redpacket::COIN_DIAMOND])) {
|
||||
return ['code' => 0, 'msg' => '币种类型错误', 'data' => null];
|
||||
}
|
||||
|
||||
if ($data['total_amount'] <= 0 || $data['total_count'] <= 0) {
|
||||
return ['code' => 0, 'msg' => '金额和数量必须大于0', 'data' => null];
|
||||
}
|
||||
|
||||
if ($data['total_amount'] < $data['total_count']) {
|
||||
return ['code' => 0, 'msg' => '总金额不能小于总个数', 'data' => null];
|
||||
}
|
||||
|
||||
// 验证领取条件
|
||||
if (isset($data['conditions'])) {
|
||||
$res_con = $this->validateConditions($data['conditions']);
|
||||
if ($res_con !== true) {
|
||||
return $res_con;
|
||||
}
|
||||
}
|
||||
|
||||
return ['code' => 1, 'msg' => '验证成功', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证领取条件
|
||||
*/
|
||||
private function validateConditions($conditions)
|
||||
{
|
||||
if (empty($conditions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//字符串转为数组
|
||||
$conditions = explode(',', $conditions);
|
||||
|
||||
if (in_array(Redpacket::CONDITION_NONE, $conditions) && count($conditions) > 1) {
|
||||
return V(0, '选择"无"条件时不能选择其他条件');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否满足领取条件
|
||||
*/
|
||||
private function checkConditions($redpacket, $userId)
|
||||
{
|
||||
$conditions = $redpacket['conditions'] ?: [];
|
||||
|
||||
if (empty($conditions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in_array(Redpacket::CONDITION_NONE, $conditions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
switch ($condition) {
|
||||
case Redpacket::CONDITION_COLLECT_ROOM:
|
||||
// 检查用户是否收藏了房间
|
||||
if (!$this->checkUserCollectedRoom($userId)) {
|
||||
throw new \Exception('不满足收藏房间条件');
|
||||
}
|
||||
break;
|
||||
|
||||
case Redpacket::CONDITION_MIC_USER:
|
||||
// 检查用户是否在麦位上
|
||||
if (!$this->checkUserOnMic($userId)) {
|
||||
throw new \Exception('不满足麦位用户条件');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否收藏了房间(需要根据实际业务实现)
|
||||
*/
|
||||
private function checkUserCollectedRoom($userId,$roomId)
|
||||
{
|
||||
$collect = Db::name('user_follow')->where(['user_id' => $userId,'type' => 2,'follow_id' => $roomId])->find();
|
||||
if (!$collect) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否在麦位上(需要根据实际业务实现)
|
||||
*/
|
||||
private function checkUserOnMic($userId,$roomId)
|
||||
{
|
||||
$room_type = Db::name('vs_room')->where('id',$roomId)->field('type_id,label_id')->find();
|
||||
//实际麦位
|
||||
if($room_type['type_id'] == 1 || $room_type['type_id'] == 7 || $room_type['type_id'] == 8){
|
||||
$onPit = Db::name('vs_room_pit')->where(['user_id' => $userId,'room_id' => $roomId])->value('pit_number');
|
||||
if ($onPit <= 0){
|
||||
return false;
|
||||
}
|
||||
}elseif($room_type['type_id'] ==2){//拍卖
|
||||
//获取房间的当前拍卖ID
|
||||
$auctionId = Db::name('vs_room_auction')->where(['room_id' => $roomId,'status' => 2])->value('auction_id');
|
||||
$onPit = [];
|
||||
if($auctionId){
|
||||
$onPits = model('api/RoomAuction')->room_auction_list_on($auctionId);
|
||||
//提取数组里面的user_id的值 来判断用户是否在里面
|
||||
$onPit = array_column($onPits,'user_id');
|
||||
//拍卖位 从缓存中取 Cache::get('auction_user_'.$room_id)
|
||||
$onpitNumber_10 = Cache::get('auction_user_'.$roomId);
|
||||
if($onpitNumber_10){
|
||||
$onPit[] = $onpitNumber_10;
|
||||
}
|
||||
}
|
||||
$onpitNumber_9 = Db::name('vs_room_pit')->where(['pit_number' => 9,'room_id' => $roomId])->value('user_id');
|
||||
if($onpitNumber_9){
|
||||
$onPit[] = $onpitNumber_9;
|
||||
}
|
||||
|
||||
if (!in_array($userId,$onPit)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查并更新红包状态
|
||||
* 在抢红包前调用,确保状态正确
|
||||
*/
|
||||
public function checkAndUpdateRedpacketStatus($redpacketId)
|
||||
{
|
||||
$redpacket = Db::name('redpacket')->where('id', $redpacketId)->find();
|
||||
if (!$redpacket) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$redpacketKey = "redpacket:{$redpacketId}";
|
||||
|
||||
// 如果红包状态为未开始(0),但当前时间已超过开始时间,则更新为进行中(1)
|
||||
if ($redpacket['status'] == Redpacket::STATUS_PENDING && $now >= $redpacket['start_time']) {
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacketId)
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_ACTIVE,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 更新Redis中的状态
|
||||
$redis->hSet($redpacketKey, 'status', Redpacket::STATUS_ACTIVE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果红包状态为进行中(1),但已抢完,则更新为已结束(2)
|
||||
if ($redpacket['status'] == Redpacket::STATUS_ACTIVE && $redpacket['left_count'] <= 0) {
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacketId)
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_FINISHED,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 更新Redis中的状态
|
||||
$redis->hSet($redpacketKey, 'status', Redpacket::STATUS_FINISHED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果红包状态为进行中(1),但已超过结束时间,则更新为已结束(2)
|
||||
if ($redpacket['status'] == Redpacket::STATUS_ACTIVE && $now > $redpacket['end_time']) {
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacketId)
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_FINISHED,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 更新Redis中的状态
|
||||
$redis->hSet($redpacketKey, 'status', Redpacket::STATUS_FINISHED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -172,6 +172,7 @@ return [
|
||||
'path' => LOG_PATH,
|
||||
// 日志记录级别
|
||||
'level' => [],
|
||||
'max_files'=>100,//最大保存日志数,超过tp将自动清理
|
||||
],
|
||||
// +----------------------------------------------------------------------
|
||||
// | Trace设置 开启 app_trace 后 有效
|
||||
|
||||
43
application/cron/controller/DaySeconds.php
Normal file
43
application/cron/controller/DaySeconds.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use think\Db;
|
||||
|
||||
|
||||
/*
|
||||
* 定时任务,每秒执行的方法
|
||||
*/
|
||||
class DaySeconds
|
||||
{
|
||||
/*
|
||||
* 运行函数
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
echo "清除房间热度值:\n";
|
||||
$this->clear_room_today_hot_value();//0点以后房间热度值清零
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* 0点以后房间热度值清零
|
||||
* 配置:定时脚本每天 0点 执行
|
||||
* 配置:http://vschat.qxmier.com/api/Cron/DaySeconds
|
||||
*/
|
||||
public function clear_room_today_hot_value() {
|
||||
$where = [];
|
||||
$where['delete_time'] = 0;
|
||||
$where['is_show_room'] = 1;
|
||||
$room = db::name('vs_room')->where($where)->select();
|
||||
echo date('Y-m-d H:i:s').' 开始清零:'.count($room)."\n";
|
||||
foreach ($room as $key => $value) {
|
||||
$data = [
|
||||
'today_hot_value' => 0,
|
||||
];
|
||||
db::name('vs_room')->where(['id' => $value['id']])->update($data);
|
||||
}
|
||||
echo date('Y-m-d H:i:s').' 完成'."\n";
|
||||
die;
|
||||
}
|
||||
}
|
||||
56
application/cron/controller/FriendEnd.php
Normal file
56
application/cron/controller/FriendEnd.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use think\Db;
|
||||
|
||||
class FriendEnd
|
||||
{
|
||||
/*
|
||||
* 运行函数
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
echo "清除交友房过期未结束数据开始:\n";
|
||||
$this->clearFriendingEndRoom();//清除交友房过期未结束数据
|
||||
echo "清除结束 \n";
|
||||
|
||||
echo "清除私密小屋过期数据开始:\n";
|
||||
$this->clear_room_end();//清除私密小屋过期数据
|
||||
echo "清除私密小屋过期数据结束 \n";
|
||||
}
|
||||
|
||||
|
||||
//清除交友房过期未结束数据
|
||||
public function clearFriendingEndRoom()
|
||||
{
|
||||
//清除交友房过期数据
|
||||
$room_list = db::name('vs_room')->where(['type_id'=>7])->whereIn('step', [2,3])
|
||||
->field(['id','step'])->select();
|
||||
if(!empty($room_list)){
|
||||
foreach ($room_list as $room) {
|
||||
//查询交友信息
|
||||
$friending_info = db::name('vs_user_friending')->where('room_id', $room['id'])->where('status', 1)->order('id', 'desc')->find();
|
||||
if($friending_info){
|
||||
//判断结束时间是否到期
|
||||
if($friending_info['end_time'] <= time() || $room['step'] == 3){
|
||||
model('Friend')->end_friend(0,$room['id'],$friending_info['id'],1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//清除私密小屋过期数据
|
||||
public function clear_room_end()
|
||||
{
|
||||
$room_list = db::name('vs_room_cp_movie')->where(['status' => 1,'type'=>1,'time_day' =>['<',time()]])->select();
|
||||
if(!empty($room_list)){
|
||||
foreach ($room_list as $room) {
|
||||
model('Friend')->outRoom(0,$room['room_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use app\common\model\Redpacket;
|
||||
use app\common\model\UserWallet;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use Yzh\YunPay;
|
||||
|
||||
@@ -30,6 +33,12 @@ class PerformPerSecond
|
||||
echo "pk发起10秒后无应答拒绝:\n";
|
||||
$this->pk_start_refuse();
|
||||
echo "\n";
|
||||
echo "房间红包清退:\n";
|
||||
$this->processExpiredRedpackets();
|
||||
echo "\n";
|
||||
// echo "房间火热值更新:\n";
|
||||
// $this->room_hot_update();
|
||||
// echo "\n";
|
||||
echo "提现云账号订单状态查询:\n";
|
||||
$this->withdraw_order_status();
|
||||
echo "\n";
|
||||
@@ -136,6 +145,9 @@ class PerformPerSecond
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if($value['yun_order_status'] == 5077){
|
||||
continue;
|
||||
}
|
||||
echo "提现订单查询:".$value['order_sn']."\n";
|
||||
$yun_pay = new YunPay($value['order_sn'], "", "", "", "","");
|
||||
$result = $yun_pay->queryOrder($value['type']);
|
||||
@@ -144,15 +156,33 @@ class PerformPerSecond
|
||||
db::name('vs_user_withdrawal')->where('order_sn',$value['order_sn'])->update([
|
||||
'status' => 6,
|
||||
'pay_time' => time(),
|
||||
'updatetime' => time()
|
||||
'pay_message' => $result['data']['msg'],
|
||||
'updatetime' => time(),
|
||||
'yun_order_status' => $result['data']['code'],
|
||||
// 'personal_tax_rate' => $result['personal_tax_rate'] ?? 0,
|
||||
'received_tax_amount' => $result['received_tax_amount'] ?? 0,
|
||||
]);
|
||||
}else{
|
||||
db::name('vs_user_withdrawal')->where('order_sn',$value['order_sn'])->update([
|
||||
'status' => 5,
|
||||
'pay_time' => time(),
|
||||
'pay_message' => $result['data']['msg'],
|
||||
'updatetime' => time()
|
||||
'updatetime' => time(),
|
||||
'yun_order_status' => $result['data']['code'],
|
||||
// 'personal_tax_rate' => $result['personal_tax_rate'] ?? 0,
|
||||
'received_tax_amount' => $result['received_tax_amount'] ?? 0,
|
||||
]);
|
||||
if(in_array($result['data']['code'],[5077,261]) && $value['yun_order_status'] == null){
|
||||
// if($result['data']['code']==5077 && $value['yun_order_status'] == null){
|
||||
//该支付宝账户不存在或未开通手机号转账功能。如有疑问,请收款用户联系支付宝客服咨询。
|
||||
//退还金币
|
||||
$res = model('api/UserWithdrawal')->withdrawal_fail($value['order_sn']);
|
||||
if($res){
|
||||
echo "提现订单失败,退回金币成功\n";
|
||||
}else{
|
||||
echo "提现订单失败,退回金币失败:".$res['msg']."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "提现订单查询成功:".$result['msg']."\n";
|
||||
@@ -161,4 +191,140 @@ class PerformPerSecond
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//房间火热值更新
|
||||
public function room_hot_update(){
|
||||
$room_id_list = db::name('vs_room_hot_value_log')->field('id,room_id')->select();
|
||||
$room_list = db::name('vs_room_hot_value_log')->field('room_id,sum(hot_value) as value')->group('room_id')->select();
|
||||
|
||||
if($room_list){
|
||||
$data_count = 0;
|
||||
$data_room_list = [];
|
||||
foreach ($room_list as $value){
|
||||
$hot_value = 0;
|
||||
$hot_values = db::name('vs_room')->where('id',$value['room_id'])->field('hot_value,today_hot_value')->find();
|
||||
if($hot_values['today_hot_value'] == $value['value'] || $value['value'] == 0){
|
||||
continue;
|
||||
}
|
||||
if($hot_values['today_hot_value'] < $value['value']){
|
||||
$hot_value = $hot_values['hot_value'] + ($value['value'] - $hot_values['today_hot_value']);
|
||||
}
|
||||
if($hot_values['today_hot_value'] > $value['value']){
|
||||
$hot_value = $hot_values['hot_value'];
|
||||
$today_hot_value = $value['value'];
|
||||
}
|
||||
|
||||
$res = db::name('vs_room')->where('id',$value['room_id'])->update([
|
||||
'today_hot_value' => $today_hot_value,
|
||||
'hot_value' => $hot_value,
|
||||
'updatetime' => time()
|
||||
]);
|
||||
if($res){
|
||||
// db::name('vs_room_hot_value_log')->where('room_id',$value['room_id'])->delete();
|
||||
$data_room_list[] = $value['room_id'];
|
||||
}
|
||||
$data_count ++;
|
||||
}
|
||||
foreach ($room_id_list as $v){
|
||||
if(in_array($v['room_id'],$data_room_list)){
|
||||
db::name('vs_room_hot_value_log')->where('id',$v['id'])->delete();
|
||||
}
|
||||
}
|
||||
echo "房间火热值更新操作-共". $data_count . "条数据\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理过期红包退款
|
||||
*/
|
||||
public function processExpiredRedpackets()
|
||||
{
|
||||
$now = time();
|
||||
$processedCount = 0;
|
||||
|
||||
// 1. 处理到时间的未开始红包,更新为进行中
|
||||
$pendingRedpackets = Db::name('redpacket')
|
||||
->where('status', Redpacket::STATUS_PENDING)
|
||||
->where('start_time', '<=', $now)
|
||||
->select();
|
||||
|
||||
foreach ($pendingRedpackets as $redpacket) {
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacket['id'])
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_ACTIVE,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 更新Redis缓存
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$redisKey = "redpacket:{$redpacket['id']}";
|
||||
$redis->hSet($redisKey, 'status', Redpacket::STATUS_ACTIVE);
|
||||
|
||||
$processedCount++;
|
||||
}
|
||||
|
||||
// 2. 处理已过期的进行中红包,更新为已结束并退款
|
||||
$expiredRedpackets = Db::name('redpacket')
|
||||
->where('status', Redpacket::STATUS_ACTIVE)
|
||||
->where('end_time', '<', $now)
|
||||
->where('left_count', '>', 0)
|
||||
->select();
|
||||
|
||||
foreach ($expiredRedpackets as $redpacket) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 退款给发红包用户
|
||||
if ($redpacket['left_amount'] > 0) {
|
||||
// 更新用户钱包
|
||||
$coinField = $redpacket['coin_type'] == 1 ? 'coin' : 'earnings';
|
||||
//增加余额
|
||||
$addres = Db::name('user_wallet')
|
||||
->where('user_id', $redpacket['user_id'])
|
||||
->inc($coinField, $redpacket['left_amount'])
|
||||
->update();
|
||||
//记录用户金币日志
|
||||
$data = [
|
||||
'user_id' => $redpacket['user_id'],
|
||||
'change_value' => $redpacket['left_amount'],
|
||||
'room_id' => $redpacket['room_id'],
|
||||
'money_type' => $redpacket['coin_type'],
|
||||
//记录日志 32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石),33-红包剩余退回(金币),34-红包剩余退回(钻石)
|
||||
'change_type' => $redpacket['coin_type'] == 1 ? 33 : 34,
|
||||
'from_id' => $redpacket['room_id'],
|
||||
'remarks' => '红包剩余退回',
|
||||
'createtime' => time()
|
||||
];
|
||||
|
||||
$res = Db::name('vs_user_money_log')->insert($data);
|
||||
if(!$res || !$addres){
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新红包状态为已结束
|
||||
Db::name('redpacket')
|
||||
->where('id', $redpacket['id'])
|
||||
->update([
|
||||
'status' => Redpacket::STATUS_FINISHED,
|
||||
'updatetime' => $now
|
||||
]);
|
||||
|
||||
// 更新Redis缓存
|
||||
$redis = Cache::store('redis')->handler();
|
||||
$redisKey = "redpacket:{$redpacket['id']}";
|
||||
$redis->hSet($redisKey, 'status', Redpacket::STATUS_FINISHED);
|
||||
|
||||
Db::commit();
|
||||
$processedCount++;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
// 记录日志
|
||||
\think\Log::error("红包退款失败: {$redpacket['id']}, 错误: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
echo "处理过期红包-共". $processedCount . "条数据\n";
|
||||
}
|
||||
|
||||
}
|
||||
405
application/cron/controller/RoomHourRanking.php
Normal file
405
application/cron/controller/RoomHourRanking.php
Normal file
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use app\common\controller\Push;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
class RoomHourRanking
|
||||
{
|
||||
/*
|
||||
* 运行函数
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
echo "小时榜 开始发礼物:\n";
|
||||
$this->send_gift();//小时榜 送礼物
|
||||
echo "发礼物结束 \n";
|
||||
|
||||
}
|
||||
|
||||
public function send_gift()
|
||||
{
|
||||
//获取上一个小时的开始时间和结束时间
|
||||
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
$end_time = strtotime(date('Y-m-d H:00:00'));
|
||||
echo "开始时间:" .$start_time."\n";
|
||||
echo "结束时间:" .$end_time."\n";
|
||||
//当前小时的前一个小时(24小时计时法,0-23)
|
||||
$pre_hour = date('H', strtotime('-1 hour'));
|
||||
echo "上个时间段:" .$pre_hour."\n";
|
||||
$is_open_time = db::name('vs_hour_ranking_config')->where('id', 1)->value('open_time');
|
||||
if ($is_open_time == 0) {
|
||||
echo "未开启时间段:" .$is_open_time."\n";
|
||||
return;
|
||||
}
|
||||
//是否全局飘瓶
|
||||
$is_public_server = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_public_server');
|
||||
if ($is_public_server == 1) {
|
||||
//全局飘瓶时间段
|
||||
$xlh_time_range = db::name('vs_hour_ranking_config')->where('id', 1)->value('broadcast_times');
|
||||
if($xlh_time_range){
|
||||
if($xlh_time_range == 25){
|
||||
$is_piao = 1;
|
||||
}else{
|
||||
|
||||
//当前的前一个小时是否在 $xlh_time_range中
|
||||
if (in_array($pre_hour, explode(',', $xlh_time_range))) {
|
||||
$is_piao = 1;
|
||||
} else {
|
||||
$is_piao = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$is_piao = 0;
|
||||
}
|
||||
}else{
|
||||
$is_piao = 0;
|
||||
}
|
||||
|
||||
//获取上一个时间段的配置
|
||||
// $gift_list = db::name('vs_hour_ranking_gift_config')->where('time_id',$pre_hour)->group('ranking')->order('id', 'desc')->select();
|
||||
$gift_list = $this->get_hour_ranking($pre_hour);
|
||||
// echo "上个时间段的配置:" .json_encode($gift_list)."\n";
|
||||
// 提取所有有奖励的内容
|
||||
$allRewards = $this->extractAllRewards($gift_list);
|
||||
// 按index分组
|
||||
$groupedRewards = $this->groupRewardsByIndex($allRewards);
|
||||
// 按名次顺序分配奖励
|
||||
$distributionResult = $this->distributeByRank($groupedRewards);
|
||||
|
||||
//获取上个数组的个数,从而获取配置了多少个名次
|
||||
$count = count($distributionResult);
|
||||
echo "上个时间段的配置总数:" .$count."\n";
|
||||
//获取前一个小时的 前$count名房间排行
|
||||
$room_list = model('api/RoomHourRanking')->room_hour_ranking(1, $count, $start_time, $end_time);
|
||||
$room_owner = [];
|
||||
if ($room_list['code'] == 1) {
|
||||
//获取房间排行奖励最低值
|
||||
$min_price = db::name('vs_hour_ranking_config')->where('id', 1)->value('min_price');
|
||||
if ($room_list['data']['lists']) {
|
||||
echo "房间列表:" .json_encode($room_list['data']['lists'])."\n";
|
||||
foreach ($room_list['data']['lists'] as $v){
|
||||
if ($v['total_price'] >= $min_price) {
|
||||
$room_owner[] = [
|
||||
'user_id' => $v['user_id'],
|
||||
'room_name' => $v['room_name'],
|
||||
'room_id' => $v['room_id'],
|
||||
'total_price' => $v['total_price']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($distributionResult && $room_owner) {
|
||||
$text_list_new = [];
|
||||
echo "礼物数:" .json_encode($distributionResult)."\n";
|
||||
echo "房主:" .json_encode($room_owner)."\n";
|
||||
foreach ($distributionResult as $k => $value) {
|
||||
//礼物全部给他偷偷放在装扮表及金额 中
|
||||
//有几个用户就发几个
|
||||
if(count($room_owner) > $k){
|
||||
// 为每个房间添加一个标志,表示是否已处理推送信息
|
||||
$hasProcessedPush = false;
|
||||
|
||||
foreach ($value['rewards'] as $v){
|
||||
if($v['type'] == 0){//1金币2礼物3头像4坐骑
|
||||
echo "发金币:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
|
||||
$res = $this->add_coin($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
|
||||
}elseif ($v['type'] == 1){
|
||||
echo "发礼物:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
|
||||
$res = $this->add_gift($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
|
||||
}elseif ($v['type'] == 2){
|
||||
$res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,3);
|
||||
}elseif ($v['type'] == 3){
|
||||
$res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,4);
|
||||
}
|
||||
// 只有在第一次处理奖励时添加推送信息,避免重复推送
|
||||
if(!$hasProcessedPush && $is_piao == 1) {
|
||||
$room_name = $room_owner[$k]['room_name'];
|
||||
//推送礼物横幅
|
||||
if ($k == 0) {
|
||||
$text = '新科状元!【' . $room_name . '】独占鳌头!';
|
||||
} elseif ($k == 1) {
|
||||
$text = '金榜榜眼!【' . $room_name . '】才气逼人!';
|
||||
} elseif ($k == 2) {
|
||||
$text = '风采探花!【' . $room_name . '】实力绽放!';
|
||||
}
|
||||
|
||||
$text_list_new[] = [
|
||||
'text' => $text ?? '恭喜【' . $room_name . '】获得礼物!',
|
||||
'room_id' => $room_owner[$k]['room_id'],
|
||||
'room_name' => $room_name,
|
||||
'rank_number' => $k + 1,
|
||||
];
|
||||
|
||||
$hasProcessedPush = true; // 标记已处理推送
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(!empty($text_list_new)){
|
||||
$push = new Push();
|
||||
$push->hourRanking($text_list_new);
|
||||
}
|
||||
}
|
||||
echo "送礼-共" . count($room_owner) . "个房间房主获益\n";
|
||||
}
|
||||
|
||||
//添加金币到钱包
|
||||
public function add_coin($coin,$user_id,$ranking,$room_id,$total_price,$is_piao){
|
||||
if($coin > 0){
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'change_value' => $coin,
|
||||
// 'room_id' => $room_ids,
|
||||
'money_type' => 1,
|
||||
'change_type' => 27,
|
||||
'from_id' => 0,
|
||||
'remarks' => '小时榜获得',
|
||||
'createtime' => time()
|
||||
];
|
||||
|
||||
//开启事务
|
||||
Db::startTrans();
|
||||
$res = Db::name('vs_user_money_log')->insert($data);
|
||||
if(!$res){
|
||||
Db::rollback();
|
||||
}
|
||||
|
||||
//增加用户金币
|
||||
$res1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setInc('coin',$coin);
|
||||
if(!$res1){
|
||||
Db::rollback();
|
||||
}
|
||||
|
||||
//添加到排行表
|
||||
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
$end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
$res2 = db::name('vs_hour_ranking')->insert([
|
||||
'ranking' => $ranking,
|
||||
'room_id' => $room_id,
|
||||
'flowing_water' => $total_price,
|
||||
'coin' => $coin,
|
||||
'time_id' => date('H', strtotime('-1 hour')),
|
||||
'stime' => $start_time,
|
||||
'etime' => $end_time,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time(),
|
||||
'is_public_server' => $is_piao
|
||||
]);
|
||||
if(!$res2){
|
||||
Db::rollback();
|
||||
}
|
||||
Db::commit();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//添加礼物到背包
|
||||
public function add_gift($gift_id,$user_id,$ranking,$room_id,$total_price,$is_piao){
|
||||
$res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$gift_id,1,model('UserGiftPack')::HOUR_RANK_GET,"小时榜获得");
|
||||
if($res['code'] == 0){
|
||||
Log::record("小时榜获取礼物失败:".$res['msg'],"info");
|
||||
}
|
||||
|
||||
//添加到排行表
|
||||
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
$end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
$res2 = db::name('vs_hour_ranking')->insert([
|
||||
'ranking' => $ranking,
|
||||
'room_id' => $room_id,
|
||||
'flowing_water' => $total_price,
|
||||
'gift_id' => $gift_id,
|
||||
'gift_type' => 2,
|
||||
'time_id' => date('H', strtotime('-1 hour')),
|
||||
'stime' => $start_time,
|
||||
'etime' => $end_time,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time(),
|
||||
'is_public_server' => $is_piao
|
||||
]);
|
||||
if(!$res2){
|
||||
Log::record("小时榜礼物锁定失败","info");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//添加装扮到背包
|
||||
public function add_decorate($avatar_id,$user_id,$ranking,$room_id,$total_price,$is_piao,$type){
|
||||
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$avatar_id])->find();
|
||||
if(empty($decorate_price_info)){
|
||||
Log::record("小时榜获取装扮失败:没有找到装扮!".$avatar_id,"info");
|
||||
}
|
||||
$res = model('api/Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],2);
|
||||
if($res['code'] == 0){
|
||||
Log::record("小时榜获取装扮失败:".$res['msg']."-".$avatar_id,"info");
|
||||
}
|
||||
//添加到排行表
|
||||
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
$end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
$res2 = db::name('vs_hour_ranking')->insert([
|
||||
'ranking' => $ranking,
|
||||
'room_id' => $room_id,
|
||||
'flowing_water' => $total_price,
|
||||
'gift_id' => $avatar_id,
|
||||
'gift_type' => $type,
|
||||
'time_id' => date('H', strtotime('-1 hour')),
|
||||
'stime' => $start_time,
|
||||
'etime' => $end_time,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time(),
|
||||
'is_public_server' => $is_piao,
|
||||
]);
|
||||
if(!$res2){
|
||||
Log::record("小时榜咋装扮锁定失败","info");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提取所有有奖励的内容
|
||||
*/
|
||||
private function extractAllRewards($responseData)
|
||||
{
|
||||
$allRewards = [];
|
||||
|
||||
foreach ($responseData as $timeSlot) {
|
||||
foreach ($timeSlot['reward'] as $rewardItem) {
|
||||
$index = $rewardItem['index'];
|
||||
$content = $rewardItem['content'];
|
||||
|
||||
// 只处理有奖励内容的数据
|
||||
if (!empty($content)) {
|
||||
foreach ($content as $rewardContent) {
|
||||
$allRewards[] = [
|
||||
'index' => $index,
|
||||
'type' => $rewardContent['type'],
|
||||
'value' => $rewardContent['value'],
|
||||
'name' => $rewardContent['name'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $allRewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按index分组奖励
|
||||
*/
|
||||
private function groupRewardsByIndex($allRewards)
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($allRewards as $reward) {
|
||||
$index = $reward['index'];
|
||||
if (!isset($grouped[$index])) {
|
||||
$grouped[$index] = [];
|
||||
}
|
||||
$grouped[$index][] = $reward;
|
||||
}
|
||||
|
||||
// 按index排序
|
||||
ksort($grouped);
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按名次顺序分配奖励
|
||||
*/
|
||||
private function distributeByRank($groupedRewards)
|
||||
{
|
||||
$distribution = [];
|
||||
$currentRank = 0; // 从第1名开始
|
||||
|
||||
// 按index顺序分配(index 0 = 第1名,index 1 = 第2名,以此类推)
|
||||
foreach ($groupedRewards as $index => $rewards) {
|
||||
// 确保名次连续,如果有空缺则填充空名次
|
||||
while ($currentRank < $index) {
|
||||
$distribution[] = [
|
||||
'rank' => $currentRank + 1,
|
||||
'rewards' => []
|
||||
];
|
||||
$currentRank++;
|
||||
}
|
||||
|
||||
// 分配当前名次的奖励
|
||||
$distribution[] = [
|
||||
'rank' => $currentRank + 1,
|
||||
'rewards' => $rewards
|
||||
];
|
||||
$currentRank++;
|
||||
}
|
||||
|
||||
return $distribution;
|
||||
}
|
||||
|
||||
public function get_hour_ranking($time){
|
||||
// 先按时间段和排名索引分组查询
|
||||
$timeRanges = db::name('vs_hour_ranking_gift_config')->distinct(true)
|
||||
->where('time_id', '=', $time)
|
||||
->order('time_id')
|
||||
->column('time_id');
|
||||
|
||||
$result = [];
|
||||
foreach ($timeRanges as $timeRange) {
|
||||
// 查询该时间段的所有数据
|
||||
$rewards = db::name('vs_hour_ranking_gift_config')->where('time_id', $timeRange)
|
||||
->field('ranking, gift_type, gift_id,coin,name')
|
||||
->order('ranking')
|
||||
->select();
|
||||
|
||||
$rewardMap = [];
|
||||
foreach ($rewards as $reward) {
|
||||
$rankIndex = $reward['ranking'];
|
||||
|
||||
if (!isset($rewardMap[$rankIndex])) {
|
||||
$rewardMap[$rankIndex] = [
|
||||
'index' => $rankIndex,
|
||||
// 'name' => $reward['rank_name'],
|
||||
'content' => []
|
||||
];
|
||||
}
|
||||
|
||||
// 添加奖励内容到content数组
|
||||
if ($reward['gift_id'] != 0 || $reward['coin'] != 0) {
|
||||
if($reward['gift_id'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['gift_id'],
|
||||
// 'coin' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
if($reward['coin'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 按index排序
|
||||
ksort($rewardMap);
|
||||
|
||||
$result[] = [
|
||||
'time' => $timeRange,
|
||||
'reward' => array_values($rewardMap)
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
195
application/cron/controller/RoomPan.php
Normal file
195
application/cron/controller/RoomPan.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use app\common\controller\Push;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
|
||||
|
||||
/*
|
||||
* 定时任务,每秒执行的方法
|
||||
*/
|
||||
class RoomPan
|
||||
{
|
||||
/*
|
||||
* 运行函数
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
echo "巡乐会礼物发放开始:\n";
|
||||
$this->xlh_gift_send();//拍卖房结束提醒
|
||||
echo "礼物发放结束 \n";
|
||||
|
||||
echo "盲盒转盘礼物补发:\n";
|
||||
$this->blind_box_turntable_gift_send();//盲盒转盘礼物补发
|
||||
echo "盲盒转盘礼物补发结束 \n";
|
||||
}
|
||||
|
||||
/*
|
||||
* 盲盒转盘礼物推送补发
|
||||
*/
|
||||
public function blind_box_turntable_gift_send(){
|
||||
$blind_box_turntable = db('vs_blind_box_turntable_log')->where(['is_sued'=>0,'createtime'=>['>=',time()-60*30]])->limit(1000)->select();
|
||||
if(empty($blind_box_turntable)){
|
||||
echo "没有需要发放的礼物 \n";
|
||||
}
|
||||
echo "开始发放".count($blind_box_turntable)." \n";
|
||||
foreach ($blind_box_turntable as $k => $v) {
|
||||
$blind_box_turntable_results_log = db('vs_blind_box_turntable_results_log')->where('tid',$v['id'])->select();
|
||||
if(empty($blind_box_turntable_results_log)){
|
||||
echo $v['id']." 没有需要发放的礼物 \n";
|
||||
continue;
|
||||
}
|
||||
$room_id = $v['room_id'];
|
||||
$room_name = Db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->value('room_name');
|
||||
$FromUserInfo = Db::name('user')->where(['id'=>$v['user_id']])->find();
|
||||
$FromUserInfo['user_id'] = $FromUserInfo['id'];
|
||||
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
||||
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
|
||||
$user_nickname = $FromUserInfo['nickname'];
|
||||
$textMessage = $user_nickname;
|
||||
$text_message = $user_nickname;
|
||||
foreach ($blind_box_turntable_results_log as $key => $value) {
|
||||
$ToUserInfo = Db::name('user')->where(['id' => $value['gift_user_id']])->field('id as user_id,nickname,avatar,sex')->find();
|
||||
$draw_gift = Db::name('vs_gift')->where(['gid'=>$value['gift_id']])->find();
|
||||
$textMessage = $textMessage . ' 送给 ' . $ToUserInfo['nickname']. ' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$value['count']."\n";
|
||||
$play_image[] = $draw_gift['play_image'];
|
||||
$gift_names[] = $draw_gift['gift_name'];
|
||||
|
||||
$text_message = $text_message . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $value['count']."\n";
|
||||
if($draw_gift['is_public_server'] == 1) {
|
||||
$text_list_new[] = [
|
||||
'text' => $text_message,
|
||||
'gift_picture' => $draw_gift['base_image'],
|
||||
'room_id' => $room_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $draw_gift['gift_name'],
|
||||
'roomId' => $room_id,
|
||||
'number' => $value['count'],
|
||||
];
|
||||
}
|
||||
$ToUserInfosList[$value['gift_user_id']] = $ToUserInfo;
|
||||
}
|
||||
foreach($ToUserInfosList as &$userInfo) {
|
||||
$userInfo['icon'][0] = model('UserData')->user_wealth_icon($userInfo['user_id']);//财富图标
|
||||
$userInfo['icon'][1] = model('UserData')->user_charm_icon($userInfo['user_id']);//魅力图标
|
||||
$userInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $userInfo['user_id'],'room_id' => $room_id])->value('charm');//魅力
|
||||
$ToUserInfos[] = $userInfo;
|
||||
}
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfos' => $ToUserInfos,
|
||||
'GiftInfo' => [
|
||||
'play_image' => implode(',',$play_image),
|
||||
'gift_name' => implode(',',$gift_names),
|
||||
],
|
||||
'text' => rtrim($textMessage, "\n")
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1005,$room_id,$text);
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $room_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $room_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $room_id,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$room_id,$text1);
|
||||
}else{
|
||||
if(!empty($text_list_new)){
|
||||
//推送礼物横幅
|
||||
$push = new Push($v['user_id'], $room_id);
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
}
|
||||
db::name('vs_blind_box_turntable_log')->where('id', $v['id'])->update(['is_sued' => 1, 'updatetime' => time()]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会结束 礼物发放 【定时脚本】
|
||||
*/
|
||||
public function xlh_gift_send(){
|
||||
$xlh_list = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'end_time'=>['<=',time()]])->select();
|
||||
if(empty($xlh_list)){
|
||||
echo "没有需要发放的礼物 \n";
|
||||
}
|
||||
foreach ($xlh_list as $key=>$value){
|
||||
try{
|
||||
if($value['user_id'] == 0){
|
||||
echo "第.".$value['periods']." 巡乐会结束 没有中奖用户 \n";
|
||||
$res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([
|
||||
'send_time' => time()
|
||||
]);
|
||||
// db::name("vs_room")->where('id',$value['room_id'])->update([
|
||||
// 'xlh_periods_num' => 0
|
||||
// ]);
|
||||
Cache::set("xlh_periods_num", 0, 0);
|
||||
//推送礼物横幅
|
||||
$text = "本轮巡乐会已结束,请大家重新开始下一轮巡乐会";
|
||||
$push = new Push(0, $value['room_id']);
|
||||
$text_list_new = [
|
||||
'text' => $text,
|
||||
'room_id' => $value['room_id'],
|
||||
'from_type' => 104
|
||||
];
|
||||
$push->xunlehui($text_list_new);
|
||||
continue;
|
||||
}
|
||||
//发放
|
||||
//抽中礼物落包
|
||||
$res = [];
|
||||
$res = model('api/UserGiftPack')->change_user_gift_pack($value['user_id'],$value['gift_id'],$value['num'],model('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖发放");
|
||||
if ($res['code'] != 1) {
|
||||
echo $res['msg']."\n";
|
||||
continue;
|
||||
}
|
||||
echo "巡乐会中奖礼物发放成功 用户Id:".$value['user_id']."\n";
|
||||
//房主礼物落包
|
||||
$res = [];
|
||||
//获取房主id
|
||||
$user_id = db::name('vs_room')->where(['id'=>$value['room_id']])->value('user_id');
|
||||
$res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$value['homeowner_gift_id'],1,model('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖后房主礼物发放");
|
||||
if ($res['code'] != 1) {
|
||||
echo $res['msg']."\n";
|
||||
continue;
|
||||
}
|
||||
echo "巡乐会中奖后房主礼物发放成功 房主Id:".$user_id."\n";
|
||||
//处理发放记录
|
||||
$res = [];
|
||||
$res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([
|
||||
'send_time' => time()
|
||||
]);
|
||||
$xlh_log = db::name('vs_room_pan_xlh_log')->where(['xlh_id'=>$value['id'],'user_id'=>$value['user_id']])->order('id desc')->find();
|
||||
$res = db::name('vs_room_pan_xlh_log')->where('id',$xlh_log['id'])->update([
|
||||
'is_send' => 1
|
||||
]);
|
||||
if ($res === false) {
|
||||
echo "处理发放记录失败 \n";
|
||||
continue;
|
||||
}
|
||||
Cache::set("xlh_periods_num", 0, 0);
|
||||
//推送
|
||||
$FromUserInfo = db::name('user')->field('nickname,avatar')->where(['id'=>$value['user_id']])->find();
|
||||
$gift_name = db::name('vs_gift')->where(['gid'=>$value['gift_id']])->value('gift_name');
|
||||
$text = $FromUserInfo['nickname'] . ' 用户在巡乐会中 ' .$gift_name.'礼物 x ' .$value['num']." 已收入背包";
|
||||
//推送礼物横幅
|
||||
$push = new Push(0, $value['room_id']);
|
||||
$text_list_new = [
|
||||
'text' => $text,
|
||||
'room_id' => $value['room_id'],
|
||||
'from_type' => 104
|
||||
];
|
||||
$push->xunlehui($text_list_new);
|
||||
}catch (\Exception $e){
|
||||
echo $e->getMessage()."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,24 +30,37 @@ class Subsidy
|
||||
*/
|
||||
public function createGuildSubsidyData(){
|
||||
//获取上周第一天时间
|
||||
$week_start_time = strtotime('-1 weeklast monday');
|
||||
$week_end_time = strtotime('last sunday');
|
||||
// $week_start_time = strtotime('this week monday');
|
||||
// $week_end_time = strtotime('sunday');
|
||||
$week_start_time = strtotime('last week Monday');
|
||||
$week_end_time = strtotime(date('Y-m-d 23:59:59',strtotime('last week Sunday')));
|
||||
// $week_start_time = strtotime('2025-09-29');
|
||||
// $week_end_time = strtotime('2025-09-29 23:59:59');
|
||||
|
||||
//获取上周时间
|
||||
$time_value = date('o-W', strtotime('-1 week'));
|
||||
$time_value = date('o-W', $week_start_time);
|
||||
echo $time_value . "工会周补贴数据生成开始\n";
|
||||
//查询所有工会
|
||||
$guild_list = db::name('vs_guild')->where(['delete_time'=>0])->field('id')->select();
|
||||
$data_count = 0;
|
||||
foreach ($guild_list as $key => $value) {
|
||||
//获取所有工会房间ID
|
||||
$room_ids = db::name('vs_guild_user')->where('guild_id', $value['id'])->field('room_id')->select();
|
||||
$room_ids = array_column($room_ids, 'room_id');
|
||||
$transaction = db::name('vs_give_gift')
|
||||
->whereIn('from_id',$room_ids)
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$week_start_time, $week_end_time]]])
|
||||
->sum('total_price');
|
||||
$guild_user_data = db::name('vs_guild_user')->where('guild_id', $value['id'])->field('room_id,createtime,quit_time')->select();
|
||||
$transaction = 0;
|
||||
foreach ($guild_user_data as $k => $v) {
|
||||
$week_start_time_seach = $week_start_time;
|
||||
$week_end_time_seach = $week_end_time;
|
||||
if($v['createtime'] && $week_start_time_seach < $v['createtime']){
|
||||
$week_start_time_seach = $v['createtime'];
|
||||
}
|
||||
if($v['quit_time'] && ($week_end_time_seach > $v['quit_time'])){
|
||||
$week_end_time_seach = $v['quit_time'];
|
||||
}
|
||||
$transaction_one = db::name('vs_give_gift')
|
||||
->whereIn('from_id',$v['room_id'])
|
||||
->where(['from'=>['in',[2,3,6]],'createtime' => ['between', [$week_start_time_seach, $week_end_time_seach]]])
|
||||
->sum('total_price');
|
||||
$transaction += $transaction_one;
|
||||
}
|
||||
|
||||
if($transaction > 0){
|
||||
//判断是否已经生成过
|
||||
if (db::name('vs_guild_subsidy')->where(['guild_id'=>$value['id'],'week'=>$time_value])->find()) {
|
||||
@@ -64,7 +77,7 @@ class Subsidy
|
||||
foreach ($config as $k => $v) {
|
||||
if ($transaction >= $v['end_amount']) {
|
||||
$subsidy_ratio = $v['subsidy_ratio'];
|
||||
$subsidy_amount = $transaction * ($subsidy_ratio / 100);
|
||||
$subsidy_amount = ($transaction * ($subsidy_ratio / 100)) / get_system_config_value('rmb_coin_ratio');//转为钻石
|
||||
break; // 找到匹配项后提前退出循环
|
||||
}
|
||||
}
|
||||
@@ -80,6 +93,7 @@ class Subsidy
|
||||
'status' => 0,
|
||||
'createtime' => time(),
|
||||
];
|
||||
// echo "工会".$value['id']."生成数据:流水金额:{$transaction} 补贴比例:{$subsidy_ratio}% 补贴金额:{$subsidy_amount}\n";
|
||||
$subsidy_id = Db::name('vs_guild_subsidy')->insertGetId($data);
|
||||
if ($subsidy_id) {
|
||||
echo "工会".$value['id']."生成成功(补贴ID:".$subsidy_id." 补贴金额:".$subsidy_amount.")\n";
|
||||
@@ -97,12 +111,13 @@ class Subsidy
|
||||
*/
|
||||
public function createRoomSubsidyData(){
|
||||
//获取上周第一天时间
|
||||
$week_start_time = strtotime('-1 weeklast monday');
|
||||
$week_end_time = strtotime('last sunday');
|
||||
// $week_start_time = strtotime('this week monday');
|
||||
// $week_end_time = strtotime('sunday');
|
||||
$week_start_time = strtotime('last monday');
|
||||
$week_end_time = strtotime(date('Y-m-d 23:59:59',strtotime('last sunday')));
|
||||
// $week_start_time = strtotime('2025-08-11');
|
||||
// $week_end_time = strtotime('2025-08-17 23:59:59');
|
||||
|
||||
//获取上周时间
|
||||
$time_value = date('o-W', strtotime('-1 week'));
|
||||
$time_value = date('o-W', $week_start_time);
|
||||
echo $time_value . "房间周补贴数据生成开始\n";
|
||||
//查询所有房间
|
||||
$room_list = db::name('vs_room')->where(['delete_time'=>0,'is_earnings'=>1])->field('id')->select();
|
||||
@@ -128,7 +143,7 @@ class Subsidy
|
||||
foreach ($config as $k => $v) {
|
||||
if ($transaction >= $v['end_amount']) {
|
||||
$subsidy_ratio = $v['subsidy_ratio'];
|
||||
$subsidy_amount = $transaction * ($subsidy_ratio / 100);
|
||||
$subsidy_amount = ($transaction * ($subsidy_ratio / 100)) / get_system_config_value('rmb_coin_ratio');//转为钻石;
|
||||
break; // 找到匹配项后提前退出循环
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,14 @@ class TenSeconds
|
||||
echo "房间在线人数:\n";
|
||||
$this->auction_end_notice();//拍卖房结束提醒
|
||||
echo "\n";
|
||||
//清理切后台超过5分钟的用户
|
||||
echo "清理切后台超过5分钟的用户\n";
|
||||
$this->clear_offline_user();
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
||||
//在线人数
|
||||
protected function auction_end_notice()
|
||||
{
|
||||
$auction_list = db::name('vs_room')->field('id')->where(['room_status'=>1,'apply_status' => 2,'type_id' =>['<>',6]])->select();
|
||||
@@ -40,17 +45,6 @@ class TenSeconds
|
||||
$data_number++;
|
||||
}
|
||||
}
|
||||
// else{
|
||||
// if($on_pit_num > 0){
|
||||
// $text = [
|
||||
// 'online_number' => $on_pit_num,
|
||||
// 'room_id' => $value['id'],//接受房间id
|
||||
// ];
|
||||
// model('api/Chat')->sendMsg(1036,$value['id'],$text);
|
||||
// $data_number++;
|
||||
// }
|
||||
// }
|
||||
|
||||
$data_count++;
|
||||
}
|
||||
}
|
||||
@@ -58,4 +52,18 @@ class TenSeconds
|
||||
echo "房间在线人数>0 的总共" . $data_number . "条数据\n";
|
||||
}
|
||||
|
||||
//清理切后台超过5分钟的用户
|
||||
protected function clear_offline_user()
|
||||
{
|
||||
$time = time() - 300;
|
||||
$user_list = db::name('vs_user_in_room_bg')->where('updatetime', '<=', $time)->select();
|
||||
if($user_list){
|
||||
foreach ($user_list as $v){
|
||||
//删除
|
||||
db::name('vs_user_in_room_bg')->delete($v['id']);
|
||||
model('api/Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id'],2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
158
application/cron/controller/Test.php
Normal file
158
application/cron/controller/Test.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use think\Db;
|
||||
use Yzh\YunPay;
|
||||
|
||||
/*
|
||||
* 定时任务,每秒执行的方法
|
||||
*/
|
||||
class Test
|
||||
{
|
||||
/*
|
||||
* 运行函数
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
// 设置脚本执行时间无限
|
||||
set_time_limit(0);
|
||||
echo "统计盲盒转盘错误数据\n";
|
||||
$this->blind_box_error();
|
||||
echo "\n";
|
||||
|
||||
}
|
||||
|
||||
//统计盲盒转盘错误数据
|
||||
public function blind_box_error()
|
||||
{
|
||||
die("暂停");
|
||||
// 设置数据库查询超时时间
|
||||
Db::query("SET SESSION wait_timeout=600");
|
||||
Db::query("SET SESSION interactive_timeout=600");
|
||||
|
||||
// 使用连表查询,直接找出送给多人的数据
|
||||
echo "开始查询送给多人的数据...\n";
|
||||
|
||||
// 先查询所有有多个不同 gift_user_id 的 tid
|
||||
$multipleGiftRecords = Db::name('vs_blind_box_turntable_results_log')
|
||||
->group('tid')
|
||||
->having('COUNT(DISTINCT gift_user_id) > 1')
|
||||
->field('tid, COUNT(DISTINCT gift_user_id) as user_count,gift_user_id')
|
||||
->select();
|
||||
|
||||
echo "找到 " . count($multipleGiftRecords) . " 条送给多人的记录\n";
|
||||
|
||||
// 输出详细信息
|
||||
foreach ($multipleGiftRecords as $record) {
|
||||
echo "转盘ID: {$record['tid']}, 接收人数: {$record['user_count']}\n";
|
||||
// 获取该转盘的详细信息
|
||||
$turntableInfo = Db::name('vs_blind_box_turntable_log')
|
||||
->where('id', $record['tid'])
|
||||
->find();
|
||||
|
||||
if ($turntableInfo) {
|
||||
echo " 开奖用户ID: {$turntableInfo['user_id']}, 礼包ID: {$turntableInfo['gift_bag_id']}\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "统计盲盒转盘错误数据完成\n";
|
||||
}
|
||||
|
||||
//统计盲盒转盘错误数据
|
||||
public function blind_box_error1()
|
||||
{
|
||||
die("暂停");
|
||||
// 设置数据库查询超时时间
|
||||
Db::query("SET SESSION wait_timeout=600");
|
||||
Db::query("SET SESSION interactive_timeout=600");
|
||||
|
||||
// 分批处理数据,避免一次性加载大量数据到内存
|
||||
$batchSize = 1000;
|
||||
$offset = 0;
|
||||
$data_multiple = [];
|
||||
$totalProcessed = 0;
|
||||
|
||||
do {
|
||||
// 分批获取数据
|
||||
$turntable_log = Db::name('vs_blind_box_turntable_log')
|
||||
->limit($offset, $batchSize)
|
||||
->select();
|
||||
|
||||
// 如果没有更多数据,退出循环
|
||||
if (empty($turntable_log)) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($turntable_log as $key => $value) {
|
||||
//查询本轮是否有多个接收礼物的人
|
||||
$turntable_results_log = Db::name('vs_blind_box_turntable_results_log')
|
||||
->where('tid', $value['id'])
|
||||
->group('gift_user_id')
|
||||
->select();
|
||||
|
||||
// 统计送给多人的数据
|
||||
if (count($turntable_results_log) > 1) {
|
||||
$data_multiple[] = [
|
||||
'turntable_id' => $value['id'],
|
||||
'recipient_count' => count($turntable_results_log),
|
||||
'data' => $value
|
||||
];
|
||||
}
|
||||
|
||||
$totalProcessed++;
|
||||
|
||||
// 每处理100条记录输出一次进度
|
||||
if ($totalProcessed % 100 == 0) {
|
||||
echo "已处理 {$totalProcessed} 条记录...\n";
|
||||
// 每100条记录后清理内存
|
||||
gc_collect_cycles();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新偏移量
|
||||
$offset += $batchSize;
|
||||
|
||||
// 释放内存
|
||||
unset($turntable_log);
|
||||
unset($turntable_results_log);
|
||||
|
||||
} while ($totalProcessed <= 1400);
|
||||
|
||||
echo "送给多人的数据共 " . count($data_multiple) . " 条记录\n";
|
||||
echo "统计盲盒转盘错误数据完成-共处理 " . $totalProcessed . " 条数据\n";
|
||||
|
||||
// 输出详细信息
|
||||
foreach ($data_multiple as $item) {
|
||||
echo "转盘ID: {$item['turntable_id']}, 接收人数: {$item['recipient_count']}\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function RoomOwners()
|
||||
{
|
||||
$room = Db::name('vs_room')->where(['room_status' => 1,'apply_status' => 2])->select();
|
||||
$arr = [];
|
||||
foreach ($room as $key => $value) {
|
||||
$liushui = Db::name('vs_give_gift')->where(['from_id' => $value['id'],'from' => 2])->sum('total_price');
|
||||
$usercode = Db::name('user')->where(['id' => $value['user_id']])->value('user_code');
|
||||
$nickname = Db::name('user')->where(['id' => $value['user_id']])->value('nickname');
|
||||
$arr[] = [
|
||||
'room_id' => $value['id'],
|
||||
'user_id' => $value['user_id'],
|
||||
'user_code' => $usercode,
|
||||
'nickname' => $nickname,
|
||||
'liushui' => $liushui
|
||||
];
|
||||
}
|
||||
|
||||
//房主的收益
|
||||
foreach ($arr as $key => $v){
|
||||
$shouyi = db::name('vs_user_money_log')->where(['user_id' => $v['user_id'],'change_type' => 18,'money_type' =>2,'createtime'=>['<',1759585380]])->sum('change_value');
|
||||
$arr[$key]['shouyi'] = $shouyi;
|
||||
$arr[$key]['duibi'] = $shouyi.'-'.$v['liushui']/10/10;
|
||||
$arr[$key]['chazhi'] = $v['liushui']/10/10 - $shouyi;
|
||||
}
|
||||
var_dump($arr);
|
||||
}
|
||||
|
||||
}
|
||||
12
application/extra/redis.php
Normal file
12
application/extra/redis.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 6379,
|
||||
'password' => '',
|
||||
'select' => 0,
|
||||
'timeout' => 0,
|
||||
'expire' => 0,
|
||||
'persistent' => false,
|
||||
'prefix' => 'fa_redpacket_',
|
||||
];
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
return array (
|
||||
'name' => '羽声(Vespa)',
|
||||
'name' => '羽声',
|
||||
'beian' => '',
|
||||
'cdnurl' => '',
|
||||
'version' => '1.0.3',
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user