徐总多门店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
jiuhaoshenghuo/app/controller/supplier/file/SystemAttachment.php

231 lines
6.9 KiB

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\supplier\file;
use app\controller\supplier\AuthController;
use app\services\other\CacheServices;
use app\services\system\admin\SystemAdminServices;
use app\services\system\attachment\SystemAttachmentServices;
use think\facade\App;
/**
* 图片管理类
* Class SystemAttachment
* @package app\controller\store\file
*/
class SystemAttachment extends AuthController
{
protected $service;
public function __construct(App $app, SystemAttachmentServices $service)
{
parent::__construct($app);
$this->service = $service;
}
/**
* 显示列表
* @return mixed
*/
public function index()
{
$where = $this->request->getMore([
['pid', 0],
['file_type', 1]
]);
$where['type'] = 4;
$where['relation_id'] = $this->supplierId;
return app('json')->success($this->service->getImageList($where));
}
/**
* 删除指定资源
*
* @param string $ids
* @return \think\Response
*/
public function delete()
{
[$ids] = $this->request->postMore([
['ids', '']
], true);
$this->service->del($ids);
return app('json')->success('删除成功');
}
/**
* 图片上传
* @param int $upload_type
* @param int $type
* @return mixed
*/
public function upload($upload_type = 0, $type = 0)
{
[$pid, $file] = $this->request->postMore([
['pid', 0],
['file', 'file'],
], true);
$res = $this->service->storeUpload((int)$pid, $file, (int)$this->supplierId, 4);
return app('json')->success('上传成功', ['src' => $res]);
}
/**
* 移动图片
* @return mixed
*/
public function moveImageCate()
{
$data = $this->request->postMore([
['pid', 0],
['images', '']
]);
$this->service->move($data);
return app('json')->success('移动成功');
}
/**
* 修改文件名
* @param $id
* @return mixed
*/
public function update($id)
{
$realName = $this->request->post('real_name', '');
if (!$realName) {
return app('json')->fail('文件名称不能为空');
}
$this->service->update($id, ['real_name' => $realName]);
return app('json')->success('修改成功');
}
/**
* 获取上传类型
* @return mixed
*/
public function uploadType()
{
$data['upload_type'] = (string)sys_config('upload_type', 1);
return app('json')->success($data);
}
/**
* 视频分片上传
* @return mixed
*/
public function videoUpload()
{
$data = $this->request->postMore([
['chunkNumber', 0],//第几分片
['currentChunkSize', 0],//分片大小
['chunkSize', 0],//总大小
['totalChunks', 0],//分片总数
['file', 'file'],//文件
['md5', ''],//MD5
['filename', ''],//文件名称
['pid', 0],//分类ID
]);
$fileHandle = $this->request->file($data['file']);
if (!$fileHandle) return $this->fail('上传信息为空');
$res = $this->service->videoUpload($data, $fileHandle, 4, (int)$this->supplierId);
return app('json')->success($res);
}
/**
* 保存云端视频记录
* @return mixed
*/
public function saveVideoAttachment()
{
$data = $this->request->postMore([
['path', ''],//视频地址
['cover_image', ''],//封面地址
['pid', 0],//分类ID
['upload_type', 1],//上传类型
]);
$res = $this->service->saveOssVideoAttachment($data, 4, (int)$this->supplierId, (int)$data['upload_type']);
return app('json')->success($res);
}
/**获取扫码上传页面链接以及参数
* @return \think\Response
*/
public function scanUploadQrcode(CacheServices $services)
{
[$pid] = $this->request->getMore([
['pid', 0]
], true);
$uploadToken = md5(time());
$upload_file_size_max = config('upload.filesize');//文件上传大小kb
$services->setDbCache($this->supplierId.'_supplier_scan_upload', $uploadToken, 68400);
$url = sys_config('site_url') . '/app/upload?pid=' . $pid . '&cache='. $this->supplierId .'_supplier_scan_upload&type=4&relation_id='. $this->supplierId . '&upload_file_size_max=' . $upload_file_size_max . '&token=' . $uploadToken;
return app('json')->success(['url' => $url]);
}
/**删除二维码
* @return \think\Response
*/
public function removeUploadQrcode(CacheServices $services)
{
$services->delectDbCache($this->supplierId.'_supplier_scan_upload');
return app('json')->success();
}
/**获取扫码上传的图片数据
* @param $scan_token
* @return \think\Response
*/
public function scanUploadImage($scan_token)
{
return app('json')->success($this->service->scanUploadImage($scan_token));
}
/**网络图片上传
* @return \think\Response
*/
public function onlineUpload()
{
$data = $this->request->postMore([
['pid', 0],
['images', []]
]);
$this->service->onlineUpload($data,4,(int)$this->supplierId);
return app('json')->success('上传完成');
}
/**获取上传信息
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdminsData()
{
/** @var SystemAdminServices $adminServices */
$adminServices = app()->make(SystemAdminServices::class);
$data['is_way'] = $adminServices->value(['id'=>$this->supplierId], 'is_way');
$data['upload_file_size_max'] = config('upload.filesize');//文件上传大小kb
return app('json')->success($data);
}
/**保存上传信息
* @param int $is_way
* @return \think\Response
*/
public function setAdminsData(int $is_way = 0)
{
/** @var SystemAdminServices $adminServices */
$adminServices = app()->make(SystemAdminServices::class);
if(!in_array($is_way,[0,1,2])) return app('json')->fail('参数有误!');
$res = $adminServices->update($this->supplierId, ['is_way' => $is_way]);
if($res) return app('json')->success('ok');
else return app('json')->fail('保存失败');
}
}