|
@@ -662,8 +662,59 @@ module.exports = app => {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- async bindSp(spid, tids) {
|
|
|
- return await this.db.update(this.tableName, { spid }, { where: { id: tids } });
|
|
|
+ async bindSp(pid, spid, tids) {
|
|
|
+ const subProject = await this.ctx.service.subProject.getDataById(spid);
|
|
|
+ const orgRelaTenderId = subProject.rela_tender !== '' ? subProject.rela_tender.split(',') : [];
|
|
|
+ orgRelaTenderId.push(...tids);
|
|
|
+ // 更新category
|
|
|
+ const orgCategoryData = await this.ctx.service.category.getOrgAllCategory(pid);
|
|
|
+ const newCategoryData = await this.ctx.service.category.getAllCategory(subProject);
|
|
|
+ const updateTenders = [];
|
|
|
+ for (const tid of tids) {
|
|
|
+ const tender = await this.getDataById(tid);
|
|
|
+ const oneUpdate = {
|
|
|
+ id: tid,
|
|
|
+ spid,
|
|
|
+ };
|
|
|
+ if (tender.category) {
|
|
|
+ const newCategory = [];
|
|
|
+ const orgCategory = JSON.parse(tender.category);
|
|
|
+ for (const c of orgCategory) {
|
|
|
+ const orgC = orgCategoryData.find(item => item.id === c.cid);
|
|
|
+ if (orgC) {
|
|
|
+ const newC = newCategoryData.find(item => item.name === orgC.name);
|
|
|
+ if (newC) {
|
|
|
+ const orgV = orgC.value.find(item => item.id === c.value);
|
|
|
+ if (orgV) {
|
|
|
+ const newV = newC.value.find(item => item.value === orgV.value);
|
|
|
+ if (newV) {
|
|
|
+ newCategory.push({
|
|
|
+ cid: newC.id,
|
|
|
+ value: newV.id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (newCategory.length > 0) {
|
|
|
+ oneUpdate.category = JSON.stringify(newCategory);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateTenders.push(oneUpdate);
|
|
|
+ }
|
|
|
+ const conn = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await conn.updateRows(this.tableName, updateTenders);
|
|
|
+ await conn.update(this.ctx.service.subProject.tableName, { id: subProject.id, rela_tender: this._.uniq(orgRelaTenderId).join(',') });
|
|
|
+ await conn.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender: this._.uniq(orgRelaTenderId).join(',') });
|
|
|
+ await conn.commit();
|
|
|
+ return true;
|
|
|
+ } catch (error) {
|
|
|
+ await conn.rollback();
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ // return await this.ctx.subProject.setRelaTender({ id: spid, rela_tender: newTids });
|
|
|
}
|
|
|
}
|
|
|
|