<?php namespace Place_user\Api;
use Dever;
use Place;
use Place\Lib\Main;
class Address extends Main
{
    protected $login = true;
    protected $entry = true;

    # 获取地址列表
    public function list()
    {
        return Dever::load('address', 'place_user')->getList();
    }


    # 添加或者更新地址接口
    public function up()
    {
        $id = Dever::input('id');
        $type = Dever::input('type', 'is_numeric', '类型', 1);
        $province = Dever::input('province', 'is_numeric', '省份');
        $city = Dever::input('city', 'is_numeric', '城市');
        $county = Dever::input('county', 'is_numeric', '区县');
        $address = Dever::input('address', 'is_string', '地址');
        $name = Dever::input('name', 'is_string', '联系人');
        $phone = Dever::input('phone', 'is_string', '联系方式');

        return Dever::load('address', 'place_user')->update($id, $type, $phone, $name, $province, $city, $county, $address);
    }

    # 获取默认地址
    public function getDefault()
    {
        return Dever::load('address', 'place_user')->getDefault();
    }

    # 获取某个收货地址
    public function getInfo()
    {
        $id = Dever::input('id', 'is_numeric', '收货地址');
        $uid = Place::$uid;
        return Dever::load('address', 'place_user')->getInfo($id, $uid);
    }

    # 删除地址
    public function delete()
    {
        $id = Dever::input('id', 'is_numeric', '收货地址');
        return Dever::load('address', 'place_user')->delete($id);
    }
}