import { default as BaseController } from "../../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { AppProductApply } from "../../../entity/crm/app/appProductApply";
|
import { BaseProductInfo } from "../../../entity/basicInfo/base/baseProductInfo";
|
import { In } from "typeorm";
|
export default class AppProductApplyController extends BaseController {
|
//#region 保存物料
|
/**
|
* 保存物料
|
*/
|
@Post()
|
public async save() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
try {
|
if (!body.productName) {
|
this.info.result = false;
|
this.info.msg = "物料名称不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
if (!body.productModel) {
|
this.info.result = false;
|
this.info.msg = "物料条码不能为空!";
|
ctx.body = this.info;
|
return;
|
}
|
// 保存数据
|
body.images = JSON.stringify(body.images);
|
body.auditDate = new Date();
|
body.auditing = 0;
|
|
if (!body.productApply_Id) {
|
// 新建时,获取编码
|
let code = await this.ctx.service.common.getCodeRegular(1791);
|
body.productCode = code;
|
}
|
// 设置账套数据
|
await this.setAccountInfo(body);
|
await this.dbWrite.save(AppProductApply, body);
|
|
this.info.result = true;
|
this.info.data = body;
|
this.info.msg = "物料申请保存成功";
|
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "物料申请保存失败" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region ProductAuditing
|
/**
|
* 物料审核
|
*/
|
@Post()
|
public async productAuditing() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
|
try {
|
if (!body.IDs) {
|
this.info.result = false;
|
this.info.msg = "至少选择一条物料";
|
return;
|
}
|
let IDs = body.IDs.split(",");
|
|
await this.dbWrite.update(
|
AppProductApply,
|
{
|
userProduct_Id: userInfo.userProduct_Id,
|
productApply_Id: In(IDs)
|
},
|
{
|
auditor: userInfo.userTrueName,
|
auditing: 2,
|
auditDate: new Date()
|
}
|
);
|
|
let datatable = await this.dbRead.find(AppProductApply, {
|
// userProduct_Id: userInfo.userProduct_Id,
|
productApply_Id: In(IDs)
|
});
|
|
for (let item of datatable) {
|
let prodctInfo = new BaseProductInfo();
|
prodctInfo.productCode = item.productCode;
|
prodctInfo.brandName = item.brandName;
|
prodctInfo.productModel = item.productModel;
|
prodctInfo.consignor_Id = item.consignor_Id;
|
prodctInfo.consignorCode = item.consignorCode;
|
prodctInfo.consignorName = item.consignorName;
|
prodctInfo.productName = item.productName;
|
prodctInfo.type_Id = item.typeid;
|
prodctInfo.typeName = item.typeName;
|
prodctInfo.smallUnit = item.smallUnit;
|
prodctInfo.originPlace = item.originPlace;
|
await this.setAccountInfo(prodctInfo);
|
await this.dbWrite.save(prodctInfo);
|
}
|
|
this.info.result = true;
|
this.info.msg = "审核成功";
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|