myCurrency.js 2.01 KB
/**
* 个人中心我的有货币
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/08/16
*/

'use strict';

const myCurrencyModel = require('../models/myCurrency');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const _ = require('lodash');

const myCurrency = (req, res, next) => {
    let uid = req.user.uid;
    let contentCode = '05afedf76886d732573f10f7451a1703';

    req.ctx(myCurrencyModel).myCurrency(uid, contentCode).then(result => {
        res.render('currency-new', {
            module: 'home',
            page: 'mycurrency',
            pageHeader: _.assign(headerModel.setNav({
                navTitle: '有货币'
            }), {
                currencyPage: true,
                navBtn: false
            }),
            title: '有货币',
            pageFooter: true,
            yohoCoin: result.yohoCoin,
            banner: result.banner,
            localCss: true
        });
    }).catch(next);
};

const currencyDetail = (req, res, next) => {
    let uid = req.user.uid;
    let page = 1;
    let limit = 10;

    req.ctx(myCurrencyModel).currencyDetailIndex(uid, page, limit).then(result => {
        res.render('currency-detail', {
            module: 'home',
            page: 'currencyDetail',
            pageHeader: _.assign(headerModel.setNav({
                navTitle: '有货币明细'
            }), {
                currencyDetailPage: true,
                navBtn: false
            }),
            title: '有货币明细',
            pageFooter: true,
            result: result,
            money: (result.yohoCoin.yohocoin_num && result.yohoCoin.yohocoin_num > 0),
            localCss: true
        });
    }).catch(next);
};

let ajaxCurrencyDetail = (req, res, next) => {
    let uid = req.user.uid;
    let page = req.body.page || 1;
    let limit = 10;

    req.ctx(myCurrencyModel).currencyDetail(uid, page, limit).then(result => {
        res.json(result);
    }).catch(next);
};

module.exports = {
    myCurrency,
    currencyDetail,
    ajaxCurrencyDetail
};