| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace hd\models\homePageConfig;
- use bizHd\homePageConfig\classes\HomePageConfigClass;
- use hd\models\BaseForm;
- use Yii;
- /**
- * 删除单张轮播图 OSS
- */
- class DeleteBannerImgForm extends BaseForm
- {
- public $filePath;
- public function rules()
- {
- return [
- ['filePath', 'required', 'message' => '参数错误'],
- ['filePath', 'validateFilePath'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'filePath' => '图片路径',
- ];
- }
- public function validateFilePath($attribute)
- {
- $filePath = ltrim(strval($this->$attribute), '/');
- $this->$attribute = $filePath;
- if ($filePath === '') {
- $this->addError($attribute, '参数错误');
- return;
- }
- $controller = Yii::$app->controller;
- $mainId = intval($controller->mainId ?? 0);
- $shopId = intval($controller->shopId ?? 0);
- $prefix = HomePageConfigClass::BANNER_OSS_ROOT . '/' . $mainId . '/' . $shopId . '/';
- if (strpos($filePath, $prefix) !== 0) {
- $this->addError($attribute, '无权删除该图片');
- }
- }
- /**
- * @return string
- */
- public function getFilePath()
- {
- return ltrim(strval($this->filePath), '/');
- }
- }
|