TaskSystem/app/common/logic/task/TaskLogic.php
2023-08-05 16:14:43 +08:00

133 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
use app\common\model\task\Task;
use app\common\logic\BaseLogic;
use app\common\model\informationg\UserInformationg;
use think\facade\Db;
/**
* 任务逻辑
* Class TaskLogic
* @package app\adminapi\logic\task
*/
class TaskLogic extends BaseLogic
{
/**
* @notes 添加任务
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/05 13:39
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Task::create([
'title' => $params['title'],
'template_id' => $params['template_id'],
'company_id' => $params['company_id'],
// 'admin_id' => $params['admin_id'],
'start_time' => strtotime($params['start_time']),
'end_time' =>strtotime($params['end_time']),
'director_uid' => $params['director_uid'],
'type' => $params['type'],
'status' => $params['status'],
'content' => $params['content'],
'extend'=>json_encode($params['extend'])
]);
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/05 13:39
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Task::where('id', $params['id'])->update([
'title' => $params['title'],
'template_id' => $params['template_id'],
'company_id' => $params['company_id'],
'admin_id' => $params['admin_id'],
'start_time' => $params['start_time'],
'end_time' => $params['end_time'],
'director_uid' => $params['director_uid'],
'type' => $params['type'],
'status' => $params['status'],
'content' => $params['content']
]);
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/05 13:39
*/
public static function delete(array $params): bool
{
return Task::destroy($params['id']);
}
/**
* @notes 获取任务详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/05 13:39
*/
public static function detail($params): array
{
$task= Task::findOrEmpty($params['id'])->toArray();
if($task){
if(isset($task['extend']['informationg'])){
$task['extend']['informationg']=UserInformationg::where('id',$task['extend']['informationg'])->field('name,phone,sex,age,update_time')
->find()->toArray();
}
}
return $task;
}
}