index.js 1.02 KB
'use strict';
const SeoIndexModel = require('../../models/seo/index');

const index = (req, res) => {
    return req.ctx(SeoIndexModel).writerGoodsXml(req.params).then(result => {
        return res.json(result);
    });
};

const autoGoodsXml = (req, res) => {
    if (global.IS_GOODS_XML_RUN) {
        return res.json({code: 201, message: '后台正在运行中...'});
    }

    global.IS_GOODS_XML_RUN = true;

    req.ctx(SeoIndexModel).autoGoodsXml({start: 1});

    res.json({code: 200, message: 'success...'});
};

const setTask = (req, res) => {
    return req.ctx(SeoIndexModel).setTask(req.query).then(result => {
        return res.json(result);
    });
};

const delTask = (req, res) => {
    return req.ctx(SeoIndexModel).delTask(req.query.url).then(result => {
        return res.json(result);
    });
};

const demoXml = (req, res) => {
    res.setHeader('Content-Type', 'text/xml; charset=utf-8');
    res.render('seo/demo-xml');
};

module.exports = {
    index,
    autoGoodsXml,
    setTask,
    delTask,
    demoXml
};