Blame view

apps/product/controllers/notify.js 1.23 KB
htoooth authored
1 2 3
/**
 * 到货通知
 */
htoooth authored
4 5 6
'use strict';

const mRoot = '../models';
htoooth authored
7
const NotifyModel = require(`${mRoot}/detail-notify-service`);
htoooth authored
8 9 10 11 12 13 14 15 16 17 18 19 20 21

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: '商品信息错误'
        });
    }
htoooth authored
22
    req.ctx(NotifyModel).add(skn, sku, uid, mobile).then((result) => {
htoooth authored
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
        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: '商品信息错误'
        });
    }
htoooth authored
38
    req.ctx(NotifyModel).cancel(sku, uid).then((result) => {
htoooth authored
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
        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: '商品信息错误'
        });
    }
htoooth authored
54
    req.ctx(NotifyModel).show(sku, uid).then((result) => {
htoooth authored
55 56 57 58 59 60 61 62 63
        return res.json(result);
    }).catch(next);
};

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