'use strict'; module.exports = { /** * XXXnameXXX * @url client/enquiry/sheet/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: ""}; // 业务逻辑开始----------------------------------------------------------- // 生成询价编号 let amountItem, amount, goodsName, id, sheet, isSingleQuote = false if (data.buyQuoteMode === 'single') { switch (data.type) { case 'enquiry' : { sheet = await vk.baseDao.findByWhereJson({ dbName: "jjx-enquiry-sheet", whereJson: { _id: data.id } }) } break; case 'old' : { sheet = await vk.baseDao.findByWhereJson({ dbName: "jjx-old", whereJson: { _id: data.id } }) } break; case 'process' : { sheet = await vk.baseDao.findByWhereJson({ dbName: "jjx-process-sheet", whereJson: { _id: data.id } }) } break; } id = '6587b034466d41a591df881c' amountItem = await vk.baseDao.findById({ dbName: 'jjx-dict', id }) if (sheet.quoteAmount) { amount = sheet.quoteAmount isSingleQuote = true } else { amount = amountItem.content } goodsName = '单次报价购买' } else { id = data.buyQuoteMode amountItem = await vk.baseDao.findById({ dbName: 'jjx-quote-num-config', id }) amount = amountItem.amount goodsName = `${amountItem.name}报价购买` } 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) } } const orderId = await vk.baseDao.add({ dbName: "jjx-order", dataJson: { orderNo: vk.pubfn.createOrderNo("39XU", 20), uid, orderStatus: 0, type: 7, amount, offAmount, saveAmount, offRate, } }) await vk.baseDao.add({ dbName: "jjx-order-goods", dataJson: { orderId, goodsId: id, mode: data.buyQuoteMode === 'single' ? 'single' : 'monthly', num: 1, goodsName, goodsPrice: amount, goodsCover: null, isSingleQuote, sheetId: data.id, type: data.type, } }) res.data = orderId // 业务逻辑结束----------------------------------------------------------- return res; } }