作者 李美松

Revert "优化程序"

This reverts commit 2e4661c6
@@ -12,8 +12,6 @@ use Illuminate\Http\File; @@ -12,8 +12,6 @@ use Illuminate\Http\File;
12 12
13 class ProjectFilePDF extends Command 13 class ProjectFilePDF extends Command
14 { 14 {
15 - use CmdSignal;  
16 -  
17 /** 15 /**
18 * The name and signature of the console command. 16 * The name and signature of the console command.
19 * 17 *
@@ -34,11 +32,6 @@ class ProjectFilePDF extends Command @@ -34,11 +32,6 @@ class ProjectFilePDF extends Command
34 32
35 protected $time; 33 protected $time;
36 34
37 - // 最大支持5个进程  
38 - public $maxRunNumber = 50;  
39 -  
40 - public $fileController;  
41 -  
42 /** 35 /**
43 * Create a new command instance. 36 * Create a new command instance.
44 * 37 *
@@ -46,100 +39,73 @@ class ProjectFilePDF extends Command @@ -46,100 +39,73 @@ class ProjectFilePDF extends Command
46 */ 39 */
47 public function __construct() 40 public function __construct()
48 { 41 {
49 - $this->AiccWechat = new ProjectAssociation();  
50 - $this->DataFile = new DataFile();  
51 - $this->time = date("Y-m");  
52 - $this->fileController = new FileController(); 42 + $this->AiccWechat = new ProjectAssociation();
  43 + $this->DataFile = new DataFile();
  44 + $this->time = date("Y-m");
53 parent::__construct(); 45 parent::__construct();
54 } 46 }
55 47
  48 + /**
  49 + * Execute the console command.
  50 + *
  51 + * @return int
  52 + */
  53 + public function handle()
  54 + {
  55 + $data = $this->get_data();
  56 + # 详细数据
  57 + $items = $data['items'];
  58 + # 总分页
  59 + $totalPage = $data['totalPage'];
  60 + $this->dataPush($items);
  61 + if ($totalPage > 1) {
  62 + for ($page = 2; $page <= $totalPage; $page++) {
  63 + $da = $this->get_data();
  64 + $this->dataPush($da['items']);
  65 + }
  66 + }
  67 + $this->info('生成pdf完成');
  68 + return 0;
  69 + }
56 70
57 -// public function handle()  
58 -// {  
59 -// $status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题1  
60 -// $lists = $this->DataFile::query()->where('status', $status)  
61 -// ->where('project_id', '!=', 0)  
62 -// ->where('friend_id', '!=', 0)  
63 -// ->where('user_id', '!=', 0)  
64 -// ->where('created_at', 'like', $this->time . '%')->first();  
65 -// if (is_null($lists)) {  
66 -// $this->error('没有任务,等待中');  
67 -// sleep(60);  
68 -// return 0;  
69 -// }  
70 -// $key = $this->signature . '-' . $lists->id;  
71 -// $count = redis_get($key);  
72 -// $project_id = $lists->project_id;  
73 -// $user_id = $lists->user_id;  
74 -// $friend_id = $lists->friend_id;  
75 -// // todo 根据项目查询数据  
76 -// $project_data = [];  
77 -// $html = $this->html($project_data);  
78 -// $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);  
79 -// $file_path = $this->savePDF($html, $filename);  
80 -// if (empty($file_path)) {  
81 -// $this->error('pdf生成失败!');  
82 -// return 0;  
83 -// }  
84 -// $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);  
85 -// if (!$isRes) {  
86 -// if ($count == 2) {  
87 -// $lists->is_pdf = 2;  
88 -// $lists->save();  
89 -// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);  
90 -// } else {  
91 -// redis_add($key, $count + 1);  
92 -// $this->error('项目文件数据保存失败! - ' . $key);  
93 -// }  
94 -// }  
95 -// $lists->is_pdf = 1;  
96 -// $lists->save();  
97 -// $this->error('项目文件数据保存成功!');  
98 -// return 0;  
99 -// }  
100 -  
101 - public function start(): int 71 + /**
  72 + * 数据生成并保存
  73 + * @param array $items
  74 + * @return void
  75 + */
  76 + public function dataPush(array $items)
102 { 77 {
103 - $status = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题  
104 - $lists = $this->DataFile::query()->where('status', $status)  
105 - ->where('project_id', '!=', 0)  
106 - ->where('friend_id', '!=', 0)  
107 - ->where('user_id', '!=', 0)  
108 - ->where('created_at', 'like', $this->time . '%')->first();  
109 - if (is_null($lists)) {  
110 - $this->debug_echo('没有任务,等待中');  
111 - sleep(60);  
112 - return 0; 78 + foreach ($items as $item) {
  79 + $project_id = $item->project_id;
  80 + $user_id = $item->user_id;
  81 + $friend_id = $item->friend_id;
  82 + // todo 根据项目查询数据
  83 + $project_data = [];
  84 + $html = $this->html($project_data);
  85 + $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
  86 + $file_path = $this->savePDF($html, $filename);
  87 + var_dump($file_path);
  88 + $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
113 } 89 }
114 - $key = $this->signature . '-' . $lists->id;  
115 - $count = redis_get($key);  
116 - $project_id = $lists->project_id;  
117 - $user_id = $lists->user_id;  
118 - $friend_id = $lists->friend_id;  
119 - // todo 根据项目查询数据  
120 - $project_data = [];  
121 - $html = $this->html($project_data);  
122 - $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);  
123 - $file_path = $this->savePDF($html, $filename);  
124 - if (empty($file_path)) {  
125 - $this->debug_echo('pdf生成失败!'); 90 + }
  91 +
  92 +
  93 + public function get_data($page = 1, $perPage = 20)
  94 + {
  95 + $data = $this->AiccWechat->allData($page, $perPage);
  96 + # 总条数
  97 + $total = $data['total'];
  98 + if (empty($total)) {
  99 + $this->error('暂无绑定AICC微信数据');
126 return 0; 100 return 0;
127 } 101 }
128 - $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);  
129 - if (!$isRes) {  
130 - if ($count == 2) {  
131 - $lists->is_pdf = 2;  
132 - $lists->save();  
133 - $this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);  
134 - } else {  
135 - redis_add($key, $count + 1);  
136 - $this->debug_echo('项目文件数据保存失败! - ' . $key);  
137 - }  
138 - }  
139 - $lists->is_pdf = 1;  
140 - $lists->save();  
141 - $this->debug_echo('项目文件数据保存成功!');  
142 - return 0; 102 + # 详细数据
  103 + $items = $data['items'];
  104 + # 总分页
  105 + $totalPage = $data['totalPage'];
  106 + # 当前页
  107 + $currentPage = $data['currentPage'];
  108 + return compact('total', 'items', 'totalPage', 'currentPage');
143 } 109 }
144 110
145 public function savePDF($html, $filename) 111 public function savePDF($html, $filename)
@@ -172,15 +138,16 @@ class ProjectFilePDF extends Command @@ -172,15 +138,16 @@ class ProjectFilePDF extends Command
172 // 获取PDF内容 138 // 获取PDF内容
173 $pdfContent = $dompdf->output(); 139 $pdfContent = $dompdf->output();
174 140
  141 + $fileController = new FileController();
  142 +
175 // 将PDF内容保存到文件 143 // 将PDF内容保存到文件
176 @file_put_contents($savePath, $pdfContent); 144 @file_put_contents($savePath, $pdfContent);
177 145
178 // 创建一个文件实例 146 // 创建一个文件实例
179 $file = new File($savePath); 147 $file = new File($savePath);
180 -// var_dump($file->getExtension());  
181 -// exit();  
182 -  
183 - echo $this->fileController->single($file); 148 +var_dump($file->getFilename());
  149 +exit();
  150 + return $fileController->single($file);
184 } 151 }
185 152
186 /** 153 /**
@@ -24,12 +24,10 @@ class WebsiteData extends Command @@ -24,12 +24,10 @@ class WebsiteData extends Command
24 protected $description = '向AICC推送数据'; 24 protected $description = '向AICC推送数据';
25 25
26 // 最大支持5个进程 26 // 最大支持5个进程
27 - public int $maxRunNumber = 50; 27 + public $maxRunNumber = 50;
28 28
29 protected $time; 29 protected $time;
30 30
31 - protected $url;  
32 -  
33 /** 31 /**
34 * Create a new command instance. 32 * Create a new command instance.
35 * 33 *
@@ -37,17 +35,13 @@ class WebsiteData extends Command @@ -37,17 +35,13 @@ class WebsiteData extends Command
37 */ 35 */
38 public function __construct() 36 public function __construct()
39 { 37 {
40 - $this->time = date('Y-m');  
41 - $this->url = env('AICC_URL'); 38 + $this->time = date('y-d');
42 parent::__construct(); 39 parent::__construct();
43 } 40 }
44 41
45 42
46 public function start(): int 43 public function start(): int
47 { 44 {
48 - # 0 - 未推送  
49 - # 1 - 已推送  
50 - # 2 - 其他问题  
51 $status = 0; 45 $status = 0;
52 $lists = DataFile::query()->where('status', $status) 46 $lists = DataFile::query()->where('status', $status)
53 ->where('created_at', 'like', $this->time . '%')->first(); 47 ->where('created_at', 'like', $this->time . '%')->first();
@@ -56,23 +50,44 @@ class WebsiteData extends Command @@ -56,23 +50,44 @@ class WebsiteData extends Command
56 sleep(60); 50 sleep(60);
57 return 0; 51 return 0;
58 } 52 }
59 - $key = $this->signature . '-' . $lists->id;  
60 - $count = redis_get($key);  
61 - $isRes = http_post($this->url, json_encode(['data' => $lists->getOriginal()]));  
62 - if (!$isRes) {  
63 - if ($count == 2) {  
64 - $lists->is_pdf = 2;  
65 - $lists->save();  
66 - $this->debug_echo('项目文件数据推送失败! - 其他原因 - ' . $key);  
67 - } else {  
68 - redis_add($key, $count + 1);  
69 - $this->debug_echo('项目文件数据推送失败! - ' . $key);  
70 - }  
71 - }  
72 - $lists->status = 1;  
73 - $lists->save();  
74 - $this->debug_echo('项目文件数据保存成功!');  
75 - return 0; 53 + var_dump($lists);
  54 + exit();
  55 + $data = $lists['items'];
  56 +
  57 + $url = env('AICC_URL');
  58 + $msg = http_post($url, json_encode(compact('data')));
  59 +
  60 + }
  61 +
  62 + /**
  63 + * Execute the console command.
  64 + *
  65 + * @return int
  66 + */
  67 +// public function handle()
  68 +// {
  69 +// $DataFile = new DataFile();
  70 +// $data = $DataFile->allData();
  71 +// # 详细数据
  72 +// $items = $data['items'];
  73 +// # 总分页
  74 +// $totalPage = $data['totalPage'];
  75 +// $this->post_data($items);
  76 +// if ($totalPage > 1) {
  77 +// for ($page = 2; $page <= $totalPage; $page++) {
  78 +// $da = $DataFile->allData($page);
  79 +// $this->post_data($da['items']);
  80 +// }
  81 +// }
  82 +// $this->info('项目文件数据推送完成!');
  83 +// return 0;
  84 +// }
  85 +
  86 + public function post_data($data)
  87 + {
  88 + $url = env('AICC_URL');
  89 + $msg = http_post($url, json_encode(compact('data')));
  90 + print_r($msg);
76 } 91 }
77 92
78 } 93 }
@@ -9,7 +9,6 @@ use GuzzleHttp\Client; @@ -9,7 +9,6 @@ use GuzzleHttp\Client;
9 use GuzzleHttp\Exception\GuzzleException; 9 use GuzzleHttp\Exception\GuzzleException;
10 use Illuminate\Support\Carbon; 10 use Illuminate\Support\Carbon;
11 use App\Models\File\File; 11 use App\Models\File\File;
12 -use Illuminate\Support\Facades\Redis;  
13 12
14 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/'); 13 define('HTTP_OPENAI_URL', 'http://openai.waimaoq.com/');
15 /** 14 /**
@@ -617,29 +616,3 @@ function getRouteMap($source,$source_id){ @@ -617,29 +616,3 @@ function getRouteMap($source,$source_id){
617 } 616 }
618 return $route; 617 return $route;
619 } 618 }
620 -  
621 -function redis_get($key){  
622 - return Redis::connection()->client()->get($key);  
623 -}  
624 -function redis_del(...$key){  
625 - return Redis::connection()->client()->del(...$key);  
626 -}  
627 -  
628 -function redis_set($key,$val,$ttl=3600){  
629 - return Redis::connection()->client()->set($key,$val,$ttl);  
630 -}  
631 -  
632 -/**  
633 - * 添加缓存,存在则失败  
634 - * @param $key  
635 - * @param $val  
636 - * @param int $ttl  
637 - * @return mixed  
638 - * @author:dc  
639 - * @time 2023/10/25 9:48  
640 - */  
641 -function redis_add($key,$val,$ttl=3600){  
642 - return Redis::connection()->client()->eval(  
643 - "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])", [$key, $val, $ttl], 1  
644 - );  
645 -}  
  1 +Options +FollowSymLinks -Indexes
  2 +RewriteEngine On
  3 +
  4 +RewriteCond %{HTTP:Authorization} .
  5 +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  6 +
  7 +RewriteCond %{REQUEST_FILENAME} !-d
  8 +RewriteCond %{REQUEST_FILENAME} !-f
  9 +RewriteRule ^ index.php [L]