50], [['err_msg'], 'string', 'max' => 500], [['url'], 'string', 'max' => 2000], [['method'], 'string', 'max' => 7], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'url' => 'Url', 'path' => 'Path', 'method' => 'Method', 'request_data' => 'Request Data', 'response_data' => 'Response Data', 'headers' => 'Headers', 'http_state_code' => 'Http State Code', 'err_msg' => 'Err Msg', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function setData(int $mall_id, array $data) { if (empty($data['id'])) { $model = new self(); $model->loadDefaultValues(); $model->mall_id = $mall_id; } else { $model = self::findOne(['mall_id' => $mall_id, 'id' => $data['id'], 'status' => StatusEnum::ENABLED]); if (!$model) throw new RuntimeException('数据记录异常'); } foreach ($data as $key => $val) { if ($key === 'response_data' && is_array($val)) { $val = json_encode($val, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } $model->$key = $val; } if (!$model->save()) { self::$static_error = '保存数据失败:' . $model->getErrorMessage(); return false; } return $model; } }