thinkphp使用模型model批量更新数据库切换fastadmin
示例
控制器
public function is_shenghe()
{
$post = $this->request->post();
$ids = empty($post['ids']) ? [] : $post['ids'];
$is_shenghe = (int)request()->request("is_shenghe");
if (!$ids) {
$this->error("请选择要操作的数据");
}
$this->model->where('id', 'in', $ids)->where('product_name', '<>', '')->update(['is_shenghe' => $is_shenghe]);
$this->success("批量操作成功");
}
视图列表index.html
<a class="btn btn-success is_shenghe btn-disabled disabled" href="javascript:;" data-params="1"><i class="fa fa-eye is_shenghe"></i> 批准</a>
<a class="btn btn-success is_shenghe btn-disabled disabled" href="javascript:;" data-params="2"><i class="fa fa-eye-slash is_shenghe"></i> 拒绝</a>
/assets/js/backend/kuaidi.js的index方法中
// 为表格绑定事件
Table.api.bindevent(table);
// 绑定批量操作按钮的点击事件
$('#toolbar .is_shenghe').click(function () {
var ids = Table.api.selectedids(table);
var is_shenghe = $(this).data('params'); // 获取按钮的数据参数
console.log(1111,ids, is_shenghe);
// return;
if (ids.length === 0) {
Layer.alert("请选择要操作的数据");
return;
}
// 发送批量审核请求
$.ajax({
url: "message/kuaidi/is_shenghe",
method: 'POST',
data: {
ids: ids,
is_shenghe: is_shenghe
},
success: function (data) {
if (data.code === 1) {
Layer.alert("操作成功");
table.bootstrapTable('refresh');
} else {
Layer.alert("操作失败:" + data.message);
}
}
});
});
结束