wheel-surf.js 1.52 KB
/* eslint-disable array-callback-return */
const {ActWheelSurfConf, ActWheelSurfPrize, Activity} = require('../../../db');

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

    list() {
        return Activity.findAll({where: {type: 1}})
    }
    create(data) {
        return Activity.create(data);
    }
    actDelete(id) {
        return Activity.findOne({where: {id}}).then(activity => {
            return activity.destroy();
        });
    }


    configModify(obj) {
        if (obj.id) {
            let where = {id: obj.id};

            delete obj.id;
            return ActWheelSurfConf.update(obj, {where: where});
        } else {
            return ActWheelSurfConf.create(obj);
        }
    }

    configList() {
        return ActWheelSurfConf.findAll();
    }

    configFindOne(act_id) {
        return ActWheelSurfConf.findOne({where: {act_id}});
    }

    prizeCreate(arr) {
        return ActWheelSurfPrize.bulkCreate(arr);
    }

    prizeUpdate(arr) {
        try {
            arr.map((value) => {
                let where = {id: value.id};

                delete value.id;
                ActWheelSurfPrize.update(value, {where: where});
            });
            return Promise.resolve({code: 200, result: true});
        } catch (e) {
            return Promise.resolve({code: 201, result: false, msg: e});
        }

    }

    prizeFindByActId(act_id) {
        return ActWheelSurfPrize.findAll({where: {act_id}});
    }
}

module.exports = ActWheelSurfModel;