作者 lms

合并分支 'lms' 到 'develop'

Lms



查看合并请求 !92
@@ -28,16 +28,18 @@ class ProjectFilePDF extends Command @@ -28,16 +28,18 @@ class ProjectFilePDF extends Command
28 */ 28 */
29 protected $description = '网站项目数据,生成PDF文件'; 29 protected $description = '网站项目数据,生成PDF文件';
30 30
31 - protected ProjectAssociation $AiccWechat; 31 + protected $AiccWechat;
32 32
33 - protected DataFile $DataFile; 33 + protected $ProjectAssociation;
  34 +
  35 + protected $DataFile;
34 36
35 protected $time; 37 protected $time;
36 38
37 - // 最大支持5个进程  
38 - public int $maxRunNumber = 50; 39 + protected $fileController;
39 40
40 - public FileController $fileController; 41 + // 最大支持5个进程
  42 + public $maxRunNumber = 50;
41 43
42 /** 44 /**
43 * Create a new command instance. 45 * Create a new command instance.
@@ -46,46 +48,52 @@ class ProjectFilePDF extends Command @@ -46,46 +48,52 @@ class ProjectFilePDF extends Command
46 */ 48 */
47 public function __construct() 49 public function __construct()
48 { 50 {
49 - $this->AiccWechat = new ProjectAssociation();  
50 - $this->DataFile = new DataFile();  
51 - $this->time = date("Y-m");  
52 - $this->fileController = new FileController(); 51 + $this->AiccWechat = new ProjectAssociation();
  52 + $this->ProjectAssociation = new ProjectAssociation();
  53 + $this->DataFile = new DataFile();
  54 + $this->time = date("Y-m");
  55 + $this->fileController = new FileController();
53 parent::__construct(); 56 parent::__construct();
54 } 57 }
55 58
56 public function start(): int 59 public function start(): int
57 { 60 {
58 - $status = 1; # 1 - 正常, 0 - 禁用  
59 - $is_pdf = 0; # 0 - 未生成 1 - 已生成 2 - 其它问题  
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('is_pdf', $is_pdf)->where('created_at', 'like', $this->time . '%')->first(); 61 + # 0 - 未生成
  62 + # 1 - 已生成
  63 + # 2 - 其它问题
  64 + $is_pdf = 0;
  65 + $lists = $this->ProjectAssociation::query()->where('is_pdf', $is_pdf)
  66 + ->where('project_id', '!=', 0)
  67 + ->where('friend_id', '!=', 0)
  68 + ->where('user_id', '!=', 0)
  69 + ->where('created_at', 'like', $this->time . '%')->first();
  70 +
65 if (is_null($lists)) { 71 if (is_null($lists)) {
66 $this->debug_echo('没有任务,等待中'); 72 $this->debug_echo('没有任务,等待中');
67 - sleep(60); 73 + sleep(30);
68 return 0; 74 return 0;
69 } 75 }
70 - $key = $this->signature . '-' . $lists->id;  
71 - $count = redis_get($key);  
72 - $item = $lists->getOriginal();  
73 - $project_id = $item->project_id;  
74 - $user_id = $item->user_id;  
75 - $friend_id = $item->friend_id; 76 + $key = $this->signature . '-' . $lists->id;
  77 + $count = redis_get($key);
  78 +
  79 + $project_id = $lists->project_id;
  80 + $user_id = $lists->user_id;
  81 + $friend_id = $lists->friend_id;
76 // todo 根据项目查询数据 82 // todo 根据项目查询数据
77 $project_data = []; 83 $project_data = [];
78 $html = $this->html($project_data); 84 $html = $this->html($project_data);
79 $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id); 85 $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
80 - $file_path = $this->savePDF($html, $filename); 86 +
  87 + $file_path = $this->savePDF($html, $filename);
81 if (empty($file_path)) { 88 if (empty($file_path)) {
82 $this->debug_echo('pdf生成失败!'); 89 $this->debug_echo('pdf生成失败!');
83 return 0; 90 return 0;
84 } 91 }
85 - $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]); 92 + $file_path = $file_path['data'];
  93 + $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
86 if (!$isRes) { 94 if (!$isRes) {
87 if ($count == 2) { 95 if ($count == 2) {
88 - $lists->is_pdf = 2; 96 + $lists->status = 2;
89 $lists->save(); 97 $lists->save();
90 $this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key); 98 $this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
91 } else { 99 } else {
@@ -93,12 +101,67 @@ class ProjectFilePDF extends Command @@ -93,12 +101,67 @@ class ProjectFilePDF extends Command
93 $this->debug_echo('项目文件数据保存失败! - ' . $key); 101 $this->debug_echo('项目文件数据保存失败! - ' . $key);
94 } 102 }
95 } 103 }
96 - $lists->is_pdf = 1; 104 + $lists->status = 1;
97 $lists->save(); 105 $lists->save();
98 $this->debug_echo('项目文件数据保存成功!'); 106 $this->debug_echo('项目文件数据保存成功!');
99 return 0; 107 return 0;
100 } 108 }
101 109
  110 + /**
  111 + * Execute the console command.
  112 + *
  113 + * @return int
  114 + */
  115 +// public function handle()
  116 +// {
  117 +// # 0 - 未生成
  118 +// # 1 - 已生成
  119 +// # 2 - 其它问题
  120 +// $is_pdf = 0;
  121 +// $lists = $this->ProjectAssociation::query()->where('is_pdf', $is_pdf)
  122 +// ->where('project_id', '!=', 0)
  123 +// ->where('friend_id', '!=', 0)
  124 +// ->where('user_id', '!=', 0)
  125 +// ->where('created_at', 'like', $this->time . '%')->first();
  126 +//
  127 +// if (is_null($lists)) {
  128 +// $this->error('没有任务,等待中');
  129 +// sleep(60);
  130 +// return 0;
  131 +// }
  132 +// $key = $this->signature . '-' . $lists->id;
  133 +// $count = redis_get($key);
  134 +// $project_id = $lists->project_id;
  135 +// $user_id = $lists->user_id;
  136 +// $friend_id = $lists->friend_id;
  137 +// // todo 根据项目查询数据
  138 +// $project_data = [];
  139 +// $html = $this->html($project_data);
  140 +// $filename = hash('md5', $this->time . '-' . $project_id . '-' . $friend_id . '-' . $user_id);
  141 +//
  142 +// $file_path = $this->savePDF($html, $filename);
  143 +// if (empty($file_path)) {
  144 +// $this->debug_echo('pdf生成失败!');
  145 +// return 0;
  146 +// }
  147 +// $file_path = $file_path['data'];
  148 +// $isRes = $this->DataFile->saveData(compact('project_id', 'user_id', 'friend_id', 'file_path') + ['time' => $this->time]);
  149 +// if (!$isRes) {
  150 +// if ($count == 2) {
  151 +// $lists->status = 2;
  152 +// $lists->save();
  153 +// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
  154 +// } else {
  155 +// redis_add($key, $count + 1);
  156 +// $this->error('项目文件数据保存失败! - ' . $key);
  157 +// }
  158 +// }
  159 +// $lists->status = 1;
  160 +// $lists->save();
  161 +// $this->info('项目文件数据保存成功!');
  162 +// return 0;
  163 +// }
  164 +
102 public function savePDF($html, $filename) 165 public function savePDF($html, $filename)
103 { 166 {
104 167
@@ -127,15 +190,14 @@ class ProjectFilePDF extends Command @@ -127,15 +190,14 @@ class ProjectFilePDF extends Command
127 $dompdf->render(); 190 $dompdf->render();
128 191
129 // 获取PDF内容 192 // 获取PDF内容
130 - $pdfContent = $dompdf->output(); 193 + $pdfContent = $dompdf->output();
  194 + $this->fileController->path = '/V6/PDF';
131 195
132 // 将PDF内容保存到文件 196 // 将PDF内容保存到文件
133 @file_put_contents($savePath, $pdfContent); 197 @file_put_contents($savePath, $pdfContent);
134 -  
135 // 创建一个文件实例 198 // 创建一个文件实例
136 $file = new File($savePath); 199 $file = new File($savePath);
137 -  
138 - return $this->fileController->single($file); 200 + return $this->fileController->api_upload_single($file);
139 } 201 }
140 202
141 /** 203 /**
@@ -148,7 +210,7 @@ class ProjectFilePDF extends Command @@ -148,7 +210,7 @@ class ProjectFilePDF extends Command
148 $html = '<html>'; 210 $html = '<html>';
149 $html .= '<body style="font-family:arial">'; 211 $html .= '<body style="font-family:arial">';
150 $html .= '<h1>Hello, World!</h1>'; 212 $html .= '<h1>Hello, World!</h1>';
151 - $html .= '<p>中文内容</p>'; 213 + $html .= '<p>中文内容ffffff</p>';
152 $html .= '</body>'; 214 $html .= '</body>';
153 $html .= '</html>'; 215 $html .= '</html>';
154 return $html; 216 return $html;
@@ -244,7 +244,7 @@ class ProjectUpdate extends Command @@ -244,7 +244,7 @@ class ProjectUpdate extends Command
244 for ($i = 0; $i < count($item['category']); $i++) { 244 for ($i = 0; $i < count($item['category']); $i++) {
245 $return = $this->get_category_name_arr($item['category'], $pid); 245 $return = $this->get_category_name_arr($item['category'], $pid);
246 if ($return) { 246 if ($return) {
247 - $category_arr[] = $return['name']; 247 + $category_arr[] = $this->special2str($return['name']);
248 $pid = $return['id']; 248 $pid = $return['id'];
249 } 249 }
250 } 250 }
1 -<?php  
2 -  
3 -namespace App\Console\Commands\Update;  
4 -  
5 -use App\Helper\Arr;  
6 -use App\Http\Logic\Bside\Product\CategoryLogic;  
7 -use App\Models\Blog\Blog;  
8 -use App\Models\Collect\CollectTask;  
9 -use App\Models\Com\UpdateLog;  
10 -use App\Models\News\News;  
11 -use App\Models\Product\Category;  
12 -use App\Models\Product\Keyword;  
13 -use App\Models\Product\Product;  
14 -use App\Models\RouteMap\RouteMap;  
15 -use App\Models\Template\BCustomTemplate;  
16 -use App\Models\WebSetting\WebSettingReceiving;  
17 -use App\Services\ProjectServer;  
18 -use Illuminate\Console\Command;  
19 -use Illuminate\Support\Facades\DB;  
20 -use Illuminate\Support\Facades\Redis;  
21 -  
22 -/**  
23 - * 4.0,5.0升级到6.0,内容同步  
24 - * Class ProjectImport  
25 - * @package App\Console\Commands  
26 - * @author Akun  
27 - * @date 2023/10/9 15:04  
28 - */  
29 -class Temp extends Command  
30 -{  
31 - /**  
32 - * The name and signature of the console command.  
33 - *  
34 - * @var string  
35 - */  
36 - protected $signature = 'project_update_temp';  
37 -  
38 - /**  
39 - * The console command description.  
40 - *  
41 - * @var string  
42 - */  
43 - protected $description = '执行项目升级任务';  
44 -  
45 -  
46 - public function handle()  
47 - {  
48 - $this->start_update();  
49 - }  
50 -  
51 - protected function start_update()  
52 - {  
53 -  
54 -// $data = UpdateLog::where('project_id','<=',530)->where('api_type','category')->get();  
55 - $data = UpdateLog::where('project_id', '=', 298)->where('api_type', 'category')->get();  
56 - foreach ($data as $task) {  
57 - $project_id = $task->project_id;  
58 - $api_type = $task->api_type;  
59 - $api_url_arr = explode('?', $task->api_url);  
60 - $api_url = $api_url_arr[0];  
61 -  
62 - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL;  
63 -  
64 - //设置数据库  
65 - $project = ProjectServer::useProject($project_id);  
66 - if ($project) {  
67 - //分类  
68 - $url = $api_url . '?' . http_build_query(['w' => 'category']);  
69 - $data = curl_c($url);  
70 - if (isset($data['code']) && $data['code'] == 200) {  
71 - $items = $data['data'] ?? [];  
72 - $this->category_insert($project_id, $items, 0);  
73 - } else {  
74 - continue;  
75 - }  
76 - }  
77 - //关闭数据库  
78 - DB::disconnect('custom_mysql');  
79 -  
80 - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;  
81 - }  
82 - }  
83 -  
84 - //获取地址路由  
85 - protected function get_url_route($url)  
86 - {  
87 - $arr = parse_url($url);  
88 - if (empty($arr['path'])) {  
89 - return '';  
90 - }  
91 - $path = $arr['path'];  
92 -  
93 - if (strpos($path, '.') !== false) {  
94 - $path = substr($path, 0, strpos($path, '.'));  
95 - }  
96 -  
97 - $path_arr = explode('/', $path);  
98 -  
99 - return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2];  
100 - }  
101 -  
102 - //多级分类入库  
103 - protected function category_insert($project_id, $items, $pid = 0)  
104 - {  
105 - $model = new Category();  
106 - foreach ($items as $item) {  
107 - if ($item['name'] ?? '') {  
108 - $parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id');  
109 - if (!$parent) {  
110 - try {  
111 - $item['name'] = $this->special2str($item['name']);  
112 - $parent_id = $model->addReturnId([  
113 - 'project_id' => $project_id,  
114 - 'title' => $item['name'],  
115 - 'pid' => $pid,  
116 - 'keywords' => $item['keywords'] ?? '',  
117 - 'describe' => $item['description'] ?? '',  
118 - 'route' => $this->get_url_route($item['url'])  
119 - ]);  
120 - $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);  
121 - } catch (\Exception $e) {  
122 - echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;  
123 - continue;  
124 - }  
125 - } else {  
126 - $parent_id = $parent['id'];  
127 - }  
128 -  
129 - if (!empty($item['children'])) {  
130 - $this->category_insert($project_id, $item['children'], $parent_id);  
131 - }  
132 - }  
133 - }  
134 - }  
135 -  
136 - //获取分类名称数组  
137 - protected function get_category_name_arr($category, $pid = 0)  
138 - {  
139 - foreach ($category as $k => $v) {  
140 - if ($v['parent'] == $pid) {  
141 - return $v;  
142 - }  
143 - }  
144 -  
145 - return [];  
146 - }  
147 -  
148 - //特殊字符转换  
149 - protected function special2str($str)  
150 - {  
151 - if (strpos($str, ';') === false) {  
152 - return $str;  
153 - }  
154 -  
155 - $list = [  
156 - '&lt;' => '<',  
157 - '&gt;' => '>',  
158 - '&amp;' => '&',  
159 - '&acute;' => '´',  
160 - '&quot;' => '“',  
161 - '&nbsp;' => ' '  
162 - ];  
163 -  
164 - foreach ($list as $k => $v) {  
165 - $str = str_replace($k, $v, $str);  
166 - }  
167 -  
168 - return $str;  
169 - }  
170 -  
171 - //路由入库  
172 - protected function set_map($route, $source, $source_id, $project_id)  
173 - {  
174 - if ($route) {  
175 - $route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first();  
176 - if (!$route_map) {  
177 - $route_map = new RouteMap();  
178 - $route_map->project_id = $project_id;  
179 - $route_map->source = $source;  
180 - $route_map->source_id = $source_id;  
181 - $route_map->route = $route;  
182 -  
183 - if ($source == RouteMap::SOURCE_NEWS) {  
184 - $route_map->path = RouteMap::SOURCE_NEWS;  
185 - } elseif ($source == RouteMap::SOURCE_BLOG) {  
186 - $route_map->path = RouteMap::SOURCE_BLOG;  
187 - }  
188 -  
189 - $route_map->save();  
190 - }  
191 - }  
192 - }  
193 -}  
@@ -69,7 +69,7 @@ class UpdateProgress extends Command @@ -69,7 +69,7 @@ class UpdateProgress extends Command
69 if(!empty($info)){ 69 if(!empty($info)){
70 $info = (array)$info; 70 $info = (array)$info;
71 //超时时间 71 //超时时间
72 - $time = date("Y-m-d H:i:s",strtotime($info['created_at']) + $info['total_num'] * 60); 72 + $time = date("Y-m-d H:i:s",strtotime($info['created_at']) + $info['total_num'] * 30);
73 if($time > date("Y-m-d H:i:s")){ 73 if($time > date("Y-m-d H:i:s")){
74 DB::connection('custom_mysql')->table('gl_update_progress')->where('id',$info['id'])->update(['current_num'=>$info['total_num']]); 74 DB::connection('custom_mysql')->table('gl_update_progress')->where('id',$info['id'])->update(['current_num'=>$info['total_num']]);
75 //获取当前项目的用户 75 //获取当前项目的用户
@@ -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 *
@@ -38,10 +36,49 @@ class WebsiteData extends Command @@ -38,10 +36,49 @@ class WebsiteData extends Command
38 public function __construct() 36 public function __construct()
39 { 37 {
40 $this->time = date('Y-m'); 38 $this->time = date('Y-m');
41 - $this->url = env('AICC_URL');  
42 parent::__construct(); 39 parent::__construct();
43 } 40 }
44 41
  42 + /**
  43 + * Execute the console command.
  44 + *
  45 + * @return int
  46 + */
  47 +// public function handle()
  48 +// {
  49 +// # 0 - 未推送
  50 +// # 1 - 已推送
  51 +// # 2 - 其他问题
  52 +// $status = 0;
  53 +// $lists = DataFile::query()->where('status', $status)
  54 +// ->where('created_at', 'like', $this->time . '%')->first();
  55 +// if (is_null($lists)) {
  56 +// $this->error('没有任务,等待中');
  57 +// sleep(30);
  58 +// return 0;
  59 +// }
  60 +//
  61 +// $key = $this->signature . '-' . $lists->id;
  62 +// $count = redis_get($key);
  63 +// $data = $lists;
  64 +//
  65 +// $url = env('AICC_URL');
  66 +// $msg = http_post($url, json_encode(compact('data')));
  67 +// $status_code = $msg['status'];
  68 +// if ($status_code != 200) {
  69 +// if ($count == 2) {
  70 +// $lists->status = 2;
  71 +// $lists->save();
  72 +// $this->error('项目文件数据保存失败! - 其他原因 - ' . $key);
  73 +// } else {
  74 +// redis_add($key, $count + 1);
  75 +// $this->error('项目文件数据保存失败! - ' . $key);
  76 +// }
  77 +// }
  78 +// $lists->status = 1;
  79 +// $lists->save();
  80 +// return 0;
  81 +// }
45 82
46 public function start(): int 83 public function start(): int
47 { 84 {
@@ -53,26 +90,61 @@ class WebsiteData extends Command @@ -53,26 +90,61 @@ class WebsiteData extends Command
53 ->where('created_at', 'like', $this->time . '%')->first(); 90 ->where('created_at', 'like', $this->time . '%')->first();
54 if (is_null($lists)) { 91 if (is_null($lists)) {
55 $this->debug_echo('没有任务,等待中'); 92 $this->debug_echo('没有任务,等待中');
56 - sleep(60); 93 + sleep(30);
57 return 0; 94 return 0;
58 } 95 }
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) { 96 +
  97 + $key = $this->signature . '-' . $lists->id;
  98 + $count = redis_get($key);
  99 + $data = $lists;
  100 + $url = env('AICC_URL');
  101 + $msg = http_post($url, json_encode(compact('data')));
  102 + $status_code = $msg['status'];
  103 + if ($status_code != 200) {
63 if ($count == 2) { 104 if ($count == 2) {
64 - $lists->is_pdf = 2; 105 + $lists->status = 2;
65 $lists->save(); 106 $lists->save();
66 - $this->debug_echo('项目文件数据推送失败! - 其他原因 - ' . $key); 107 + $this->debug_echo('项目文件数据保存失败! - 其他原因 - ' . $key);
67 } else { 108 } else {
68 redis_add($key, $count + 1); 109 redis_add($key, $count + 1);
69 - $this->debug_echo('项目文件数据推送失败! - ' . $key); 110 + $this->debug_echo('项目文件数据保存失败! - ' . $key);
70 } 111 }
71 } 112 }
72 $lists->status = 1; 113 $lists->status = 1;
73 $lists->save(); 114 $lists->save();
74 - $this->debug_echo('项目文件数据保存成功!'); 115 + $this->info('项目文件数据保存成功!');
75 return 0; 116 return 0;
76 } 117 }
77 118
  119 + /**
  120 + * Execute the console command.
  121 + *
  122 + * @return int
  123 + */
  124 +// public function handle()
  125 +// {
  126 +// $DataFile = new DataFile();
  127 +// $data = $DataFile->allData();
  128 +// # 详细数据
  129 +// $items = $data['items'];
  130 +// # 总分页
  131 +// $totalPage = $data['totalPage'];
  132 +// $this->post_data($items);
  133 +// if ($totalPage > 1) {
  134 +// for ($page = 2; $page <= $totalPage; $page++) {
  135 +// $da = $DataFile->allData($page);
  136 +// $this->post_data($da['items']);
  137 +// }
  138 +// }
  139 +// $this->info('项目文件数据推送完成!');
  140 +// return 0;
  141 +// }
  142 +
  143 + public function post_data($data)
  144 + {
  145 + $url = env('AICC_URL');
  146 + $msg = http_post($url, json_encode(compact('data')));
  147 + print_r($msg);
  148 + }
  149 +
78 } 150 }
@@ -107,8 +107,7 @@ class FileController @@ -107,8 +107,7 @@ class FileController
107 */ 107 */
108 public function single(&$files){ 108 public function single(&$files){
109 $hash = hash_file('md5', $files->getPathname()); 109 $hash = hash_file('md5', $files->getPathname());
110 -// $name = $files->getClientOriginalName();  
111 - $name = $files->getFilename(); 110 + $name = $files->getClientOriginalName();
112 //查看文件是否存在 111 //查看文件是否存在
113 $fileModel = new File(); 112 $fileModel = new File();
114 //查看图片是否已上传 113 //查看图片是否已上传
@@ -121,8 +120,7 @@ class FileController @@ -121,8 +120,7 @@ class FileController
121 return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name)); 120 return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
122 } 121 }
123 $url = $this->config['root'].$this->path; 122 $url = $this->config['root'].$this->path;
124 -// $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();  
125 - $fileName = uniqid().rand(10000,99999).'.'.$files->getExtension(); 123 + $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
126 //同步数据到cos 124 //同步数据到cos
127 if($this->upload_location == 1){ 125 if($this->upload_location == 1){
128 $cosService = new CosService(); 126 $cosService = new CosService();
@@ -138,6 +136,53 @@ class FileController @@ -138,6 +136,53 @@ class FileController
138 } 136 }
139 137
140 /** 138 /**
  139 + * 接口上传单文件
  140 + * @param $files
  141 + * @return array
  142 + */
  143 + public function api_upload_single(&$files)
  144 + {
  145 + $hash = hash_file('md5', $files->getPathname());
  146 + $name = $files->getFilename();
  147 + //查看文件是否存在
  148 + $fileModel = new File();
  149 + //查看图片是否已上传
  150 + $param = ['hash' => $hash, 'refer' => $this->param['refer'] ?? 0];
  151 + if (isset($this->cache['project_id']) && !empty($this->cache['project_id'])) {
  152 + $param['project_id'] = $this->cache['project_id'];
  153 + }
  154 + $file_hash = $fileModel->read($param);
  155 + if ($file_hash !== false) {
  156 + return [
  157 + 'message' => '资源',
  158 + 'code' => Code::SUCCESS,
  159 + 'data' => $this->responseData($file_hash['path'], $name)
  160 + ];
  161 + }
  162 + $url = $this->config['root'] . $this->path;
  163 + $fileName = uniqid() . rand(10000, 99999) . '.' . $files->getExtension();
  164 + //同步数据到cos
  165 + if ($this->upload_location == 1) {
  166 + $cosService = new CosService();
  167 + $cosService->uploadFile($files, $this->path, $fileName);
  168 + } else {
  169 + $res = $files->move($url, $fileName);
  170 + if ($res === false) {
  171 + return [
  172 + 'message' => $files->getError(),
  173 + 'code' => Code::USER_ERROR
  174 + ];
  175 + }
  176 + }
  177 + $this->saveMysql($fileModel, $files->getSize(), $files->getExtension(), $fileName, $hash, $this->upload_location, $files->getMimeType(), $name);
  178 + return [
  179 + 'message' => '资源',
  180 + 'code' => Code::SUCCESS,
  181 + 'data' => $this->responseData($this->path . '/' . $fileName, $name)
  182 + ];
  183 + }
  184 +
  185 + /**
141 * @remark :保存数据库 186 * @remark :保存数据库
142 * @name :saveMysql 187 * @name :saveMysql
143 * @author :lyh 188 * @author :lyh
@@ -204,7 +249,7 @@ class FileController @@ -204,7 +249,7 @@ class FileController
204 $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime,$name); 249 $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime,$name);
205 $data[] = $this->responseData($this->path.'/'.$fileName, $name); 250 $data[] = $this->responseData($this->path.'/'.$fileName, $name);
206 } 251 }
207 - $this->response('资源',Code::SUCCESS,$data); 252 + $this->response('资源',Code::SUCCESS,$data);
208 } 253 }
209 254
210 255
  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]