coupon.js 2.9 KB
'use strict';

const mRoot = '../models';
const library = '../../../library';

const couponModel = require(`${mRoot}/coupon`); // 领取优惠券 model
const log = require(`${library}/logger`);

exports.index = (req, res) => {
    var renderData = {
            module: 'coupon',
            page: 'index',
            appDownLoadLink: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho'
        },
        ordercode = req.query.ordercode,
        uid = req.query.uid,
        mobile = req.query.mobile;

    renderData.uid = uid;
    renderData.mobile = mobile;
    renderData.ordercode = ordercode;

    // 测试假数据
    // res.render('coupon', renderData); // 渲染页面
    couponModel.getPageInfo({
        ordercode: ordercode,
        uid: uid
    }).then((couponData) => {
        if (couponData.code === 200) {
            // 获取信息成功
            couponData.ordercode = ordercode;
        }
        couponData.appDownLoadLink = renderData.appDownLoadLink;
        res.render('coupon', {
            result: couponData,
            module: 'coupon',
            page: 'index',
            title: couponData.title
        });
    }).catch((err) => {
        log.error('频道页面渲染错误:' + JSON.stringify(err));
    });
};

exports.getCoupon = (req, res) => {
    var renderData = {
        module: 'coupon',
        page: 'index'
    };

    var ordercode = req.query.ordercode,
        mobile = req.query.mobile;

    renderData.mobile = mobile;
    renderData.ordercode = ordercode;

    // //测试假数据
    // res.render('coupon', renderData); // 渲染页面
    couponModel.getCoupon({
        ordercode: ordercode,
        mobile: mobile
    }).then((couponData) => {
        if (couponData.code === 200) {
            // 获取信息成功
            couponData.ordercode = ordercode;
        }
        console.log(couponData);
        res.json({
            result: couponData
        });
    }).catch((err) => {
        log.error('频道页面渲染错误:' + JSON.stringify(err));
    });
};

exports.verify = (req, res) => {
    var renderData = {
        module: 'coupon',
        page: 'index'
    };


    var ordercode = req.query.ordercode,
        mobile = req.query.mobile,
        identifycode = req.query.identifycode;

    renderData.mobile = mobile;
    renderData.ordercode = ordercode;
    renderData.identifycode = identifycode;

    // //测试假数据
    // res.render('coupon', renderData); // 渲染页面
    couponModel.registerAndSendCoupon({
        ordercode: ordercode,
        mobile: mobile,
        identifycode: identifycode
    }).then((couponData) => {
        if (couponData.code === 200) {
            // 获取信息成功
            couponData.ordercode = ordercode;
        }
        console.log(couponData);
        res.json({
            result: couponData
        });
    }).catch((err) => {
        log.error('频道页面渲染错误:' + JSON.stringify(err));
    });
};