import { default as BaseController } from "../../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { BaseExpressCorp } from "../../../entity/basicInfo/base/baseExpressCorp";
|
import { SysParamValue } from "../../../entity/sys/core/sysParamValue";
|
import { TMSPort } from '../../../entity/express/tms/tmsPort';
|
|
export default class ExpressCorpController extends BaseController {
|
//#region 根据快递公司ID获取快递公司信息
|
/**
|
* 根据快递公司ID获取快递公司信息
|
*/
|
@Post()
|
public async getById() {
|
let { ctx } = this;
|
let body = ctx.body;
|
let userInfo = await ctx.helper.userInfo();
|
let userProduct_Id = userInfo.userProduct_Id;
|
if (!body.id) {
|
this.info.result = false;
|
this.info.msg = "ID不存在";
|
ctx.body = this.info;
|
return;
|
}
|
|
try {
|
let dataList = await this.dbRead.find(BaseExpressCorp, {
|
select: ["expressCorp_Id", "expressCorpCode", "expressCorpName"],
|
where: {
|
expressCorp_Id: body.id,
|
userProduct_Id: userProduct_Id
|
},
|
order: {
|
expressCorp_Id: "ASC"
|
}
|
});
|
|
this.info.result = true;
|
this.info.data = dataList;
|
} catch (error) {
|
this.info.result = false;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 获得快递公司列表
|
/**
|
* 获得快递公司列表
|
*/
|
@Post()
|
public async getList() {
|
let { ctx } = this;
|
let body = ctx.body;
|
let userInfo = await ctx.helper.userInfo();
|
let userProduct_Id = userInfo.userProduct_Id;
|
let where: any = {
|
userProduct_Id: userProduct_Id
|
};
|
if (body.expressCorpType) {
|
where.expressCorpType = body.expressCorpType;
|
}
|
|
try {
|
let dataList = await this.dbRead.find(BaseExpressCorp, {
|
select: ["expressCorp_Id", "expressCorpCode", "expressCorpName"],
|
where: where,
|
order: {
|
expressCorp_Id: "ASC"
|
}
|
});
|
|
this.info.result = true;
|
this.info.data = dataList;
|
} catch (error) {
|
this.info.result = false;
|
this.info.data = error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region getExpressCorpType 获得快递公司类别
|
/**
|
* 获得快递公司类别
|
*/
|
@Post()
|
public async getExpressCorpType() {
|
var modelList = await this.dbRead.find(SysParamValue, {
|
userProduct_Id: (await this.userInfo).userProduct_Id,
|
type_Id: 503,
|
enable: 1
|
});
|
if (modelList.length == 0) {
|
modelList = await this.dbRead
|
.createQueryBuilder(SysParamValue, "t")
|
.where(`type_Id=503 And isnull(userProduct_Id, 0)=0 And enable=1`)
|
.getMany();
|
}
|
if (modelList.length > 0) {
|
this.info.result = true;
|
this.info.data = modelList.map(item => {
|
return {
|
value: item.value01,
|
name: item.value02
|
};
|
});
|
} else {
|
this.info.result = false;
|
this.info.msg = "您还没有添加快递信息!";
|
}
|
this.ctx.body = this.info;
|
}
|
//#endregion
|
/**
|
* 运单根据口岸获取关联下拉框类别
|
*/
|
@Post()
|
public async getWayBillExpressCorpType() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
if (!body.port_Id) {
|
this.info.result = false;
|
this.info.msg = "请先选择口岸!";
|
ctx.body = this.info;
|
return;
|
}
|
//根据口岸ID查询口岸信息
|
let dataInfo = await this.dbRead.findOne(TMSPort, {
|
port_Id: body.port_Id
|
});
|
if (dataInfo) {
|
if (dataInfo.portExpress) {
|
this.info.result = true;
|
let portExpress = JSON.parse(dataInfo.portExpress);
|
this.info.data = ctx.helper.arrayToCase(portExpress);
|
ctx.body = this.info;
|
return;
|
}
|
} else {
|
this.info.result = false;
|
this.info.msg = "口岸信息不存在!";
|
ctx.body = this.info;
|
return;
|
}
|
} catch (ex) {
|
let msg = "异常错误信息:" + ex.message;
|
this.info.result = false;
|
this.info.msg = msg;
|
ctx.body = this.info;
|
return;
|
}
|
}
|
//#endregion
|
}
|