/** * Updates an existing ShopProduct model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $categories = ShopCategory::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'categories' => $categories]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ShopCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * Finds the ShopCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ShopCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ShopCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use common\models\ShopProduct; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\ShopProductSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('common', 'Shop Product'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="shop-product-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => Yii::t('common', 'Shop Product')]), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'title', ['attribute' => 'relation_game', 'value' => function ($model) { return $model->relationGame ? $model->relationGame->name : null; }], 'description:ntext', ['attribute' => 'category_id', 'value' => function ($model) { return $model->category ? $model->category->title : null; }, 'filter' => \yii\helpers\ArrayHelper::map(\common\models\ShopCategory::find()->all(), 'id', 'title')], 'price', ['label' => Yii::t('common', 'Thumbnail'), 'format' => 'html', 'value' => function ($dataProvider) { return Html::img(Yii::$app->glide->createSignedUrl(['glide/index', 'path' => $dataProvider->thumbnail_path, 'w' => 100], true), ['class' => 'img-rounded pull-left img-responsive']); }], ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'is_on_sale', 'enum' => [Yii::t('common', 'Not'), Yii::t('common', 'Yes')]], ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => ShopProduct::getStatus()], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function actionDuiHuan() { $post = \Yii::$app->request->post(); $user = \Yii::$app->user->identity; $dzUser = (new DzHelper())->getDzUserByUsername($user->username); $data = []; $bbsUrl = \Yii::getAlias('@bbsUrl'); $model = ShopProduct::findOne($post['dataId']); //实体物品 if ($post['dataType'] == ShopCategory::findOne(['slug' => 'shi-ti-wu-pin'])->id) { return $this->redirect(['shi-wu-order', 'slug' => $model->slug]); } //判断积分 if ($model->jifen > $dzUser['credits']) { $data['msg'] = '<i class="glyphicon glyphicon-ok"></i> 您当前的积分为 : ' . $dzUser['credits']; $data['msg'] .= '<br>'; $data['msg'] .= '<i class="glyphicon glyphicon-ok"></i> 很遗憾您的积分不够兑换该礼品'; $data['msg'] .= '<br>'; $data['msg'] .= "<a href={$bbsUrl} target='_blank'>[去论坛赚积分]</a>"; return json_encode($data); } else { //实体物品 if ($post['dataType'] == ShopCategory::findOne(['slug' => 'shi-ti-wu-pin'])->id) { return $this->redirect(['shi-wu-order', 'slug' => $model->slug]); } //虚拟物品 if ($post['dataType'] == ShopCategory::findOne(['slug' => 'xu-ni-wu-pin'])->id) { } } $data['msg'] = '<i class="glyphicon glyphicon-ok"></i> 系统异常,请稍后在试!'; return json_encode($data); }
/** * @return \yii\db\ActiveQuery */ public function getShopCategories() { return $this->hasMany(ShopCategory::className(), ['parent_id' => 'id']); }
$this->render('_breadcrumbs'); ?> <div class="content container"> <div class="row"> <div class="col-md-3 filter-by-block md-margin-bottom-60"> <?php include_once '_leftPanel.php'; ?> </div> <div class="col-md-9"> <div class="row margin-bottom-5"> <div class="col-sm-4 result-category"> <h2><?php echo ShopCategory::findOne($queryCatId)->title; ?> </h2> <small class="shop-bg-red badge-results"><?php echo Buuug7Util::getOnSaleProductCount($queryCatId); ?> </small> </div> <div class="col-sm-8"> <ul class="list-inline clear-both"> <li class="sort-list-btn"> <h3>排序 :</h3> <div class="btn-group"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<div class="panel-group" id="accordion-v2"> <div class="panel panel-default"> <div class="panel-heading"> <h2 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion-v2" href="#collapseTwo"> 按照分类 <i class="fa fa-angle-down"></i> </a> </h2> </div> <div id="collapseTwo" class="panel-collapse collapse in"> <div class="panel-body"> <ul class="list-unstyled checkbox-list"> <?php foreach (ShopCategory::find()->all() as $sc) { ?> <li> <label class="checkbox"> <input type="checkbox" name="checkbox" checked=""> <i></i> <?php echo Html::a($sc->title, ['list', 'ShopProductSearch[category_id]' => $sc->id]); ?> <small><?php echo Buuug7Util::getOnSaleProductCount($sc->id); ?> </small> </label> </li>
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(ShopCategory::className(), ['id' => 'category_id']); }
</ul> </div> </div> <?php } ?> </div> </div> <!--/end xuni product --> <div class="shiti-product"> <div class="heading-v1"> <h2> 实体物品 <?php echo Html::a('<i class="fa fa-plus-square"></i>', ['list', 'ShopProductSearch[category_id]' => ShopCategory::findOne(['slug' => 'xu-ni-wu-pin'])['id']]); ?> </h2> </div> <div class="row illustration-v4 margin-bottom-40"> <?php foreach ($shitiProduct as $hp) { ?> <div class="col-md-3 col-sm-6"> <div class="thumb-product"> <a href="<?php echo Url::to(['/product/view', 'slug' => $hp->slug]); ?> "> <?php echo Html::img(Yii::$app->glide->createSignedUrl(['glide/index', 'path' => $hp->thumbnail_path], true), ['class' => 'thumb-product-img']);