WokerTask/app/common/logic/task_scheduling_plan/TaskSchedulingPlanLogic.php

128 lines
4.0 KiB
PHP
Raw Normal View History

2023-12-27 14:06:33 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\logic\task_scheduling_plan;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\logic\BaseLogic;
use app\common\model\task\Task;
use app\common\model\task_scheduling\TaskScheduling;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\User;
use think\facade\Db;
/**
* 任务排期日历逻辑
* Class TaskSchedulingPlanLogic
* @package app\adminapi\logic\task_scheduling_plan
*/
class TaskSchedulingPlanLogic extends BaseLogic
{
/**
* @notes 添加任务排期日历
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/08 10:34
*/
public static function add(array $params): bool
{
Db::startTrans();
$company_id=TaskScheduling::where('id',$params['scheduling_id'])->value('company_id');
try {
TaskSchedulingPlan::create([
'create_user_id' => $params['create_user_id'],
'company_id' => $company_id,
'template_id' => $params['template_id'],
'scheduling_id' => $params['scheduling_id'],
'start_time' => $params['start_time'],
'end_time' => $params['end_time'],
'sn' =>User::createUserSn(),
'status' => 1
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑任务排期日历
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/08 10:34
*/
public static function edit(array $params): bool
{
Db::startTrans();
$company_id=TaskScheduling::where('id',$params['scheduling_id'])->value('company_id');
try {
TaskSchedulingPlan::where('id', $params['id'])->update([
'company_id' => $company_id,
'create_user_id' => $params['create_user_id'],
'template_id' => $params['template_id'],
'scheduling_id' => $params['scheduling_id'],
'start_time' => $params['start_time'],
'end_time' => $params['end_time'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除任务排期日历
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/08 10:34
*/
public static function delete(array $params): bool
{
Task::where('scheduling_plan_id',$params['id'])->delete();
return TaskSchedulingPlan::destroy($params['id']);
}
/**
* @notes 获取任务排期日历详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/08 10:34
*/
public static function detail($params): array
{
$data=TaskSchedulingPlan::findOrEmpty($params['id'])->toArray();
$data['task_info']=TaskTemplate::where('id',$data['template_id'])->with('dataType')->find();
return $data;
}
}