예제 #1
0
 /**
  * 通过产品ID集合获取产品信息
  *
  * @param array $ids 产品ID集合
  * @return array
  */
 public function getByIds($ids = [], $page = 1)
 {
     $result = false;
     if (!$ids || !is_array($ids)) {
         return $result;
     }
     // print_r($ids);exit;
     $startNum = ($page - 1) * self::PAGE_SIZE;
     $result = self::find()->where(['id' => $ids])->addParams([':idstr' => implode(',', $ids)])->with(['image' => function ($query) {
         return $query->select(['product_id', 'url'])->andWhere(['type' => ProductImage::TYPE_ALBUM, 'status' => ProductImage::STATUS_AVAILABLE])->orderBy(['order_num' => SORT_DESC]);
     }])->with(['stat' => function ($query) {
         return $query->select(['product_id', 'support_num', 'paied_num', 'partake_num', 'amount', 'follow_num', 'page_views']);
     }])->with(['user' => function ($query) {
         return $query->select(['uid', 'username', 'nickname', 'avatar', 'province', 'city']);
     }])->with(['aproduct' => function ($query) {
         return $query->select(['id', 'acti_id', 'product_id', 'start_time', 'end_time', 'status'])->with('apstat')->where([ActivityProduct::tableName() . '.status' => 3])->andWhere(ActivityProduct::tableName() . ".acti_id != " . ActivityBase::FANS_FESTIVAL);
     }])->with(['extra' => function ($query) {
         return $query->select(['product_id', 'summary']);
     }])->offset($startNum)->limit(self::PAGE_SIZE)->orderBy([new \yii\db\Expression('FIND_IN_SET(id, :idstr)')]);
     // asArray()->
     // all();
     // echo "<pre>";var_dump($result);exit;
     return $result;
 }