巡乐会抽奖接口提交.-bug修改
This commit is contained in:
@@ -255,49 +255,94 @@ class BlindBox extends adminApi
|
||||
$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;
|
||||
$room_ids = [];
|
||||
$target_room_ids = [];
|
||||
if(!empty($room_id)){
|
||||
$where['room_id'] = $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();
|
||||
// 处理单个房间
|
||||
$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(['room_id'=>$room_id,'gift_bag_id'=>$gift_bag_id])->delete();
|
||||
$room_ids = db::name('vs_room')->field('id')->where(['is_open_blind_box_turntable'=>1,'room_status'=>1])->select();
|
||||
$room_ids = array_column($room_ids,'id');
|
||||
// 处理所有房间
|
||||
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');
|
||||
}
|
||||
foreach ($gift_bag_detail as $k=>$v){
|
||||
$where['gift_bag_detail_id'] = $v['id'];
|
||||
$room_pan = db::name('vs_room_pan')->where($where)->select();
|
||||
if(!empty($room_pan)){
|
||||
$bag_data = db::name('vs_room_pan')->where($where)->update(['remaining_number'=>$v['quantity'],'periods'=>$periods]);
|
||||
}else{
|
||||
if($room_id){
|
||||
$bag_data = db::name('vs_room_pan')->insert([
|
||||
// 批量插入数据
|
||||
$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 ($room_ids as $mid){
|
||||
$bag_data = db::name('vs_room_pan')->insert([
|
||||
'room_id' => $mid,
|
||||
'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']]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user