const system = require("../../../system");
const applyDao = system.getObject("db.invoice.applyDao");
const invoiceDao = system.getObject("db.invoice.invoiceDao");
const delivererDao = system.getObject("db.invoice.delivererDao");
const common = require("./common");
//待处理 1300(平台第二次审核失败)
module.exports.unAuditFailForDeliverer=async (params)=>{
  console.log("待处理 1300");
  let _apply =await common.applyVerification(params);
  if(_apply.status==-1){return _apply;}
  // let _apply = await applyDao.findOne({
  //   id: common.trim(params.id)
  // });
  if (!_apply) {
    return system.getResult(null, `发票不存在，请核对发票ID`);
  }
  let _deliverer = await delivererDao.model.findOne({
    where: {
      id: _apply.delivererId
    }
  });
  if (!_deliverer) {
    return system.getResult(null, `交付商不存在，请联系管理员`);
  }
  await applyDao.db.transaction(async (t) => {
    //更新 申请单和发票单
    await applyDao.update({
      status: "1300",
      id: _apply.id
    }, t);
    await invoiceDao.update({
      status: "1300",
      id: _apply.id
    }, t);

    if (_deliverer.id) {
      //提交审核信息
      await delivererDao.update({
        auditContent: common.trim(params.auditContent),
        id: _deliverer.id
      });
    }
  }).catch(error => {
    return system.getResult(null, `系统错误 错误信息 ${error}`);
  });
  return system.getResultSuccess();
}