【无标题】后端和前端

【无标题】后端和前端,第1张

 public function index()
    {
        $name = $this->request->get('name', "");
        $password = $this->request->get('password', '');
        $phone = $this->request->get('phone', '');
        $where = [];
        if (!empty($name)) {
            array_push($where, [
                'name',
                'like',
                "%$name%"
            ]);
        }

        if (!empty($password)) {
            array_push($where, [
                'password',
                '=',
                $password
            ]);
        }

        if (!empty($phone)) {
            array_push($where, [
                'phone',
                '=',
                $phone
            ]);
        }
        $model = new peop();
        $result = $model->where($where)->paginate([

            'query' => Request::param(), //url额外参数
            'list_rows' => 5, //每页数量
        ]);
        //定义一个变量来储存$result->toArray()
        $page = $result->toArray();
        //首页
        $per_page = 1;
        //上一页
        $row_page = $page['current_page'] - 1;
        if ($row_page <= $per_page) {
            $row_page = 1;
        }
        //下一页
        $After_page = $page['current_page'] + 1;
        if ($After_page >= $page['last_page']) {
            $After_page = $page['last_page'];
        }
        //最后一页 末页
        $last_page = $page['last_page'];


        return View::fetch('index', [
            'list' => $result->toArray(),
            'name' => $name,
            'password' => $password,
            'phone' => $phone,
            'per_page' => $per_page,
            'row_page' => $row_page,
            'After_page' => $After_page,
            'last_page' => $last_page
        ]);
    }

    public function add()
    {
        if ($this->request->isGet()) {
            return View::fetch('add');
        } else {
            $data = $this->request->post();
            if (empty($data['name'])) {
                echo '用户名为空';
                die;
            }
            if (empty($data['password'])) {
                echo '密码为空';
                die;
            }
            if (empty($data['phone'])) {
                echo '手机号码为空';
                die;
            }
            if ($data['sex'] != 0 && $data['sex'] != 1) {
                echo '没有选择性别';
                die;
            }
            $data['date_time'] = date('Y-m-d H:i:s');
            $data['update_time'] = date('Y-m-d H:i:s');
            $model = new peop();
            if ($model->save($data)) {
                echo '新增成功 用户列表';
            } else {
                echo '新增失败';
            }
        }
    }

    public function edit()
    {
        $id = $this->request->get('id');
        if (empty($id)) {
            echo 'id值有误';
            die;
        }
        $model = new peop();
        $result = $model->find($id);
        if (empty($result)) {
            echo '找不到该记录';
            die;
        }
        $oldtime = strtotime($result['date_time']);
        $result['date_time'] = date('Y-m-d', $oldtime);
//      dump($result->toArray());die;
        if ($this->request->isGet()) {
            return View::fetch('edit', [
                'result' => $result->toArray()
            ]);
        } else {
            $result['name'] = $this->request->post('name');
            $result['password'] = $this->request->post('password');
            $result['phone'] = $this->request->post('phone');
            $result['sex'] = $this->request->post('sex');
            if (empty($result['name'])){
                echo '用户名为空';
                die;
            }
            if (empty($result['password'])){
                echo '密码为空';
                die;
            }
            if (empty($result['phone'])){
                echo '手机号码为空';
                die;
            }if (empty($result['sex']!==0&&$result['sex']!==1)){
                echo '性别未选择';
                die;
            }
            if ($result->save()){
                echo '修改成功 用户列表';
            }
            else{
                echo '修改失败 用户列表';
            }
        }
    }

    public function del()
    {
        $id = $this->request->get('id');
        $model = new peop();
        $result = $model->where([
            ['id', '=', $id]
        ])->find();
        if ($result->delete()){
            return $this->success('删除成功','/admins/index','','3');
//            echo '删除成功 用户列表';
        }
        else{
            echo '删除失败 用户列表';
        }
    }
    public function login(){
        if ($this->request->isGet())
        {
            return View::fetch('login');
        }
        else{
            $name=$this->request->post('name');
            $password=$this->request->post('password');
            if (empty($name)){
                return $this->error('用户名为空','/admins/login','');
            }
            if (empty($password)){
                return $this->error('密码为空','/admins/login','');
            }
            $model = new peop();
            $where=[];
            array_push($where,[
                'name',
                '=',
                $name
            ]);
            $result = $model->where($where)->find();
            if (empty($result)){
                return $this->error('用户名或密码错误','/admins/login','');
            }
            if ($result['password']!=$password){
                return $this->error('用户名或密码错误','/admins/login','');
            }
            return $this->success('登录成功','/admins/index','','0');
        }

    }



    
    
    
    



    







    
    
    
    



    
    

新增用户


用户名 密码 性别 手机号码 开户时间 状态 *** 作
" >修改 " >删除

&password=&phone=&page=">首页 &password=&phone=&page=">上一页 &password=&phone=&page=">下一页 &password=&phone=&page=">末页




    
    Title









    
    Title






欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1322539.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-12
下一篇 2022-06-12

发表评论

登录后才能评论

评论列表(0条)

保存