detail-notify-service.js 1.23 KB


'use strict';

const DetailNotifyApi = require('./detail-notify-api');
const _ = require('lodash');


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

        this.api = new DetailNotifyApi(ctx);
        this.add = this.api.addNotifyAsync.bind(this.api);
        this.cancel = this.api.cancelNotifyAsync.bind(this.api);
    }

    show(sku, uid) {
        return this.api.getNotifyStatusAsync(sku, uid).then((result) => {
            if (result.code === 200) {
                if (!_.isEmpty(result.data)) {
                    return {
                        code: 200,
                        data: {
                            status: 'Y'
                        },
                        message: '已添加通知'
                    };
                } else {
                    return {
                        code: 200,
                        data: {
                            status: 'N'
                        },
                        message: '没有添加通知'
                    };
                }
            } else {
                return {
                    code: 401,
                    message: '服务器错误'
                };
            }
        });
    }
};