Authored by zhangxiaoru

cartCount

  1 +// 购物车数量
  2 +
  3 +'use strict';
  4 +
  5 +const countModel = require('../models/count');
  6 +
  7 +let cartCount = (req, res, next) => {
  8 +
  9 + let uid = req.user.uid;
  10 + let shoppingKey = req.cookies._SPK || '';
  11 +
  12 + countModel.cartCount(uid, shoppingKey).then((result) => {
  13 + res.json(result);
  14 + }).catch(next);
  15 +};
  16 +
  17 +module.exports = {
  18 + cartCount
  19 +};
  1 +/**
  2 + * sub app channel
  3 + * @author: Bi Kai<kai.bi@yoho.cn>
  4 + * @date: 2016/05/09
  5 + */
  6 +
  7 +var express = require('express'),
  8 + path = require('path'),
  9 + hbs = require('express-handlebars');
  10 +
  11 +var app = express();
  12 +
  13 +// set view engin
  14 +var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
  15 +
  16 +app.on('mount', function(parent) {
  17 + delete parent.locals.settings; // 不继承父 App 的设置
  18 + Object.assign(app.locals, parent.locals);
  19 +});
  20 +
  21 +app.set('views', path.join(__dirname, 'views/action'));
  22 +app.engine('.hbs', hbs({
  23 + extname: '.hbs',
  24 + defaultLayout: 'layout',
  25 + layoutsDir: doraemon,
  26 + partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
  27 + helpers: global.yoho.helpers
  28 +}));
  29 +
  30 +// router
  31 +app.use(require('./router'));
  32 +
  33 +module.exports = app;
  1 +'use strict';
  2 +
  3 +const api = global.yoho.API;
  4 +
  5 +const cartCount = (uid, shoppingKey) => {
  6 +
  7 + return api.get('', {
  8 + method: 'app.Shopping.count',
  9 + uid: uid,
  10 + shopping_key: shoppingKey
  11 + }).then((result) => {
  12 + return result;
  13 + });
  14 +};
  15 +
  16 +module.exports = {
  17 + cartCount
  18 +};
  1 +/**
  2 + * router of sub app channel
  3 + * @author: Bi Kai<kai.bi@yoho.cn>
  4 + * @date: 2016/05/09
  5 + */
  6 +
  7 +'use strict';
  8 +
  9 +const express = require('express');
  10 +const router = express.Router();
  11 +const cRoot = './controllers';
  12 +const countController = require(`${cRoot}/count`);
  13 +
  14 +router.get('/index/count', countController.cartCount);
  15 +
  16 +module.exports = router;
@@ -17,6 +17,7 @@ module.exports = app => { @@ -17,6 +17,7 @@ module.exports = app => {
17 app.use('/product', require('./apps/product')); 17 app.use('/product', require('./apps/product'));
18 app.use('/guang', require('./apps/guang')); 18 app.use('/guang', require('./apps/guang'));
19 app.use('/activity', require('./apps/activity')); 19 app.use('/activity', require('./apps/activity'));
  20 + app.use('/cart', require('./apps/cart'));
20 21
21 // 分期付款 22 // 分期付款
22 app.use('/home', require('./apps/home')); 23 app.use('/home', require('./apps/home'));