import * as sql from "mssql";
|
import { Post } from "egg-shell-decorators";
|
import { BaseConsignorAddress } from "../../../entity/basicInfo/consignor/baseConsignorAddress";
|
import { BaseProductInfo } from "../../../entity/basicInfo/base/baseProductInfo";
|
import BaseController from "../../baseController";
|
import { BaseCity } from "../../../entity/basicInfo/base/baseCity";
|
import { BaseConsignor } from "../../../entity/basicInfo/consignor/baseConsignor";
|
import { TMSWayBill } from "../../../entity/express/tms/tmsWayBill";
|
import { TMSWayBillReceive } from "../../../entity/express/tms/tmsWayBillReceive";
|
import { TMSIdCard } from "../../../entity/express/tms/tmsIdCard";
|
import { TMSWayBillList } from "../../../entity/express/tms/tmsWayBillList";
|
import { In } from "typeorm";
|
|
/**
|
* 客户端运单管理
|
*/
|
export default class BillController extends BaseController {
|
//#region 获取省信息
|
/**
|
* 获取省信息
|
*/
|
@Post()
|
public async getCity() {
|
try {
|
let cityList = await this.dbRead.find(BaseCity, {
|
parentId: this.body.parentId
|
});
|
this.info.data = cityList;
|
this.info.result = true;
|
this.ctx.body = this.info;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
this.ctx.body = this.info;
|
}
|
}
|
//#endregion
|
|
//#region 根据手机号调取收件地址信息
|
/**
|
* 根据手机号调取收件地址信息
|
*/
|
@Post()
|
public async getConsignorAddress() {
|
let userInfo = await this.userInfo;
|
try {
|
let where =
|
" CHARINDEX(:mobile,mobile)>0 and userProduct_Id=:userProduct_Id and enable=1 and linkmanAttr=:linkmanAttr and consignor_Id=:consignor_Id";
|
let consignorAddressList = await this.dbRead
|
.createQueryBuilder(BaseConsignorAddress, "t")
|
.select(["mobile"])
|
.where(where, {
|
mobile: this.body.mobile,
|
userProduct_Id: userInfo.userProduct_Id,
|
linkmanAttr: this.body.type,
|
consignor_Id: userInfo.consignor_Id
|
})
|
.take(30)
|
.getRawMany();
|
this.info.data = consignorAddressList;
|
this.info.result = true;
|
this.ctx.body = this.info;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
this.ctx.body = this.info;
|
}
|
}
|
@Post()
|
public async getConsignorAddressInfo() {
|
let userInfo = await this.userInfo;
|
try {
|
let consignorAddressList = await this.dbRead.findOne(BaseConsignorAddress, {
|
mobile: this.body.mobile,
|
userProduct_Id: userInfo.userProduct_Id,
|
consignor_Id: userInfo.consignor_Id,
|
enable: 1,
|
linkmanAttr: "寄件人"
|
});
|
this.info.data = consignorAddressList;
|
this.info.result = true;
|
this.ctx.body = this.info;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
this.ctx.body = this.info;
|
}
|
}
|
//#endregion
|
|
//#region 获取寄件人信息
|
@Post()
|
public async getConsignorAddressBill() {
|
let userInfo = await this.userInfo;
|
try {
|
if (!this.body.mobile) {
|
this.info.result = false;
|
this.info.msg = "手机号不能为空";
|
this.ctx.body = this.info;
|
}
|
let dataList = await this.dbRead.find(BaseConsignorAddress, {
|
mobile: this.body.mobile,
|
userProduct_Id: userInfo.userProduct_Id,
|
consignor_Id: userInfo.consignor_Id,
|
enable: 1,
|
linkmanAttr: "寄件人"
|
});
|
this.info.result = true;
|
this.info.data = dataList;
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = ex.message;
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 根据关键词获取订单可选物料信息
|
/**
|
* 根据关键词获取订单可选物料信息
|
*/
|
@Post()
|
public async getChooseBaseProductInfo() {
|
let userInfo = await this.userInfo;
|
try {
|
let where = `(CHARINDEX(:searchText,productModel)>0 or CHARINDEX(:searchText,productName)>0 or CHARINDEX(:searchText,BrandName)>0 or CHARINDEX(:searchText,TypeName)>0 )and userProduct_Id=:userProduct_Id and Auditing=2 `;
|
let dataList = await this.dbRead
|
.createQueryBuilder(BaseProductInfo, "t")
|
.where(where, {
|
userProduct_Id: userInfo.userProduct_Id,
|
searchText: this.body.searchText
|
})
|
.take(50)
|
.getMany();
|
this.info.data = dataList;
|
this.info.result = true;
|
this.ctx.body = this.info;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
this.ctx.body = this.info;
|
}
|
}
|
//#endregion
|
|
//#region 客户端 运单录入
|
/// <summary>
|
/// 客户端 运单录入
|
/// </summary>
|
/// <returns>运单录入</returns>
|
///
|
@Post()
|
public async saveWayBillInfo() {
|
let userInfo = await this.userInfo;
|
try {
|
if (!this.body.wayBillInfo.consignor_Id) {
|
this.info.result = false;
|
this.info.msg = "账号信息不存在";
|
return;
|
}
|
let conInfo = await this.dbRead.findOne(BaseConsignor, {
|
consignor_Id: this.body.wayBillInfo.consignor_Id
|
});
|
let code = "";
|
if (conInfo != null) {
|
// 获得编码
|
const connection: any = await this.dbWrite.connection;
|
let request = new sql.Request(connection.driver.master);
|
request.input("consignor_Id", conInfo.consignor_Id);
|
request.input("user_Id", userInfo.user_Id);
|
request.output("code", sql.NVarChar(2000));
|
let result = await request.execute("sp_GetCodePlateRule");
|
code = result.output.code;
|
|
if (code && this.body.productLine == "标准线") {
|
code = code + "B";
|
} else if (code && this.body.productLine == "专线") {
|
code = code + "E";
|
}
|
}
|
//查询运单号是否已揽收
|
//添加运单表
|
let wayBillInfo = new TMSWayBill();
|
wayBillInfo.consignorName = this.body.wayBillInfo.consignorName;
|
wayBillInfo.consignorCode = this.body.wayBillInfo.consignorCode;
|
wayBillInfo.consignor_Id = this.body.wayBillInfo.consignor_Id;
|
wayBillInfo.wayBillCode = code;
|
wayBillInfo.consigneeName = this.body.wayBillInfo.consigneeName;
|
wayBillInfo.provinceName = this.body.wayBillInfo.ProvinceName;
|
wayBillInfo.province_Id = this.body.wayBillInfo.province_Id;
|
wayBillInfo.cityName = this.body.wayBillInfo.cityName;
|
wayBillInfo.city_Id = this.body.wayBillInfo.city_Id;
|
wayBillInfo.regionName = this.body.wayBillInfo.regionName;
|
wayBillInfo.region_Id = this.body.wayBillInfo.region_Id;
|
wayBillInfo.street = this.body.wayBillInfo.street;
|
wayBillInfo.consigneeAddress = this.body.wayBillInfo.consigneeAddress;
|
wayBillInfo.consigneePostCode = this.body.wayBillInfo.consigneePostCode;
|
wayBillInfo.consigneeMobile = this.body.wayBillInfo.consigneeMobile;
|
wayBillInfo.consigneeIdcard = this.body.wayBillInfo.consigneeIdcard;
|
//weight = this.body.wayBillInfo.weight;
|
wayBillInfo.grossWeight = this.body.wayBillInfo.grossWeight;
|
wayBillInfo.isStoreMate = 0;
|
wayBillInfo.orderType = this.body.wayBillInfo.orderType;
|
wayBillInfo.storage_Id = this.body.wayBillInfo.storage_Id;
|
wayBillInfo.storageName = this.body.wayBillInfo.storageName;
|
wayBillInfo.remark = this.body.wayBillInfo.remark;
|
wayBillInfo.billingName = this.body.wayBillInfo.billingName;
|
wayBillInfo.billingMobile = this.body.wayBillInfo.billingMobile;
|
wayBillInfo.billingAddress = this.body.wayBillInfo.billingAddress;
|
wayBillInfo.expressCorp_Id = null;
|
wayBillInfo.expressCorpName = null;
|
wayBillInfo.port_Id = null;
|
wayBillInfo.portName = null;
|
this.setAccountInfo(wayBillInfo);
|
wayBillInfo.orderStatus = "新建";
|
wayBillInfo.makeWay = "OMS录入";
|
wayBillInfo.collectStatus = null;
|
|
let wayBillReceiveInfo = await this.dbRead.findOne(TMSWayBillReceive, {
|
wayBillCode: wayBillInfo.wayBillCode
|
});
|
|
// 揽收身份证不为空,以揽收为准
|
if (wayBillReceiveInfo != null && wayBillReceiveInfo.consigneeName && wayBillReceiveInfo.consigneeIdcard) {
|
wayBillInfo.consigneeName = wayBillReceiveInfo.consigneeName;
|
wayBillInfo.consigneeIdcard = wayBillReceiveInfo.consigneeIdcard;
|
}
|
await this.dbWrite.save(wayBillInfo);
|
|
//#region 更新收货人手机到身份证库
|
if (this.body.wayBillInfo.consigneeIdcard) {
|
let idcard = await this.dbRead.findOne(TMSIdCard, {
|
idCardCode: this.body.wayBillInfo.consigneeIdcard
|
});
|
if (idcard != null) {
|
var flag = true;
|
if (!idcard.mobile) {
|
idcard.mobile = wayBillInfo.consigneeMobile;
|
flag = false;
|
} else if (!idcard.mobile2 && flag && idcard.mobile != idcard.mobile2) {
|
idcard.mobile2 = wayBillInfo.consigneeMobile;
|
flag = false;
|
} else if (!idcard.mobile3 && flag && idcard.mobile != idcard.mobile3 && idcard.mobile2 != idcard.mobile3) {
|
idcard.mobile3 = wayBillInfo.consigneeMobile;
|
flag = false;
|
}
|
await this.dbWrite.save(idcard);
|
}
|
}
|
//#endregion
|
|
//#region 运单明细处理
|
let quantityOrder = 0; //数量
|
let rowTotal = 0; //金额
|
for (let detailInfo of this.body.wayBillDetails) {
|
let product_Id = detailInfo.product_Id; //物料ID
|
let dataInfo = await this.dbRead.findOne(BaseProductInfo, product_Id); //查询物料信息
|
//添加到TMS_WayBillList表
|
let listInfo = new TMSWayBillList();
|
listInfo.wayBill_Id = wayBillInfo.wayBill_Id;
|
listInfo.product_Id = product_Id;
|
listInfo.productName = detailInfo.productName;
|
listInfo.productCode = dataInfo.productCode;
|
listInfo.productModel = detailInfo.productModel;
|
listInfo.productSpec = detailInfo.productSpec;
|
listInfo.quantityOrder = detailInfo.quantityOrder;
|
listInfo.smallUnit = detailInfo.smallUnit;
|
listInfo.salePrice = detailInfo.salePrice || 0;
|
listInfo.rowTotal = detailInfo.quantityOrder * (detailInfo.salePrice || 0);
|
listInfo.weight = detailInfo.weight;
|
listInfo.grossWeight = detailInfo.weight + 0.1; //以前是加100
|
|
quantityOrder = quantityOrder + listInfo.quantityOrder;
|
rowTotal = rowTotal + listInfo.rowTotal;
|
await this.dbWrite.save(listInfo);
|
}
|
//#endregion
|
|
//#region 修改运单合计数量和合计金额
|
let sqlwhere = `Update TMS_WayBill Set GrandTotal=${rowTotal},TotalQuantityOrder=${quantityOrder},
|
weight =(select sum(weight) from TMS_WayBillList where wayBill_Id =TMS_WayBill.wayBill_Id)
|
Where wayBill_Id =${wayBillInfo.wayBill_Id}`;
|
await this.dbWrite.query(sqlwhere);
|
//#endregion
|
|
if (this.body.saveAddress) {
|
//查收收件人手机
|
let addrInfo = await this.dbRead.findOne(BaseConsignorAddress, {
|
userProduct_Id: userInfo.userProduct_Id,
|
mobile: this.body.wayBillInfo.consigneeMobile,
|
enable: 1,
|
linkmanAttr: "收件人"
|
});
|
if (addrInfo == null) {
|
addrInfo = new BaseConsignorAddress();
|
}
|
addrInfo.consignee = this.body.wayBillInfo.consigneeName;
|
addrInfo.consigneeIdcard = this.body.wayBillInfo.consigneeIdcard;
|
addrInfo.province_Id = this.body.wayBillInfo.province_Id;
|
addrInfo.provinceName = this.body.wayBillInfo.provinceName;
|
addrInfo.city_Id = this.body.wayBillInfo.city_Id;
|
addrInfo.cityName = this.body.wayBillInfo.cityName;
|
addrInfo.region_Id = this.body.wayBillInfo.region_Id;
|
addrInfo.regionName = this.body.wayBillInfo.regionName;
|
addrInfo.consignorName = this.body.wayBillInfo.consignorName;
|
addrInfo.consignorCode = this.body.wayBillInfo.consignorCode;
|
addrInfo.consignor_Id = this.body.wayBillInfo.consignor_Id;
|
addrInfo.street = this.body.wayBillInfo.street;
|
addrInfo.detailAddress = this.body.wayBillInfo.consigneeAddress;
|
addrInfo.mobile = this.body.wayBillInfo.consigneeMobile;
|
addrInfo.enable = 1;
|
addrInfo.linkmanAttr = "收件人";
|
this.setAccountInfo(addrInfo);
|
await this.dbWrite.save(addrInfo);
|
//查询寄件人手机
|
let addressInfo = await this.dbRead.findOne(BaseConsignorAddress, {
|
userProduct_Id: userInfo.userProduct_Id,
|
mobile: this.body.wayBillInfo.billingMobile
|
});
|
if (addressInfo == null) {
|
addressInfo = new BaseConsignorAddress();
|
}
|
addressInfo.consignee = this.body.wayBillInfo.billingName;
|
//addressInfo.consigneeIdcard = this.body.wayBillInfo.consigneeIdcard;
|
//addressInfo.province_Id = this.body.wayBillInfo.province_Id;
|
//addressInfo.provinceName = this.body.wayBillInfo.provinceName;
|
//addressInfo.city_Id = this.body.wayBillInfo.city_Id;
|
//addressInfo.cityName = this.body.wayBillInfo.cityName;
|
//addressInfo.region_Id = this.body.wayBillInfo.region_Id;
|
//addressInfo.regionName = this.body.wayBillInfo.regionName;
|
addressInfo.consignorName = this.body.wayBillInfo.consignorName;
|
addressInfo.consignorCode = this.body.wayBillInfo.consignorCode;
|
addressInfo.consignor_Id = this.body.wayBillInfo.consignor_Id;
|
//addressInfo.street = this.body.wayBillInfo.street;
|
addressInfo.detailAddress = this.body.wayBillInfo.billingAddress;
|
addressInfo.mobile = this.body.wayBillInfo.billingMobile;
|
addressInfo.enable = 1;
|
addressInfo.linkmanAttr = "寄件人";
|
this.setAccountInfo(addressInfo);
|
await this.dbWrite.save(addressInfo);
|
}
|
|
//添加运单追踪记录
|
this.ctx.service.tms.wayBillHelper.setStatusHistory(wayBillInfo, "客户端录入", "客户端录入成功");
|
|
this.info.msg = wayBillInfo.orderStatus;
|
this.info.result = true;
|
this.info.data = wayBillInfo;
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 改变打印状态
|
@Post()
|
public async changePrintStatus() {
|
try {
|
let wayBill_Ids = this.body.wayBill_Ids;
|
if (!Array.isArray(wayBill_Ids) || !wayBill_Ids.length) {
|
this.info.result = false;
|
this.info.msg = "更新打印状态没有执行的数据";
|
return;
|
}
|
await this.dbWrite.update(
|
TMSWayBill,
|
{
|
wayBill_Id: In(wayBill_Ids)
|
},
|
{
|
printStatus: "已打印"
|
}
|
);
|
this.info.result = true;
|
} catch (ex) {
|
this.info.msg = "更新打印状态错误:" + ex.message;
|
this.info.result = false;
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
}
|