1、HTML页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<table class="table">
<tr>
<th><input type="checkbox" ></th>
<th>编号</th>
<th>收货人</th>
<th>价格</th>
<th>支付方式</th>
<th>支付状态</th>
<th>订单状态</th>
<th>发送方式</th>
<th>下单时间</th>
<th>操作</th>
</tr>
{foreach $arr as $v}
<tr>
<td><input type="checkbox" name="ck[]" value="{$arr.id}" ></td>
<td>{$v.order_number}</td>
<td>{$v.receiver}</td>
<td>{$v.price}</td>
<td>{$v.payway_name}</td>
<td>{$v.paystate_name}</td>
<td>{$v.orderstate_name}</td>
<td>{$v.sendway_name}</td>
<td>{$v.create_time}</td>
<td>
</td>
</tr>
{/foreach}
<tr>
<button type="button" class="btn btn-default" id="allcheck">全选</button>
<button type="button" class="btn btn-default" id="allnot">取消全选</button>
<button type="button" class="btn btn-default" id="fan">反选</button>
<button type="button" class="btn btn-default" onclick="moredelete()">批量删除</button>
</tr>
</table>
{$arr | raw}
</body>
<script>
//批量删除
function moredelete(){
//选择删除对象
var ck=$("input[name='ck[]']:checked");
if(ck.length==0){
alert('请选择要删除的对象');
return false;
}
//定义空数组存入
var arr=[];
$(ck).each(function (i) {
arr.push($(this).val());
})
$.ajax({
//批量删除接口
url:"",
dataType: "json",
type:"get",
data:{
'ck[]':all,
},
success:function (res) {
if(res.code==200){
alert(res.msg);
$("input[name='ck[]']:checked").parents('tr').remove();
}
}
})
}
</script>
</html>
2、路由
/*
* 批量删除
* */
Route::post('moredel','Order/mordelete');
3、控制器
/*
* 批量删除
* */
public function mordelete(Request $request){
$ids=$request->all();
// dd($ids);
foreach ($ids as $v){
$arr = implode(",",$v);
}
// dd($arr);
//业务逻辑
// Orders::mordel($arr);
$res = Db::table('Order')->whereIn('id',$arr)->delete();
if($res){
return success(200,'删除成功','');
}else{
return fail(2001,'删除失败','');
}
}