2023-08-05 16:14:43 +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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\model\task\Task;
|
|
|
|
|
use app\common\logic\BaseLogic;
|
|
|
|
|
use app\common\model\informationg\UserInformationg;
|
2023-08-10 17:10:12 +08:00
|
|
|
|
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
2023-08-05 16:14:43 +08:00
|
|
|
|
use think\facade\Db;
|
2023-08-10 17:10:12 +08:00
|
|
|
|
use think\facade\Log;
|
2023-08-05 16:14:43 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 任务逻辑
|
|
|
|
|
* 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']),
|
2023-08-10 17:10:12 +08:00
|
|
|
|
'end_time' => strtotime($params['end_time']),
|
2023-08-05 16:14:43 +08:00
|
|
|
|
'director_uid' => $params['director_uid'],
|
|
|
|
|
'type' => $params['type'],
|
|
|
|
|
'status' => $params['status'],
|
|
|
|
|
'content' => $params['content'],
|
2023-08-10 17:10:12 +08:00
|
|
|
|
'extend' => json_encode($params['extend'])
|
2023-08-05 16:14:43 +08:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Db::rollback();
|
|
|
|
|
self::setError($e->getMessage());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-10 17:10:12 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 定时添加任务
|
|
|
|
|
*/
|
|
|
|
|
public static function CronAdd(array $v): bool
|
2023-08-10 10:29:57 +08:00
|
|
|
|
{
|
2023-08-10 17:10:12 +08:00
|
|
|
|
if ($v['template_info'] != null) {
|
2023-08-11 16:35:07 +08:00
|
|
|
|
try{
|
2023-08-10 17:10:12 +08:00
|
|
|
|
if ($v['template_info']['type'] == 31) {
|
|
|
|
|
$res = self::random_informationg($v['scheduling']['company_id']);
|
2023-08-11 16:35:07 +08:00
|
|
|
|
if(!$res){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-08-10 17:10:12 +08:00
|
|
|
|
$task_id=[];
|
|
|
|
|
foreach ($res as $key => $value) {
|
|
|
|
|
$extend['informationg']['arr'] = $value['id'];
|
|
|
|
|
$extend['informationg']['arr_count'] = 1;
|
|
|
|
|
$extend['informationg']['create_user_id'] = $value['create_user_id'];
|
|
|
|
|
$extend['informationg']['update'] = 0;
|
|
|
|
|
$extend['informationg']['update_count'] = 0;
|
|
|
|
|
$arr = [
|
|
|
|
|
'template_id' => $v['template_id'],
|
|
|
|
|
'scheduling_plan_id' => $v['id'],
|
|
|
|
|
'company_id' => $v['scheduling']['company_id'],
|
2023-08-11 16:35:07 +08:00
|
|
|
|
'director_uid' => $value['create_user_id'],
|
2023-08-10 17:10:12 +08:00
|
|
|
|
'title' => $v['template_info']['title'],
|
|
|
|
|
'money' => $v['template_info']['money'],
|
|
|
|
|
'type' => $v['template_info']['type'],
|
|
|
|
|
'content' => $v['template_info']['content'],
|
|
|
|
|
'start_time' => strtotime($v['start_time']),
|
|
|
|
|
'end_time' => strtotime($v['end_time']),
|
|
|
|
|
"extend" => json_encode($extend),
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'update_time' => time(),
|
|
|
|
|
];
|
|
|
|
|
$data = $arr;
|
|
|
|
|
$task_id[] = (new Task())->insertGetId($data);
|
|
|
|
|
}
|
2023-08-11 16:35:07 +08:00
|
|
|
|
TaskSchedulingPlan::where('id', $v['id'])->update(['task_id' => implode(',', $task_id), 'is_execute' => 1]);
|
|
|
|
|
return true;
|
2023-08-10 17:10:12 +08:00
|
|
|
|
} else {
|
|
|
|
|
// foreach ($res as $key => $value) {
|
|
|
|
|
// $extend['informationg']['arr']=$value['id'];
|
|
|
|
|
// $extend['informationg']['arr_count']=1;
|
|
|
|
|
// $extend['informationg']['create_user_id']=$value['create_user_id'];
|
|
|
|
|
// $extend['informationg']['update']=0;
|
|
|
|
|
// $extend['informationg']['update_count']=0;
|
|
|
|
|
// }
|
|
|
|
|
$arr = [
|
|
|
|
|
'template_id' => $v['template_id'],
|
|
|
|
|
'scheduling_plan_id' => $v['id'],
|
|
|
|
|
'company_id' => $v['scheduling']['company_id'],
|
|
|
|
|
'title' => $v['template_info']['title'],
|
|
|
|
|
'money' => $v['template_info']['money'],
|
|
|
|
|
'type' => $v['template_info']['type'],
|
|
|
|
|
'content' => $v['template_info']['content'],
|
|
|
|
|
'start_time' => strtotime($v['start_time']),
|
|
|
|
|
'end_time' => strtotime($v['end_time']),
|
|
|
|
|
"extend" => json_encode([]),
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'update_time' => time(),
|
|
|
|
|
];
|
|
|
|
|
$data = $arr;
|
2023-08-11 16:35:07 +08:00
|
|
|
|
$task_id = (new Task())->insertGetId($data);
|
|
|
|
|
TaskSchedulingPlan::where('id', $v['id'])->update(['task_id' => $task_id, 'is_execute' => 1]);
|
2023-08-10 17:10:12 +08:00
|
|
|
|
}
|
|
|
|
|
return true;
|
2023-08-11 16:35:07 +08:00
|
|
|
|
}catch(\Exception $e){
|
|
|
|
|
Log::error('定时任务添加失败',[$e->getMessage()]);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-08-10 17:10:12 +08:00
|
|
|
|
}
|
2023-08-11 16:35:07 +08:00
|
|
|
|
|
2023-08-10 10:29:57 +08:00
|
|
|
|
}
|
2023-08-05 16:14:43 +08:00
|
|
|
|
|
2023-08-10 17:10:12 +08:00
|
|
|
|
|
2023-08-05 16:14:43 +08:00
|
|
|
|
/**
|
2023-08-10 17:10:12 +08:00
|
|
|
|
* @notes 随机生成信息更新任务
|
|
|
|
|
*/
|
|
|
|
|
private static function random_informationg($company_id)
|
|
|
|
|
{
|
|
|
|
|
$res = UserInformationg::where('company_id', $company_id)->where('status', 1)->order('update_time', 'desc')->limit(5)->field('id,create_user_id')->select();
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @notes 更新任务状态
|
2023-08-05 16:14:43 +08:00
|
|
|
|
* @param array $params
|
|
|
|
|
* @return bool
|
|
|
|
|
* @author likeadmin
|
|
|
|
|
* @date 2023/08/05 13:39
|
|
|
|
|
*/
|
|
|
|
|
public static function edit(array $params): bool
|
|
|
|
|
{
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
try {
|
2023-08-10 17:10:12 +08:00
|
|
|
|
Task::where('id', $params['id'])->update(['status' => 3, 'update_time' => time()]);
|
2023-08-05 16:14:43 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2023-08-10 17:10:12 +08:00
|
|
|
|
$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();
|
2023-08-05 16:14:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $task;
|
|
|
|
|
}
|
2023-08-10 17:10:12 +08:00
|
|
|
|
}
|