wangzhibo
2026-07-17 23c4d49cab8300f3e8ae0de7cac7e20fe79ff0d5
可回收物销售
7个文件已添加
1个文件已修改
258 ■■■■■ 已修改文件
src/modules/basicdata/controller/admin/buyer.ts 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/basicdata/controller/admin/driver.ts 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/basicdata/entity/buyer.ts 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/basicdata/service/buyer.ts 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/operation/config.ts 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/operation/controller/admin/wastesale.ts 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/operation/entity/wastesale.ts 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/operation/service/wastesale.ts 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/modules/basicdata/controller/admin/buyer.ts
New file
@@ -0,0 +1,27 @@
import { CoolController, BaseController } from '@cool-midway/core';
import { BasicdataBuyerEntity } from '../../entity/buyer';
import { BasicdataBuyerService } from '../../service/buyer';
import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department';
/**
 * 购买方管理
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: BasicdataBuyerEntity,
  service: BasicdataBuyerService,
  pageQueryOp: {
    fieldEq: ['a.departmentId', 'a.name', 'a.contact'],
    fieldLike: ['a.name','a.address'],
    select: ['a.*', 'b.name AS departmentName'],
    join: [
      {
        entity: BaseSysDepartmentEntity,
        alias: 'b',
        condition: 'a.departmentId = b.id',
        type: 'leftJoin',
      },
    ],
  },
})
export class AdminOperationBuyerController extends BaseController {}
src/modules/basicdata/controller/admin/driver.ts
@@ -18,16 +18,16 @@
      'a.phone',
      'a.licenseNo',
    ],
    fieldEq: ['a.departmentId','a.status'],
    fieldEq: ['a.departmentId', 'a.status'],
    select: ['a.*', 'b.name AS departmentName'],
        join: [
          {
            entity: BaseSysDepartmentEntity,
            alias: 'b',
            condition: 'a.departmentId = b.id',
            type: 'leftJoin',
          },
        ],
    join: [
      {
        entity: BaseSysDepartmentEntity,
        alias: 'b',
        condition: 'a.departmentId = b.id',
        type: 'leftJoin',
      },
    ],
  },
})
src/modules/basicdata/entity/buyer.ts
New file
@@ -0,0 +1,33 @@
import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';
/**
 * 购买方信息
 */
@Entity('t_basicdata_buyer')
export class BasicdataBuyerEntity extends BaseEntity {
  @Index()
  @Column({ comment: '部门ID', type: 'bigint', nullable: true })
  departmentId: number;
  departmentName: string;
  @Index({ unique: true })
  @Column({ comment: '代码', length: 50 })
  code: string;
  @Column({ comment: '名称', length: 200 })
  name: string;
  @Column({ comment: '地址', length: 255, nullable: true })
  address: string;
  @Column({ comment: '联系人', length: 50, nullable: true })
  contact: string;
  @Column({ comment: '联系电话', length: 50, nullable: true })
  phone: string;
  @Column({ comment: '备注', type: 'text', nullable: true })
  remark: string;
}
src/modules/basicdata/service/buyer.ts
New file
@@ -0,0 +1,14 @@
import { Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { BasicdataBuyerEntity } from '../entity/buyer';
/**
 * 可回收物购买方服务
 */
@Provide()
export class BasicdataBuyerService extends BaseService {
  @InjectEntityModel(BasicdataBuyerEntity)
  basicdataBuyerEntity: Repository<BasicdataBuyerEntity>;
}
src/modules/operation/config.ts
New file
@@ -0,0 +1,13 @@
import { ModuleConfig } from '@cool-midway/core';
/**
 * 运营回收
 */
export default () => {
  return {
    name: '运营回收模块',
    description: '运营回收和统计服务',
    middlewares: [],
    globalMiddlewares: [],
  } as ModuleConfig;
};
src/modules/operation/controller/admin/wastesale.ts
New file
@@ -0,0 +1,78 @@
import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { OperationWastesaleEntity } from '../../entity/wastesale';
import { OperationWastesaleService } from '../../service/wastesale';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';
import { BasicdataBuyerEntity } from '../../../basicdata/entity/buyer'
import { BaseSysDepartmentEntity } from '../../../base/entity/sys/department';
import { BasicdataSiteEntity } from '../../../basicdata/entity/site'
import { BasicdataWastetypeEntity } from '../../../basicdata/entity/wastetype';
/**
 * 可回收物收益管理
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OperationWastesaleEntity,
  service: OperationWastesaleService,
  insertParam: (ctx) => {
    return {
      handlerId: ctx.admin.userId,
    };
  },
  pageQueryOp: {
    select: [
      'a.*',
      'b.name AS departmentName',
      'c.businessName AS siteName',
      'd.name AS wasteName',
      'e.name AS handlerName',
      'f.name AS buyerName',
    ],
    join: [
      {
        entity: BaseSysDepartmentEntity,
        alias: 'b',
        condition: 'a.departmentId = b.id',
        type: 'leftJoin',
      },
      {
        entity: BasicdataSiteEntity,
        alias: 'c',
        condition: 'a.siteId = c.businessId',
        type: 'leftJoin',
      },
      {
        entity: BasicdataWastetypeEntity,
        alias: 'd',
        condition: 'a.wasteCode = d.code',
        type: 'leftJoin',
      },
      {
        entity: BaseSysUserEntity,
        alias: 'e',
        condition: 'a.handlerId = e.userId',
        type: 'leftJoin',
      },
      {
        entity: BasicdataBuyerEntity,
        alias: 'f',
        condition: 'a.buyerCode = f.code',
        type: 'leftJoin',
      },
    ],
    fieldEq: ['a.departmentId', 'a.collectionPointId'],
    where: async (ctx) => {
      const { startTime, endTime } = ctx.request.body;
      const condition = [];
      if (startTime && endTime) {
        condition.push(['a.dateTime BETWEEN :startTime AND :endTime', { startTime, endTime }]);
      }
      return condition;
    },
  },
})
export class AdminOperationWastesaleController extends BaseController {
  @Inject()
  ctx;
}
src/modules/operation/entity/wastesale.ts
New file
@@ -0,0 +1,50 @@
import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';
/**
 * 可回收物收益
 */
@Entity('t_operation_waste_sale')
export class OperationWastesaleEntity extends BaseEntity {
  @Index()
  @Column({ comment: '部门ID', type: 'bigint' })
  departmentId: number;
  departmentName: string;
  @Index()
  @Column({ comment: '收集点ID', nullable: true })
  siteId: string;
  siteName: string;
  @Index()
  @Column({ comment: '垃圾种类' })
  wasteCode: string;
  wasteName: string;
  @Column({ comment: '日期时间', type: 'datetime' })
  dateTime: Date;
  @Column({ comment: '重量', type: 'decimal', precision: 10, scale: 2 })
  weight: number;
  @Column({ comment: '单价', type: 'decimal', precision: 10, scale: 2 })
  unitPrice: number;
  @Column({ comment: '总价', type: 'decimal', precision: 12, scale: 2 })
  totalPrice: number;
  @Index()
  @Column({ comment: '经手人ID', type: 'bigint' })
  handlerId: number;
  handlerName: string;
  @Column({ comment: '收购方代码', length: 50 })
  buyerCode: string;
  buyerName: string;
}
src/modules/operation/service/wastesale.ts
New file
@@ -0,0 +1,25 @@
import { Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { OperationWastesaleEntity } from '../entity/wastesale';
/**
 * 可回收物收益服务
 */
@Provide()
export class OperationWastesaleService extends BaseService {
  @InjectEntityModel(OperationWastesaleEntity)
  operationWastesaleEntity: Repository<OperationWastesaleEntity>;
  /**
   * 写入前计算总价
   */
  async modifyBefore(data: any, type: 'add' | 'update') {
    if (type === 'add' || type === 'update') {
      if (data.weight !== undefined && data.unitPrice !== undefined) {
        data.totalPrice = Number((Number(data.weight) * Number(data.unitPrice)).toFixed(2));
      }
    }
  }
}