guochao.js 954 Bytes
/* eslint-disable array-callback-return */
const { actGuochaoShop } = require('../../../db');

class Guochao extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    async addFavAsync(uid, id, type) {
        console.log({uid, id, type});
        try {
            await this.get({ data: {
                method: 'app.favorite.add',
                id: id,
                uid: uid,
                type: type
            }});

            let item = await actGuochaoShop.findOne({where: {shop_id: id}});
            let result = await item.increment('collect_count');

            return Promise.resolve({code: 200, result: true, data: result});
        } catch (e) {
            console.log(e.toString());
            return Promise.resolve({code: 202, result: false, errorMsg: e});
        }
    }

    async list() {
        return actGuochaoShop.findAll({order: [['sort', 'desc']]});
    }
}

module.exports = Guochao;