<?php

namespace app\admin\controller;
use think\Lang;

class Certification extends AdminControl
{

    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/db.lang.php');

    }

    /**
     * 个人实名认证列表
     * @return mixed
     */
    public function personal()
    {
        $userinfo = Model('User');

        $condition = array();
        $condition['user_type'] = '1';
        $condition['user_status'] = '2';
        $user_list = $userinfo->getUserList($condition, '*', 10);
        for($i=0;$i<count($user_list);$i++){
            $user_list[$i]['user_addTime'] = date("Y-m-d H:i:s",$user_list[$i]['user_addTime']);

            if($user_list[$i]['user_status'] == -1){
                $user_list[$i]['user_status'] = '未实名认证';
            }
            if($user_list[$i]['user_status'] == 2){
                $user_list[$i]['user_status'] = '实名认证中';
            }
            if($user_list[$i]['user_status'] == 1){
                $user_list[$i]['user_status'] = '已实名认证';
            }
            if($user_list[$i]['user_status'] == 3){
                $user_list[$i]['user_status'] = '实名认证失败';
            }

            if($user_list[$i]['user_type'] == 1){
                $user_list[$i]['user_type'] = '个人用户';
            }
            if($user_list[$i]['user_type'] == 2){
                $user_list[$i]['user_type'] = '企业用户';
            }
        }

        $allpower = $this->qxhans();
        $this->assign('allpower',$allpower);
        $this->setAdminCurItem('db');
        $this->assign('user_list',$user_list);
        return $this->fetch('personal');
    }

    /**
     * 企业实名认证列表
     * @return mixed
     */
    public function enterprise()
    {
        $userinfo = Model('User');

        $condition = array();
        $condition['user_type'] = '2';
        $condition['user_status'] = '2';
        $user_list = $userinfo->getUserList($condition, '*', 10);
        for($i=0;$i<count($user_list);$i++){
            $user_list[$i]['user_addTime'] = date("Y-m-d H:i:s",$user_list[$i]['user_addTime']);

            if($user_list[$i]['user_status'] == -1){
                $user_list[$i]['user_status'] = '未实名认证';
            }
            if($user_list[$i]['user_status'] == 2){
                $user_list[$i]['user_status'] = '实名认证中';
            }
            if($user_list[$i]['user_status'] == 1){
                $user_list[$i]['user_status'] = '已实名认证';
            }
            if($user_list[$i]['user_status'] == 3){
                $user_list[$i]['user_status'] = '实名认证失败';
            }

            if($user_list[$i]['user_type'] == 1){
                $user_list[$i]['user_type'] = '个人用户';
            }
            if($user_list[$i]['user_type'] == 2){
                $user_list[$i]['user_type'] = '企业用户';
            }
        }

        $allpower = $this->qxhans();
        $this->assign('allpower',$allpower);
        $this->setAdminCurItem('db');
        $this->assign('user_list',$user_list);
        return $this->fetch('enterprise');
    }

    /**
     * 个人实名认证详情
     * @return mixed
     */
    public function personal_detail() {
        $user_id = $_SERVER['QUERY_STRING'];
//        print_r($user_id);
        if (request()->isPost()){
            $user_id = input('post.user_id');
            if(input('post.pass') == '通过审核'){
                $update_info = array(
                    'user_status' => 1
                );
                db('user')->where('user_id', $user_id)->update($update_info);
                return $this->redirect('Admin/Certification/personal');
            }
            if(input('post.nopass') == '未通过审核'){
                $update_info = array(
                    'user_status' => 3
                );
                db('user')->where('user_id', $user_id)->update($update_info);
                return $this->redirect('Admin/Certification/personal');
            }

        }else{
            $user = Model('User');

            $userinfo = $user->getUserInfo($user_id);

            $userinfo['user_addTime'] = date("Y-m-d H:i:s",$userinfo['user_addTime']);

            if($userinfo['user_status'] == -1){
                $userinfo['user_status'] = '未实名认证';
            }
            if($userinfo['user_status'] == 2){
                $userinfo['user_status'] = '实名认证中';
            }
            if($userinfo['user_status'] == 1){
                $userinfo['user_status'] = '已实名认证';
            }

            if($userinfo['user_type'] == 1){
                $userinfo['user_type'] = '个人用户';
            }
            if($userinfo['user_type'] == 2){
                $userinfo['user_type'] = '企业用户';
            }

            $allpower = $this->qxhans();
            $this->assign('allpower',$allpower);
            $this->assign('userinfo',$userinfo);
            return $this->fetch('personal_detail');
        }
    }

    /**
     * 企业实名认证详情
     * @return mixed
     */
    public function enterprise_detail() {
        $user_id = $_SERVER['QUERY_STRING'];
//        print_r($user_id);
        if (request()->isPost()){
            $user_id = input('post.user_id');
            //$inputval = input('post.pass');
            if(input('post.pass') == '通过审核'){
                $update_info = array(
                    'user_status' => 1
                );
                db('user')->where('user_id', $user_id)->update($update_info);
                return $this->redirect('Admin/Certification/enterprise');
            }
            if(input('post.nopass') == '未通过审核'){
                $update_info = array(
                    'user_status' => 3
                );
                db('user')->where('user_id', $user_id)->update($update_info);
                return $this->redirect('Admin/Certification/enterprise');
            }
        }else{
            $user = Model('User');

            $userinfo = $user->getUserInfo($user_id);

            $userinfo['user_addTime'] = date("Y-m-d H:i:s",$userinfo['user_addTime']);

            if($userinfo['user_status'] == -1){
                $userinfo['user_status'] = '未实名认证';
            }
            if($userinfo['user_status'] == 2){
                $userinfo['user_status'] = '实名认证中';
            }
            if($userinfo['user_status'] == 1){
                $userinfo['user_status'] = '已实名认证';
            }

            if($userinfo['user_type'] == 1){
                $userinfo['user_type'] = '个人用户';
            }
            if($userinfo['user_type'] == 2){
                $userinfo['user_type'] = '企业用户';
            }

            $allpower = $this->qxhans();
            $this->assign('allpower',$allpower);
            $this->assign('userinfo',$userinfo);
            return $this->fetch('enterprise_detail');
        }
    }


}

?>
