$attribute) { if ($oldAttributes[ $key ] != $attribute) { $data[ $key ] = [ 'old' => $attribute, 'new' => $oldAttributes[ $key ], ]; } } return $data; } /** * @param array $data * @param int $identityId * @param array $params */ public static function saveData(array $data, int $identityId, $params = []) { if (!empty($data)) { $log = new OrderProductLog(); $log->order_product_id = (integer) $identityId; $log->order_id = $params[ 'order_id' ]; $log->data = Json::encode($data); $user = \Yii::$app->user->identity; if (get_class($user) == User::className()) { $log->user_id = (integer) $user->getId(); } else { $log->user_id = NULL; } $log->save(); } } }