| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace api\modules\v1\controllers;
- use api\controllers\OnAuthController;
- use common\helpers\UploadHelper;
- use common\models\common\Attachment;
- /**
- * 文件上传
- *
- * Class FileController
- * @Author: hua
- * @DateTime: 2021/10/14 9:46
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @package api\modules\v1\controllers
- */
- class FileController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index', 'search','upload'];
- /**
- * 上传
- * @Author: hua
- * @DateTime: 2021/10/14 9:46
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionUpload()
- {
- try {
- ini_set('memory_limit', '512M');
- $post = \Yii::$app->request->post();
- if (empty($post['upload_type']) || !isset(Attachment::$uploadTypeExplain[$post['upload_type']])) {
- return $this->error('上传类型有误');
- }
- $config = \Yii::$app->services->attachment->getStorageConfig($this->mall_id);
- $config['mall_id'] = $this->mall_id;
- $upload = new UploadHelper($config, $post['upload_type']);
- $upload->verifyFile();
- $upload->save();
- return $this->success('上传成功',$upload->getBaseInfo($this->mall_id,$this->user->mch_id ?? 0,0));
- } catch (\Exception $e) {
- return $this->error('上传失败:'.$e->getMessage());
- }
- }
- }
|