20261008
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url admin/article/category/sys/list 前端调用的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, page} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
res = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-album',
|
||||
whereJson: {page},
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/category/pub/getList 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.getTableData({
|
||||
dbName: 'jjx-article-category',
|
||||
sortArr: [
|
||||
{ name: "sort", type: "asc" },
|
||||
{ name: "_id", type: "desc" },
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/collect/kh/changeCollect 前端调用的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 collect = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-article-collect',
|
||||
whereJson: {
|
||||
uid,
|
||||
articleId: data.articleId
|
||||
}
|
||||
})
|
||||
|
||||
if (collect) {
|
||||
await vk.baseDao.deleteById({
|
||||
dbName: "jjx-article-collect",
|
||||
id: collect._id
|
||||
});
|
||||
} else {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-article-collect",
|
||||
dataJson: {
|
||||
uid,
|
||||
articleId: data.articleId
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/collect/kh/check 前端调用的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 collect = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-article-collect',
|
||||
whereJson: {
|
||||
uid,
|
||||
articleId: data.articleId
|
||||
}
|
||||
})
|
||||
|
||||
res.data = !!collect
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/collect/kh/getList 前端调用的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, pageIndex, pageSize} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: 'jjx-article-collect',
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
whereJson: {
|
||||
uid
|
||||
},
|
||||
sortArr: [
|
||||
{name: "_id", type: "desc"}
|
||||
],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "jjx-article",
|
||||
localKey: "articleId",
|
||||
foreignKey: "_id",
|
||||
as: "article",
|
||||
limit: 1
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/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 res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: 'jjx-article',
|
||||
dataJson: {
|
||||
...data, ...{
|
||||
viewNum: 0,
|
||||
downloadNum: 0,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/kh/addDownload 前端调用的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 (userInfo.userLevel < 0) return {code: 1, msg: "非会员,无法下载"};
|
||||
if (userInfo.userLevel === 0 && userInfo.remainArticleDownloadNum === 0) return {code: 1, msg: "无下载次数,无法下载"};
|
||||
// if (userInfo.userLevel === 0 && userInfo.remainArticleDownloadNum > 0) {
|
||||
// await vk.baseDao.update({
|
||||
// dbName: 'uni-id-users',
|
||||
// whereJson: {
|
||||
// _id: uid,
|
||||
// },
|
||||
// dataJson: {
|
||||
// remainArticleDownloadNum: _.inc(-1)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
const check = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-article-download",
|
||||
whereJson: {
|
||||
uid,
|
||||
articleId: data.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!check) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-article-download",
|
||||
dataJson: {
|
||||
uid,
|
||||
articleId: data.id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/kh/check 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res.data = !!await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-article-download",
|
||||
whereJson: {
|
||||
uid,
|
||||
articleId: data.id
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/kh/addDownload 前端调用的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, pageIndex, pageSize} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: "jjx-article-download",
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
whereJson: {
|
||||
uid,
|
||||
},
|
||||
sortArr: [
|
||||
{name: "_id", type: "desc"}
|
||||
],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "jjx-article",
|
||||
localKey: "articleId",
|
||||
foreignKey: "_id",
|
||||
as: "article",
|
||||
limit: 1
|
||||
},
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/kh/getUserList 前端调用的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, pageIndex, pageSize} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.select({
|
||||
dbName: 'jjx-article',
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
whereJson: {
|
||||
uid
|
||||
},
|
||||
sortArr: [
|
||||
{name: "_id", type: "desc"}
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/pub/addDownload 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-article",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
downloadNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/pub/addView 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-article",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
viewNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/otherArticle/list/pub/getDetail 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
// await vk.baseDao.update({
|
||||
// dbName: "uni-id-users",
|
||||
// whereJson:{
|
||||
// remainArticleDownloadNum: 0
|
||||
// },
|
||||
// dataJson:{
|
||||
// remainArticleDownloadNum: 3
|
||||
// },
|
||||
// })
|
||||
|
||||
res = await vk.baseDao.findById({
|
||||
dbName: "jjx-article",
|
||||
id: data.id,
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/pub/getList 前端调用的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 {pageIndex, pageSize, parentId, keyword} = data
|
||||
const whereJson = {parentId}
|
||||
if (vk.pubfn.isNotNull(keyword)) {
|
||||
whereJson.name = new RegExp(keyword)
|
||||
}
|
||||
res = await vk.baseDao.select({
|
||||
dbName: 'jjx-article',
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
whereJson,
|
||||
sortArr: [
|
||||
{name: "_id", type: "desc"}
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/cart/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 inCart = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-cart",
|
||||
whereJson: {
|
||||
uid,
|
||||
goodsId: data.goodsId,
|
||||
skuId: data.skuId,
|
||||
}
|
||||
});
|
||||
console.log('inCart', inCart)
|
||||
if (inCart) {
|
||||
const res = await vk.baseDao.updateById({
|
||||
dbName: "jjx-cart",
|
||||
id: inCart._id,
|
||||
dataJson: {
|
||||
num: _.inc(1)
|
||||
}
|
||||
})
|
||||
console.log('res2', res)
|
||||
} else {
|
||||
const res = await vk.baseDao.add({
|
||||
dbName: "jjx-cart",
|
||||
dataJson: {
|
||||
num: data.num,
|
||||
goodsId: data.goodsId,
|
||||
skuId: data.skuId,
|
||||
uid
|
||||
}
|
||||
})
|
||||
console.log('res1', res)
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/cart/kh/changeNum 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-cart",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
num: data.num,
|
||||
}
|
||||
});
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/cart/kh/delete 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
await vk.baseDao.del({
|
||||
dbName: "jjx-cart",
|
||||
whereJson: {
|
||||
uid,
|
||||
_id: _.in(data.ids)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/cart/kh/getList 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: "jjx-cart",
|
||||
getCount: true,
|
||||
whereJson: {
|
||||
uid
|
||||
},
|
||||
pageIndex: 1,
|
||||
pageSize: 500
|
||||
})
|
||||
|
||||
// ,
|
||||
// foreignDB: [
|
||||
// {
|
||||
// dbName: "jjx-goods",
|
||||
// localKey: "goodsId",
|
||||
// foreignKey: "_id",
|
||||
// as: "goods",
|
||||
// limit: 1
|
||||
// }
|
||||
// ]
|
||||
|
||||
for (let i in res.rows) {
|
||||
res.rows[i].goods = await vk.baseDao.findById({
|
||||
dbName: 'jjx-goods',
|
||||
id: res.rows[i].goodsId
|
||||
})
|
||||
|
||||
res.rows[i].sku = res.rows[i].goods.sku.find(item => item._index === res.rows[i].skuId)
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config");
|
||||
const dayjs = require("dayjs");
|
||||
var isBetween = require('dayjs/plugin/isBetween')
|
||||
dayjs.extend(isBetween)
|
||||
|
||||
const PROCESS_PAY_METHOD = ['预付', '货到验收后付款', '提货付全款', '信誉采购,货到签单后账期:']
|
||||
const WRITE_INVOICE_TIME = ['付款当月(限20号之前付款,20号之后付款次月开票)', '付款后次月', '付款前']
|
||||
const INVOICE_TYPE = ['增值税专用发票13%', '增值税普通发票', '普通发票']
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增合同
|
||||
* @url client/contract/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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
// await vk.baseDao.updateById({
|
||||
// dbName: 'jjx-process-sheet',
|
||||
// id: data.sheetId,
|
||||
// dataJson: {
|
||||
// status: 1
|
||||
// }
|
||||
// })
|
||||
const quote = await vk.baseDao.updateAndReturn({
|
||||
dbName: 'jjx-process-quote',
|
||||
whereJson: {
|
||||
_id: data.quoteId
|
||||
},
|
||||
dataJson: {
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
// const quote = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-process-quote',
|
||||
// id: data.quoteId
|
||||
// })
|
||||
|
||||
const sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: 'jjx-process-sheet',
|
||||
whereJson: {
|
||||
_id: quote.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
otherUid: data.seller,
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
const checkMessage = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
process: true,
|
||||
uid: quote.userId
|
||||
}
|
||||
})
|
||||
|
||||
if (checkMessage && sheet) {
|
||||
let send = true
|
||||
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}`)))
|
||||
// send = false
|
||||
// }
|
||||
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}`)))
|
||||
send = false
|
||||
}
|
||||
}
|
||||
if (send) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: quote.userId,
|
||||
title: `加工:${sheet.title}被选商`,
|
||||
content: `您报价的加工信息已被选商,赶紧去签合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
pk: quote.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(quote.userId, 'SMS_474210523')
|
||||
}
|
||||
}
|
||||
|
||||
if (sheet.signMethod !== 1) {
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("P", 20)
|
||||
let contractTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
data.transactionId = contractTransactionId
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
...data, ...{
|
||||
fadadaContractId,
|
||||
status: 0,
|
||||
userId: uid,
|
||||
changeNum: 0,
|
||||
tradeMethod: sheet.tradeMethod
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("P", 20),
|
||||
userId: uid,
|
||||
role: 'buyer',
|
||||
sign: false,
|
||||
contractId,
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("P", 20),
|
||||
userId: data.seller,
|
||||
role: 'seller',
|
||||
sign: false,
|
||||
contractId,
|
||||
}
|
||||
])
|
||||
|
||||
// 标准合同
|
||||
if (sheet.signMethod === 0) {
|
||||
|
||||
const templateId = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '80e3bed065a5560e075799d24532b14f'
|
||||
})
|
||||
const buyerSignKeyword = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '0b153f9a65a56a2007227cf5157133bf'
|
||||
})
|
||||
const sellerSignKeyword = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '09e7876865a56a320731cb244bbef818'
|
||||
})
|
||||
const signMaxDate = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '657d78958b0da41d311bd94c'
|
||||
})
|
||||
const signEndDate = vk.pubfn.getOffsetTime(new Date(), {
|
||||
day: parseInt(signMaxDate.content),
|
||||
mode: "after",
|
||||
});
|
||||
// const fieldList = await vk.baseDao.select({
|
||||
// dbName: 'jjx-contract-template',
|
||||
// whereJson: {
|
||||
// isOn: true
|
||||
// }
|
||||
// })
|
||||
const sellerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: quote.userId
|
||||
})
|
||||
const buyerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: uid
|
||||
})
|
||||
|
||||
let tradeInfo = PROCESS_PAY_METHOD[sheet.payMethod]
|
||||
if (sheet.payMethod === 0) tradeInfo += `${sheet.advancePayRate}%货到付全款`
|
||||
if (sheet.payMethod === 3) tradeInfo += `${sheet.reputationPayDay}天`
|
||||
tradeInfo += `,${sheet.invoice ? '含税' : '不含税'},`
|
||||
if (sheet.invoiceOther) tradeInfo += `,${sheet.invoiceOther}`
|
||||
else {
|
||||
if (sheet.taxType && sheet.invoiceType && sheet.taxRate) tradeInfo += `,${sheet.taxType},${sheet.invoiceType},${sheet.taxRate}`
|
||||
}
|
||||
// tradeInfo += `,${INVOICE_TYPE[sheet.invoiceType]}${sheet.invoiceOther ? sheet.invoiceOther : '无'}`
|
||||
let expressRequire = ''
|
||||
expressRequire += `随货资料:${sheet.transportDocuments.join()},其他要求:${sheet.otherTransportDocuments ? sheet.otherTransportDocuments : '无'},运输限制要求:${sheet.transportLimit ? '有' : '无'}`
|
||||
if (sheet.transportLimit && sheet.otherTransportRequest) expressRequire += `运输限制说明:${sheet.otherTransportRequest}`
|
||||
let region = sheet.addressRegion.province.name + sheet.addressRegion.city.name + sheet.addressRegion.area.name
|
||||
// if (sheet.type === 'process') {
|
||||
if (buyerUser.accountType === 2 && buyerUser.company && buyerUser.company.addressRegion && buyerUser.company.addressRegion.province) {
|
||||
region = buyerUser.company.addressRegion.province.name + buyerUser.company.addressRegion.city.name + buyerUser.company.addressRegion.area.name
|
||||
}
|
||||
if (buyerUser.accountType === 1 && buyerUser.person && buyerUser.person.addressRegion && buyerUser.person.addressRegion.province) {
|
||||
region = buyerUser.person.addressRegion.province.name + buyerUser.person.addressRegion.city.name + buyerUser.person.addressRegion.area.name
|
||||
}
|
||||
|
||||
// }
|
||||
// console.log(buyerUser)
|
||||
const accountType = sheet.invoice ? 'company' : 'person'
|
||||
const buyerBank = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-account",
|
||||
whereJson: {
|
||||
uid: buyerUser._id,
|
||||
type: accountType
|
||||
}
|
||||
})
|
||||
let buyerBankName = buyerUser.accountType === 2 ? buyerUser.company.companyBankName : buyerUser.person.personBankName
|
||||
let buyerAccount = buyerUser.accountType === 2 ? buyerUser.company.companyAccount : buyerUser.person.personAccount
|
||||
let buyerBankAccountName = buyerUser.accountType === 2 ? buyerUser.company.companyAccount : buyerUser.person.personAccount
|
||||
let sellerBankName = sellerUser.accountType === 2 ? sellerUser.company.companyBankName : sellerUser.person.personBankName
|
||||
let sellerAccount = sellerUser.accountType === 2 ? sellerUser.company.companyAccount : sellerUser.person.personAccount
|
||||
let sellerBankAccountName = sellerUser.accountType === 2 ? sellerUser.company.companyAccount : sellerUser.person.personAccount
|
||||
if (buyerBank) {
|
||||
buyerBankName = buyerBank.bankName
|
||||
buyerAccount = buyerBank.account
|
||||
buyerBankAccountName = buyerBank.accountName
|
||||
}
|
||||
const sellerBank = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-account",
|
||||
whereJson: {
|
||||
uid: sellerUser._id,
|
||||
type: accountType
|
||||
}
|
||||
})
|
||||
if (sellerBank) {
|
||||
sellerBankName = sellerBank.bankName
|
||||
sellerAccount = sellerBank.account
|
||||
sellerBankAccountName = sellerBank.accountName
|
||||
}
|
||||
|
||||
const parameter = {
|
||||
seller: sellerUser.accountType === 2 ? sellerUser.company.companyName : sellerUser.person.personName,
|
||||
buyer: buyerUser.accountType === 2 ? buyerUser.company.companyName : buyerUser.person.personName,
|
||||
date: dayjs().format('YYYY年MM月DD日'),
|
||||
sellerSignDate: dayjs(signEndDate).format('YYYY年MM月DD日 HH时mm分'),
|
||||
buyerSignDate: dayjs(signEndDate).format('YYYY年MM月DD日 HH时mm分'),
|
||||
contractNo: fadadaContractId,
|
||||
region,
|
||||
detail: sheet.title,
|
||||
info: sheet.remark ? sheet.remark : '无',
|
||||
tradeInfo,
|
||||
expressRequire,
|
||||
defaultDuty: '1.乙方所交产品品种、型号、规格、质量不符合规定的,如果甲方同意利用,应当按质论价;如果甲方不能利用的,应根据产品的具体情况,由乙方负责包换或包修,并承担修理、调换或退货而支付的实际费用;2.乙方不予供货违约责任为甲方的实际损失+违约金,如乙方材料符合订货标准,甲方不能退货和不收货,甲方无条件应按实际本合同订货数量支付100%货款,并支付乙方因此产生的实际费用。带有甲乙双方单位相关收货人和发货人签字的本合同的发货清单事项和内容均视为本合同的补充合同,与本合同有相同的法律效力,双方应共同遵照执行。',
|
||||
solve: '1、凡因本合同引起的或与本合同有关的任何争议,均可友好协商或仲裁解决,协商或仲裁不成的,双方协商同意在合同签订地人民法院管辖地起诉,违约一方或对合同争议承担主要责任的一方,应承担对方因仲裁和起诉而产生的全部律师代理费、鉴定(检验)费、诉讼保全费、诉讼保险费、公告费、差旅费、执行费、误工費和获取证据产生费用等其他相关费用。2、双方本合同相关权利放弃均应有双方书面作出并加盖公章或授权委托人签字后生效。',
|
||||
forceMajeure: '甲乙双方的任何一方由于不可抗力或突发公共事件的原因不能履行合同时,应及时向对方通报不能履行或不能完全履行的理由,以减轻可能给对方造成的损失,在取得有关机构证明以后,允许延期履行、部分履行或者不履行合同,并根据情况可部分或全部免予承担违约责任。',
|
||||
other: '本合同的全部内容由双方平等共同协商一致,共同起草制定,非一方事先拟定,不属于格式条款。本合同自双方签字盖章后生效(包括电子签字、盖章),按本合同内容地址、联系方式寄送的一切文书、函件送达与否,均为视为送达有法律效力,通知途径和本合同内联系方式或地址送达文件双方均予以验证。',
|
||||
buyerSupplement: sheet.supplementary ? sheet.supplementary : '无',
|
||||
sellerSupplement: sheet.supplierExt ? sheet.supplierExt : (quote.remark ? quote.remark : '无'),
|
||||
buyerAddress: buyerUser.accountType === 2 ? buyerUser.company.mailAddress : buyerUser.person.address,
|
||||
sellerAddress: sellerUser.accountType === 2 ? sellerUser.company.mailAddress : sellerUser.person.address,
|
||||
buyerLegal: buyerUser.accountType === 2 ? buyerUser.company.legalName : '',
|
||||
sellerLegal: sellerUser.accountType === 2 ? sellerUser.company.legalName : '',
|
||||
buyerAgent: buyerUser.accountType === 2 ? buyerUser.manager.personName : '',
|
||||
sellerAgent: sellerUser.accountType === 2 ? sellerUser.manager.personName : '',
|
||||
buyerMobile: buyerUser.accountType === 2 ? buyerUser.manager.mobile : buyerUser.mobile,
|
||||
sellerMobile: sellerUser.accountType === 2 ? sellerUser.manager.mobile : sellerUser.mobile,
|
||||
buyerBankName,
|
||||
sellerBankName,
|
||||
buyerAccount,
|
||||
sellerAccount,
|
||||
buyerBankAccountName,
|
||||
sellerBankAccountName,
|
||||
}
|
||||
// for (let i = 0; i < fieldList.length; i++) {
|
||||
//
|
||||
// const field = fieldList[i]
|
||||
// parameter[field.field] = ''
|
||||
// }
|
||||
const uploaddocs = await pubFun.fadada('generate_contract.api', {
|
||||
template_id: templateId.content,
|
||||
contract_id: contractTransactionId,
|
||||
parameter_map: JSON.stringify(parameter)
|
||||
})
|
||||
let otherFileResList = []
|
||||
if (sheet.files && sheet.files.length > 0) {
|
||||
for (let i = 0; i < sheet.files.length; i++) {
|
||||
otherFileResList.push(contractTransactionId + 'f' + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contractTransactionId + 'f' + i.toString(),
|
||||
doc_title: sheet.title + `:附件${i + 1}`,
|
||||
doc_url: sheet.files[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
}
|
||||
if (sheet.multiFiles && sheet.multiFiles.length > 0) {
|
||||
for (let i = 0; i < sheet.multiFiles.length; i++) {
|
||||
otherFileResList.push(contractTransactionId + 'mf' + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contractTransactionId + 'mf' + i.toString(),
|
||||
doc_title: sheet.title + `:加工商附件${i + 1}`,
|
||||
doc_url: sheet.multiFiles[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
// otherFileResList.unshift(contractTransactionId)
|
||||
|
||||
// 合并接口
|
||||
// contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
// const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
// contract_id: contractTransactionId,
|
||||
// doc_title: sheet.title,
|
||||
// contract_ids: otherFileResList.join()
|
||||
// })
|
||||
// console.log('mergeRes', mergeRes)
|
||||
// console.log('otherFileResList', otherFileResList)
|
||||
}
|
||||
// 存在附件则合并
|
||||
|
||||
if (quote.files && quote.files.length > 0) {
|
||||
for (let i = 0; i < quote.files.length; i++) {
|
||||
otherFileResList.push(contractTransactionId + 'qf' + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contractTransactionId + 'qf' + i.toString(),
|
||||
doc_title: sheet.title + `:报价附件${i + 1}`,
|
||||
doc_url: quote.files[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
// otherFileResList.unshift(contractTransactionId)
|
||||
|
||||
// 合并接口
|
||||
// contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
// const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
// contract_id: contractTransactionId,
|
||||
// doc_title: sheet.title,
|
||||
// contract_ids: otherFileResList.join()
|
||||
// })
|
||||
// console.log('quote mergeRes', mergeRes)
|
||||
// console.log('quote otherFileResList', otherFileResList)
|
||||
}
|
||||
if (otherFileResList.length) {
|
||||
otherFileResList.unshift(contractTransactionId)
|
||||
// 合并接口
|
||||
contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
contract_id: contractTransactionId,
|
||||
doc_title: sheet.title,
|
||||
contract_ids: otherFileResList.join()
|
||||
})
|
||||
console.log('mergeRes', mergeRes)
|
||||
console.log('otherFileResList', otherFileResList)
|
||||
}
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
dataJson: {
|
||||
transactionId: contractTransactionId,
|
||||
}
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
await vk.baseDao.updateAndReturn({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: sheet.title,
|
||||
signEndDate,
|
||||
otherFile: '',
|
||||
contractBase: null,
|
||||
buyerSignKeyword: buyerSignKeyword.content,
|
||||
sellerSignKeyword: sellerSignKeyword.content
|
||||
}
|
||||
})
|
||||
// await vk.baseDao.updateAndReturn({
|
||||
// dbName: 'jjx-process-sheet',
|
||||
// whereJson: {
|
||||
// _id: data.sheetId
|
||||
// },
|
||||
// dataJson: {
|
||||
// status: 2
|
||||
// }
|
||||
// })
|
||||
|
||||
res.data = uploaddocs.result
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: quote.userId,
|
||||
title: `加工:${sheet.title}待签合同`,
|
||||
content: `您报价的加工信息已创建合同,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
pk: quote.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(quote.userId, 'SMS_474295535')
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: uploaddocs.msg
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const orderId = await vk.baseDao.add({
|
||||
dbName: "jjx-order",
|
||||
dataJson: {
|
||||
orderNo: vk.pubfn.createOrderNo("39XU", 20),
|
||||
uid: uid,
|
||||
sellerUid: quote.userId,
|
||||
orderStatus: 0,
|
||||
payStatus: 0,
|
||||
type: 5,
|
||||
amount: quote.totalPrice,
|
||||
offAmount: quote.totalPrice,
|
||||
signMethod: 1,
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增签约宝合同
|
||||
* @url client/contract/kh/addSign 前端调用的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 payByUser = userInfo;
|
||||
|
||||
const otherUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.phone
|
||||
}
|
||||
})
|
||||
if (JSON.stringify(otherUser) === '{}' || !otherUser) return {
|
||||
code: -1,
|
||||
msg: '签约接收方账号不存在'
|
||||
}
|
||||
if (data.payBy === undefined || data.payBy === null || data.payBy === '')
|
||||
return {
|
||||
code: -1,
|
||||
msg: `请选择费用承担方`
|
||||
}
|
||||
if (data.payBy === 1) payByUser = otherUser
|
||||
// console.log('data.thirdList', data.thirdList, data.thirdList && data.thirdList.length > 0, data.thirdList.length > 0)
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
// let inThird = false
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
if (!thirdUser) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}不存在`
|
||||
}
|
||||
if (!thirdUser.fadadaConfirm) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}未通过法大大认证,无法签约`
|
||||
}
|
||||
if (thirdUser.uid === uid) return {
|
||||
code: -1,
|
||||
msg: '第三方不能为自己'
|
||||
}
|
||||
if (thirdUser.uid === otherUser._id) return {
|
||||
code: -1,
|
||||
msg: '第三方不能与对方为相同账号'
|
||||
}
|
||||
if (data.payBy === 2 && i === 0) {
|
||||
payByUser = thirdUser
|
||||
}
|
||||
}
|
||||
// if (data.payBy === 2 && !inThird) return {
|
||||
// code: -1,
|
||||
// msg: '该承担方不在第三方名单中'
|
||||
// }
|
||||
}
|
||||
|
||||
if (!otherUser.fadadaConfirm) return {
|
||||
code: -1,
|
||||
msg: '签约接收方账号未通过法大大认证,无法签约'
|
||||
}
|
||||
|
||||
if (otherUser._id === uid) return {
|
||||
code: -1,
|
||||
msg: '无法与自己签约'
|
||||
}
|
||||
if (payByUser.qybNum <= 0) return {
|
||||
code: -1,
|
||||
msg: '费用承担方已无签约宝次数,无法继续签约'
|
||||
}
|
||||
data.payerUid = payByUser._id
|
||||
data.transactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
let doc_url = data.contractFile
|
||||
if (Array.isArray(doc_url)) doc_url = doc_url[doc_url.length - 1]
|
||||
const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: data.transactionId,
|
||||
doc_title: data.title,
|
||||
doc_url,
|
||||
// file: doc_url,
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
let partyCount = 2
|
||||
if (data.thirdList && data.thirdList.length > 0) partyCount += data.thirdList.length
|
||||
// 对方是甲方
|
||||
const buyerSignKeyword = data.buyerSignKeyword // 签约发起方
|
||||
const sellerSignKeyword = data.sellerSignKeyword // 签约被邀请方
|
||||
data.buyerSignKeyword = data.userType % 2 === 1 ? sellerSignKeyword : buyerSignKeyword
|
||||
data.sellerSignKeyword = data.userType % 2 === 1 ? buyerSignKeyword : sellerSignKeyword
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
...data, ...{
|
||||
status: 1,
|
||||
userId: uid,
|
||||
changeNum: 0,
|
||||
productTitle: data.title,
|
||||
docTitle: data.title,
|
||||
type: 'sign',
|
||||
contractBase: data.contractFile,
|
||||
partyCount,
|
||||
signCount: 0,
|
||||
tradeMethod: data.tradeMethod
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("S", 20),
|
||||
userId: uid,
|
||||
role: data.userType === 1 ? 'seller' : 'buyer',
|
||||
sign: false,
|
||||
contractId,
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("S", 20),
|
||||
userId: otherUser._id,
|
||||
role: data.userType === 1 ? 'buyer' : 'seller',
|
||||
sign: false,
|
||||
contractId,
|
||||
}
|
||||
])
|
||||
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
console.log('thirdUser', thirdUser)
|
||||
if (thirdUser) {
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("ST", 20),
|
||||
userId: thirdUser._id,
|
||||
role: 'third',
|
||||
sign: false,
|
||||
contractId,
|
||||
keyword: data.thirdList[i].signKeyword,
|
||||
},
|
||||
])
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: thirdUser._id,
|
||||
title: `金久信签约宝`,
|
||||
content: `您有签约宝邀请,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
}
|
||||
});
|
||||
}
|
||||
// await pubFun.sendNotifySms(thirdUser._id, 'SMS_474570002', {
|
||||
// name: thirdUser.accountType === 2 ? thirdUser.company.companyName : thirdUser.person.personName,
|
||||
// name2: userInfo.accountType === 2 ? userInfo.company.companyName : userInfo.person.personName,
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: payByUser._id,
|
||||
dataJson: {
|
||||
qybNum: _.inc(-1)
|
||||
}
|
||||
});
|
||||
|
||||
// 签约宝扣费记录
|
||||
const remainNum = payByUser.qybNum - 1
|
||||
const addSignLog = await vk.baseDao.add({
|
||||
dbName: "jjx-sign-pay_list",
|
||||
dataJson: {
|
||||
userId: payByUser._id,
|
||||
remainNum,
|
||||
contractId,
|
||||
payBy: data.payBy
|
||||
}
|
||||
});
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: otherUser._id,
|
||||
title: `金久信签约宝`,
|
||||
content: `您有金久信签约宝邀请,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
}
|
||||
});
|
||||
// await pubFun.sendNotifySms(otherUser._id, 'SMS_474570002', {
|
||||
// name: otherUser.accountType === 2 ? otherUser.company.companyName : otherUser.person.personName,
|
||||
// name2: userInfo.accountType === 2 ? userInfo.company.companyName : userInfo.person.personName,
|
||||
// })
|
||||
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config");
|
||||
const dayjs = require("dayjs");
|
||||
const PROCESS_PAY_METHOD = ['预付', '货到验收后付款', '提货付全款', '信誉采购,货到签单后账期:']
|
||||
const WRITE_INVOICE_TIME = ['付款当月(限20号之前付款,20号之后付款次月开票)', '付款后次月', '付款前']
|
||||
const INVOICE_TYPE = ['增值税专用发票13%', '增值税普通发票', '普通发票']
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 删除合同
|
||||
* @url client/contract/kh/del 前端调用的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 contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-contract',
|
||||
whereJson: {
|
||||
_id: data.id
|
||||
},
|
||||
})
|
||||
|
||||
if (contract && contract.type === 'sign') {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: contract.payerUid,
|
||||
dataJson: {
|
||||
qybNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
// await vk.baseDao.add({
|
||||
// dbName: "jjx-sign-pay_list",
|
||||
// dataJson: {
|
||||
// userId: contract.userId,
|
||||
// contractId,
|
||||
// payBy: data.payBy
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-contract',
|
||||
whereJson: {
|
||||
_id: data.id,
|
||||
uid
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-user-contract',
|
||||
whereJson: {
|
||||
contractId: data.id
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config.js")
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* 签署合同
|
||||
* @url client/enquiry/quote/kh/extSign 前端调用的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, contractId } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
// 获取用户ID
|
||||
const {fadadaCustomerId, fadadaSealId} = userInfo
|
||||
|
||||
// if(!fadadaSealId) {
|
||||
// return {
|
||||
// code: -1,
|
||||
// msg: '请在个人中心上传印章'
|
||||
// }
|
||||
// }
|
||||
|
||||
const contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
}
|
||||
})
|
||||
|
||||
// 时间判断
|
||||
if (contract.signEndDate && dayjs(contract.signEndDate).isBefore(dayjs())) {
|
||||
return {
|
||||
code: -1,
|
||||
msg: '合同已过期'
|
||||
}
|
||||
}
|
||||
|
||||
// 获取合同信息
|
||||
const userContract = await vk.baseDao.selects({
|
||||
dbName: dbName.userContract,
|
||||
getMain: true,
|
||||
getOne: true,
|
||||
whereJson: {
|
||||
contractId: contractId,
|
||||
userId: uid
|
||||
},
|
||||
foreignDB:[
|
||||
{
|
||||
dbName: dbName.contract,
|
||||
localKey:"contractId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "contract",
|
||||
limit: 1, // 当limit = 1时,以对象形式返回,否则以数组形式返回
|
||||
}
|
||||
],
|
||||
})
|
||||
console.log('userContract: ',userContract);
|
||||
|
||||
let sign_keyword = '';
|
||||
if(userContract.role === 'buyer') {
|
||||
sign_keyword = userContract.contract.buyerSignKeyword
|
||||
}else if(userContract.role === 'seller') {
|
||||
sign_keyword = userContract.contract.sellerSignKeyword
|
||||
}else if(userContract.role === 'third') {
|
||||
sign_keyword = userContract.keyword
|
||||
}
|
||||
let return_url = 'https://www.jinjiuxinzg.cn/#/pages/contract/index?tab=1'
|
||||
if (!data.isSignOnly) {
|
||||
if (!!data.isWap) return_url = 'https://m.jinjiuxinzg.cn/#/pages/public/contract?tab=1'
|
||||
}else {
|
||||
if (!!data.isWap) return_url = 'https://m.jinjiuxinzg.cn/signOnly/#/pages/public/contract?tab=1'
|
||||
else return_url = 'https://www.jinjiuxinzg.cn/signOnly/#/pages/contract/index?tab=1'
|
||||
}
|
||||
res.data = await pubFun.fadadaUrl('extsign.api', {
|
||||
transaction_id: userContract.transactionId,
|
||||
contract_id: contract.transactionId,
|
||||
customer_id: fadadaCustomerId,
|
||||
acrosspage_customer_id: fadadaCustomerId,
|
||||
doc_title: userContract.contract.docTitle,
|
||||
sign_keyword,
|
||||
// notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_contract_notify',
|
||||
// return_url: 'https://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/contract/index?tab=1'
|
||||
notify_url: 'https://tcb-n44byxi8bmrfrki-d4bn1c4a206d.service.tcloudbase.com/fadada_contract_notify',
|
||||
// return_url: 'https://tcb-nnexmh3j3i5hwh5-7caw62c422be-1252168680.tcloudbaseapp.com/#/pages/contract/index?tab=1'
|
||||
return_url
|
||||
})
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 发起/创建合同
|
||||
* @url client/contract/kh/launch 前端调用的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, contractId,title,contractFile,otherFile,signEndDate,buyerSignKeyword, sellerSignKeyword } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
}
|
||||
})
|
||||
console.log('contract: ',dbName.contract,uid);
|
||||
// 上传合同模板并填充
|
||||
pubFun.fadada('generate_contract.api', {
|
||||
template_id: '20231120',
|
||||
contract_id: contract.fadadaContractId,
|
||||
parameter_map: JSON.stringify({
|
||||
jiaName: userInfo.accountType == 1?userInfo.person.personName: userInfo.company.companyName,
|
||||
jiaDate: '',
|
||||
jiaPhone: '',
|
||||
yiName: userInfo.accountType == 1?userInfo.person.personName: userInfo.company.companyName,
|
||||
yiDate: '',
|
||||
yiPhone: '',
|
||||
sellerSupplement: contract.sellerSupplement,
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contract.fadadaContractId,
|
||||
doc_title: title,
|
||||
doc_url: contractFile,
|
||||
// file: doc_url,
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
|
||||
if(uploaddocs.code == 1000) {
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: title,
|
||||
signEndDate,
|
||||
otherFile,
|
||||
contractBase: contractFile,
|
||||
buyerSignKeyword,
|
||||
sellerSignKeyword
|
||||
}
|
||||
})
|
||||
|
||||
res.data = uploaddocs.result
|
||||
}else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: uploaddocs.msg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../dao/config");
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/contract/kh/getDetail 前端调用的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, contractId } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res.data = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
}
|
||||
})
|
||||
|
||||
const partyList = await vk.baseDao.selects({
|
||||
dbName: dbName.userContract,
|
||||
whereJson: {
|
||||
contractId
|
||||
},
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "userId",
|
||||
foreignKey: "_id",
|
||||
as: "user",
|
||||
limit: 1, // limit=1则以对象形式返回
|
||||
fieldJson: {
|
||||
_id: true,
|
||||
mobile: true,
|
||||
},
|
||||
}
|
||||
]
|
||||
});
|
||||
res.data.partyList = partyList.rows
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 获取我的合同列表
|
||||
* @url client/enquiry/contract/kh/getList 前端调用的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, pageIndex, pageSize, tradeMethod, status, type, signType} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const lastWhereJson = {}
|
||||
const whereJson = {
|
||||
userId: uid
|
||||
}
|
||||
if (vk.pubfn.isNotNull(tradeMethod) && tradeMethod != null) lastWhereJson['contract.tradeMethod'] = tradeMethod
|
||||
|
||||
if (vk.pubfn.isNotNull(status) && status != null) lastWhereJson['contract.status'] = status
|
||||
if (vk.pubfn.isNotNull(type) && type != null) lastWhereJson['contract.type'] = type
|
||||
if (vk.pubfn.isNotNull(signType) && signType != null && status !== 1) {
|
||||
if (signType === '1') lastWhereJson['contract.signType'] = signType
|
||||
else {
|
||||
lastWhereJson['contract.signType'] = _.in(['2', undefined])
|
||||
}
|
||||
}
|
||||
|
||||
res = await vk.daoCenter.userContractDao.selects({
|
||||
// data: {
|
||||
// pageIndex,
|
||||
// pageSize
|
||||
// },
|
||||
whereJson: whereJson,
|
||||
sortArr: [{"name": "_add_time", "type": "desc"}],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.contract,
|
||||
localKey: "contractId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "contract",
|
||||
limit: 1, // 当limit = 1时,以对象形式返回,否则以数组形式返回
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.userContract,
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "contractId", // 副表外键字段名
|
||||
as: "partyList",
|
||||
limit: 100,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.user,
|
||||
localKey: "userId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "user",
|
||||
limit: 1,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: 'uni-id-users',
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "userId", // 副表外键字段名
|
||||
company: {
|
||||
companyName: true
|
||||
},
|
||||
person: {
|
||||
personName: true
|
||||
},
|
||||
businessCard: true,
|
||||
accountType: true,
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
dbName: 'jjx-sign-pay_list',
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "contractId", // 副表外键字段名
|
||||
as: "payUser",
|
||||
limit: 1,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: dbName.user,
|
||||
localKey: "userId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "user",
|
||||
limit: 1
|
||||
},
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
dbName: 'jjx-certificate',
|
||||
localKey: "_id", // 主表外键字段名
|
||||
foreignKey: "contractId", // 副表外键字段名
|
||||
as: "certificate",
|
||||
limit: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
lastWhereJson: lastWhereJson
|
||||
})
|
||||
|
||||
let result = {
|
||||
rows: [],
|
||||
total: 0,
|
||||
hasMore: false,
|
||||
code: 0,
|
||||
msg: "查询成功",
|
||||
}
|
||||
console.log("rows", res.rows)
|
||||
if (vk.pubfn.isNotNull(data.keyword) && data.keyword != null && data.keyword) {
|
||||
const userList = await vk.baseDao.select({
|
||||
dbName: "uni-id-users",
|
||||
getCount: true,
|
||||
whereJson: _.or([
|
||||
{
|
||||
mobile: data.keyword
|
||||
},
|
||||
{
|
||||
'person.personName': data.keyword
|
||||
},
|
||||
{
|
||||
'company.companyName': data.keyword
|
||||
}
|
||||
])
|
||||
});
|
||||
console.log("userList", userList)
|
||||
if (userList.total > 0) {
|
||||
for (let i in res.rows) {
|
||||
const row = res.rows[i]
|
||||
for (let j in row.contract.partyList) {
|
||||
const party = row.contract.partyList[j]
|
||||
for (let k in userList.rows) {
|
||||
const user = userList.rows[k]
|
||||
if (party.user._id === user._id) {
|
||||
result.rows.push(row)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.total = result.rows.length
|
||||
} else {
|
||||
result = res
|
||||
}
|
||||
|
||||
for (let i in result.rows) {
|
||||
const row = result.rows[i]
|
||||
let sheet = null, order = null
|
||||
if (row.contract) {
|
||||
row.contract.isMine = row.contract.userId === uid
|
||||
if (row.contract.type === 'enquiry' && row.contract.sheetId) {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-enquiry-sheet',
|
||||
id: row.contract.sheetId
|
||||
})
|
||||
} else if (row.contract.type === 'process' && row.contract.sheetId) {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-process-sheet',
|
||||
id: row.contract.sheetId
|
||||
})
|
||||
} else if (row.contract.type === 'old' && row.contract.sheetId) {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-old',
|
||||
id: row.contract.sheetId
|
||||
})
|
||||
}
|
||||
order = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-order',
|
||||
whereJson: {
|
||||
contractId: row.contract._id
|
||||
}
|
||||
})
|
||||
if (row.contract.certificate) {
|
||||
const orderGoods = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-goods",
|
||||
whereJson: {
|
||||
goodsId: row.contract._id
|
||||
}
|
||||
})
|
||||
if (orderGoods) {
|
||||
row.contract.certificate.orderId = orderGoods.orderId
|
||||
}
|
||||
}
|
||||
}
|
||||
result.rows[i].sheet = sheet
|
||||
result.rows[i].order = order
|
||||
}
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 发起/创建合同
|
||||
* @url client/contract/kh/launch 前端调用的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, contractId, title, contractFile, otherFile, signEndDate, buyerSignKeyword, sellerSignKeyword} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const otherUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-user-contract',
|
||||
whereJson: {
|
||||
contractId: contractId,
|
||||
userId: _.neq(uid)
|
||||
}
|
||||
})
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
if (data.thirdList[i].phone) {
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
if (!thirdUser) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}不存在`
|
||||
}
|
||||
if (!thirdUser.fadadaConfirm) return {
|
||||
code: -1,
|
||||
msg: `该用户:${data.thirdList[i].phone}未通过法大大认证,无法签约`
|
||||
}
|
||||
if (thirdUser.uid === uid) return {
|
||||
code: -1,
|
||||
msg: '第三方不能为自己'
|
||||
}
|
||||
if (thirdUser.uid === otherUser._id) return {
|
||||
code: -1,
|
||||
msg: '第三方不能与对方为相同账号'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
}
|
||||
})
|
||||
console.log('contract: ', contract);
|
||||
let newTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
let doc_url = contractFile
|
||||
if (Array.isArray(doc_url)) doc_url = doc_url[doc_url.length - 1]
|
||||
const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: newTransactionId,
|
||||
doc_title: title,
|
||||
doc_url,
|
||||
// file: doc_url,
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
let otherFileResList = []
|
||||
// 存在附件则合并
|
||||
if (otherFile && otherFile.length > 0) {
|
||||
for (let i = 0; i < otherFile.length; i++) {
|
||||
otherFileResList.push(newTransactionId + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: newTransactionId + i.toString(),
|
||||
doc_title: title + `:附件${i + 1}`,
|
||||
doc_url: otherFile[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
otherFileResList.unshift(newTransactionId)
|
||||
|
||||
// 合并接口
|
||||
newTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
contract_id: newTransactionId,
|
||||
doc_title: title,
|
||||
contract_ids: otherFileResList.join()
|
||||
})
|
||||
console.log('mergeRes', mergeRes)
|
||||
console.log('otherFileResList', otherFileResList)
|
||||
}
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
dataJson: {
|
||||
transactionId: newTransactionId,
|
||||
}
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
let partyCount = 2
|
||||
if (data.thirdList && data.thirdList.length > 0) partyCount += data.thirdList.filter(item => !!item.phone).length
|
||||
const contract = await vk.baseDao.updateAndReturn({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: title,
|
||||
signEndDate,
|
||||
otherFile,
|
||||
partyCount,
|
||||
contractBase: contractFile,
|
||||
buyerSignKeyword,
|
||||
sellerSignKeyword
|
||||
}
|
||||
})
|
||||
if (contract.type === 'enquiry') {
|
||||
await vk.baseDao.update({
|
||||
dbName: 'jjx-enquiry-sheet',
|
||||
whereJson: {
|
||||
_id: contract.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
status: 2,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// const otherUser = await vk.baseDao.findByWhereJson({
|
||||
// dbName: 'jjx-user-contract',
|
||||
// whereJson: {
|
||||
// contractId: contractId,
|
||||
// userId: _.neq(uid)
|
||||
// }
|
||||
// })
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: otherUser.userId,
|
||||
title: `您有新的合同待签署`,
|
||||
content: `您有新的合同待签署,赶紧去签合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
}
|
||||
});
|
||||
// await pubFun.sendNotifySms(otherUser.userId, 'SMS_474525001')
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-user-contract',
|
||||
whereJson: {
|
||||
contractId,
|
||||
role: 'third',
|
||||
}
|
||||
})
|
||||
await vk.baseDao.del({
|
||||
dbName: 'jjx-message',
|
||||
whereJson: {
|
||||
contractId,
|
||||
type: 'contract',
|
||||
isThird: true
|
||||
}
|
||||
})
|
||||
if (data.thirdList && data.thirdList.length > 0) {
|
||||
console.log('data.thirdList', data.thirdList)
|
||||
for (let i = 0; i < data.thirdList.length; i++) {
|
||||
if (data.thirdList[i].phone) {
|
||||
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile: data.thirdList[i].phone
|
||||
}
|
||||
})
|
||||
if (thirdUser) {
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("ST", 20),
|
||||
userId: thirdUser.uid,
|
||||
role: 'third',
|
||||
sign: false,
|
||||
contractId,
|
||||
keyword: data.thirdList[i].signKeyword,
|
||||
},
|
||||
])
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: thirdUser.uid,
|
||||
title: `合同`,
|
||||
content: `您有合同待签署,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
contractId,
|
||||
isThird: true
|
||||
}
|
||||
});
|
||||
}
|
||||
// await pubFun.sendNotifySms(thirdUser._id, 'SMS_474525001')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.data = uploaddocs.result
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: uploaddocs.msg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/contract/kh/report 前端调用的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 {contractNum, evidenceType} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const url = 'https://tczapi.fadada.com/czapi/api/compliance-contract-report'
|
||||
// const url = 'https://czapi-test.fadada.com/evidence-api/api/compliance-contract-report'
|
||||
const result = await pubFun.fadada(url, {
|
||||
contractNum,
|
||||
evidenceType
|
||||
}, true)
|
||||
if (parseInt(result.code) === 1000) {
|
||||
res.data = result.data
|
||||
}
|
||||
return res
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/contract/kh/stopContract 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-contract",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
// status:
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* 查看合同
|
||||
* @url client/contract/kh/view 前端调用的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, contractId } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const contract = await vk.daoCenter.contractDao.selects({
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
getOne: true,
|
||||
getMain: true
|
||||
})
|
||||
|
||||
const viewRes = pubFun.fadadaUrl('viewContract.api', {
|
||||
contract_id: contract.transactionId
|
||||
})
|
||||
|
||||
res.data = viewRes
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/coop/config/pub/getList 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.select({
|
||||
dbName: 'jjx-coop-config',
|
||||
whereJson: {
|
||||
type: data.type,
|
||||
},
|
||||
sortArr: [
|
||||
{name: "sort", type: "asc"},
|
||||
{name: "_id", type: "desc"},
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/dict/pub/getDetail 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.findById({
|
||||
dbName: "jjx-dict",
|
||||
id: data.id
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
const dbName = 'jjx-enquiry-attributes'
|
||||
module.exports = {
|
||||
/**
|
||||
* 查询现货列表
|
||||
* @url client/spot/goods/kh/getList 前端调用的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 {pageIndex,pageSize,label } = data
|
||||
|
||||
let whereJson = {
|
||||
enable: true,
|
||||
label
|
||||
};
|
||||
|
||||
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName,
|
||||
getCount:false,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
// 主表where条件
|
||||
whereJson: whereJson,
|
||||
// 主表字段显示规则
|
||||
fieldJson:{},
|
||||
// 主表排序规则
|
||||
sortArr:[{ name:"sort", type:"asc" }],
|
||||
|
||||
});
|
||||
|
||||
res.rows.forEach(item => {
|
||||
item.options = item.values.map(citem => {
|
||||
return {
|
||||
label: citem,
|
||||
value: citem
|
||||
}
|
||||
})
|
||||
delete item.values
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
const dbName = 'jjx-enquiry-attributes'
|
||||
module.exports = {
|
||||
/**
|
||||
* 查询现货列表
|
||||
* @url client/spot/goods/kh/getList 前端调用的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: "",list: [] };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const {pageIndex,pageSize,label } = data
|
||||
|
||||
let whereJson = {
|
||||
enable: true,
|
||||
label
|
||||
};
|
||||
|
||||
|
||||
|
||||
const info = await vk.baseDao.findByWhereJson({
|
||||
dbName,
|
||||
getCount:false,
|
||||
whereJson: whereJson,
|
||||
});
|
||||
|
||||
if(info != null) {
|
||||
res.list = info.values.map(item => {
|
||||
return {
|
||||
label: item,
|
||||
value: item
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 查询商品分类列表
|
||||
* @url client/product/category/pub/getAll 前端调用的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, whereJson } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
let dbName = "jjx-enquiry-category";
|
||||
res.data = await vk.baseDao.selects({
|
||||
dbName,
|
||||
getMain: true,
|
||||
whereJson,
|
||||
pageSize: -1
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 查询商品分类列表
|
||||
* @url client/product/category/pub/getAll 前端调用的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 dbName = "jjx-enquiry-category";
|
||||
res = await vk.baseDao.selects({
|
||||
dbName,
|
||||
pageIndex: 1,
|
||||
pageSize: 500,
|
||||
whereJson: {
|
||||
parent_id: _.in([null, ""]),
|
||||
_id: _.exists(true)
|
||||
},
|
||||
sortArr: [{name: "sort", type: "asc"}],
|
||||
// 树状结构参数
|
||||
treeProps: {
|
||||
id: "_id", // 唯一标识字段,默认为 _id
|
||||
parent_id: "parent_id", // 父级标识字段,默认为 parent_id
|
||||
children: "children", // 自定义返回的下级字段名,默认为 children
|
||||
level: 3, // 查询返回的树的最大层级。超过设定层级的节点不会返回。默认10级,最大15,最小1
|
||||
limit: 500, // 每一级最大返回的数据。
|
||||
whereJson: {}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 获取我的合同列表
|
||||
* @url client/enquiry/contract/kh/getList 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.getTableData({
|
||||
dbName: 'jjx-contract',
|
||||
data
|
||||
})
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
var isBetween = require('dayjs/plugin/isBetween')
|
||||
dayjs.extend(isBetween)
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增报价
|
||||
* @url client/enquiry/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, totalPrice} = data;
|
||||
let {company, manager, person, accountType} = userInfo
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
let noQuoteNo = false
|
||||
if (parseInt(userInfo.userLevel) < 3) {
|
||||
if (parseInt(userInfo.remainQuoteNum) === 0 || !userInfo.remainQuoteNum) {
|
||||
const checkSheetQuoteNum = await vk.baseDao.findById({
|
||||
dbName: "jjx-enquiry-sheet",
|
||||
id: data.sheetId
|
||||
})
|
||||
if (checkSheetQuoteNum.quoteAmount) {
|
||||
const checkQuoteNum = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-user-quote-num",
|
||||
whereJson: {
|
||||
uid,
|
||||
type: 'enquiry',
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let subjectName = ''
|
||||
let subjectMobile = ''
|
||||
let managerName = ''
|
||||
let managerMobile = ''
|
||||
|
||||
const checkSheet = await vk.baseDao.findById({
|
||||
dbName: "jjx-enquiry-sheet",
|
||||
id: data.sheetId
|
||||
})
|
||||
|
||||
if (checkSheet.status > 0) return {
|
||||
code: -1,
|
||||
msg: "此询价单采购商已确认合作方,请您及时查看平台信息发布,及时报价,以免错过商机。"
|
||||
}
|
||||
|
||||
if (checkSheet.earnestMoney && checkSheet.earnestMoney > 0 && checkSheet.earnestMoney > userInfo.paidEnsure) {
|
||||
return {
|
||||
code: 12,
|
||||
msg: "您的保证金不足,请先缴纳保证金"
|
||||
}
|
||||
}
|
||||
|
||||
if (accountType === 1 && person.personName && person.mobile) {
|
||||
subjectName = person.personName
|
||||
subjectMobile = person.mobile
|
||||
} else {
|
||||
subjectName = company.companyName
|
||||
subjectMobile = company.mobile
|
||||
if (manager && manager.mobile && manager.personName) {
|
||||
managerName = manager.personName
|
||||
managerMobile = manager.mobile
|
||||
}
|
||||
}
|
||||
|
||||
// 添加报价单
|
||||
res.data = await vk.baseDao.add({
|
||||
dbName: "jjx-enquiry-quote",// 表名
|
||||
dataJson: { // 需要新增的数据 json格式
|
||||
...data,
|
||||
...{
|
||||
userId: data.uid,
|
||||
status: 0,
|
||||
subjectName,
|
||||
subjectMobile,
|
||||
managerName,
|
||||
managerMobile,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-enquiry-sheet",// 表名
|
||||
whereJson: {
|
||||
_id: data.sheetId,
|
||||
},
|
||||
dataJson: {
|
||||
quoteNum: _.inc(1)
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",// 表名
|
||||
id: data.uid,
|
||||
dataJson: {
|
||||
quoteTimes: _.inc(1)
|
||||
}
|
||||
})
|
||||
|
||||
const checkMessage = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
enquiry: true,
|
||||
uid: sheet.userId
|
||||
}
|
||||
})
|
||||
|
||||
if (checkMessage) {
|
||||
let send = true
|
||||
// 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}`)))
|
||||
// send = false
|
||||
// }
|
||||
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}`)))
|
||||
send = false
|
||||
}
|
||||
|
||||
if (checkMessage.tradeAmount && checkMessage.tradeAmount[0]) {
|
||||
if (sheet.totalPrice < checkMessage.tradeAmount[0] || sheet.totalPrice > checkMessage.tradeAmount[1])
|
||||
send = false
|
||||
}
|
||||
if (send) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: sheet.userId,
|
||||
title: `找供应:${sheet.title}报价`,
|
||||
content: `您的找供应信息有新的报价,赶紧去看看吧`,
|
||||
type: 'enquiry',
|
||||
hasRead: false,
|
||||
pk: data.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(sheet.userId, 'SMS_493290524')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
'use strict';
|
||||
|
||||
const dbName = require('../../../../../dao/config.js')
|
||||
const dayjs = require("dayjs");
|
||||
var isBetween = require('dayjs/plugin/isBetween')
|
||||
dayjs.extend(isBetween)
|
||||
|
||||
const PROCESS_PAY_METHOD = ['预付', '货到验收后付款', '提货付全款', '信誉采购,货到签单后账期:']
|
||||
const WRITE_INVOICE_TIME = ['付款当月(限20号之前付款,20号之后付款次月开票)', '付款后次月', '付款前']
|
||||
const INVOICE_TYPE = ['增值税专用发票13%', '增值税普通发票', '普通发票']
|
||||
|
||||
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 {
|
||||
pubFun,
|
||||
vk,
|
||||
} = 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.updateAndReturn({
|
||||
dbName: dbName.enquirySheet,
|
||||
whereJson: {_id: quote.sheetId},
|
||||
dataJson: {
|
||||
otherUid: quote.userId,
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
const checkMessage = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
enquiry: true,
|
||||
uid: quote.userId
|
||||
}
|
||||
})
|
||||
|
||||
if (checkMessage) {
|
||||
let send = true
|
||||
// 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}`)))
|
||||
// send = false
|
||||
// }
|
||||
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}`)))
|
||||
send = false
|
||||
}
|
||||
|
||||
if (send) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: quote.userId,
|
||||
title: `找买家:${sheet.title}被选商`,
|
||||
content: `您报价的找买家信息已被选商,赶紧去签合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
pk: data.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(quote.userId, 'SMS_474250536')
|
||||
}
|
||||
}
|
||||
|
||||
// 获取商品信息
|
||||
const otherCate = sheet.otherCate ? String(sheet.otherCate).trim() : ''
|
||||
const sheetProductList = otherCate ? [{
|
||||
goodsName: otherCate,
|
||||
procureNumber: sheet.procureNumber,
|
||||
procureUnit: sheet.procureUnit,
|
||||
}] : (Array.isArray(sheet.productList) ? sheet.productList : [])
|
||||
const productTitle = sheetProductList.map(item => item.goodsName).filter(Boolean).join("/") || sheet.title
|
||||
|
||||
if (sheet.signMethod !== 1) {
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("E", 20)
|
||||
// 上传合同模板并填充
|
||||
|
||||
// 新增合同记录
|
||||
let contractTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
fadadaContractId,
|
||||
contractBase: '', // 原始合同
|
||||
contractHistory: [], // 历史合同
|
||||
contractFinal: '', // 归档合同
|
||||
status: 0,
|
||||
userId: uid,
|
||||
type: 'enquiry',
|
||||
quoteId: quoteId,
|
||||
sheetId: quote.sheetId,
|
||||
productList: sheetProductList,
|
||||
productTitle,
|
||||
tradeMethod: sheet.tradeMethod,
|
||||
partyCount: 2,
|
||||
signCount: 0,
|
||||
contractType: sheet.contractType,
|
||||
signMethod: sheet.signMethod,
|
||||
sellerSupplement: sheet.sellerSupplement,
|
||||
transactionId: contractTransactionId,
|
||||
amount: quote.totalPrice,
|
||||
docTitle: productTitle
|
||||
}
|
||||
})
|
||||
|
||||
// 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: quote.userId,
|
||||
role: 'seller',
|
||||
sign: false,
|
||||
contractId
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: uid,
|
||||
role: 'buyer',
|
||||
sign: false,
|
||||
contractId
|
||||
}
|
||||
])
|
||||
|
||||
if (sheet.signMethod === 0) {
|
||||
const templateId = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '80e3bed065a5560e075799d24532b14f'
|
||||
})
|
||||
const buyerKeyword = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '0b153f9a65a56a2007227cf5157133bf'
|
||||
})
|
||||
const sellerKeyword = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '09e7876865a56a320731cb244bbef818'
|
||||
})
|
||||
const signMaxDate = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '657d78958b0da41d311bd94c'
|
||||
})
|
||||
const signEndDate = vk.pubfn.getOffsetTime(new Date(), {
|
||||
day: parseInt(signMaxDate.content),
|
||||
mode: "after",
|
||||
});
|
||||
// const fieldList = await vk.baseDao.select({
|
||||
// dbName: 'jjx-contract-template',
|
||||
// whereJson: {
|
||||
// isOn: true
|
||||
// }
|
||||
// })
|
||||
const sellerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: quote.userId
|
||||
})
|
||||
const buyerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: uid
|
||||
})
|
||||
|
||||
const sellerUserBank = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-account',
|
||||
whereJson: {
|
||||
uid: quote.userId,
|
||||
isDefault: true
|
||||
}
|
||||
})
|
||||
const buyerUserBank = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-account',
|
||||
whereJson: {
|
||||
uid: uid,
|
||||
isDefault: true
|
||||
}
|
||||
})
|
||||
|
||||
let tradeInfo = PROCESS_PAY_METHOD[sheet.payMethod]
|
||||
if (sheet.payMethod === 0 && sheet.advancePayRate) tradeInfo += `${sheet.advancePayRate}%货到付全款`
|
||||
if (sheet.payMethod === 3 && sheet.reputationPayDay) tradeInfo += `${sheet.reputationPayDay}天`
|
||||
tradeInfo += `,发票要求:${sheet.invoice ? '含税' : '不含税'},开票时间:` + WRITE_INVOICE_TIME[sheet.writeInvoiceTime]
|
||||
if (sheet.invoiceOther) tradeInfo += `,其他要求:${sheet.invoiceOther ? sheet.invoiceOther : '无'}`
|
||||
else {
|
||||
if (sheet.invoice)
|
||||
tradeInfo += `,纳税人身份:${sheet.taxType},发票种类:${sheet.invoiceType},税率:${sheet.taxRate}`
|
||||
}
|
||||
let expressRequire = ''
|
||||
expressRequire += `随货资料:${sheet.transportDocuments.join()},其他要求:${sheet.otherTransportDocuments ? sheet.otherTransportDocuments : '无'}${sheet.transportLimit ? '' : ',运输限制要求:无'}`
|
||||
if (sheet.transportLimit && sheet.otherTransportRequest) expressRequire += `,运输限制说明:${sheet.otherTransportRequest}`
|
||||
let detail = ''
|
||||
if (sheet.fillType === 0) {
|
||||
sheet.productList.forEach((item, index) => {
|
||||
detail += `${item.goodsName}(${item.procureNumber}${item.procureUnit})`
|
||||
if (item.deliverService) detail += ` ,${item.deliverService}`
|
||||
if (item.pricingForm) detail += ` ,${item.pricingForm}`
|
||||
if (item.loadPaidBy) detail += ` ,${item.loadPaidBy}`
|
||||
item.model.forEach((model) => {
|
||||
detail += `,${model.label}:${model.value}`
|
||||
})
|
||||
if (index < sheet.productList.length - 1) detail += '\r\n'
|
||||
})
|
||||
} else {
|
||||
detail = productTitle
|
||||
}
|
||||
let info = sheet.remark ? `其他要求:${sheet.remark}` : ''
|
||||
if (quote.remark) {
|
||||
if (info) info += `,${quote.remark}`
|
||||
else info = quote.remark
|
||||
}
|
||||
if (info === '') info = '无'
|
||||
|
||||
const accountType = sheet.invoice ? 'company' : 'person'
|
||||
const buyerBank = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-account",
|
||||
whereJson: {
|
||||
uid: buyerUser._id,
|
||||
type: accountType
|
||||
}
|
||||
})
|
||||
let buyerBankName = buyerUser.accountType === 2 ? buyerUser.company.companyBankName : buyerUser.person.personBankName
|
||||
let buyerAccount = buyerUser.accountType === 2 ? buyerUser.company.companyAccount : buyerUser.person.personAccount
|
||||
let buyerBankAccountName = buyerUser.accountType === 2 ? buyerUser.company.companyAccount : buyerUser.person.personAccount
|
||||
let sellerBankName = sellerUser.accountType === 2 ? sellerUser.company.companyBankName : sellerUser.person.personBankName
|
||||
let sellerAccount = sellerUser.accountType === 2 ? sellerUser.company.companyAccount : sellerUser.person.personAccount
|
||||
let sellerBankAccountName = sellerUser.accountType === 2 ? sellerUser.company.companyAccount : sellerUser.person.personAccount
|
||||
if (buyerBank) {
|
||||
buyerBankName = buyerBank.bankName
|
||||
buyerAccount = buyerBank.account
|
||||
buyerBankAccountName = buyerBank.accountName
|
||||
}
|
||||
const sellerBank = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-account",
|
||||
whereJson: {
|
||||
uid: sellerUser._id,
|
||||
type: accountType
|
||||
}
|
||||
})
|
||||
if (sellerBank) {
|
||||
sellerBankName = sellerBank.bankName
|
||||
sellerAccount = sellerBank.account
|
||||
sellerBankAccountName = sellerBank.accountName
|
||||
}
|
||||
|
||||
const parameter = {
|
||||
seller: sellerUser.accountType === 2 ? sellerUser.company.companyName : sellerUser.person.personName,
|
||||
buyer: buyerUser.accountType === 2 ? buyerUser.company.companyName : buyerUser.person.personName,
|
||||
date: dayjs().format('YYYY年MM月DD日'),
|
||||
sellerSignDate: dayjs(signEndDate).format('YYYY年MM月DD日 HH时mm分'),
|
||||
buyerSignDate: dayjs(signEndDate).format('YYYY年MM月DD日 HH时mm分'),
|
||||
// time: dayjs().format('HH:mm'),
|
||||
contractNo: fadadaContractId,
|
||||
region: sheet.addressRegion.province.name + sheet.addressRegion.city.name + sheet.addressRegion.area.name,
|
||||
detail,
|
||||
info,
|
||||
// content: '无',
|
||||
tradeInfo,
|
||||
expressRequire,
|
||||
defaultDuty: '1.乙方所交产品品种、型号、规格、质量不符合规定的,如果甲方同意利用,应当按质论价;如果甲方不能利用的,应根据产品的具体情况,由乙方负责包换或包修,并承担修理、调换或退货而支付的实际费用;2.乙方不予供货违约责任为甲方的实际损失+违约金,如乙方材料符合订货标准,甲方不能退货和不收货,甲方无条件应按实际本合同订货数量支付100%货款,并支付乙方因此产生的实际费用。带有甲乙双方单位相关收货人和发货人签字的本合同的发货清单事项和内容均视为本合同的补充合同,与本合同有相同的法律效力,双方应共同遵照执行。',
|
||||
solve: '1、凡因本合同引起的或与本合同有关的任何争议,均可友好协商或仲裁解决,协商或仲裁不成的,双方协商同意在合同签订地人民法院管辖地起诉,违约一方或对合同争议承担主要责任的一方,应承担对方因仲裁和起诉而产生的全部律师代理费、鉴定(检验)费、诉讼保全费、诉讼保险费、公告费、差旅费、执行费、误工費和获取证据产生费用等其他相关费用。2、双方本合同相关权利放弃均应有双方书面作出并加盖公章或授权委托人签字后生效。',
|
||||
forceMajeure: '甲乙双方的任何一方由于不可抗力或突发公共事件的原因不能履行合同时,应及时向对方通报不能履行或不能完全履行的理由,以减轻可能给对方造成的损失,在取得有关机构证明以后,允许延期履行、部分履行或者不履行合同,并根据情况可部分或全部免予承担违约责任。',
|
||||
other: '本合同的全部内容由双方平等共同协商一致,共同起草制定,非一方事先拟定,不属于格式条款。本合同自双方签字盖章后生效(包括电子签字、盖章),按本合同内容地址、联系方式寄送的一切文书、函件送达与否,均为视为送达有法律效力,通知途径和本合同内联系方式或地址送达文件双方均予以验证。',
|
||||
buyerSupplement: sheet.supplementary ? sheet.supplementary : '无',
|
||||
sellerSupplement: quote.supplierExt ? quote.supplierExt : '无',
|
||||
buyerAddress: buyerUser.accountType === 2 ? buyerUser.company.mailAddress : buyerUser.person.address,
|
||||
sellerAddress: sellerUser.accountType === 2 ? sellerUser.company.mailAddress : sellerUser.person.address,
|
||||
buyerLegal: buyerUser.accountType === 2 ? buyerUser.company.legalName : '',
|
||||
sellerLegal: sellerUser.accountType === 2 ? sellerUser.company.legalName : '',
|
||||
// buyerAgent: buyerUser.accountType === 2 ? buyerUser.manager.personName : '',
|
||||
buyerAgent: sheet.businessName,
|
||||
sellerAgent: sellerUser.accountType === 2 ? sellerUser.manager.personName : '',
|
||||
// buyerMobile: buyerUser.accountType === 2 ? buyerUser.manager.mobile : buyerUser.person.mobile,
|
||||
buyerMobile: sheet.businessMobile,
|
||||
sellerMobile: sellerUser.accountType === 2 ? sellerUser.manager.mobile : sellerUser.person.mobile,
|
||||
buyerBankName,
|
||||
sellerBankName,
|
||||
buyerAccount,
|
||||
sellerAccount,
|
||||
buyerBankAccountName,
|
||||
sellerBankAccountName,
|
||||
signName: sheet.signName ? sheet.signName : '',
|
||||
signIdCard: sheet.signIdCard ? sheet.signIdCard : '',
|
||||
}
|
||||
// for (let i = 0; i < fieldList.length; i++) {
|
||||
//
|
||||
// const field = fieldList[i]
|
||||
// parameter[field.field] = ''
|
||||
// }
|
||||
const uploaddocs = await pubFun.fadada('generate_contract.api', {
|
||||
template_id: templateId.content,
|
||||
contract_id: contractTransactionId,
|
||||
parameter_map: JSON.stringify(parameter)
|
||||
})
|
||||
let otherFileResList = []
|
||||
// 存在附件则合并
|
||||
// if (sheet.files && sheet.files.length > 0) {
|
||||
// for (let i = 0; i < sheet.files.length; i++) {
|
||||
// otherFileResList.push(contractTransactionId + i.toString())
|
||||
// await pubFun.fadada('uploaddocs.api', {
|
||||
// contract_id: contractTransactionId + i.toString(),
|
||||
// doc_title: sheet.title + `:附件${i + 1}`,
|
||||
// doc_url: sheet.files[i],
|
||||
// doc_type: '.pdf'
|
||||
// })
|
||||
// }
|
||||
// otherFileResList.unshift(contractTransactionId)
|
||||
//
|
||||
// // 合并接口
|
||||
// contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
// const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
// contract_id: contractTransactionId,
|
||||
// doc_title: sheet.title,
|
||||
// contract_ids: otherFileResList.join()
|
||||
// })
|
||||
// console.log('mergeRes', mergeRes)
|
||||
// console.log('otherFileResList', otherFileResList)
|
||||
// }
|
||||
// 存在附件则合并
|
||||
if (quote.files && quote.files.length > 0) {
|
||||
for (let i = 0; i < quote.files.length; i++) {
|
||||
otherFileResList.push(contractTransactionId + 'qf' + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contractTransactionId + 'qf' + i.toString(),
|
||||
doc_title: sheet.title + `:附件${i + 1}`,
|
||||
doc_url: quote.files[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
otherFileResList.unshift(contractTransactionId)
|
||||
|
||||
// 合并接口
|
||||
contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
contract_id: contractTransactionId,
|
||||
doc_title: sheet.title,
|
||||
contract_ids: otherFileResList.join()
|
||||
})
|
||||
console.log('quote mergeRes', mergeRes)
|
||||
console.log('quote otherFileResList', otherFileResList)
|
||||
}
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
dataJson: {
|
||||
transactionId: contractTransactionId,
|
||||
}
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: sheet.title,
|
||||
signEndDate,
|
||||
otherFile: '',
|
||||
contractBase: null,
|
||||
buyerSignKeyword: buyerKeyword.content,
|
||||
sellerSignKeyword: sellerKeyword.content
|
||||
}
|
||||
})
|
||||
// await vk.baseDao.updateAndReturn({
|
||||
// dbName: 'jjx-enquiry-sheet',
|
||||
// whereJson: {
|
||||
// _id: quote.sheetId
|
||||
// },
|
||||
// dataJson: {
|
||||
// status: 2
|
||||
// }
|
||||
// })
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: quote.userId,
|
||||
title: `询价:${sheet.title}待签合同`,
|
||||
content: `您报价的询价信息已创建合同,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
pk: quote.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(quote.userId, 'SMS_474455034')
|
||||
res.data = uploaddocs.result
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: uploaddocs.msg
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const orderId = await vk.baseDao.add({
|
||||
dbName: "jjx-order",
|
||||
dataJson: {
|
||||
orderNo: vk.pubfn.createOrderNo("39XU", 20),
|
||||
uid: uid,
|
||||
sellerUid: quote.userId,
|
||||
orderStatus: 0,
|
||||
payStatus: 0,
|
||||
type: 4,
|
||||
amount: quote.totalPrice,
|
||||
offAmount: quote.totalPrice,
|
||||
signMethod: 1,
|
||||
sheetId: quote.sheetId,
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-order-goods",
|
||||
dataJson: {
|
||||
orderId,
|
||||
goodsId: null,
|
||||
num: 1,
|
||||
goodsName: productTitle || '询价单',
|
||||
goodsPrice: quote.totalPrice,
|
||||
goodsCover: null,
|
||||
}
|
||||
})
|
||||
}
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 上传合同
|
||||
* @url client/enquiry/quote/kh/uploadTemplate 前端调用的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, base64 } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const file = pubFun.base64ToFile(base64, 'adv.pdf')
|
||||
|
||||
res.data = await pubFun.fadada('upload_template_docs.api', {
|
||||
contract_template_id: vk.pubfn.createOrderNo("Contract", 25),
|
||||
template_name: 'template_name',
|
||||
file: file
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
'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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
var isBetween = require('dayjs/plugin/isBetween')
|
||||
dayjs.extend(isBetween)
|
||||
|
||||
const DEFAULT_NOTARY_SERVICE_RATE = 0.1;
|
||||
|
||||
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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
// 生成询价编号
|
||||
|
||||
if (!userInfo.fadadaConfirm && userInfo.authStatus === 1) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: '请先完成认证'
|
||||
}
|
||||
} else if (!userInfo.businessCard) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: '请完善名片信息'
|
||||
}
|
||||
} else {
|
||||
if (userInfo.businessCard.status !== 1) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: '您的名片信息未审核,请耐心等待'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 这里需要把 params1 params2 params3 改成你数据库里允许用户添加的字段
|
||||
let dbName = "jjx-enquiry-sheet";
|
||||
const notaryServiceRate = data.tradeMethod === 1
|
||||
? ((data.notaryServiceRate === undefined || data.notaryServiceRate === null || data.notaryServiceRate === '') ? DEFAULT_NOTARY_SERVICE_RATE : data.notaryServiceRate)
|
||||
: null
|
||||
res.id = await vk.baseDao.add({
|
||||
dbName,
|
||||
dataJson: {
|
||||
...data,
|
||||
...{
|
||||
answerNumber: 0,
|
||||
userId: uid,
|
||||
status: 0,
|
||||
quoteNum: 0,
|
||||
isShow: 0,
|
||||
notaryServiceRate
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
'use strict';
|
||||
const dbName = require("../../../../../dao/config");
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/enquiry/sheet/kh/changeToOnlineSign 前端调用的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 sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-enquiry-sheet",
|
||||
whereJson: {
|
||||
_id: data.id
|
||||
},
|
||||
dataJson: {
|
||||
signMethod: 0,
|
||||
status: 1
|
||||
}
|
||||
});
|
||||
|
||||
const quote = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-enquiry-quote",
|
||||
whereJson: {
|
||||
sheetId: data.id,
|
||||
status: 1
|
||||
}
|
||||
});
|
||||
|
||||
if (quote) {
|
||||
|
||||
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("E", 20)
|
||||
const contractTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
fadadaContractId,
|
||||
contractBase: '', // 原始合同
|
||||
contractHistory: [], // 历史合同
|
||||
contractFinal: '', // 归档合同
|
||||
status: 0,
|
||||
userId: uid,
|
||||
type: 'enquiry',
|
||||
quoteId: quote.id,
|
||||
sheetId: quote.sheetId,
|
||||
productList: quote.productList,
|
||||
productTitle: sheet.title,
|
||||
tradeMethod: 0,
|
||||
partyCount: 2,
|
||||
signCount: 0,
|
||||
contractType: sheet.contractType,
|
||||
signMethod: sheet.signMethod,
|
||||
sellerSupplement: sheet.sellerSupplement,
|
||||
transactionId: contractTransactionId,
|
||||
amount: quote.totalPrice,
|
||||
docTitle: sheet.title
|
||||
}
|
||||
})
|
||||
|
||||
// 上传合同模板
|
||||
|
||||
//新增 用户与合同的关联记录
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: quote.userId,
|
||||
role: 'seller',
|
||||
sign: false,
|
||||
contractId
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: uid,
|
||||
role: 'buyer',
|
||||
sign: false,
|
||||
contractId
|
||||
}
|
||||
])
|
||||
}
|
||||
// const contractFile = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d36befe975f63af1f24e7'
|
||||
// })
|
||||
// const signMaxDate = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d78958b0da41d311bd94c'
|
||||
// })
|
||||
// const buyerSignKeyword = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d37972139294200fc9a01'
|
||||
// })
|
||||
// const sellerSignKeyword = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d37a609664c4f4a5c4afb'
|
||||
// })
|
||||
// const signEndDate = vk.pubfn.getOffsetTime(new Date(), {
|
||||
// day: parseInt(signMaxDate.content),
|
||||
// mode: "after",
|
||||
// });
|
||||
//
|
||||
// const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
// contract_id: contractTransactionId,
|
||||
// doc_title: sheet.title,
|
||||
// doc_url: contractFile.content,
|
||||
// // file: doc_url,
|
||||
// doc_type: '.pdf'
|
||||
// })
|
||||
// if (parseInt(uploaddocs.code) === 1000) {
|
||||
// await vk.baseDao.updateAndReturn({
|
||||
// dbName: dbName.contract,
|
||||
// whereJson: {
|
||||
// _id: contractId,
|
||||
// userId: uid
|
||||
// },
|
||||
// dataJson: {
|
||||
// status: 1,
|
||||
// docTitle: sheet.title,
|
||||
// signEndDate,
|
||||
// otherFile: '',
|
||||
// contractBase: contractFile.content,
|
||||
// buyerSignKeyword: buyerSignKeyword.content,
|
||||
// sellerSignKeyword: sellerSignKeyword.content
|
||||
// }
|
||||
// })
|
||||
// await vk.baseDao.updateAndReturn({
|
||||
// dbName: 'jjx-enquiry-sheet',
|
||||
// whereJson: {
|
||||
// _id: data.id
|
||||
// },
|
||||
// dataJson: {
|
||||
// status: 2
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// res.data = uploaddocs.result
|
||||
// } else {
|
||||
// return {
|
||||
// code: -1,
|
||||
// msg: uploaddocs.msg
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
const dbName = require('../../../../../dao/config.js')
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/enquiry/sheet/kh/delete 前端调用的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 { _id } = data;
|
||||
if(vk.pubfn.isNull(_id)){
|
||||
return { code : -1, msg : 'id不能为空' };
|
||||
}
|
||||
await vk.baseDao.deleteById({
|
||||
dbName: dbName.enquirySheet,
|
||||
id:_id
|
||||
});
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 获取用户发布的询价单
|
||||
* @url client/enquiry/sheet/pub/getList 前端调用的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, pageIndex, pageSize, keyword, categoryIds, provinceCodes, formData, status, isSeller} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
let dbName = "jjx-enquiry-sheet";
|
||||
|
||||
|
||||
let whereJson = {isShow: 1};
|
||||
|
||||
if (vk.pubfn.isNotNull(keyword)) whereJson.title = new RegExp(keyword)
|
||||
|
||||
if (vk.pubfn.isNotNull(isSeller) && isSeller) whereJson.otherUid = uid
|
||||
else whereJson.userId = uid
|
||||
|
||||
if (vk.pubfn.isNotNull(status) && status !== 'all') {
|
||||
if (status === 'noQuote') {
|
||||
whereJson.quoteNum = 0
|
||||
whereJson.status = 0
|
||||
}
|
||||
else if (status === 'notPick') {
|
||||
whereJson.quoteNum = _.gt(0)
|
||||
whereJson.status = 0
|
||||
}
|
||||
else if (status === 'picked') whereJson.status = _.in([1, 2])
|
||||
}
|
||||
|
||||
if (formData && formData.hasOwnProperty('companyList') && vk.pubfn.isNotNull(formData.companyList)) {
|
||||
whereJson.userId = _.in(formData.companyList)
|
||||
}
|
||||
|
||||
if (formData && formData.hasOwnProperty('categoryIds') && vk.pubfn.isNotNull(formData.categoryIds)) {
|
||||
whereJson.categoryIds = _.in(formData.categoryIds)
|
||||
}
|
||||
|
||||
// if (vk.pubfn.isNotNull(provinceCodes)) {
|
||||
// whereJson['address.province.code'] = _.in(provinceCodes)
|
||||
// }
|
||||
|
||||
// console.log('whereJson', whereJson)
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
getCount: true,
|
||||
whereJson,
|
||||
sortArr: [{name: "_add_time", type: "desc"}],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "userId",
|
||||
foreignKey: "_id",
|
||||
as: "user",
|
||||
limit: 1, // limit=1则以对象形式返回
|
||||
fieldJson: {
|
||||
_id: true,
|
||||
company: {
|
||||
companyName: true
|
||||
},
|
||||
person: {
|
||||
personName: true
|
||||
},
|
||||
businessCard: true,
|
||||
accountType: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "otherUid",
|
||||
foreignKey: "_id",
|
||||
as: "otherUser",
|
||||
limit: 1, // limit=1则以对象形式返回
|
||||
fieldJson: {
|
||||
_id: true,
|
||||
company: {
|
||||
companyName: true,
|
||||
mobile: true
|
||||
},
|
||||
person: {
|
||||
personName: true,
|
||||
mobile: true
|
||||
},
|
||||
businessCard: true,
|
||||
accountType: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
dbName: "jjx-enquiry-quote",
|
||||
localKey: "_id",
|
||||
foreignKey: "sheetId",
|
||||
as: "quoteList",
|
||||
limit: 500, // limit=1则以对象形式返回
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const rows = res.rows
|
||||
const rowIds = rows.map(item => item._id)
|
||||
const orderMap = {}
|
||||
if (rowIds.length > 0) {
|
||||
const orderRes = await vk.baseDao.select({
|
||||
dbName: 'jjx-order',
|
||||
whereJson: {
|
||||
sheetId: _.in(rowIds)
|
||||
},
|
||||
sortArr: [{name: "_add_time", type: "desc"}]
|
||||
})
|
||||
if (orderRes && orderRes.rows) {
|
||||
orderRes.rows.forEach(order => {
|
||||
if (!orderMap[order.sheetId]) orderMap[order.sheetId] = order
|
||||
})
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const row = rows[i];
|
||||
row.order = orderMap[row._id] || null
|
||||
for (let j = 0; j < row.productList.length; j++) {
|
||||
const product = rows[i].productList[j]
|
||||
if (product && product.goodsId) {
|
||||
rows[i].productList[j].template = await vk.baseDao.findById({
|
||||
dbName,
|
||||
id: product.goodsId
|
||||
});
|
||||
}
|
||||
}
|
||||
row.contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-contract',
|
||||
whereJson: {
|
||||
sheetId: row._id,
|
||||
type: 'enquiry',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
res.notPickNum = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
isShow: 1,
|
||||
userId: uid,
|
||||
status: 0,
|
||||
quoteNum: _.gt(0)
|
||||
},
|
||||
});
|
||||
|
||||
res.pickedNum = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
isShow: 1,
|
||||
userId: uid,
|
||||
status: _.in([1, 2])
|
||||
},
|
||||
});
|
||||
|
||||
res.noQuoteNum = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
isShow: 1,
|
||||
userId: uid,
|
||||
quoteNum: 0,
|
||||
status: 0
|
||||
},
|
||||
});
|
||||
|
||||
res.all = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
isShow: 1,
|
||||
userId: uid,
|
||||
},
|
||||
});
|
||||
|
||||
res.rows = rows
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 获取报价单详情
|
||||
* @url client/enquiry/sheet/pub/getDetail 前端调用的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, _id } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
let dbName = "jjx-enquiry-sheet";
|
||||
res.data = await vk.baseDao.findByWhereJson({
|
||||
dbName,
|
||||
whereJson: {
|
||||
_id: _id
|
||||
},
|
||||
// foreignDB: [
|
||||
// {
|
||||
// dbName:"uni-id-users",
|
||||
// localKey:"userId",
|
||||
// foreignKey:"_id",
|
||||
// as:"user",
|
||||
// limit:1, // limit=1则以对象形式返回
|
||||
// fieldJson:{
|
||||
// _id: true,
|
||||
// company: {
|
||||
// companyName: true,
|
||||
// mobile: true,
|
||||
// },
|
||||
// person: {
|
||||
// personName: true,
|
||||
// mobile: true,
|
||||
// },
|
||||
// businessCard: true,
|
||||
// accountType: true,
|
||||
// },
|
||||
// }
|
||||
// ]
|
||||
});
|
||||
|
||||
res.data.user = await vk.baseDao.findByWhereJson({
|
||||
dbName:"uni-id-users",
|
||||
whereJson: {
|
||||
_id: res.data.userId
|
||||
}
|
||||
})
|
||||
if (res.data.user && (res.data.user.isNotaryBusiness === undefined || res.data.user.isNotaryBusiness === null)) {
|
||||
res.data.user.isNotaryBusiness = res.data.user.notaryUnionPayProfile && res.data.user.notaryUnionPayProfile.status === 1 ? 1 : 0
|
||||
}
|
||||
|
||||
res.data.quoteList = []
|
||||
const quoteList = await vk.baseDao.select({
|
||||
dbName: "jjx-enquiry-quote",
|
||||
whereJson: {
|
||||
sheetId: _id
|
||||
}
|
||||
})
|
||||
|
||||
res.data.hasQuote = false
|
||||
res.data.isMine = res.data.userId === uid
|
||||
quoteList.rows.forEach(quote => {
|
||||
if (quote.userId === uid) res.data.hasQuote = true
|
||||
})
|
||||
|
||||
if (quoteList.rows.length > 0) res.data.quoteList = quoteList.rows
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 获取用户发布的询价单
|
||||
* @url client/enquiry/sheet/pub/getList 前端调用的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,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
keyword,
|
||||
categoryIds,
|
||||
provinceCodes,
|
||||
formData,
|
||||
status,
|
||||
companyList,
|
||||
cateList,
|
||||
material,
|
||||
area,
|
||||
latest,
|
||||
} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
let dbName = "jjx-enquiry-sheet";
|
||||
|
||||
|
||||
// const andArr = [];
|
||||
let whereJson = {isShow: 1}
|
||||
if (data.userId && vk.pubfn.isNotNull(data.userId)) {
|
||||
// andArr.push({userId: data.userId})
|
||||
whereJson.userId = data.userId
|
||||
} else {
|
||||
// andArr.push({status: 0})
|
||||
whereJson.status = 0
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNotNull(keyword)) {
|
||||
whereJson.title = new RegExp(keyword)
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNotNull(area)) {
|
||||
console.log(area.length)
|
||||
if (area.length === 3) whereJson['addressRegion.area.code'] = area[2]
|
||||
if (area.length === 2) whereJson['addressRegion.city.code'] = area[1]
|
||||
if (area.length === 1) whereJson['addressRegion.province.code'] = area[0]
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNotNull(latest)) {
|
||||
whereJson['answerStartTime'] = _.gte(dayjs().format('YYYY-MM-DD HH:mm:ss'))
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNotNull(status) && status !== 'all') {
|
||||
// if (status === 'noQuote') andArr.push({quoteNum: 0})
|
||||
// else if (status === 'notPick') andArr.push({status: 0})
|
||||
// else if (status === 'picked') andArr.push({status: 1})
|
||||
if (status === 'noQuote') whereJson.quoteNum = 0
|
||||
else if (status === 'notPick') whereJson.status = 0
|
||||
else if (status === 'picked') whereJson.status = 1
|
||||
}
|
||||
|
||||
if (formData && formData.hasOwnProperty('companyList') && vk.pubfn.isNotNull(formData.companyList)) {
|
||||
// andArr.push({userId: _.in(formData.companyList)})
|
||||
whereJson.stealFactory = _.in(formData.companyList)
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNotNull(companyList)) {
|
||||
// andArr.push({userId: _.in(companyList)})
|
||||
whereJson.stealFactory = _.in(companyList)
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNotNull(cateList)) {
|
||||
// andArr.push({userId: _.in(companyList)})
|
||||
if (cateList.length === 1 && cateList[0] === 0) {
|
||||
whereJson.otherCate = _.exists(true)
|
||||
whereJson.otherCate = _.neq(null)
|
||||
}
|
||||
else whereJson.nameList = _.in(cateList)
|
||||
}
|
||||
|
||||
console.log(whereJson)
|
||||
|
||||
if (vk.pubfn.isNotNull(material)) {
|
||||
// andArr.push({userId: _.in(companyList)})
|
||||
whereJson.material = _.in(material)
|
||||
}
|
||||
|
||||
// if (vk.pubfn.isNotNull(categoryIds)) {
|
||||
// whereJson.userId = _.in(categoryIds)
|
||||
// }
|
||||
|
||||
// if (formData && formData.hasOwnProperty('categoryIds') && vk.pubfn.isNotNull(formData.categoryIds)) {
|
||||
// whereJson.categoryIds = _.in(formData.categoryIds)
|
||||
// }
|
||||
|
||||
// if (vk.pubfn.isNotNull(provinceCodes)) {
|
||||
// whereJson['address.province.code'] = _.in(provinceCodes)
|
||||
// }
|
||||
// const cateFilterList = []
|
||||
// if (vk.pubfn.isNotNull(cateList)) {
|
||||
// cateList.forEach(item => {
|
||||
// cateFilterList.push({
|
||||
// nameList: item,
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
getCount: true,
|
||||
whereJson,
|
||||
sortArr: [{name: "_add_time", type: "desc"}],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "userId",
|
||||
foreignKey: "_id",
|
||||
as: "user",
|
||||
limit: 1, // limit=1则以对象形式返回
|
||||
fieldJson: {
|
||||
_id: true,
|
||||
company: {
|
||||
companyName: true
|
||||
},
|
||||
person: {
|
||||
personName: true
|
||||
},
|
||||
businessCard: true,
|
||||
accountType: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
dbName: "jjx-enquiry-quote",
|
||||
localKey: "_id",
|
||||
foreignKey: "sheetId",
|
||||
as: "quoteList",
|
||||
limit: 500, // limit=1则以对象形式返回
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const rows = res.rows
|
||||
rows.forEach((row, rowIndex) => {
|
||||
row.productList.forEach(async (product, productIndex) => {
|
||||
rows[rowIndex].productList[productIndex].template = await vk.baseDao.findById({
|
||||
dbName,
|
||||
id: product.goodsId
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
res.notPickNum = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
userId: uid,
|
||||
status: 0
|
||||
},
|
||||
});
|
||||
|
||||
res.pickedNum = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
userId: uid,
|
||||
status: 1
|
||||
},
|
||||
});
|
||||
|
||||
res.noQuoteNum = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
userId: uid,
|
||||
quoteNum: 0
|
||||
},
|
||||
});
|
||||
|
||||
res.all = await vk.baseDao.count({
|
||||
dbName,
|
||||
whereJson: {
|
||||
userId: uid,
|
||||
},
|
||||
});
|
||||
|
||||
res.rows = rows
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
const dbName = 'jjx-enquiry-template'
|
||||
module.exports = {
|
||||
/**
|
||||
* 查询现货列表
|
||||
* @url client/spot/goods/kh/getList 前端调用的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 {pageIndex, pageSize} = data
|
||||
|
||||
let whereJson = {
|
||||
enable: true
|
||||
};
|
||||
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName,
|
||||
getCount: false,
|
||||
pageIndex,
|
||||
pageSize: 500,
|
||||
// 主表where条件
|
||||
whereJson: whereJson,
|
||||
// 主表字段显示规则
|
||||
fieldJson: {},
|
||||
// 主表排序规则
|
||||
sortArr: [{name: "sort", type: "asc"}, {"name": "_add_time", "type": "desc"}],
|
||||
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/factory/kh/addUpdate 前端调用的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 check = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-factory",
|
||||
whereJson: {
|
||||
uid
|
||||
}
|
||||
});
|
||||
|
||||
if (check && check.status === 0) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: "审核中,请勿重复提交"
|
||||
}
|
||||
}
|
||||
|
||||
if (!check) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-factory",
|
||||
dataJson: {...data, uid, status: 0, refuseReason: null}
|
||||
});
|
||||
|
||||
} else {
|
||||
await vk.baseDao.update({
|
||||
dbName: "jjx-factory",
|
||||
whereJson: {uid},
|
||||
dataJson: {...data, status: 0}
|
||||
});
|
||||
}
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: uid,
|
||||
dataJson: {
|
||||
factoryStatus: 0
|
||||
}
|
||||
});
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/factory/kh/addUpdate 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-factory",
|
||||
whereJson: {
|
||||
uid
|
||||
}
|
||||
});
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/factory/kh/addUpdate 前端调用的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 {userId} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const resData = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-factory",
|
||||
whereJson: {
|
||||
uid: userId
|
||||
}
|
||||
});
|
||||
res.data = resData
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,623 @@
|
||||
'use strict';
|
||||
const {
|
||||
verify
|
||||
} = require("crypto");
|
||||
var CryptoJS = require("crypto-js");
|
||||
var vk; // 全局vk实例
|
||||
// 涉及的表名
|
||||
const dbName = require("../../dao/config.js")
|
||||
|
||||
var db = uniCloud.database(); // 全局数据库引用
|
||||
var _ = db.command; // 数据库操作符
|
||||
var $ = _.aggregate; // 聚合查询操作符
|
||||
/**
|
||||
* 权限注意:访问以下链接查看
|
||||
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#内置权限
|
||||
*/
|
||||
var cloudObject = {
|
||||
isCloudObject: true, // 标记为云对象模式
|
||||
/**
|
||||
* 请求前处理,主要用于调用方法之前进行预处理,一般用于拦截器、统一的身份验证、参数校验、定义全局对象等。
|
||||
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#before-预处理
|
||||
*/
|
||||
_before: async function () {
|
||||
vk = this.vk; // 将vk定义为全局对象
|
||||
// let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
|
||||
},
|
||||
/**
|
||||
* 请求后处理,主要用于处理本次调用方法的返回结果或者抛出的错误
|
||||
* 文档地址:https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#after-后处理
|
||||
*/
|
||||
_after: async function (options) {
|
||||
let {
|
||||
err,
|
||||
res
|
||||
} = options;
|
||||
if (err) {
|
||||
return; // 如果方法抛出错误,直接return;不处理
|
||||
}
|
||||
return res;
|
||||
},
|
||||
/**
|
||||
* 获取列表
|
||||
* @url client/fadada.getList 前端调用的url参数地址
|
||||
*/
|
||||
getList: async function (data) {
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
},
|
||||
/**
|
||||
* 模板函数
|
||||
* @url client/fadada.test 前端调用的url参数地址
|
||||
*/
|
||||
test: async function (data) {
|
||||
|
||||
},
|
||||
/**
|
||||
* 实名认证异步通知回调
|
||||
* @param {Object} data
|
||||
*/
|
||||
async pub_verifyNotify(data) {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
console.log('fadada res:', data)
|
||||
const {
|
||||
customerId
|
||||
} = data;
|
||||
// 查询认证结果
|
||||
let user = await vk.baseDao.findByWhereJson({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
fadadaCustomerId: customerId,
|
||||
}
|
||||
});
|
||||
let res, fadadaConfirm = false
|
||||
let authStatus = 1
|
||||
if (user.accountType === 1) {
|
||||
res = await pubFun.fadada('find_personCertInfo.api', {
|
||||
verified_serialno: user.fadadaVerify.transactionNo
|
||||
})
|
||||
console.log('fadada check res:', res)
|
||||
// 认证结果
|
||||
const {person} = res.data
|
||||
if (res.code !== 1 || ![2, 3].includes(parseInt(person.status))) {
|
||||
return
|
||||
}
|
||||
fadadaConfirm = parseInt(person.status) === 2
|
||||
} else {
|
||||
res = await pubFun.fadada('find_companyCertInfo.api', {
|
||||
verified_serialno: user.fadadaVerify.transactionNo
|
||||
})
|
||||
console.log('fadada check res:', res)
|
||||
// 认证结果
|
||||
const {company, manager} = res.data
|
||||
if (res.code !== 1 || ![3, 4].includes(parseInt(company.status)) || ![2, 3].includes(parseInt(manager.status))) {
|
||||
return
|
||||
}
|
||||
fadadaConfirm = parseInt(company.status) === 4 && parseInt(manager.status) === 2
|
||||
if (parseInt(company.status) === 3) authStatus = 0
|
||||
}
|
||||
|
||||
|
||||
// 认证成功
|
||||
await vk.baseDao.setById({
|
||||
dbName: "fadada-verify-record",
|
||||
dataJson: {
|
||||
_id: user._id,
|
||||
...res.data
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: user._id,
|
||||
dataJson: {
|
||||
person: {
|
||||
...res.data.person,
|
||||
addressRegion: {
|
||||
province: {},
|
||||
city: {},
|
||||
area: {},
|
||||
}
|
||||
},
|
||||
company: {
|
||||
...res.data.company, ...{
|
||||
mainSpotCategoryIds: [],
|
||||
addressRegion: {
|
||||
province: {},
|
||||
city: {},
|
||||
area: {},
|
||||
}
|
||||
}
|
||||
},
|
||||
manager: res.data.manager,
|
||||
bankCard: res.data.bankCard,
|
||||
fadadaConfirm,
|
||||
// status: 1,
|
||||
authType: 1,
|
||||
// authStatus: 0,
|
||||
userLevel: 0,
|
||||
userGrade: 0,
|
||||
authSubmitTime: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
|
||||
}
|
||||
});
|
||||
|
||||
if (user.inviter_uid && user.inviter_uid.length > 0) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: user.inviter_uid[0],
|
||||
dataJson: {
|
||||
inviteNum: _.inc(1)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return res
|
||||
},
|
||||
/**
|
||||
* 合同签署回调处理
|
||||
* @param {Object} data
|
||||
*/
|
||||
async pub_contractNotify(data) {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
// 开启事务
|
||||
const transaction = await vk.baseDao.startTransaction();
|
||||
|
||||
const {
|
||||
transaction_id,
|
||||
contract_id,
|
||||
timestamp,
|
||||
result_code,
|
||||
download_url,
|
||||
viewpdf_url
|
||||
} = data
|
||||
try {
|
||||
if (parseInt(result_code) == 3000) {
|
||||
// 获取用户信息
|
||||
const userContract = await vk.daoCenter.userContractDao.updateAndReturn({
|
||||
db: transaction,
|
||||
whereJson: {
|
||||
transactionId: transaction_id,
|
||||
sign: false
|
||||
},
|
||||
dataJson: {
|
||||
sign: true,
|
||||
signedAt: timestamp,
|
||||
}
|
||||
})
|
||||
|
||||
let contract = await vk.daoCenter.contractDao.updateAndReturn({
|
||||
db: transaction,
|
||||
whereJson: {
|
||||
_id: userContract.contractId,
|
||||
status: 1,
|
||||
},
|
||||
dataJson: {
|
||||
signCount: _.inc(1),
|
||||
contractHistory: _.push(download_url)
|
||||
}
|
||||
})
|
||||
|
||||
if (userContract.userId === contract.userId) {
|
||||
const userInfo = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
_id: userContract.userId
|
||||
}
|
||||
})
|
||||
let otherList = await vk.daoCenter.userContractDao.selects({
|
||||
whereJson: {
|
||||
contractId: userContract.contractId,
|
||||
}
|
||||
}
|
||||
)
|
||||
otherList.rows = otherList.rows.filter(item => item.userId !== userContract.userId)
|
||||
for (let i = 0; i < otherList.rows.length; i++) {
|
||||
const thirdUserItem = otherList.rows[i]
|
||||
const thirdUser = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
_id: thirdUserItem.userId
|
||||
}
|
||||
})
|
||||
if (thirdUser !== null) {
|
||||
await pubFun.sendNotifySms(thirdUser._id, 'SMS_474570002', {
|
||||
name: thirdUser.accountType === 2 ? thirdUser.company.companyName : thirdUser.person.personName,
|
||||
name2: userInfo.accountType === 2 ? userInfo.company.companyName : userInfo.person.personName,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (contract.type !== 'sign') {
|
||||
// 用户交易额
|
||||
const user = await vk.baseDao.updateAndReturn({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
_id: userContract.userId
|
||||
},
|
||||
dataJson: {
|
||||
transactionAmount: _.inc(parseFloat(contract.amount))
|
||||
}
|
||||
})
|
||||
|
||||
if (user.userLevel > -1) {
|
||||
const userLevel = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-user-level',
|
||||
whereJson: {
|
||||
level: user.userLevel
|
||||
},
|
||||
})
|
||||
await vk.baseDao.update({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
_id: userContract.userId
|
||||
},
|
||||
dataJson: {
|
||||
userGrade: Math.floor(user.transactionAmount / parseFloat(userLevel.upgradeAmount))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (contract.signCount == contract.partyCount) {
|
||||
let sheetId = null
|
||||
contract = await vk.daoCenter.contractDao.updateAndReturn({
|
||||
db: transaction,
|
||||
whereJson: {
|
||||
_id: userContract.contractId,
|
||||
status: 1
|
||||
},
|
||||
dataJson: {
|
||||
status: 2
|
||||
}
|
||||
})
|
||||
|
||||
console.log('contract.type', contract.type)
|
||||
|
||||
// 合同归档
|
||||
const contractFilingRes = await pubFun.fadada('contractFiling.api', {
|
||||
contract_id: contract.transactionId
|
||||
})
|
||||
// console.log('contractFilingRes', contractFilingRes)
|
||||
|
||||
// 添加订单
|
||||
// type 4: 询价 -- enquiry
|
||||
// type 5: 加工 -- process
|
||||
// type 6: 旧货 -- old
|
||||
const otherContract = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-user-contract',
|
||||
whereJson: {
|
||||
contractId: userContract.contractId,
|
||||
role: userContract.role === 'seller' ? 'buyer' : 'seller'
|
||||
}
|
||||
})
|
||||
let sellerUid = null, buyerUid = null
|
||||
if (userContract.role === 'seller') {
|
||||
sellerUid = userContract.userId
|
||||
buyerUid = otherContract.userId
|
||||
} else {
|
||||
sellerUid = otherContract.userId
|
||||
buyerUid = userContract.userId
|
||||
}
|
||||
let type = null, goodsName = null, makeOrder = false, sheet = null
|
||||
if (contract.type === 'enquiry') {
|
||||
type = 4
|
||||
goodsName = '询价单'
|
||||
sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-enquiry-sheet",
|
||||
whereJson: {
|
||||
_id: contract.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
status: 2
|
||||
}
|
||||
})
|
||||
sheetId = contract.sheetId
|
||||
if (sheet.tradeMethod === 1) makeOrder = true
|
||||
} else if (contract.type === 'process') {
|
||||
type = 5
|
||||
goodsName = '加工单'
|
||||
sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-process-sheet",
|
||||
whereJson: {
|
||||
_id: contract.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
status: 2
|
||||
}
|
||||
})
|
||||
sheetId = contract.sheetId
|
||||
if (sheet.tradeMethod === 1) makeOrder = true
|
||||
} else if (contract.type === 'old') {
|
||||
await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-old",
|
||||
whereJson: {
|
||||
_id: contract.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
status: 2
|
||||
}
|
||||
})
|
||||
} else if (contract.type === 'sign') {
|
||||
if (contract.tradeMethod === 1) {
|
||||
makeOrder = true
|
||||
type = 14
|
||||
goodsName = '金久信签约宝'
|
||||
}
|
||||
} else if (contract.type === 'self-support') {
|
||||
makeOrder = true
|
||||
type = 15
|
||||
goodsName = '金久信自营询价'
|
||||
sheetId = contract.sheetId
|
||||
}
|
||||
if (makeOrder) {
|
||||
const orderId = await vk.baseDao.add({
|
||||
dbName: "jjx-order",
|
||||
dataJson: {
|
||||
orderNo: vk.pubfn.createOrderNo("39XU", 20),
|
||||
uid: buyerUid,
|
||||
sellerUid,
|
||||
orderStatus: 0,
|
||||
payStatus: 0,
|
||||
type,
|
||||
amount: contract.amount,
|
||||
offAmount: contract.amount,
|
||||
signMethod: 0,
|
||||
contractId: contract._id,
|
||||
sheetId
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-order-goods",
|
||||
dataJson: {
|
||||
orderId,
|
||||
goodsId: null,
|
||||
num: 1,
|
||||
goodsName,
|
||||
goodsPrice: contract.amount,
|
||||
goodsCover: null,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
await transaction.commit();
|
||||
} catch (e) {
|
||||
await transaction.rollback();
|
||||
console.log('fadada err:', e)
|
||||
return false
|
||||
}
|
||||
return data;
|
||||
},
|
||||
/**
|
||||
* 获取用户认证结果
|
||||
*/
|
||||
async getVerifyResult() {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
let {
|
||||
accountType,
|
||||
fadadaCustomerId
|
||||
} = await this.getUserInfo();
|
||||
|
||||
res.data = await vk.baseDao.findById({
|
||||
dbName: "fadada-verify-record",
|
||||
id: uid
|
||||
});
|
||||
|
||||
return res
|
||||
},
|
||||
/**
|
||||
* 获取实名认证地址
|
||||
*/
|
||||
async getVerifyUrl(event) {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
let {
|
||||
accountType,
|
||||
fadadaCustomerId,
|
||||
fadadaVerify
|
||||
} = await this.getUserInfo();
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
if (fadadaVerify && !event.reset) {
|
||||
res.data = fadadaVerify
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
let verify_url_res;
|
||||
|
||||
let return_url = event.isMobile ? 'https://m.jinjiuxinzg.cn/pages/user/user' : 'https://www.jinjiuxinzg.cn/#/pages/user/user?menu=fadada'
|
||||
if (event.isSignOnly) {
|
||||
return_url = event.isMobile ? 'https://m.jinjiuxinzg.cn/signOnly/#/' : 'https://www.jinjiuxinzg.cn/signOnly/#/pages/user/user?menu=fadada'
|
||||
}
|
||||
let notify_url = 'https://tcb-n44byxi8bmrfrki-d4bn1c4a206d.service.tcloudbase.com/fadada_verify_notify'
|
||||
if (accountType === 1) {
|
||||
verify_url_res = await pubFun.fadada('get_person_verify_url.api', {
|
||||
customer_id: fadadaCustomerId,
|
||||
verified_way: 2,
|
||||
page_modify: 1,
|
||||
cert_flag: 1,
|
||||
// notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify',
|
||||
// return_url: 'https://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/user/user?menu=fadada'
|
||||
notify_url,
|
||||
return_url
|
||||
|
||||
})
|
||||
} else {
|
||||
verify_url_res = await pubFun.fadada('get_company_verify_url.api', {
|
||||
customer_id: fadadaCustomerId,
|
||||
page_modify: 1,
|
||||
cert_flag: 1,
|
||||
// notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify',
|
||||
// return_url: 'https://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/user/user?menu=fadada'
|
||||
notify_url,
|
||||
return_url
|
||||
})
|
||||
}
|
||||
|
||||
console.log('verify_url_data: ', {
|
||||
customer_id: fadadaCustomerId,
|
||||
verified_way: 2,
|
||||
page_modify: 1,
|
||||
cert_flag: 1,
|
||||
// notify_url: 'https://fc-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/fadada_verify_notify',
|
||||
// return_url: 'https://static-mp-0737e52b-fffa-4223-bcdf-d4ad3d9968a5.next.bspapp.com/#/pages/user/user?menu=fadada'
|
||||
notify_url,
|
||||
return_url
|
||||
|
||||
});
|
||||
console.log('verify_url_res: ', verify_url_res);
|
||||
let {
|
||||
transactionNo,
|
||||
url
|
||||
} = verify_url_res.data
|
||||
var parsedWordArray = CryptoJS.enc.Base64.parse(url);
|
||||
url = parsedWordArray.toString(CryptoJS.enc.Utf8);
|
||||
|
||||
await vk.baseDao.update({
|
||||
dbName: "uni-id-users",
|
||||
whereJson: {
|
||||
_id: uid
|
||||
},
|
||||
dataJson: {
|
||||
fadadaVerify: {
|
||||
transactionNo,
|
||||
url
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
res.data = {
|
||||
transactionNo,
|
||||
url
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
|
||||
},
|
||||
/**
|
||||
* 调用此接口将customer_id与实名交易号进行绑定,
|
||||
* 绑定成功后该customer_id无法再次绑定其它不同主体认证交易号。
|
||||
* 必须绑定成功后续才可发起签署
|
||||
*/
|
||||
async applyCert({
|
||||
customerId,
|
||||
transactionNo
|
||||
}) {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
},
|
||||
async generateContract() {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil(); // 获取工具包
|
||||
let res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
};
|
||||
let {
|
||||
uid
|
||||
} = this.getClientInfo(); // 获取客户端信息
|
||||
const contract_id = vk.pubfn.createOrderNo("Contract", 25);
|
||||
const parameter_map = {
|
||||
saler: '网宿科技'
|
||||
};
|
||||
const dynamic_tables = [{
|
||||
headers: ["采购商品", "采购数量", "商品单位"], //表头,
|
||||
datas: [
|
||||
["螺纹钢", "200", "米"]
|
||||
],
|
||||
pageBegin: -1
|
||||
}]
|
||||
const params = {
|
||||
template_id: 'sale',
|
||||
doc_title: '测试买卖合同',
|
||||
contract_id: contract_id,
|
||||
fill_type: 0, // 填充类型 0 pdf 模板、1 在线填充模板
|
||||
parameter_map: JSON.stringify(parameter_map), //填充内容
|
||||
dynamic_tables: JSON.stringify(dynamic_tables), //填充表格
|
||||
}
|
||||
console.log(params);
|
||||
res.data = await pubFun.fadada('generate_contract.api', params)
|
||||
return res;
|
||||
},
|
||||
async getFile({uuid}) {
|
||||
let {
|
||||
customUtil,
|
||||
uniID,
|
||||
config,
|
||||
pubFun
|
||||
} = this.getUtil();
|
||||
const res = {
|
||||
code: 0,
|
||||
msg: ''
|
||||
}
|
||||
const file = await pubFun.fadada('get_file.api', {
|
||||
uuid
|
||||
})
|
||||
res.msg = await vk.uploadFile({
|
||||
title: "上传中...",
|
||||
file,
|
||||
needSave: true,
|
||||
});
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = cloudObject;
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/goods/category/pub/getList 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.getTableData({
|
||||
dbName: 'jjx-goods-category',
|
||||
sortArr: [
|
||||
{ name: "sort", type: "asc" },
|
||||
{ name: "_id", type: "desc" },
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/article/list/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 res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: 'jjx-article',
|
||||
dataJson: {
|
||||
...data, ...{
|
||||
viewNum: 0,
|
||||
downloadNum: 0,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/goods/list/pub/getDetail 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.findById({
|
||||
dbName: "jjx-goods",
|
||||
id: data.id
|
||||
});
|
||||
|
||||
if (!res.sales) {
|
||||
res.sales = 0;
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/goods/list/pub/getList 前端调用的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 {pageIndex, pageSize, parentId, keyword, city, } = data
|
||||
const whereJson = {}
|
||||
if (vk.pubfn.isNotNull(keyword)) {
|
||||
whereJson.name = new RegExp(keyword)
|
||||
}
|
||||
if (vk.pubfn.isNotNull(city)) {
|
||||
whereJson['address.city.code'] = city
|
||||
}
|
||||
if (vk.pubfn.isNotNull(parentId)) {
|
||||
whereJson.parentId = parentId
|
||||
}
|
||||
|
||||
res = await vk.baseDao.select({
|
||||
dbName: 'jjx-goods',
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
whereJson,
|
||||
sortArr: [
|
||||
{name: "recommend", type: "desc"},
|
||||
{name: "sort", type: "asc"},
|
||||
{name: "_add_time", type: "desc"},
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/config/kh/getConfig 前端调用的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 messageConfig = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
uid
|
||||
}
|
||||
});
|
||||
|
||||
if (!messageConfig) {
|
||||
const id = await vk.baseDao.add({
|
||||
dbName: "jjx-message-config",
|
||||
dataJson: {
|
||||
uid,
|
||||
article: true,
|
||||
process: true,
|
||||
old: true,
|
||||
enquiry: true,
|
||||
productList: [],
|
||||
addressRegion: {}
|
||||
}
|
||||
})
|
||||
|
||||
res = await vk.baseDao.findById({
|
||||
dbName: "jjx-message-config",
|
||||
id: id
|
||||
});
|
||||
} else res = messageConfig
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/config/kh/setConfig 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/config/kh/update 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.update({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {uid},
|
||||
dataJson: {
|
||||
...data
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
console.log('here is message', data)
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid,
|
||||
title: data.title,
|
||||
content: data.content,
|
||||
type: data.type,
|
||||
hasRead: false
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/kh/delete 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.deleteById({
|
||||
dbName: "jjx-message",
|
||||
id: data.id
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/kh/getList 前端调用的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, pageIndex, pageSize} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.select({
|
||||
dbName: "jjx-message",
|
||||
getCount: true,
|
||||
whereJson: {
|
||||
uid,
|
||||
},
|
||||
sortArr: [{"name": "_add_time", "type": "desc"}],
|
||||
pageIndex,
|
||||
pageSize
|
||||
})
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/kh/getUnreadCount 前端调用的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, pageIndex, pageSize} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res.data = await vk.baseDao.count({
|
||||
dbName: "jjx-message",
|
||||
whereJson: {
|
||||
uid,
|
||||
hasRead: false
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/kh/setAllRead 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.update({
|
||||
dbName: "jjx-message",
|
||||
whereJson: {
|
||||
uid: uid,
|
||||
hasRead: false
|
||||
},
|
||||
dataJson: {
|
||||
hasRead: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/message/kh/setRead 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-message",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
hasRead: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/notice/list/pub/getDetail 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.findById({
|
||||
dbName: "jjx-notice",
|
||||
id: data.id,
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/notice/list/pub/getList 前端调用的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 {pageIndex, pageSize, parentId, keyword} = data
|
||||
const whereJson = {parentId}
|
||||
if (vk.pubfn.isNotNull(keyword)) {
|
||||
whereJson.name = new RegExp(keyword)
|
||||
}
|
||||
res = await vk.baseDao.select({
|
||||
dbName: 'jjx-notice',
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize: 12,
|
||||
whereJson,
|
||||
sortArr: [
|
||||
{name: "_id", type: "desc"}
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/old/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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
if (!userInfo.fadadaConfirm && userInfo.authStatus === 1) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: '请先完成认证'
|
||||
}
|
||||
} else if (!userInfo.businessCard) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: '请完善名片信息'
|
||||
}
|
||||
} else {
|
||||
if (userInfo.businessCard.status !== 1) {
|
||||
return {
|
||||
code: 1,
|
||||
msg: '您的名片信息未审核,请耐心等待'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!userInfo.remainOldNum || parseInt(userInfo.remainOldNum) === 0) return {
|
||||
code: 1,
|
||||
msg: '本月旧货发布次数已用完'
|
||||
}
|
||||
|
||||
const isUrgent = data.isUrgent
|
||||
delete data.isUrgent
|
||||
const pk = await vk.baseDao.add({
|
||||
dbName: "jjx-old",
|
||||
dataJson: {
|
||||
...data, ...{
|
||||
quoteNum: 0,
|
||||
status: 0,
|
||||
isUrgent: false,
|
||||
isShow: 0,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const messageUserList = await vk.baseDao.select({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
old: true
|
||||
}
|
||||
})
|
||||
const messageList = []
|
||||
for (let i = 0; i < messageUserList.rows.length; i++) {
|
||||
if (messageUserList.rows[i].uid !== uid) {
|
||||
messageList.push({
|
||||
uid: messageUserList.rows[i].uid,
|
||||
title: `旧货:${data.title}`,
|
||||
content: `新的旧货信息发布,赶紧去看看吧`,
|
||||
type: 'old',
|
||||
hasRead: false,
|
||||
pk
|
||||
})
|
||||
await pubFun.sendNotifySms(messageUserList.rows[i].uid, 'SMS_474130452')
|
||||
}
|
||||
}
|
||||
if (messageList.length > 0) {
|
||||
await vk.baseDao.adds({
|
||||
dbName: "jjx-message",
|
||||
dataJson: messageList
|
||||
});
|
||||
}
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "uni-id-users",
|
||||
id: uid,
|
||||
dataJson: {
|
||||
remainOldNum: _.inc(-1)
|
||||
}
|
||||
});
|
||||
|
||||
if (isUrgent) {
|
||||
const amountItem = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '6587dd2fe0ec19027452c5b5'
|
||||
})
|
||||
|
||||
const amount = amountItem.content
|
||||
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: 9,
|
||||
amount,
|
||||
offAmount,
|
||||
saveAmount,
|
||||
offRate,
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-order-goods",
|
||||
dataJson: {
|
||||
orderId,
|
||||
goodsId: pk,
|
||||
num: 1,
|
||||
goodsName: '旧货信息加急',
|
||||
goodsPrice: amount,
|
||||
goodsCover: null,
|
||||
}
|
||||
})
|
||||
res.data = orderId
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
var isBetween = require('dayjs/plugin/isBetween')
|
||||
dayjs.extend(isBetween)
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增报价
|
||||
* @url client/enquiry/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, totalPrice} = data;
|
||||
let {company, manager, person, accountType} = userInfo
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
let noQuoteNo = false
|
||||
|
||||
if (parseInt(userInfo.userLevel) < 3) {
|
||||
if (parseInt(userInfo.remainQuoteNum) === 0 || !userInfo.remainQuoteNum) {
|
||||
|
||||
const checkSheetQuoteNum = await vk.baseDao.findById({
|
||||
dbName: "jjx-old",
|
||||
id: data.sheetId
|
||||
})
|
||||
if (checkSheetQuoteNum.quoteAmount) {
|
||||
const checkQuoteNum = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-user-quote-num",
|
||||
whereJson: {
|
||||
uid,
|
||||
type: 'old',
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let subjectName = ''
|
||||
let subjectMobile = ''
|
||||
let managerName = ''
|
||||
let managerMobile = ''
|
||||
|
||||
const checkSheet = await vk.baseDao.findById({
|
||||
dbName: "jjx-old",
|
||||
id: data.sheetId
|
||||
})
|
||||
|
||||
if (checkSheet.status > 0) return {
|
||||
code: -1,
|
||||
msg: "该旧货交易已关闭"
|
||||
}
|
||||
|
||||
if (accountType === 1 && person.personName && person.mobile) {
|
||||
subjectName = person.personName
|
||||
subjectMobile = person.mobile
|
||||
} else {
|
||||
subjectName = company.companyName
|
||||
subjectMobile = company.companyMobile
|
||||
// if (manager && manager.mobile && manager.personName) {
|
||||
// managerName = manager.personName
|
||||
// managerMobile = manager.mobile
|
||||
// }
|
||||
}
|
||||
|
||||
// 添加报价单
|
||||
res.data = await vk.baseDao.add({
|
||||
dbName: "jjx-old-quote",// 表名
|
||||
dataJson: { // 需要新增的数据 json格式
|
||||
...data,
|
||||
...{
|
||||
userId: data.uid,
|
||||
status: 0,
|
||||
subjectName,
|
||||
subjectMobile,
|
||||
managerName,
|
||||
managerMobile,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const sheet = vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-old",// 表名
|
||||
whereJson: {
|
||||
_id: data.sheetId,
|
||||
},
|
||||
dataJson: {
|
||||
quoteNum: _.inc(1)
|
||||
}
|
||||
})
|
||||
|
||||
const checkMessage = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
old: true,
|
||||
uid: sheet.userId
|
||||
}
|
||||
})
|
||||
|
||||
if (checkMessage) {
|
||||
let send = true
|
||||
// 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}`)))
|
||||
// send = false
|
||||
// }
|
||||
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}`)))
|
||||
send = false
|
||||
}
|
||||
|
||||
if (checkMessage.tradeAmount && checkMessage.tradeAmount[0]) {
|
||||
if (sheet.totalPrice < checkMessage.tradeAmount[0] || sheet.totalPrice > checkMessage.tradeAmount[1])
|
||||
send = false
|
||||
}
|
||||
|
||||
if (send) {
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: sheet.userId,
|
||||
title: `旧货:${sheet.title}报价`,
|
||||
content: `您的旧货信息有新的报价,赶紧去看看吧`,
|
||||
type: 'old',
|
||||
hasRead: false,
|
||||
pk: data.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(sheet.userId, 'SMS_474185570')
|
||||
}
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 新增报价
|
||||
* @url client/enquiry/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, totalPrice} = data;
|
||||
let {company, manager, person, accountType} = userInfo
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const amountItem = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '6587dd54189f86d49b3d5ff5'
|
||||
})
|
||||
|
||||
const amount = amountItem.content
|
||||
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: 10,
|
||||
amount,
|
||||
offAmount,
|
||||
saveAmount,
|
||||
offRate,
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-order-goods",
|
||||
dataJson: {
|
||||
orderId,
|
||||
goodsId: null,
|
||||
num: 1,
|
||||
goodsName: '旧货发布次数购买',
|
||||
goodsPrice: amount,
|
||||
goodsCover: null,
|
||||
}
|
||||
})
|
||||
|
||||
res.data = orderId
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/enquiry/sheet/kh/changeToOnlineSign 前端调用的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 sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-old",
|
||||
whereJson: {
|
||||
_id: data.id
|
||||
},
|
||||
dataJson: {
|
||||
signMethod: 0,
|
||||
status: 1
|
||||
}
|
||||
});
|
||||
|
||||
const quote = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-old-quote",
|
||||
whereJson: {
|
||||
sheetId: data.id,
|
||||
status: 1
|
||||
}
|
||||
});
|
||||
|
||||
if (quote) {
|
||||
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("OL", 20)
|
||||
const contractTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
fadadaContractId,
|
||||
contractBase: '', // 原始合同
|
||||
contractHistory: [], // 历史合同
|
||||
contractFinal: '', // 归档合同
|
||||
status: 0,
|
||||
userId: uid,
|
||||
type: 'old',
|
||||
quoteId: quote.id,
|
||||
sheetId: quote.sheetId,
|
||||
productList: quote.productList,
|
||||
productTitle: sheet.title,
|
||||
tradeMethod: 0,
|
||||
partyCount: 2,
|
||||
signCount: 0,
|
||||
contractType: sheet.contractType,
|
||||
signMethod: sheet.signMethod,
|
||||
sellerSupplement: sheet.sellerSupplement,
|
||||
transactionId: contractTransactionId,
|
||||
amount: quote.totalPrice,
|
||||
docTitle: sheet.title,
|
||||
}
|
||||
})
|
||||
|
||||
// 上传合同模板
|
||||
|
||||
//新增 用户与合同的关联记录
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: quote.userId,
|
||||
role: 'seller',
|
||||
sign: false,
|
||||
contractId
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: uid,
|
||||
role: 'buyer',
|
||||
sign: false,
|
||||
contractId
|
||||
}
|
||||
])
|
||||
}
|
||||
// const contractFile = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d36befe975f63af1f24e7'
|
||||
// })
|
||||
// const signMaxDate = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d78958b0da41d311bd94c'
|
||||
// })
|
||||
// const buyerSignKeyword = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d37972139294200fc9a01'
|
||||
// })
|
||||
// const sellerSignKeyword = await vk.baseDao.findById({
|
||||
// dbName: 'jjx-dict',
|
||||
// id: '657d37a609664c4f4a5c4afb'
|
||||
// })
|
||||
// const signEndDate = vk.pubfn.getOffsetTime(new Date(), {
|
||||
// day: parseInt(signMaxDate.content),
|
||||
// mode: "after",
|
||||
// });
|
||||
//
|
||||
// const uploaddocs = await pubFun.fadada('uploaddocs.api', {
|
||||
// contract_id: contractTransactionId,
|
||||
// doc_title: sheet.title,
|
||||
// doc_url: contractFile.content,
|
||||
// // file: doc_url,
|
||||
// doc_type: '.pdf'
|
||||
// })
|
||||
// if (parseInt(uploaddocs.code) === 1000) {
|
||||
// await vk.baseDao.updateAndReturn({
|
||||
// dbName: dbName.contract,
|
||||
// whereJson: {
|
||||
// _id: contractId,
|
||||
// userId: uid
|
||||
// },
|
||||
// dataJson: {
|
||||
// status: 1,
|
||||
// docTitle: sheet.title,
|
||||
// signEndDate,
|
||||
// otherFile: '',
|
||||
// contractBase: contractFile.content,
|
||||
// buyerSignKeyword: buyerSignKeyword.content,
|
||||
// sellerSignKeyword: sellerSignKeyword.content
|
||||
// }
|
||||
// })
|
||||
// await vk.baseDao.updateAndReturn({
|
||||
// dbName: 'jjx-old',
|
||||
// whereJson: {
|
||||
// _id: data.id
|
||||
// },
|
||||
// dataJson: {
|
||||
// status: 2
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// res.data = uploaddocs.result
|
||||
// } else {
|
||||
// return {
|
||||
// code: -1,
|
||||
// msg: uploaddocs.msg
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,414 @@
|
||||
'use strict';
|
||||
|
||||
const dbName = require("../../../../dao/config");
|
||||
const dayjs = require("dayjs");
|
||||
var isBetween = require('dayjs/plugin/isBetween')
|
||||
dayjs.extend(isBetween)
|
||||
|
||||
const PROCESS_PAY_METHOD = ['预付', '货到验收后付款', '提货付全款', '信誉采购,货到签单后账期:']
|
||||
const WRITE_INVOICE_TIME = ['付款当月(限20号之前付款,20号之后付款次月开票)', '付款后次月', '付款前']
|
||||
const INVOICE_TYPE = ['增值税专用发票13%', '增值税普通发票', '普通发票']
|
||||
|
||||
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-old-quote',
|
||||
whereJson: {
|
||||
_id: quoteId,
|
||||
status: 0
|
||||
},
|
||||
dataJson: {
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
if (!quote) {
|
||||
return {
|
||||
code: -1,
|
||||
msg: '请刷新页面'
|
||||
}
|
||||
}
|
||||
// 获取乙方信息
|
||||
const quoteUser = await vk.baseDao.select({
|
||||
dbName: 'uni-id-users',
|
||||
getMain: true,
|
||||
getOne: true,
|
||||
whereJson: {
|
||||
_id: quote.userId
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 获取询价单信息
|
||||
const sheet = await vk.baseDao.updateAndReturn({
|
||||
dbName: 'jjx-old',
|
||||
whereJson: {_id: quote.sheetId},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
quoteUid: quote.userId
|
||||
}
|
||||
})
|
||||
|
||||
// 获取商品信息
|
||||
const productTitle = sheet.title
|
||||
if (sheet.type !== 3 && sheet.signMethod !== 1) {
|
||||
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("E", 20)
|
||||
// 新增合同记录
|
||||
let contractTransactionId = vk.pubfn.createOrderNo("C", 20)
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
fadadaContractId: fadadaContractId,
|
||||
contractBase: '', // 原始合同
|
||||
contractHistory: [], // 历史合同
|
||||
contractFinal: '', // 归档合同
|
||||
status: 0,
|
||||
userId: uid,
|
||||
type: 'old',
|
||||
quoteId: quoteId,
|
||||
sheetId: quote.sheetId,
|
||||
productList: [],
|
||||
productTitle,
|
||||
tradeMethod: 0,
|
||||
partyCount: 2,
|
||||
signCount: 0,
|
||||
contractType: sheet.contractType,
|
||||
signMethod: sheet.signMethod,
|
||||
sellerSupplement: sheet.sellerSupplement,
|
||||
transactionId: contractTransactionId,
|
||||
amount: quote.totalPrice,
|
||||
docTitle: sheet.title
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: 'jjx-old',
|
||||
id: quote.sheetId,
|
||||
dataJson: {
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
const checkMessage = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-message-config",
|
||||
whereJson: {
|
||||
old: true,
|
||||
uid: quote.userId
|
||||
}
|
||||
})
|
||||
|
||||
if (checkMessage) {
|
||||
if (checkMessage.doNotDisturbRange) {
|
||||
if (dayjs().isBetween(checkMessage.doNotDisturbRange[0], checkMessage.doNotDisturbRange[1])) return
|
||||
}
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: quote.userId,
|
||||
title: `旧货:${sheet.title}被选商`,
|
||||
content: `您报价的旧货信息已被选商,赶紧去签合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
pk: quote.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(quote.userId, 'SMS_474130453')
|
||||
}
|
||||
|
||||
// 上传合同模板
|
||||
|
||||
//新增 用户与合同的关联记录
|
||||
let buyerUid = uid
|
||||
let sellerUid = quote.userId
|
||||
if (sheet.type === 0) {
|
||||
buyerUid = quote.userId
|
||||
sellerUid = uid
|
||||
}
|
||||
await vk.daoCenter.userContractDao.adds([
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: buyerUid,
|
||||
role: 'buyer',
|
||||
sign: false,
|
||||
contractId
|
||||
},
|
||||
{
|
||||
transactionId: vk.pubfn.createOrderNo("E", 20),
|
||||
userId: sellerUid,
|
||||
role: 'seller',
|
||||
sign: false,
|
||||
contractId
|
||||
}
|
||||
])
|
||||
|
||||
if (sheet.signMethod === 0) {
|
||||
const templateId = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '80e3bed065a5560e075799d24532b14f'
|
||||
})
|
||||
const buyerSignKeyword = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '0b153f9a65a56a2007227cf5157133bf'
|
||||
})
|
||||
const sellerSignKeyword = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '09e7876865a56a320731cb244bbef818'
|
||||
})
|
||||
const signMaxDate = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: '657d78958b0da41d311bd94c'
|
||||
})
|
||||
const signEndDate = vk.pubfn.getOffsetTime(new Date(), {
|
||||
day: parseInt(signMaxDate.content),
|
||||
mode: "after",
|
||||
});
|
||||
// const fieldList = await vk.baseDao.select({
|
||||
// dbName: 'jjx-contract-template',
|
||||
// whereJson: {
|
||||
// isOn: true
|
||||
// }
|
||||
// })
|
||||
let buyerSupplement = sheet.supplementary ? sheet.supplementary : ''
|
||||
let sellerSupplement = quote.remark ? quote.remark : ''
|
||||
if (quote.supplierExt) sellerSupplement += `${quote.remark ? ',' : ''}${quote.supplierExt}`
|
||||
let sellerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: quote.userId
|
||||
})
|
||||
let buyerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: uid
|
||||
})
|
||||
if (sheet.type === 0) {
|
||||
sellerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: uid
|
||||
})
|
||||
buyerUser = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: quote.userId
|
||||
})
|
||||
buyerSupplement = quote.remark ? quote.remark : ''
|
||||
if (quote.supplierExt) buyerSupplement += `,${quote.supplierExt}`
|
||||
sellerSupplement = sheet.supplementary ? sheet.supplementary : ''
|
||||
}
|
||||
let detail = sheet.title
|
||||
if (sheet.otherCate) detail += `,${sheet.otherCateName}`
|
||||
if (sheet.type === 0 && sheet.unit) {
|
||||
detail += `,计价单位: ${sheet.unit},人民币单价: ${quote.totalPrice}元`
|
||||
}
|
||||
|
||||
let tradeInfo = ''
|
||||
if (sheet.type === 0) tradeInfo = `${sheet.payMethod}`
|
||||
else tradeInfo = `报价:${quote.totalPrice}元,${sheet.payMethod}`
|
||||
if (sheet.payMethod === '预付' && sheet.prePayRate) tradeInfo += `,${sheet.prePayRate}%货到付全款`
|
||||
if (sheet.payMethod === '其他付款方式描述') tradeInfo += `:${sheet.otherPayMethodDesc}`
|
||||
|
||||
if (sheet.type === 2) {
|
||||
tradeInfo += (sheet.invoice ? ',含税' : ',不含税')
|
||||
if (sheet.invoice) tradeInfo += (',开票时间:' + (sheet.writeInvoiceTime ? WRITE_INVOICE_TIME[sheet.writeInvoiceTime] : '无'))
|
||||
// tradeInfo += (',发票种类:' + (sheet.invoiceType ? INVOICE_TYPE[sheet.invoiceType] : '无'))
|
||||
// tradeInfo += (',其他要求:' + (sheet.invoiceOther ? sheet.invoiceOther : '无'))
|
||||
if (sheet.invoiceOther) tradeInfo += (',其他要求:' + sheet.invoiceOther)
|
||||
else {
|
||||
if (sheet.taxType && sheet.invoiceType && sheet.taxRate) tradeInfo += (`,纳税人身份:${sheet.taxType},发票种类:${sheet.invoiceType},税率:${sheet.taxRate}`)
|
||||
}
|
||||
tradeInfo += (',报价明细:' + (sheet.invoiceDetail ? sheet.invoiceDetail : '无'))
|
||||
} else if ([0, 1].includes(sheet.type)) {
|
||||
if (sheet.invoiceOther) tradeInfo += (',其他要求:' + sheet.invoiceOther)
|
||||
else {
|
||||
if (sheet.taxType && sheet.invoiceType && sheet.taxRate) tradeInfo += (`,纳税人身份:${sheet.taxType},发票种类:${sheet.invoiceType},税率:${sheet.taxRate}`)
|
||||
}
|
||||
}
|
||||
let expressRequire = '无'
|
||||
// expressRequire += `随货资料:${sheet.transportDocuments.join()},其他要求:${sheet.otherTransportDocuments ? sheet.otherTransportDocuments : '无'},运输限制要求:${sheet.transportLimit ? '有' : '无'}`
|
||||
// if (sheet.transportLimit && sheet.otherTransportRequest) expressRequire += `运输限制说明:${sheet.otherTransportRequest}`
|
||||
let region = ''
|
||||
if (sheet.type === 1) region = sheet.deliverAddressRegion.province.name + ' ' + sheet.deliverAddressRegion.city.name + ' ' + sheet.deliverAddressRegion.area.name
|
||||
else region = sheet.addressRegion.province.name + ' ' + sheet.addressRegion.city.name + ' ' + sheet.addressRegion.area.name
|
||||
const parameter = {
|
||||
seller: sellerUser.accountType === 2 ? sellerUser.company.companyName : sellerUser.person.personName,
|
||||
buyer: buyerUser.accountType === 2 ? buyerUser.company.companyName : buyerUser.person.personName,
|
||||
date: dayjs().format('YYYY年MM月DD日'),
|
||||
sellerSignDate: dayjs().format('YYYY年MM月DD日 HH时mm'),
|
||||
buyerSignDate: dayjs().format('YYYY年MM月DD日 HH时mm'),
|
||||
contractNo: fadadaContractId,
|
||||
region,
|
||||
detail,
|
||||
info: '无',
|
||||
tradeInfo,
|
||||
expressRequire,
|
||||
defaultDuty: '1.乙方所交产品品种、型号、规格、质量不符合规定的,如果甲方同意利用,应当按质论价;如果甲方不能利用的,应根据产品的具体情况,由乙方负责包换或包修,并承担修理、调换或退货而支付的实际费用;2.乙方不予供货违约责任为甲方的实际损失+违约金,如乙方材料符合订货标准,甲方不能退货和不收货,甲方无条件应按实际本合同订货数量支付100%货款,并支付乙方因此产生的实际费用。带有甲乙双方单位相关收货人和发货人签字的本合同的发货清单事项和内容均视为本合同的补充合同,与本合同有相同的法律效力,双方应共同遵照执行。',
|
||||
solve: '1、凡因本合同引起的或与本合同有关的任何争议,均可友好协商或仲裁解决,协商或仲裁不成的,双方协商同意在合同签订地人民法院管辖地起诉,违约一方或对合同争议承担主要责任的一方,应承担对方因仲裁和起诉而产生的全部律师代理费、鉴定(检验)费、诉讼保全费、诉讼保险费、公告费、差旅费、执行费、误工費和获取证据产生费用等其他相关费用。2、双方本合同相关权利放弃均应有双方书面作出并加盖公章或授权委托人签字后生效。',
|
||||
forceMajeure: '甲乙双方的任何一方由于不可抗力或突发公共事件的原因不能履行合同时,应及时向对方通报不能履行或不能完全履行的理由,以减轻可能给对方造成的损失,在取得有关机构证明以后,允许延期履行、部分履行或者不履行合同,并根据情况可部分或全部免予承担违约责任。',
|
||||
other: '本合同的全部内容由双方平等共同协商一致,共同起草制定,非一方事先拟定,不属于格式条款。本合同自双方签字盖章后生效(包括电子签字、盖章),按本合同内容地址、联系方式寄送的一切文书、函件送达与否,均为视为送达有法律效力,通知途径和本合同内联系方式或地址送达文件双方均予以验证。',
|
||||
buyerSupplement,
|
||||
sellerSupplement,
|
||||
buyerAddress: buyerUser.accountType === 2 ? buyerUser.company.mailAddress : buyerUser.person.address,
|
||||
sellerAddress: sellerUser.accountType === 2 ? sellerUser.company.mailAddress : sellerUser.person.address,
|
||||
buyerLegal: buyerUser.accountType === 2 ? buyerUser.company.legalName : '',
|
||||
sellerLegal: sellerUser.accountType === 2 ? sellerUser.company.legalName : '',
|
||||
buyerAgent: buyerUser.accountType === 2 ? buyerUser.manager.personName : '',
|
||||
sellerAgent: sellerUser.accountType === 2 ? sellerUser.manager.personName : '',
|
||||
buyerMobile: buyerUser.accountType === 2 ? buyerUser.manager.mobile : buyerUser.mobile,
|
||||
sellerMobile: sellerUser.accountType === 2 ? sellerUser.manager.mobile : sellerUser.mobile,
|
||||
buyerBankName: buyerUser.accountType === 2 ? buyerUser.company.companyBankName : buyerUser.person.personBankName,
|
||||
sellerBankName: sellerUser.accountType === 2 ? sellerUser.company.companyBankName : sellerUser.person.personBankName,
|
||||
buyerAccount: buyerUser.accountType === 2 ? buyerUser.company.companyAccount : buyerUser.person.personAccount,
|
||||
sellerAccount: sellerUser.accountType === 2 ? sellerUser.company.companyAccount : sellerUser.person.personAccount,
|
||||
}
|
||||
// for (let i = 0; i < fieldList.length; i++) {
|
||||
//
|
||||
// const field = fieldList[i]
|
||||
// parameter[field.field] = ''
|
||||
// }
|
||||
const uploaddocs = await pubFun.fadada('generate_contract.api', {
|
||||
template_id: templateId.content,
|
||||
contract_id: contractTransactionId,
|
||||
parameter_map: JSON.stringify(parameter)
|
||||
})
|
||||
let otherFileResList = []
|
||||
if (quote.files && quote.files.length > 0) {
|
||||
for (let i = 0; i < quote.files.length; i++) {
|
||||
otherFileResList.push(contractTransactionId + 'qf' + i.toString())
|
||||
await pubFun.fadada('uploaddocs.api', {
|
||||
contract_id: contractTransactionId + 'qf' + i.toString(),
|
||||
doc_title: sheet.title + `:报价附件${i + 1}`,
|
||||
doc_url: quote.files[i],
|
||||
doc_type: '.pdf'
|
||||
})
|
||||
}
|
||||
}
|
||||
if (otherFileResList.length) {
|
||||
otherFileResList.unshift(contractTransactionId)
|
||||
// 合并接口
|
||||
contractTransactionId = vk.pubfn.createOrderNo("MC", 20)
|
||||
const mergeRes = await pubFun.fadada('merge_contract.api', {
|
||||
contract_id: contractTransactionId,
|
||||
doc_title: sheet.title,
|
||||
contract_ids: otherFileResList.join()
|
||||
})
|
||||
console.log('mergeRes', mergeRes)
|
||||
console.log('otherFileResList', otherFileResList)
|
||||
}
|
||||
await vk.baseDao.update({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId
|
||||
},
|
||||
dataJson: {
|
||||
transactionId: contractTransactionId,
|
||||
}
|
||||
})
|
||||
if (parseInt(uploaddocs.code) === 1000) {
|
||||
await vk.baseDao.updateAndReturn({
|
||||
dbName: dbName.contract,
|
||||
whereJson: {
|
||||
_id: contractId,
|
||||
userId: uid
|
||||
},
|
||||
dataJson: {
|
||||
status: 1,
|
||||
docTitle: sheet.title,
|
||||
signEndDate,
|
||||
otherFile: '',
|
||||
contractBase: null,
|
||||
buyerSignKeyword: buyerSignKeyword.content,
|
||||
sellerSignKeyword: sellerSignKeyword.content
|
||||
}
|
||||
})
|
||||
await vk.baseDao.updateAndReturn({
|
||||
dbName: 'jjx-old',
|
||||
whereJson: {
|
||||
_id: quote.sheetId
|
||||
},
|
||||
dataJson: {
|
||||
status: 2
|
||||
}
|
||||
})
|
||||
|
||||
res.data = uploaddocs.result
|
||||
|
||||
await vk.baseDao.add({
|
||||
dbName: "jjx-message",
|
||||
dataJson: {
|
||||
uid: quote.userId,
|
||||
title: `旧货:${sheet.title}待签合同`,
|
||||
content: `您报价的旧货信息已创建合同,赶紧去签订合同吧`,
|
||||
type: 'contract',
|
||||
hasRead: false,
|
||||
pk: quote.sheetId
|
||||
}
|
||||
});
|
||||
await pubFun.sendNotifySms(quote.userId, 'SMS_474195497')
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: uploaddocs.msg
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// const orderId = await vk.baseDao.add({
|
||||
// dbName: "jjx-order",
|
||||
// dataJson: {
|
||||
// orderNo: vk.pubfn.createOrderNo("CO", 20),
|
||||
// uid: uid,
|
||||
// sellerUid: quote.userId,
|
||||
// orderStatus: 0,
|
||||
// type: 4,
|
||||
// amount: quote.totalPrice,
|
||||
// offAmount: quote.totalPrice,
|
||||
// signMethod: 1
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// await vk.baseDao.add({
|
||||
// dbName: "jjx-order-goods",
|
||||
// dataJson: {
|
||||
// orderId,
|
||||
// goodsId: null,
|
||||
// num: 1,
|
||||
// goodsName: '旧货交易',
|
||||
// goodsPrice: quote.totalPrice,
|
||||
// goodsCover: null,
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/enquiry/sheet/kh/delete 前端调用的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 {id} = data;
|
||||
if (vk.pubfn.isNull(id)) {
|
||||
return {code: -1, msg: 'id不能为空'};
|
||||
}
|
||||
await vk.baseDao.deleteById({
|
||||
dbName: 'jjx-old',
|
||||
id
|
||||
});
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/old/kh/getList 前端调用的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, pageIndex, pageSize = -1} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
let whereJson = {}
|
||||
if (vk.pubfn.isNotNull(data.sellerOnly)) {
|
||||
// whereJson.uid = data.uid
|
||||
// whereJson.type = _.in([0, 2, 3])
|
||||
whereJson = _.or([
|
||||
_.and({
|
||||
uid: data.uid,
|
||||
type: _.in([0, 3]),
|
||||
}),
|
||||
_.and([
|
||||
{
|
||||
uid: data.uid,
|
||||
type: 2,
|
||||
rentType: 0
|
||||
}
|
||||
])
|
||||
])
|
||||
if (vk.pubfn.isNotNull(data.signMethod)) {
|
||||
if (parseInt(data.signMethod) === 1) whereJson[0].push({
|
||||
signMethod: parseInt(data.signMethod
|
||||
)
|
||||
})
|
||||
else whereJson.signMethod = whereJson.push({
|
||||
signMethod: _.neq(1)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
if (vk.pubfn.isNotNull(data.buyerOnly)) {
|
||||
// whereJson.uid = data.uid
|
||||
// whereJson.type = _.in([0, 2, 3])
|
||||
const orArr = [
|
||||
_.and({
|
||||
uid: data.uid,
|
||||
type: _.in([1]),
|
||||
}),
|
||||
_.and([
|
||||
{
|
||||
uid: data.uid,
|
||||
type: 2,
|
||||
rentType: 0
|
||||
}
|
||||
]),
|
||||
_.and({
|
||||
quoteUid: data.quoteUid,
|
||||
type: _.in([0, 3]),
|
||||
}),
|
||||
_.and([
|
||||
{
|
||||
quoteUid: data.quoteUid,
|
||||
type: 2,
|
||||
rentType: 1
|
||||
}
|
||||
]),
|
||||
]
|
||||
if (vk.pubfn.isNotNull(data.signMethod)) {
|
||||
if (parseInt(data.signMethod) === 1) orArr.push(_.and({
|
||||
|
||||
signMethod: parseInt(data.signMethod)
|
||||
}))
|
||||
else {
|
||||
orArr.push(_.and({
|
||||
signMethod: _.neq(1)
|
||||
}))
|
||||
}
|
||||
}
|
||||
whereJson = _.or([
|
||||
...orArr
|
||||
])
|
||||
} else {
|
||||
if (vk.pubfn.isNotNull(data.quoteUid)) {
|
||||
whereJson.quoteUid = data.quoteUid;
|
||||
} else whereJson.uid = data.uid;
|
||||
if (vk.pubfn.isNotNull(data.signMethod)) {
|
||||
if (parseInt(data.signMethod) === 1) whereJson.signMethod = parseInt(data.signMethod);
|
||||
else whereJson.signMethod = _.neq(1)
|
||||
}
|
||||
}
|
||||
console.log('whereJson', whereJson)
|
||||
|
||||
// console.log(whereJson)
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: "jjx-old",
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
whereJson,
|
||||
sortArr: [{"name": "_add_time", "type": "desc"}],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "jjx-old-quote",
|
||||
localKey: "_id",
|
||||
foreignKey: "sheetId",
|
||||
as: "quoteList",
|
||||
limit: 500,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "uid",
|
||||
foreignKey: "_id",
|
||||
as: "user",
|
||||
limit: 1
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
})
|
||||
for (let i = 0; i < res.rows.length; i++) {
|
||||
if (res.rows[i].quoteUid) {
|
||||
res.rows[i].otherUser = await vk.baseDao.findById({
|
||||
dbName: "uni-id-users",
|
||||
id: res.rows[i].quoteUid
|
||||
})
|
||||
}
|
||||
res.rows[i].user = await vk.baseDao.findById({
|
||||
dbName: "uni-id-users",
|
||||
id: res.rows[i].uid
|
||||
})
|
||||
|
||||
res.rows[i].contract = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-contract",
|
||||
whereJson: {
|
||||
sheetId: res.rows[i]._id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
'use strict';
|
||||
|
||||
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-old-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: 'jjx-old',
|
||||
whereJson: {_id: quote.sheetId},
|
||||
getMain: true,
|
||||
getOne: true
|
||||
})
|
||||
|
||||
// 获取商品信息
|
||||
const productTitle = sheet.title
|
||||
|
||||
const fadadaContractId = vk.pubfn.createOrderNo("E", 20)
|
||||
// 上传合同模板并填充
|
||||
// if(sheet.signMethod == 0 && sheet.contractType == 0) {
|
||||
// pubFun.fadada('generate_contract.api', {
|
||||
// template_id: '20231120',
|
||||
// contract_id: fadadaContractId,
|
||||
// parameter_map: JSON.stringify({
|
||||
// jiaName: userInfo.accountType == 1?userInfo.person.personName: userInfo.company.companyName,
|
||||
// jiaDate: '',
|
||||
// jiaPhone: '',
|
||||
// yiName: userInfo.accountType == 1?userInfo.person.personName: userInfo.company.companyName,
|
||||
// yiDate: '',
|
||||
// yiPhone: '',
|
||||
// sellerSupplement: '',
|
||||
// }),
|
||||
// })
|
||||
// }
|
||||
|
||||
|
||||
// 新增合同记录
|
||||
const contractId = await vk.baseDao.add({
|
||||
dbName: 'jjx-contract',
|
||||
dataJson: {
|
||||
fadadaContractId: fadadaContractId,
|
||||
contractBase: '', // 原始合同
|
||||
contractHistory: [], // 历史合同
|
||||
contractFinal: '', // 归档合同
|
||||
status: 0,
|
||||
userId: uid,
|
||||
type: 'old',
|
||||
quoteId: quoteId,
|
||||
sheetId: quote.sheetId,
|
||||
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,
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: 'jjx-old',
|
||||
id: quote.sheetId,
|
||||
dataJson: {
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: 'jjx-old-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
|
||||
}
|
||||
])
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/old/pub/getDetail 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-old",
|
||||
getOne: true,
|
||||
whereJson: {
|
||||
_id: data.id
|
||||
},
|
||||
});
|
||||
if (res) {
|
||||
const {rows} = await vk.baseDao.select({
|
||||
dbName: "jjx-old-quote",
|
||||
whereJson: {
|
||||
sheetId: data.id
|
||||
},
|
||||
limit: 500,
|
||||
sortArr: [{"name": "_add_time", "type": "desc"}],
|
||||
})
|
||||
for(let i = 0; i< rows.length; i++){
|
||||
rows[i].user = await vk.baseDao.findByWhereJson({
|
||||
dbName: "uni-id-users",
|
||||
getOne: true,
|
||||
whereJson: {
|
||||
_id: rows[i].userId
|
||||
},
|
||||
})
|
||||
}
|
||||
res.quoteList = rows
|
||||
|
||||
res.hasQuote = false
|
||||
res.isMine = res.uid === uid
|
||||
res.quoteList.forEach(quote => {
|
||||
if (quote.userId === uid) res.hasQuote = true
|
||||
})
|
||||
|
||||
res.user = await vk.baseDao.findByWhereJson({
|
||||
dbName: "uni-id-users",
|
||||
getOne: true,
|
||||
whereJson: {
|
||||
_id: res.uid
|
||||
},
|
||||
})
|
||||
|
||||
}else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: "未找到该旧货信息"
|
||||
}
|
||||
}
|
||||
// res = result.rows
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/old/pub/getList 前端调用的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, pageIndex, pageSize, type, isUrgent, rentType} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const whereJson = {isShow: 1, status: 0}
|
||||
if (vk.pubfn.isNotNull(data.keyword) && data.keyword !== '') {
|
||||
whereJson.title = new RegExp(data.keyword)
|
||||
}
|
||||
if (vk.pubfn.isNotNull(type)) {
|
||||
whereJson.type = parseInt(type)
|
||||
if (parseInt(type) === 2) {
|
||||
if (vk.pubfn.isNotNull(rentType)) whereJson.rentType = parseInt(rentType)
|
||||
}
|
||||
}
|
||||
if (vk.pubfn.isNotNull(isUrgent) && isUrgent) whereJson.isUrgent = true
|
||||
if (vk.pubfn.isNotNull(data.categoryIds)) {
|
||||
if (data.categoryIds.length === 1 && data.categoryIds[0] === 0) {
|
||||
whereJson['category'] = ''
|
||||
} else {
|
||||
whereJson.category = _.in(data.categoryIds)
|
||||
}
|
||||
}
|
||||
if (vk.pubfn.isNotNull(data.provinceCodes)) {
|
||||
whereJson['addressRegion.province.code'] = _.in(data.provinceCodes)
|
||||
}
|
||||
if (vk.pubfn.isNotNull(data.cityCode)) {
|
||||
whereJson['addressRegion.city.code'] = _.in([data.cityCode])
|
||||
}
|
||||
whereJson['expiredTime'] = _.gte(dayjs().format('YYYY-MM-DD'))
|
||||
console.log(whereJson)
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: "jjx-old",
|
||||
pageIndex,
|
||||
pageSize,
|
||||
getCount: true,
|
||||
sortArr: [{"name": "isUrgent", "type": "desc"}, {"name": "_add_time", "type": "desc"}],
|
||||
whereJson,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "uid",
|
||||
foreignKey: "_id",
|
||||
as: "user",
|
||||
limit: 1, // limit=1则以对象形式返回
|
||||
fieldJson: {
|
||||
_id: true,
|
||||
company: {
|
||||
companyName: true,
|
||||
mobile: true,
|
||||
},
|
||||
person: {
|
||||
personName: true,
|
||||
mobile: true,
|
||||
},
|
||||
businessCard: true,
|
||||
accountType: true,
|
||||
},
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
'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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/addFromList 前端调用的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 amount = 0
|
||||
const cartList = await vk.baseDao.selects({
|
||||
dbName: "jjx-cart",
|
||||
whereJson: {
|
||||
uid,
|
||||
_id: _.in(data.ids)
|
||||
},
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "jjx-goods", // 副表名
|
||||
localKey: "goodsId", // 主表外键字段名
|
||||
foreignKey: "_id", // 副表外键字段名
|
||||
as: "goods",
|
||||
limit: 1,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
if (cartList.total === 0) return {
|
||||
code: -1,
|
||||
msg: "购物车中没有此商品"
|
||||
}
|
||||
|
||||
for (const item of cartList.rows) {
|
||||
const sku = item.goods.sku.find(sku => sku._index === item.skuId)
|
||||
amount += item.num * parseFloat(sku.values)
|
||||
}
|
||||
|
||||
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)
|
||||
saveAmount = amount - offAmount
|
||||
}
|
||||
saveAmount = saveAmount.toFixed(2)
|
||||
}
|
||||
|
||||
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 companyList = []
|
||||
for (const item of cartList.rows) {
|
||||
if (item.goods.companyId) companyList.push(item.goods.companyId)
|
||||
}
|
||||
const orderId = await vk.baseDao.add({
|
||||
dbName: "jjx-order",
|
||||
dataJson: {
|
||||
orderNo: vk.pubfn.createOrderNo("39XU", 20),
|
||||
orderStatus: 0,
|
||||
type: data.type,
|
||||
uid,
|
||||
amount,
|
||||
offAmount,
|
||||
saveAmount,
|
||||
offRate,
|
||||
name,
|
||||
phone,
|
||||
addressRegion,
|
||||
addressDetail,
|
||||
companyList,
|
||||
}
|
||||
})
|
||||
|
||||
const list = []
|
||||
for (const item of cartList.rows) {
|
||||
list.push({
|
||||
orderId: orderId,
|
||||
goodsId: item.goodsId,
|
||||
num: item.num,
|
||||
goodsName: item.goods.name,
|
||||
goodsPrice: parseFloat(item.goods.amount),
|
||||
goodsCover: item.goods.cover,
|
||||
skuId: item.skuId,
|
||||
companyId: item.goods.companyId,
|
||||
})
|
||||
}
|
||||
|
||||
await vk.baseDao.adds({
|
||||
dbName: "jjx-order-goods",
|
||||
dataJson: list
|
||||
})
|
||||
|
||||
await vk.baseDao.del({
|
||||
dbName: "jjx-cart",
|
||||
whereJson: {
|
||||
uid,
|
||||
_id: _.in(data.ids)
|
||||
}
|
||||
})
|
||||
|
||||
res.data = orderId
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/changeOrderStatus 前端调用的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, orderStatus, sendMethod, resultFiles } = data;
|
||||
let res = { code: 0, msg: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
orderStatus,
|
||||
sendMethod,
|
||||
resultFiles,
|
||||
expressTime: dayjs().valueOf(),
|
||||
}
|
||||
});
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 查询当前买家 24 小时内即将自动划付的公证付款申请。
|
||||
*/
|
||||
main: async (event) => {
|
||||
const {data = {}, util} = event;
|
||||
const {uid} = data;
|
||||
const {vk, _} = util;
|
||||
const now = Date.now();
|
||||
const deadline = now + 24 * 60 * 60 * 1000;
|
||||
|
||||
const result = await vk.baseDao.select({
|
||||
dbName: 'jjx-order-pay-list',
|
||||
whereJson: _.and([
|
||||
{
|
||||
buyerUid: uid,
|
||||
isNotaryPay: true,
|
||||
isNotaryApply: true,
|
||||
hasPaid: true,
|
||||
buyerRefuse: false,
|
||||
sellerConfirm: false,
|
||||
},
|
||||
{autoTransferTimestamp: _.gte(now)},
|
||||
{autoTransferTimestamp: _.lte(deadline)},
|
||||
]),
|
||||
sortArr: [{name: 'autoTransferTimestamp', type: 'asc'}],
|
||||
pageIndex: 1,
|
||||
pageSize: 20,
|
||||
});
|
||||
|
||||
return {
|
||||
code: 0,
|
||||
msg: '',
|
||||
data: {
|
||||
count: (result.rows || []).length,
|
||||
rows: (result.rows || []).map(item => ({
|
||||
orderId: item.orderId,
|
||||
type: item.type,
|
||||
amount: item.amount,
|
||||
autoTransferAt: item.autoTransferAt,
|
||||
autoTransferTimestamp: item.autoTransferTimestamp,
|
||||
})),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/getInfo 前端调用的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, resetOrderNo} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: "jjx-order",
|
||||
getOne: true,
|
||||
getMain: true,
|
||||
whereJson: {
|
||||
_id: data.id
|
||||
},
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "jjx-order-goods",
|
||||
localKey: "_id",
|
||||
foreignKey: "orderId",
|
||||
as: "goods",
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
if (vk.pubfn.isNotNull(resetOrderNo) && resetOrderNo && res) {
|
||||
const orderNo = vk.pubfn.createOrderNo("39XU", 24)
|
||||
// const orderNo = vk.pubfn.createOrderNo("3199", 24)
|
||||
await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-order",
|
||||
whereJson: {
|
||||
_id: data.id
|
||||
},
|
||||
dataJson: {
|
||||
orderNo
|
||||
}
|
||||
});
|
||||
res.orderNo = orderNo
|
||||
}
|
||||
|
||||
if (res.type === 0) {
|
||||
for (const goodsItem of res.goods) {
|
||||
const goods = await vk.baseDao.findById({
|
||||
dbName: "jjx-goods",
|
||||
id: goodsItem.goodsId
|
||||
});
|
||||
goodsItem.sku = goods.sku.find(item => item._index === goodsItem.skuId)
|
||||
if (goods.companyId) {
|
||||
goodsItem.company = await vk.baseDao.findById({
|
||||
dbName: "uni-id-users",
|
||||
id: goods.companyId
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/getList 前端调用的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, type, pageIndex, pageSize, isSeller, signMethod, orderStatus, keyword} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const whereJsonArr = []
|
||||
if (!vk.pubfn.isNull(type)) {
|
||||
if (Array.isArray(type)) whereJsonArr.push({type: _.in(type)})
|
||||
else whereJsonArr.push({type})
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNull(isSeller) || parseInt(isSeller) === 0) whereJsonArr.push({uid})
|
||||
else {
|
||||
whereJsonArr.push(_.or([
|
||||
{
|
||||
sellerUid: uid
|
||||
},
|
||||
{
|
||||
companyList: _.in([uid])
|
||||
}
|
||||
]))
|
||||
}
|
||||
|
||||
if (vk.pubfn.isNotNull(signMethod)) whereJsonArr.push({signMethod})
|
||||
else whereJsonArr.push({signMethod: _.neq(1)})
|
||||
|
||||
if (vk.pubfn.isNotNull(orderStatus)) whereJsonArr.push({orderStatus})
|
||||
else whereJsonArr.push({orderStatus: _.neq(-1)})
|
||||
|
||||
if (vk.pubfn.isNotNull(keyword)) whereJsonArr.push({orderNo: new RegExp(keyword)})
|
||||
|
||||
let whereJson = null
|
||||
if (whereJsonArr.length > 0) whereJson = _.and(whereJsonArr)
|
||||
console.log('whereJsonArr', whereJsonArr)
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: "jjx-order",
|
||||
getCount: true,
|
||||
whereJson: whereJson,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
sortArr: [{"name": "_add_time", "type": "desc"}],
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "jjx-order-goods",
|
||||
localKey: "_id",
|
||||
foreignKey: "orderId",
|
||||
as: "goods",
|
||||
limit: 500,
|
||||
foreignDB: [
|
||||
{
|
||||
dbName: "jjx-goods",
|
||||
localKey: "goodsId",
|
||||
foreignKey: "_id",
|
||||
as: "goods",
|
||||
limit: 1
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "uid",
|
||||
foreignKey: "_id",
|
||||
as: "buyer",
|
||||
limit: 1
|
||||
},
|
||||
{
|
||||
dbName: "uni-id-users",
|
||||
localKey: "sellerUid",
|
||||
foreignKey: "_id",
|
||||
as: "seller",
|
||||
limit: 1
|
||||
},
|
||||
{
|
||||
dbName: "jjx-order-pay-list",
|
||||
localKey: "_id",
|
||||
foreignKey: "orderId",
|
||||
as: "payList",
|
||||
limit: 1,
|
||||
sortArr: [{"name": "_add_time", "type": "desc"}],
|
||||
},
|
||||
{
|
||||
dbName: "jjx-contract",
|
||||
localKey: "contractId",
|
||||
foreignKey: "_id",
|
||||
as: "contract",
|
||||
limit: 1,
|
||||
},
|
||||
|
||||
],
|
||||
})
|
||||
|
||||
for (let i in res.rows) {
|
||||
res.rows[i].isSeller = res.rows[i].uid !== uid
|
||||
res.rows[i].isBuyer = res.rows[i].uid === uid
|
||||
if (res.rows[i].type > 3 && res.rows[i].orderStatus > 0) {
|
||||
res.rows[i].hasPay = !!await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson: {
|
||||
orderId: res.rows[i]._id,
|
||||
buyerRefuse: false,
|
||||
hasPaid: true
|
||||
}
|
||||
})
|
||||
}
|
||||
if (res.rows[i].contract) {
|
||||
let sheet = null
|
||||
if (res.rows[i].contract.type === 'enquiry') {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-enquiry-sheet',
|
||||
id: res.rows[i].contract.sheetId
|
||||
})
|
||||
} else if (res.rows[i].contract.type === 'process') {
|
||||
sheet = await vk.baseDao.findById({
|
||||
dbName: 'jjx-process-sheet',
|
||||
id: res.rows[i].contract.sheetId
|
||||
})
|
||||
}
|
||||
res.rows[i].sheet = sheet
|
||||
}
|
||||
if (res.rows[i].type === 3) res.rows[i].upgradeExpiredAt = dayjs(userInfo.upgradeExpiredAt).format('YYYY-MM-DD HH:mm:ss')
|
||||
if (res.rows[i].type === 8) res.rows[i].spot = await vk.baseDao.findById({
|
||||
dbName: "jjx-spot-goods",
|
||||
id: res.rows[i].goods[0].pk
|
||||
})
|
||||
if (res.rows[i].type === 0) {
|
||||
for (const goodsItem of res.rows[i].goods) {
|
||||
const goods = await vk.baseDao.findById({
|
||||
dbName: "jjx-goods",
|
||||
id: goodsItem.goodsId
|
||||
});
|
||||
if (goods && goods.sku && goods.sku.length > 0) goodsItem.sku = goods.sku.find(item => item._index === goodsItem.skuId)
|
||||
}
|
||||
}
|
||||
if (res.rows[i].type === 1) {
|
||||
res.rows[i].selfProduct = await vk.baseDao.findByWhereJson({
|
||||
dbName: 'jjx-order-selfProduct',
|
||||
whereJson: {
|
||||
orderId: res.rows[i]._id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (res.rows[i].type === 12 && res.rows[i].goods[0].goodsId) {
|
||||
res.rows[i].certificate = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-certificate",
|
||||
whereJson: {
|
||||
contractId: res.rows[i].goods[0].goodsId
|
||||
}
|
||||
});
|
||||
console.log('res.rows[i].certificate', res.rows[i].certificate)
|
||||
}
|
||||
if (res.rows[i].type === 7) {
|
||||
for (let j in res.rows[i].goods) {
|
||||
if (res.rows[i].goods[j].isSingleQuote) {
|
||||
switch (res.rows[i].goods[j].type) {
|
||||
case 'enquiry' : {
|
||||
res.rows[i].goods[j].sheet = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-enquiry-sheet",
|
||||
whereJson: {
|
||||
_id: res.rows[i].goods[j].sheetId
|
||||
}
|
||||
})
|
||||
}
|
||||
break;
|
||||
case 'old' : {
|
||||
res.rows[i].goods[j].sheet = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-old",
|
||||
whereJson: {
|
||||
_id: res.rows[i].goods[j].sheetId
|
||||
}
|
||||
})
|
||||
}
|
||||
break;
|
||||
case 'process' : {
|
||||
res.rows[i].goods[j].sheet = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-process-sheet",
|
||||
whereJson: {
|
||||
_id: res.rows[i].goods[j].sheetId
|
||||
}
|
||||
})
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
'use strict';
|
||||
const notaryPay = require('./util/notaryPay');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 获取或创建公证全额支付单
|
||||
* @url client/order/kh/getOrCreateNotaryFullPay 前端调用的url参数地址
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, util} = event;
|
||||
let {vk} = util;
|
||||
let res = {code: 0, msg: ''};
|
||||
|
||||
const order = await vk.baseDao.findById({
|
||||
dbName: 'jjx-order',
|
||||
id: data.id
|
||||
});
|
||||
if (!order) return {code: -1, msg: '订单不存在'};
|
||||
if (!(Number(order.type) > 3 && Number(order.signMethod) === 0)) {
|
||||
return {code: -1, msg: '当前订单不是公证支付订单'};
|
||||
}
|
||||
if (Number(order.notaryPayStatus) === 1) {
|
||||
return {code: -1, msg: '订单已完成公证支付'};
|
||||
}
|
||||
|
||||
let payRecord = await notaryPay.findFullPayRecord(vk, order._id);
|
||||
if (payRecord && payRecord.hasPaid) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: 'jjx-order',
|
||||
id: order._id,
|
||||
dataJson: {
|
||||
notaryPayStatus: 1,
|
||||
notaryPayListId: payRecord._id,
|
||||
notaryPayOrderNo: payRecord.orderNo,
|
||||
payStatus: 2
|
||||
}
|
||||
});
|
||||
return {code: -1, msg: '订单已完成公证支付'};
|
||||
}
|
||||
if (!payRecord) {
|
||||
const now = vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
const dataJson = {
|
||||
orderId: order._id,
|
||||
amount: order.offAmount || order.amount,
|
||||
type: '公证支付',
|
||||
remark: '买家全额支付到金久信公证平台',
|
||||
buyerRemark: '',
|
||||
photos: [],
|
||||
payerUid: null,
|
||||
hasPaid: false,
|
||||
paidVoucher: '',
|
||||
paidAt: '',
|
||||
confirmAt: '',
|
||||
buyerUid: order.uid,
|
||||
sellerUid: order.sellerUid,
|
||||
status: 0,
|
||||
buyerRefuse: false,
|
||||
refuseReason: null,
|
||||
buyerPhotos: [],
|
||||
expressPhoto: [],
|
||||
isExpress: false,
|
||||
expressName: null,
|
||||
expressNo: null,
|
||||
ext: [],
|
||||
isNotaryPay: true,
|
||||
isNotaryFullPay: true,
|
||||
transferStatus: 0,
|
||||
sellerConfirm: false,
|
||||
orderNo: vk.pubfn.createOrderNo("39XU", 24),
|
||||
applyAt: now,
|
||||
applyTimestamp: Date.now()
|
||||
};
|
||||
const id = await vk.baseDao.add({
|
||||
dbName: 'jjx-order-pay-list',
|
||||
dataJson
|
||||
});
|
||||
payRecord = {
|
||||
...dataJson,
|
||||
_id: id
|
||||
};
|
||||
}
|
||||
|
||||
res.data = payRecord;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
const notaryPay = require('./util/notaryPay');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/makePayList 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
// orderStatus 0待支付 1已支付待发货 2已发货待收货 3已收货待完成 4已完成
|
||||
const order = await vk.baseDao.findById({
|
||||
dbName: "jjx-order",
|
||||
id: data.payInfo.orderId
|
||||
})
|
||||
const isNotaryPay = !!order && Number(order.type) > 3 && Number(order.signMethod) === 0
|
||||
let fullPayRecord = null
|
||||
if (isNotaryPay) {
|
||||
if (Number(order.notaryPayStatus) !== 1) return {code: -1, msg: '买家尚未完成公证全额支付,暂不能申请付款'}
|
||||
fullPayRecord = await notaryPay.findFullPayRecord(vk, order._id)
|
||||
if (!fullPayRecord || !fullPayRecord.hasPaid || !fullPayRecord.orderNo) {
|
||||
return {code: -1, msg: '未找到已支付的公证全额支付单'}
|
||||
}
|
||||
const applyList = await vk.baseDao.select({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson: {
|
||||
orderId: order._id,
|
||||
isNotaryApply: true,
|
||||
buyerRefuse: false
|
||||
},
|
||||
pageIndex: 1,
|
||||
pageSize: -1
|
||||
})
|
||||
const appliedAmount = (applyList.rows || []).reduce((sum, item) => sum + Number(item.amount || 0), 0)
|
||||
const nextAmount = Number(data.payInfo.amount || 0)
|
||||
const fullAmount = Number(fullPayRecord.amount || 0)
|
||||
if (!Number.isFinite(nextAmount) || nextAmount <= 0) return {code: -1, msg: '申请金额不正确'}
|
||||
if (Number((appliedAmount + nextAmount).toFixed(2)) > fullAmount) {
|
||||
return {code: -1, msg: '累计申请金额不能超过买家公证支付总额'}
|
||||
}
|
||||
}
|
||||
const payApplyFields = await notaryPay.buildPayApplyFields(vk)
|
||||
const dataJson = {
|
||||
...data.payInfo,
|
||||
...payApplyFields,
|
||||
isNotaryPay,
|
||||
isNotaryApply: isNotaryPay,
|
||||
sourcePayListId: isNotaryPay ? fullPayRecord._id : '',
|
||||
sourcePayOrderNo: isNotaryPay ? fullPayRecord.orderNo : '',
|
||||
fullPayListId: isNotaryPay ? fullPayRecord._id : '',
|
||||
fullPayOrderNo: isNotaryPay ? fullPayRecord.orderNo : '',
|
||||
fullPayAmount: isNotaryPay ? fullPayRecord.amount : '',
|
||||
fullPayAt: isNotaryPay ? (fullPayRecord.paidAt || '') : '',
|
||||
hasPaid: isNotaryPay ? true : data.payInfo.hasPaid,
|
||||
paidAt: isNotaryPay ? (fullPayRecord.paidAt || '') : data.payInfo.paidAt,
|
||||
paidVoucher: isNotaryPay ? '' : data.payInfo.paidVoucher,
|
||||
buyerRemark: isNotaryPay ? '公证付款申请,待买家确认划付' : data.payInfo.buyerRemark
|
||||
}
|
||||
dataJson.orderNo = vk.pubfn.createOrderNo("39XU", 24)
|
||||
const payListId = await vk.baseDao.add({
|
||||
dbName: "jjx-order-pay-list",
|
||||
dataJson
|
||||
});
|
||||
dataJson._id = payListId
|
||||
|
||||
let orderStatus = data.payInfo.isExpress ? 2 : 1;
|
||||
|
||||
const hasExpress = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson:{
|
||||
orderId: data.payInfo.orderId,
|
||||
isExpress: true,
|
||||
buyerRefuse: false
|
||||
}
|
||||
});
|
||||
|
||||
if (hasExpress) orderStatus = 2
|
||||
|
||||
// payStatus(弃用) 0待创建 1待支付预付款 2已支付预付款,支付进度款中 3进度款已支付,尾款支付中 4完成
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: data.payInfo.orderId,
|
||||
dataJson: {
|
||||
orderStatus,
|
||||
payStatus: isNotaryPay ? 2 : 1
|
||||
}
|
||||
});
|
||||
|
||||
if (isNotaryPay) {
|
||||
await notaryPay.notifyPayApply({
|
||||
vk,
|
||||
payRecord: dataJson,
|
||||
order
|
||||
})
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/orderPayList 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.select({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson: {
|
||||
orderId: data.id
|
||||
},
|
||||
sortArr: [{"name": "_add_time", "type": "asc"}],
|
||||
pageIndex: 1,
|
||||
pageSize: -1
|
||||
})
|
||||
|
||||
for (const item of res.rows) {
|
||||
item.isSeller = item.sellerUid === uid
|
||||
item.isBuyer = item.buyerUid === uid
|
||||
item.seller = await vk.baseDao.findById({
|
||||
dbName: "uni-id-users",
|
||||
id: item.sellerUid
|
||||
});
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
'use strict';
|
||||
const notaryPay = require('./util/notaryPay');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/paidConfirm 前端调用的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 payRecord = await vk.baseDao.findById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: data.id
|
||||
})
|
||||
if (!payRecord) return {code: -1, msg: '支付单不存在'}
|
||||
|
||||
if (payRecord.isNotaryPay || payRecord.isNotaryApply) {
|
||||
res = await notaryPay.executeTransfer({
|
||||
vk,
|
||||
payRecord,
|
||||
operator: 'buyer'
|
||||
})
|
||||
if (res.code !== 0) return res
|
||||
return res
|
||||
}
|
||||
|
||||
const confirmAt = vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: payRecord._id,
|
||||
dataJson: {
|
||||
sellerConfirm: true,
|
||||
confirmAt
|
||||
}
|
||||
})
|
||||
|
||||
if (['尾款', '货到付款', '全款'].includes(payRecord.type)) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: payRecord.orderId,
|
||||
dataJson: {
|
||||
orderStatus: 4
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 添加余额、记录
|
||||
// const seller = await vk.baseDao.findById({
|
||||
// dbName: 'uni-id-users',
|
||||
// id: payRecord.sellerUid,
|
||||
// })
|
||||
// if (seller) {
|
||||
// if (!seller.balance) {
|
||||
// await vk.baseDao.updateById({
|
||||
// dbName: 'uni-id-users',
|
||||
// id: seller._id,
|
||||
// dataJson: {
|
||||
// balance: payRecord.price,
|
||||
// }
|
||||
// })
|
||||
// } else {
|
||||
// await vk.baseDao.updateById({
|
||||
// dbName: 'uni-id-users',
|
||||
// id: seller._id,
|
||||
// dataJson: {
|
||||
// balance: _.inc(payRecord.price),
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// await vk.baseDao.add({
|
||||
// dbName: "jjx-user-balance-log",
|
||||
// dataJson: {
|
||||
// uid: seller._id,
|
||||
// orderId: payRecord.orderId,
|
||||
// type: payRecord.type,
|
||||
// price: payRecord.price,
|
||||
// desc: "订单支付成功",
|
||||
// createTime: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss"),
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// const order = await vk.baseDao.findById({
|
||||
// dbName: "jjx-order",
|
||||
// id: payRecord.orderId,
|
||||
// })
|
||||
//
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/payListChangeStatus 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
status: data.status
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
const OpenSdk = require('../../../../util/base').default;
|
||||
const notaryPay = require('./util/notaryPay');
|
||||
|
||||
const sdk = new OpenSdk({
|
||||
appId: '8a81c1db8fc5238d01910b9e312d0692',
|
||||
appKey: 'a15ceac60f5b464eb758c4fe7800ee9f'
|
||||
});
|
||||
|
||||
const REFUND_MID = '898450100002303';
|
||||
const REFUND_TID = 'G5SBN2XJ';
|
||||
const REFUND_INST_MID = 'WGDEFAULT';
|
||||
const REFUND_SUB_MID = '898450100004218';
|
||||
const REFUND_SUB_MID_MAIN = '898450100004711';
|
||||
const PLATFORM_RATE_DICT_ID = 'd84694f2696818f20c28f55f36764783';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/payRefuse 前端调用的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, refuseReason} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const payRecord = await vk.baseDao.updateAndReturn({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson: {
|
||||
_id: data.id,
|
||||
},
|
||||
dataJson: {
|
||||
buyerRefuse: true,
|
||||
refuseReason,
|
||||
transferStatus: 2,
|
||||
transferRefuseAt: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
|
||||
}
|
||||
})
|
||||
|
||||
const order = await vk.baseDao.findById({
|
||||
dbName: 'jjx-order',
|
||||
id: payRecord.orderId
|
||||
})
|
||||
|
||||
const isNotaryPay = !!order && Number(order.type) > 3 && Number(order.signMethod) === 0;
|
||||
|
||||
if (isNotaryPay && payRecord.isNotaryApply) {
|
||||
res.refund = {
|
||||
skipped: true,
|
||||
reason: '公证付款申请驳回不触发退款'
|
||||
};
|
||||
await notaryPay.addMessage(vk, {
|
||||
uid: payRecord.sellerUid,
|
||||
title: '付款单被驳回',
|
||||
content: `订单${order && order.orderNo ? order.orderNo : payRecord.orderId}的${payRecord.type || ''}付款单已被买家驳回,原因:${refuseReason || '未填写'}`,
|
||||
type: 'order-pay-refuse',
|
||||
pk: payRecord.orderId
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
if (['预付款', '货到付款'].includes(payRecord.type) && !isNotaryPay) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: payRecord.orderId,
|
||||
dataJson: {
|
||||
payStatus: 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const hasPay = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson: {
|
||||
orderId: payRecord.orderId,
|
||||
buyerRefuse: false,
|
||||
sellerConfirm: true
|
||||
}
|
||||
})
|
||||
const hasExpress = await vk.baseDao.findByWhereJson({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson: {
|
||||
orderId: payRecord.orderId,
|
||||
isExpress: true,
|
||||
hasPaid: true,
|
||||
}
|
||||
})
|
||||
|
||||
// orderStatus 0待支付 1已支付待发货 2已发货待收货 3已收货待完成 4已完成
|
||||
// 发货单已支付的不能再次发货
|
||||
let orderStatus = 0
|
||||
// 未发货且没有支付单
|
||||
if (!hasExpress && !hasPay) orderStatus = 0
|
||||
// 未发货且有支付单
|
||||
if (!hasExpress && !!hasPay) orderStatus = 1
|
||||
// 已发货且已确认支付
|
||||
if (!!hasExpress) orderStatus = 2
|
||||
|
||||
res.hasExpress = hasExpress
|
||||
res.hasPay = hasPay
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: payRecord.orderId,
|
||||
dataJson: {
|
||||
orderStatus
|
||||
}
|
||||
});
|
||||
|
||||
const hasManualVoucher = Array.isArray(payRecord.paidVoucher) ? payRecord.paidVoucher.length > 0 : !!payRecord.paidVoucher;
|
||||
const refundAmount = Math.round(Number(payRecord.amount || 0) * 100);
|
||||
const shouldCallRefund = !!payRecord.hasPaid && !hasManualVoucher && !!payRecord.orderNo && refundAmount > 0 && !isNotaryPay;
|
||||
|
||||
if (shouldCallRefund) {
|
||||
const refundOrderId = vk.pubfn.createOrderNo("39XU", 24);
|
||||
const refundData = {
|
||||
queryUrl: 'https://api-mop.chinaums.com/v1/netpay/refund',
|
||||
timestamp: dayjs().format('YYYYMMDDHHmmss'),
|
||||
nonce: `refund_${Date.now()}`,
|
||||
content: {
|
||||
requestTimestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
merOrderId: payRecord.orderNo,
|
||||
instMid: REFUND_INST_MID,
|
||||
mid: REFUND_MID,
|
||||
tid: REFUND_TID,
|
||||
refundAmount,
|
||||
refundOrderId,
|
||||
refundDesc: refuseReason || '买家驳回支付单退款'
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const platformRateData = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: PLATFORM_RATE_DICT_ID
|
||||
});
|
||||
const platformRate = Number(platformRateData && platformRateData.content);
|
||||
if (!Number.isNaN(platformRate) && platformRate >= 0 && platformRate <= 100) {
|
||||
const subAmount = parseInt(refundAmount * ((100 - platformRate) / 100), 10);
|
||||
const subAmountMain = refundAmount - subAmount;
|
||||
refundData.content.platformAmount = 0;
|
||||
refundData.content.subOrders = [
|
||||
{
|
||||
mid: REFUND_SUB_MID,
|
||||
totalAmount: String(subAmount),
|
||||
},
|
||||
{
|
||||
mid: REFUND_SUB_MID_MAIN,
|
||||
totalAmount: String(subAmountMain),
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
const refundRawResult = await sdk.exec(refundData);
|
||||
const refundResult = typeof refundRawResult === "string" ? JSON.parse(refundRawResult) : refundRawResult;
|
||||
const refundSuccess = refundResult && refundResult.errCode === 'SUCCESS';
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: payRecord._id,
|
||||
dataJson: {
|
||||
refundApplyAt: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss"),
|
||||
refundApplyPayload: refundData.content,
|
||||
refundApplyResult: refundResult,
|
||||
refundApplySuccess: refundSuccess
|
||||
}
|
||||
});
|
||||
|
||||
res.refund = {
|
||||
success: refundSuccess,
|
||||
result: refundResult
|
||||
};
|
||||
} catch (err) {
|
||||
const errMsg = err && err.message ? err.message : JSON.stringify(err);
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: payRecord._id,
|
||||
dataJson: {
|
||||
refundApplyAt: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss"),
|
||||
refundApplyPayload: refundData.content,
|
||||
refundApplySuccess: false,
|
||||
refundApplyError: errMsg
|
||||
}
|
||||
});
|
||||
|
||||
res.refund = {
|
||||
success: false,
|
||||
error: errMsg
|
||||
};
|
||||
}
|
||||
} else {
|
||||
res.refund = {
|
||||
skipped: true,
|
||||
reason: '当前支付单未命中线上退款条件'
|
||||
};
|
||||
}
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/refund 前端调用的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, refundReason, refundPhotos} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const order = await vk.baseDao.findById({
|
||||
dbName: "jjx-order",
|
||||
id: data.id
|
||||
});
|
||||
if ([4, 5, 6].includes(order.type)) {
|
||||
const payList = await vk.baseDao.select({
|
||||
dbName: "jjx-order-pay-list",
|
||||
whereJson: {
|
||||
orderId: data.id,
|
||||
buyerRefuse: false
|
||||
}
|
||||
});
|
||||
let paidConfirmNum = 0
|
||||
for (let i = 0; i < payList.rows.length; i++) {
|
||||
if ( payList.rows[i].sellerConfirm) paidConfirmNum++
|
||||
}
|
||||
if (paidConfirmNum === payList.rows.length) {
|
||||
res.code = 1;
|
||||
res.msg = "订单已确认收款,无法申请退款";
|
||||
} else {
|
||||
res.code = 0;
|
||||
res.msg = "平台将在2个工作日内审核,请您耐心等待";
|
||||
}
|
||||
}
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
refundReason,
|
||||
refundPhotos,
|
||||
orderStatus: 5,
|
||||
refundRequestAt: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
|
||||
}
|
||||
})
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
'use strict';
|
||||
const dayjs = require("dayjs");
|
||||
const OpenSdk = require('../../../../util/base').default;
|
||||
|
||||
const sdk = new OpenSdk({
|
||||
appId: '8a81c1db8fc5238d01910b9e312d0692',
|
||||
appKey: 'a15ceac60f5b464eb758c4fe7800ee9f'
|
||||
});
|
||||
|
||||
const REFUND_MID = '898450100002303';
|
||||
const REFUND_TID = 'G5SBN2XJ';
|
||||
const REFUND_INST_MID = 'WGDEFAULT';
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 退款查询
|
||||
* @url client/order/kh/refundQuery 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, util} = event;
|
||||
let {vk} = util;
|
||||
let res = {code: 0, msg: ""};
|
||||
|
||||
const payRecord = await vk.baseDao.findById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: data.id
|
||||
});
|
||||
|
||||
if (!payRecord) {
|
||||
return {
|
||||
code: -1,
|
||||
msg: "支付单不存在"
|
||||
};
|
||||
}
|
||||
|
||||
const refundOrderId = data.refundOrderId
|
||||
|| (payRecord.refundApplyPayload && payRecord.refundApplyPayload.refundOrderId)
|
||||
|| (payRecord.refundApplyResult && payRecord.refundApplyResult.refundOrderId);
|
||||
|
||||
if (!refundOrderId) {
|
||||
return {
|
||||
code: -1,
|
||||
msg: "未找到退款单号,请先发起退款"
|
||||
};
|
||||
}
|
||||
|
||||
const queryData = {
|
||||
queryUrl: 'https://api-mop.chinaums.com/v1/netpay/refund-query',
|
||||
timestamp: dayjs().format('YYYYMMDDHHmmss'),
|
||||
nonce: `refund_query_${Date.now()}`,
|
||||
content: {
|
||||
requestTimestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
merOrderId: refundOrderId,
|
||||
instMid: REFUND_INST_MID,
|
||||
mid: REFUND_MID,
|
||||
tid: REFUND_TID
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const queryRawResult = await sdk.exec(queryData);
|
||||
const queryResult = typeof queryRawResult === "string" ? JSON.parse(queryRawResult) : queryRawResult;
|
||||
const querySuccess = queryResult && queryResult.errCode === 'SUCCESS';
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: payRecord._id,
|
||||
dataJson: {
|
||||
refundQueryAt: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss"),
|
||||
refundQueryPayload: queryData.content,
|
||||
refundQueryResult: queryResult,
|
||||
refundQuerySuccess: querySuccess
|
||||
}
|
||||
});
|
||||
|
||||
res.data = queryResult;
|
||||
res.querySuccess = querySuccess;
|
||||
res.msg = querySuccess ? "查询成功" : (queryResult.errMsg || "查询失败");
|
||||
return res;
|
||||
} catch (err) {
|
||||
const errMsg = err && err.message ? err.message : JSON.stringify(err);
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: payRecord._id,
|
||||
dataJson: {
|
||||
refundQueryAt: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss"),
|
||||
refundQueryPayload: queryData.content,
|
||||
refundQuerySuccess: false,
|
||||
refundQueryError: errMsg
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
code: -1,
|
||||
msg: errMsg
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/resetOrderNo 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
orderNo: vk.pubfn.createOrderNo("39XU", 20),
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/setExpress 前端调用的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, id, expressName, expressNo, remark, expressPhoto,} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id,
|
||||
dataJson: {
|
||||
expressName,
|
||||
expressNo,
|
||||
remark,
|
||||
expressPhoto,
|
||||
orderStatus: 2,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/makePayList 前端调用的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: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
// status 0待支付 1已支付待发货 2已发货待收货 3已收货待完成 4已完成
|
||||
|
||||
await vk.baseDao.adds({
|
||||
dbName: "jjx-order-pay-list",
|
||||
dataJson: data.payList
|
||||
});
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: data.payList[0].orderId,
|
||||
dataJson: {
|
||||
orderStatus: 1
|
||||
}
|
||||
});
|
||||
|
||||
console.log('orderId', data.payList[0].orderId)
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/updateAddress 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order",
|
||||
id: data.id,
|
||||
dataJson: {
|
||||
address: data.address,
|
||||
addressDetail: data.addressDetail,
|
||||
phone: data.phone,
|
||||
name: data.name,
|
||||
remark: data.remark,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/order/kh/uploadPayVoucher 前端调用的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, buyerPhotos, paidVoucher, buyerRemark} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
const payRecord = await vk.baseDao.findById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: data._id
|
||||
})
|
||||
if (payRecord && payRecord.isNotaryApply) {
|
||||
return {code: -1, msg: '公证付款申请无需买家再次支付'}
|
||||
}
|
||||
|
||||
await vk.baseDao.updateById({
|
||||
dbName: "jjx-order-pay-list",
|
||||
id: data._id,
|
||||
dataJson: {
|
||||
hasPaid: true,
|
||||
paidVoucher,
|
||||
paidAt: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss"),
|
||||
buyerPhotos,
|
||||
buyerRemark
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
'use strict';
|
||||
|
||||
const AUTO_TRANSFER_DAYS_DICT_ID = '238cef266a67e89a006025974a41dbd7';
|
||||
const DEFAULT_AUTO_TRANSFER_DAYS = 3;
|
||||
|
||||
function nowText(vk) {
|
||||
return vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
}
|
||||
|
||||
async function getAutoTransferDays(vk) {
|
||||
try {
|
||||
const config = await vk.baseDao.findById({
|
||||
dbName: 'jjx-dict',
|
||||
id: AUTO_TRANSFER_DAYS_DICT_ID
|
||||
});
|
||||
const days = parseInt(config && config.content, 10);
|
||||
if (Number.isFinite(days) && days > 0) return days;
|
||||
} catch (err) {
|
||||
console.error('getAutoTransferDays error:', err);
|
||||
}
|
||||
return DEFAULT_AUTO_TRANSFER_DAYS;
|
||||
}
|
||||
|
||||
async function buildPayApplyFields(vk) {
|
||||
const applyTimestamp = Date.now();
|
||||
const autoTransferDays = await getAutoTransferDays(vk);
|
||||
const autoTransferTimestamp = applyTimestamp + autoTransferDays * 24 * 60 * 60 * 1000;
|
||||
return {
|
||||
transferStatus: 0,
|
||||
applyAt: nowText(vk),
|
||||
applyTimestamp,
|
||||
autoTransferDays,
|
||||
autoTransferAt: vk.pubfn.timeFormat(new Date(autoTransferTimestamp), "yyyy-MM-dd hh:mm:ss"),
|
||||
autoTransferTimestamp
|
||||
};
|
||||
}
|
||||
|
||||
async function findFullPayRecord(vk, orderId) {
|
||||
const res = await vk.baseDao.select({
|
||||
dbName: 'jjx-order-pay-list',
|
||||
whereJson: {
|
||||
orderId,
|
||||
isNotaryFullPay: true,
|
||||
buyerRefuse: false
|
||||
},
|
||||
sortArr: [{name: '_add_time', type: 'desc'}],
|
||||
pageIndex: 1,
|
||||
pageSize: 1
|
||||
});
|
||||
return res && res.rows && res.rows[0] ? res.rows[0] : null;
|
||||
}
|
||||
|
||||
async function resolveTransferSourcePayRecord(vk, payRecord) {
|
||||
if (!payRecord) return null;
|
||||
if (payRecord.isNotaryFullPay) return payRecord;
|
||||
if (payRecord.fullPayListId) {
|
||||
const fullPayRecord = await vk.baseDao.findById({
|
||||
dbName: 'jjx-order-pay-list',
|
||||
id: payRecord.fullPayListId
|
||||
});
|
||||
if (fullPayRecord) return fullPayRecord;
|
||||
}
|
||||
if (payRecord.sourcePayListId) {
|
||||
const fullPayRecord = await vk.baseDao.findById({
|
||||
dbName: 'jjx-order-pay-list',
|
||||
id: payRecord.sourcePayListId
|
||||
});
|
||||
if (fullPayRecord) return fullPayRecord;
|
||||
}
|
||||
if (payRecord.orderId) {
|
||||
return await findFullPayRecord(vk, payRecord.orderId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取卖家用于银联划付的企业用户号。
|
||||
* 企业用户号属于卖家用户资料,不能使用客户端传入值或固定商户号。
|
||||
*/
|
||||
async function resolveSellerMerNo(vk, payRecord) {
|
||||
const sellerUid = payRecord && payRecord.sellerUid;
|
||||
if (!sellerUid) return '';
|
||||
try {
|
||||
const seller = await vk.baseDao.findById({
|
||||
dbName: 'uni-id-users',
|
||||
id: sellerUid
|
||||
});
|
||||
return String((seller && seller.merNo) || '').trim();
|
||||
} catch (err) {
|
||||
console.error('resolveSellerMerNo error:', err);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
async function addMessage(vk, dataJson) {
|
||||
if (!dataJson || !dataJson.uid) return;
|
||||
await vk.baseDao.add({
|
||||
dbName: 'jjx-message',
|
||||
dataJson: {
|
||||
...dataJson,
|
||||
hasRead: false
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function notifyPaySuccess({ vk, payRecord, order }) {
|
||||
await addMessage(vk, {
|
||||
uid: payRecord.sellerUid,
|
||||
title: '买家已完成公证支付',
|
||||
content: `订单${order && order.orderNo ? order.orderNo : payRecord.orderId}买家已支付货款到金久信公证平台,请按约定发起付款单申请划付。`,
|
||||
type: 'order-pay',
|
||||
pk: payRecord.orderId
|
||||
});
|
||||
}
|
||||
|
||||
async function notifyPayApply({ vk, payRecord, order }) {
|
||||
await addMessage(vk, {
|
||||
uid: payRecord.buyerUid,
|
||||
title: '卖家已发起付款单',
|
||||
content: `订单${order && order.orderNo ? order.orderNo : payRecord.orderId}卖家已发起${payRecord.type || ''}付款单,金额${payRecord.amount}元,请及时通过申请或驳回。`,
|
||||
type: 'order-pay',
|
||||
pk: payRecord.orderId
|
||||
});
|
||||
}
|
||||
|
||||
async function executeTransfer({ vk, payRecord, operator = 'buyer' }) {
|
||||
if (!payRecord) return { code: -1, msg: '支付单不存在' };
|
||||
if (!payRecord.isNotaryApply) return { code: -1, msg: '当前支付单不是公证划付申请单' };
|
||||
if (payRecord.buyerRefuse) return { code: -1, msg: '支付单已被买家驳回' };
|
||||
if (!payRecord.hasPaid) return { code: -1, msg: '公证托管资金尚未支付' };
|
||||
if (payRecord.sellerConfirm) return { code: 0, msg: '已划付', data: payRecord.transferResult || null };
|
||||
|
||||
const fullPayRecord = await resolveTransferSourcePayRecord(vk, payRecord);
|
||||
const sourcePayOrderNo = fullPayRecord && fullPayRecord.orderNo ? fullPayRecord.orderNo : (payRecord.fullPayOrderNo || payRecord.sourcePayOrderNo || '');
|
||||
const sourcePayListId = fullPayRecord && fullPayRecord._id ? fullPayRecord._id : (payRecord.fullPayListId || payRecord.sourcePayListId || '');
|
||||
const sourcePayAmount = fullPayRecord && Number(fullPayRecord.amount || 0) > 0 ? Number(fullPayRecord.amount) : Number(payRecord.fullPayAmount || 0);
|
||||
if (!sourcePayOrderNo) return { code: -1, msg: '未找到全额支付单单号,无法划付' };
|
||||
if (fullPayRecord && !fullPayRecord.hasPaid) return { code: -1, msg: '全额支付单尚未支付,无法划付' };
|
||||
|
||||
// const buyer = await vk.baseDao.findById({
|
||||
// dbName: 'uni-id-users',
|
||||
// id: payRecord.buyerUid,
|
||||
// });
|
||||
// if (!buyer || !buyer.mid) {
|
||||
// return { code: -1, msg: '买家商户号不存在' };
|
||||
// }
|
||||
|
||||
const payAmt = Number(payRecord.amount || payRecord.price || 0);
|
||||
if (!Number.isFinite(payAmt) || payAmt <= 0) {
|
||||
return { code: -1, msg: '付款单金额不正确' };
|
||||
}
|
||||
const accNo = await resolveSellerMerNo(vk, payRecord);
|
||||
if (!accNo) {
|
||||
return { code: -1, msg: '卖家未配置企业用户号,无法划付' };
|
||||
}
|
||||
const transferResult = await vk.request({
|
||||
url: 'http://jjx-union-pay.gxwebsoft.com/api/union-pay-jjx/transByOrder',
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
header: {
|
||||
'content-type': 'application/json; charset=utf-8'
|
||||
},
|
||||
data: {
|
||||
accNo,
|
||||
merOrderNo: sourcePayOrderNo,
|
||||
payAmt,
|
||||
amount: payAmt,
|
||||
},
|
||||
timeout: 60000
|
||||
});
|
||||
|
||||
const transferAt = nowText(vk);
|
||||
await vk.baseDao.updateById({
|
||||
dbName: 'jjx-order-pay-list',
|
||||
id: payRecord._id,
|
||||
dataJson: {
|
||||
sellerConfirm: true,
|
||||
confirmAt: transferAt,
|
||||
transferStatus: 1,
|
||||
transferAt,
|
||||
transferOperator: operator,
|
||||
transferResult,
|
||||
transferSourcePayListId: sourcePayListId,
|
||||
transferSourceOrderNo: sourcePayOrderNo,
|
||||
transferSourceAmount: sourcePayAmount
|
||||
}
|
||||
});
|
||||
|
||||
if (['尾款', '货到付款', '全款'].includes(payRecord.type)) {
|
||||
await vk.baseDao.updateById({
|
||||
dbName: 'jjx-order',
|
||||
id: payRecord.orderId,
|
||||
dataJson: {
|
||||
orderStatus: 4,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await addMessage(vk, {
|
||||
uid: payRecord.sellerUid,
|
||||
title: '付款单已划付',
|
||||
content: `付款单${payRecord.type || ''}已${operator === 'auto' ? '自动' : '由买家确认'}划付,金额${payRecord.amount}元,来源单号:${sourcePayOrderNo}。`,
|
||||
type: 'order-pay-transfer',
|
||||
pk: payRecord.orderId
|
||||
});
|
||||
|
||||
return {
|
||||
code: 0,
|
||||
msg: '划付成功',
|
||||
data: {
|
||||
transferResult,
|
||||
sourcePayOrderNo,
|
||||
sourcePayListId,
|
||||
sourcePayAmount
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AUTO_TRANSFER_DAYS_DICT_ID,
|
||||
DEFAULT_AUTO_TRANSFER_DAYS,
|
||||
getAutoTransferDays,
|
||||
buildPayApplyFields,
|
||||
findFullPayRecord,
|
||||
resolveTransferSourcePayRecord,
|
||||
addMessage,
|
||||
notifyPaySuccess,
|
||||
notifyPayApply,
|
||||
resolveSellerMerNo,
|
||||
executeTransfer
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 此函数名称
|
||||
* @url client/order/pub/test 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @params {String} params1 参数1
|
||||
*/
|
||||
main: async (event) => {
|
||||
let { data = {}, userInfo, util, originalParam } = event;
|
||||
let { customUtil, config, pubFun, vk, db, _ } = util;
|
||||
let { uid } = data;
|
||||
let res = { code : 0, msg : '' };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
// 可写与数据库的交互逻辑等等
|
||||
|
||||
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/otherArticle/category/pub/getList 前端调用的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, pageIndex, pageSize} = data;
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.selects({
|
||||
dbName: 'jjx-other-article-category',
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
sortArr: [
|
||||
{name: "sort", type: "asc"},
|
||||
{name: "_id", type: "desc"},
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/otherArticle/list/pub/getDetail 前端调用的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: "" };
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
|
||||
res = await vk.baseDao.findById({
|
||||
dbName: "jjx-other-article",
|
||||
id: data.id,
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* XXXnameXXX
|
||||
* @url client/otherArticle/list/pub/getList 前端调用的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 {pageIndex, pageSize, parentId} = data
|
||||
const whereJson = {}
|
||||
if (vk.pubfn.isNotNull(parentId)){
|
||||
if (Array.isArray(parentId)) {
|
||||
whereJson.parentId = _.in(parentId)
|
||||
} else {
|
||||
whereJson.parentId = parentId
|
||||
}
|
||||
}
|
||||
res = await vk.baseDao.select({
|
||||
dbName: 'jjx-other-article',
|
||||
getCount: true,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
whereJson,
|
||||
sortArr: [
|
||||
{name: "sort", type: "asc"},
|
||||
{name: "_add_time", type: "desc"}
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// 业务逻辑结束-----------------------------------------------------------
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user