<?php

namespace app\api\controller;

use fastphp\base\Controller;
use app\api\model\User;

class Realname extends Controller
{

    public function index()
    {
        $temp = json_decode(file_get_contents("php://input"),true);
        $user_data = [];
        $data = [];
        $user = new User;
        $user_one_info = $user->getOne(['Id'=>$this->userinfo['UserId']]);

        if ($user_one_info['is_verify'] == 2){
            $data = [
                'Code'=>-10000
            ];
            echo  json_encode($data);
            die;
        }

        $ip_addr = getIp();
        $user_data['ip_addr'] = $ip_addr;
        $user->updateOne(['Id'=>$this->userinfo['UserId']],$user_data);
        if ($user_one_info['is_verify'] == 1){
            $data = [
                'Code'=>10000
            ];
            echo  json_encode($data);
            die;
        }
        if (isset($temp['name'])){
            if(realname($temp)){
                $user_data['Name'] = $temp['name'];
                $user_data['id_code'] = $temp['id_code'];
                $user_data['is_verify'] = 1;
                if($user->updateOne(['Id'=>$this->userinfo['UserId']],$user_data)){
                    $data = [
                        'Code'=>10000
                    ];
                }
            } else {
                $data = [
                    'Code'=>-10000
                ];
            }
        } else {
            $data = [
                'Code'=>-10000
            ];
        }
        echo  json_encode($data);
    }

}