wechat.js 1.37 KB
/**
 * 微信model
 * @author: qiujun <jun.qiu@yoho.cn>
 * @date: 15/11/2017
 */

const mysqlCli = global.yoho.utils.mysqlCli;

const TABLE_WECHAT = 'wechat_token';

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

    getAccessKeys() {
        let strSql = `select * from ${TABLE_WECHAT} limit 0, 1;`;

        return mysqlCli.query(strSql);
    }

    saveAccessKeys(access_token, access_ticket, access_create_time, access_expired, type) {
        let strSql = '';
        let params = {
            access_token,
            access_ticket,
            access_create_time,
            access_expired
        };

        if (type === 'save') {
            strSql = `insert into ${TABLE_WECHAT} 
                    (access_token, access_ticket, access_create_time, access_expired) values 
                    (:access_token, :access_ticket, :access_create_time, :access_expired);`;

            return mysqlCli.insert(strSql, params);
        } else if (type === 'update') {
            strSql = `update ${TABLE_WECHAT} set 
                      access_token = :access_token,
                      access_ticket = :access_ticket,
                      access_create_time = :access_create_time,
                      access_expired = :access_expired`;

            return mysqlCli.update(strSql, params);
        }

    }
}

module.exports = WechatModel;