128 lines
4.1 KiB
JavaScript
128 lines
4.1 KiB
JavaScript
'use strict';
|
|
module.exports = {
|
|
/**
|
|
* XXXnameXXX
|
|
* @url client/order/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: ""};
|
|
// 业务逻辑开始-----------------------------------------------------------
|
|
const companyList = []
|
|
let goods
|
|
if (data.type === 0) {
|
|
goods = await vk.baseDao.findById({
|
|
dbName: "jjx-goods",
|
|
id: data.goodsId
|
|
})
|
|
if (goods.companyId) companyList.push(goods.companyId)
|
|
} else {
|
|
goods = data.goods
|
|
}
|
|
|
|
let amount
|
|
if (goods.sku) {
|
|
const sku = goods.sku.find(item => item._index === data.skuId)
|
|
amount = sku.values * data.num
|
|
}else {
|
|
amount = goods.amount * data.num
|
|
}
|
|
|
|
let ensureIndex = 0
|
|
if (data.ensureIndex) ensureIndex = data.ensureIndex
|
|
|
|
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 && ![2, 3].includes(data.type)) {
|
|
offRate = parseInt(userLevel.valueAddRate)
|
|
offAmount = (amount * (parseInt(userLevel.valueAddRate) / 100)).toFixed(2)
|
|
saveAmount = (amount - offAmount).toFixed(2)
|
|
}
|
|
}
|
|
|
|
// orderStatus 0待支付 1已支付待发货 2已发货待收货 3已收货待完成 4已完成 5退款审核中 6退款成功 7退款失败 10 待设置价格 11已派单待完成(平台服务)
|
|
|
|
// type 0: 商品
|
|
// type 1: 自营
|
|
// type 2: 保证金
|
|
// type 3: 会员升级
|
|
// type 4: 询价
|
|
// type 5: 加工
|
|
// type 6: 旧货
|
|
// type 7: 询价次数
|
|
// type 8: 现货广告
|
|
// type 9: 旧货加急
|
|
// type 10: 旧货次数
|
|
// type 11: 下载次数
|
|
// type 12: 合同下载
|
|
// type 13: 签约宝次数
|
|
// type 14: 签约宝
|
|
// type 15: 自营询价
|
|
|
|
const defaultAddress = await vk.baseDao.findByWhereJson({
|
|
dbName: "jjx-user-address",
|
|
whereJson: {
|
|
uid,
|
|
isDefault: true
|
|
}
|
|
})
|
|
let name = '', phone = '', addressRegion = null, addressDetail = ''
|
|
if (defaultAddress) {
|
|
name = defaultAddress.name
|
|
phone = defaultAddress.phone
|
|
addressRegion = defaultAddress.addressRegion
|
|
addressDetail = defaultAddress.addressDetail
|
|
}
|
|
|
|
const orderId = await vk.baseDao.add({
|
|
dbName: "jjx-order",
|
|
dataJson: {
|
|
orderNo: vk.pubfn.createOrderNo("39XU", 24),
|
|
// orderNo: vk.pubfn.createOrderNo("3199", 24),
|
|
uid,
|
|
orderStatus: 0,
|
|
type: data.type,
|
|
amount,
|
|
offAmount,
|
|
saveAmount,
|
|
offRate,
|
|
name,
|
|
phone,
|
|
addressRegion,
|
|
addressDetail,
|
|
companyList,
|
|
ensureIndex,
|
|
}
|
|
})
|
|
|
|
await vk.baseDao.add({
|
|
dbName: "jjx-order-goods",
|
|
dataJson: {
|
|
orderId,
|
|
goodsId: data.goodsId,
|
|
skuId: data.skuId,
|
|
num: data.num,
|
|
goodsName: goods.name,
|
|
goodsPrice: goods.amount,
|
|
goodsCover: goods.cover,
|
|
companyId: goods.companyId,
|
|
}
|
|
})
|
|
|
|
res.data = orderId
|
|
// 业务逻辑结束-----------------------------------------------------------
|
|
return res;
|
|
}
|
|
}
|