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

  /**
   * 订单管理列表 分页总数查询
   * @param {*} params 
   */
  async ordersCount(params){
    let sql = [];
    sql.push('SELECT COUNT(1) AS orderCount FROM o_order WHERE 1 = 1 ');
    this.setOrderCount(sql,params);
    return await this.customQuery(sql.join(" "), params);
  }

  /**
   * 订单列表 分页
   * @param {*} params 
   */
  async findAll(params){
    let sql = [];
    sql.push(`SELECT * FROM o_order WHERE 1=1 `);
    this.setOrderCount(sql,params);
    sql.push(`limit ${params.currentPage} ,${params.pageSize}`);
    return await this.customQuery(sql.join(" "), params);

  }

  /**
   * 订单管理列表查询条件参数设置
   * @param {*} params 
   */
  async setOrderCount(sql,params){
    if(params.id){
      sql.push(`AND id = :id `);
    }
    if(params.progress){
      sql.push(`AND progress = :progress `);
    }
    if(params.deliver_id){
      sql.push(`AND deliver_id = :deliver_id `);
    }
    if (params.begin) {
      sql.push(`AND created_at >= :begin `);
    }
    if (params.end) {
      sql.push(`AND created_at <= :end`);
    }
    if (params.deliver_id) {
      sql.push(`AND deliver_id = :deliver_id`);
    }
  }

}
module.exports = OorderDao;