예제 #1
0
 /**
  * search the product id from the campaign
  * @param $accountId,MongoId
  * @param $pageSize,int,the number record for one page
  * @param $page,int, which page to show
  */
 public static function searchProductInfo($accountId, $pageSize, $page)
 {
     $where = ['accountId' => $accountId, 'isDeleted' => self::NOT_DELETED];
     $campaigns = Campaign::find()->select(['promotion.data'])->where($where)->all();
     $showData = [];
     //get productId
     if (!empty($campaigns)) {
         $productIds = [];
         foreach ($campaigns as $campaign) {
             if (!empty($campaign['promotion']['data'])) {
                 $ids = $campaign['promotion']['data'];
                 foreach ($ids as $id) {
                     $productIds[] = $id;
                 }
             }
         }
         //get product info from product with productId
         if (!empty($productIds)) {
             $productIds = array_values(array_unique($productIds));
             $len = count($productIds);
             $offset = 0;
             $where = ['_id' => ['$in' => $productIds]];
             $query = Product::find()->select(['_id', 'name'])->where($where);
             if ($len > $pageSize && $pageSize > 0) {
                 $offset = ($page - 1) * $pageSize;
                 $showData = $query->offset($offset)->limit($pageSize);
             }
             $showData = $query->all();
         }
     }
     $data = ['data' => $showData, 'num' => empty($len) ? 0 : $len];
     return $data;
 }