guochao.js 1.97 KB
/**
 * 优惠券管理controller
 * @author: leo <y.huang@yoho.cn>
 * @date: 08/08/2018
 */

const GuochaoModel = require('../models/guochao');
const _ = require('lodash');

const guochaoController = {

    async addFav(req, res, next) {
        let param = req.body;
        let sessionKey = param.sessionKey;
        let appVersion = param.appVersion;
        let appSessionType = param.sessionType;


        // 调用接口传参时切勿使用toString获得字符串
        let uid = {
            toString: () => {
                return _.parseInt(req.body.uid);
            },
            sessionKey,
            appVersion,
            appSessionType
        };

        try {
            let r = await req.ctx(GuochaoModel).addFavAsync(uid, param.id, 'shop');

            res.json(r);
        } catch (e) {
            next;
        }

    },
    checkFav: async function(req, res, next) {
        let param = req.body;
        let sessionKey = param.sessionKey;
        let appVersion = param.appVersion;
        let appSessionType = param.sessionType;
        let uid = {
            toString: () => {
                return _.parseInt(req.body.uid);
            },
            sessionKey,
            appVersion,
            appSessionType
        };
        let ids = [1292, 282, 3082, 3372, 3548, 25, 3350, 1898, 1330, 1306, 1482, 992, 1474, 1472, 97, 1298, 1248, 3520, 2642, 964, 990, 1262, 1494, 292, 3146, 369, 720, 1282, 2312, 1878, 3210, 3576, 468, 3196, 1938, 3012];

        try {
            let result = await req.ctx(GuochaoModel).checkFavs(uid, ids, 'shop');

            res.json(result);
        } catch (e) {
            next;
        }
    },
    list: async function(req, res, next) {
        try {
            let result = await req.ctx(GuochaoModel).list();

            res.json({
                data: result,
                code: 200,
                result: true
            });
        } catch (e) {
            next;
        }
    }
};

module.exports = guochaoController;