AddressData.php 3.24 KB
<?php

namespace LibModels\Web\Home;

use Api\Yohobuy;
use Api\Sign;

class AddressData
{

    /**
     * 获取省市区信息
     * $parentId 父级ID
     */
    public static function getProviceCityInfo($parentId=0)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.address.provinces';
        $param['id'] = $parentId;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }
    
    /**
     * 地址数据
     *
     * @param int $uid 用户ID
     * @param int $limit 分页大小参数(默认10条)
     * @return array 地址接口返回的数据
     */
    public static function addressData($uid, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.address.gethidden';
        $param['uid'] = $uid;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }
    
    
    /**
     * 保存地址数据
     *
     * @param int $uid 用户ID
     * @param string $address 地址信息
     * @param int $area_code 城市码
     * @param string $consignee 收货人
     * @param string $email 邮箱地址
     * @param int $id 地址唯一标识符id
     * @param string $mobile 手机号码
     * @param string $phone 电话号码
     * @param string $zip_code 邮编
     * @return array 地址接口返回的数据
     */
    public static function saveAddressData($uid, $address, $area_code, $consignee, $email, $id, $mobile, $phone, $zip_code)
    {
        $param = Yohobuy::param();
        $param['address'] = $address;
        $param['area_code'] = $area_code;
        $param['consignee'] = $consignee;
        $param['email'] = $email;

        if (!empty($id)) { // 修改
            $param['id'] = $id;
            $param['method'] = 'app.address.update';
        } else { // 添加
            $param['method'] = 'app.address.add';
        }

        $param['mobile'] = $mobile;
        $param['phone'] = $phone;
        $param['zip_code'] = $zip_code;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }
    
    /**
     * 删除地址
     *
     * @param int $uid 用户ID
     * @param int $id 地址唯一标识符id
     * @return array 接口返回的数据
     */
    public static function deleteAddress($uid, $id)
    {
        $param = Yohobuy::param();
        $param['id'] = $id;
        $param['method'] = 'app.address.del';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }
    
    /**
     * 设置默认地址
     *
     * @param int $uid 用户ID
     * @param int $id 地址唯一标识符id
     * @return array 接口返回的数据
     */
    public static function setDefaultAddress($uid, $id)
    {
        $param = Yohobuy::param();
        $param['id'] = $id;
        $param['method'] = 'app.address.setdefault';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

}