|
@@ -71,13 +71,14 @@ module.exports = app => {
|
|
|
* @param {int} id 工料id
|
|
|
* @return {void}
|
|
|
*/
|
|
|
- async del(id, ms_id = null,) {
|
|
|
+ async del(id, ms_id = null, gather_qty = null) {
|
|
|
if (!this.ctx.tender || !this.ctx.material) {
|
|
|
throw '数据错误';
|
|
|
}
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
const selfInfo = await this.getDataById(id);
|
|
|
+ selfInfo.gather_qty = gather_qty;
|
|
|
await this.updateAllMaterials(transaction, selfInfo, ms_id);
|
|
|
// 判断是否可删
|
|
|
const result = await transaction.delete(this.tableName, { id });
|
|
@@ -108,8 +109,8 @@ module.exports = app => {
|
|
|
const materialListData = await this.ctx.service.materialList.getAllDataByCondition({
|
|
|
where: searchSql,
|
|
|
});
|
|
|
+ const mbIdList = [];
|
|
|
if (materialListData && materialListData.length > 0) {
|
|
|
- const mbIdList = [];
|
|
|
for (const ml of materialListData) {
|
|
|
if (mbIdList.indexOf(ml.mb_id) === -1) {
|
|
|
mbIdList.push(ml.mb_id);
|
|
@@ -122,38 +123,18 @@ module.exports = app => {
|
|
|
xmj_id: data.xmj_id,
|
|
|
mx_id: data.mx_id ? data.mx_id : '',
|
|
|
});
|
|
|
- const materialListGclData = await this.ctx.service.materialListGcl.getAllDataByCondition({
|
|
|
- where: { tid: this.ctx.tender.id, gcl_id: data.gcl_id },
|
|
|
- });
|
|
|
- const insertList = [];
|
|
|
- if (this.ctx.material.is_stage_self) {
|
|
|
- const materialStageList = await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } });
|
|
|
- for (const ms of materialStageList) {
|
|
|
- const oneML = this._.filter(materialListData, { ms_id: ms.id });
|
|
|
- const gather_qty = oneML[0].gather_qty;
|
|
|
- const is_join = oneML[0].is_join;
|
|
|
- for (const m of materialListGclData) {
|
|
|
- insertList.push({
|
|
|
- tid: this.ctx.tender.id,
|
|
|
- order: m.order,
|
|
|
- mid: this.ctx.material.id,
|
|
|
- mb_id: m.mb_id,
|
|
|
- gcl_id: data.gcl_id,
|
|
|
- xmj_id: data.xmj_id,
|
|
|
- mx_id: data.mx_id,
|
|
|
- ms_id: ms.id,
|
|
|
- gather_qty,
|
|
|
- quantity: m.quantity,
|
|
|
- expr: m.expr,
|
|
|
- is_join,
|
|
|
- is_self: 0,
|
|
|
- in_time: new Date(),
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- const gather_qty = materialListData[0].gather_qty;
|
|
|
- const is_join = materialListData[0].is_join;
|
|
|
+ }
|
|
|
+ const materialListGclData = await this.ctx.service.materialListGcl.getAllDataByCondition({
|
|
|
+ where: { tid: this.ctx.tender.id, gcl_id: data.gcl_id },
|
|
|
+ });
|
|
|
+ const insertList = [];
|
|
|
+ const is_join = await this.ctx.service.materialListNotjoin.getJoinMsg(transaction, this.ctx.material.id, data);
|
|
|
+ if (this.ctx.material.is_stage_self) {
|
|
|
+ const materialStageList = await transaction.select(this.ctx.service.materialStage.tableName, { where: { mid: this.ctx.material.id } });
|
|
|
+ for (const ms of materialStageList) {
|
|
|
+ // const oneML = this._.filter(materialListData, { ms_id: ms.id });
|
|
|
+ // const gather_qty = oneML[0].gather_qty;
|
|
|
+ // const is_join = oneML[0].is_join;
|
|
|
for (const m of materialListGclData) {
|
|
|
insertList.push({
|
|
|
tid: this.ctx.tender.id,
|
|
@@ -163,7 +144,8 @@ module.exports = app => {
|
|
|
gcl_id: data.gcl_id,
|
|
|
xmj_id: data.xmj_id,
|
|
|
mx_id: data.mx_id,
|
|
|
- gather_qty,
|
|
|
+ ms_id: ms.id,
|
|
|
+ gather_qty: data.gather_qty[ms.id],
|
|
|
quantity: m.quantity,
|
|
|
expr: m.expr,
|
|
|
is_join,
|
|
@@ -172,12 +154,32 @@ module.exports = app => {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- if (insertList.length > 0) await transaction.insert(this.ctx.service.materialList.tableName, insertList);
|
|
|
- // 重新计算金额
|
|
|
- for (const mb_id of mbIdList) {
|
|
|
- await this.service.materialList.calcQuantityByML(transaction, mb_id, ms_id, 'all');
|
|
|
+ } else {
|
|
|
+ // const gather_qty = materialListData[0].gather_qty;
|
|
|
+ // const is_join = materialListData[0].is_join;
|
|
|
+ for (const m of materialListGclData) {
|
|
|
+ insertList.push({
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
+ order: m.order,
|
|
|
+ mid: this.ctx.material.id,
|
|
|
+ mb_id: m.mb_id,
|
|
|
+ gcl_id: data.gcl_id,
|
|
|
+ xmj_id: data.xmj_id,
|
|
|
+ mx_id: data.mx_id,
|
|
|
+ gather_qty: data.gather_qty,
|
|
|
+ quantity: m.quantity,
|
|
|
+ expr: m.expr,
|
|
|
+ is_join,
|
|
|
+ is_self: 0,
|
|
|
+ in_time: new Date(),
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
+ if (insertList.length > 0) await transaction.insert(this.ctx.service.materialList.tableName, insertList);
|
|
|
+ // 重新计算金额
|
|
|
+ for (const mb_id of mbIdList) {
|
|
|
+ await this.service.materialList.calcQuantityByML(transaction, mb_id, ms_id, 'all');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|