| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace hd\models\goods;
- use bizHd\goods\classes\GoodsClass;
- use hd\models\BaseForm;
- use Yii;
- /**
- * 创建商品描述表单模型
- */
- class CreateDescForm extends BaseForm
- {
- public $id;
- public $mainId;
- public $title;
- public $goodsId;
- public $content;
- public function rules()
- {
- return [
- [['goodsId'], 'required'],
- ['title', 'string', 'max' => 60],
- [['id', 'goodsId', 'mainId'], 'integer'],
- ['goodsId', 'validateGoodsId'],
- ['content', 'safe'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'title' => '标题',
- 'goodsId' => '商品ID',
- 'content' => '图文内容',
- ];
- }
- /**
- * 验证商品ID
- * @param $attribute
- */
- public function validateGoodsId($attribute)
- {
- if (!$this->hasErrors()) {
- $goods = GoodsClass::getById($this->goodsId, true, 'mainId');
- if (empty($goods) || $goods->mainId != Yii::$app->controller->mainId) {
- $this->addError($attribute, '商品不存在或不属于当前商户');
- }
- }
- }
- }
|