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");
//已开具 1050
module.exports.invoiced=async function(params){
  console.log("已开具 1050");
  let obj = await common.delivererVerification(params);
  if(obj.status==-1){return obj;}
  //更改发票表信息
  let invoiceData = {};
  invoiceData.id = params.id;
  invoiceData.invoiceNo = common.trim(params.invoiceNo);
  invoiceData.invoiceTime = common.trim(params.invoiceTime);
  invoiceData.invoiceImg = common.trim(params.invoiceImg);
  invoiceData.status = common.trim(params.nextStatus);
  //更改申请表信息
  let applyData = {};
  applyData.id = params.id;
  applyData.status = common.trim(params.nextStatus);
  applyData.customerStatus = common.trim(params.nextStatus);
  await delivererDao.db.transaction(async (t) => {
    //更新申请表状态
    await applyDao.update(applyData, t);
    //更新发票表状态
    await invoiceDao.update(invoiceData, t);
  }).catch(error => {
    return system.getResult(null, `系统错误 错误信息 ${error}`);
  });
  return system.getResultSuccess();
}