orders-api.js 5.93 KB
/**
 * @author: weiqingting<qingting.wei@yoho.cn>
 */
'use strict';

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

    /**
     * 我的订单-分页
     * @param type uid
     * @param type page
     * @param type limit
     * @param type type 获取订单类型 type=1全部,type=2待付款,type=3待发货,type=4待收货,type=5待评论(已成功) 7取消
     * @return type
     */
    getUserOrders(uid, page, limit, type) {
        let options = {
            method: 'app.SpaceOrders.list',
            uid: uid,
            type: type,
            page: page,
            limit: limit
        };

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

    /**
     * 订单详情
     * @param type uid
     * @param type orderCode
     * @return type
     */
    getOrderDetail(uid, orderCode) {
        let options = {
            method: 'app.SpaceOrders.detail',
            uid: uid,
            order_code: orderCode
        };

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

    /**
     * 取消订单
     * @param type uid
     * @param type orderCode
     * @return type
     */
    cancelUserOrder(uid, orderCode, reason, reasonId) {
        let options = {
            method: 'app.SpaceOrders.close',
            uid: uid,
            order_code: orderCode
        };

        if (reasonId) {
            Object.assign(options, {
                reasonId: reasonId,
                reasons: reason
            });
        }

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

    /**
     * 确认订单
     * @param type uid
     * @param type orderCode
     * @return type
     */
    confirmUserOrder(uid, orderCode) {
        let options = {
            method: 'app.SpaceOrders.confirm',
            uid: uid,
            order_code: orderCode
        };

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

    /**
     * 获取虚拟订单ticketCode
     * @param type orderCode
     * @return type
     */
    getTicketCode(orderCode) {
        let options = {
            method: 'app.SpaceOrders.getQrByOrderCode',
            order_code: orderCode
        };

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

    /**
     * 我的订单-查看物流
     *
     * @param int orderCode 订单号
     * @param int uid 用户ID
     * @return array
     */
    getLogisticsData(orderCode, uid) {
        let options = {
            method: 'app.express.li',
            order_code: orderCode,
            uid: uid
        };

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

    /**
     * 获取历史订单
     * @param type uid
     * @param type page
     * @param type limit
     */
    getHistoryOrders(uid, page, limit) {
        let options = {
            method: 'app.SpaceOrders.history',
            uid: uid,
            page: page,
            limit: limit
        };

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

    /**
     * 更新订单的支付方式
     *
     * @param int orderCode 订单号
     * @param int payment 支付方式
     * @param int uid 用户ID
     * @return array
     */
    updateOrderPayment(orderCode, payment, uid) {
        let options = {
            method: 'app.SpaceOrders.updateOrdersPaymentByCode',
            order_code: Number(orderCode),
            payment: payment,
            uid: uid
        };

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

    /**
     * 取消订单原因列表
     * @return type
     */
    closeReasons() {
        let options = {
            method: 'app.SpaceOrders.closeReasons'
        };

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

    /**
     * 订单详情页——地址修改
     * @param type order_code
     * @param type address_id
     * @return type
     */
    updateDeliveryAddress(orderId, userName, areaCode, address, mobile, phone, uid, udid) {
        let options = {
            method: 'app.SpaceOrders.updateDeliveryAddress',
            order_code: orderId,
            user_name: userName,
            area_code: areaCode,
            address: address,
            uid: uid
        };

        if (mobile) {
            Object.assign(options, {mobile: mobile});
        }

        if (phone) {
            Object.assign(options, {phone: phone});
        }

        if (udid) {
            Object.assign(options, {udid: udid});
        }

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

    /**
     * 查看订单详情
     *
     * @param string orderCode 订单号
     * @param int uid 用户ID
     * @param string sessionKey 用户会话
     * @return array
     */
    viewOrderData(orderCode, uid, sessionKey) {
        let options = {
            method: 'app.SpaceOrders.info',
            order_code: orderCode,
            uid: uid,
            session_key: sessionKey
        };

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

    /**
     * 重新加入购物车
     */
    reBuy(uid, orderId) {
        let options = {
            method: 'app.Shopping.readd',
            uid: uid,
            order_code: orderId
        };

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

    /**
     * 删除订单数据
     */
    del(uid, gender, channel, orderId) {
        let options = {
            method: 'app.SpaceOrders.delOrderByCode',
            uid: uid,
            gender: gender,
            yh_channel: channel,
            order_code: orderId
        };

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

    /**
     * 申请退款
     */
    refund(uid, orderId, reasonId, reason) {
        let options = {
            method: 'app.SpaceOrders.refundApply',
            uid: uid,
            order_code: orderId
        };

        if (reasonId) {
            options.reason_id = reasonId;
        }

        if (reason) {
            options.reason = reason;
        }

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

    /**
     * 申请退款原因
     */
    refundReason() {
        let options = {
            method: 'app.SpaceOrders.refundApplyReasons'
        };

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