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

    // amtType 费用类型 00服务费 10个税 20增值费 30附加费


    // 流水记录 00开票冻结 10解冻扣款 20撤回发票退款 30审核驳回退款
  }

  async getAmtTypes() {
    return {
      "00": "服务费",
      "10": "个税",
      "20": "增值费",
      "30": "附加费"
    }
  }
  async getBusiTypes() {
    return {
      "00": "开票冻结",
      "10": "解冻扣款",
      "20": "撤回发票退款",
      "30": "审核驳回退款",
    }
  }

  async findMapByInvoiceId(invoiceId, busiTypes) {
    var sql = [];
    sql.push("SELECT * ");
    sql.push("FROM `xgg_merchant_trade_process` ");
    sql.push("WHERE invoice_id = :invoiceId");
    if (busiTypes && busiTypes.length > 0) {
      sql.push("AND busiType IN (:busiTypes)");
    }

    var list = await this.customQuery(sql.join(""), {invoiceId: invoiceId, busiTypes: busiTypes});
    var result = {};
    for(var item of list) {
      var lst = result[item.amtType] || [];
      lst.push(item);
      result[item.amtType] = lst;
    }
    return result;
  }

  async findUnComplete(invoiceId) {
    var sql = "SELECT * FROM `xgg_merchant_trade_process` WHERE invoice_id = 1 AND busiType IN ('00') AND complete = 0";
    var list = await this.customQuery(sql, {invoiceId: invoiceId});
    return list || [];
  }
}
module.exports=MerchanttradeprocessDao;
    // var u=new UserDao();
    // var roledao=system.getObject("db.roleDao");
    // (async ()=>{
    //   var users=await u.model.findAll({where:{app_id:1}});
    //   var role=await roledao.model.findOne({where:{code:"guest"}});
    //   console.log(role);
    //   for(var i=0;i<users.length;i++){
    //     await users[i].setRoles([role]);
    //     console.log(i);
    //   }
    //
    // })();
