| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\common\CommonOverRun;
- use app\models\common\CommonUpload;
- use app\models\UploadConfig;
- use Yii;
- use yii\web\Response;
- use app\modules\admin\models\StorageForm;
- use app\models\Storage;
- class StorageController extends BaseController
- {
- /**
- * 上传图片
- * @return Response
- */
- public function actionUploadImages()
- {
- $form = new StorageForm();
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $form->parent_id = input_params('parent_id', 0);
- $res = $form->uploadFile(Storage::TYPE_IMAGE);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res,
- ]);
- }
- /**
- * 上传表格
- * @return Response
- */
- public function actionUploadXlsx()
- {
- $form = new StorageForm();
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $form->parent_id = input_params('parent_id', 0);
- $res = $form->uploadFile(Storage::TYPE_XlSX);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res,
- ]);
- }
- /**
- * 上传视频
- * @return Response
- */
- public function actionUploadVideos()
- {
- $form = new StorageForm();
- $form->parent_id = input_params('parent_id', 0);
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $form->supplier_id = get_supplier_id();
- $res = $form->uploadFile(Storage::TYPE_VIDEO);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res,
- ]);
- }
- public function actionUploadAudio()
- {
- $form = new StorageForm();
- $form->parent_id = input_params('parent_id', 0);
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $res = $form->uploadFile(Storage::TYPE_AUDIO);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res,
- ]);
- }
- /**
- * 上传证书文件
- * @return Response
- */
- public function actionUploadCrt()
- {
- $form = new StorageForm();
- $form->parent_id = input_params('parent_id', 0);
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $res = $form->uploadFile(Storage::TYPE_CRT);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'status' => 'done',
- 'data' => $res,
- ]);
- }
- /**
- * 上传证书文件
- * @return Response
- */
- public function actionUploadPfx()
- {
- $form = new StorageForm();
- // $form->parent_id = input_params('parent_id', 0);
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $res = $form->uploadFile(Storage::TYPE_PFX);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'status' => 'done',
- 'data' => $res,
- ]);
- }
- /**
- * 上传证书文件
- * @return Response
- */
- public function actionUploadPem()
- {
- $form = new StorageForm();
- // $form->parent_id = input_params('parent_id', 0);
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $res = $form->uploadFile(Storage::TYPE_PEM);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'status' => 'done',
- 'data' => $res,
- ]);
- }
- /**
- * 上传证书文件
- * @return Response
- */
- public function actionUploadCer()
- {
- $form = new StorageForm();
- // $form->parent_id = input_params('parent_id', 0);
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $res = $form->uploadFile(Storage::TYPE_CER);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'status' => 'done',
- 'data' => $res,
- ]);
- }
- /**
- * 上传apk文件
- * @return Response
- */
- public function actionUploadApp()
- {
- $form = new StorageForm();
- $form->parent_id = input_params('parent_id', 0);
- $form->upload_config = UploadConfig::getConf(get_store_id());
- $res = $form->uploadFile(Storage::TYPE_APK);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'status' => 'done',
- 'data' => $res,
- ]);
- }
- /**
- * 获取storage配置
- * @return Response
- */
- public function actionStorageOption()
- {
- $form = new StorageForm();
- $type = get_params('type');
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $form->getStorageOption($type),
- ]);
- }
- /**
- * 获取文件列表
- * @return Response
- */
- public function actionGetList()
- {
- $form = new StorageForm();
- $form->parent_id = input_params('parent_id', 0);
- $form->type = input_params('type', Storage::TYPE_IMAGE);
- $form->search_name = input_params('search_name');
- $form->sort_type = input_params('sort_type', 'id');
- $form->sort_method = input_params('sort_method', 'ASC');
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $form->getList(),
- ]);
- }
- /**
- * 创建目录
- * @return Response
- */
- public function actionAddDir()
- {
- $dirName = input_params('dir_name');
- if (! $dirName) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '目录名称不能为空'
- ]);
- }
- try {
- $form = new StorageForm();
- $form->parent_id = input_params('parent_id', 0);
- if ($form->addDir($dirName)) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '目录创建成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '目录创建失败'
- ]);
- } catch (\Throwable $throwable) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $throwable->getMessage(),
- ]);
- }
- }
- /**
- * 重命名
- * @return Response
- */
- public function actionRename()
- {
- $name = input_params('name');
- $id = input_params('id');
- if (! $id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少必要参数ID'
- ]);
- }
- if (! $name) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '名称不能为空'
- ]);
- }
- try {
- $form = new StorageForm();
- $form->rename($id, $name);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '操作成功'
- ]);
- } catch (\Throwable $throwable) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $throwable->getMessage(),
- ]);
- }
- }
- /**
- * 批量删除资源
- * @return Response
- */
- public function actionDelete()
- {
- try {
- $ids = input_params('ids');
- $form = new StorageForm();
- $form->deleteById($ids);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- } catch (\Throwable $throwable) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $throwable->getMessage(),
- ]);
- }
- }
- /**
- * 删除目录
- * @return Response
- */
- public function actionDeleteDir()
- {
- try {
- $id = input_params('id');
- $form = new StorageForm();
- $form->deleteDirById($id);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- } catch (\Throwable $throwable) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $throwable->getMessage(),
- ]);
- }
- }
- /**
- * 获取目录树
- * @return Response
- */
- public function actionGetDirTree()
- {
- // 该字段用来排除目录, 如果有数据就会过滤该目录及下级目录
- $exclude_id = input_params('exclude_id');
- $form = new StorageForm();
- $res = $form->getDirTree(0, $exclude_id);
- $data = [[
- 'key' => '0',
- 'title' => '根目录',
- 'children' => $res,
- ]];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data,
- ]);
- }
- /**
- * 移动目录
- * @return Response
- */
- public function actionDragDir()
- {
- try {
- $parent_id = input_params('parent_id', 0);
- $ids = input_params('ids');
- $form = new StorageForm();
- $form->dragDir($parent_id, $ids);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '移动成功'
- ]);
- } catch (\Throwable $throwable) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $throwable->getMessage(),
- ]);
- }
- }
- /**
- * 上传设置
- */
- public function actionConfig()
- {
- $model = UploadConfig::findOne([
- 'store_id' => get_store_id(),
- 'is_delete' => 0,
- ]);
- if (!$model) {
- $model = new UploadConfig();
- }
- if (\Yii::$app->request->isPost) {
- $form = new CommonUpload();
- $form->attributes = post_params();
- $form->model = $model;
- $form->store_id = get_store_id();
- return $this->asJson($form->save());
- } else {
- $model->aliyun = json_decode($model->aliyun, true);
- $model->qcloud = json_decode($model->qcloud, true);
- $model->qiniu = json_decode($model->qiniu, true);
- return $this->asJson([
- 'code' => 0,
- 'data' => $model
- ]);
- }
- }
- /**
- * 越限设置
- * @return string
- * @throws \Exception
- */
- public function actionRunOver()
- {
- if (\Yii::$app->request->isPost) {
- $form = new CommonOverRun();
- $form->attributes = post_params();
- return $this->asJson($form->save());
- } else {
- $form = new CommonOverRun();
- return $this->asJson($form->search());
- }
- }
- }
|