public function actionSave() { $this->_setJSONFormat(Yii::$app); $request = Yii::$app->request; $data = $request->post(); $code = '1'; if (!empty($data['_id'])) { $product = Product::findOne($data['_id']['$id']); $data['updatedAt'] = new \MongoDate(); $code = '2'; } if (empty($product)) { $product = new Product(); $accessToken = Token::getToken(); $user = User::findOne(['_id' => $accessToken->userId]); $data['accountId'] = $this->getAccountId(); $data['creator'] = $user->name; $data['createdAt'] = new \MongoDate(); $data['isDeleted'] = false; } if (!empty($product->accountId)) { unset($data['accountId']); } $product->attributes = $data; $product->save(); return ['code' => $code]; }