notify.js 1.23 KB
/**
 * 到货通知
 */
'use strict';

const mRoot = '../models';
const NotifyModel = require(`${mRoot}/detail-notify-service`);

const add = (req, res, next) => {
    let uid = req.user.uid;
    let skn = req.body.skn;
    let sku = req.body.sku;
    let mobile = req.body.mobile;

    if (!(skn && sku)) {
        res.json({
            code: 401,
            message: '商品信息错误'
        });
    }

    req.ctx(NotifyModel).add(skn, sku, uid, mobile).then((result) => {
        return res.json(result);
    }).catch(next);
};

const cancel = (req, res, next) => {
    let uid = req.user.uid;
    let sku = req.body.sku;

    if (!sku) {
        return res.json({
            code: 401,
            message: '商品信息错误'
        });
    }

    req.ctx(NotifyModel).cancel(sku, uid).then((result) => {
        return res.json(result);
    }).catch(next);
};

const show = (req, res, next) => {
    let uid = req.user.uid;
    let sku = req.query.sku;

    if (!sku) {
        return res.json({
            code: 401,
            message: '商品信息错误'
        });
    }

    req.ctx(NotifyModel).show(sku, uid).then((result) => {
        return res.json(result);
    }).catch(next);
};

module.exports = {
    add,
    show,
    cancel
};