const common = require("./common");
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");
//待处理 1030
module.exports.pendingDisposal=async function (params){
  console.log("待处理 1030");
  if (!params.id || !params.delivererName) {
    return system.getResult(-1, `系统错误 错误信息 ${error}`);
  }
  let _apply =await common.applyVerification(params);
  if(_apply.status==-1){return _apply;}
  await applyDao.db.transaction(async (t) => {
    let _deliverer = await delivererDao.create({
      invoiceId: _apply.id,
      applyNo: _apply.applyNo,
      merchantId: _apply.merchantId,
      delivererId: common.trim(params.delivererId),
      delivererName: common.trim(params.delivererName),
      delivererAmount: Number(common.trim(params.delivererAmount))
    }, t);
    let applyData = {};
    applyData.status = common.trim(params.nextStatus);
    applyData.customerStatus = common.trim(params.nextStatus);
    applyData.delivererId = common.trim(_deliverer.id);
    applyData.id = common.trim(params.id);
    //更新申请发票内容
    await applyDao.update(applyData, t);
    //更改发票状态
    let invoiceData = {};
    invoiceData.status = common.trim(params.nextStatus);
    invoiceData.id = common.trim(params.id);
    await invoiceDao.update(invoiceData, t);
  }).catch(error => {
    return system.getResult(null, `系统错误 错误信息 ${error}`);
  });
  return system.getResultSuccess();
}