<?php


namespace app\Home\controller;
use think\Db;


class Base
{
    public $post="";
    public $userinfo="";
    public function __construct()
    {
        if(request()->isOptions()){
            echo '';
            die();
        }
        $this->post=request()->post();
        $token = isset($this->post['token'])&&$this->post['token']!="" ? trim($this->post['token']):"";
        if($token==""){
            return error_show(102,"token不能为空");
        }
        $verify = verifyToken($token);
        if($verify['code']!=0){
            return error_show($verify['code'],$verify['msg']);
        }
        $tokeninfo = Db::name("account_token")->where(["token"=>$token])->find();
        if(!isset($tokeninfo['accountid'])){
            return error_show(1004,"未找到账户id");
        }

        $userinfo = Db::name("account")->alias('a')->where(["a.id"=>$tokeninfo['accountid'],'a.is_del'=>0])
            ->join("fc_rela_account b", "a.id = b.accountid", "left")
            ->join("fc_account_info c", "b.account_info= c.id", "left")
            ->field("`a`.`id` AS `id`,
	                      `a`.`username` AS `username`,
	                      `a`.`password` AS `password`,
	                      `a`.`salt` AS `salt`,
	                      `a`.`status` AS `status`,
                          `a`.`is_del` AS `is_del`,
                          a.type as type,
                          `a`.`starttime` AS `starttime`,
                          `a`.`expiretime` AS `expiretime`,
                          `a`.`activetime` AS `activetime`,
                          `a`.`addtime` AS `addtime`,
                           `c`.`nickname` AS `nickname`,
                           `c`.`avatar` AS `avatar`,
                           `c`.`mobile` AS `mobile`,
                           `c`.`remark` AS `remark`,
                           `c`.`sex` AS `sex`")
            ->find();
        if(empty($userinfo)){
            return error_show(1004,"未找到账户数据");
        }
        $this->userinfo=$userinfo;
    }

}