const system=require("../../../system");
const Dao=require("../../dao.base");
class EordersignlogDao extends Dao{
    constructor(){
        super(Dao.getModelName(EordersignlogDao));
    }

    /**
     * fn:分页查询计数
     * @param params
     * @returns {Promise<void>}
     */
    async countEorderSignLog(params){
        let sql = [];
        sql.push('SELECT COUNT(1) AS eordersignlogCount FROM e_order_sign_log WHERE 1 = 1 ');
        this.setEorderSignLogParams(sql,params);
        let list = await this.customQuery(sql.join(" "), params);
        if(!list || list.length==0){
            return {count:0};
        }
        return list[0];
    }

    async setEorderSignLogParams(sql,params){
        if(params.id){
            sql.push('and id=:id');
        }
        if(params.order_id){
            sql.push('and order_id=:order_id');
        }
        if (params.spendedBegin) {
            sql.push("AND spended_at >= :spendedBegin");
        }
        if (params.spendedEnd) {
            sql.push("AND spended_at <= :spendedEnd");
        }
    }

    /**
     * fn:分页查询
     * @param params
     * @returns {Promise<void>}
     */
    async pageEorderSignLog(params){
        let sql = [];
        sql.push('SELECT *  FROM e_order_sign_log WHERE 1 = 1 ');
        this.setEorderParams(sql,params);
        sql.push("ORDER BY spended_at DESC");
        sql.push("LIMIT :startRow, :pageSize");
        let list = await this.customQuery(sql.join(" "), params);
        return list ||[];
    }

}
module.exports=EordersignlogDao;
