123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?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\admin\system\attachment;
- use app\common\AdminBaseController;
- use app\Request;
- use app\services\system\attachment\SystemAttachmentServices;
- use app\services\system\admin\SystemAdminServices;
- use qiniu\services\CacheService;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Response;
- /**
- * 图片管理类
- * Class SystemAttachment
- * @package app\controller\admin\v1\file
- */
- class SystemAttachment extends AdminBaseController
- {
- protected $service;
- public function __construct(Request $request, SystemAttachmentServices $service)
- {
- parent::__construct($request);
- $this->service = $service;
- $this->searchable = [
- ['name', ''],
- ['pid', 0],
- ['file_type', 1]
- ];
- }
- /**
- * 显示列表
- * @return mixed
- * @throws DbException
- */
- public function index()
- {
- $where = $this->request->getMore($this->searchable);
- $where['type'] = 1;
- return $this->success($this->service->getImageList($where));
- }
- /**
- * 删除指定资源
- *
- * @return Response
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function batchDelete()
- {
- $ids = $this->request->post('ids', '');
- $this->service->del($ids);
- return $this->success('删除成功');
- }
- /**图片上传
- * @param int $upload_type
- * @param int $type
- * @return mixed
- */
- public function upload(int $upload_type = 0, int $type = 0)
- {
- [$pid, $file] = $this->request->postMore([
- ['pid', 0],
- ['file', 'file'],
- ], true);
- $res = $this->service->upload((int)$pid, $file, (int)$upload_type, (int)$type);
- return $this->success('上传成功', ['src' => $res]);
- }
- /**
- * 移动图片
- * @return mixed
- */
- public function moveImageCate()
- {
- $data = $this->request->postMore([
- ['pid', 0],
- ['images', '']
- ]);
- $this->service->move($data);
- return $this->success('移动成功');
- }
- /**
- * 修改文件名
- * @param $id
- * @return mixed
- */
- public function update($id)
- {
- $realName = $this->request->post('real_name', '');
- if (!$realName) {
- return $this->error('文件名称不能为空');
- }
- $this->service->update($id, ['real_name' => $realName]);
- return $this->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->error('上传信息为空');
- $res = $this->service->videoUpload($data, $fileHandle);
- 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, 1, 0, (int)$data['upload_type']);
- return app('json')->success($res);
- }
- /**网络图片上传
- * @return Response
- * @throws \Exception
- */
- public function onlineUpload()
- {
- $data = $this->request->postMore([
- ['pid', 0],
- ['images', []]
- ]);
- $this->service->onlineUpload($data);
- return app('json')->success('上传完成');
- }
- }
|