Commit 080d2196 by 宋毅

tj

parent c01fa032
......@@ -52,13 +52,22 @@ class TmOrderAPI extends APIBase {
var opResult = null;
if (["subTmOrder", "getTmOrderList", "getTmOrderInfo", "getTmApplyInfo", "getTmNclList", "getNeedInfo",
"tmConfirm", "updateTmInfo", "updateNclInfo", "updateContacts", "updateCustomerInfo",
"updateCustomerInfo"].indexOf(action_type) >= 0) {
"updateCustomerInfo", "addOrderAndDelivery"].indexOf(action_type) >= 0) {
if (!action_body.channelUserId) {
return system.getResult(null, "verify channelUserId is not empty");
}
}
switch (action_type) {
// sy
case "updateOrderStatus"://更新订单状态
opResult = await this.orderSve.updateOrderStatus(action_body, req);
break;
case "updateOrderPayStatus"://更新订单付款状态
opResult = await this.orderSve.updateOrderStatus(action_body, req);
break;
case "addOrderAndDelivery"://创建订单和交付单
opResult = await this.orderSve.addOrderAndDelivery(action_body, pobj, req);
break;
case "clearAllCache":
await this.cacheManager["MagCache"].clearAll();
opResult = system.getResultSuccess(null, "清理缓存成功");
......@@ -186,7 +195,7 @@ class TmOrderAPI extends APIBase {
}
break;
case "pushFqBusiness"://推送商机到峰擎
opResult = await this.orderSve.pushFqBusiness(action_body, pobj, req);
opResult = await this.orderSve.push1688FqBusiness(action_body, pobj, req);
break;
case "getProductDetail"://根据渠道产品码获取产品详情
opResult = await this.appProductSve.findByChannelItemCode(action_body);
......
......@@ -17,6 +17,8 @@ class AppProductDao extends Dao {
"picUrl", // 产品图片地址
"channelItemCode", // 渠道产品编码
"channelItemName", // 渠道产品名称
"serviceItemCode",
"pushServiceItemCode",
"status", // 状态 0禁用 1启用
"verifyPrice", // 是否验证价格 0不验证 1验证
"proPrice", // 产品价格
......@@ -44,6 +46,8 @@ class AppProductDao extends Dao {
"picUrl", // 产品图片地址
"channelItemCode", // 渠道产品编码
"channelItemName", // 渠道产品名称
"serviceItemCode",
"pushServiceItemCode",
"status", // 状态 0禁用 1启用
"verifyPrice", // 是否验证价格 0不验证 1验证
"proPrice", // 产品价格
......@@ -72,6 +76,7 @@ class AppProductDao extends Dao {
"channelItemCode", // 渠道产品编码
"channelItemName", // 渠道产品名称
"serviceItemCode",
"pushServiceItemCode",
"deliveryUrl",
"status", // 状态 0禁用 1启用
"verifyPrice", // 是否验证价格 0不验证 1验证
......
......@@ -10,6 +10,7 @@ module.exports = (db, DataTypes) => {
channelItemCode :DataTypes.STRING(100),// 渠道产品编码
channelItemName :DataTypes.STRING(100),// 渠道产品名称
serviceItemCode :DataTypes.STRING(100),// 服务商产品编码
pushServiceItemCode :DataTypes.STRING(100),// 推送到服务商的产品编码
status :DataTypes.BOOLEAN,// 状态 0禁用 1启用
verifyPrice :DataTypes.BOOLEAN,// 是否验证价格 0不验证 1验证
proPrice :DataTypes.DOUBLE,// 产品价格
......
......@@ -55,6 +55,7 @@ module.exports = (db, DataTypes) => {
invoiceApplyStatus :DataTypes.STRING(10),// 发票状态:00: 未申请, 10: 已申请,20:已开票
channelUserId :DataTypes.STRING(64), // 渠道用户ID
needNo :DataTypes.STRING(64), // 需求单号
needNoOrderNo :DataTypes.STRING(64), // 需求订单号
sourceType: DataTypes.STRING(10),//来源类型:00订单,10需求需要用户确认方案
picUrl :DataTypes.STRING(500),// 产品图片地址
productType_id :DataTypes.INTEGER, //产品类型Id
......
......@@ -50,6 +50,7 @@ module.exports = (db, DataTypes) => {
channelServiceNo: DataTypes.STRING(64),//渠道服务单号
channelOrderNo: DataTypes.STRING(1024),//渠道订单号列表,多个以,隔开
needNo: DataTypes.STRING(64),//需求单号
needNoOrderNo :DataTypes.STRING(64), // 需求订单号
sourceType: DataTypes.STRING(10),//来源类型:00订单,10需求需要用户确认方案
picUrl: DataTypes.STRING(500), //商标图样
colorizedPicUrl: DataTypes.STRING(500),//商标彩色图样
......
......@@ -9,8 +9,128 @@ class OrderService extends ServiceBase {
this.appproductDao = system.getObject("db.dbapp.appproductDao");
this.ordertmproductDao = system.getObject("db.dborder.ordertmproductDao");
this.receiptvoucherDao = system.getObject("db.dborder.receiptvoucherDao");
this.customercontactsDao = system.getObject("db.dborder.customercontactsDao");
this.execClient = system.getObject("util.execClient");
}
async addOrderAndDelivery(action_body, pobj, req) {
if (!action_body.needNo) {
return system.getResult(null, "needNo is not empty");
}
if (!action_body.channelItemCode) {
return system.getResult(null, "channelItemCode is not empty");
}
var productItem = await this.appproductDao.findOneByChannelItemCode(action_body.channelItemCode, req.app.id);//获取产品
if (!productItem) {
return;
}
var orderCount = await this.dao.findCount({ where: { needNo: action_body.needNo } });
if (orderCount > 0) {
return system.getResultFail(system.existData, "order is exist");
}
var self = this;
return await self.db.transaction(async function (t) {
//创建订单
var ordercode = await self.getBusUid("tm");
var orderParams = {
app_id: req.app.id,//
orderNo: ordercode,// 订单号
payTime: new Date(),//
itemCode: productItem.itemCode,//
itemName: productItem.itemName,//
channelItemCode: productItem.channelItemCode,// 渠道产品编码
channelItemName: productItem.channelItemName,// 渠道产品名称
salesNum: 1,//项目订单数量(即服务项目的倍数,默认值为1)
salesDiliverNum: 0,//项目订单交付数量(即与项目订单数量相对应)
minitermNum: 10,//订单小项数量
minitermDiliverNum: 0,//订单小项交付数量
orderType: "dkxd",// 订单类型,zzdd: 自主订单,dkxd: 代客下单
orderPayStatus: "yfk",// 订单付款状态dfk: 待付款, zfpz: 已上传支付凭证, yfk: 已付款, ddqx: 订单取消, tkclz: 退款处理中, bfytk: 部分已退款, ytk: 已退款,zfshbtg:支付审核不通过
totalServiceCharge: productItem.totalServiceCharge || 0,// 服务费总额(产品配置的服务费*订单件数)
totalPublicExpense: productItem.totalPublicExpense || 0,// 官费总额(产品配置的官费*订单件数)
totalSum: productItem.proPrice || 0,// 订单总额(产品价格×优惠费率×订单件数)
refundSum: 0,// 退款金额
buyerMoblie: action_body.buyerMoblie || "",
// notes: apply.notes, //备注
appPayType: "00",// 支付类型:00第三方支付,10平台代收款
payAccountType: "other",// 帐户类型( 支付类型):cash: 现金, bank: 银行,wx:微信,alipay:支付,other:其它
createuser_id: req.user.id,
owner_id: req.user.id,//
creator: req.user.nickname || "",
owner: req.user.nickname || "",//
ownerMoblie: req.user.userMoblie || "",//
invoiceApplyStatus: "00",// 发票状态:00: 未申请, 10: 已申请,20:已开票
channelUserId: req.user.channelUserId || "",// 渠道用户id
needNo: action_body.needNo || null,//需求单号
needNoOrderNo: action_body.needNoOrderNo || null,//需求单号
picUrl: productItem.picUrl,//
productType_id: productItem.productType_id,//产品类型Id
productOneType_id: productItem.productOneType_id,//产品大类Id
serviceItemSnapshot: JSON.stringify(productItem),//产品快照
};
var orderItem = await self.dao.create(orderParams, t);//创建订单
var receiptvoucherItem = await self.receiptvoucherDao.addReceiptvoucher(orderParams, req, t);//创建订单支付信息
var pushType = "ic_";
if (["fzsbzc", "dbsbzc"].indexOf(productItem.itemCode) >= 0) {
var tmDeliveryOrderNo = await self.getBusUid("jf")
var orderProductObj = {
app_id: req.app.id,//
productType_id: productItem.productType_id,//产品类型Id
productOneType_id: productItem.productOneType_id,//产品大类Id
itemCode: productItem.itemCode,//
itemName: productItem.itemName,//
orderServicePayStatus: "yfk",//支付状态:dfk: 待付款, yfk: 已支付
appDataOpType: req.app.appDataOpType,// 应用数据操作类型:00独立,10全委托,20部分委托
sourceOrderNo: ordercode,//来源单号
deliveryOrderNo: tmDeliveryOrderNo,
needNo: action_body.needNo || null,//需求单号
needNoOrderNo: action_body.needNoOrderNo || null,//需求单号
sourceType: "00",
channelUserId: req.user.channelUserId || "",// 渠道用户id
createuser_id: req.user.id,//
createuser: req.user.nickname,//
};
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=" + item.buyerMoblie,
clientIp: pobj.clientIp,
optitle: "未能推送订单商机到FQ信息,pushServiceItemCode 或 buyerMoblie 为空",
});
}
return system.getResultSuccess({
deliveryOrderNo: orderProductObj.deliveryOrderNo,
needNo: action_body.needNo
});
});
}
//更新订单状态
async updateOrderStatus(action_body, pobj, req) {
var setObj = {};
if (pobj.actionProcess == "jd") {
setObj.needNo = pobj.needNo;
setObj.needNoOrderNo = pobj.needNoOrderNo;
}
await this.dao.updateByWhere(setObj, { where: { orderNo: action_body.orderNo } });
return system.getResultSuccess();
}
//更新付款状态
async updateOrderPayStatus(action_body, pobj, req) {
return await self.db.transaction(async function (t) {
await this.dao.updateByWhere({ orderPayStatus: "yfk", buyerMoblie: action_body.buyerMoblie }, { where: { needNoOrderNo: action_body.needNoOrderNo, app_id: req.app.id } }, t);
await this.ordertmproductDao.updateByWhere({ payStatus: "yfk" }, { where: { needNoOrderNo: action_body.needNoOrderNo, app_id: req.app.id } }, t);
return system.getResultSuccess();
});
}
async op1688ChannelPushOrder(action_body, pobj, req) {
try {
//var reqUrl = "https://inte-mcp.chanjet.com/gsb/getOrder?token=" + action_body.token; //测试环境
......@@ -387,7 +507,6 @@ class OrderService extends ServiceBase {
}
}
async addOrderNeed(action_body, req, returnValue) {
var addOrderList = [];
var productItem = await this.appproductDao.findOneByChannelItemCode(action_body.channelItemCode, req.app.id);//获取产品
if (!productItem) {
return;
......@@ -474,9 +593,7 @@ class OrderService extends ServiceBase {
}
}
}
async pushFqBusiness(action_body, pobj, req) {
var rc = system.getObject("util.aliyunClient");
async push1688FqBusiness(action_body, pobj, req) {
var item = await this.dao.getItemByChannelServiceNo(action_body.channelServiceNo, req.app.id);
if (!item) {
return system.getResult(null, "没有找到相关订单信息");
......@@ -487,19 +604,39 @@ class OrderService extends ServiceBase {
if (item.buyerMoblie) {
return system.getResult(null, "订单已经推送过,请勿重覆推送");
}
item.buyerMoblie = action_body.buyerMoblie;
var result = await this.pushFqBusiness("tm_", item, "5dd513db4f3b08000a6fc082", pobj, req);
if (result.status != 0) {
return result;
}
await this.updateByWhere({ buyerMoblie: action_body.buyerMoblie }, { where: { channelServiceNo: action_body.channelServiceNo } });
return result;
}
/**
*
* @param {*} pushType 推送的类型 tm_ ic_ icp_
* @param {*} item 订单信息 包含buyerMoblie
* @param {*} pushServiceItemCode 推送的产品id
* @param {*} pobj
* @param {*} req
*/
async pushFqBusiness(pushType, item, pushServiceItemCode, pobj, req) {
var rc = system.getObject("util.aliyunClient");
var rtn = null;
var reqUrl = "https://yunfuapi.gongsibao.com/crm/order/submit";
// var reqUrl = "https://yunfuapi.gongsibao.com/crm/order/submit";//线上域名
var reqUrl = "https://yunfuapi-dev.gongsibao.com/crm/order/submit";//域名
try {
var body = {
idempotentId: item.channelServiceNo,// 是 业务 ID
idempotentSource: req.app.appSourceCode ? "tm_" + req.app.appSourceCode : "tm_1688",// 是 业务来源(ali、jd)
idempotentId: item.needNo,// 是 业务 ID
idempotentSource: req.app.appSourceCode ? pushType + req.app.appSourceCode : "tm_1688",// 是 业务来源(ali、jd)
idempotentSourceName: req.app.name || "1688应用",// 是 阿里,京东
city: "",// 否 所属城市
phone: action_body.buyerMoblie,// 是 手机号
phone: item.buyerMoblie,// 是 手机号
userId: item.channelUserId,// 否 用户 ID
companyName: "",// 否 公司名称
orderPrice: item.totalSum,// 是 订单金额
productId: "5dd513db4f3b08000a6fc082",// 是 产品 ID
productId: pushServiceItemCode,// 是 产品 ID
productQuantity: item.salesNum,// 是 产品数量
};
rtn = await rc.post(reqUrl, body);
......@@ -512,11 +649,9 @@ class OrderService extends ServiceBase {
clientIp: pobj.clientIp,
optitle: "推送订单商机到FQ信息",
});
if (rtn.code != 200 && rtn.success != true) {
return system.getResult(null, "推送失败,失败原因:" + rtn.errorMsg + ",selfrequestId=" + req.requestId + ",requestId=" + rtn.requestId);
}
await this.updateByWhere({ buyerMoblie: action_body.buyerMoblie }, { where: { channelServiceNo: action_body.channelServiceNo } });
return system.getResultSuccess(null, "推送成功");
} catch (e) {
//日志记录
......
......@@ -210,6 +210,7 @@ class OrderTmProductService extends ServiceBase {
var orderAmount = tm;
orderAmount.salesNum = tm.nclOneCodes.length;
orderAmount.minitermNum = tm.nclCount;
channelOrder.payStatus = "dfk";
var orderResult = await self.orderDao.addOrder(ordercode, orderType, user, app, productItem, channelOrder, channelUser, apply, orderAmount, t);
if (orderResult.status != 0) {
return orderResult;
......
......@@ -141,11 +141,11 @@ class System {
var bucketlist = notice_count.buckets;
var bucklist = [];
bucketlist.forEach(function (d) {
var notice_issue=d.key;
var date=d.date_max.value;
var data={
notice_issue:notice_issue,
date:date
var notice_issue = d.key;
var date = d.date_max.value;
var data = {
notice_issue: notice_issue,
date: date
}
bucklist.push(data);
})
......@@ -200,7 +200,7 @@ class System {
var objabspath = classpath + "/" + filename + ".js";
if (System.objTable[objabspath] != null) {
console.log(objabspath,"get cached obj....");
console.log(objabspath, "get cached obj....");
return System.objTable[objabspath];
} else {
console.log("no cached...");
......@@ -309,4 +309,7 @@ System.signFail = 1300;
//获取访问token失败
System.getAppInfoFail = 1130;
//已经存在信息
System.existData = 1400;
module.exports = System;
\ No newline at end of file
......@@ -2,8 +2,8 @@ const Client = require('aliyun-api-gateway').Client;
var RPCClient = require('@alicloud/pop-core').RPCClient;
// const client = new Client('203756805', 'crkyej0xlmqa6bmvqijun6ltxparllyn');
const client = new Client('203763771', 'e5e2ytnn6nrkr9qnqk4w5e6z0xlhkznu');
const client = new Client('203756805', 'crkyej0xlmqa6bmvqijun6ltxparllyn');
// const client = new Client('203763771', 'e5e2ytnn6nrkr9qnqk4w5e6z0xlhkznu');//线上
class aliyunClient {
constructor() {
// this.aliReqUrl = "https://aliapi.gongsibao.com/tm/springboard";
......
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