后台会员的启用、禁用 -2018-12-26

2018-12-26  本文已影响0人  lhg_xz
捕sss获.PNG

1. html 页面代码

        <td class="td-manage">
                        @if($member->enable == 0)
                            <a style="text-decoration:none" onClick="member_start( this,'{{$member->nickname}}','{{$member->id}}')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe6e1;</i></a>
                        @else
                            <a style="text-decoration:none" onClick="member_stop( this,'{{$member->nickname}}','{{$member->id}}')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>
                        @endif

2. ajax 代码

//用户禁用
    function member_stop( obj,name,id){
        layer.confirm('确认要禁用id:'+id+', 昵称:"' +name+'"的用户吗?',function (index) {
            $.ajax({
                type:'post',
                url:'/admin/service/member/enable',
                datetype:'json',
                data: {
                    _enable:0,
                         id: id,
                     _token:"{{csrf_token()}}"
                },

                success:function(data){
                    $(obj).parents("tr").find(".td-manage").prepend(
                        ' <a style="text-decoration:none" onClick="member_start( this,\'{{$member->nickname}}\',\'{{$member->id}}\')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe6e1;</i></a>'
                    );
                    //
                    $(obj).parents('tr').find('.td-status').html('<span class="label label-defaunt radius">已停用</span>');

                  $(obj).remove();
                  layer.msg('已停用!',{icon:5,time:1000});

                },
                error: function(xhr, status, error) {
                    console.log(xhr);
                    console.log(status);
                    console.log(error);
                    layer.msg('ajax error', {icon:2, time:2000});
                },

            });
        });

    }
    //用户解禁
    function member_start(obj ,name,id){
        layer.confirm('确认要解封id' +id+'昵称:“'+name+'”的用户吗?',function(index){
            $.ajax({
                type:'post',
                url:'/admin/service/member/enable',
                datatype:'json',
                data:{
                    _enable:1,
                         id:id,
                     _token:"{{csrf_token()}}"
                },
                success:function(data){
                    $(obj).parents("tr").find(".td-manage").prepend(
                        ' <a style="text-decoration:none" onClick="member_stop( this,\'{{$member->nickname}}\',\'{{$member->id}}\')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe631;</i></a>'
                    );
                    //
                    $(obj).parents('tr').find('.td-status').html('');

                    $(obj).remove();
                    layer.msg('已启用!',{icon:6,time:1000});

                },
                error: function(xhr, status, error) {
                    console.log(xhr);
                    console.log(status);
                    console.log(error);
                    layer.msg('ajax error', {icon:2, time:2000});
                },
            });

        });
    }

3. 路由设置

Route::post('/service/member/enable', 'admin\MemberController@memberEnable');

4 .控制器

//用户的禁用和解禁
    public function memberEnable( Request $request){
        $m3_result = new M3Result;

        $id = $request->input('id','');
        $_enable = $request->input('_enable','');

        $res = Member::where('id',$id)->update(['enable'=>$_enable]);
        if($res)
        {
            if($_enable == 1)
            {
                $m3_result->status = 0;
                $m3_result->message ="启用成功";
            }else{
                $m3_result->status = 0;
                $m3_result->message ="禁用成功";
            }

        }else{
            if($_enable == 1)
            {
                $m3_result->status = 1;
                $m3_result->message ="启用失败";
            }else{
                $m3_result->status = 1;
                $m3_result->message ="禁用失败";
            }
        }

        return $m3_result->toJson();

    }
上一篇 下一篇

猜你喜欢

热点阅读