Commit b085f798 by 孙亚楠

Merge branch 'xggsve-order-dev' of gitlab.gongsibao.com:jiangyong/zhichan into xggsve-order-dev

parents c773cea6 6fb6bc63
......@@ -56,6 +56,7 @@ module.exports = (db, DataTypes) => {
deliverNo: DataTypes.STRING,
deliverImg: DataTypes.STRING,
productItems: DataTypes.STRING,
completeFile: DataTypes.STRING,
}, {
paranoid: true, //假的删除
underscored: true,
......
......@@ -879,6 +879,7 @@ class IborderService extends ServiceBase {
deliverType: self.trim(params.deliverType),
deliverNo: self.trim(params.deliverNo),
deliverImg: self.trim(params.deliverImg),
completeFile: self.trim(params.completeFile),
}
await self.dao.update(orderFields, t);
await self.businessmenDao.update({
......
......@@ -272,21 +272,85 @@ class IborderdeliverService extends ServiceBase {
this.addWhereTime(where, 'created_at', params.createdBegin, params.createdEnd);
var page = await this.getPageList(currentPage, pageSize, where, orderby);
if (page && page.rows) {
await this.setOrder(page.rows, "`id`, `legalName`, `legalMobile`, `price`, `idcard`, `productItems` ");
for (var row of page.rows) {
await this.dao.setRowCodeName(row, "status");
// 下一个状态
var nextObj = await this.orderBusinessStatus.findOrderNextBusinessStatus(row.status);
row.nextStatus = nextObj.status;
row.nextStatusName = nextObj.name;
await this.setNextStatus(row);
// var nextObj = await this.orderBusinessStatus.findOrderNextBusinessStatus(row.status);
// row.nextStatus = nextObj.status;
// row.nextStatusName = nextObj.name;
this.handleDate(row, ["created_at"], null, -8);
}
await this.setOrder(page.rows, "`id`, `legalName`, `legalMobile`, `price`, `idcard`");
}
return system.getResultSuccess(page);
}
async setNextStatus(row) {
if (!row) {
return;
}
let items = this.trim(row.productItems);
if (items) {
let itemArr = items.split(",");
// 当前订单状态
let curStatus = row.status;
let nextStatus = "";
if (curStatus == "1030") {
if(itemArr.indexOf("1050") != -1) {
nextStatus = "1050";
} else if (itemArr.indexOf("1070") != -1) {
nextStatus = "1070";
} else if (itemArr.indexOf("1090") != -1) {
nextStatus = "1090";
} else if (itemArr.indexOf("1110") != -1) {
nextStatus = "1110";
} else {
nextStatus = await this.orderBusinessStatus.findOrderNextBusinessStatus(curStatus);
}
} else if(curStatus == "1050") {
if (itemArr.indexOf("1070") != -1) {
nextStatus = "1070";
} else if (itemArr.indexOf("1090") != -1) {
nextStatus = "1090";
} else if (itemArr.indexOf("1110") != -1) {
nextStatus = "1110";
} else {
nextStatus = await this.orderBusinessStatus.findOrderNextBusinessStatus(curStatus);
}
} else if (curStatus == "1070") {
if (itemArr.indexOf("1090") != -1) {
nextStatus = "1090";
} else if (itemArr.indexOf("1110") != -1) {
nextStatus = "1110";
} else {
nextStatus = await this.orderBusinessStatus.findOrderNextBusinessStatus(curStatus);
}
} else if (curStatus == "1090") {
if (itemArr.indexOf("1110") != -1) {
nextStatus = "1110";
} else {
nextStatus = await this.orderBusinessStatus.findOrderNextBusinessStatus(curStatus);
}
} else {
nextStatus = await this.orderBusinessStatus.findOrderNextBusinessStatus(curStatus);
}
var nextObj = await this.orderBusinessStatus.findOrderBusinessStatus(nextStatus);
row.nextStatus = nextObj.status;
row.nextStatusName = nextObj.name;
return;
}
var nextObj = await this.orderBusinessStatus.findOrderNextBusinessStatus(row.status);
row.nextStatus = nextObj.status;
row.nextStatusName = nextObj.name;
}
async setOrder(rows, attrs) {
if (!rows || rows.length == 0) {
return;
......
......@@ -350,6 +350,41 @@ class IborderdkService extends ServiceBase {
return system.getResult(null,`系统错误 错误信息 ${error}`);
}
}
async orderPage(params) {
let currentPage = Number(params.currentPage || 1);
let pageSize = Number(params.pageSize || 10);
let statuses = params.statuses;
var where = {};
var orderby = [
["id", 'desc']
];
if (params.id) {
where.id = params.id;
}
if (statuses && statuses.length > 0) {
where.status = {
[this.db.Op.in]: statuses
}
}
this.addWhereTime(where, 'created_at', params.createdBegin, params.createdEnd);
var page = await this.getPageList(currentPage, pageSize, where, orderby, null);
if (page && page.rows) {
for (var row of page.rows) {
await this.dao.setRowCodeName(row, "status");
this.handleDate(row, ["created_at"], null, -8);
}
}
return system.getResultSuccess(page);
}
}
module.exports = IborderdkService;
......@@ -6,6 +6,184 @@ const moment = require("moment");
class IborderdzService extends ServiceBase {
constructor() {
super("order", ServiceBase.getDaoName(IborderdzService));
this.iborderbaseDao = system.getObject("db.order.iborderbaseDao");
this.businessmenDao = system.getObject("db.business.businessmenDao");
}
/**
* 创建订单
* @param {*} params
*/
async createOrder(params, t) {
try {
if (!params.merchantId) {
return system.getResult(null, `参数错误 商户ID不能为空`);
}
if (!params.businessmentId) {
return system.getResult(null, `参数错误 个体户ID不能为空`);
}
if (!params.orderpayId) {
return system.getResult(null, `参数错误 支付ID不能为空`);
}
if (!Number(params.price) < 0) {
return system.getResult(null, `参数错误 订单金额格式错误`);
}
this.trimObject(params);
let _ibOrderDk = await this.dao.create(params, t);
return system.getResult(_ibOrderDk);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/**
* 更新数据
* @param {*} params
* @param {*} t
*/
async updateOrder(params, t) {
try {
if (!params.id) {
return system.getResult(null, `参数错误 ID 不能为空`);
}
this.trimObject(params);
return await this.dao.update(params, t);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/**
* 完善信息
* @param {*} params
* legalName
* legalMobile
* names
* creditCode
* isBank
* businessScope
*/
async completedOrder(params) {
try {
//1 检查个体户是否存在 (根据统一社会信用代码查个体工商户是否存在)
this.trimObject(params);
if (!params.id) {
return system.getResult(null, `参数错误 ID 不能为空`);
}
if (!params.legalName) {
return system.getResult(null, `参数错误 法人姓名不能为空`);
}
if (!params.legalMobile) {
return system.getResult(null, `参数错误 法人电话不能为空`);
}
if (!params.creditCode) {
return system.getResult(null, `参数错误 法人统一社会信用代码不能为空`);
}
if (!params.names) {
return system.getResult(null, `参数错误 个体户名称不能为空`);
}
if (!params.businessScope) {
return system.getResult(null, `参数错误 经营范围不能为空`);
}
//2 如果不存在添加保存个体户 完善信息
let _businessmenRes = await this.businessmenDao.findBusinessmenByCreditCode(this.trim(params.creditCode));
if (_businessmenRes.hasOwnProperty("status")) {
return _businessmenRes;
}
if (_businessmenRes.id) {
//如果用户存在id 直接更新
let _iborderbase = await this.iborderbaseDao.findById(this.trim(params.id));
if (!_iborderbase) {
return system.getResult(null, `参数错误 订单不存在`);
}
let self = this;
//向参数中添加 是否完善信息标识
params.isInfoComplete = 1;
await this.db.transaction(async t => {
//更新主表
await self.iborderbaseDao.update({
businessmen_id: self.trim(_businessmenRes.id),
id: self.trim(params.id), isInfoComplete: 1
}, t);
//更新子表
await this.dao.update(params, t);
});
} else {
let self = this;
await this.db.transaction(async t => {
//如果不存在id 创建后更新
let _businessment = await this.businessmenDao.create(params, t);
//更新主表
await self.iborderbaseDao.update({
businessmen_id: self.trim(_businessment.id), id: self.trim(params.id),
isInfoComplete: 1
}, t);
//更新子表
await this.dao.update(params, t);
});
}
return system.getResultSuccess();
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/**
* 订单办理
* @param {} params
* businessmenId 个体户ID
* id 订单ID
*/
async handing(params) {
try {
let id = Number(params.id);
let baseOrder = this.iborderbaseDao.findById(id);
let order = this.dao.findById(id);
baseOrder.status = "1020";
order.status = "1020";
await baseOrder.save();
await order.save();
return system.getResultSuccess();
} catch (error) {
return system.getResult(null, `系统错误 错误信息${error}`);
}
}
async orderPage(params) {
let currentPage = Number(params.currentPage || 1);
let pageSize = Number(params.pageSize || 10);
let statuses = params.statuses;
var where = {};
var orderby = [
["id", 'desc']
];
if (params.id) {
where.id = params.id;
}
if (statuses && statuses.length > 0) {
where.status = {
[this.db.Op.in]: statuses
}
}
this.addWhereTime(where, 'created_at', params.createdBegin, params.createdEnd);
var page = await this.getPageList(currentPage, pageSize, where, orderby, null);
if (page && page.rows) {
for (var row of page.rows) {
await this.dao.setRowCodeName(row, "status");
this.handleDate(row, ["created_at"], null, -8);
}
}
return system.getResultSuccess(page);
}
}
......
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