作者 lyh

gx

@@ -112,12 +112,6 @@ zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K @@ -112,12 +112,6 @@ zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
112 * "linkedin", "instagram","youtube", "reddit" ,"telegram"" 112 * "linkedin", "instagram","youtube", "reddit" ,"telegram""
113 */ 113 */
114 public function post_send_msg($param){ 114 public function post_send_msg($param){
115 - $param = [  
116 - 'post'=>$param['post'],//内容(帖子文本)  
117 - 'platforms'=>$param['platforms'],//平台  
118 - 'idempotencyKey'=>$param['idempotencyKey'],//帖子唯一id  
119 - 'mediaUrls'=>$param['mediaUrls'],  
120 - ];  
121 //平台参数处理 115 //平台参数处理
122 $this->headers['Accept-Encoding'] = 'gzip'; 116 $this->headers['Accept-Encoding'] = 'gzip';
123 $this->headers['Authorization'] = $this->headers['Authorization'].$param['profile_key']; 117 $this->headers['Authorization'] = $this->headers['Authorization'].$param['profile_key'];
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\AyrShare;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic;
  7 +
  8 +/**
  9 + * @name:社交发布
  10 + */
  11 +class AyrReleaseController extends BaseController
  12 +{
  13 + /**
  14 + * @name :(发布社交)send_post
  15 + * @author :lyh
  16 + * @method :post
  17 + * @time :2023/5/9 9:36
  18 + */
  19 + public function send_post(AyrReleaseLogic $ayrReleaseLogic){
  20 + //保存数据库
  21 + $ayrReleaseLogic->release_add();
  22 +
  23 + }
  24 +
  25 +}
@@ -101,54 +101,4 @@ class AyrShareController extends BaseController @@ -101,54 +101,4 @@ class AyrShareController extends BaseController
101 $this->response('success',Code::SUCCESS,$res); 101 $this->response('success',Code::SUCCESS,$res);
102 } 102 }
103 103
104 - /**  
105 - * @name :(获取当前用户的配置文件)get_profiles  
106 - * @author :lyh  
107 - * @method :post  
108 - * @time :2023/5/6 16:39  
109 - */  
110 - public function get_profiles(AyrShareLogic $ayrShareLogic){  
111 - $this->request->validate([  
112 - 'id'=>['required']  
113 - ],[  
114 - 'id.required' => 'ID不能为空'  
115 - ]);  
116 - $info = $ayrShareLogic->ayr_share_info();  
117 - //发送请求注册社交用户  
118 - $ayrShareHelper = new AyrShareHelper();  
119 - $data = [  
120 - 'title'=>$info['title'],  
121 - 'refId'=>$info['ref_id'],  
122 - 'profileKeys'=>$info['profile_keys']  
123 - ];  
124 - $res = $ayrShareHelper->post_generate_jwt($data);  
125 - if($res['status'] == 'fail'){  
126 - $this->response($res['message'],Code::USER_ERROR);  
127 - }  
128 - $this->response('success',Code::SUCCESS,$res);  
129 - }  
130 -  
131 - /**  
132 - * @name :(上传图片到第三方)post_uploads  
133 - * @author :lyh  
134 - * @method :post  
135 - * @time :2023/5/8 13:45  
136 - */  
137 - public function post_uploads(){  
138 -  
139 - }  
140 - /**  
141 - * @name :(发布推文到第三方平台)send_api_post  
142 - * @author :lyh  
143 - * @method :post  
144 - * @time :2023/5/8 13:37  
145 - */  
146 - public function send_api_post(AyrShareLogic $ayrShareLogic){  
147 - $this->request->validate([  
148 - 'id'=>['required']  
149 - ],[  
150 - 'id.required' => 'ID不能为空'  
151 - ]);  
152 - $info = $ayrShareLogic->ayr_share_info();  
153 - }  
154 } 104 }
@@ -160,6 +160,9 @@ class BaseController extends Controller @@ -160,6 +160,9 @@ class BaseController extends Controller
160 case 'image': 160 case 'image':
161 $data['image_link'] = url('/b/image/' . $v); 161 $data['image_link'] = url('/b/image/' . $v);
162 break; 162 break;
  163 + case 'file':
  164 + $data['file_link'] = url('/b/file_hash/' . $v);
  165 + break;
163 case 'operator_id': 166 case 'operator_id':
164 if(!empty($v)){ 167 if(!empty($v)){
165 $name = (new UserModel())->read(['operator_id'=>$v],['id','name']); 168 $name = (new UserModel())->read(['operator_id'=>$v],['id','name']);
@@ -9,9 +9,7 @@ use App\Http\Controllers\Bside\json; @@ -9,9 +9,7 @@ use App\Http\Controllers\Bside\json;
9 use App\Http\Logic\Bside\ProjectGroupLogic; 9 use App\Http\Logic\Bside\ProjectGroupLogic;
10 use App\Http\Logic\Bside\User\GroupLogic; 10 use App\Http\Logic\Bside\User\GroupLogic;
11 use App\Http\Requests\Bside\User\ProjectGroupRequest; 11 use App\Http\Requests\Bside\User\ProjectGroupRequest;
12 -use App\Models\ProjectGroup as ProjectGroupModel;  
13 -use App\Models\User\User as UserModel;  
14 -use Illuminate\Http\Request; 12 +use App\Models\User\ProjectGroup;
15 13
16 14
17 /** 15 /**
@@ -25,9 +23,9 @@ class ProjectGroupController extends BaseController @@ -25,9 +23,9 @@ class ProjectGroupController extends BaseController
25 * @author :liyuhang 23 * @author :liyuhang
26 * @method 24 * @method
27 */ 25 */
28 - public function lists(ProjectGroupModel $projectGroupModel) 26 + public function lists(ProjectGroup $projectGroup)
29 { 27 {
30 - $lists = $projectGroupModel->lists($this->map,$this->page,$this->row); 28 + $lists = $projectGroup->lists($this->map,$this->page,$this->row);
31 $this->response('success',Code::SUCCESS,$lists); 29 $this->response('success',Code::SUCCESS,$lists);
32 } 30 }
33 31
@@ -4,6 +4,9 @@ namespace App\Http\Controllers\file; @@ -4,6 +4,9 @@ namespace App\Http\Controllers\file;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Models\File\File; 6 use App\Models\File\File;
  7 +use App\Models\File\Image as ImageModel;
  8 +use Illuminate\Http\Exceptions\HttpResponseException;
  9 +use Illuminate\Http\JsonResponse;
7 10
8 class FileController 11 class FileController
9 { 12 {
@@ -30,10 +33,17 @@ class FileController @@ -30,10 +33,17 @@ class FileController
30 { 33 {
31 $this->request = request(); 34 $this->request = request();
32 $this->config = config('filesystems.disks.upload'); 35 $this->config = config('filesystems.disks.upload');
33 - $this->path = $this->config['root']; 36 + $this->path = $this->config['root'].'/file/';
34 } 37 }
35 38
36 - public function index($hash = '', $w = 0 ,$h = 0){ 39 + /**
  40 + * @param :(获取文件)$hash
  41 + * @name :index
  42 + * @author :lyh
  43 + * @method :post
  44 + * @time :2023/5/9 9:15
  45 + */
  46 + public function index($hash = ''){
37 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) { 47 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
38 header("HTTP/1.1 304 Not Modified"); 48 header("HTTP/1.1 304 Not Modified");
39 exit; 49 exit;
@@ -51,4 +61,110 @@ class FileController @@ -51,4 +61,110 @@ class FileController
51 $header['Content-Length'] = $info['size']; 61 $header['Content-Length'] = $info['size'];
52 return response($content, 200, $header); 62 return response($content, 200, $header);
53 } 63 }
  64 + /**
  65 + * 图片上传
  66 + */
  67 + public function upload() {
  68 + $this->request->validate([
  69 + 'image'=>['required'],
  70 + ],[
  71 + 'image.required'=>'图片必须填写',
  72 + ]);
  73 + $files = $this->request->file('file');
  74 + if (empty($files)) {
  75 + $this->response('没有上传的文件!', 400);
  76 + }
  77 + $type = $this->request->post('type', 'single');
  78 + if ($type == 'multi') {
  79 + return $this->multi($files);
  80 + } else {
  81 + return $this->single($files);
  82 + }
  83 + }
  84 + /**
  85 + * @name :上传图片
  86 + * @return void
  87 + * @author :liyuhang
  88 + * @method
  89 + */
  90 + public function single($files){
  91 + $hash = hash_file('md5', $files->getPathname());
  92 + //查看文件是否存在
  93 + $fileModel = new File();
  94 + $file_hash = $fileModel->read(['hash'=>$hash]);
  95 + if($file_hash !== false){
  96 + return $hash;
  97 + }
  98 + $url = $this->path;
  99 + $res = $this->request->file('image')->move($url);
  100 + if ($res === false) {
  101 + return $this->response($files->getError(), Code::USER_ERROR);
  102 + }
  103 + $data = [
  104 + 'path' => $url.'/'.$res->getClientOriginalName(),
  105 + 'created_at' => date('Y-m-d H:i:s',time()),
  106 + 'size' => $res->getSize(),
  107 + 'hash' => $hash,
  108 + 'type'=>$files->getClientOriginalExtension(),
  109 + ];
  110 + $rs = $fileModel->add($data);
  111 + if ($rs === false) {
  112 + return $this->response('添加失败', Code::USER_ERROR);
  113 + }
  114 + return $hash;
  115 + }
  116 + /**
  117 + * 多文件上传
  118 + * @param type $files file对象集合
  119 + * @return type
  120 + */
  121 + private function multi($files) {
  122 + if (!is_array($files)) {
  123 + $files = [$files];
  124 + }
  125 + $save_data = [];
  126 + $data = [];
  127 + foreach ($files as $file) {
  128 + $fileModel = new File();
  129 + $hash = hash_file('md5', $file->getPathname());
  130 + $file_hash = $fileModel->read(['hash'=>$hash]);
  131 + if($file_hash !== false){
  132 + $data[] = $hash;
  133 + continue;
  134 + }
  135 + $url = $this->path;
  136 + $res = $file->move($url);
  137 + if ($res === false) {
  138 + return $this->response($file->getError(), Code::USER_ERROR);
  139 + }
  140 + $save_data[] = [
  141 + 'path' => $url.'/'.$res->getClientOriginalName(),
  142 + 'created_at' => date('Y-m-d H:i:s',time()),
  143 + 'size' => $res->getSize(),
  144 + 'hash' => $hash,
  145 + 'type'=>$files->getClientOriginalExtension(),
  146 + ];
  147 + $data[] = $hash;
  148 + }
  149 + $fileModel->insert($save_data);
  150 + return $data;
  151 + }
  152 + /**
  153 + * @name 统一返回参数
  154 + * @return JsonResponse
  155 + * @author :liyuhang
  156 + * @method
  157 + */
  158 + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
  159 + {
  160 + $code = Code::fromValue($code);
  161 + $result = [
  162 + 'msg' => $msg == ' ' ? $code->description : $msg,
  163 + 'code' => $code->value,
  164 + 'data' => $data,
  165 + ];
  166 + $this->header['Content-Type'] = $type;
  167 + $response = response($result,$result_code,$this->header);
  168 + throw new HttpResponseException($response);
  169 + }
54 } 170 }
@@ -80,6 +80,7 @@ class ImageController @@ -80,6 +80,7 @@ class ImageController
80 $img_base64 = 'data:image/' . $img_type . ';base64,' . $content; 80 $img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
81 return response($img_base64, 200, $header); 81 return response($img_base64, 200, $header);
82 } 82 }
  83 +
83 /** 84 /**
84 * 图片上传 85 * 图片上传
85 */ 86 */
@@ -100,6 +101,7 @@ class ImageController @@ -100,6 +101,7 @@ class ImageController
100 return $this->single($files); 101 return $this->single($files);
101 } 102 }
102 } 103 }
  104 +
103 /** 105 /**
104 * @name :上传图片 106 * @name :上传图片
105 * @return void 107 * @return void
@@ -115,7 +117,6 @@ class ImageController @@ -115,7 +117,6 @@ class ImageController
115 return $hash; 117 return $hash;
116 } 118 }
117 $url = $this->path; 119 $url = $this->path;
118 - $filename = date('ymdHis').rand(10000,99999);  
119 $res = $this->request->file('image')->move($url); 120 $res = $this->request->file('image')->move($url);
120 if ($res === false) { 121 if ($res === false) {
121 return $this->response($files->getError(), Code::USER_ERROR); 122 return $this->response($files->getError(), Code::USER_ERROR);
@@ -167,13 +168,12 @@ class ImageController @@ -167,13 +168,12 @@ class ImageController
167 continue; 168 continue;
168 } 169 }
169 $url = $this->path; 170 $url = $this->path;
170 - $filename = date('ymdHis').rand(10000,99999);  
171 - $res = $file->move($url,$filename); 171 + $res = $file->move($url);
172 if ($res === false) { 172 if ($res === false) {
173 return $this->response($file->getError(), Code::USER_ERROR); 173 return $this->response($file->getError(), Code::USER_ERROR);
174 } 174 }
175 $save_data[] = [ 175 $save_data[] = [
176 - 'path' => $url.'/'.$filename, 176 + 'path' => $url.'/'.$res->getClientOriginalName(),
177 'created_at' => date('Y-m-d H:i:s',time()), 177 'created_at' => date('Y-m-d H:i:s',time()),
178 'size' => $res->getSize(), 178 'size' => $res->getSize(),
179 'hash' => $hash, 179 'hash' => $hash,
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\AyrShare;
  4 +
  5 +use App\Http\Logic\Bside\BaseLogic;
  6 +use App\Models\AyrShare\AyrRelease;
  7 +
  8 +class AyrReleaseLogic extends BaseLogic
  9 +{
  10 +
  11 +
  12 + public function __construct()
  13 + {
  14 + parent::__construct();
  15 + $this->model = new AyrRelease();
  16 + $this->param = $this->requestAll;
  17 + }
  18 +
  19 + /**
  20 + * @name :(发布社交写入数据库)release_add
  21 + * @author :lyh
  22 + * @method :post
  23 + * @time :2023/5/9 9:38
  24 + */
  25 + public function release_add(){
  26 + $rs = $this->model->add($this->param);
  27 + if($rs === false){
  28 + $this->fail('error');
  29 + }
  30 + return $this->success();
  31 + }
  32 +}
@@ -9,10 +9,11 @@ use App\Models\AyrShare\AyrShare; @@ -9,10 +9,11 @@ use App\Models\AyrShare\AyrShare;
9 9
10 class AyrShareLogic extends BaseLogic 10 class AyrShareLogic extends BaseLogic
11 { 11 {
  12 +
  13 +
12 public function __construct() 14 public function __construct()
13 { 15 {
14 parent::__construct(); 16 parent::__construct();
15 -  
16 $this->model = new AyrShare(); 17 $this->model = new AyrShare();
17 $this->param = $this->requestAll; 18 $this->param = $this->requestAll;
18 } 19 }
1 <?php 1 <?php
2 2
3 -namespace App\Models; 3 +namespace App\Models\User;
  4 +
  5 +use App\Models\Base;
4 6
5 class ProjectGroup extends Base 7 class ProjectGroup extends Base
6 { 8 {
@@ -192,7 +192,10 @@ Route::middleware(['bloginauth'])->group(function () { @@ -192,7 +192,10 @@ Route::middleware(['bloginauth'])->group(function () {
192 Route::prefix('images')->group(function () { 192 Route::prefix('images')->group(function () {
193 Route::post('/upload', [\App\Http\Controllers\file\ImageController::class, 'upload'])->name('image_upload'); 193 Route::post('/upload', [\App\Http\Controllers\file\ImageController::class, 'upload'])->name('image_upload');
194 }); 194 });
195 - 195 + //文件上传第三方操作
  196 + Route::prefix('files')->group(function () {
  197 + Route::post('/upload', [\App\Http\Controllers\file\FileController::class, 'upload'])->name('files_upload');
  198 + });
196 //精准询盘 199 //精准询盘
197 Route::prefix('inquiry')->group(function () { 200 Route::prefix('inquiry')->group(function () {
198 Route::get('/', [\App\Http\Controllers\Bside\InquiryController::class, 'index'])->name('inquiry'); 201 Route::get('/', [\App\Http\Controllers\Bside\InquiryController::class, 'index'])->name('inquiry');
@@ -218,7 +221,8 @@ Route::middleware(['bloginauth'])->group(function () { @@ -218,7 +221,8 @@ Route::middleware(['bloginauth'])->group(function () {
218 //无需登录验证的路由组 221 //无需登录验证的路由组
219 Route::group([], function () { 222 Route::group([], function () {
220 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); 223 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
221 - Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country'); 224 +// Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country');
222 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); 225 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
223 Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show'); 226 Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show');
  227 + Route::any('/file_hash/{hash}', [\App\Http\Controllers\file\FileController::class,'index'])->name('file_show');
224 }); 228 });