wuyi 1 жил өмнө
parent
commit
88dba55400

+ 6 - 0
src/task/task.controller.ts

@@ -82,6 +82,12 @@ export class TaskController {
         await this.operationLogService.create(req, id, 'Task', OperationType.UPDATE, '强制完成')
     }
 
+    @Get('/:id/unscheduledSending')
+    async unscheduledSending(@Req() req, @Param('id') id: string) {
+        await this.taskService.unscheduledSending(parseInt(id))
+        await this.operationLogService.create(req, id, 'Task', OperationType.UPDATE, '取消定时任务')
+    }
+
     @Post('/item')
     async findAllTaskItem(@Body() page: PageRequest<TaskItem>) {
         (page.search as any).where.embed = false

+ 13 - 0
src/task/task.service.ts

@@ -327,6 +327,19 @@ export class TaskService implements OnModuleInit {
         }
     }
 
+    async unscheduledSending(id: number) {
+        const task = await this.taskRepository.findOneBy({ id })
+        if (task.status === TaskStatus.SCHEDULED) {
+            await this.taskRepository.update({ id }, { status: TaskStatus.IDLE, paid: false })
+        }
+        const costBalanceRecord = await this.balanceRecordRepository.findOneBy({
+            taskId: id,
+            type: BalanceType.CONSUMPTION
+        })
+        // 退款
+        await this.balanceService.feeRefund(task.userId, costBalanceRecord.amount, task.id)
+    }
+
     async exportTaskItem(taskId: number) {
         const workbook = new ExcelJS.Workbook()
         const worksheet = workbook.addWorksheet('Sheet1')