更新项目管理模块中合同管理、项目安装、项目验收、回访记录等功能
This commit is contained in:
1 parent
307e9cf1b9
commit
b3cef22a54
32 files changed
+6094
-2600
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Provide } from "@midwayjs/core";
|
||||
import { Provide, Inject } from "@midwayjs/core";
|
||||
import { InjectRepository } from "@midwayjs/sequelize";
|
||||
import { Repository } from "sequelize-typescript";
|
||||
import { Op, UniqueConstraintError } from "sequelize";
|
||||
@@ -7,6 +7,7 @@ import Contract from "../entity/contract.entity";
|
||||
import Customer from "../entity/customer.entity";
|
||||
import SysUserRole from "../entity/sysUserRole.entity";
|
||||
import SysRole from "../entity/sysRole.entity";
|
||||
import { LogService } from "./log.service";
|
||||
|
||||
@Provide()
|
||||
export class ContractService {
|
||||
@@ -22,6 +23,9 @@ export class ContractService {
|
||||
@InjectRepository(SysRole)
|
||||
roleModel!: Repository<SysRole>;
|
||||
|
||||
@Inject()
|
||||
logService!: LogService;
|
||||
|
||||
private async isAdmin(userId: number): Promise<boolean> {
|
||||
const userRoles = await this.userRoleModel.findAll({ where: { userId }, include: [this.roleModel] });
|
||||
return userRoles.some((ur) => (ur as any).role?.roleCode === "ADMIN");
|
||||
@@ -72,11 +76,20 @@ export class ContractService {
|
||||
const where: any = {};
|
||||
|
||||
if (query.keyword) {
|
||||
where[Op.or] = [{ xtContractNo: { [Op.like]: `%${query.keyword}%` } }, { contractDesc: { [Op.like]: `%${query.keyword}%` } }];
|
||||
where[Op.or] = [
|
||||
{ contractNo: { [Op.like]: `%${query.keyword}%` } },
|
||||
{ xtContractNo: { [Op.like]: `%${query.keyword}%` } },
|
||||
{ contractDesc: { [Op.like]: `%${query.keyword}%` } }
|
||||
];
|
||||
}
|
||||
if (query.customerId !== undefined) where.customerId = query.customerId;
|
||||
if (query.salesmanId) where.salesmanId = query.salesmanId;
|
||||
if (query.status !== undefined) where.status = query.status;
|
||||
if (query.signStartDate || query.signEndDate) {
|
||||
where.signDate = {};
|
||||
if (query.signStartDate) where.signDate[Op.gte] = query.signStartDate;
|
||||
if (query.signEndDate) where.signDate[Op.lte] = query.signEndDate;
|
||||
}
|
||||
|
||||
if (!(await this.isAdmin(userId))) {
|
||||
const myCustomers = await this.customerModel.findAll({ where: { salesmanId: userId }, attributes: ["id"] });
|
||||
@@ -109,6 +122,7 @@ export class ContractService {
|
||||
data.contractNo = await this.generateContractNo();
|
||||
if (!data.xtContractNo) data.xtContractNo = await this.generateXtContractNo();
|
||||
const created = await this.contractModel.create(data);
|
||||
await this.logService.logAction(ctx, "项目合同", "创建", data.contractNo, `创建项目合同 ${data.contractNo}`);
|
||||
return { code: 200, message: "创建项目合同成功", data: created.toJSON() };
|
||||
} catch (err: any) {
|
||||
if (err instanceof UniqueConstraintError) {
|
||||
@@ -131,6 +145,7 @@ export class ContractService {
|
||||
}
|
||||
delete data.contractNo;
|
||||
await record.update(data);
|
||||
await this.logService.logAction(ctx, "项目合同", "更新", record.contractNo, `更新项目合同 ${record.contractNo}`);
|
||||
return { code: 200, message: "更新项目合同成功", data: record.toJSON() };
|
||||
}
|
||||
|
||||
@@ -138,7 +153,9 @@ export class ContractService {
|
||||
const record = await this.contractModel.findByPk(id);
|
||||
if (!record) return { code: 404, message: "项目合同不存在", data: null };
|
||||
if (!(await this.isCustomerOwner(ctx.state.user.userId, record.customerId))) return { code: 403, message: "无权限删除该合同", data: null };
|
||||
const contractNo = record.contractNo;
|
||||
await record.destroy();
|
||||
await this.logService.logAction(ctx, "项目合同", "删除", contractNo, `删除项目合同 ${contractNo}`);
|
||||
return { code: 200, message: "删除项目合同成功", data: null };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user