admin.js 1.27 KB
/**
 * 管理model
 * @author: leo <qi.li@yoho.cn>
 * @date: 28/06/2017
 */

const mysqlCli = global.yoho.utils.mysqlCli;

const TABLE_ACTIVITY = 'activity';

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

    /**
     * 创建活动
     * @param title 活动标题
     * @param startTime 活动开始时间
     * @param endTime 活动结束时间
     * @returns {*}
     */
    createActivity({title, startTime, endTime}) {
        return mysqlCli.insert(
            `insert into ${TABLE_ACTIVITY} (title, start_time, end_time) values (:title, :startTime, :endTime);`,
            {
                title,
                startTime,
                endTime
            }
        );
    }

    /**
     * 活动列表
     * @returns {*}
     */
    activityList() {
        return mysqlCli.query(
            `select id, title, start_time startTime, end_time endTime, create_time createTime from ${TABLE_ACTIVITY};`
        );
    }

    /**
     * 删除活动
     * @param actId 活动ID
     * @returns {*}
     */
    deleteActivity(actId) {
        return mysqlCli.delete(
            `delete from ${TABLE_ACTIVITY} where id = :actId;`,
            {
                actId
            }
        );
    }
}

module.exports = AdminModel;