const system=require("../../system");
const ServiceBase=require("../sve.base");
class CcashinfoSve extends ServiceBase {
  constructor() {
    super(ServiceBase.getDaoName(CcashinfoSve));
  }


  /**
   * fn:根据条件获取对象
   * @param params
   * @returns {Promise<null>}
   *
   * 条件：mchtId ecid
   *
   */
  async getBean(params) {
    try {
      let where = {};
      if(params.mchtId){
        where.mchtId = params.mchtId;
      }
      if(params.outTradeNo){
        where.outTradeNo = params.outTradeNo;
      }
      if(params.id){
        where.id = params.id;
      }
      let bean =  this.dao.model.findOne({
        where:where
      });
      return bean ||null;
    }catch (e) {
      console.log(e);
      return system.getResult(null,`系统错误 错误信息：`+JSON.stringify(e))
    }
    return null;
  }

  /**
   * fn:保存
   * @param params
   * @returns {Promise<void>}
   */
  async save(params){
    if(!params){
      return null;
    }
    try{
      await this.dao.create(params);
      let res = await this.getBean({
        mchtId:params.mchtId,
        outTradeNo:params.outTradeNo
      })
      return res;
    }catch (e) {
      console.log(e);
    }
  }


}


module.exports=CcashinfoSve;
