public function actionView($slug)
 {
     $productModel = new Product();
     $productData = $productModel->findOne(['slug' => $slug]);
     $relatedProduct = $productModel->find()->where(['category_id' => $productData->category_id])->andWhere(['<>', 'id', $productData->id])->limit(9)->orderBy(['id' => SORT_ASC])->all();
     return $this->render('view', ['node' => $productData, 'relateNodes' => $relatedProduct]);
 }
 public function actionCreate()
 {
     $model = new Product();
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $nodes = Product::find()->where(['status' => 10])->limit(3)->all();
     return $this->render('ProductBottomTopWidget', ['nodes' => $nodes]);
 }
示例#4
0
 /**
  * 上传商品图片
  */
 public function actionProductpic()
 {
     $user_id = \Yii::$app->user->getId();
     $p_params = Yii::$app->request->get();
     $product = Product::findOne($p_params['id']);
     if (!$product) {
         throw new NotFoundHttpException(Yii::t('app', 'Page not found'));
     }
     $picture = new UploadForm();
     $picture->file = UploadedFile::getInstance($product, 'product_s_img');
     if ($picture->file !== null && $picture->validate()) {
         Yii::$app->response->getHeaders()->set('Vary', 'Accept');
         Yii::$app->response->format = Response::FORMAT_JSON;
         $response = [];
         if ($picture->productSave()) {
             $response['files'][] = ['name' => $picture->file->name, 'type' => $picture->file->type, 'size' => $picture->file->size, 'url' => '/' . $picture->getImageUrl(), 'thumbnailUrl' => '/' . $picture->getOImageUrl(), 'deleteUrl' => Url::to(['/uploadfile/deletepropic', 'id' => $picture->getID()]), 'deleteType' => 'POST'];
         } else {
             $response[] = ['error' => Yii::t('app', '上传错误')];
         }
         @unlink($picture->file->tempName);
     } else {
         if ($picture->hasErrors()) {
             $response[] = ['error' => '上传错误'];
         } else {
             throw new HttpException(500, Yii::t('app', '上传错误'));
         }
     }
     return $response;
 }
示例#5
0
 /**
  * @brief 根据用户的输入产生交易记录
  *
  * @return  public function 
  * @retval   
  * @see 
  * @note 
  * @author 吕宝贵
  * @date 2015/12/19 20:39:07
  **/
 public function generateTrans()
 {
     $product = Product::findOne(['pid' => $this->booking->pid]);
     $buyerAccount = Yii::$app->account->getUserAccount(Yii::$app->user->identity['uid']);
     //根据booking_id生成交易记录
     $trans = new Trans();
     $trans->pay_mode = Trans::PAY_MODE_VOUCHPAY;
     $trans->trans_type_id = Trans::TRANS_TYPE_TRADE;
     $trans->currency = 1;
     $trans->total_money = $this->booking->price_final;
     $trans->profit = $this->booking->price_for_platform;
     $trans->money = $trans->total_money - $trans->profit;
     //保证金,目前还没有上
     //$trans->earnest_money = $this->booking->earnest_money;
     $trans->trans_id_ext = $this->booking_id;
     $trans->from_uid = $buyerAccount->uid;
     $trans->to_uid = $this->booking->hug_uid;
     $trans->status = Trans::PAY_STATUS_WAITPAY;
     //1为等待支付状态
     if ($trans->save()) {
         return $trans;
     } else {
         $this->addErrors($trans->getErrors());
         return false;
     }
 }
示例#6
0
 public function actionCheckout()
 {
     session_start();
     $prod_ids = $_SESSION['cart-item'];
     $products = Product::find()->where(['prod_id' => $prod_ids])->all();
     return $this->render('checkout', ['products' => $products]);
 }
示例#7
0
 public function actionView($id)
 {
     if ($id <= 0) {
         $this->goHome();
     }
     $allCategory = Category::find()->asArray()->all();
     $arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
     $arrSubCat = Category::getArraySubCatalogId($id, $allCategory);
     /****** 价格筛选 ****/
     $result = (new Query())->select('min(price) as min, max(price) as max')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->one();
     $min = $result['min'];
     $max = $result['max'];
     if ($max > $min && $max > 0) {
         // 计算跨度
         $priceGrade = 0.0001;
         for ($i = -2; $i < log10($max); $i++) {
             $priceGrade *= 10;
         }
         $span = ceil(($max - $min) / 5 / $priceGrade) * $priceGrade;
         if ($span == 0) {
             $span = $priceGrade;
         }
         // 计算价格的起点和终点
         for ($i = 1; $min > $span * $i; $i++) {
         }
         for ($j = 1; $min > $span * ($i - 1) + $priceGrade * $j; $j++) {
         }
         $priceFilter['start'] = $span * ($i - 1) + $priceGrade * ($j - 1);
         for (; $max >= $span * $i; $i++) {
         }
         $priceFilter['end'] = $span * $i + $priceGrade * ($j - 1);
         $priceFilter['span'] = $span;
     }
     /****** 价格筛选 end ****/
     /****** 品牌筛选 start ****/
     $result = (new Query())->select('distinct(brand_id)')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->all();
     $ids = ArrayHelper::map($result, 'brand_id', 'brand_id');
     $brandFilter = Brand::find()->where(['id' => $ids])->orderBy(['name' => SORT_ASC])->all();
     /****** 品牌筛选 end ****/
     $query = Product::find()->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE]);
     // 如果选择了价格区间
     if (Yii::$app->request->get('max')) {
         $min = intval(Yii::$app->request->get('min'));
         $max = intval(Yii::$app->request->get('max'));
         if ($min >= 0 && $max) {
             $query->andWhere(['and', ['>', 'price', $min], ['<=', 'price', $max]]);
         }
     }
     // 如果选择了品牌
     if (Yii::$app->request->get('brand_id')) {
         $brandId = intval(Yii::$app->request->get('brand_id'));
         if ($brandId >= 0) {
             $query->andWhere(['brand_id' => $brandId]);
         }
     }
     // 侧边热销商品
     $sameCategoryProducts = Product::find()->where(['category_id' => $id])->orderBy(['sales' => SORT_DESC])->limit(5)->all();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     return $this->render('view', ['model' => $this->findModel($id), 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'priceFilter' => isset($priceFilter) ? $priceFilter : null, 'brandFilter' => $brandFilter, 'sameCategoryProducts' => $sameCategoryProducts]);
 }
 public function actionIndex($c_url, $sc_url, $r_url, $product_ui)
 {
     if (!($product = Product::find()->withProperties()->select(['{{product}}.*', 'IF(round(sum(product_review.rating) / count(product.reviews_count)) IS NULL, 0, rating) as rating'])->joinWith('productReviews')->groupBy('{{product}}.id')->with(['photos', 'videos', 'photos360'])->byUi($product_ui)->one())) {
         throw new NotFoundHttpException();
     }
     Yii::$app->recently->add($product);
     return $this->render('index', ['model' => $product]);
 }
示例#9
0
 public function actionUpdate($id, $quantity)
 {
     $product = Product::findOne($id);
     if ($product) {
         \Yii::$app->cart->update($product, $quantity);
         $this->redirect(['cart/list']);
     }
 }
示例#10
0
 public function actionIndex()
 {
     $hotProducts = Product::getHots();
     $bestProducts = Product::getBests();
     $newProducts = Product::getNews();
     $randomProducts = Product::getRandoms();
     return $this->render('index', compact('hotProducts', 'bestProducts', 'newProducts', 'randomProducts'));
 }
示例#11
0
 public function getProduct()
 {
     /**
      * 第一个参数为要关联的字表模型类名称,
      * 第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
      */
     return $this->hasOne(Product::className(), ['product_id' => 'product_id']);
 }
示例#12
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     $Prod = new Product();
     $Number_Of_Products = $Prod->getNumberOfProducts();
     $max = $Number_Of_Products[0]["COUNT('product_id')"];
     $Rand_Prod = array();
     $numbers = range(1, $max);
     shuffle($numbers);
     if ($max >= 9) {
         foreach (range(0, 8) as $number) {
             array_push($Rand_Prod, $product = Product::find()->where(['product_id' => $numbers[$number]])->one());
         }
     } else {
         throw new \yii\base\UserException("Add At Lease 9 Products to Database" . "\n" . "Products in Database : " . $max);
     }
     return $this->render('index', ['Rand' => $Rand_Prod]);
 }
示例#13
0
 public function findById($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('请求页面不存在');
     }
 }
示例#14
0
 /**
  * Finds the Product model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#15
0
 /**
  * Finds the Product model based on its slug.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $slug
  * @return Product the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($slug)
 {
     if (($model = Product::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('frontend', 'The requested page does not exist.'));
     }
 }
示例#16
0
 /**
  * Lists all Image models.
  * @param int $id product id
  * @return mixed
  *
  * @throws NotFoundHttpException
  */
 public function actionIndex($id)
 {
     $form = new MultipleUploadForm();
     if (!Product::find()->where(['id' => $id])->exists()) {
         throw new NotFoundHttpException();
     }
     $searchModel = new ImageSearch();
     $searchModel->product_id = $id;
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if (Yii::$app->request->isPost) {
         $form->files = UploadedFile::getInstances($form, 'files');
         if ($form->files && $form->validate()) {
             foreach ($form->files as $file) {
                 //
                 // UPLOADING THE IMAGE:
                 //
                 $image = new Image();
                 $image->product_id = $id;
                 if ($image->save()) {
                     // Save an original image;
                     $path = $image->getPath();
                     $file->saveAs($path);
                     // Original size:
                     $size = getimagesize($path);
                     $height = $size[1];
                     $width = $size[0];
                     // IMAGINE
                     ImagineImage::$driver = [ImagineImage::DRIVER_GD2];
                     $imagine = new Imagine();
                     $picture = $imagine->open($path);
                     //---------------------------
                     //                        $size = new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT);
                     //                        $center = new Center($size);
                     //---------------------------
                     //                        $picture->crop(new Point(0, 0),
                     //                            new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path);
                     /**
                      * If the image's height is bigger than needed, it must be cut.
                      * Otherwise it must be resized.
                      */
                     if ($height >= self::IMAGE_HEIGHT) {
                         $picture->thumbnail(new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path, ['quality' => 100]);
                         // re-save cropped image;
                     } else {
                         $picture->resize(new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path);
                     }
                     sleep(1);
                     //                        $background = new Color('#FFF');
                     //                        $topLeft    = new Point(0, 0);
                     //                        $canvas = $imagine->create(new Box(450, 450), $background);
                     //                        $canvas->paste($picture, $topLeft)->save($path);
                 }
             }
         }
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'uploadForm' => $form]);
 }
示例#17
0
 /**
  * 保存商品
  */
 public function save()
 {
     #获得用户的地区信息用来提供浏览者的显示信息
     $userinfo = \Yii::$app->user->getIdentity();
     $newProduct = new Product();
     $newProduct->product_country = 0;
     if (!empty($userinfo->province)) {
         $newProduct->product_province = $userinfo->province;
     }
     if (!empty($userinfo->city)) {
         $newProduct->product_city = $userinfo->city;
     }
     if (!empty($userinfo->area)) {
         $newProduct->product_area = $userinfo->area;
     }
     $newProduct->setAttributes($this->attributes);
     return $newProduct->save();
 }
 public function actionOrganization($id)
 {
     // Все кроме текущей
     $orgList = Organization::loadList('*', "id != {$id}");
     // Продукты организации
     $productList = Product::loadList('*', ['organization_id' => $id]);
     $model = $this->findModel($id);
     return $this->render('organization', ['model' => $model, 'orgList' => $orgList, 'productList' => $productList]);
 }
示例#19
0
 public function getModel($id)
 {
     $product = Product::findOne($id);
     if (!$product) {
         throw new NotFoundHttpException(Yii::t('app', 'specify product could not be found.'));
     } else {
         return $product;
     }
 }
示例#20
0
 /**
  * Remove a product from the cart.
  * @param $id
  * @throws NotFoundHttpException
  */
 public function actionRemove($id)
 {
     $model = Product::findOne($id);
     if ($model) {
         \Yii::$app->cart->remove($model);
         $this->redirect(['index']);
     }
     throw new NotFoundHttpException();
 }
示例#21
0
 public function actionDetail($id)
 {
     $product = Product::findOne(['prod_id' => $id]);
     //        echo '<pre>';
     //        print_r(Product::getMetaByName('color'));exit;
     //echo '<pre>';
     //        print_r($product->getProductImg('color')); exit;
     return $this->render('detail', ['prod' => $product]);
 }
示例#22
0
 public function actionSample()
 {
     if (Yii::$app->request->isAjax) {
         $data = Yii::$app->request->post();
         $id = explode(":", $data['id']);
         $search = $id[0];
         $product = Product::find()->where(['id' => $search])->one();
         return $this->renderPartial('_sample', ['product' => $product]);
     }
 }
示例#23
0
 public function actionFavorite()
 {
     $productIds = ArrayHelper::map(Favorite::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC])->asArray()->all(), 'product_id', 'product_id');
     if (count($productIds)) {
         $query = Product::find()->where(['id' => $productIds]);
         $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeOrder']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
         return $this->render('favorite', ['products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination]);
     }
     return $this->render('favorite', ['products' => []]);
 }
示例#24
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Product::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]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
示例#25
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Product::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'main_image', $this->main_image])->andFilterWhere(['like', 'short_text', $this->short_text])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'brand', $this->brand])->andFilterWhere(['like', 'made_in', $this->made_in])->andFilterWhere(['like', 'slug', $this->slug]);
     return $dataProvider;
 }
 public function run()
 {
     parent::run();
     // TODO: Change the autogenerated stub
     $category = new Category();
     $product = new Product();
     $parent_category = $category->findOne(['id' => $this->category_id]);
     $categoriesData = $category->findAll(['parent_id' => $this->category_id]);
     $category_slug = $parent_category->slug;
     $categoryIDs = [];
     if ($categoriesData) {
         foreach ($categoriesData as $categoryData) {
             $categoryIDs[] = $categoryData->id;
         }
         $products = $product->find()->where(['status' => 10, 'is_featured' => 10])->andWhere(['in', 'category_id', $categoryIDs])->limit($this->limit)->all();
     } else {
         $products = $product->find()->where(['status' => 10, 'is_front' => 10, 'category_id' => $this->category_id])->limit($this->limit)->all();
     }
     return $this->render('widget/front_product', ['nodes' => $products, 'category_slug' => $category_slug]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Product::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'price' => $this->price]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
 public function search($params)
 {
     $query = Product::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'price_discount' => $this->price_discount, 'price' => $this->price, 'organization_id' => $this->organization_id, 'type_id' => $this->type_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'icon_image', $this->icon_image])->andFilterWhere(['like', 'main_image', $this->main_image])->andFilterWhere(['like', 'results', $this->results])->andFilterWhere(['like', 'group_services', $this->group_services])->andFilterWhere(['like', 'orientation', $this->orientation])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'recommend', $this->recommend])->andFilterWhere(['like', 'prepare', $this->prepare])->andFilterWhere(['like', 'notes', $this->notes]);
     return $dataProvider;
 }
 public function actionToggle()
 {
     $id = Yii::$app->request->post('id');
     if (($product = Product::findOne(['id' => $id])) && !$this->user->hasWish($id)) {
         $this->user->addWish($product);
         return ['status' => 'added'];
     } else {
         $this->user->removeWish($product);
         return ['status' => 'removed'];
     }
 }
示例#30
0
 public function actionProduct($id)
 {
     if ($id) {
         $product = Product::findOne(['id' => $id]);
         if ($product === NULL) {
             throw new NotFoundHttpException("Товар № {$id} не найден");
         }
         $this->getView()->title = "Mexanika 74 - Каталог техники: " . $product->name;
         return $this->render('product_item', ['product' => $product]);
     }
 }