//#region import
|
import { default as BaseController } from "../baseController";
|
import * as sql from "mssql";
|
import { Post } from "egg-shell-decorators";
|
import { SaleOrderPrint } from "../../entity/outbound/manufacture/saleOrderPrint";
|
import { vSaleOrderPrintListGroup } from "../../entity/outbound/manufacture/vSaleOrderPrintListGroup";
|
import { SaleOrder } from "../../entity/outbound/sale/saleOrder";
|
import { SaleSendList } from "../../entity/outbound/sale/saleSendList";
|
import { SaleOuter } from "../../entity/outbound/sale/saleOuter";
|
//#endregion
|
|
/**
|
* 收货 - 上架
|
*/
|
export default class OrderSendFastController extends BaseController {
|
//#region 部分发运
|
@Post()
|
public async partialSaveScan() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
let batchCode = body.batchCode;
|
let expressCode = body.expressCode;
|
let wrapperBarcode = body.wrapperBarcode;
|
let newExpressCode = body.newExpressCode;
|
let weight = body.weight || 0;
|
var _expressCode = expressCode || newExpressCode;
|
|
//#region 校验
|
if (!batchCode) {
|
this.info.msg = "波次不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
if (expressCode.IsNullOrEmpty()) {
|
this.info.msg = "快递单号不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
var wrapperBarcodeArray = wrapperBarcode.split("\n").filters(item => item);
|
|
if (body.dataList.length == 0) {
|
this.info.msg = "请先扫描条码!";
|
ctx.body = this.info;
|
return;
|
}
|
|
let orderPrint = await this.dbRead.findOne(SaleOrderPrint, {
|
orderPrintCode: body.orderPrintCode,
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (orderPrint) {
|
this.info.msg = "波次不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
|
let where = "orderPrint_Id=:orderPrint_Id AND (expressCode=:expressCode OR orderCode=:expressCode)";
|
let printList = await this.dbRead
|
.createQueryBuilder(vSaleOrderPrintListGroup, "t")
|
.where(where, {
|
orderPrint_Id: orderPrint.orderPrint_Id,
|
expressCode: expressCode
|
})
|
.getOne();
|
if (printList == null) {
|
this.info.msg = "该波次下不存在该快递单!";
|
ctx.body = this.info;
|
}
|
if ((printList.quantityOuter || 0) - (printList.quantityOrder || 0) - (printList.freezeQuanity || 0) >= 0) {
|
this.info.msg = "该订单已经打包完成!";
|
ctx.body = this.info;
|
return;
|
}
|
let outerModel = await this.dbRead.findOne(SaleOuter, {
|
expressCode: expressCode
|
});
|
if (outerModel) {
|
this.info.msg = "该快递单号[" + _expressCode + "]在[打包校验]已经使用过!";
|
ctx.body = this.info;
|
return;
|
}
|
//验证耗材是否正确
|
if (wrapperBarcodeArray.Length > 0) {
|
let sql = `SELECT TOP 1 v.col FROM [dbo].[Func_SplitStrToTable]${wrapperBarcodeArray.Join(",")}) AS v
|
WHERE NOT EXISTS(
|
SELECT * FROM dbo.vBase_ProductInfo_SKU WHERE ProductModel=v.col AND userProduct_Id=${userInfo.userProduct_Id}
|
)`;
|
let notExistsSku = await this.dbRead.query(sql);
|
if (notExistsSku.length) {
|
this.info.msg = "包材[" + notExistsSku[0].col + "]在物料信息中不存在,请先维护好基础数据!";
|
ctx.body = this.info;
|
return;
|
}
|
}
|
let order = await this.dbRead.findOne(SaleOrder, printList.order_Id);
|
if (order == null) {
|
this.info.msg = "波次中的明细订单在销售订单中已经不存在了,订单ID:" + printList.order_Id;
|
ctx.body = this.info;
|
return;
|
}
|
|
let sendListModel = await this.dbRead.findOne(SaleSendList, {
|
expressCode: expressCode
|
});
|
if (sendListModel != null) {
|
this.info.msg = _expressCode + "快递单号已存在,不允许重复使用!";
|
ctx.body = this.info;
|
}
|
//判断出库的物料数量是否大于可以出库的数量
|
let isExistsSql = "";
|
for (var model of body.dataList) {
|
var scanCount = model.scanCount;
|
if (isExistsSql) {
|
isExistsSql += " UNION ";
|
}
|
isExistsSql += ` SELECT productCode,(quantityOrder-ISNULL(quantityOuter,0)) AS enableQty,
|
${scanCount} AS currentQty FROM dbo.Sale_OrderPrintList WHERE orderPrint_Id=${orderPrint.orderPrint_Id}
|
AND orderList_Id=" + orderList_Id + @" AND (quantityOrder-ISNULL(quantityOuter,0)-" + scanCount + ")<0 `;
|
}
|
isExistsSql = `SELECT productCode,enableQty,currentQty FROM (${isExistsSql}) AS v`;
|
let table = await this.dbRead.query(isExistsSql);
|
if (table && table.length > 0) {
|
let row = table[0];
|
this.info.msg = `物料[${row["productCode"]}]的可出库数量[${row["enableQty"]}]小于当前的出库数量[${row["currentQty"]}]!`;
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
let outerCode = await ctx.service.common.getCodeRegular(268);
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("outerCode", outerCode);
|
request.input("order_Id", order.order_Id);
|
request.input("wrapperBarcode", wrapperBarcode);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("weight", weight);
|
request.input("orderPrint_Id", orderPrint.orderPrint_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Sale_SendFast");
|
let outMsg = result.output.outMsg;
|
|
ctx.service.outbound.orderHelper.setStatusHistory(order.order_Id, order.statusID, 12, "订单状态", "闪电发货");
|
this.info.result = true;
|
if (outMsg) {
|
this.info.result = false;
|
this.info.msg = outMsg;
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|