瀏覽代碼

Merge remote-tracking branch 'origin/master'

q 1 年之前
父節點
當前提交
3ffe8d53ec
共有 2 個文件被更改,包括 40 次插入7 次删除
  1. 31 7
      Modules/Camera/Http/Controllers/Api/CameraApiController.php
  2. 9 0
      config/filesystems.php

+ 31 - 7
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -866,6 +866,11 @@ class CameraApiController extends BaseController
 
         if(count($result) > 0){
             for($i=0;$i<count($result);$i++){
+                if($result[$i]->type=="mkxw"){
+                    unset($result[$i]);
+                    $newObject = ['type' => 'mkxw','name'=>'煤矿新闻'];
+                    array_unshift($result, $newObject);
+                }
                 if($result[$i]->type == 'aqsc'){
                     $result[$i]->name = '安全生产';
                 }
@@ -923,7 +928,9 @@ class CameraApiController extends BaseController
 
         $result = DB::connection('etl_zaoquan')->select("select * from news_column_list where type = '".$params['type']."' order by create_time desc limit ".$params['page_size']." offset ".$offset);
 
-        $pattern = '/<img(.*?)src=["\'](.*?)["\'](.*?)>/i';
+        $pattern = '/<img(.*?)src=["\'](.*?)["\'](.*?)>/i';//图片
+
+        $pattern2 = '/href="([^"]+)"/';//文件
 
         if(count($result) > 0){
             for($i=0;$i<count($result);$i++){
@@ -942,8 +949,9 @@ class CameraApiController extends BaseController
 
                 unset($result[$i]->create_time);
 
-                //替换text
+                //替换text的图片
                 preg_match_all($pattern, $result[$i]->text, $matches);
+
                 foreach ($matches[2] as $index => $oldSrc) {
                     $news_img_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
                     if(count($news_img_list) > 0){
@@ -951,6 +959,18 @@ class CameraApiController extends BaseController
                         $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
                     }
                 }
+
+                //替换text的文件
+                preg_match_all($pattern2, $result[$i]->text, $matches2);
+
+                foreach ($matches2[1] as $index => $oldSrc) {
+                    $news_file_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
+                    if(count($news_file_list) > 0){
+                        $newSrc = $news_file_list[0]->new_name;
+
+                        $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
+                    }
+                }
             }
         }
 
@@ -987,20 +1007,24 @@ class CameraApiController extends BaseController
         curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
         $rawdata = curl_exec ($ch);
         curl_close ($ch);
+
+        $houzhui = explode('.',$file_path);
+        $houzhui = '.'.$houzhui[count($houzhui)-1];
+
         // 使用中文文件名需要转码
-        $fp = fopen(public_path() . '/filedownload/' . $rename.'.jpg', 'w');
+        $fp = fopen(public_path() . '/filedownload/' . $rename.$houzhui, 'w');
         fwrite($fp, $rawdata);
         fclose($fp);
 
         $file_name = $rename;
 
         //上传文件
-        $file_oss_path = $this->uploadFile($file_name);
+        $file_oss_path = $this->uploadFile($file_name,$houzhui);
         return $file_oss_path;
     }
 
     //上传文件
-    public function uploadFile($file_name)
+    public function uploadFile($file_name,$houzhui)
     {
         try{
             $oss = new OssClient(
@@ -1009,8 +1033,8 @@ class CameraApiController extends BaseController
                 Config::get('filesystems.disks.oss_view.endpoint')
             );
 
-            $file_path = public_path() . '/filedownload/' . $file_name.'.jpg';
-            $res = $oss->uploadFile(Config::get('filesystems.disks.oss_view.bucket'), $file_name.'.jpeg', $file_path);
+            $file_path = public_path() . '/filedownload/' . $file_name.$houzhui;
+            $res = $oss->uploadFile(Config::get('filesystems.disks.oss_view.bucket'), $file_name.$houzhui, $file_path);
         } catch(\OssException $e) {
             printf(__FUNCTION__ . ": FAILED\n");
             printf($e->getMessage() . "\n");

+ 9 - 0
config/filesystems.php

@@ -73,6 +73,15 @@ return [
             'bucket'     => 'jiewei-php-view-files',//'http://colliery-system.oss-cn-qingdao.aliyuncs.com',//env('OSS_BUCKET'),
             'isCName'    => false,//env('OSS_IS_CNAME', false), // 如果 isCname 为 false,endpoint 应配置 oss 提供的域名如:`oss-cn-beijing.aliyuncs.com`,否则为自定义域名,,cname 或 cdn 请自行到阿里 oss 后台配置并绑定 bucket
         ],
+        'oss_colliery' => [
+            'driver'     => 'oss',
+            'root'       => '',
+            'access_key' => 'LTAICf62eG5csLjc',//env('OSS_ACCESS_KEY'),
+            'secret_key' => 'ZkWb0KW2sunAGQnt0k3SDtYrOb7GeQ',//env('OSS_SECRET_KEY'),
+            'endpoint'   => 'oss-cn-qingdao.aliyuncs.com',//env('OSS_ENDPOINT'), // 使用 ssl 这里设置如: https://oss-cn-beijing.aliyuncs.com
+            'bucket'     => 'colliery-system',//'http://colliery-system.oss-cn-qingdao.aliyuncs.com',//env('OSS_BUCKET'),
+            'isCName'    => false,//env('OSS_IS_CNAME', false), // 如果 isCname 为 false,endpoint 应配置 oss 提供的域名如:`oss-cn-beijing.aliyuncs.com`,否则为自定义域名,,cname 或 cdn 请自行到阿里 oss 后台配置并绑定 bucket
+        ],
 
     ],