<?php
namespace Agent\Lib;

use Dever;

class Address
{
    # 获取某个收货地址
    public function getOne($mid, $id)
    {
        $where['mid'] = $mid;
        $where['id'] = $id;
        $data = Dever::db('agent/member_address')->find($where);

        if ($data && Dever::project('area')) {
            $data = $this->getInfo($data);
        }

        return $data;
    }

    private function getInfo($data)
    {
        $data['address_info'] = $data['add_string'] = $data['address'];
        $data['province_name'] = $data['city_name'] = $data['county_name'] = '';
        if ($data['province'] && $data['city'] && $data['county']) {
            $info = Dever::db('area/province')->find($data['province']);
            $data['province_name'] = $info['name'];

            $info = Dever::db('area/city')->find($data['city']);
            $data['city_name'] = $info['name'];

            $info = Dever::db('area/county')->find($data['county']);
            $data['county_name'] = $info['name'];

            //$data['address_info'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'];
            $data['add_string'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'] .','. $data['contact'] .','. $data['mobile'];
        }

        return $data;
    }
}
