mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-10 17:42:50 +00:00
调整上传类
This commit is contained in:
parent
a9dc22ddc0
commit
de84cc4d60
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,4 +6,6 @@
|
||||
runtime/
|
||||
install.lock
|
||||
public/uploads
|
||||
remarks.txt
|
||||
remarks.txt
|
||||
*.jpg
|
||||
*.png
|
||||
|
||||
@ -211,7 +211,7 @@ class AgentManage extends AuthController
|
||||
if(!$imageInfo){
|
||||
$res = \app\models\routine\RoutineCode::getShareCode($uid, 'spread', '', '');
|
||||
if(!$res) throw new \think\Exception('二维码生成失败');
|
||||
$imageInfo = UploadService::getInstance()->setUploadPath('routine/spread/code')->imageStream($name,$res['res']);
|
||||
$imageInfo = UploadService::instance()->setUploadPath('routine/spread/code')->imageStream($name,$res['res']);
|
||||
if(!is_array($imageInfo)) return $imageInfo;
|
||||
SystemAttachment::attachmentAdd($imageInfo['name'],$imageInfo['size'],$imageInfo['type'],$imageInfo['dir'],$imageInfo['thumb_path'],1,$imageInfo['image_type'],$imageInfo['time']);
|
||||
RoutineQrcode::setRoutineQrcodeFind($res['id'],['status'=>1,'time'=>time(),'qrcode_url'=>$imageInfo['dir']]);
|
||||
@ -246,7 +246,7 @@ class AgentManage extends AuthController
|
||||
if(!$imageInfo){
|
||||
$res = \app\models\routine\RoutineCode::getShareCode($uid, 'spread', '', '');
|
||||
if(!$res) return JsonService::fail('二维码生成失败');
|
||||
$imageInfo = UploadService::getInstance()->setUploadPath('routine/spread/code')->imageStream($name,$res['res']);
|
||||
$imageInfo = UploadService::instance()->setUploadPath('routine/spread/code')->imageStream($name,$res['res']);
|
||||
if(!is_array($imageInfo)) return JsonService::fail($imageInfo);
|
||||
SystemAttachment::attachmentAdd($imageInfo['name'],$imageInfo['size'],$imageInfo['type'],$imageInfo['dir'],$imageInfo['thumb_path'],1,$imageInfo['image_type'],$imageInfo['time']);
|
||||
RoutineQrcode::setRoutineQrcodeFind($res['id'],['status'=>1,'time'=>time(),'qrcode_url'=>$imageInfo['dir']]);
|
||||
|
||||
@ -99,7 +99,7 @@ class Article extends AuthController
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload_image(){
|
||||
$res = Upload::getInstance()->setUploadPath('wechat/image/'.date('Ymd'))->image($_POST['file']);
|
||||
$res = Upload::instance()->setUploadPath('wechat/image/'.date('Ymd'))->image($_POST['file']);
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
|
||||
return Json::successful('上传成功!',['url'=>$res['dir']]);
|
||||
|
||||
@ -72,7 +72,7 @@ class ArticleCategory extends AuthController
|
||||
* s上传图片
|
||||
* */
|
||||
public function upload(){
|
||||
$res = Upload::getInstance()->setUploadPath('article')->image('file');
|
||||
$res = Upload::instance()->setUploadPath('article')->image('file');
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
|
||||
@ -89,7 +89,7 @@ class WechatNews extends AuthController
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload_image(){
|
||||
$res = Upload::getInstance()->setUploadPath('wechat/image/'.date('Ymd'))->image($_POST['file']);
|
||||
$res = Upload::instance()->setUploadPath('wechat/image/'.date('Ymd'))->image($_POST['file']);
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
|
||||
return Json::successful('上传成功!',['url'=>$res['thumb_path']]);
|
||||
|
||||
@ -400,7 +400,7 @@ class SystemConfig extends AuthController
|
||||
* 文件上传
|
||||
* */
|
||||
public function file_upload(){
|
||||
$res = Upload::getInstance()->setUploadPath('config/file')->file($this->request->param('file','file'));
|
||||
$res = Upload::instance()->setUploadPath('config/file')->file($this->request->param('file','file'));
|
||||
if(!$res->status) return Json::fail($res->error);
|
||||
return Json::successful('上传成功!',['filePath'=>$res->filePath]);
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ class SystemGroupData extends AuthController
|
||||
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::getInstance()->setUploadPath('common')->image('file');
|
||||
$res = Upload::instance()->setUploadPath('common')->image('file');
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],6,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
|
||||
@ -770,7 +770,7 @@ class CopyTaobao extends AuthController
|
||||
$size = strlen(trim($content));
|
||||
if (!$content || $size <= 2) return '图片流获取失败';
|
||||
$date_dir = date('Y') . DS . date('m') . DS . date('d');
|
||||
$imageInfo = UploadService::getInstance()->setUploadPath('attach/' . $date_dir)->imageStream($name, $content);
|
||||
$imageInfo = UploadService::instance()->setUploadPath('attach/' . $date_dir)->imageStream($name, $content);
|
||||
if (!is_array($imageInfo)) return $imageInfo;
|
||||
$date['path'] = $imageInfo['dir'];
|
||||
$date['name'] = $imageInfo['name'];
|
||||
|
||||
@ -107,7 +107,7 @@ class StoreCategory extends AuthController
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::getInstance()->setUploadPath('store/category'.date('Ymd'))->image('file');
|
||||
$res = Upload::instance()->setUploadPath('store/category'.date('Ymd'))->image('file');
|
||||
if(is_array($res)){
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],1,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
|
||||
@ -68,7 +68,7 @@ class StoreInfoMana extends AuthController
|
||||
* */
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::getInstance()->setUploadPath('article/'.date('Ymd'))->image('file');
|
||||
$res = Upload::instance()->setUploadPath('article/'.date('Ymd'))->image('file');
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],2,$res['image_type'],$res['time']);
|
||||
if(is_array($res))
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
|
||||
@ -176,7 +176,7 @@ class StoreProduct extends AuthController
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::getInstance()->setUploadPath('store/product/'.date('Ymd'))->image('file');
|
||||
$res = Upload::instance()->setUploadPath('store/product/'.date('Ymd'))->image('file');
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],1,$res['image_type'],$res['time']);
|
||||
if(is_array($res))
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
|
||||
@ -21,7 +21,7 @@ class SystemAttachment extends AuthController
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::getInstance()->setUploadPath('editor/'.date('Ymd'))->image('upfile');
|
||||
$res = Upload::instance()->setUploadPath('editor/'.date('Ymd'))->image('upfile');
|
||||
if(is_array($res)){
|
||||
SystemAttachmentModel::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],0,$res['image_type'],$res['time']);
|
||||
$info["originalName"] = $res['name'];
|
||||
|
||||
@ -191,7 +191,7 @@ class StoreSeckill extends AuthController
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::getInstance()->setUploadPath('store/product/'.date('Ymd'))->image('file');
|
||||
$res = Upload::instance()->setUploadPath('store/product/'.date('Ymd'))->image('file');
|
||||
if(is_array($res)){
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],4,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
|
||||
@ -82,7 +82,7 @@ class Reply extends AuthController
|
||||
{
|
||||
$name = $this->request->post('file');
|
||||
if(!$name) return Json::fail('请上传图片');
|
||||
$res = Upload::getInstance()->setUploadType(1)->setUploadPath('wechat/image')
|
||||
$res = Upload::instance()->setUploadType(1)->setUploadPath('wechat/image')
|
||||
->setAutoValidate(true)->image($name);
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],0,$res['image_type'],$res['time']);
|
||||
@ -93,7 +93,7 @@ class Reply extends AuthController
|
||||
{
|
||||
$name = $this->request->post('file');
|
||||
if(!$name) return Json::fail('请上传声音');
|
||||
$res = Upload::getInstance()->setUploadPath('wechat/voice')->setAutoValidate(true)->file($name);
|
||||
$res = Upload::instance()->setUploadPath('wechat/voice')->setAutoValidate(true)->file($name);
|
||||
return $res->status === true ? Json::successful('上传成功',$res->filePath) : Json::fail($res->error);
|
||||
}
|
||||
|
||||
|
||||
@ -136,7 +136,7 @@ class StoreService extends AuthController
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::getInstance()->setUploadPath('store/product/'.date('Ymd'))->image('file');
|
||||
$res = Upload::instance()->setUploadPath('store/product/'.date('Ymd'))->image('file');
|
||||
if(is_array($res)){
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],2,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
|
||||
@ -71,7 +71,7 @@ class Images extends AuthController
|
||||
$upload_type = $this->request->get('upload_type',0);
|
||||
try{
|
||||
$path = make_path('attach',2,true);
|
||||
$res = Upload::getInstance()->setUploadPath($path)->setAutoValidate(true)
|
||||
$res = Upload::instance()->setUploadPath($path)->setAutoValidate(true)
|
||||
->setUploadType($upload_type)->image('file');
|
||||
if(is_object($res) && $res->status === false){
|
||||
$info = array(
|
||||
|
||||
@ -137,7 +137,7 @@ class PublicController
|
||||
],$request);
|
||||
if(!$data['filename']) return app('json')->fail('参数有误');
|
||||
if(Cache::has('start_uploads_'.$request->uid()) && Cache::get('start_uploads_'.$request->uid()) >= 100) return app('json')->fail('非法操作');
|
||||
$res = UploadService::getInstance()->setUploadPath('store/comment')->image($data['filename']);
|
||||
$res = UploadService::instance()->setUploadPath('store/comment')->image($data['filename']);
|
||||
if(!is_array($res)) return app('json')->fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'],1, $res['image_type'], $res['time'], 2);
|
||||
if(Cache::has('start_uploads_'.$request->uid()))
|
||||
|
||||
@ -314,7 +314,7 @@ class StoreBargainController
|
||||
if($user['is_promoter'] || sysConfig('store_brokerage_statu') == 2) $valueData.='&pid='.$user['uid'];
|
||||
$res = RoutineCode::getPageCode('pages/activity/goods_bargain_details/index',$valueData,280);
|
||||
if(!$res) return app('json')->fail('二维码生成失败');
|
||||
$imageInfo = UploadService::getInstance()->setUploadPath('routine/activity/bargain/code')->imageStream($name,$res);
|
||||
$imageInfo = UploadService::instance()->setUploadPath('routine/activity/bargain/code')->imageStream($name,$res);
|
||||
if(!is_array($imageInfo)) return app('json')->fail($imageInfo);
|
||||
if($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl.$imageInfo['dir']);
|
||||
else $remoteImage = UtilService::remoteImage($imageInfo['dir']);
|
||||
|
||||
@ -204,7 +204,7 @@ class StoreCombinationController
|
||||
if($user['is_promoter'] || sysConfig('store_brokerage_statu')==2) $valueData.='&pid='.$user['uid'];
|
||||
$res = RoutineCode::getPageCode('pages/activity/goods_combination_status/index',$valueData,280);
|
||||
if(!$res) return app('json')->fail('二维码生成失败');
|
||||
$imageInfo = UploadService::getInstance()->setUploadPath('routine/activity/pink/code')->imageStream($name,$res);
|
||||
$imageInfo = UploadService::instance()->setUploadPath('routine/activity/pink/code')->imageStream($name,$res);
|
||||
if(!is_array($imageInfo)) return app('json')->fail($imageInfo);
|
||||
if($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl.$imageInfo['dir']);
|
||||
else $remoteImage = UtilService::remoteImage($imageInfo['dir']);
|
||||
|
||||
@ -79,7 +79,7 @@ class StoreProductController
|
||||
if($user['is_promoter'] || sysConfig('store_brokerage_statu')==2) $data.='&pid='.$user['uid'];
|
||||
$res = \app\models\routine\RoutineCode::getPageCode('pages/goods_details/index',$data,280);
|
||||
if(!$res) return app('json')->fail('二维码生成失败');
|
||||
$imageInfo = \crmeb\services\UploadService::getInstance()->setUploadPath('routine/product')->imageStream($name,$res);
|
||||
$imageInfo = \crmeb\services\UploadService::instance()->setUploadPath('routine/product')->imageStream($name,$res);
|
||||
if(is_string($imageInfo)) return app('json')->fail($imageInfo);
|
||||
if($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl.$imageInfo['dir']);
|
||||
else $remoteImage = UtilService::remoteImage($imageInfo['dir']);
|
||||
|
||||
@ -166,7 +166,7 @@ class UserBillController
|
||||
if(!$imageInfo){
|
||||
$res = RoutineCode::getShareCode($user['uid'], 'spread', '', '');
|
||||
if(!$res) return app('json')->fail('二维码生成失败');
|
||||
$imageInfo = UploadService::getInstance()->setUploadPath('routine/spread/code')->imageStream($name,$res['res']);
|
||||
$imageInfo = UploadService::instance()->setUploadPath('routine/spread/code')->imageStream($name,$res['res']);
|
||||
if(!is_array($imageInfo)) return app('json')->fail($imageInfo);
|
||||
SystemAttachment::attachmentAdd($imageInfo['name'],$imageInfo['size'],$imageInfo['type'],$imageInfo['dir'],$imageInfo['thumb_path'],1,$imageInfo['image_type'],$imageInfo['time'],2);
|
||||
RoutineQrcode::setRoutineQrcodeFind($res['id'],['status'=>1,'time'=>time(),'qrcode_url'=>$imageInfo['dir']]);
|
||||
|
||||
@ -10,13 +10,23 @@ namespace crmeb\services;
|
||||
use crmeb\services\storage\COS;
|
||||
use crmeb\services\storage\OSS;
|
||||
use crmeb\services\storage\Qiniu;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use crmeb\traits\LogicTrait;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use think\File;
|
||||
|
||||
/**
|
||||
* Class UploadService
|
||||
* @package crmeb\services
|
||||
* @method $this setReturnErr(bool $returnErr) 设置发生错误时是否返回错误信息
|
||||
* @method $this setAutoValidate(bool $autoValidate) 设置是否校验上传文件
|
||||
* @method $this setUploadType(int $uploadType) 设置上传类型
|
||||
* @method $this setImageValidate(string $imageValidate) 设置上传图片大小等验证信息
|
||||
* @method $this setUploadPath(string $uploadPath) 设置文件上传路径
|
||||
*/
|
||||
class UploadService
|
||||
{
|
||||
use LogicTrait;
|
||||
/**
|
||||
* 文件校验
|
||||
* @var bool
|
||||
@ -61,87 +71,24 @@ class UploadService
|
||||
*/
|
||||
private static $uploadStatus;
|
||||
|
||||
/**
|
||||
* 本类实例化
|
||||
* @var
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* 上传图片的大小 2MB 单位字节
|
||||
* @var string
|
||||
*/
|
||||
protected $imageValidate = 'filesize:2097152|fileExt:jpg,jpeg,png,gif,pem|fileMime:image/jpeg,image/gif,image/png,text/plain';
|
||||
|
||||
protected $propsRule = [
|
||||
'returnErr' => false,
|
||||
'autoValidate' => false,
|
||||
'uploadPath' => null,
|
||||
'uploadType' => null,
|
||||
];
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
self::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UploadService
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance)) self::$instance = new self();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传图片大小等验证信息
|
||||
* @param string $imageValidate
|
||||
* @return $this
|
||||
*/
|
||||
public function setImageValidate(string $imageValidate)
|
||||
{
|
||||
$this->imageValidate = $imageValidate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否校验上传文件
|
||||
* @param bool $autoValidate
|
||||
* @return $this
|
||||
*/
|
||||
public function setAutoValidate(bool $autoValidate)
|
||||
{
|
||||
$this->autoValidate = $autoValidate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传路径
|
||||
* @param string $uploadPath
|
||||
* @return $this
|
||||
*/
|
||||
public function setUploadPath(string $uploadPath)
|
||||
{
|
||||
$this->uploadPath = $uploadPath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上传类型
|
||||
* @param int $uploadType
|
||||
* @return $this
|
||||
*/
|
||||
public function setUploadType(int $uploadType)
|
||||
{
|
||||
$this->uploadType = $uploadType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置发生错误时是否返回错误信息
|
||||
* @param bool $returnErr
|
||||
* @return $this
|
||||
*/
|
||||
public function serReturnErr(bool $returnErr)
|
||||
{
|
||||
$this->returnErr = $returnErr;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
@ -465,8 +412,8 @@ class UploadService
|
||||
return DS . $savePath;
|
||||
}
|
||||
|
||||
protected function __clone()
|
||||
protected function __destruct()
|
||||
{
|
||||
// TODO: Implement __clone() method.
|
||||
// TODO: Implement __destruct() method.
|
||||
}
|
||||
}
|
||||
@ -511,7 +511,7 @@ class UtilService
|
||||
$res = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999) . '.jpg';
|
||||
return UploadService::getInstance()->setUploadPath($path)->imageStream($key, $res);
|
||||
return UploadService::instance()->setUploadPath($path)->imageStream($key, $res);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user