'ID', 'mall_id' => 'Mall ID', 'goods_id' => 'Goods ID', 'is_alone' => 'Is Alone', 'setting' => 'Setting', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getGoods() { return $this->hasOne(Goods::class, ['id' => 'goods_id']); } /** * @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; } } }