Commit b3a8e9b4 by 宋毅

渠道增加

parent 747b0365
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class IcOrderAPI extends APIBase {
constructor() {
super();
this.orderSve = system.getObject("service.dborder.orderSve");
}
/**
* 接口跳转-POST请求
* action_process 执行的流程
......@@ -36,6 +38,7 @@ class IcOrderAPI extends APIBase {
}
return result;
}
async opActionProcess(action_process, action_type, action_body, pobj, req) {
action_body.app = req.app;
action_body.user = req.user;
......@@ -48,6 +51,17 @@ class IcOrderAPI extends APIBase {
switch (action_type) {
case "addOrderAndDelivery"://创建订单和交付单
opResult = await this.orderSve.addOrderAndDelivery(action_body, pobj, req);
pobj.actionBody.quantity = 1;
pobj.actionBody.channelOrder = {};
pobj.actionBody.channelOrder.channelServiceNo = pobj.actionBody.needNo;
pobj.actionBody.channelOrder.channelOrderNo = pobj.actionBody.needNo;
pobj.actionBody.channelOrder.payTime = new Date();
pobj.actionBody.channelOrder.orderStatus = 2;//订单状态dfk: 1: 待付款, 2: 已付款, 4: 待服务, 8: 已完成
pobj.actionBody.orderContact = {};
pobj.actionBody.orderContact.mobile = pobj.actionBody.buyerMoblie;
pobj.actionBody.orderContact.email = pobj.actionBody.email;
let tmpResult = await this.orderSve.addQifuOrder(pobj, pobj.actionBody, req);
this.execClientNew.execLogs("igirl-channel-addOrderAndDelivery", pobj, "igirl-channel-addOrderAndDelivery", tmpResult, null);
break;
case "getOrderDetailByOrderNo"://获取订单详情
opResult = system.getResultSuccess(null, "测试成功");
......@@ -65,4 +79,5 @@ class IcOrderAPI extends APIBase {
return opResult;
}
}
module.exports = IcOrderAPI;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
class OrderService extends ServiceBase {
constructor() {
super("dborder", ServiceBase.getDaoName(OrderService));
......@@ -21,7 +22,9 @@ class OrderService extends ServiceBase {
this.pushlogDao = system.getObject("db.common.pushlogDao");
this.customerinfoDao = system.getObject("db.dborder.customerinfoDao");
this.trademarkDao = system.getObject("db.dbtrademark.trademarkDao");
this.execClientNew = system.getObject("util.execClientNew");
}
//订单线下支付(上传支付凭证)
async offlinePaymentOrder(obj) {
var app = obj.app;
......@@ -41,7 +44,7 @@ class OrderService extends ServiceBase {
return system.getResultFail(-103, "paymentVoucher参数错误");
}
var order = await this.dao.model.findOne({
where: { orderNo: orderNo, app_id: app.id },
where: {orderNo: orderNo, app_id: app.id},
raw: true
});
if (!order) {
......@@ -52,12 +55,12 @@ class OrderService extends ServiceBase {
}
var self = this;
return await self.db.transaction(async function (t) {
var orderObj = { id: order.id, orderPayStatus: "zfpz", payTime: new Date() };
var orderObj = {id: order.id, orderPayStatus: "zfpz", payTime: new Date()};
await self.dao.update(orderObj, t);
var logMsg = { sourceOrderNo: order.orderNo, opContent: "订单提交支付凭证", app_id: app.id, isShow: 1 };
var logMsg = {sourceOrderNo: order.orderNo, opContent: "订单提交支付凭证", app_id: app.id, isShow: 1};
await self.orderflowDao.create(logMsg, t);
var orderReceiptVoucher = await self.receiptvoucherDao.model.findOne({
where: { busPayOrderCode: order.orderNo, createapp_id: app.id },
where: {busPayOrderCode: order.orderNo, createapp_id: app.id},
raw: true
});
var orderReceiptVoucherObj = {
......@@ -84,6 +87,7 @@ class OrderService extends ServiceBase {
return system.getResultSuccess();
})
}
async addOrderAndDelivery(action_body, pobj, req) {
if (!action_body.needNo) {
return system.getResult(null, "needNo is empty");
......@@ -93,9 +97,10 @@ class OrderService extends ServiceBase {
}
var productItem = await this.appproductDao.findOneByChannelItemCode(action_body.channelItemCode, req.app.id);//获取产品
if (!productItem) {
return system.getResult(null, action_body.channelItemCode + " productItem is empty");;
return system.getResult(null, action_body.channelItemCode + " productItem is empty");
;
}
var orderCount = await this.dao.findCount({ where: { needNo: action_body.needNo } });
var orderCount = await this.dao.findCount({where: {needNo: action_body.needNo}});
if (orderCount > 0) {
return system.getResultFail(system.existData, "order is exist");
}
......@@ -167,20 +172,21 @@ class OrderService extends ServiceBase {
var orderTm = await self.ordertmproductDao.create(orderProductObj, t);//创建订单交付流程
pushType = "tm_";
}//创建服务单
//推送商机到峰擎
if (productItem.pushServiceItemCode && orderParams.buyerMoblie) {
self.pushFqBusiness(pushType, orderParams, productItem.pushServiceItemCode, pobj, req);
} else {
self.logCtl.info({
appid: req.app.id,
appkey: req.app.uappKey,
requestId: req.requestId || "",
op: "/igirl-channel/zhichan/igirl-channel/app/base/service/impl/dborder/orderSve/addOrderAndDelivery",
content: "pushServiceItemCode=" + productItem.pushServiceItemCode + ",buyerMoblie=" + action_body.buyerMoblie,
clientIp: pobj.clientIp,
optitle: "未能推送订单商机到FQ信息,pushServiceItemCode 或 buyerMoblie 为空",
});
}
// //推送商机到峰擎//---------------------------------------------------------//TODO:sy处理从启服通进行推送
// if (productItem.pushServiceItemCode && orderParams.buyerMoblie) {
// self.pushFqBusiness(pushType, orderParams, productItem.pushServiceItemCode, pobj, req);
// } else {
// self.logCtl.info({
// appid: req.app.id,
// appkey: req.app.uappKey,
// requestId: req.requestId || "",
// op: "/igirl-channel/zhichan/igirl-channel/app/base/service/impl/dborder/orderSve/addOrderAndDelivery",
// content: "pushServiceItemCode=" + productItem.pushServiceItemCode + ",buyerMoblie=" + action_body.buyerMoblie,
// clientIp: pobj.clientIp,
// optitle: "未能推送订单商机到FQ信息,pushServiceItemCode 或 buyerMoblie 为空",
// });
// }
return system.getResultSuccess({
orderNo: ordercode,
deliveryOrderNo: orderProductObj.deliveryOrderNo || ordercode,
......@@ -188,17 +194,19 @@ class OrderService extends ServiceBase {
});
});
}
//关联订单对应的需求ID和需求订单号--渠道web用
async updateOrderStatus(action_body, pobj, req) {
// var setObj = { channelServiceNo: action_body.channelServiceNo, needNo: action_body.needNo, needNoOrderNo: action_body.needNoOrderNo };
var setObj = { needNo: action_body.needNo, needNoOrderNo: action_body.needNoOrderNo };
var setObj = {needNo: action_body.needNo, needNoOrderNo: action_body.needNoOrderNo};
var self = this;
return await this.db.transaction(async function (t) {
await self.dao.updateByWhere(setObj, { where: { orderNo: action_body.orderNo } }, t);
await self.ordertmproductDao.updateByWhere(setObj, { where: { sourceOrderNo: action_body.orderNo } }, t);
await self.dao.updateByWhere(setObj, {where: {orderNo: action_body.orderNo}}, t);
await self.ordertmproductDao.updateByWhere(setObj, {where: {sourceOrderNo: action_body.orderNo}}, t);
return system.getResultSuccess();
});
}
//更新付款状态--渠道web用
async updateOrderPayStatus(action_body, pobj, req) {
var payStatus = action_body.payStatus || "dfk";
......@@ -208,11 +216,19 @@ class OrderService extends ServiceBase {
return system.getResult(null, "data is empty");
}
return await this.db.transaction(async function (t) {
await self.dao.updateByWhere({ orderPayStatus: payStatus, buyerMoblie: action_body.buyerMoblie || "" }, { where: { needNoOrderNo: action_body.needNoOrderNo, app_id: req.app.id } }, t);
await self.ordertmproductDao.updateByWhere({ payStatus: payStatus }, { where: { needNoOrderNo: action_body.needNoOrderNo, app_id: req.app.id } }, t);
var logMsg = { sourceOrderNo: result.deliveryOrderNo, opContent: "订单已成功支付", app_id: req.app.id, isShow: 1 };
await self.dao.updateByWhere({
orderPayStatus: payStatus,
buyerMoblie: action_body.buyerMoblie || ""
}, {where: {needNoOrderNo: action_body.needNoOrderNo, app_id: req.app.id}}, t);
await self.ordertmproductDao.updateByWhere({payStatus: payStatus}, {
where: {
needNoOrderNo: action_body.needNoOrderNo,
app_id: req.app.id
}
}, t);
var logMsg = {sourceOrderNo: result.deliveryOrderNo, opContent: "订单已成功支付", app_id: req.app.id, isShow: 1};
await self.orderflowDao.create(logMsg, t);
return system.getResultSuccess({ deliveryOrderNo: result.deliveryOrderNo });
return system.getResultSuccess({deliveryOrderNo: result.deliveryOrderNo});
});
}
......@@ -226,6 +242,7 @@ class OrderService extends ServiceBase {
}
return system.getResult(null, "付款状态为未支付才进行修改");
}
async op1688ChannelPushOrder(action_body, pobj, req) {
try {
//var reqUrl = "https://inte-mcp.chanjet.com/gsb/getOrder?token=" + action_body.token; //测试环境
......@@ -261,6 +278,7 @@ class OrderService extends ServiceBase {
});
}
}
async op1688ChannelPushOrderTest(action_body, pobj, req) {
try {
......@@ -601,6 +619,7 @@ class OrderService extends ServiceBase {
});
}
}
async addOrderNeed(action_body, req, returnValue) {
var productItem = await this.appproductDao.findOneByChannelItemCode(action_body.channelItemCode, req.app.id);//获取产品
if (!productItem) {
......@@ -613,7 +632,7 @@ class OrderService extends ServiceBase {
const element = returnValue[index];
if (element) {
if (element.bizStatusExt == "service" || element.bizStatusExt == "audit_pass") {
var orderCount = await self.findCount({ where: { needNo: element.orderItemNum } });
var orderCount = await self.findCount({where: {needNo: element.orderItemNum}});
if (orderCount > 0) {
continue;
}
......@@ -688,6 +707,7 @@ class OrderService extends ServiceBase {
}
}
}
async push1688FqBusiness(action_body, pobj, req) {
var item = await this.dao.getItemByChannelServiceNo(action_body.channelServiceNo, req.app.id);
if (!item) {
......@@ -704,9 +724,10 @@ class OrderService extends ServiceBase {
if (result.status != 0) {
return result;
}
await this.updateByWhere({ buyerMoblie: action_body.buyerMoblie }, { where: { channelServiceNo: action_body.channelServiceNo } });
await this.updateByWhere({buyerMoblie: action_body.buyerMoblie}, {where: {channelServiceNo: action_body.channelServiceNo}});
return result;
}
/**
*
* @param {*} pushType 推送的类型 tm_ ic_ icp_
......@@ -760,6 +781,7 @@ class OrderService extends ServiceBase {
});
}
}
async againPushFqBusiness(pobj, req) {//再次推送商机
var rc = system.getObject("util.aliyunClient");
var rtn = null;
......@@ -794,6 +816,7 @@ class OrderService extends ServiceBase {
});
}
}
async getIcbcOrderDetails(pobj, req) {//通过峰擎阿里云接口获取工商详情
var rc = system.getObject("util.aliyunClient");
var rtn = null;
......@@ -828,6 +851,7 @@ class OrderService extends ServiceBase {
});
}
}
async gsbOrderInfo(pobj, req) {//公司宝官网订单
var rc = system.getObject("util.aliyunClient");
var rtn = null;
......@@ -864,6 +888,7 @@ class OrderService extends ServiceBase {
});
}
}
//------------新的产品查询----start---------------------------------------------------------------
/**
* 获取启服务通订单交付信息
......@@ -909,6 +934,7 @@ class OrderService extends ServiceBase {
var result = JSON.parse(rtn.stdout);
return result;
}
/**
* 获取启服务通订单交付流程信息
* @param {*} pobj
......@@ -953,6 +979,7 @@ class OrderService extends ServiceBase {
var result = JSON.parse(rtn.stdout);
return result;
}
/**
* 获取启服务通订单列表信息
* @param {*} pobj
......@@ -1071,6 +1098,7 @@ class OrderService extends ServiceBase {
var result = JSON.parse(rtn.stdout);
return result;
}
/**
* 获取产品详情
* @param {*} pobj
......@@ -1118,6 +1146,7 @@ class OrderService extends ServiceBase {
var result = JSON.parse(rtn.stdout);
return result;
}
//获取通联支付二维码
async getTlPayQrCode(obj) {
if (!obj.app || !obj.app.uAppId || !obj.app.id) {
......@@ -1127,7 +1156,7 @@ class OrderService extends ServiceBase {
return system.getResultFail(-101, "orderNo参数有误");
}
var order = await this.dao.model.findOne({
where: { orderNo: obj.orderNo, app_id: obj.app.id }, raw: true,
where: {orderNo: obj.orderNo, app_id: obj.app.id}, raw: true,
attributes: ["id", "orderNo", "itemCode", "itemName", "channelItemCode", "channelItemName", "salesNum",
"orderPayStatus", "orderPayStatusName", "totalSum", "created_at"]
});
......@@ -1177,7 +1206,7 @@ class OrderService extends ServiceBase {
if (obj && obj.trxstatus == "0000") {
// obj.company_id = obj.uappid;
var app = await this.appDao.model.findOne({
where: { uAppId: obj.uappid }, raw: true
where: {uAppId: obj.uappid}, raw: true
});
if (!app) {
return system.getResultFail(-100, "渠道参数错误");
......@@ -1187,19 +1216,18 @@ class OrderService extends ServiceBase {
return resultSign;
}
var orderInfo = await this.dao.model.findOne({
where: { orderNo: obj.out_trade_no, app_id: app.id },
where: {orderNo: obj.out_trade_no, app_id: app.id},
raw: true
});
if (!orderInfo) {
return system.getResultFail(-102, "订单数据不存在");
}
if (orderInfo.orderPayStatus == "yfk") {
return system.getResultSuccess({ orderPayStatus: "yfk" });
return system.getResultSuccess({orderPayStatus: "yfk"});
}
//修改并返回订单支付状态,创建收款单
return await this.opBackNotify(obj, "接收通联支付通知回调", app);
}
else if (obj.trxstatus == "3045") {
} else if (obj.trxstatus == "3045") {
return system.getResultFail(-104, "超时未支付,queryTlPayOrder新页面");
}
return system.getResultFail(-105, "请及时支付");
......@@ -1207,6 +1235,7 @@ class OrderService extends ServiceBase {
return system.getResultFail(-200, e.stack);
}
}
async checkPayStatusTl(obj) {//通联支付状态验证
var wxPayOrderCode = obj.wxPayOrderCode || "";
var aliPayOrderCode = obj.aliPayOrderCode || "";
......@@ -1221,7 +1250,7 @@ class OrderService extends ServiceBase {
return system.getResultFail(-101, "参数错误");
}
var orderInfo = await this.dao.model.findOne({
where: { orderNo: orderCode, app_id: app.id },
where: {orderNo: orderCode, app_id: app.id},
raw: true
});
if (!orderInfo) {
......@@ -1241,7 +1270,7 @@ class OrderService extends ServiceBase {
"orderPayStatus": "yfk",
};
var orderReceiptVoucher = await this.receiptvoucherDao.model.findOne({
where: { createapp_id: app.id, busPayOrderCode: orderInfo.orderNo },
where: {createapp_id: app.id, busPayOrderCode: orderInfo.orderNo},
raw: true
});
if (orderReceiptVoucher && orderReceiptVoucher.busPayOrderCode) {
......@@ -1258,8 +1287,7 @@ class OrderService extends ServiceBase {
let attachList = [];
if (payStatus.data.reqsn.indexOf("_") >= 0) {
attachList = payStatus.data.reqsn.split("_");
}
else {
} else {
attachList.push(payStatus.data.reqsn);
}
if (attachList.length != 2) {
......@@ -1269,12 +1297,12 @@ class OrderService extends ServiceBase {
payStatus.data.company_id = attachList[1];
//修改并返回订单支付状态,创建收款单
return await this.opBackNotify(payStatus.data, "queryTlPayOrder面回调", app);
}
else if (payStatus && payStatus.code == 1 && payStqueryTlPayOrders.data.trxstatus == "3045") {
} else if (payStatus && payStatus.code == 1 && payStqueryTlPayOrders.data.trxstatus == "3045") {
return system.getResultFail(-104, "超时未支付,queryTlPayOrder新页面");
}
return system.getResultFail(-104, "请及时支付");
}
//查询通联支付订单
async queryTlPayOrder(app, payTrxid) {
var token = "";
......@@ -1300,6 +1328,7 @@ class OrderService extends ServiceBase {
var result = JSON.parse(rtn.stdout);
return result;
}
//操作回调业务逻辑
async opBackNotify(getParams, opDesc, app) {
try {
......@@ -1320,8 +1349,7 @@ class OrderService extends ServiceBase {
getParams.req_accountType = "alipay";
}
return await this.notifyOpDb(getParams, app);
}
else {
} else {
// await this.cacheManager["ZxPayLocker"].release(getParams.trxid);//---测试时放开
this.logCtl.info({
appid: app.id,
......@@ -1339,6 +1367,7 @@ class OrderService extends ServiceBase {
return system.getResultFail(-200, e.stack);
}
}
/*
返回值:
-430:对应的业务支付订单号暂无
......@@ -1354,7 +1383,7 @@ class OrderService extends ServiceBase {
if (obj.req_accountType == "alipay") {
accountType = "alipay";
}
var sqlWheres = { orderNo: obj.out_trade_no, app_id: app.id };
var sqlWheres = {orderNo: obj.out_trade_no, app_id: app.id};
var orderItem = await this.dao.model.findOne({
where: sqlWheres,
raw: true
......@@ -1371,10 +1400,10 @@ class OrderService extends ServiceBase {
var self = this;
return await this.db.transaction(async function (t) {
// 订单付款状态dfk: 待付款, zfpz: 已上传支付凭证, yfk: 已付款, ddqx: 订单取消, tkclz: 退款处理中, bfytk: 部分已退款, ytk: 已退款,zfshbtg:支付审核不通过
var putParams = { orderPayStatus: "yfk", payDate: new Date() };
await self.dao.updateByWhere(putParams, { where: sqlWheres }, t);
var putParams = {orderPayStatus: "yfk", payDate: new Date()};
await self.dao.updateByWhere(putParams, {where: sqlWheres}, t);
var otmp = await self.ordertmproductDao.model.findOne({
where: { sourceOrderNo: obj.out_trade_no, app_id: app.id },
where: {sourceOrderNo: obj.out_trade_no, app_id: app.id},
raw: true
});
if (otmp && otmp.id) {
......@@ -1382,7 +1411,12 @@ class OrderService extends ServiceBase {
payStatus: "yfk"
};
// await self.ordertmproductDao.model.update(otmpObj, t);
await self.ordertmproductDao.model.update(otmpObj, { where: { sourceOrderNo: obj.out_trade_no, app_id: app.id }, transaction: t });
await self.ordertmproductDao.model.update(otmpObj, {
where: {
sourceOrderNo: obj.out_trade_no,
app_id: app.id
}, transaction: t
});
}
//订单流程log
self.orderflowDao.create({
......@@ -1422,6 +1456,7 @@ class OrderService extends ServiceBase {
return system.getResultSuccess(resdata);
});
}
// async testpushDataToFq(){
// var order= await this.dao.model.findOne({
// where:{id:501},raw:true
......@@ -1453,7 +1488,7 @@ class OrderService extends ServiceBase {
return;
}
var user = await this.appuserDao.model.findOne({//订单所属用户
where: { id: order.createuser_id }, raw: true
where: {id: order.createuser_id}, raw: true
});
if (!user) {
logObj.content = "订单用户不存在";
......@@ -1469,7 +1504,7 @@ class OrderService extends ServiceBase {
"orgPath": user.orgPath
};
var otmp = await this.ordertmproductDao.model.findOne({//订单交付单
where: { sourceOrderNo: order.orderNo, app_id: app.id }, raw: true
where: {sourceOrderNo: order.orderNo, app_id: app.id}, raw: true
});
if (!otmp) {
logObj.content = "订单交付单不存在";
......@@ -1484,7 +1519,7 @@ class OrderService extends ServiceBase {
"payTime": new Date()
};
var ci = await this.customerinfoDao.model.findOne({
where: { app_id: app.id, deliveryOrderNo: otmp.deliveryOrderNo }, raw: true
where: {app_id: app.id, deliveryOrderNo: otmp.deliveryOrderNo}, raw: true
});
if (!ci) {
logObj.content = "订单申请人信息为空";
......@@ -1492,7 +1527,7 @@ class OrderService extends ServiceBase {
return;
}
var contacts = await this.customercontactsDao.model.findOne({
where: { app_id: app.id, deliveryOrderNo: otmp.deliveryOrderNo }, raw: true
where: {app_id: app.id, deliveryOrderNo: otmp.deliveryOrderNo}, raw: true
});
if (!contacts) {
logObj.content = "订单申请联系人信息为空";
......@@ -1530,7 +1565,7 @@ class OrderService extends ServiceBase {
"totalTaxes": order.totalTaxes
};
var tms = await this.trademarkDao.model.findAll({
where: { app_id: app.id, deliveryOrderNo: otmp.deliveryOrderNo }, raw: true
where: {app_id: app.id, deliveryOrderNo: otmp.deliveryOrderNo}, raw: true
});
if (!tms || tms.length < 1) {
logObj.content = "商标信息为空";
......@@ -1548,9 +1583,16 @@ class OrderService extends ServiceBase {
nclones.push(nclone);
}
reqObj = {//请求参数汇总
itemCode: order.itemCode, channelUser: channelUser, channelOrder: channelOrder, tm: tm, apply: apply,
nclones: nclones, appid: "2e787bbaacda4c6488b9fae58fff30ba", channelCode: app.appSourceCode,
channelUserId: user.channelUserId, deliveryOrderNo: otmp.deliveryOrderNo
itemCode: order.itemCode,
channelUser: channelUser,
channelOrder: channelOrder,
tm: tm,
apply: apply,
nclones: nclones,
appid: "2e787bbaacda4c6488b9fae58fff30ba",
channelCode: app.appSourceCode,
channelUserId: user.channelUserId,
deliveryOrderNo: otmp.deliveryOrderNo
};
rtn = await this.execClient.execPost(reqObj, url);
var returnType = "0";
......@@ -1577,7 +1619,7 @@ class OrderService extends ServiceBase {
await this.pushLog(logObj);
return;
}
await this.pushFqBusiness("tm_", order, productItem.pushServiceItemCode, { clientIp: "" }, { app: app });
await this.pushFqBusiness("tm_", order, productItem.pushServiceItemCode, {clientIp: ""}, {app: app});
return;
}
} catch (e) {
......@@ -1620,9 +1662,11 @@ class OrderService extends ServiceBase {
this.pushlogDao.create(qobj);
}
}
//-------------------------通联支付------end---------------------------------------------------------
}
module.exports = OrderService;
// var task = new OrderService();
// var app={
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment