20261008
This commit is contained in:
@@ -0,0 +1,431 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config");
|
||||
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/contract/kh/add 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
// await vk.baseDao.updateById({
|
||||
// dbName: 'jjx-process-sheet',
|
||||
// id: data.sheetId,
|
||||
// dataJson: {
|
||||
// status: 1
|
||||
// }
|
||||
// })
|
||||
const quote = await vk.baseDao.updateAndReturn({
|
||||
dbName: 'jjx-process-quote',
|
||||
whereJson: {
|
||||
_id: data.quoteId
|
||||
},
|
||||
dataJson: {
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
// const quote = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-process-quote',
|
||||
// id: data.quoteId
|
||||
// })
|
||||
|
||||
const sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: 'jjx-process-sheet',
|
||||
whereJson: {
|
||||
_id: quote.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
otherUid: data.seller,
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
const checkMessage = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
process: true,
|
||||
uid: quote.userId
|
||||
}
|
||||
})
|
||||
|
||||
if (checkMessage && sheet) {
|
||||
let send = true
|
||||
if (checkMessage) {
|
||||
// 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: quote.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(quote.userId, 'SMS_474210523')
|
||||
}
|
||||
}
|
||||
|
||||
if (sheet.signMethod !== 1) {
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("P", 20)
|
||||
let contractTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
data.transactionId = contractTransactionId
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
...data, ...{
|
||||
fadadaContractId,
|
||||
status: 0,
|
||||
userId: uid,
|
||||
changeNum: 0,
|
||||
tradeMethod: sheet.tradeMethod
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("P", 20),
|
||||
userId: uid,
|
||||
role: 'buyer',
|
||||
sign: false,
|
||||
contractId,
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("P", 20),
|
||||
userId: data.seller,
|
||||
role: 'seller',
|
||||
sign: false,
|
||||
contractId,
|
||||
}
|
||||
])
|
||||
|
||||
// 标准合同
|
||||
if (sheet.signMethod === 0) {
|
||||
|
||||
const templateId = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '80e3bed065a5560e075799d24532b14f'
|
||||
})
|
||||
const buyerSignKeyword = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '0b153f9a65a56a2007227cf5157133bf'
|
||||
})
|
||||
const sellerSignKeyword = 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
|
||||
})
|
||||
|
||||
let tradeInfo = PROCESS_PAY_METHOD[sheet.payMethod]
|
||||
if (sheet.payMethod === 0) tradeInfo += `${sheet.advancePayRate}%货到付全款`
|
||||
if (sheet.payMethod === 3) tradeInfo += `${sheet.reputationPayDay}天`
|
||||
tradeInfo += `,${sheet.invoice ? '含税' : '不含税'},`
|
||||
if (sheet.invoiceOther) tradeInfo += `,${sheet.invoiceOther}`
|
||||
else {
|
||||
if (sheet.taxType && sheet.invoiceType && sheet.taxRate) tradeInfo += `,${sheet.taxType},${sheet.invoiceType},${sheet.taxRate}`
|
||||
}
|
||||
// tradeInfo += `,${INVOICE_TYPE[sheet.invoiceType]}${sheet.invoiceOther ? sheet.invoiceOther : '无'}`
|
||||
let expressRequire = ''
|
||||
expressRequire += `随货资料:${sheet.transportDocuments.join()},其他要求:${sheet.otherTransportDocuments ? sheet.otherTransportDocuments : '无'},运输限制要求:${sheet.transportLimit ? '有' : '无'}`
|
||||
if (sheet.transportLimit && sheet.otherTransportRequest) expressRequire += `运输限制说明:${sheet.otherTransportRequest}`
|
||||
let region = sheet.addressRegion.province.name + sheet.addressRegion.city.name + sheet.addressRegion.area.name
|
||||
// if (sheet.type === 'process') {
|
||||
if (buyerUser.accountType === 2 && buyerUser.company && buyerUser.company.addressRegion && buyerUser.company.addressRegion.province) {
|
||||
region = buyerUser.company.addressRegion.province.name + buyerUser.company.addressRegion.city.name + buyerUser.company.addressRegion.area.name
|
||||
}
|
||||
if (buyerUser.accountType === 1 && buyerUser.person && buyerUser.person.addressRegion && buyerUser.person.addressRegion.province) {
|
||||
region = buyerUser.person.addressRegion.province.name + buyerUser.person.addressRegion.city.name + buyerUser.person.addressRegion.area.name
|
||||
}
|
||||
|
||||
// }
|
||||
// console.log(buyerUser)
|
||||
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分'),
|
||||
contractNo: fadadaContractId,
|
||||
region,
|
||||
detail: sheet.title,
|
||||
info: sheet.remark ? sheet.remark : '无',
|
||||
tradeInfo,
|
||||
expressRequire,
|
||||
defaultDuty: '1.乙方所交产品品种、型号、规格、质量不符合规定的,如果甲方同意利用,应当按质论价;如果甲方不能利用的,应根据产品的具体情况,由乙方负责包换或包修,并承担修理、调换或退货而支付的实际费用;2.乙方不予供货违约责任为甲方的实际损失+违约金,如乙方材料符合订货标准,甲方不能退货和不收货,甲方无条件应按实际本合同订货数量支付100%货款,并支付乙方因此产生的实际费用。带有甲乙双方单位相关收货人和发货人签字的本合同的发货清单事项和内容均视为本合同的补充合同,与本合同有相同的法律效力,双方应共同遵照执行。',
|
||||
solve: '1、凡因本合同引起的或与本合同有关的任何争议,均可友好协商或仲裁解决,协商或仲裁不成的,双方协商同意在合同签订地人民法院管辖地起诉,违约一方或对合同争议承担主要责任的一方,应承担对方因仲裁和起诉而产生的全部律师代理费、鉴定(检验)费、诉讼保全费、诉讼保险费、公告费、差旅费、执行费、误工費和获取证据产生费用等其他相关费用。2、双方本合同相关权利放弃均应有双方书面作出并加盖公章或授权委托人签字后生效。',
|
||||
forceMajeure: '甲乙双方的任何一方由于不可抗力或突发公共事件的原因不能履行合同时,应及时向对方通报不能履行或不能完全履行的理由,以减轻可能给对方造成的损失,在取得有关机构证明以后,允许延期履行、部分履行或者不履行合同,并根据情况可部分或全部免予承担违约责任。',
|
||||
other: '本合同的全部内容由双方平等共同协商一致,共同起草制定,非一方事先拟定,不属于格式条款。本合同自双方签字盖章后生效(包括电子签字、盖章),按本合同内容地址、联系方式寄送的一切文书、函件送达与否,均为视为送达有法律效力,通知途径和本合同内联系方式或地址送达文件双方均予以验证。',
|
||||
buyerSupplement: sheet.supplementary ? sheet.supplementary : '无',
|
||||
sellerSupplement: sheet.supplierExt ? sheet.supplierExt : (quote.remark ? quote.remark : '无'),
|
||||
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 : '',
|
||||
sellerAgent: sellerUser.accountType === 2 ? sellerUser.manager.personName : '',
|
||||
buyerMobile: buyerUser.accountType === 2 ? buyerUser.manager.mobile : buyerUser.mobile,
|
||||
sellerMobile: sellerUser.accountType === 2 ? sellerUser.manager.mobile : sellerUser.mobile,
|
||||
buyerBankName,
|
||||
sellerBankName,
|
||||
buyerAccount,
|
||||
sellerAccount,
|
||||
buyerBankAccountName,
|
||||
sellerBankAccountName,
|
||||
}
|
||||
// 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 + 'f' + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contractTransactionId + 'f' + i.toString(),
|
||||
doc_title: sheet.title + `:附件${i + 1}`,
|
||||
doc_url: sheet.files[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
}
|
||||
if (sheet.multiFiles && sheet.multiFiles.length > 0) {
|
||||
for (let i = 0; i < sheet.multiFiles.length; i++) {
|
||||
otherFileResList.push(contractTransactionId + 'mf' + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contractTransactionId + 'mf' + i.toString(),
|
||||
doc_title: sheet.title + `:加工商附件${i + 1}`,
|
||||
doc_url: sheet.multiFiles[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)
|
||||
}
|
||||
if (otherFileResList.length) {
|
||||
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)
|
||||
}
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
dataJson: {
|
||||
transactionId: contractTransactionId,
|
||||
}
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
await vk.baseDao.updateAndReturn({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: sheet.title,
|
||||
signEndDate,
|
||||
otherFile: '',
|
||||
contractBase: null,
|
||||
buyerSignKeyword: buyerSignKeyword.content,
|
||||
sellerSignKeyword: sellerSignKeyword.content
|
||||
}
|
||||
})
|
||||
// await vk.baseDao.updateAndReturn({
|
||||
// dbName: 'jjx-process-sheet',
|
||||
// whereJson: {
|
||||
// _id: data.sheetId
|
||||
// },
|
||||
// dataJson: {
|
||||
// status: 2
|
||||
// }
|
||||
// })
|
||||
|
||||
res.data = uploaddocs.result
|
||||
|
||||
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_474295535')
|
||||
} 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: 5,
|
||||
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: '加工单',
|
||||
goodsPrice: quote.totalPrice,
|
||||
goodsCover: null,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增签约宝合同
|
||||
* @url client/contract/kh/addSign 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
let payByUser = userInfo;
|
||||
|
||||
const otherUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.phone
|
||||
}
|
||||
})
|
||||
if (JSON.stringify(otherUser) === '{}' || !otherUser) return {
|
||||
code: -1,
|
||||
msg: '签约接收方账号不存在'
|
||||
}
|
||||
if (data.payBy === undefined || data.payBy === null || data.payBy === '')
|
||||
return {
|
||||
code: -1,
|
||||
msg: `请选择费用承担方`
|
||||
}
|
||||
if (data.payBy === 1) payByUser = otherUser
|
||||
// console.log('data.thirdList', data.thirdList, data.thirdList && data.thirdList.length > 0, data.thirdList.length > 0)
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
// let inThird = false
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
if (!thirdUser) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}不存在`
|
||||
}
|
||||
if (!thirdUser.fadadaConfirm) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}未通过法大大认证,无法签约`
|
||||
}
|
||||
if (thirdUser.uid === uid) return {
|
||||
code: -1,
|
||||
msg: '第三方不能为自己'
|
||||
}
|
||||
if (thirdUser.uid === otherUser._id) return {
|
||||
code: -1,
|
||||
msg: '第三方不能与对方为相同账号'
|
||||
}
|
||||
if (data.payBy === 2 && i === 0) {
|
||||
payByUser = thirdUser
|
||||
}
|
||||
}
|
||||
// if (data.payBy === 2 && !inThird) return {
|
||||
// code: -1,
|
||||
// msg: '该承担方不在第三方名单中'
|
||||
// }
|
||||
}
|
||||
|
||||
if (!otherUser.fadadaConfirm) return {
|
||||
code: -1,
|
||||
msg: '签约接收方账号未通过法大大认证,无法签约'
|
||||
}
|
||||
|
||||
if (otherUser._id === uid) return {
|
||||
code: -1,
|
||||
msg: '无法与自己签约'
|
||||
}
|
||||
if (payByUser.qybNum <= 0) return {
|
||||
code: -1,
|
||||
msg: '费用承担方已无签约宝次数,无法继续签约'
|
||||
}
|
||||
data.payerUid = payByUser._id
|
||||
data.transactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
let doc_url = data.contractFile
|
||||
if (Array.isArray(doc_url)) doc_url = doc_url[doc_url.length - 1]
|
||||
const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: data.transactionId,
|
||||
doc_title: data.title,
|
||||
doc_url,
|
||||
// file: doc_url,
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
let partyCount = 2
|
||||
if (data.thirdList && data.thirdList.length > 0) partyCount += data.thirdList.length
|
||||
// 对方是甲方
|
||||
const buyerSignKeyword = data.buyerSignKeyword // 签约发起方
|
||||
const sellerSignKeyword = data.sellerSignKeyword // 签约被邀请方
|
||||
data.buyerSignKeyword = data.userType % 2 === 1 ? sellerSignKeyword : buyerSignKeyword
|
||||
data.sellerSignKeyword = data.userType % 2 === 1 ? buyerSignKeyword : sellerSignKeyword
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
...data, ...{
|
||||
status: 1,
|
||||
userId: uid,
|
||||
changeNum: 0,
|
||||
productTitle: data.title,
|
||||
docTitle: data.title,
|
||||
type: 'sign',
|
||||
contractBase: data.contractFile,
|
||||
partyCount,
|
||||
signCount: 0,
|
||||
tradeMethod: data.tradeMethod
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("S", 20),
|
||||
userId: uid,
|
||||
role: data.userType === 1 ? 'seller' : 'buyer',
|
||||
sign: false,
|
||||
contractId,
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("S", 20),
|
||||
userId: otherUser._id,
|
||||
role: data.userType === 1 ? 'buyer' : 'seller',
|
||||
sign: false,
|
||||
contractId,
|
||||
}
|
||||
])
|
||||
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
console.log('thirdUser', thirdUser)
|
||||
if (thirdUser) {
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("ST", 20),
|
||||
userId: thirdUser._id,
|
||||
role: 'third',
|
||||
sign: false,
|
||||
contractId,
|
||||
keyword: data.thirdList[i].signKeyword,
|
||||
},
|
||||
])
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: thirdUser._id,
|
||||
title: `金久信签约宝`,
|
||||
content: `您有签约宝邀请,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
}
|
||||
});
|
||||
}
|
||||
// await pubFun.sendNotifySms(thirdUser._id, 'SMS_474570002', {
|
||||
// name: thirdUser.accountType === 2 ? thirdUser.company.companyName : thirdUser.person.personName,
|
||||
// name2: userInfo.accountType === 2 ? userInfo.company.companyName : userInfo.person.personName,
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: payByUser._id,
|
||||
dataJson: {
|
||||
qybNum: _.inc(-1)
|
||||
}
|
||||
});
|
||||
|
||||
// 签约宝扣费记录
|
||||
const remainNum = payByUser.qybNum - 1
|
||||
const addSignLog = await vk.baseDao.add({
|
||||
dbName: "jjx-sign-pay_list",
|
||||
dataJson: {
|
||||
userId: payByUser._id,
|
||||
remainNum,
|
||||
contractId,
|
||||
payBy: data.payBy
|
||||
}
|
||||
});
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: otherUser._id,
|
||||
title: `金久信签约宝`,
|
||||
content: `您有金久信签约宝邀请,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
}
|
||||
});
|
||||
// await pubFun.sendNotifySms(otherUser._id, 'SMS_474570002', {
|
||||
// name: otherUser.accountType === 2 ? otherUser.company.companyName : otherUser.person.personName,
|
||||
// name2: userInfo.accountType === 2 ? userInfo.company.companyName : userInfo.person.personName,
|
||||
// })
|
||||
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config");
|
||||
const dayjs = require("dayjs");
|
||||
const PROCESS_PAY_METHOD = ['预付', '货到验收后付款', '提货付全款', '信誉采购,货到签单后账期:']
|
||||
const WRITE_INVOICE_TIME = ['付款当月(限20号之前付款,20号之后付款次月开票)', '付款后次月', '付款前']
|
||||
const INVOICE_TYPE = ['增值税专用发票13%', '增值税普通发票', '普通发票']
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 删除合同
|
||||
* @url client/contract/kh/del 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-contract',
|
||||
whereJson: {
|
||||
_id: data.id
|
||||
},
|
||||
})
|
||||
|
||||
if (contract && contract.type === 'sign') {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: contract.payerUid,
|
||||
dataJson: {
|
||||
qybNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
// await vk.baseDao.add({
|
||||
// dbName: "jjx-sign-pay_list",
|
||||
// dataJson: {
|
||||
// userId: contract.userId,
|
||||
// contractId,
|
||||
// payBy: data.payBy
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-contract',
|
||||
whereJson: {
|
||||
_id: data.id,
|
||||
uid
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-user-contract',
|
||||
whereJson: {
|
||||
contractId: data.id
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config.js")
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* 签署合同
|
||||
* @url client/enquiry/quote/kh/extSign 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, userInfo, util, filterResponse, originalParam } = event;
|
||||
let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
|
||||
let { uid, contractId } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
// 获取用户ID
|
||||
const {fadadaCustomerId, fadadaSealId} = userInfo
|
||||
|
||||
// if(!fadadaSealId) {
|
||||
// return {
|
||||
// code: -1,
|
||||
// msg: '请在个人中心上传印章'
|
||||
// }
|
||||
// }
|
||||
|
||||
const contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
}
|
||||
})
|
||||
|
||||
// 时间判断
|
||||
if (contract.signEndDate && dayjs(contract.signEndDate).isBefore(dayjs())) {
|
||||
return {
|
||||
code: -1,
|
||||
msg: '合同已过期'
|
||||
}
|
||||
}
|
||||
|
||||
// 获取合同信息
|
||||
const userContract = await vk.baseDao.selects({
|
||||
dbName: dbName.userContract,
|
||||
getMain: true,
|
||||
getOne: true,
|
||||
whereJson: {
|
||||
contractId: contractId,
|
||||
userId: uid
|
||||
},
|
||||
foreignDB:[
|
||||
{
|
||||
dbName: dbName.contract,
|
||||
localKey:"contractId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "contract",
|
||||
limit: 1, // 当limit = 1时,以对象形式返回,否则以数组形式返回
|
||||
}
|
||||
],
|
||||
})
|
||||
console.log('userContract: ',userContract);
|
||||
|
||||
let sign_keyword = '';
|
||||
if(userContract.role === 'buyer') {
|
||||
sign_keyword = userContract.contract.buyerSignKeyword
|
||||
}else if(userContract.role === 'seller') {
|
||||
sign_keyword = userContract.contract.sellerSignKeyword
|
||||
}else if(userContract.role === 'third') {
|
||||
sign_keyword = userContract.keyword
|
||||
}
|
||||
let return_url = 'https://www.jinjiuxinzg.cn/#/pages/contract/index?tab=1'
|
||||
if (!data.isSignOnly) {
|
||||
if (!!data.isWap) return_url = 'https://m.jinjiuxinzg.cn/#/pages/public/contract?tab=1'
|
||||
}else {
|
||||
if (!!data.isWap) return_url = 'https://m.jinjiuxinzg.cn/signOnly/#/pages/public/contract?tab=1'
|
||||
else return_url = 'https://www.jinjiuxinzg.cn/signOnly/#/pages/contract/index?tab=1'
|
||||
}
|
||||
res.data = await pubFun.fadadaUrl('extsign.api', {
|
||||
transaction_id: userContract.transactionId,
|
||||
contract_id: contract.transactionId,
|
||||
customer_id: fadadaCustomerId,
|
||||
acrosspage_customer_id: fadadaCustomerId,
|
||||
doc_title: userContract.contract.docTitle,
|
||||
sign_keyword,
|
||||
// notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_contract_notify',
|
||||
// return_url: 'https://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/contract/index?tab=1'
|
||||
notify_url: 'https://tcb-n44byxi8bmrfrki-d4bn1c4a206d.service.tcloudbase.com/fadada_contract_notify',
|
||||
// return_url: 'https://tcb-nnexmh3j3i5hwh5-7caw62c422be-1252168680.tcloudbaseapp.com/#/pages/contract/index?tab=1'
|
||||
return_url
|
||||
})
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 发起/创建合同
|
||||
* @url client/contract/kh/launch 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, userInfo, util, filterResponse, originalParam } = event;
|
||||
let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
|
||||
let { uid, contractId,title,contractFile,otherFile,signEndDate,buyerSignKeyword, sellerSignKeyword } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
}
|
||||
})
|
||||
console.log('contract: ',dbName.contract,uid);
|
||||
// 上传合同模板并填充
|
||||
pubFun.fadada('generate_contract.api', {
|
||||
template_id: '20231120',
|
||||
contract_id: contract.fadadaContractId,
|
||||
parameter_map: JSON.stringify({
|
||||
jiaName: userInfo.accountType == 1?userInfo.person.personName: userInfo.company.companyName,
|
||||
jiaDate: '',
|
||||
jiaPhone: '',
|
||||
yiName: userInfo.accountType == 1?userInfo.person.personName: userInfo.company.companyName,
|
||||
yiDate: '',
|
||||
yiPhone: '',
|
||||
sellerSupplement: contract.sellerSupplement,
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contract.fadadaContractId,
|
||||
doc_title: title,
|
||||
doc_url: contractFile,
|
||||
// file: doc_url,
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
|
||||
if(uploaddocs.code == 1000) {
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: title,
|
||||
signEndDate,
|
||||
otherFile,
|
||||
contractBase: contractFile,
|
||||
buyerSignKeyword,
|
||||
sellerSignKeyword
|
||||
}
|
||||
})
|
||||
|
||||
res.data = uploaddocs.result
|
||||
}else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: uploaddocs.msg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config");
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/contract/kh/getDetail 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, userInfo, util, filterResponse, originalParam } = event;
|
||||
let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
|
||||
let { uid, contractId } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res.data = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
}
|
||||
})
|
||||
|
||||
const partyList = await vk.baseDao.selects({
|
||||
dbName: dbName.userContract,
|
||||
whereJson: {
|
||||
contractId
|
||||
},
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "userId",
|
||||
foreignKey: "_id",
|
||||
as: "user",
|
||||
limit: 1, // limit=1则以对象形式返回
|
||||
fieldJson: {
|
||||
_id: true,
|
||||
mobile: true,
|
||||
},
|
||||
}
|
||||
]
|
||||
});
|
||||
res.data.partyList = partyList.rows
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 获取我的合同列表
|
||||
* @url client/enquiry/contract/kh/getList 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid, pageIndex, pageSize, tradeMethod, status, type, signType} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const lastWhereJson = {}
|
||||
const whereJson = {
|
||||
userId: uid
|
||||
}
|
||||
if (vk.pubfn.isNotNull(tradeMethod) && tradeMethod != null) lastWhereJson['contract.tradeMethod'] = tradeMethod
|
||||
|
||||
if (vk.pubfn.isNotNull(status) && status != null) lastWhereJson['contract.status'] = status
|
||||
if (vk.pubfn.isNotNull(type) && type != null) lastWhereJson['contract.type'] = type
|
||||
if (vk.pubfn.isNotNull(signType) && signType != null && status !== 1) {
|
||||
if (signType === '1') lastWhereJson['contract.signType'] = signType
|
||||
else {
|
||||
lastWhereJson['contract.signType'] = _.in(['2', undefined])
|
||||
}
|
||||
}
|
||||
|
||||
res = await vk.daoCenter.userContractDao.selects({
|
||||
// data: {
|
||||
// pageIndex,
|
||||
// pageSize
|
||||
// },
|
||||
whereJson: whereJson,
|
||||
sortArr: [{"name": "_add_time", "type": "desc"}],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.contract,
|
||||
localKey: "contractId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "contract",
|
||||
limit: 1, // 当limit = 1时,以对象形式返回,否则以数组形式返回
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.userContract,
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "contractId", // 副表外键字段名
|
||||
as: "partyList",
|
||||
limit: 100,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.user,
|
||||
localKey: "userId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "user",
|
||||
limit: 1,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: 'uni-id-users',
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "userId", // 副表外键字段名
|
||||
company: {
|
||||
companyName: true
|
||||
},
|
||||
person: {
|
||||
personName: true
|
||||
},
|
||||
businessCard: true,
|
||||
accountType: true,
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
dbName: 'jjx-sign-pay_list',
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "contractId", // 副表外键字段名
|
||||
as: "payUser",
|
||||
limit: 1,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.user,
|
||||
localKey: "userId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "user",
|
||||
limit: 1
|
||||
},
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
dbName: 'jjx-certificate',
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "contractId", // 副表外键字段名
|
||||
as: "certificate",
|
||||
limit: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
lastWhereJson: lastWhereJson
|
||||
})
|
||||
|
||||
let result = {
|
||||
rows: [],
|
||||
total: 0,
|
||||
hasMore: false,
|
||||
code: 0,
|
||||
msg: "查询成功",
|
||||
}
|
||||
console.log("rows", res.rows)
|
||||
if (vk.pubfn.isNotNull(data.keyword) && data.keyword != null && data.keyword) {
|
||||
const userList = await vk.baseDao.select({
|
||||
dbName: "uni-id-users",
|
||||
getCount: true,
|
||||
whereJson: _.or([
|
||||
{
|
||||
mobile: data.keyword
|
||||
},
|
||||
{
|
||||
'person.personName': data.keyword
|
||||
},
|
||||
{
|
||||
'company.companyName': data.keyword
|
||||
}
|
||||
])
|
||||
});
|
||||
console.log("userList", userList)
|
||||
if (userList.total > 0) {
|
||||
for (let i in res.rows) {
|
||||
const row = res.rows[i]
|
||||
for (let j in row.contract.partyList) {
|
||||
const party = row.contract.partyList[j]
|
||||
for (let k in userList.rows) {
|
||||
const user = userList.rows[k]
|
||||
if (party.user._id === user._id) {
|
||||
result.rows.push(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.total = result.rows.length
|
||||
} else {
|
||||
result = res
|
||||
}
|
||||
|
||||
for (let i in result.rows) {
|
||||
const row = result.rows[i]
|
||||
let sheet = null, order = null
|
||||
if (row.contract) {
|
||||
row.contract.isMine = row.contract.userId === uid
|
||||
if (row.contract.type === 'enquiry' && row.contract.sheetId) {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-enquiry-sheet',
|
||||
id: row.contract.sheetId
|
||||
})
|
||||
} else if (row.contract.type === 'process' && row.contract.sheetId) {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-process-sheet',
|
||||
id: row.contract.sheetId
|
||||
})
|
||||
} else if (row.contract.type === 'old' && row.contract.sheetId) {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-old',
|
||||
id: row.contract.sheetId
|
||||
})
|
||||
}
|
||||
order = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-order',
|
||||
whereJson: {
|
||||
contractId: row.contract._id
|
||||
}
|
||||
})
|
||||
if (row.contract.certificate) {
|
||||
const orderGoods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
goodsId: row.contract._id
|
||||
}
|
||||
})
|
||||
if (orderGoods) {
|
||||
row.contract.certificate.orderId = orderGoods.orderId
|
||||
}
|
||||
}
|
||||
}
|
||||
result.rows[i].sheet = sheet
|
||||
result.rows[i].order = order
|
||||
}
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 发起/创建合同
|
||||
* @url client/contract/kh/launch 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {uid, contractId, title, contractFile, otherFile, signEndDate, buyerSignKeyword, sellerSignKeyword} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const otherUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-user-contract',
|
||||
whereJson: {
|
||||
contractId: contractId,
|
||||
userId: _.neq(uid)
|
||||
}
|
||||
})
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
if (data.thirdList[i].phone) {
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
if (!thirdUser) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}不存在`
|
||||
}
|
||||
if (!thirdUser.fadadaConfirm) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}未通过法大大认证,无法签约`
|
||||
}
|
||||
if (thirdUser.uid === uid) return {
|
||||
code: -1,
|
||||
msg: '第三方不能为自己'
|
||||
}
|
||||
if (thirdUser.uid === otherUser._id) return {
|
||||
code: -1,
|
||||
msg: '第三方不能与对方为相同账号'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
}
|
||||
})
|
||||
console.log('contract: ', contract);
|
||||
let newTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
let doc_url = contractFile
|
||||
if (Array.isArray(doc_url)) doc_url = doc_url[doc_url.length - 1]
|
||||
const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: newTransactionId,
|
||||
doc_title: title,
|
||||
doc_url,
|
||||
// file: doc_url,
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
let otherFileResList = []
|
||||
// 存在附件则合并
|
||||
if (otherFile && otherFile.length > 0) {
|
||||
for (let i = 0; i < otherFile.length; i++) {
|
||||
otherFileResList.push(newTransactionId + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: newTransactionId + i.toString(),
|
||||
doc_title: title + `:附件${i + 1}`,
|
||||
doc_url: otherFile[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
otherFileResList.unshift(newTransactionId)
|
||||
|
||||
// 合并接口
|
||||
newTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
contract_id: newTransactionId,
|
||||
doc_title: title,
|
||||
contract_ids: otherFileResList.join()
|
||||
})
|
||||
console.log('mergeRes', mergeRes)
|
||||
console.log('otherFileResList', otherFileResList)
|
||||
}
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
dataJson: {
|
||||
transactionId: newTransactionId,
|
||||
}
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
let partyCount = 2
|
||||
if (data.thirdList && data.thirdList.length > 0) partyCount += data.thirdList.filter(item => !!item.phone).length
|
||||
const contract = await vk.baseDao.updateAndReturn({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: title,
|
||||
signEndDate,
|
||||
otherFile,
|
||||
partyCount,
|
||||
contractBase: contractFile,
|
||||
buyerSignKeyword,
|
||||
sellerSignKeyword
|
||||
}
|
||||
})
|
||||
if (contract.type === 'enquiry') {
|
||||
await vk.baseDao.update({
|
||||
dbName: 'jjx-enquiry-sheet',
|
||||
whereJson: {
|
||||
_id: contract.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
status: 2,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// const otherUser = await vk.baseDao.findByWhereJson({
|
||||
// dbName: 'jjx-user-contract',
|
||||
// whereJson: {
|
||||
// contractId: contractId,
|
||||
// userId: _.neq(uid)
|
||||
// }
|
||||
// })
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: otherUser.userId,
|
||||
title: `您有新的合同待签署`,
|
||||
content: `您有新的合同待签署,赶紧去签合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
}
|
||||
});
|
||||
// await pubFun.sendNotifySms(otherUser.userId, 'SMS_474525001')
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-user-contract',
|
||||
whereJson: {
|
||||
contractId,
|
||||
role: 'third',
|
||||
}
|
||||
})
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-message',
|
||||
whereJson: {
|
||||
contractId,
|
||||
type: 'contract',
|
||||
isThird: true
|
||||
}
|
||||
})
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
console.log('data.thirdList', data.thirdList)
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
if (data.thirdList[i].phone) {
|
||||
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
if (thirdUser) {
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("ST", 20),
|
||||
userId: thirdUser.uid,
|
||||
role: 'third',
|
||||
sign: false,
|
||||
contractId,
|
||||
keyword: data.thirdList[i].signKeyword,
|
||||
},
|
||||
])
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: thirdUser.uid,
|
||||
title: `合同`,
|
||||
content: `您有合同待签署,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
contractId,
|
||||
isThird: true
|
||||
}
|
||||
});
|
||||
}
|
||||
// await pubFun.sendNotifySms(thirdUser._id, 'SMS_474525001')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.data = uploaddocs.result
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: uploaddocs.msg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/contract/kh/report 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
let {customUtil, uniID, config, pubFun, vk, db, _} = util;
|
||||
let {contractNum, evidenceType} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const url = 'https://tczapi.fadada.com/czapi/api/compliance-contract-report'
|
||||
// const url = 'https://czapi-test.fadada.com/evidence-api/api/compliance-contract-report'
|
||||
const result = await pubFun.fadada(url, {
|
||||
contractNum,
|
||||
evidenceType
|
||||
}, true)
|
||||
if (parseInt(result.code) === 1000) {
|
||||
res.data = result.data
|
||||
}
|
||||
return res
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/contract/kh/stopContract 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, userInfo, util, filterResponse, originalParam } = event;
|
||||
let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
|
||||
let { uid } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-contract",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
// status:
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 查看合同
|
||||
* @url client/contract/kh/view 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, userInfo, util, filterResponse, originalParam } = event;
|
||||
let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
|
||||
let { uid, contractId } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const contract = await vk.daoCenter.contractDao.selects({
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
getOne: true,
|
||||
getMain: true
|
||||
})
|
||||
|
||||
const viewRes = pubFun.fadadaUrl('viewContract.api', {
|
||||
contract_id: contract.transactionId
|
||||
})
|
||||
|
||||
res.data = viewRes
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user