<?php
namespace store\Admin;

use Dever;

class Info extends Core
{
    # 获取基本信息
    public function getData()
    {
        $data = Dever::db('store/info')->find($this->id);

        $url = Dever::url('api.get&level_total=2', 'area');
        $data['area'] = '<script>function linkage_update_area(level){select_linkage(level, "dever-linkage-update_area","'.$url.'", "update_area", "'.$data['area'].'", "", "margin-top:0px;width:20%;", false, "", "", "", "", "", "", "")};$(document).ready(function(){linkage_update_area(1);});</script>';

        if ($data['status'] == 2) {
            $data['status'] = '<span>认证状态：认证中</span>';
        } elseif ($data['status'] == 3) {
            $data['status'] = '<span>认证状态：认证失败</span>&nbsp;&nbsp;<a href="javascript:;" class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-danger">重新认证</a>';
        } else {
            $data['status'] = '<span>认证状态：已认证</span>&nbsp;&nbsp;<a href="javascript:;" class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-danger">重新认证</a>';
        }

        return $data;
    }

    # 获取基本信息
    public function getConfig()
    {
        # 修改资料
        $data['update'] = Dever::url('admin/info.update', 'store');
        return $data;
    }

    # 认证
    public function update_api()
    {
        $input = Dever::input();

        $update['name'] = $input['update_name'];
        $update['truename'] = $input['update_truename'];
        $update['mobile'] = $input['update_mobile'];
        $update['area'] = $input['update_area'];
        $update['address'] = $input['update_address'];
        $update['license'] = $input['update_license'];
        $update['license_number'] = $input['update_license_number'];
        $update['idcard_front'] = $input['update_idcard_front'];
        $update['idcard_back'] = $input['update_idcard_back'];
        $update['kh_license'] = $input['update_kh_license'];
        $update['status'] = 2;

        $update['where_id'] = $this->id;

        Dever::db('store/info')->update($update);

        return 'reload';
    }
}