Files
jjx-web/uniCloud-tcb/cloudfunctions/router/service/client/selfSupport/kh/addOrder.js
T
2026-10-08 18:18:21 +08:00

134 lines
4.2 KiB
JavaScript

'use strict';
module.exports = {
/**
* XXXnameXXX
* @url client/selfSupport/kh/addOrder 前端调用的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,
contentList,
amountList,
type,
receiveAddressRegion,
email,
wechat,
receiveAddress,
requestName,
contactName,
contact,
remark,
} = data;
let res = {code: 0, msg: ""};
// 业务逻辑开始-----------------------------------------------------------
const configList = await vk.baseDao.select({
dbName: "jjx-coop-config",
whereJson: {
type
}
})
let orderId = null
const goodsList = []
let amount = 0
configList.rows.forEach(config => {
config.contents.forEach(content => {
if (content.amountList) {
content.amountList.forEach(amountItem => {
amountList.forEach(amountTmp => {
const [contentIndex, amountIndex, costNum] = amountTmp.split(',')
if (contentIndex === content._index && amountIndex === amountItem._index) {
amount += amountItem.amount
goodsList.push({
goodsName: `${config.name}-${content.title}-${amountItem.title}`,
num: contentList.length,
goodsPrice: amountItem.amount,
goodsCover: null,
goodsId: null,
costNum,
contentIndex,
amountIndex,
configId: config._id
})
}
})
})
}
})
})
amount *= contentList.length
let offAmount = amount
let saveAmount = 0, offRate = 100
if (userInfo.userLevel > 0) {
const userLevel = await vk.baseDao.findByWhereJson({
dbName: "jjx-user-level",
whereJson: {
level: userInfo.userLevel
}
})
if (userLevel) {
offRate = parseInt(userLevel.valueAddRate)
offAmount = (amount * (parseInt(userLevel.valueAddRate) / 100)).toFixed(2)
saveAmount = (amount - offAmount).toFixed(2)
}
}
if (type === 2) {
amount = saveAmount = offAmount = offRate = 0
}
orderId = await vk.baseDao.add({
dbName: "jjx-order",
dataJson: {
orderNo: vk.pubfn.createOrderNo("39XU", 20),
uid,
orderStatus: type === 2 ? 10 : 0,
type: 1,
subType: type,
amount,
saveAmount,
offAmount,
offRate,
addressRegion: contentList[0].addressRegion
}
})
goodsList.forEach((item, index) => {
goodsList[index].orderId = orderId
})
await vk.baseDao.adds({
dbName: "jjx-order-goods",
dataJson: goodsList
})
await vk.baseDao.add({
dbName: "jjx-order-selfProduct",
dataJson: {
orderId,
type,
receiveAddressRegion,
email,
wechat,
receiveAddress,
requestName,
contactName,
contact,
remark,
contentList,
uid,
}
})
if (type < 2) res.data = orderId
// 业务逻辑结束-----------------------------------------------------------
return res;
}
}