public function actionSearch() { $get = Yii::$app->getRequest()->get(); $val = null; if (isset($get['so'])) { $soarr = explode('_', $get['so']); $val = $soarr[1]; } $query = AvRel::find()->where(['status' => AvRel::STATUS_ACTIVE]); $query->andFilterWhere(['category_id' => $get['cate']])->andFilterWhere(['av_id' => $val]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $avs = $query->offset($pages->offset)->limit($pages->limit)->select('goods_id')->asArray()->all(); $avs = ArrayHelper::getColumn($avs, 'goods_id'); $goods = Goods::find()->where(['status' => Goods::STATUS_ACTIVE])->andWhere(['id' => $avs])->asArray()->all(); $covers = ArrayHelper::getColumn($goods, 'cover'); $covers = Attachment::find()->where(['id' => $covers])->indexBy('id')->asArray()->all(); foreach ($goods as &$v) { if (empty($v['cover'])) { continue; } $co = $covers[$v['cover']]; $v['img'] = $co['path'] . '/tiny_' . $co['name']; } return $this->ajaxReturn(['list' => $goods]); }
/** * Finds the Content model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Attachment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Attachment::find()->andWhere(['cid' => $id])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getByRes($res_name, $res_id, $type = '', $out = []) { $rel = self::find()->where(['res_name' => $res_name, 'res_id' => $res_id])->asArray()->all(); $list = Attachment::find()->where(['id' => \yii\helpers\ArrayHelper::getColumn($rel, 'attach_id')])->andFilterWhere(['not in', 'id', $out])->asArray()->all(); $type = $type ? $type . '_' : ''; foreach ($list as $k => &$v) { $v['url'] = $v['path'] . '/' . $type . $v['name']; } return $list; }
/** * Lists all Goods models. * @return mixed */ public function actionIndex() { $searchModel = new GoodsSearch(); $data = $searchModel->so(Yii::$app->request->queryParams, 'wx4ezbhcqq'); $covers = ArrayHelper::map($data['list'], 'id', 'cover'); $urls = \common\models\Attachment::find()->where(['id' => $covers])->asArray()->all(); $res = []; foreach ($urls as $k => $v) { $res[$v['id']] = $v['path'] . '/tiny_' . $v['name']; } foreach ($data['list'] as $k => &$v) { $v['img'] = $v['cover'] ? $res[$v['cover']] : ''; } unset($v); return $this->render('index', ['searchModel' => $searchModel, 'data' => $data]); }