address-api.js 2.95 KB
/**
 * address api
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/09/27
 */
'use strict';

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    /**
     * 获取用户收货地址列表
     * @param uid [number] uid
     */
    getAddressListAsync(uid) {
        let options = {
            method: 'app.address.gethidden',
            uid: uid
        };

        return this.get({data: options, param: {
            code: 200
        }});
    }

    /**
     * 省市区列表
     * @param id [number] 省市区id
     */
    getAreaListAsync(id) {
        let options = {
            method: 'app.address.provinces',
            id: id || 0
        };

        return this.get({data: options});
    }

    /**
     * 地址删除
     * @param uid [number] uid
     * @param id [string] address id
     */
    delAddressAsync(uid, id) {
        let options = {
            method: 'app.address.del',
            uid: uid,
            id: id
        };

        return this.get({data: options});
    }

    /**
     * 新增地址api
     * @param uid [Number]
     * @param consignee [String] 收货人
     * @param areaCode [Number] 区号
     * @param address [String] 地址
     * @param mobile [String] 手机号
     * @param phone [String] 电话号码
     * @param zipCode [String] 邮编
     * @param email [String] 邮箱
     */
    addAddressAsync(uid, consignee, areaCode, address, mobile, phone, zipCode, email) {
        let options = {
            method: 'app.address.add',
            uid: uid,
            consignee: consignee,
            area_code: areaCode,
            address: address,
            mobile: mobile,
            phone: phone,
            zip_code: zipCode,
            email: email
        };

        return this.get({data: options});
    }

    /**
     * 更新地址地址api
     * @param uid [Number]
     * @param id [Number] 地址id
     * @param consignee [String] 收货人
     * @param areaCode [Number] 区号
     * @param address [String] 地址
     * @param mobile [String] 手机号
     * @param phone [String] 电话号码
     * @param zipCode [String] 邮编
     * @param email [String] 邮箱
     */
    updateAddressAsync(uid, id, consignee, areaCode, address, mobile, phone, zipCode, email) {
        let options = {
            method: 'app.address.update',
            uid: uid,
            id: id,
            consignee: consignee,
            area_code: areaCode,
            address: address,
            mobile: mobile,
            phone: phone,
            zip_code: zipCode,
            email: email
        };

        return this.get({data: options});
    }

    /**
     * 设置默认地址
     * @param uid [Number]
     * @param id [Number] 地址id
     */
    setDefaultAddressAsync(uid, id) {
        let options = {
            method: 'app.address.setdefault',
            uid: uid,
            id: id
        };

        return this.get({data: options});
    }
};