Commit 06c8ac57 by gxfeng

新增创建服务实例

parent fd68779d
...@@ -9,6 +9,7 @@ const appconfig = system.getSysConfig(); ...@@ -9,6 +9,7 @@ const appconfig = system.getSysConfig();
class DeliverybillCtl extends CtlBase { class DeliverybillCtl extends CtlBase {
constructor() { constructor() {
super("bizchance", CtlBase.getServiceName(DeliverybillCtl)); super("bizchance", CtlBase.getServiceName(DeliverybillCtl));
this.logService = system.getObject("service.bizchance.statuslogSve");
} }
/** /**
...@@ -139,5 +140,70 @@ class DeliverybillCtl extends CtlBase { ...@@ -139,5 +140,70 @@ class DeliverybillCtl extends CtlBase {
return system.getResult(null, err.message) return system.getResult(null, err.message)
} }
} }
// 创建服务实例
async insertInfo(pobj, qobj, req) {
// console.log(pobj);
// 检验各项必传参数
if (pobj.requestId && pobj.requestId != 'undefined' &&
pobj.bizId && pobj.bizId != 'undefined' &&
pobj.contactsPhone && pobj.contactsPhone != 'undefined' &&
pobj.userId && pobj.userId != 'undefined' &&
pobj.orderId && pobj.orderId != 'undefined' &&
pobj.areaType && pobj.areaType != 'undefined' &&
pobj.area && pobj.area != 'undefined' &&
pobj.topOrgCode && pobj.topOrgCode != 'undefined' &&
pobj.taxpayerType && pobj.taxpayerType != 'undefined' &&
pobj.product_code && pobj.product_code != 'undefined' &&
pobj.product_name && pobj.product_name != 'undefined' &&
pobj.service_address && pobj.service_address != 'undefined' &&
pobj.delivery_status && pobj.delivery_status != 'undefined' &&
pobj.facilitator_id && pobj.facilitator_id != 'undefined') {
try {
// console.log(pobj);
var buInfo = await this.service.insertInfo(pobj);
var logInfo = {
"flowType": "DELIVERY",
"flowId": buInfo.id,
"statusCode": buInfo.delivery_status,
"status_reason": ""
}
await this.logService.insertInfo(logInfo);//插入状态日至表
return system.getResult(buInfo);
} catch (error) {
// console.log(error);
return system.getResultError(error);
}
} else {
return system.getResultError("参数错误!");
}
}
} }
module.exports = DeliverybillCtl; module.exports = DeliverybillCtl;
\ No newline at end of file
var task = new DeliverybillCtl();
var obj = {
"orderId": "341184456620455_book",
"source_number": "tx",
"demand_code": "demand_code",
"sku_code": "sku_code",
"solutionBizId": "scheme_number",
"product_code": "bookkeeping",
"product_name": "代账服务",
"service_address": "110100",
"delivery_status": "success",
"facilitator_id": "10",
"facilitator_name": "公司宝",
"source_name": "tencentCloud",
"requestId": "282da0a74432-738f-4bed-b48d-d51aa433",
"bizId": "1292748632",
"contactsPhone": "18510669321",
"userId": "10973452443103156",
"areaType": "city",
"area": "100010",
"topOrgCode": "rong_yi_suan",
"taxpayerType": 1
};
task.insertInfo(obj, {}, {}).then(d => {
console.log(JSON.stringify(d));
})
\ No newline at end of file
...@@ -67,5 +67,124 @@ class DeliverybillDao extends Dao { ...@@ -67,5 +67,124 @@ class DeliverybillDao extends Dao {
qc.where["$and"] = filters; qc.where["$and"] = filters;
return qw; return qw;
} }
async insertInfo(qobj, t) {
// console.log("dao层qobj===>");
// console.log(qobj);
var obj = {
"delivery_code": qobj.orderId,
"product_code": qobj.product_code,
"product_name": qobj.product_name,
"service_address": qobj.service_address,
"delivery_status": qobj.delivery_status,
"facilitator_id": qobj.facilitator_id,
"biz_id": qobj.bizId
};
// source_number
if (qobj.source_number && qobj.source_number != 'undefined') {
obj.source_number = qobj.source_number;
delete qobj.source_number;
}
// demand_code
if (qobj.demand_code && qobj.demand_code != 'undefined') {
obj.demand_code = qobj.demand_code;
delete qobj.demand_code;
}
// sku_code
if (qobj.sku_code && qobj.sku_code != 'undefined') {
obj.sku_code = qobj.sku_code;
delete qobj.sku_code;
}
// scheme_number
if (qobj.solutionBizId && qobj.solutionBizId != 'undefined') {
obj.scheme_number = qobj.solutionBizId;
delete qobj.solutionBizId;
}
// selling_price
if (qobj.selling_price && qobj.selling_price != 'undefined') {
obj.selling_price = qobj.selling_price;
delete qobj.selling_price;
}
// cost_price
if (qobj.cost_price && qobj.cost_price != 'undefined') {
obj.cost_price = qobj.cost_price;
delete qobj.cost_price;
}
// close_reason
if (qobj.close_reason && qobj.close_reason != 'undefined') {
obj.close_reason = qobj.close_reason;
delete qobj.close_reason;
}
// facilitator_name
if (qobj.facilitator_name && qobj.facilitator_name != 'undefined') {
obj.facilitator_name = qobj.facilitator_name;
delete qobj.facilitator_name;
}
// salesman_opcode
if (qobj.salesman_opcode && qobj.salesman_opcode != 'undefined') {
obj.salesman_opcode = qobj.salesman_opcode;
delete qobj.salesman_opcode;
}
// salesman_id
if (qobj.salesman_id && qobj.salesman_id != 'undefined') {
obj.salesman_id = qobj.salesman_id;
delete qobj.salesman_id;
}
// salesman_name
if (qobj.salesman_name && qobj.salesman_name != 'undefined') {
obj.salesman_name = qobj.salesman_name;
delete qobj.salesman_name;
}
// salesman_phone
if (qobj.salesman_phone && qobj.salesman_phone != 'undefined') {
obj.salesman_phone = qobj.salesman_phone;
delete qobj.salesman_phone;
}
// source_name
if (qobj.source_name && qobj.source_name != 'undefined') {
obj.source_name = qobj.source_name;
delete qobj.source_name;
}
// master_source_number
if (qobj.master_source_number && qobj.master_source_number != 'undefined') {
obj.master_source_number = qobj.master_source_number;
delete qobj.master_source_number;
}
// settle_status
if (qobj.settle_status && qobj.settle_status != 'undefined') {
obj.settle_status = qobj.settle_status;
delete qobj.settle_status;
}
// settlebill_id
if (qobj.settlebill_id && qobj.settlebill_id != 'undefined') {
obj.settlebill_id = qobj.settlebill_id;
delete qobj.settlebill_id;
}
// delivery_man_id
if (qobj.delivery_man_id && qobj.delivery_man_id != 'undefined') {
obj.delivery_man_id = qobj.delivery_man_id;
delete qobj.delivery_man_id;
}
// delivery_man_name
if (qobj.delivery_man_name && qobj.delivery_man_name != 'undefined') {
obj.delivery_man_name = qobj.delivery_man_name;
delete qobj.delivery_man_name;
}
// delivery_man_opcode
if (qobj.delivery_man_opcode && qobj.delivery_man_opcode != 'undefined') {
obj.delivery_man_opcode = qobj.delivery_man_opcode;
delete qobj.delivery_man_opcode;
}
delete qobj.orderId;
delete qobj.product_code;
delete qobj.product_name;
delete qobj.service_address;
delete qobj.delivery_status;
delete qobj.facilitator_id;
obj.delivery_info = qobj;
// console.log("dao层obj===>");
// console.log(obj);
return await this.create(obj, t);
}
} }
module.exports = DeliverybillDao; module.exports = DeliverybillDao;
...@@ -4,235 +4,241 @@ const settings = require("../../../../config/settings"); ...@@ -4,235 +4,241 @@ const settings = require("../../../../config/settings");
const System = require("../../../system"); const System = require("../../../system");
const appconfig = system.getSysConfig(); const appconfig = system.getSysConfig();
class DeliverybillService extends ServiceBase { class DeliverybillService extends ServiceBase {
constructor() { constructor() {
super("bizchance", ServiceBase.getDaoName(DeliverybillService)); super("bizchance", ServiceBase.getDaoName(DeliverybillService));
this.logService = system.getObject("service.bizchance.statuslogSve"); this.logService = system.getObject("service.bizchance.statuslogSve");
this.fitaxschemeDao = system.getObject("service.bizchance.fitaxschemeDao"); this.fitaxschemeDao = system.getObject("service.bizchance.fitaxschemeDao");
this.bizoptDao = system.getObject("service.bizchance.bizoptDao"); this.bizoptDao = system.getObject("service.bizchance.bizoptDao");
this.operationrecordDao = system.getObject("service.bizchance.operationrecordDao"); this.operationrecordDao = system.getObject("service.bizchance.operationrecordDao");
} }
async updateOrderStatus(pobj) { async updateOrderStatus(pobj) {
let deliverData = await this.dao.findOne({ let deliverData = await this.dao.findOne({
id: pobj.deliverId id: pobj.deliverId
}); });
if (!deliverData) { if (!deliverData) {
throw new Error("查不到此交付单"); throw new Error("查不到此交付单");
}
if (deliverData.delivery_status !== system.SERVERSESTATUS.RECEIVED) {
throw new Error("该状态下不可处理");
}
let updateResult = {};
let { delivery_info } = deliverData;
if (pobj.orderStaus === true) {
updateResult = {
delivery_info: {
...delivery_info,
setupAt: pobj.setupAt//建账时间
},
delivery_status: system.SERVERSESTATUS.WAITUSERCONFIRM
}
}
if (pobj.orderStaus === false) {
updateResult = {
delivery_status: system.SERVERSESTATUS.CLOSED,
close_reason: pobj.note
}
}
await this.dao.updateByWhere(updateResult, {
id: pobj.deliverId
});
this.logService.insertInfo({
flowType: system.FLOWCODE.DELIVERY,
flowId: pobj.deliverId,
statusCode: updateResult.delivery_status,
clerkName: pobj.userid,
clerkId: pobj.username
});
return "SUCCESS"
} }
if (deliverData.delivery_status !== system.SERVERSESTATUS.RECEIVED) {
async setupBill(pobj) { throw new Error("该状态下不可处理");
let deliverData = await this.dao.findOne({ }
id: pobj.deliverId let updateResult = {};
}); let { delivery_info } = deliverData;
if (!deliverData) { if (pobj.orderStaus === true) {
throw new Error("查不到此交付单"); updateResult = {
} delivery_info: {
if (deliverData.delivery_status !== system.SERVERSESTATUS.INSERVICE) { ...delivery_info,
throw new Error("该状态下不可建账"); setupAt: pobj.setupAt//建账时间
} },
await this.dao.updateByWhere({ delivery_status: system.SERVERSESTATUS.WAITUSERCONFIRM
delivery_info: { }
...delivery_info,
setupStatus: system.SERVERSESTATUS.SETUP,
setupInfo: {
contactsName: pobj.contactsName,
time: pobj.time,
accountingType: pobj.accountingType,
taxpayerType: pobj.taxpayerType,
supplier: pobj.supplier
}
}
}, {
id: pobj.deliverId
});
return "SUCCESS"
} }
if (pobj.orderStaus === false) {
updateResult = {
delivery_status: system.SERVERSESTATUS.CLOSED,
close_reason: pobj.note
}
}
await this.dao.updateByWhere(updateResult, {
id: pobj.deliverId
});
this.logService.insertInfo({
flowType: system.FLOWCODE.DELIVERY,
flowId: pobj.deliverId,
statusCode: updateResult.delivery_status,
clerkName: pobj.userid,
clerkId: pobj.username
});
return "SUCCESS"
}
async deliverInfo(pobj) { async setupBill(pobj) {
let result = {}; let deliverData = await this.dao.findOne({
let deliverData = await this.dao.findOne({ id: pobj.deliverId
id: pobj.deliverId });
}); if (!deliverData) {
if (!deliverData) { throw new Error("查不到此交付单");
throw new Error("查不到此交付单"); }
} if (deliverData.delivery_status !== system.SERVERSESTATUS.INSERVICE) {
result.deliverData = { throw new Error("该状态下不可建账");
deliveryId: deliverData.id, // id }
deliveryNumber: deliverData.delivery_code, // 交付单编号 await this.dao.updateByWhere({
companyName: deliverData.delivery_info.companyName,// 企业名称 delivery_info: {
uscc: deliverData.delivery_info.uscc, //统一信用代码 ...delivery_info,
taxpayerType: delivery_info.taxpayerType, //纳税人类型 1 一般;2 小规模 setupStatus: system.SERVERSESTATUS.SETUP,
//会计准侧 setupInfo: {
companyBizType: delivery_info.companyBizType,// 公司类型 1-商贸型;2-服务型;3-特殊行业;4-其他 contactsName: pobj.contactsName,
areaType: delivery_info.areaType, //区域类型 city-城市 time: pobj.time,
area: service_address, // 服务 地区 编码 accountingType: pobj.accountingType,
contactsName: delivery_info.contactsName,// 联系人 taxpayerType: pobj.taxpayerType,
contactsPhone: delivery_info.contactsPhone,// 联系电话 supplier: pobj.supplier
owner: salesman_name,//所属人
deliveryStatus: delivery_status, // 交付单状态
setupStatus: delivery_info.setupStatus || System.SERVERSESTATUS.NOTSETUP,//建账状态 notsetup | setup
createdAt: created_at,
updatedAt: updated_at,
} }
if (deliverData.scheme_number) { }
let schemeData = await this.fitaxschemeDao.findOne({ }, {
solution_bizid: deliverData.scheme_number id: pobj.deliverId
}); });
if (schemeData) { return "SUCCESS"
result.schemeData = { }
demandCode: schemeData.demand_code, // 需求编号
schemeCode: deliverData.scheme_number,//方案编号 async deliverInfo(pobj) {
// 服务类型 let result = {};
companyType: schemeData.company_type,//公司类型 let deliverData = await this.dao.findOne({
area: schemeData.service_name,//服务地区 id: pobj.deliverId
buyDuration: schemeData.buy_duration,//购买时长 });
buyNumber: schemeData.number,//购买数量 if (!deliverData) {
totalCost: schemeData.total_cost,//总计费用 throw new Error("查不到此交付单");
note: schemeData.remarks//备注 }
} result.deliverData = {
} deliveryId: deliverData.id, // id
deliveryNumber: deliverData.delivery_code, // 交付单编号
companyName: deliverData.delivery_info.companyName,// 企业名称
uscc: deliverData.delivery_info.uscc, //统一信用代码
taxpayerType: delivery_info.taxpayerType, //纳税人类型 1 一般;2 小规模
//会计准侧
companyBizType: delivery_info.companyBizType,// 公司类型 1-商贸型;2-服务型;3-特殊行业;4-其他
areaType: delivery_info.areaType, //区域类型 city-城市
area: service_address, // 服务 地区 编码
contactsName: delivery_info.contactsName,// 联系人
contactsPhone: delivery_info.contactsPhone,// 联系电话
owner: salesman_name,//所属人
deliveryStatus: delivery_status, // 交付单状态
setupStatus: delivery_info.setupStatus || System.SERVERSESTATUS.NOTSETUP,//建账状态 notsetup | setup
createdAt: created_at,
updatedAt: updated_at,
}
if (deliverData.scheme_number) {
let schemeData = await this.fitaxschemeDao.findOne({
solution_bizid: deliverData.scheme_number
});
if (schemeData) {
result.schemeData = {
demandCode: schemeData.demand_code, // 需求编号
schemeCode: deliverData.scheme_number,//方案编号
// 服务类型
companyType: schemeData.company_type,//公司类型
area: schemeData.service_name,//服务地区
buyDuration: schemeData.buy_duration,//购买时长
buyNumber: schemeData.number,//购买数量
totalCost: schemeData.total_cost,//总计费用
note: schemeData.remarks//备注
} }
return result }
} }
return result
}
async distributionPerson(pobj) { async distributionPerson(pobj) {
let { numbers, nickName, userId, opCode, phone, type } = pobj; // let { numbers, nickName, userId, opCode, phone, type } = pobj;
switch (type) { // switch (type) {
case System.FLOWCODE.DELIVERY: // case System.FLOWCODE.DELIVERY:
let datas = await this.dao.findAll({ // let datas = await this.dao.findAll({
delivery_code: { // delivery_code: {
$in: numbers // $in: numbers
} // }
}); // });
if (datas.length !== numbers.length) { // if (datas.length !== numbers.length) {
throw new Error("请检查单号是否正确"); // throw new Error("请检查单号是否正确");
} // }
await this.dao.updateByWhere({ // await this.dao.updateByWhere({
salesman_id: userId, // salesman_id: userId,
salesman_opcode: opCode, // salesman_opcode: opCode,
salesman_phone: phone, // salesman_phone: phone,
salesman_name: nickName // salesman_name: nickName
}, { // }, {
delivery_code: { // delivery_code: {
$in: numbers // $in: numbers
} // }
}); // });
// 插入 流转 记录 // // 插入 流转 记录
let logs = []; // let logs = [];
for (let val of datas) { // for (let val of datas) {
logs.push({ // logs.push({
demand_code: val.delivery_code, // demand_code: val.delivery_code,
operator: { // operator: {
id: pobj.userid, // id: pobj.userid,
username: pobj.username // username: pobj.username
}, // },
operation_type: "distribution", // operation_type: "distribution",
operation_details: { // operation_details: {
isFirst: val.salesman_id ? true : false, // isFirst: val.salesman_id ? true : false,
fromUserId: val.salesman_id, // fromUserId: val.salesman_id,
fromUserName: val.salesman_name, // fromUserName: val.salesman_name,
toUserId: userId, // toUserId: userId,
toUserName: nickName // toUserName: nickName
}, // },
order_type: System.FLOWCODE.DELIVERY // order_type: System.FLOWCODE.DELIVERY
}) // })
} // }
this.operationrecordDao.bulkCreate(logs); // this.operationrecordDao.bulkCreate(logs);
break // break
case System.FLOWCODE.BIZ: // case System.FLOWCODE.BIZ:
let datas = await this.bizoptDao.findAll({ // let datas = await this.bizoptDao.findAll({
demand_code: { // demand_code: {
$in: numbers // $in: numbers
} // }
}); // });
if (datas.length !== datas.length) { // if (datas.length !== datas.length) {
throw new Error("请检查单号是否正确"); // throw new Error("请检查单号是否正确");
} // }
return this.db.transaction(async (t) => { // return this.db.transaction(async (t) => {
// 更新 操作人 // // 更新 操作人
await this.bizoptDao.updateByWhere({ // await this.bizoptDao.updateByWhere({
salesman_id: userId, // salesman_id: userId,
salesman_opcode: opCode, // salesman_opcode: opCode,
salesman_phone: phone, // salesman_phone: phone,
salesman_name: nickName // salesman_name: nickName
}, { // }, {
demand_code: { // demand_code: {
$in: numbers // $in: numbers
} // }
}, t); // }, t);
// 更新 状态 // // 更新 状态
await this.bizoptDao.updateByWhere({ // await this.bizoptDao.updateByWhere({
business_status: "beforeFollowUp" // business_status: "beforeFollowUp"
}, { // }, {
$and: [ // $and: [
{ // {
demand_code: { // demand_code: {
$in: numbers // $in: numbers
} // }
}, { // }, {
business_status: "received" // business_status: "received"
} // }
] // ]
}, t); // }, t);
// 插入 流转 记录 // // 插入 流转 记录
let logs = []; // let logs = [];
for (let val of datas) { // for (let val of datas) {
logs.push({ // logs.push({
demand_code: val.demand_code, // demand_code: val.demand_code,
operator: { // operator: {
id: pobj.userid, // id: pobj.userid,
username: pobj.username // username: pobj.username
}, // },
operation_type: "distribution", // operation_type: "distribution",
operation_details: { // operation_details: {
isFirst: val.salesman_id ? true : false, // isFirst: val.salesman_id ? true : false,
fromUserId: val.salesman_id, // fromUserId: val.salesman_id,
fromUserName: val.salesman_name, // fromUserName: val.salesman_name,
toUserId: userId, // toUserId: userId,
toUserName: nickName // toUserName: nickName
}, // },
order_type: System.FLOWCODE.BIZ // order_type: System.FLOWCODE.BIZ
}) // })
} // }
this.operationrecordDao.bulkCreate(logs); // this.operationrecordDao.bulkCreate(logs);
return "success" // return "success"
}); // });
break // break
} // }
return "SUCCESS" // return "SUCCESS"
}
} async insertInfo(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj, t);
});
}
} }
module.exports = DeliverybillService; module.exports = DeliverybillService;
\ No newline at end of file
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