import BaseService from "../baseService";
|
import { BaseProductInfo } from "../../entity/basicInfo/base/baseProductInfo";
|
import { BasePosition } from "../../entity/basicInfo/base/basePosition";
|
import { Not } from "typeorm";
|
|
/**
|
* 物料信息
|
*/
|
export default class ProductInfoService extends BaseService {
|
/**
|
* 添加保存前事件
|
*/
|
public async onAddSaveBefore(t: BaseProductInfo) {
|
let userInfo = await this.userInfo;
|
this.info.result = true;
|
|
//#region 版本权限控制
|
if (!this.ctx.service.common.isSaaSAuth("SKU数量")) {
|
this.info.result = false;
|
this.info.msg = "当前版本不支持该操作";
|
} else {
|
var num = await this.ctx.service.common.getAuthNum("SKU数量");
|
if (num) {
|
var currentCount = await this.dbRead.count(BaseProductInfo, {
|
userProduct_Id: userInfo.userProduct_Id
|
});
|
if (currentCount >= num) {
|
this.info.result = false;
|
this.info.msg = "超出当前版本数量限制,请升级为更高版本!";
|
return this.info;
|
}
|
}
|
}
|
//#endregion
|
|
//自动编码
|
var sku_autoProductCode = await this.ctx.service.common.getConfigBool("sku_autoProductCode");
|
if (sku_autoProductCode && !t.productCode === null) {
|
var productCode = await this.ctx.service.common.getCodeRegular(254);
|
t.productCode = productCode;
|
if (!t.productModel) {
|
t.productModel = t.productCode;
|
}
|
}
|
//物料条码默认同物料编号
|
var sku_barcodeSyncProductCode = await this.ctx.service.common.getConfigBool("sku_barcodeSyncProductCode");
|
if (sku_barcodeSyncProductCode) {
|
t.productModel = t.productCode;
|
}
|
|
//判断货位是否存在
|
if (t.positionName) {
|
let count = await this.dbRead.count(BasePosition, {
|
positionName: t.positionName
|
});
|
if (!count) {
|
this.info.msg = t.positionName + "货位号不存在,无法添加!";
|
this.info.result = false;
|
return this.info;
|
}
|
}
|
|
//是否支持一码多品
|
let sku_barcodeToMultiProduct = await this.ctx.service.common.getConfigBool("sku_barcodeToMultiProduct");
|
//判断条码是否重复
|
if (!sku_barcodeToMultiProduct) {
|
let where: any = {
|
userProduct_Id: t.userProduct_Id,
|
productModel: t.productModel
|
};
|
if (t.product_Id > 0) {
|
where = {
|
userProduct_Id: t.userProduct_Id,
|
productModel: t.productModel,
|
product_Id: Not(t.product_Id)
|
};
|
}
|
// 编辑时排除自己
|
if (t.product_Id) {
|
where["product_Id"] = Not(t.product_Id);
|
}
|
let count = await this.dbRead.count(BaseProductInfo, where);
|
if (count) {
|
this.info.msg = t.productModel + "当前模式是一品一码,【" + t.productModel + "】条码已存在不允许重复添加,无法添加!";
|
this.info.result = false;
|
}
|
}
|
|
return this.info;
|
}
|
}
|