20261008
This commit is contained in:
@@ -0,0 +1,387 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config");
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* 企业用户列表
|
||||
* @url client/user/pub/getCompany 前端调用的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 res = {code: 0, msg: ""};
|
||||
|
||||
const order = await vk.baseDao.findByWhereJson({
|
||||
|
||||
dbName: "jjx-order",
|
||||
whereJson: {
|
||||
orderNo: data.orderNo,
|
||||
}
|
||||
});
|
||||
|
||||
// type 0: 商品
|
||||
// type 1: 自营
|
||||
// type 2: 保证金
|
||||
// type 3: 会员升级
|
||||
// type 7: 询价次数
|
||||
|
||||
// orderStatus 0待支付 1已支付待发货 2已发货待收货 3已收货待完成 4已完成 5退款审核中 6退款成功 7退款失败
|
||||
if (order && order.orderStatus === 0 && data.billStatus === 'PAID') {
|
||||
const billPayment = JSON.parse(data.billPayment)
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: order._id,
|
||||
dataJson: {
|
||||
orderStatus: 1,
|
||||
payTime: billPayment.payTime,
|
||||
payAmount: parseFloat(billPayment.receiptAmount) / 100,
|
||||
payNo: billPayment.paySeqId,
|
||||
}
|
||||
});
|
||||
|
||||
if ([2, 3, 11, 12, 13].includes(order.type)) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: order._id,
|
||||
dataJson: {
|
||||
orderStatus: 4
|
||||
}
|
||||
});
|
||||
}
|
||||
if (order.type === 0) {
|
||||
const goodsList = await vk.baseDao.select({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
console.log('goodsList', goodsList)
|
||||
for (let i = 0; i < goodsList.rows.length; i++) {
|
||||
const orderGoods = goodsList.rows[i];
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-goods",
|
||||
whereJson: {
|
||||
_id: orderGoods.goodsId,
|
||||
}
|
||||
});
|
||||
console.log('goods', goods)
|
||||
if (!goods.sales) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-goods",
|
||||
id: orderGoods.goodsId,
|
||||
dataJson: {
|
||||
sales: 1,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-goods",
|
||||
id: orderGoods.goodsId,
|
||||
dataJson: {
|
||||
sales: _.inc(1),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if (order.type === 2) {
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: order.uid,
|
||||
dataJson: {
|
||||
paidEnsure: _.inc(goods.goodsPrice),
|
||||
}
|
||||
});
|
||||
} else if (order.type === 3) {
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
const userLevelConfig = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-user-level",
|
||||
whereJson: {
|
||||
level: goods.goodsId,
|
||||
}
|
||||
});
|
||||
const dataJson = {
|
||||
userLevel: goods.goodsId,
|
||||
userGrade: 0,
|
||||
upgradeExpiredAt: vk.pubfn.getOffsetTime(new Date(), {
|
||||
year: 1,
|
||||
mode: "after",
|
||||
})
|
||||
}
|
||||
if (userLevelConfig.ensureAmount && userLevelConfig.ensureAmount > 0) {
|
||||
dataJson.paidEnsure = _.inc(userLevelConfig.ensureAmount)
|
||||
}
|
||||
const user = await vk.baseDao.updateAndReturn({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
_id: order.uid,
|
||||
},
|
||||
dataJson
|
||||
});
|
||||
const messageConfig = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
dataJson: {
|
||||
uid: order.uid
|
||||
}
|
||||
});
|
||||
|
||||
if (!messageConfig) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message-config",
|
||||
dataJson: {
|
||||
uid: order.uid,
|
||||
article: true,
|
||||
process: true,
|
||||
old: true,
|
||||
enquiry: true,
|
||||
productList: [],
|
||||
addressList: [],
|
||||
tradeSelf: true,
|
||||
tradePlatform: true,
|
||||
doNotDisturbRange: [],
|
||||
tradeAmount: [],
|
||||
}
|
||||
})
|
||||
}
|
||||
} else if (order.type === 7) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: order._id,
|
||||
dataJson: {
|
||||
orderStatus: 4
|
||||
}
|
||||
});
|
||||
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
// 单次
|
||||
if (goods.goodsId === '6587b034466d41a591df881c') {
|
||||
// 仅针对单条询价次数
|
||||
if (goods.isSingleQuote) {
|
||||
const checkData = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-user-quote-num",
|
||||
whereJson: {
|
||||
uid: order.uid,
|
||||
type: goods.type,
|
||||
sheetId: goods.sheetId,
|
||||
}
|
||||
});
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-user-quote-num",
|
||||
dataJson: {
|
||||
num: checkData ? _.inc(1) : 1,
|
||||
type: goods.type,
|
||||
sheetId: goods.sheetId,
|
||||
uid: order.uid,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: order.uid,
|
||||
dataJson: {
|
||||
remainQuoteNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const amountItem = await vk.baseDao.findById({
|
||||
dbName: 'jjx-quote-num-config',
|
||||
id: goods.goodsId
|
||||
})
|
||||
const user = await vk.baseDao.findById({
|
||||
dbName: "uni-id-users",
|
||||
id: order.uid
|
||||
});
|
||||
let quoteExpiredAt = vk.pubfn.getOffsetTime(new Date(), {
|
||||
day: amountItem.day,
|
||||
mode: "after",
|
||||
})
|
||||
if (user.quoteExpiredAt) {
|
||||
if (dayjs(user.quoteExpiredAt).isAfter(dayjs())) {
|
||||
vk.pubfn.getOffsetTime(dayjs(user.quoteExpiredAt).toDate(), {
|
||||
day: amountItem.day,
|
||||
mode: "after",
|
||||
})
|
||||
}
|
||||
}
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: order.uid,
|
||||
dataJson: {
|
||||
quoteExpiredAt
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (order.type === 8) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: order._id,
|
||||
dataJson: {
|
||||
orderStatus: 4
|
||||
}
|
||||
});
|
||||
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
|
||||
const hasData = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-spot-ad",
|
||||
whereJson: {
|
||||
uid: order.uid,
|
||||
province: goods.goodsId
|
||||
}
|
||||
})
|
||||
let topExpiredAt = vk.pubfn.getOffsetTime(new Date(), {
|
||||
month: goods.num,
|
||||
mode: "after",
|
||||
})
|
||||
|
||||
if (!hasData) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-spot-ad",
|
||||
dataJson: {
|
||||
uid: order.uid,
|
||||
province: goods.goodsId,
|
||||
topExpiredAt
|
||||
}
|
||||
})
|
||||
} else {
|
||||
topExpiredAt = vk.pubfn.getOffsetTime(hasData.topExpiredAt, {
|
||||
month: goods.num,
|
||||
mode: "after",
|
||||
})
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-spot-ad",
|
||||
id: hasData._id,
|
||||
dataJson: {
|
||||
topExpiredAt
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-spot-goods",
|
||||
id: goods.pk,
|
||||
dataJson: {
|
||||
topExpiredAt
|
||||
}
|
||||
});
|
||||
} else if (order.type === 9) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: order._id,
|
||||
dataJson: {
|
||||
orderStatus: 4
|
||||
}
|
||||
});
|
||||
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-old",
|
||||
id: goods.goodsId,
|
||||
dataJson: {
|
||||
isUrgent: true
|
||||
}
|
||||
})
|
||||
} else if (order.type === 10) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: order._id,
|
||||
dataJson: {
|
||||
orderStatus: 4
|
||||
}
|
||||
});
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: order.uid,
|
||||
dataJson: {
|
||||
remainOldNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
} else if (order.type === 11) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: order.uid,
|
||||
dataJson: {
|
||||
remainArticleDownloadNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
} else if (order.type === 12) {
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
const contract = await vk.baseDao.findById({
|
||||
dbName: "jjx-contract",
|
||||
id: goods.goodsId
|
||||
});
|
||||
const canDownloadUidList = []
|
||||
if (!contract.canDownloadUidList) {
|
||||
canDownloadUidList.push(order.uid)
|
||||
} else {
|
||||
canDownloadUidList.push(...contract.canDownloadUidList, order.uid)
|
||||
}
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-contract",
|
||||
id: goods.goodsId,
|
||||
dataJson: {
|
||||
canDownloadUidList
|
||||
}
|
||||
});
|
||||
} else if (order.type === 13) {
|
||||
const goods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
}
|
||||
});
|
||||
const qyb = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-qyb",
|
||||
whereJson: {
|
||||
_id: goods.goodsId
|
||||
}
|
||||
});
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: order.uid,
|
||||
dataJson: {
|
||||
qybNum: _.inc(qyb.getNum)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user