更新
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user