8], [['frontend_name'], 'string', 'max' => 4], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'name' => 'Name', 'frontend_name' => 'Frontend Name', 'use_num' => 'Use Num', 'fields' => 'Fields', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * @param array $params * * @return bool|self */ public static function setData(array $params) { try { if (!empty($params['id'])) { $model = static::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (!$model) { throw new RuntimeException('数据不存在或已删除'); } if ($model->mall_id != $params['mall_id']) { throw new RuntimeException('不允许操作此数据'); } } else { $model = new static(); $model->loadDefaultValues(); } if (!$model->load($params, '')) { throw new RuntimeException($model->getErrorMessage()); } if (!$model->save()) { throw new RuntimeException($model->getErrorMessage()); } return $model; } catch (Exception $e) { static::$static_error = $e->getMessage(); return false; } } }