//#region import
|
import { default as BaseController } from "../baseController";
|
import * as sql from "mssql";
|
import { Post } from "egg-shell-decorators";
|
import { SaleOuter } from "../../entity/outbound/sale/saleOuter";
|
//#endregion
|
|
/**
|
* 发货校验
|
*/
|
export default class OrderSendController extends BaseController {
|
//#region 校验快递单号
|
@Post()
|
public async checkExpressCode() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
let expressCode = body.expressCode;
|
let scanType = body.scanType;
|
let isNoCheckExpressCorp = body.isNoCheckExpressCorp;
|
let where = "";
|
let whereParam: any = [];
|
|
try {
|
if (isNoCheckExpressCorp) {
|
//不校验快递公司
|
//#region
|
if (scanType == "快递单号") {
|
//快递单号
|
where = " (t.expressCode=@0) AND userProduct_Id=@1";
|
} else if (scanType == "出库单号") {
|
//出库单号
|
where = " (t.orderCode=@0 OR L.orderCode=@0 OR t.storeOrderCode=@0) AND userProduct_Id=@1";
|
} else if (scanType == "波次号") {
|
//波次号
|
where = " (t.orderPrintCode=@0) AND userProduct_Id=@1";
|
} else {
|
where = " (t.expressCode=@0 OR t.orderCode=@0 OR L.orderCode=@0 OR t.storeOrderCode=@0) AND userProduct_Id=@1";
|
}
|
//#endregion
|
} else {
|
//#region
|
if (scanType == "快递单号") {
|
//快递单号
|
where = `(t.expressCode=@0) AND userProduct_Id=@1`;
|
} else if (scanType == "出库单号") {
|
//出库单号
|
where = `
|
(
|
t.orderCode=@0
|
OR L.orderCode=@0 OR t.storeOrderCode=@0
|
) AND userProduct_Id=@1`;
|
} else if (scanType == "波次号") {
|
//波次号
|
where = `
|
(
|
t.orderPrintCode=@0
|
) AND userProduct_Id=@1`;
|
} else {
|
where = `
|
(
|
t.expressCode=@0 OR t.orderCode=@0
|
OR L.orderCode=@0 OR t.storeOrderCode=@0
|
) AND userProduct_Id=@1`;
|
}
|
//#endregion
|
}
|
let sql = "";
|
sql =
|
`
|
SELECT top 1 t.expressCorp_Id, t.IsSend, t.outer_Id,
|
CASE WHEN L.order_Id IS NULL THEN t.order_Id ELSE L.order_Id END AS order_Id,
|
CASE WHEN L.orderCode IS NULL THEN t.orderCode ELSE L.orderCode END AS orderCode,
|
CASE WHEN L.orderCode IS NULL THEN 0 ELSE 1 END AS isBatchOuter --波次出库
|
FROM Sale_Outer t INNER JOIN dbo.Sale_OuterList L ON t.outer_Id=L.outer_Id
|
Where ISNULL(t.IsSend,0)=0 --只查询未发运的单子
|
AND ` + where;
|
|
whereParam = [expressCode, userInfo.userProduct_Id];
|
let dt = await this.dbRead.query(sql, whereParam);
|
if (dt.length > 0) {
|
this.info.result = true;
|
this.info.data = {
|
order_Id: dt[0]["order_Id"],
|
outer_Id: dt[0]["outer_Id"],
|
orderCode: dt[0]["orderCode"],
|
isBatchOuter: dt[0]["isBatchOuter"]
|
};
|
} else {
|
this.info.result = false;
|
this.info.msg = "快递单号不存在!";
|
}
|
} catch (error) {
|
this.info.msg = "错误:" + error.message;
|
this.info.result = false;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 订单校验
|
@Post()
|
public async orderSave() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
try {
|
let saleOuter = await this.dbRead.findOne(SaleOuter, body.outer_Id);
|
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("isNoCheckExpressCorp", body.isNoCheckExpressCorp);
|
request.input("expressCode", body.expressCode);
|
request.input("expressCorp_Id", body.expressCorp_Id);
|
request.input("weight", body.weight);
|
request.input("user_Id", userInfo.user_Id);
|
request.input("outer_Id", body.outer_Id);
|
request.output("outMsg", sql.NVarChar(2000));
|
let result = await request.execute("sp_Sale_SendScan");
|
let outMsg = result.output.outMsg;
|
|
if (outMsg) {
|
this.info.msg = outMsg;
|
this.info.result = false;
|
ctx.body = this.info;
|
return;
|
} else {
|
this.info.msg = "打包单号" + saleOuter.outerCode + "发货成功。";
|
this.info.result = true;
|
this.info.data = {
|
orderCode: saleOuter.outerCode,
|
expressCode: saleOuter.expressCode,
|
shippingName: saleOuter.shippingName,
|
shippingAddress: saleOuter.shippingAddress,
|
weight: body.weight || 0
|
};
|
}
|
} catch (error) {
|
this.info.msg = "错误:" + error.message;
|
this.info.result = false;
|
}
|
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|