| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace common\components;
- use common\helpers\UploadHelper;
- use common\models\common\Attachment;
- use common\traits\BaseControllerTrait;
- use Exception;
- use Yii;
- use yii\base\Action;
- class UploadAction extends Action
- {
- use BaseControllerTrait;
- public $mall_id = 0;
- public $store_id = 0;
- public $mch_id = 0;
- public $upload_type = '';
- public $group_id = 0;
- public $addons_name = '';
- public function run()
- {
- try {
- if (!$this->upload_type || !isset(Attachment::$uploadTypeExplain[$this->upload_type])) {
- throw new Exception('上传类型有误');
- }
- $config = Yii::$app->services->attachment->getStorageConfig($this->mall_id);
- $config['mall_id'] = $this->mall_id;
- $upload = new UploadHelper($config, $this->upload_type);
- $upload->verifyFile();
- // 添加禁止上传到系统图标目录
- if (in_array($this->group_id, array_column(Yii::$app->services->attachment->systemIconGroup, 'id'))) {
- throw new Exception('禁止上传至系统图标目录');
- }
- $upload->save();
- $this->success('上传成功',$upload->getBaseInfo($this->mall_id,$this->mch_id,$this->group_id,$this->store_id,$this->addons_name));
- } catch (Exception $e) {
- $this->error('上传失败:'.$e->getMessage());
- }
- }
- }
|