wesmiler преди 1 месец
родител
ревизия
46a9c95cba
променени са 6 файла, в които са добавени 199 реда и са изтрити 5 реда
  1. 24 4
      app/Helpers/common.php
  2. 18 0
      app/Models/ConfigModel.php
  3. 4 0
      app/Services/Common/ConfigService.php
  4. 85 0
      app/Services/QiniuService.php
  5. 1 0
      composer.json
  6. 67 1
      composer.lock

+ 24 - 4
app/Helpers/common.php

@@ -915,6 +915,13 @@ if (!function_exists('get_image_path')) {
         if (empty($image_url)) {
             return false;
         }
+
+        // 是否七牛
+        $driver = \App\Services\ConfigService::make()->getConfigByCode('file_upload_driver','local');
+        if($driver == 'qiniu'){
+            return $image_url;
+        }
+
         $data = explode('/uploads', $image_url);
         return $data ? end($data) : $image_url;
     }
@@ -1041,17 +1048,21 @@ if (!function_exists('get_format_content')) {
         }
 
         $domain = request()->header('HOST');
+        $driver = \App\Services\ConfigService::make()->getConfigByCode('file_upload_driver','local');
         if(preg_match("/127/", $domain)){
             $host = env('IMG_URL','');
             if(empty($host)){
                 $https = request()->secure();
                 $host = ($https ? 'https://' : 'http://') . $host . '/uploads';
             }
+        }else if($driver == 'qiniu'){
+            $host = \App\Services\ConfigService::make()->getConfigByCode('qiniu_host','');
         }else{
             $https = request()->secure();
             $host = ($https ? 'https://' : 'http://') . $domain . '/uploads';
         }
 
+
         $content = str_replace(["\"/uploads","'/uploads"],["\"{$host}","'{$host}"], htmlspecialchars_decode($content));
         return  $content;
     }
@@ -1885,11 +1896,20 @@ if (!function_exists('upload_image')) {
         $file_name = ($userId? $userId.'_'.str_replace('=','',base64_encode(date('YmdHis').$userId.$original_name)): str_replace('=','',base64_encode(date('YmdHis').$original_name)));
         $file_name =  $file_name. '.' . $ext;
 
-        // 重命名保存
-        $path = $file->move($file_dir, $file_name);
+        $driver = \App\Services\ConfigService::make()->getConfigByCode('file_upload_driver','local');
+        if($driver == 'qiniu'){
+            // 上传云
+            $file_path = \App\Services\QiniuService::make()->upload($file_name, $file);
+        }else{
+            // 重命名保存
+            $path = $file->move($file_dir, $file_name);
+            // 文件临时路径
+            $file_path = str_replace(ATTACHMENT_PATH, '', $file_dir) . '/' . $file_name;
+        }
+
+
+
 
-        // 文件临时路径
-        $file_path = str_replace(ATTACHMENT_PATH, '', $file_dir) . '/' . $file_name;
 
         // 返回结果
         $result = [

+ 18 - 0
app/Models/ConfigModel.php

@@ -35,6 +35,24 @@ class ConfigModel extends BaseModel
                 $info['value'] = json_decode($info['value'], true);
             }
 
+            if($type == 'select' && $info['options']){
+                $options = [];
+                $datas = explode("\n", $info['options']);
+                foreach($datas as $v){
+                    $v = explode('=', $v);
+                    $key = isset($v[0])? $v[0] : '';
+                    $name = isset($v[1])? $v[1] : '';
+                    if($key && $name){
+                        $options[] = [
+                            'label'=> $name,
+                            'value'=> $key
+                        ];
+                    }
+
+                }
+                $info['options_value'] = $options;
+            }
+
         }
         return $info;
     }

+ 4 - 0
app/Services/Common/ConfigService.php

@@ -83,6 +83,10 @@ class ConfigService extends BaseService
             $data['value'] = $data['value']? str_replace(['|','-',':'],['|','-',':'], $data['value']) : '';
         }
 
+        if(isset($data['options_value'])){
+            unset($data['options_value']);
+        }
+
         $data['options'] = isset($data['options'])? $data['options'] :'';
 
         RedisService::keyDel("caches:config:app*");

+ 85 - 0
app/Services/QiniuService.php

@@ -0,0 +1,85 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services;
+
+use Qiniu\Auth;
+use Qiniu\Storage\UploadManager;
+
+/**
+ * 七牛存储接口管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Services
+ */
+class QiniuService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+    protected $host = '';
+    protected $accessKey = '';
+    protected $secretKey = '';
+    protected $bucket = '';
+
+    public function __construct()
+    {
+        $this->accessKey = ConfigService::make()->getConfigByCode('qiniu_access_key');
+        $this->secretKey = ConfigService::make()->getConfigByCode('qiniu_secret_key');
+        $this->bucket = ConfigService::make()->getConfigByCode('qiniu_bucket','');
+        $this->host = ConfigService::make()->getConfigByCode('qiniu_host','');
+    }
+
+    /**
+     * 静态入口
+     */
+    public static function make(){
+        if(!self::$instance){
+            self::$instance = new static();
+        }
+
+        return self::$instance;
+    }
+
+
+    /**
+     * 查询
+     * @param $no 快递单号
+     * @param string $phone // 手机号
+     * @param string $code 快递公司编号
+     * @return bool
+     */
+    public function upload($filename,$file)
+    {
+        // 配置参数
+        if(empty($this->apiKey) || empty($this->apiCode) || empty($this->bucket) || empty($this->host)){
+            $this->error = '接口参数未配置';
+            return false;
+        }
+
+        // 初始化鉴权对象
+        $auth = new Auth($this->accessKey, $this->secretKey);
+
+        // 生成上传策略
+        $policy = null;
+        $uptoken = $auth->uploadToken($this->bucket, $filename, 3600, $policy);
+
+        // 初始化 UploadManager 对象并进行文件上传
+        $uploadMgr = new UploadManager();
+        list($ret, $err) = $uploadMgr->putFile($uptoken, $filename, $file->getPathname());
+
+        if ($err !== null) {
+            $this->error = '图片上传失败:' . $err->getMessage();
+            return false;
+        } else {
+            return $this->host . '/' . $filename;
+        }
+    }
+}

+ 1 - 0
composer.json

@@ -21,6 +21,7 @@
         "laravel/socialite": "^5.6",
         "laravel/tinker": "^2.5",
         "maatwebsite/excel": "^3.1",
+        "qiniu/php-sdk": "^7.14",
         "socialiteproviders/weixin": "^4.1",
         "yansongda/pay": "~3.4.0"
     },

+ 67 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "674157fc281d4efd8a5b95110ca8f2b9",
+    "content-hash": "6e1492a68bbcf2b27213b8c8fafdf458",
     "packages": [
         {
             "name": "asm89/stack-cors",
@@ -4434,6 +4434,72 @@
             "time": "2025-11-28T00:00:14+00:00"
         },
         {
+            "name": "qiniu/php-sdk",
+            "version": "v7.14.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/qiniu/php-sdk.git",
+                "reference": "ee752ffa7263ce99fca0bd7340cf13c486a3516c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/qiniu/php-sdk/zipball/ee752ffa7263ce99fca0bd7340cf13c486a3516c",
+                "reference": "ee752ffa7263ce99fca0bd7340cf13c486a3516c",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-curl": "*",
+                "ext-xml": "*",
+                "myclabs/php-enum": "~1.5.2 || ~1.6.6 || ~1.7.7 || ~1.8.4",
+                "php": ">=5.3.3"
+            },
+            "require-dev": {
+                "paragonie/random_compat": ">=2",
+                "phpunit/phpunit": "^4.8 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4",
+                "squizlabs/php_codesniffer": "^2.3 || ~3.6"
+            },
+            "type": "library",
+            "autoload": {
+                "files": [
+                    "src/Qiniu/functions.php",
+                    "src/Qiniu/Http/Middleware/Middleware.php"
+                ],
+                "psr-4": {
+                    "Qiniu\\": "src/Qiniu"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Qiniu",
+                    "email": "sdk@qiniu.com",
+                    "homepage": "http://www.qiniu.com"
+                }
+            ],
+            "description": "Qiniu Resource (Cloud) Storage SDK for PHP",
+            "homepage": "http://developer.qiniu.com/",
+            "keywords": [
+                "cloud",
+                "qiniu",
+                "sdk",
+                "storage"
+            ],
+            "support": {
+                "issues": "https://github.com/qiniu/php-sdk/issues",
+                "source": "https://github.com/qiniu/php-sdk/tree/v7.14.0"
+            },
+            "time": "2024-10-25T08:39:01+00:00"
+        },
+        {
             "name": "ralouphie/getallheaders",
             "version": "3.0.3",
             "source": {