20261008
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增加工单
|
||||
* @url client/process/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,
|
||||
title,
|
||||
address,
|
||||
files,
|
||||
remark,
|
||||
invoice,
|
||||
writeInvoiceTime,
|
||||
invoiceType,
|
||||
transportDocuments,
|
||||
otherTransportDocuments,
|
||||
transportLimit,
|
||||
tradeMethod,
|
||||
payMethod,
|
||||
advancePayRate,
|
||||
otherPayMethod,
|
||||
reputationPayDay,
|
||||
answerTime,
|
||||
earnestMoney,
|
||||
status
|
||||
} = data;
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: "添加成功"
|
||||
};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
if (parseInt(userInfo.userLevel) < 3)
|
||||
{
|
||||
if (parseInt(userInfo.remainQuoteNum) === 0 || !userInfo.remainQuoteNum) {
|
||||
|
||||
return {
|
||||
code: 1,
|
||||
msg: "您的询价次数用完"
|
||||
}
|
||||
}
|
||||
if (userInfo.quoteExpiredAt || dayjs(userInfo.quoteExpiredAt).isBefore(dayjs())) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: "您的询价次数已过期"
|
||||
}
|
||||
}
|
||||
}
|
||||
if (userInfo.remainQuoteNum && userInfo.remainQuoteNum > 0) {
|
||||
await vk.baseDao.update({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
uid
|
||||
},
|
||||
dataJson: {
|
||||
remainQuoteNum: _.inc(-1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.id = await vk.baseDao.add({
|
||||
dbName: '',
|
||||
dataJson:{
|
||||
title,
|
||||
address,
|
||||
files,
|
||||
remark,
|
||||
invoice,
|
||||
writeInvoiceTime,
|
||||
invoiceType,
|
||||
transportDocuments,
|
||||
otherTransportDocuments,
|
||||
transportLimit,
|
||||
tradeMethod,
|
||||
payMethod,
|
||||
advancePayRate,
|
||||
otherPayMethod,
|
||||
reputationPayDay,
|
||||
answerTime,
|
||||
earnestMoney,
|
||||
status,
|
||||
answerNumber: 0,
|
||||
showInAdmin: 1,
|
||||
userId: uid
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
var isBetween = require('dayjs/plugin/isBetween')
|
||||
dayjs.extend(isBetween)
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增报价
|
||||
* @url client/process/quote/kh/addQuote 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
if (parseInt(userInfo.factoryStatus) !== 1) return {
|
||||
code: 1,
|
||||
msg: "非加工厂,无法报价,请去个人中心申请加工厂"
|
||||
}
|
||||
|
||||
let noQuoteNo = false
|
||||
|
||||
if (parseInt(userInfo.userLevel) < 3) {
|
||||
if (parseInt(userInfo.remainQuoteNum) === 0 || !userInfo.remainQuoteNum) {
|
||||
|
||||
const checkSheetQuoteNum = await vk.baseDao.findById({
|
||||
dbName: "jjx-process-sheet",
|
||||
id: data.sheetId
|
||||
})
|
||||
if (checkSheetQuoteNum.quoteAmount) {
|
||||
const checkQuoteNum = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-user-quote-num",
|
||||
whereJson: {
|
||||
uid,
|
||||
type: 'process',
|
||||
sheetId: data.sheetId,
|
||||
}
|
||||
});
|
||||
if (!checkQuoteNum || checkQuoteNum.num === 0) noQuoteNo = true
|
||||
} else noQuoteNo = true
|
||||
}
|
||||
noQuoteNo = !!(userInfo.quoteExpiredAt && dayjs(userInfo.quoteExpiredAt).isBefore(dayjs()));
|
||||
}
|
||||
if (noQuoteNo) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: "您的报价次数已过期/用完"
|
||||
}
|
||||
}
|
||||
if (userInfo.remainQuoteNum && userInfo.remainQuoteNum > 0) {
|
||||
await vk.baseDao.update({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
uid
|
||||
},
|
||||
dataJson: {
|
||||
remainQuoteNum: _.inc(-1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const checkSheet = await vk.baseDao.findById({
|
||||
dbName: "jjx-process-sheet",
|
||||
id: data.sheetId
|
||||
})
|
||||
|
||||
if (checkSheet.status > 0) return {
|
||||
code: 11,
|
||||
msg: "该加工单已关闭"
|
||||
}
|
||||
|
||||
if (checkSheet.earnestMoney && checkSheet.earnestMoney > 0 && checkSheet.earnestMoney > userInfo.paidEnsure) {
|
||||
return {
|
||||
code: 12,
|
||||
msg: "您的保证金不足,请先缴纳保证金"
|
||||
}
|
||||
}
|
||||
|
||||
const dbName = 'jjx-process-quote'
|
||||
await vk.baseDao.add({
|
||||
dbName,// 表名
|
||||
dataJson: { // 需要新增的数据 json格式
|
||||
...data,
|
||||
...{
|
||||
userId: data.uid,
|
||||
status: 0
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await vk.baseDao.update({
|
||||
dbName: "jjx-process-sheet",// 表名
|
||||
whereJson: {
|
||||
_id: data.sheetId,
|
||||
},
|
||||
dataJson: {
|
||||
quoteNum: _.inc(1)
|
||||
}
|
||||
})
|
||||
|
||||
const sheet = await vk.baseDao.findById({
|
||||
dbName: "jjx-process-sheet",// 表名
|
||||
id: data.sheetId
|
||||
});
|
||||
|
||||
const checkMessage = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
process: true,
|
||||
uid: sheet.userId
|
||||
}
|
||||
})
|
||||
|
||||
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}`)))
|
||||
// return res
|
||||
// }
|
||||
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}`)))
|
||||
return res
|
||||
}
|
||||
|
||||
if (checkMessage.tradeAmount && checkMessage.tradeAmount[0]) {
|
||||
if (sheet.totalPrice < checkMessage.tradeAmount[0] || sheet.totalPrice > checkMessage.tradeAmount[1])
|
||||
return res
|
||||
}
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: sheet.userId,
|
||||
title: `加工:${sheet.title}报价`,
|
||||
content: `您的加工信息有新的报价,赶紧去看看吧`,
|
||||
type: 'process',
|
||||
hasRead: false,
|
||||
pk: data.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(sheet.userId, 'SMS_474165512')
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
'use strict';
|
||||
|
||||
const dbName = require('../../../../../dao/config.js')
|
||||
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 {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun,
|
||||
vk,
|
||||
db,
|
||||
_
|
||||
} = 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.selects({
|
||||
dbName: dbName.enquirySheet,
|
||||
whereJson: {_id: quote.sheetId},
|
||||
getMain: true,
|
||||
getOne: true
|
||||
})
|
||||
|
||||
// 获取商品信息
|
||||
const productTitle = sheet.productList.map(item => {
|
||||
return item.goodsName
|
||||
}).join("/")
|
||||
|
||||
if (sheet.signMethod !== 1) {
|
||||
console.log('quote', quote)
|
||||
console.log('sheet', sheet)
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("E", 20)
|
||||
// 新增合同记录
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
fadadaContractId: fadadaContractId,
|
||||
contractBase: '', // 原始合同
|
||||
contractHistory: [], // 历史合同
|
||||
contractFinal: '', // 归档合同
|
||||
status: 0,
|
||||
userId: uid,
|
||||
type: 'enquiry',
|
||||
quoteId: quoteId,
|
||||
sheetId: quote.sheetId,
|
||||
productList: quote.productList,
|
||||
productTitle,
|
||||
tradeMethod: quote.tradeMethod,
|
||||
partyCount: 2,
|
||||
signCount: 0,
|
||||
contractType: sheet.contractType,
|
||||
signMethod: sheet.signMethod,
|
||||
sellerSupplement: sheet.sellerSupplement,
|
||||
transactionId: vk.pubfn.createOrderNo("C", 20),
|
||||
amount: quote.totalPrice,
|
||||
docTitle: sheet.title,
|
||||
}
|
||||
})
|
||||
|
||||
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: uid,
|
||||
role: 'buyer',
|
||||
sign: false,
|
||||
contractId
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: quote.userId,
|
||||
role: 'seller',
|
||||
sign: false,
|
||||
contractId
|
||||
}
|
||||
])
|
||||
}else {
|
||||
const orderId = await vk.baseDao.add({
|
||||
dbName: "jjx-order",
|
||||
dataJson: {
|
||||
orderNo: vk.pubfn.createOrderNo("39XU", 20),
|
||||
uid: uid,
|
||||
sellerUid: quote.userId,
|
||||
orderStatus: 0,
|
||||
type: 4,
|
||||
amount: quote.totalPrice,
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user