//食品分类删除
public function foodtypedelete(){
$id = $_POST['id'];
$where['pid'] = $id;
$result = D('foodtype')->where($where)->select();
if ($result) {
$code['msg'] = '该分类下有子类';
$code['error'] = '400';
} else {
$whereg['food_type'] = $id;
$result = D('food')->where($whereg)->select();
if ($result) {
$code['msg'] = '该分类下有数据';
$code['error'] = '400';
} else {
if (M('foodtype')->delete($id)) {
$code['msg'] = '删除成功';
$code['error'] = '200';
} else {
$code['msg'] = '删除失败';
$code['error'] = '400';
}
}
}
$this->ajaxReturn(json_encode($code));
}
//只有一个分类的删除
// 店铺删除
public function foodmanagementdelete()
{
$id = $_POST['id'];
if (M('foodmanagement')->delete($id)) {
$code['msg'] = '删除成功';
$code['error'] = '200';
} else {
$code['msg'] = '删除失败';
$code['error'] = '400';
}
$this->ajaxReturn(json_encode($code));
}
前台ajax
$('.typedelete').click(function(){
var that = $(this);
if(confirm('您确定要删除')) {
var data = {'id':that.data('id')};
$.ajax({
url:"{:U('/addon/WeiuidDeit/web/foodmanagementdelete')}",
type:'POST',
data:data,
dataType:'json',
success:function(data){
data = JSON.parse(data);
if(data.error == 200){
that.parents('tr').remove();
}
alert(data.msg);
},
error:function(){alert('删除出错')}
})
}
})