From 23c4d49cab8300f3e8ae0de7cac7e20fe79ff0d5 Mon Sep 17 00:00:00 2001
From: wangzhibo <wangzhibo@shsening.com>
Date: 星期五, 17 七月 2026 16:24:17 +0800
Subject: [PATCH] 可回收物销售

---
 src/modules/basicdata/controller/admin/buyer.ts     |   27 +++++
 src/modules/basicdata/entity/buyer.ts               |   33 ++++++
 src/modules/basicdata/service/buyer.ts              |   14 ++
 src/modules/operation/controller/admin/wastesale.ts |   78 +++++++++++++++
 src/modules/operation/entity/wastesale.ts           |   50 ++++++++++
 src/modules/operation/config.ts                     |   13 ++
 src/modules/basicdata/controller/admin/driver.ts    |   18 +-
 src/modules/operation/service/wastesale.ts          |   25 +++++
 8 files changed, 249 insertions(+), 9 deletions(-)

diff --git a/src/modules/basicdata/controller/admin/buyer.ts b/src/modules/basicdata/controller/admin/buyer.ts
new file mode 100644
index 0000000..1359b0f
--- /dev/null
+++ b/src/modules/basicdata/controller/admin/buyer.ts
@@ -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 {}
\ No newline at end of file
diff --git a/src/modules/basicdata/controller/admin/driver.ts b/src/modules/basicdata/controller/admin/driver.ts
index 27fc7bc..8bb26e6 100644
--- a/src/modules/basicdata/controller/admin/driver.ts
+++ b/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',
+      },
+    ],
 
   },
 })
diff --git a/src/modules/basicdata/entity/buyer.ts b/src/modules/basicdata/entity/buyer.ts
new file mode 100644
index 0000000..ce9e4f1
--- /dev/null
+++ b/src/modules/basicdata/entity/buyer.ts
@@ -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: '浠g爜', 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;
+}
\ No newline at end of file
diff --git a/src/modules/basicdata/service/buyer.ts b/src/modules/basicdata/service/buyer.ts
new file mode 100644
index 0000000..43b4059
--- /dev/null
+++ b/src/modules/basicdata/service/buyer.ts
@@ -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>;
+}
\ No newline at end of file
diff --git a/src/modules/operation/config.ts b/src/modules/operation/config.ts
new file mode 100644
index 0000000..23536a7
--- /dev/null
+++ b/src/modules/operation/config.ts
@@ -0,0 +1,13 @@
+import { ModuleConfig } from '@cool-midway/core';
+
+/**
+ * 杩愯惀鍥炴敹
+ */
+export default () => {
+  return {
+    name: '杩愯惀鍥炴敹妯″潡',
+    description: '杩愯惀鍥炴敹鍜岀粺璁℃湇鍔�',
+    middlewares: [],
+    globalMiddlewares: [],
+  } as ModuleConfig;
+};
diff --git a/src/modules/operation/controller/admin/wastesale.ts b/src/modules/operation/controller/admin/wastesale.ts
new file mode 100644
index 0000000..be277fe
--- /dev/null
+++ b/src/modules/operation/controller/admin/wastesale.ts
@@ -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;
+}
\ No newline at end of file
diff --git a/src/modules/operation/entity/wastesale.ts b/src/modules/operation/entity/wastesale.ts
new file mode 100644
index 0000000..67423b7
--- /dev/null
+++ b/src/modules/operation/entity/wastesale.ts
@@ -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: '鏀堕泦鐐笽D', 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: '缁忔墜浜篒D', type: 'bigint' })
+  handlerId: number;
+
+  handlerName: string;
+
+  @Column({ comment: '鏀惰喘鏂逛唬鐮�', length: 50 })
+  buyerCode: string;
+
+  buyerName: string;
+
+}
\ No newline at end of file
diff --git a/src/modules/operation/service/wastesale.ts b/src/modules/operation/service/wastesale.ts
new file mode 100644
index 0000000..70b0f4c
--- /dev/null
+++ b/src/modules/operation/service/wastesale.ts
@@ -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));
+      }
+    }
+  }
+}
\ No newline at end of file

--
Gitblit v1.9.1