<?php

namespace Option\Lib;

use Dever;

class Member
{
    public function getInfo($id)
    {
        if ($id < 0) {
            return '无';
        }
        $account = Dever::db('option/member')->find(array('id' => $id, 'clear_top' => true));
        if ($account) {
            $string = $account['name'] . '<br />' . $account['mobile'] . '<br />' . $account['idcard'] . '<br />' . $account['key'];

            $company = Dever::db('manage/company')->find($account['company_id']);
            if ($company) {
                $string .= '<br />' . $company['name'];
            }
            return $string;
            
        } else {
            return '';
        }
    }

    public function search_api()
    {
        $value = Dever::input('value');
        if ($value) {
            $company = Dever::load('manage/company.get');
            $where = array('key' => $value);
            if ($company) {
                $where['company_id'] = $company;
            }
            $data = Dever::db('option/member')->getList($where);
            $table = array();
            if ($data) {
                $table = array();
                $table['head'] = array('公司', '序列号', '姓名', '手机号', '类型');
                $table['body'] = array();
                foreach ($data as $k => $v) {
                    $company = Dever::db('manage/company')->one($v['company_id']);
                    if ($v['main'] == 1) {
                        $main = '主账号';
                    } else {
                        $main = '子账号';
                    }
                    $table['body'][] = array($company['name'], $v['key'], $v['name'], $v['mobile'], $main);
                }

                $result[] = array
                (
                    'type' => 'table',
                    'content' => $table,
                );

                $html = Dever::show('', $result, false, false);
                return $html;
            }

            return '暂无账号';
        } else {
            return '';
        }
    }
}