/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ShopProduct::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'price' => $this->price, 'jifen' => $this->jifen, 'product_number' => $this->product_number, 'return_jifen' => $this->return_jifen, 'is_on_sale' => $this->is_on_sale, 'is_delete' => $this->is_delete, 'is_hot' => $this->is_hot, 'is_promote' => $this->is_promote, 'is_check' => $this->is_check, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'thumbnail_base_url', $this->thumbnail_base_url])->andFilterWhere(['like', 'thumbnail_path', $this->thumbnail_path])->andFilterWhere(['like', 'img_base_url', $this->img_base_url])->andFilterWhere(['like', 'img_path', $this->img_path]); return $dataProvider; }
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>
echo $form->field($model, 'is_delete')->checkbox(); ?> <?php echo $form->field($model, 'is_hot')->checkbox(); ?> <?php echo $form->field($model, 'is_promote')->checkbox(); ?> <?php echo $form->field($model, 'is_check')->checkbox(); ?> <?php echo $form->field($model, 'status')->dropDownList(ShopProduct::getStatus()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
public function actionShiWuOrder($slug) { $shopOrder = new ShopOrder(); $shopProducts = ShopProduct::findOne(['slug' => $slug]); //myVarDump($shopOrder->validate()); if ($shopOrder->load(\Yii::$app->request->post()) && $shopOrder->validate()) { $transaction = $shopOrder->getDb()->beginTransaction(); $shopOrder->user_id = \Yii::$app->user->getId(); $shopOrder->setOrderSn(); $shopOrder->save(false); $shopOrderItem = new ShopOrderItem(); $shopOrderItem->order_id = $shopOrder->id; $shopOrderItem->title = $shopProducts['title']; $shopOrderItem->price = $shopProducts['price']; $shopOrderItem->product_id = $shopProducts['id']; $shopOrderItem->quantity = 1; if (!$shopOrderItem->save(false)) { $transaction->rollBack(); \Yii::$app->session->addFlash('error', '暂时不能处理您的订单!'); return $this->redirect(['catalog/list']); } $transaction->commit(); \Yii::$app->cart->removeAll(); \Yii::$app->session->addFlash('success', '谢谢您的订单,我们会尽快处理!'); $shopOrder->sendEmail(); return $this->redirect(['product/my-order']); } return $this->render('shi-wu-order', ['shopOrder' => $shopOrder, 'shopProducts' => $shopProducts]); }
/** * Finds the ShopProduct model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ShopProduct the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ShopProduct::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\widgets\DetailView; use common\models\ShopProduct; /* @var $this yii\web\View */ /* @var $model common\models\ShopProduct */ $this->title = $model->title; $this->params['breadcrumbs'][] = ['label' => Yii::t('common', 'Shop Product'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="shop-product-view"> <p> <?php echo Html::a(Yii::t('backend', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'), 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['title', ['attribute' => 'relation_game', 'value' => $model->relationGame ? $model->relationgame->name : null], 'slug', 'description:ntext', ['attribute' => 'category_id', 'value' => $model->category->title], 'price', 'jifen', 'content:html', 'keywords', 'thumbnail_base_url:url', 'thumbnail_path', 'img_base_url:url', 'img_path', 'product_number', 'return_jifen', ['attribute' => 'is_on_sale', 'value' => $model->is_on_sale == ShopProduct::IS_ON_SALE_UP ? Yii::t('common', 'Yes') : Yii::t('common', 'Not')], ['attribute' => 'is_delete', 'value' => $model->is_delete == ShopProduct::IS_DELETE_YES ? Yii::t('common', 'Yes') : Yii::t('common', 'Not')], ['attribute' => 'is_hot', 'value' => $model->is_hot == ShopProduct::IS_HOT_YES ? Yii::t('common', 'Yes') : Yii::t('common', 'Not')], ['attribute' => 'is_promote', 'value' => $model->is_promote == ShopProduct::IS_PROMOTE_YES ? Yii::t('common', 'Yes') : Yii::t('common', 'Not')], ['attribute' => 'is_check', 'value' => $model->is_check == ShopProduct::IS_CHECK_YES ? Yii::t('common', 'Yes') : Yii::t('common', 'Not')], 'created_at:datetime', 'updated_at:datetime', ['attribute' => 'status', 'value' => ArrayHelper::getValue(ShopProduct::getStatus(), $model->status)]]]); ?> </div>
/** * @param null $cat * @return int|string */ public static function getOnSaleProductCount($cat = null) { $query = ShopProduct::find()->statusInUseAndOnSale(); if ($cat != null) { $query->andWhere(['category_id' => $cat]); } return $query->count(); }
/** * @return \yii\db\ActiveQuery */ public function getShopProducts() { return $this->hasMany(ShopProduct::className(), ['category_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(ShopProduct::className(), ['id' => 'product_id']); }
/** * Created by PhpStorm. * User: buuug7 * Date: 2016/1/11 * Time: 9:26 * Desc: */ use yii\helpers\Url; use yii\bootstrap\Html; use common\models\ShopProduct; use common\util\Buuug7Util; use common\models\ShopCategory; $this->title = '积分商城'; $hotProduct = ShopProduct::find()->statusInUseAndOnSale()->andWhere(['is_hot' => ShopProduct::IS_HOT_YES])->all(); $xuniProduct = ShopProduct::find()->statusInUseAndOnSale()->andWhere(['category_id' => ShopCategory::findOne(['slug' => 'xu-ni-wu-pin'])->id])->all(); $shitiProduct = ShopProduct::find()->statusInUseAndOnSale()->andWhere(['category_id' => ShopCategory::findOne(['slug' => 'shi-ti-wu-pin'])->id])->all(); $this->beginBlock('slider'); ?> <div class="collection-banner"> <div class="container"> <div class="col-md-7 md-margin-bottom-50"> <h2>积分商城</h2> <p>积分兑换好礼,丰富好礼等你来拿!</p><br> </div> <div class="col-md-5"> <div class="overflow-h"> <span class="percent-numb">50</span> <div class="percent-off"> <span class="discount-percent">%</span>