<?php

namespace app\user\controller;

use think\Validate;
use think\Lang;

class Member extends UserControl
{

    public function _initialize()
    {
        parent::_initialize();
        Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/member.lang.php');
    }

    /**
     * 用户
     * @return mixed
     */
    public function index()
    {
        $user_info = $this->getAdminInfo();
        if (request()->isPost()) {
            $user_name = input('post.user_name');
            $company = input('post.company');
            $trade = input('post.trade');
            $address = input('post.address');

            $update_info = array(
                'user_name' => $user_name,
                'company' => $company,
                'trade' => $trade,
                'address' => $address
            );
            //print_r($update_info);
            $res = db('user')->where('user_id', $user_info['user_id'])->update($update_info);
            if($res == 1){
                return $this->redirect('User/Member/index');
            }

        }else{
            $user = db('user')->where('user_email',$user_info['user_email'])->find();
            if($user['user_status'] ==1){
                $user['user_status_cn'] = '已实名认证';
            }else{
                $user['user_status_cn'] = '未实名认证';
            }

            if($user['user_type'] ==1){
                $user['user_type_cn'] = '个人用户';
            }
            if($user['user_type'] ==2){
                $user['user_type_cn'] = '企业用户';
            }
            $this->assign('user', $user);
            return $this->fetch();
        }
    }


}
