c6fea1cc0d
去掉货到付款和发货凭证,尾款或全款时提示交易已完结;已购单据报价次数也可查看买家信息。 Co-authored-by: Cursor <cursoragent@cursor.com>
494 lines
24 KiB
JavaScript
494 lines
24 KiB
JavaScript
'use strict';
|
|
|
|
const dbName = require('../../../../../dao/config.js')
|
|
const dayjs = require("dayjs");
|
|
var isBetween = require('dayjs/plugin/isBetween')
|
|
dayjs.extend(isBetween)
|
|
|
|
const PROCESS_PAY_METHOD = ['预付', '货到验收后付款', '提货付全款', '信誉采购,货到签单后账期:']
|
|
const WRITE_INVOICE_TIME = ['付款当月(限20号之前付款,20号之后付款次月开票)', '付款后次月', '付款前']
|
|
const INVOICE_TYPE = ['增值税专用发票13%', '增值税普通发票', '普通发票']
|
|
|
|
module.exports = {
|
|
/**
|
|
* 同意合作
|
|
* @url client/enquiry/quote/kh/confirmQuote 前端调用的url参数地址
|
|
* data 请求参数
|
|
* @param {String} params1 参数1
|
|
*/
|
|
main: async (event) => {
|
|
let {
|
|
data = {}, userInfo, util, filterResponse, originalParam
|
|
} = event;
|
|
let {
|
|
pubFun,
|
|
vk,
|
|
} = util;
|
|
let {
|
|
uid,
|
|
quoteId
|
|
} = data;
|
|
let res = {
|
|
code: 0,
|
|
msg: ""
|
|
};
|
|
// 业务逻辑开始-----------------------------------------------------------
|
|
|
|
// 修改报价单状态
|
|
const quote = await vk.baseDao.updateAndReturn({
|
|
dbName: 'jjx-enquiry-quote',
|
|
whereJson: {
|
|
_id: quoteId,
|
|
status: 0
|
|
},
|
|
dataJson: {
|
|
status: 1,
|
|
}
|
|
})
|
|
|
|
if (!quote) {
|
|
return {
|
|
code: -1,
|
|
msg: '请刷新页面'
|
|
}
|
|
}
|
|
// 获取乙方信息
|
|
const quoteUser = await vk.baseDao.select({
|
|
dbName: dbName.user,
|
|
getMain: true,
|
|
getOne: true,
|
|
whereJson: {
|
|
_id: quote.userId
|
|
}
|
|
})
|
|
|
|
// 获取询价单信息
|
|
const sheet = await vk.baseDao.updateAndReturn({
|
|
dbName: dbName.enquirySheet,
|
|
whereJson: {_id: quote.sheetId},
|
|
dataJson: {
|
|
otherUid: quote.userId,
|
|
status: 1
|
|
}
|
|
})
|
|
|
|
const checkMessage = await vk.baseDao.findByWhereJson({
|
|
dbName: "jjx-message-config",
|
|
whereJson: {
|
|
enquiry: true,
|
|
uid: quote.userId
|
|
}
|
|
})
|
|
|
|
if (checkMessage) {
|
|
let send = true
|
|
// if (checkMessage.doNotDisturbRange && checkMessage.doNotDisturbRange[0]) {
|
|
// const date = dayjs().format("YYYY-MM-DD")
|
|
// const doNotDisturbRangeStart = dayjs(checkMessage.doNotDisturbRange[0]).format("HH:mm")
|
|
// const doNotDisturbRangeEnd = dayjs(checkMessage.doNotDisturbRange[1]).format("HH:mm")
|
|
// if (dayjs().isBetween(dayjs(`${date} ${doNotDisturbRangeStart}`), dayjs(`${date} ${doNotDisturbRangeEnd}`)))
|
|
// send = false
|
|
// }
|
|
const date = dayjs().format("YYYY-MM-DD")
|
|
if (checkMessage.doNotDisturbStart && checkMessage.doNotDisturbStart.length) {
|
|
const doNotDisturbRangeStart = dayjs(`${date} ${checkMessage.doNotDisturbStart[0]}:${checkMessage.doNotDisturbStart[1]}`).format("HH:mm")
|
|
const doNotDisturbRangeEnd = dayjs(`${date} ${checkMessage.doNotDisturbEnd[0]}:${checkMessage.doNotDisturbEnd[1]}`).format("HH:mm")
|
|
if (dayjs().isBetween(dayjs(`${date} ${doNotDisturbRangeStart}`), dayjs(`${date} ${doNotDisturbRangeEnd}`)))
|
|
send = false
|
|
}
|
|
|
|
if (send) {
|
|
await vk.baseDao.add({
|
|
dbName: "jjx-message",
|
|
dataJson: {
|
|
uid: quote.userId,
|
|
title: `找买家:${sheet.title}被选商`,
|
|
content: `您报价的找买家信息已被选商,赶紧去签合同吧`,
|
|
type: 'contract',
|
|
hasRead: false,
|
|
pk: data.sheetId
|
|
}
|
|
});
|
|
await pubFun.sendNotifySms(quote.userId, 'SMS_474250536')
|
|
}
|
|
}
|
|
|
|
// 获取商品信息
|
|
const otherCate = sheet.otherCate ? String(sheet.otherCate).trim() : ''
|
|
const sheetProductList = otherCate ? [{
|
|
goodsName: otherCate,
|
|
procureNumber: sheet.procureNumber,
|
|
procureUnit: sheet.procureUnit,
|
|
}] : (Array.isArray(sheet.productList) ? sheet.productList : [])
|
|
const productTitle = sheetProductList.map(item => item.goodsName).filter(Boolean).join("/") || sheet.title
|
|
|
|
if (sheet.signMethod !== 1) {
|
|
const fadadaContractId = vk.pubfn.createOrderNo("E", 20)
|
|
// 上传合同模板并填充
|
|
|
|
// 新增合同记录
|
|
let contractTransactionId = vk.pubfn.createOrderNo("C", 20)
|
|
const contractId = await vk.baseDao.add({
|
|
dbName: 'jjx-contract',
|
|
dataJson: {
|
|
fadadaContractId,
|
|
contractBase: '', // 原始合同
|
|
contractHistory: [], // 历史合同
|
|
contractFinal: '', // 归档合同
|
|
status: 0,
|
|
userId: uid,
|
|
type: 'enquiry',
|
|
quoteId: quoteId,
|
|
sheetId: quote.sheetId,
|
|
productList: sheetProductList,
|
|
productTitle,
|
|
tradeMethod: sheet.tradeMethod,
|
|
partyCount: 2,
|
|
signCount: 0,
|
|
contractType: sheet.contractType,
|
|
signMethod: sheet.signMethod,
|
|
sellerSupplement: sheet.sellerSupplement,
|
|
transactionId: contractTransactionId,
|
|
amount: quote.totalPrice,
|
|
docTitle: productTitle
|
|
}
|
|
})
|
|
|
|
// await vk.baseDao.updateById({
|
|
// dbName: 'jjx-enquiry-sheet',
|
|
// id: quote.sheetId,
|
|
// dataJson: {
|
|
// status: 1
|
|
// }
|
|
// })
|
|
// await vk.baseDao.updateById({
|
|
// dbName: 'jjx-enquiry-quote',
|
|
// id: quoteId,
|
|
// dataJson: {
|
|
// status: 1
|
|
// }
|
|
// })
|
|
|
|
// 上传合同模板
|
|
|
|
//新增 用户与合同的关联记录
|
|
await vk.daoCenter.userContractDao.adds([
|
|
{
|
|
transactionId: vk.pubfn.createOrderNo("E", 20),
|
|
userId: quote.userId,
|
|
role: 'seller',
|
|
sign: false,
|
|
contractId
|
|
},
|
|
{
|
|
transactionId: vk.pubfn.createOrderNo("E", 20),
|
|
userId: uid,
|
|
role: 'buyer',
|
|
sign: false,
|
|
contractId
|
|
}
|
|
])
|
|
|
|
if (sheet.signMethod === 0) {
|
|
const templateId = await vk.baseDao.findById({
|
|
dbName: 'jjx-dict',
|
|
id: '80e3bed065a5560e075799d24532b14f'
|
|
})
|
|
const buyerKeyword = await vk.baseDao.findById({
|
|
dbName: 'jjx-dict',
|
|
id: '0b153f9a65a56a2007227cf5157133bf'
|
|
})
|
|
const sellerKeyword = await vk.baseDao.findById({
|
|
dbName: 'jjx-dict',
|
|
id: '09e7876865a56a320731cb244bbef818'
|
|
})
|
|
const signMaxDate = await vk.baseDao.findById({
|
|
dbName: 'jjx-dict',
|
|
id: '657d78958b0da41d311bd94c'
|
|
})
|
|
const signEndDate = vk.pubfn.getOffsetTime(new Date(), {
|
|
day: parseInt(signMaxDate.content),
|
|
mode: "after",
|
|
});
|
|
// const fieldList = await vk.baseDao.select({
|
|
// dbName: 'jjx-contract-template',
|
|
// whereJson: {
|
|
// isOn: true
|
|
// }
|
|
// })
|
|
const sellerUser = await vk.baseDao.findById({
|
|
dbName: 'uni-id-users',
|
|
id: quote.userId
|
|
})
|
|
const buyerUser = await vk.baseDao.findById({
|
|
dbName: 'uni-id-users',
|
|
id: uid
|
|
})
|
|
|
|
const sellerUserBank = await vk.baseDao.findByWhereJson({
|
|
dbName: 'jjx-account',
|
|
whereJson: {
|
|
uid: quote.userId,
|
|
isDefault: true
|
|
}
|
|
})
|
|
const buyerUserBank = await vk.baseDao.findByWhereJson({
|
|
dbName: 'jjx-account',
|
|
whereJson: {
|
|
uid: uid,
|
|
isDefault: true
|
|
}
|
|
})
|
|
|
|
let tradeInfo = PROCESS_PAY_METHOD[sheet.payMethod]
|
|
if (sheet.payMethod === 0 && sheet.advancePayRate) tradeInfo += `${sheet.advancePayRate}%货到付全款`
|
|
if (sheet.payMethod === 3 && sheet.reputationPayDay) tradeInfo += `${sheet.reputationPayDay}天`
|
|
tradeInfo += `,发票要求:${sheet.invoice ? '含税' : '不含税'},开票时间:` + WRITE_INVOICE_TIME[sheet.writeInvoiceTime]
|
|
if (sheet.invoiceOther) tradeInfo += `,其他要求:${sheet.invoiceOther ? sheet.invoiceOther : '无'}`
|
|
else {
|
|
if (sheet.invoice)
|
|
tradeInfo += `,纳税人身份:${sheet.taxType},发票种类:${sheet.invoiceType},税率:${sheet.taxRate}`
|
|
}
|
|
let expressRequire = ''
|
|
expressRequire += `随货资料:${sheet.transportDocuments.join()},其他要求:${sheet.otherTransportDocuments ? sheet.otherTransportDocuments : '无'}${sheet.transportLimit ? '' : ',运输限制要求:无'}`
|
|
if (sheet.transportLimit && sheet.otherTransportRequest) expressRequire += `,运输限制说明:${sheet.otherTransportRequest}`
|
|
let detail = ''
|
|
if (sheet.fillType === 0) {
|
|
sheet.productList.forEach((item, index) => {
|
|
detail += `${item.goodsName}(${item.procureNumber}${item.procureUnit})`
|
|
if (item.deliverService) detail += ` ,${item.deliverService}`
|
|
if (item.pricingForm) detail += ` ,${item.pricingForm}`
|
|
if (item.loadPaidBy) detail += ` ,${item.loadPaidBy}`
|
|
item.model.forEach((model) => {
|
|
if (model.label && model.value && model.value !== 'null') detail += `,${model.label}:${model.value}`
|
|
})
|
|
if (index < sheet.productList.length - 1) detail += '\r\n'
|
|
})
|
|
} else {
|
|
detail = productTitle
|
|
}
|
|
let info = sheet.remark ? `其他要求:${sheet.remark}` : ''
|
|
if (quote.remark) {
|
|
if (info) info += `,${quote.remark}`
|
|
else info = quote.remark
|
|
}
|
|
if (info === '') info = '无'
|
|
|
|
const accountType = sheet.invoice ? 'company' : 'person'
|
|
const buyerBank = await vk.baseDao.findByWhereJson({
|
|
dbName: "jjx-account",
|
|
whereJson: {
|
|
uid: buyerUser._id,
|
|
type: accountType
|
|
}
|
|
})
|
|
let buyerBankName = buyerUser.accountType === 2 ? buyerUser.company.companyBankName : buyerUser.person.personBankName
|
|
let buyerAccount = buyerUser.accountType === 2 ? buyerUser.company.companyAccount : buyerUser.person.personAccount
|
|
let buyerBankAccountName = buyerUser.accountType === 2 ? buyerUser.company.companyAccount : buyerUser.person.personAccount
|
|
let sellerBankName = sellerUser.accountType === 2 ? sellerUser.company.companyBankName : sellerUser.person.personBankName
|
|
let sellerAccount = sellerUser.accountType === 2 ? sellerUser.company.companyAccount : sellerUser.person.personAccount
|
|
let sellerBankAccountName = sellerUser.accountType === 2 ? sellerUser.company.companyAccount : sellerUser.person.personAccount
|
|
if (buyerBank) {
|
|
buyerBankName = buyerBank.bankName
|
|
buyerAccount = buyerBank.account
|
|
buyerBankAccountName = buyerBank.accountName
|
|
}
|
|
const sellerBank = await vk.baseDao.findByWhereJson({
|
|
dbName: "jjx-account",
|
|
whereJson: {
|
|
uid: sellerUser._id,
|
|
type: accountType
|
|
}
|
|
})
|
|
if (sellerBank) {
|
|
sellerBankName = sellerBank.bankName
|
|
sellerAccount = sellerBank.account
|
|
sellerBankAccountName = sellerBank.accountName
|
|
}
|
|
|
|
const parameter = {
|
|
seller: sellerUser.accountType === 2 ? sellerUser.company.companyName : sellerUser.person.personName,
|
|
buyer: buyerUser.accountType === 2 ? buyerUser.company.companyName : buyerUser.person.personName,
|
|
date: dayjs().format('YYYY年MM月DD日'),
|
|
sellerSignDate: dayjs(signEndDate).format('YYYY年MM月DD日 HH时mm分'),
|
|
buyerSignDate: dayjs(signEndDate).format('YYYY年MM月DD日 HH时mm分'),
|
|
// time: dayjs().format('HH:mm'),
|
|
contractNo: fadadaContractId,
|
|
region: sheet.addressRegion.province.name + sheet.addressRegion.city.name + sheet.addressRegion.area.name,
|
|
detail,
|
|
info,
|
|
// content: '无',
|
|
tradeInfo,
|
|
expressRequire,
|
|
defaultDuty: '1.乙方所交产品品种、型号、规格、质量不符合规定的,如果甲方同意利用,应当按质论价;如果甲方不能利用的,应根据产品的具体情况,由乙方负责包换或包修,并承担修理、调换或退货而支付的实际费用;2.乙方不予供货违约责任为甲方的实际损失+违约金,如乙方材料符合订货标准,甲方不能退货和不收货,甲方无条件应按实际本合同订货数量支付100%货款,并支付乙方因此产生的实际费用。带有甲乙双方单位相关收货人和发货人签字的本合同的发货清单事项和内容均视为本合同的补充合同,与本合同有相同的法律效力,双方应共同遵照执行。',
|
|
solve: '1、凡因本合同引起的或与本合同有关的任何争议,均可友好协商或仲裁解决,协商或仲裁不成的,双方协商同意在合同签订地人民法院管辖地起诉,违约一方或对合同争议承担主要责任的一方,应承担对方因仲裁和起诉而产生的全部律师代理费、鉴定(检验)费、诉讼保全费、诉讼保险费、公告费、差旅费、执行费、误工費和获取证据产生费用等其他相关费用。2、双方本合同相关权利放弃均应有双方书面作出并加盖公章或授权委托人签字后生效。',
|
|
forceMajeure: '甲乙双方的任何一方由于不可抗力或突发公共事件的原因不能履行合同时,应及时向对方通报不能履行或不能完全履行的理由,以减轻可能给对方造成的损失,在取得有关机构证明以后,允许延期履行、部分履行或者不履行合同,并根据情况可部分或全部免予承担违约责任。',
|
|
other: '本合同的全部内容由双方平等共同协商一致,共同起草制定,非一方事先拟定,不属于格式条款。本合同自双方签字盖章后生效(包括电子签字、盖章),按本合同内容地址、联系方式寄送的一切文书、函件送达与否,均为视为送达有法律效力,通知途径和本合同内联系方式或地址送达文件双方均予以验证。',
|
|
buyerSupplement: sheet.supplementary ? sheet.supplementary : '无',
|
|
sellerSupplement: quote.supplierExt ? quote.supplierExt : '无',
|
|
buyerAddress: buyerUser.accountType === 2 ? buyerUser.company.mailAddress : buyerUser.person.address,
|
|
sellerAddress: sellerUser.accountType === 2 ? sellerUser.company.mailAddress : sellerUser.person.address,
|
|
buyerLegal: buyerUser.accountType === 2 ? buyerUser.company.legalName : '',
|
|
sellerLegal: sellerUser.accountType === 2 ? sellerUser.company.legalName : '',
|
|
// buyerAgent: buyerUser.accountType === 2 ? buyerUser.manager.personName : '',
|
|
buyerAgent: sheet.businessName,
|
|
sellerAgent: sellerUser.accountType === 2 ? sellerUser.manager.personName : '',
|
|
// buyerMobile: buyerUser.accountType === 2 ? buyerUser.manager.mobile : buyerUser.person.mobile,
|
|
buyerMobile: sheet.businessMobile,
|
|
sellerMobile: sellerUser.accountType === 2 ? sellerUser.manager.mobile : sellerUser.person.mobile,
|
|
buyerBankName,
|
|
sellerBankName,
|
|
buyerAccount,
|
|
sellerAccount,
|
|
buyerBankAccountName,
|
|
sellerBankAccountName,
|
|
signName: sheet.signName ? sheet.signName : '',
|
|
signIdCard: sheet.signIdCard ? sheet.signIdCard : '',
|
|
}
|
|
// for (let i = 0; i < fieldList.length; i++) {
|
|
//
|
|
// const field = fieldList[i]
|
|
// parameter[field.field] = ''
|
|
// }
|
|
const uploaddocs = await pubFun.fadada('generate_contract.api', {
|
|
template_id: templateId.content,
|
|
contract_id: contractTransactionId,
|
|
parameter_map: JSON.stringify(parameter)
|
|
})
|
|
let otherFileResList = []
|
|
// 存在附件则合并
|
|
// if (sheet.files && sheet.files.length > 0) {
|
|
// for (let i = 0; i < sheet.files.length; i++) {
|
|
// otherFileResList.push(contractTransactionId + i.toString())
|
|
// await pubFun.fadada('uploaddocs.api', {
|
|
// contract_id: contractTransactionId + i.toString(),
|
|
// doc_title: sheet.title + `:附件${i + 1}`,
|
|
// doc_url: sheet.files[i],
|
|
// doc_type: '.pdf'
|
|
// })
|
|
// }
|
|
// otherFileResList.unshift(contractTransactionId)
|
|
//
|
|
// // 合并接口
|
|
// contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
|
// const mergeRes = await pubFun.fadada('merge_contract.api', {
|
|
// contract_id: contractTransactionId,
|
|
// doc_title: sheet.title,
|
|
// contract_ids: otherFileResList.join()
|
|
// })
|
|
// console.log('mergeRes', mergeRes)
|
|
// console.log('otherFileResList', otherFileResList)
|
|
// }
|
|
// 存在附件则合并
|
|
if (quote.files && quote.files.length > 0) {
|
|
for (let i = 0; i < quote.files.length; i++) {
|
|
otherFileResList.push(contractTransactionId + 'qf' + i.toString())
|
|
await pubFun.fadada('uploaddocs.api', {
|
|
contract_id: contractTransactionId + 'qf' + i.toString(),
|
|
doc_title: sheet.title + `:附件${i + 1}`,
|
|
doc_url: quote.files[i],
|
|
doc_type: '.pdf'
|
|
})
|
|
}
|
|
otherFileResList.unshift(contractTransactionId)
|
|
|
|
// 合并接口
|
|
contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
|
const mergeRes = await pubFun.fadada('merge_contract.api', {
|
|
contract_id: contractTransactionId,
|
|
doc_title: sheet.title,
|
|
contract_ids: otherFileResList.join()
|
|
})
|
|
console.log('quote mergeRes', mergeRes)
|
|
console.log('quote otherFileResList', otherFileResList)
|
|
}
|
|
await vk.baseDao.update({
|
|
dbName: dbName.contract,
|
|
whereJson: {
|
|
_id: contractId
|
|
},
|
|
dataJson: {
|
|
transactionId: contractTransactionId,
|
|
}
|
|
})
|
|
if (parseInt(uploaddocs.code) === 1000) {
|
|
await vk.baseDao.update({
|
|
dbName: dbName.contract,
|
|
whereJson: {
|
|
_id: contractId,
|
|
userId: uid
|
|
},
|
|
dataJson: {
|
|
status: 1,
|
|
docTitle: sheet.title,
|
|
signEndDate,
|
|
otherFile: '',
|
|
contractBase: null,
|
|
buyerSignKeyword: buyerKeyword.content,
|
|
sellerSignKeyword: sellerKeyword.content
|
|
}
|
|
})
|
|
// await vk.baseDao.updateAndReturn({
|
|
// dbName: 'jjx-enquiry-sheet',
|
|
// whereJson: {
|
|
// _id: quote.sheetId
|
|
// },
|
|
// dataJson: {
|
|
// status: 2
|
|
// }
|
|
// })
|
|
|
|
await vk.baseDao.add({
|
|
dbName: "jjx-message",
|
|
dataJson: {
|
|
uid: quote.userId,
|
|
title: `询价:${sheet.title}待签合同`,
|
|
content: `您报价的询价信息已创建合同,赶紧去签订合同吧`,
|
|
type: 'contract',
|
|
hasRead: false,
|
|
pk: quote.sheetId
|
|
}
|
|
});
|
|
await pubFun.sendNotifySms(quote.userId, 'SMS_474455034')
|
|
res.data = uploaddocs.result
|
|
} else {
|
|
return {
|
|
code: -1,
|
|
msg: uploaddocs.msg
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
const orderId = await vk.baseDao.add({
|
|
dbName: "jjx-order",
|
|
dataJson: {
|
|
orderNo: vk.pubfn.createOrderNo("39XU", 20),
|
|
uid: uid,
|
|
sellerUid: quote.userId,
|
|
orderStatus: 0,
|
|
payStatus: 0,
|
|
type: 4,
|
|
amount: quote.totalPrice,
|
|
offAmount: quote.totalPrice,
|
|
signMethod: 1,
|
|
sheetId: quote.sheetId,
|
|
}
|
|
})
|
|
|
|
await vk.baseDao.add({
|
|
dbName: "jjx-order-goods",
|
|
dataJson: {
|
|
orderId,
|
|
goodsId: null,
|
|
num: 1,
|
|
goodsName: productTitle || '询价单',
|
|
goodsPrice: quote.totalPrice,
|
|
goodsCover: null,
|
|
}
|
|
})
|
|
}
|
|
// 业务逻辑结束-----------------------------------------------------------
|
|
return res;
|
|
}
|
|
}
|