1. //食品分类删除
    2. public function foodtypedelete(){
    3. $id = $_POST['id'];
    4. $where['pid'] = $id;
    5. $result = D('foodtype')->where($where)->select();
    6. if ($result) {
    7. $code['msg'] = '该分类下有子类';
    8. $code['error'] = '400';
    9. } else {
    10. $whereg['food_type'] = $id;
    11. $result = D('food')->where($whereg)->select();
    12. if ($result) {
    13. $code['msg'] = '该分类下有数据';
    14. $code['error'] = '400';
    15. } else {
    16. if (M('foodtype')->delete($id)) {
    17. $code['msg'] = '删除成功';
    18. $code['error'] = '200';
    19. } else {
    20. $code['msg'] = '删除失败';
    21. $code['error'] = '400';
    22. }
    23. }
    24. }
    25. $this->ajaxReturn(json_encode($code));
    26. }
    27. //只有一个分类的删除
    28. // 店铺删除
    29. public function foodmanagementdelete()
    30. {
    31. $id = $_POST['id'];
    32. if (M('foodmanagement')->delete($id)) {
    33. $code['msg'] = '删除成功';
    34. $code['error'] = '200';
    35. } else {
    36. $code['msg'] = '删除失败';
    37. $code['error'] = '400';
    38. }
    39. $this->ajaxReturn(json_encode($code));
    40. }
    1. 前台ajax
    2. $('.typedelete').click(function(){
    3. var that = $(this);
    4. if(confirm('您确定要删除')) {
    5. var data = {'id':that.data('id')};
    6. $.ajax({
    7. url:"{:U('/addon/WeiuidDeit/web/foodmanagementdelete')}",
    8. type:'POST',
    9. data:data,
    10. dataType:'json',
    11. success:function(data){
    12. data = JSON.parse(data);
    13. if(data.error == 200){
    14. that.parents('tr').remove();
    15. }
    16. alert(data.msg);
    17. },
    18. error:function(){alert('删除出错')}
    19. })
    20. }
    21. })