作者 李美松

优化程序

... ... @@ -55,10 +55,10 @@ class ProjectFilePDF extends Command
public function start(): int
{
# 0 - 未生成
# 1 - 已生成
# 2 - 其它问题
$is_pdf = 0;
# 1 - 未生成
# 2 - 已生成
# 3 - 其它问题
$is_pdf = 1;
$lists = $this->ProjectAssociation::query()->where('is_pdf', $is_pdf)
->where('project_id', '!=', 0)
->where('friend_id', '!=', 0)
... ... @@ -90,76 +90,21 @@ class ProjectFilePDF extends Command
$isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
if (!$isRes) {
if ($count == 2) {
$lists->is_pdf = 2;
$lists->is_pdf = 3;
$lists->save();
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
} else {
redis_add($key, $count + 1);
redis_set($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
}
$lists->is_pdf = 1;
$lists->is_pdf = 2;
$lists->save();
$this->debug_echo('项目文件数据保存成功!');
return 0;
}
/**
* Execute the console command.
*
* @return int
*/
// public function handle()
// {
// # 0 - 未生成
// # 1 - 已生成
// # 2 - 其它问题
// $is_pdf = 0;
// $lists = $this->ProjectAssociation::query()->where('is_pdf', $is_pdf)
// ->where('project_id', '!=', 0)
// ->where('friend_id', '!=', 0)
// ->where('user_id', '!=', 0)
// ->where('created_at', 'like', $this->time . '%')->first();
//
// if (is_null($lists)) {
// $this->error('没有任务,等待中');
// sleep(60);
// return 0;
// }
// $key = $this->signature . '-' . $lists->id;
// $count = redis_get($key);
// $project_id = $lists->project_id;
// $user_id = $lists->user_id;
// $friend_id = $lists->friend_id;
// // todo 根据项目查询数据
// $project_data = [];
// $html = $this->html($project_data);
// $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
//
// $file_path = $this->savePDF($html, $filename);
// if (empty($file_path)) {
// $this->debug_echo('pdf生成失败!');
// return 0;
// }
// $file_path = $file_path['data'];
// $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
// if (!$isRes) {
// if ($count == 2) {
// $lists->status = 2;
// $lists->save();
// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
// } else {
// redis_add($key, $count + 1);
// $this->error('项目文件数据保存失败! - ' . $key);
// }
// }
// $lists->status = 1;
// $lists->save();
// $this->info('项目文件数据保存成功!');
// return 0;
// }
/**
* @param $html
* @param $filename
* @return array
... ...
... ... @@ -39,53 +39,12 @@ class WebsiteData extends Command
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
// public function handle()
// {
// # 0 - 未推送
// # 1 - 已推送
// # 2 - 其他问题
// $status = 0;
// $lists = DataFile::query()->where('status', $status)
// ->where('created_at', 'like', $this->time . '%')->first();
// if (is_null($lists)) {
// $this->error('没有任务,等待中');
// sleep(30);
// return 0;
// }
//
// $key = $this->signature . '-' . $lists->id;
// $count = redis_get($key);
// $data = $lists;
//
// $url = env('AICC_URL');
// $msg = http_post($url, json_encode(compact('data')));
// $status_code = $msg['status'];
// if ($status_code != 200) {
// if ($count == 2) {
// $lists->status = 2;
// $lists->save();
// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
// } else {
// redis_add($key, $count + 1);
// $this->error('项目文件数据保存失败! - ' . $key);
// }
// }
// $lists->status = 1;
// $lists->save();
// return 0;
// }
public function start(): int
{
# 0 - 未推送
# 1 - 已推送
# 2 - 其他问题
$status = 0;
# 1 - 未推送
# 2 - 已推送
# 3 - 其他问题
$status = 1;
$lists = DataFile::query()->where('status', $status)
->where('created_at', 'like', $this->time . '%')->first();
if (is_null($lists)) {
... ... @@ -99,47 +58,26 @@ class WebsiteData extends Command
$data = $lists;
$url = env('AICC_URL');
$msg = http_post($url, json_encode(compact('data')));
$status_code = $msg['status'];
$status_code = 0;
if ($msg) {
$status_code = (int)$msg['status'];
}
if ($status_code != 200) {
if ($count == 2) {
$lists->status = 2;
$lists->status = 3;
$lists->save();
$this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
} else {
redis_add($key, $count + 1);
redis_set($key, $count + 1);
$this->debug_echo('项目文件数据保存失败! - ' . $key);
}
}
$lists->status = 1;
$lists->status = 2;
$lists->save();
$this->info('项目文件数据保存成功!');
return 0;
}
/**
* Execute the console command.
*
* @return int
*/
// public function handle()
// {
// $DataFile = new DataFile();
// $data = $DataFile->allData();
// # 详细数据
// $items = $data['items'];
// # 总分页
// $totalPage = $data['totalPage'];
// $this->post_data($items);
// if ($totalPage > 1) {
// for ($page = 2; $page <= $totalPage; $page++) {
// $da = $DataFile->allData($page);
// $this->post_data($da['items']);
// }
// }
// $this->info('项目文件数据推送完成!');
// return 0;
// }
public function post_data($data)
{
$url = env('AICC_URL');
... ...