示例#1
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;
     }
 }
示例#2
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;
 }
 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]);
 }
示例#4
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.');
     }
 }
示例#5
0
 public function actionUpdate($id, $quantity)
 {
     $product = Product::findOne($id);
     if ($product) {
         \Yii::$app->cart->update($product, $quantity);
         $this->redirect(['cart/list']);
     }
 }
示例#6
0
 public function findById($id)
 {
     if (($model = Product::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('请求页面不存在');
     }
 }
示例#7
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.'));
     }
 }
示例#8
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();
 }
 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;
     }
 }
示例#10
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]);
 }
 public function actionUpdate($id)
 {
     $model = Product::findOne($id);
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->validate() && $model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 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'];
     }
 }
示例#13
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]);
     }
 }
 /**
  * @param $id
  * @return array
  * @throws NotFoundHttpException
  * @throws InvalidParamException
  */
 public function actionDelete($id)
 {
     $image = Image::findOne($id);
     $filePath = $image->getPathToOrigin();
     if (!$image) {
         throw new NotFoundHttpException('Image not found');
     }
     $product = Product::findOne($image->itemId);
     if (!$product) {
         throw new NotFoundHttpException('Product not found');
     }
     $product->removeImage($image);
     if (file_exists($filePath)) {
         return ['error' => 'Ошибка удаления файла'];
     } else {
         Yii::$app->getResponse()->setStatusCode(204);
     }
 }
示例#15
0
 /**
  * @return string
  */
 public function actionDeleteAvatar()
 {
     $imageData = Json::decode(Yii::$app->request->post('imageData'));
     $modelImageForm = new ImageForm();
     $modelImageForm->deleteImage();
     if (Yii::$app->session->get('error')) {
         echo $error = Yii::$app->session->get('error');
     } else {
         $error = false;
     }
     /* @var $model \common\models\Profile */
     if ($imageData['modelName'] == 'Carousel') {
         $model = Carousel::findOne($imageData['object_id']);
     } elseif ($imageData['modelName'] == 'Product') {
         $model = Product::findOne($imageData['object_id']);
     }
     $imagesObject = $model->imagesOfObjects;
     return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imageSmallWidth' => $imageData['imageSmallWidth'], 'imageSmallHeight' => $imageData['imageSmallHeight'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]);
 }
示例#16
0
 public function init()
 {
     parent::init();
     /* Инициализация объекта, если он есть в сессии */
     if ($this->tempModel == 'Carousel') {
         if ($this->tempModel = Carousel::findOne($this->tempId)) {
             // Если объект загружен
             $this->tempDelete = true;
             // Устанавливаем флаг tempDelete для удаления
         }
     }
     if ($this->tempModel == 'Product') {
         if ($this->tempModel = Product::findOne($this->tempId)) {
             // Если объект загружен
             $this->tempDelete = true;
             // Устанавливаем флаг tempDelete для удаления
         }
     }
 }
示例#17
0
 /**
  * batch import product
  * @param integer $id
  * @return mixed
  */
 public function actionImport()
 {
     //if(!Yii::$app->user->can('viewYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $format = Product::getImportExportFormat();
     if (Yii::$app->request->post()) {
         $countCreate = $countUpdate = 0;
         $file = UploadedFile::getInstanceByName('importFile');
         $handle = fopen($file->tempName, 'r');
         $result = $this->inputCsv($handle);
         $arrData = [];
         if (count($result) <= 1) {
             Yii::$app->getSession()->setFlash('danger', Yii::t('app', 'No Record, please check file.'));
         } else {
             // 将数据的key从数字变成固定的格式
             for ($i = 1; $i < count($result); $i++) {
                 $j = 0;
                 foreach ($format as $item) {
                     $data[$item] = $result[$i][$j];
                     $j++;
                 }
                 $data['thumbs'] = $result[$i][$j];
                 $data['images'] = $result[$i][$j + 1];
                 array_push($arrData, $data);
             }
             // 处理数据,如果ID大于0,则更新,否则新增
             $line = 2;
             $errorLines = [];
             foreach ($arrData as $item) {
                 if ($item['id'] > 0) {
                     // 已存在的值,则更新数据,以及判断缩略图和图片
                     $model = Product::findOne($item['id']);
                     if ($model === null) {
                         array_push($errorLines, $line);
                         $line++;
                         continue;
                     }
                     foreach ($item as $k => $v) {
                         if ($k == 'id' || $k == 'thumbs' || $k == 'images') {
                             continue;
                         }
                         $model[$k] = iconv('gb2312', 'utf-8', trim($v));
                     }
                     $result = $model->save();
                     if (!$result) {
                         //如果保存失败
                         array_push($errorLines, $line);
                         $line++;
                         continue;
                     }
                     $countUpdate++;
                     if ($item['thumbs'] && $item['images']) {
                         $arrThumb = explode('|', $item['thumbs']);
                         $arrImage = explode('|', $item['images']);
                         $i = 0;
                         $ids = [];
                         foreach ($arrThumb as $thumb) {
                             $thumb = trim($thumb);
                             $image = trim($arrImage[$i]);
                             $productImage = ProductImage::find()->where(['product_id' => $item['id'], 'thumb' => $thumb, 'image' => $image])->one();
                             if ($productImage) {
                                 //如果图片在数据库中已经存在,则假如到ids数组,防止后续被删除
                                 array_push($ids, $productImage->id);
                             } else {
                                 //不存在的话,新增记录并将id加入到ids
                                 $productImage = new ProductImage(['product_id' => $item['id'], 'thumb' => $thumb, 'image' => $image]);
                                 $productImage->save();
                                 array_push($ids, $productImage->id);
                             }
                             $i++;
                         }
                         //删除在ids数组中记录
                         ProductImage::deleteAll(['and', 'product_id=' . $item['id'], ['not in', 'id', $ids]]);
                     }
                 } else {
                     // 新的数据,插入,并将缩略图和图片插入
                     $model = new Product();
                     foreach ($item as $k => $v) {
                         if ($k == 'id' || $k == 'thumbs' || $k == 'images') {
                             continue;
                         }
                         $model[$k] = iconv('gb2312', 'utf-8', trim($v));
                     }
                     // 将分类和品牌转换成对应的ID
                     $category = Category::find()->where(['name' => trim($model->category_id)])->one();
                     $model->category_id = $category ? $category->id : 1;
                     $brand = Brand::find()->where(['name' => trim($model->brand_id)])->one();
                     $model->brand_id = $brand ? $brand->id : 0;
                     $result = $model->save();
                     if (!$result) {
                         //如果保存失败
                         array_push($errorLines, $line);
                         $line++;
                         continue;
                     }
                     $countCreate++;
                     if ($item['thumbs'] && $item['images']) {
                         $arrThumb = explode('|', $item['thumbs']);
                         $arrImage = explode('|', $item['images']);
                         $i = 0;
                         foreach ($arrThumb as $thumb) {
                             $thumb = trim($thumb);
                             $image = trim($arrImage[$i]);
                             if ($thumb && $image) {
                                 // 缩略图和图片都有才加入
                                 $productImage = new ProductImage(['product_id' => $model->id, 'thumb' => $thumb, 'image' => $image]);
                                 $productImage->save();
                             }
                             $i++;
                         }
                     }
                 }
                 $line++;
             }
             if (count($errorLines)) {
                 $strLine = implode(', ', $errorLines);
                 Yii::$app->getSession()->setFlash('danger', Yii::t('app', "Line {strLine} error.", ['strLine' => $strLine]));
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('app', "Import Data Success. Create: {countCreate}  Update: {countUpdate}", ['countCreate' => $countCreate, 'countUpdate' => $countUpdate]));
         }
     }
     return $this->render('import', []);
 }
示例#18
0
 public function actionAjaxAdd()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $productId = Yii::$app->request->post('productId');
     $number = Yii::$app->request->post('number');
     if ($productId && $number) {
         // 如果购物车已有,则更新,否则在购物车中增加
         if ($cart = Cart::find()->where(['and', 'product_id=' . $productId, ['or', 'session_id="' . Yii::$app->session->id . '"', 'user_id=' . Yii::$app->user->isGuest ? 0 : Yii::$app->user->id]])->one()) {
             $product = Product::findOne($productId);
             if ($cart->number + $number <= $product->stock) {
                 $cart->updateAllCounters(['number' => $number], ['and', 'product_id=' . $productId, ['or', 'session_id="' . Yii::$app->session->id . '"', 'user_id=' . Yii::$app->user->isGuest ? 0 : Yii::$app->user->id]]);
                 return ['status' => 1, 'productId' => $productId, 'number' => $number];
             } else {
                 return ['status' => -2, 'productId' => $productId, 'number' => $number];
             }
         } elseif ($model = Product::findOne($productId)) {
             if ($model->stock >= $number) {
                 $cart = new Cart();
                 $cart->session_id = Yii::$app->session->id;
                 $cart->user_id = Yii::$app->user->isGuest ? 0 : Yii::$app->user->id;
                 $cart->product_id = $productId;
                 $cart->number = $number;
                 $cart->sku = $model->sku;
                 $cart->name = $model->name;
                 $cart->market_price = $model->market_price;
                 $cart->price = $model->price;
                 $cart->thumb = $model->thumb;
                 $cart->type = $model->type;
                 $cart->save();
                 return ['status' => 1, 'productId' => $productId, 'number' => $number];
             } else {
                 return ['status' => -2, 'productId' => $productId, 'number' => $number];
             }
         }
     }
     return ['status' => -1, 'productId' => $productId, 'number' => $number];
 }
示例#19
0
 public function actionDetail($id)
 {
     $product = \common\models\Product::findOne($id);
     $productForm = new \common\models\ProductForm();
     $productForm->id = $product->id;
     $productForm->name = $product->name;
     $productForm->description = $product->description;
     $productForm->price = $product->selling_price;
     $productForm->filename = $product->productPhotos[0]->image_path;
     if ($productForm->load(Yii::$app->request->post())) {
         $productForm->attributes = Yii::$app->request->post();
         $this->addToCart($productForm);
         Yii::$app->response->redirect(array('cart/cart'));
     }
     return $this->render('detail', array('product' => $product, 'productForm' => $productForm));
 }
示例#20
0
 public function actionView($slug)
 {
     $model = new Product();
     $node = $model->findOne(['slug' => $slug]);
     return $this->render('view', ['node' => $node]);
 }
示例#21
0
 public function actionDetail($id)
 {
     $product = Product::findOne(['prod_id' => $id]);
     return $this->render('detail', ['prod' => $product]);
 }
示例#22
0
        <h1><?php 
echo $this->title;
?>
</h1>
        <div class="detail_r">
            <table id="address_list" class="admin_table">
                <tbody>
                <tr>
                    <th width="60">咨询商品</th>
                    <th width="60">商品名称</th>
                    <th>咨询回复</th>
                    <th width="120">&nbsp;</th>
                </tr>
                <?php 
foreach ($models as $item) {
    $product = \common\models\Product::findOne($item->product_id);
    ?>
                    <tr>
                        <td rowspan="2"><img src="<?php 
    echo $product->thumb;
    ?>
"></td>
                        <td rowspan="2"><a target="_blank" href="<?php 
    echo Yii::$app->urlManager->createUrl(['product/view', 'id' => $product->id]);
    ?>
"><?php 
    echo $product->name;
    ?>
 </a></td>
                        <td style="text-align:left"><?php 
    echo $item->question;
 /**
  * Get all categories associated on a product
  *
  * @param $productId
  * @return array
  */
 private function getProductCategoryKeys($productId)
 {
     $productCategoryKeys = [];
     if ($productId == '') {
         return $productCategoryKeys;
     }
     $productCategories = Product::findOne(['product_id' => $productId])->product_category_fk;
     if (!empty($productCategories)) {
         $productCategoryKeys = explode(',', $productCategories);
     }
     return $productCategoryKeys;
 }
 public function actionProduct($id)
 {
     $model = Product::findOne($id);
     if (!isset($model)) {
         throw new NotFoundHttpException('Object not found.');
     }
     return $this->render('product', ['model' => $model]);
 }