50], [['img'], 'string', 'max' => 255], [[ 'jump_href'], 'string', 'max' => 5000], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城id', 'sort' => '排序', 'title' => '广告标题', 'img' => '广告图', 'jump_href' => '跳转链接', 'status' => '-1是删除,0是禁用,1是启用', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * @throws \yii\db\Exception */ public static function setData(array $params, string $scenarios = 'create') { $transaction = \Yii::$app->db->beginTransaction(); try { if ($scenarios == 'update') { $model = self::findOne(['id' => $params['id']]); } else { $model = new self(); } if (!$model->load($params, '') || false === $model->validate()) { $errors = $model->errors; $error_str = ''; foreach ($errors as $error) { $error_str .= implode(',', $error) . ','; } $error_str = trim($error_str, ','); throw new \Exception($error_str); } if (!$model->save()) throw new Exception($model->getErrorMessage()); $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollBack(); throw new Exception($e->getErrorMessage()); } } }