/** * get the name from product by string * */ public function actionName() { $params = $this->getQuery(); if (empty($params['id'])) { throw new BadRequestHttpException('missing params'); } $accountId = $this->getAccountId(); if (strrpos($params['id'], ',') !== false) { $ids = explode(',', $params['id']); foreach ($ids as $key => $id) { $ids[$key] = new \MongoId($id); } $params['id'] = $ids; } else { $params['id'] = [new \MongoId($params['id'])]; } $products = Goods::getGoodsName($params, $accountId); $names = []; foreach ($products as $product) { $names[] = $product->productName; } return $names; }