|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: zhl
|
|
|
|
* Date: 2024/5/28
|
|
|
|
* Time: 14:25
|
|
|
|
*/
|
|
|
|
namespace App\Http\Controllers\Aside\Task;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Controllers\Aside\BaseController;
|
|
|
|
use App\Models\Com\Notify;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\WebSetting\WebLanguage;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自动任务信息
|
|
|
|
* Class AutoTaskController
|
|
|
|
* @package App\Http\Controllers\Aside\Task
|
|
|
|
*/
|
|
|
|
class AutoTaskController extends BaseController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 页面生成任务
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function createHtmlTask(Request $request)
|
|
|
|
{
|
|
|
|
// 接收信息
|
|
|
|
$project_id = intval($request->input('project_id'));
|
|
|
|
$status = intval($request->input('status'));
|
|
|
|
$route = intval($request->input('route'));
|
|
|
|
$type = intval($request->input('type'));
|
|
|
|
$row = intval($request->input('row', 20));
|
|
|
|
// 所有参数都有初始化数据, 无数据验证
|
|
|
|
// 查询初始数据
|
|
|
|
$where = compact('project_id', 'route', 'type');
|
|
|
|
$where = array_filter($where);
|
|
|
|
if ($status)
|
|
|
|
$where['status'] = $status - 1;
|
|
|
|
$result = Notify::select(['id','project_id', 'type', 'data', 'status', 'route', 'num', 'updated_at', 'created_at'])
|
|
|
|
->where('id', '>', 84000) // 查询有效数据
|
|
|
|
->where('server_id', '<>', 9) // 过滤测试环境数据
|
|
|
|
->where('server_id', '>', 0) // 过滤测试环境数据
|
|
|
|
->where($where)
|
|
|
|
->orderBy('id', 'desc')
|
|
|
|
->paginate($row);
|
|
|
|
|
|
|
|
// 数据中需要处理项目信息
|
|
|
|
$project_ids = $result->pluck('project_id')->toArray();
|
|
|
|
$projects = Project::whereIN('id', $project_ids)->pluck('title', 'id')->toArray();
|
|
|
|
// 数据中需要处理的语种信息
|
|
|
|
$language = WebLanguage::pluck('chinese', 'id')->toArray();
|
|
|
|
// 数据中需要映射的参数信息
|
|
|
|
$type = Notify::typeMap();
|
|
|
|
$route = Notify::routeMap();
|
|
|
|
$status = Notify::statusMap();
|
|
|
|
// 转数组操作, 如果是对象, 添加字段会报错
|
|
|
|
$result = $result->toArray();
|
|
|
|
foreach ($result['list'] as &$val) {
|
|
|
|
// 解析data信息, 以后数据库尽量不要存需要处理的JSON信息, 拆分成指定字段
|
|
|
|
$data = json_decode($val['data'], true);
|
|
|
|
$val['language'] = [];
|
|
|
|
// 小语种 并且 有语种信息, 将语种转换成中文
|
|
|
|
if ($val['type'] == Notify::TYPE_MINOR && FALSE == empty($data['language'])) {
|
|
|
|
foreach ($data['language'] as $v) {
|
|
|
|
$val['language'][] = $language[$v];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 映射信息 以及解析信息
|
|
|
|
$val['type'] = $type[$val['type']];
|
|
|
|
$val['route'] = $route[$val['route']];
|
|
|
|
$val['status'] = $status[$val['status']];
|
|
|
|
$val['project_title'] = $projects[$val['project_id']] ?? '';
|
|
|
|
$val['domain'] = $data['domain'] ?? '';
|
|
|
|
$val['url'] = FALSE == empty($data['url']) ? json_decode($data['url'], true) : [];
|
|
|
|
|
|
|
|
}
|
|
|
|
return $this->response('success', Code::SUCCESS, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面生成任务参数
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function createHtmlTaskParam()
|
|
|
|
{
|
|
|
|
$status = Notify::statusMap();
|
|
|
|
$status_new = [];
|
|
|
|
foreach ($status as $key=>$val) {
|
|
|
|
$status_new[$key+1] = $val;
|
|
|
|
}
|
|
|
|
$result = [
|
|
|
|
'status' => $status_new,
|
|
|
|
'type' => Notify::typeMap(),
|
|
|
|
'route' => Notify::routeMap()
|
|
|
|
];
|
|
|
|
return $this->response('success', Code::SUCCESS, $result);
|
|
|
|
}
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|