예제 #1
1
 function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $file = UploadedFile::getInstance($this, 'image');
         if ($file && $file->error === UPLOAD_ERR_OK) {
             // Ищем, есть ли уже такой загруженный файл
             $file_model = Files::findOne(['hash' => md5_file($file->tempName)]);
             if ($file_model) {
                 $file_model->repeats++;
             } else {
                 $file_model = new Files();
                 $file_model->saveImageFile($file);
                 $file_model->repeats = 1;
             }
             $file_model->save();
             $this->file_id = $file_model->id;
         } else {
             $this->addError('image', 'Невозможно загрузить файл');
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
예제 #2
0
 public function postAction(Request $request)
 {
     if ($request->exists('btn-multiupload')) {
         echo '<pre>', print_r($request->file('file')), '</pre>';
         echo '<pre>', print_r($request->input()), '</pre>';
         $file = $request->file('file');
         $path = 'images/uploads';
         $filename = $file->getClientOriginalName();
         $file->move('images/uploads', $file->getClientOriginalName());
         $image = new Images();
         $image->image_name = $filename;
         $image->save();
         echo 'Uploaded';
     }
     if ($request->exists('btn-upload')) {
         $file = $request->file('uploader');
         $path = 'images/uploads';
         $filename = $file->getClientOriginalName();
         $file->move('images/uploads', $file->getClientOriginalName());
         $image = new Images();
         $image->image_name = $filename;
         $image->save();
         echo 'Uploaded';
     }
     //return redirect()->back();
 }
예제 #3
0
 /**
  *  Saves the image information in the database
  *
  * @return mixed
 */
 public function saveImgInDB()
 {
     $modelImages = new Images();
     $cookies = Yii::$app->request->cookies;
     $tocken = $cookies->getValue('user');
     $url = Yii::$app->route->getRouteWeb() . $this->image->baseName . '.' . $this->image->extension;
     $values = ['tocken' => $tocken, 'url' => $url, 'base_name' => $this->image->baseName, 'extension' => $this->image->extension];
     $modelImages->attributes = $values;
     return $modelImages->save() ? true : false;
 }
예제 #4
0
 public function getIndexProductListByCat($cat_id)
 {
     $category_service = \Yii::createObject('categoryservice');
     $cat_list = $category_service->getChildrenCat($cat_id);
     $product_list = Product::getInstance()->getIndexProductList($cat_list);
     $product_id_list = [];
     $image_id_list = [];
     foreach ($product_list as $product) {
         $product_id_list[] = $product['product_id'];
         $image_id_list[] = $product['image_default_id'];
     }
     //获取商品图片
     $image_list = Images::getInstance()->getDefaultImages($image_id_list);
     $middle_img_list = [];
     if ($image_list) {
         foreach ($image_list as $value) {
             $middle_img_list[$value->image_id] = $value->middle_url;
         }
     }
     foreach ($product_list as $k => $product) {
         if (array_key_exists($product['image_default_id'], $middle_img_list)) {
             $product_list[$k]['img'] = Yii::$app->params['img_url'] . $middle_img_list[$product['image_default_id']];
         } else {
             $product_list[$k]['img'] = '';
         }
     }
     //获取商品库存
     $client = new \GuzzleHttp\Client();
     //$res = $client->get('http://www.pzfresh.com');
     return $product_list;
 }
예제 #5
0
 public function getAdvertList($ad_position = '')
 {
     $list = Advert::getInstance()->getAdvertList($ad_position);
     $advert_list = [];
     if ($list) {
         $image_id_list = [];
         foreach ($list as $key => $value) {
             $image_id_list[] = $value->img_url;
         }
         //获取商品图片
         $image_list = Images::getInstance()->getDefaultImages($image_id_list);
         $middle_img_list = [];
         if ($image_list) {
             foreach ($image_list as $value) {
                 $middle_img_list[$value->image_id] = $value->large_url;
             }
         }
         foreach ($list as $k => $v) {
             if (array_key_exists($v->img_url, $middle_img_list)) {
                 $list[$k]->img_url = Yii::$app->params['img_url'] . $middle_img_list[$v->img_url];
             } else {
                 $list[$k]->img_url = '';
             }
         }
         if ($ad_position) {
             $advert_list[$ad_position] = $list;
         } else {
             foreach ($list as $advert) {
                 $advert_list[$advert->ad_position][] = $advert->getattributes();
             }
         }
     }
     return $advert_list;
 }
예제 #6
0
 /**
  * Finds the Images model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Images the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Images::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #7
0
 public function actionRemove()
 {
     if (Yii::$app->request->isAjax) {
         $data = Yii::$app->request->post();
         $hash = $data['hash'];
         Images::removeByHash($hash);
     }
 }
예제 #8
0
 /**
  * Deletes an existing Images model.  
  *
  * @param string $url
  *
  * @return mixed
 */
 public function actionDelete($url)
 {
     $model = Images::find()->where(['url' => $url])->one();
     $path = Yii::$app->route->getRouteUpload() . $model->base_name . '.' . $model->extension;
     if (unlink($path)) {
         $model->delete();
     }
     return $this->goHome();
 }
예제 #9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Images::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'aid' => $this->aid]);
     $query->andFilterWhere(['like', 'cover', $this->cover])->andFilterWhere(['like', 'one', $this->one])->andFilterWhere(['like', 'two', $this->two])->andFilterWhere(['like', 'three', $this->three])->andFilterWhere(['like', 'four', $this->four])->andFilterWhere(['like', 'five', $this->five]);
     return $dataProvider;
 }
예제 #10
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Images::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['image_id' => $this->image_id, 'item_id' => $this->item_id, 'date_added' => $this->date_added, 'date_modified' => $this->date_modified, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'big_image', $this->big_image])->andFilterWhere(['like', 'thumbnail', $this->thumbnail]);
     return $dataProvider;
 }
예제 #11
0
파일: Images.php 프로젝트: dosh93/shop
 static function deleteImages($model)
 {
     $images = Images::find()->where(['product_id' => $model->id])->all();
     $size = sizeof($images);
     $s = $size;
     for ($i = 0; $i <= $s; $i++) {
         if (Yii::$app->request->post('image' . $i)) {
             unlink(Yii::getAlias('@webroot/uploads/image_product/original/' . $images[$i]->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/xm/' . $images[$i]->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/sm/' . $images[$i]->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/lm/' . $images[$i]->url_image));
             $images[$i]->delete();
             $size -= 1;
             $model->images = $size;
             $model->save();
         }
     }
 }
예제 #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImages()
 {
     return $this->hasMany(Images::className(), ['file_id' => 'id']);
 }
예제 #13
0
파일: Albom.php 프로젝트: kansey/yii2albom
 /**
  * Get the picture is uploaded by user
  *
  * @return mixed 
 */
 public function getImages()
 {
     $listImages = Images::find()->select('url')->where(['tocken' => $this->getTockenUser()])->asArray()->all();
     return $listImages;
 }
예제 #14
0
 public function actionDelete($id)
 {
     if (!Yii::$app->user->can('product/delete')) {
         Yii::$app->session->setFlash('error', 'Нет доступа!');
         return $this->redirect('/');
     }
     $images = Images::find()->where(['product_id' => $id])->all();
     $char = Characteristics::find()->where(['product_id' => $id])->all();
     foreach ($char as $c) {
         $c->delete();
     }
     foreach ($images as $image) {
         if (file_exists(Yii::getAlias('@webroot/uploads/image_product/original/' . $image->url_image)) == true) {
             unlink(Yii::getAlias('@webroot/uploads/image_product/original/' . $image->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/xm/' . $image->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/sm/' . $image->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/lm/' . $image->url_image));
         }
         $image->delete();
     }
     $this->findModel($id)->delete();
     return $this->redirect(['index']);
 }
예제 #15
0
파일: view.php 프로젝트: dosh93/shop
?>
        <?php 
foreach ($products as $product) {
    ?>
            <div class='col-md-4'>
                <div class='thumbnail view-product' id="product<?php 
    echo $product->id;
    ?>
">
                    <a href=<?php 
    echo Url::to(['product/view', 'id' => $product->id]);
    ?>
>
                        <div class='product-images'>
                            <?php 
    echo Html::img('@web/uploads/image_product/xm/' . \app\models\Images::find()->where(['product_id' => $product->id])->one()->url_image, ['class' => 'product-image']);
    ?>
                        </div>
                        <div class='caption product-name'>
                            <h3 style='text-align: center'><?php 
    echo $product->name;
    ?>
</h3>
                        </div>
                    </a>
                    <div class='row'>
                        <div class='col-md-12'>
                            <h4 class='text-center'>Осталось: <span id="number_of_coupons<?php 
    echo $product->id;
    ?>
"><?php 
예제 #16
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id, Post $postModel, Images $imgModel)
 {
     $post = $postModel->getPostInfo($id);
     $data = $request->all();
     $post->fill($data);
     $post->save();
     $lastInsertedId = $id;
     if (isset($data['images'][0])) {
         foreach ($data['images'] as $file) {
             $size = $file->getSize();
             //print_r($size);
             if ($size <= 1500000) {
                 $destinationPath = public_path() . '/images/';
                 $oldaname = $file->getClientOriginalName();
                 $ex = $file->getClientOriginalExtension();
                 $filename = md5(time() . $oldaname) . '.' . $ex;
                 //echo $destinationPath.' '.$filename.' = '.$size.' // ';
                 $file->move($destinationPath, $filename);
                 $imgModel->create(['user_id' => session('id'), 'post_id' => $lastInsertedId, 'name' => $filename]);
             }
         }
     }
     return redirect()->route('post.show', ['id' => $lastInsertedId]);
 }
예제 #17
0
파일: User.php 프로젝트: kansey/yii2albom
 /**
  * @inheritdoc
 */
 public function getImages()
 {
     return $this->hasMany(Images::className(), ['tocken' => 'tocken']);
 }
예제 #18
0
 public function actionClear()
 {
     foreach (Images::find()->all() as $image) {
         $image->delete();
     }
     Yii::$app->db->createCommand("UPDATE sqlite_sequence SET seq=0 WHERE name='images'")->execute();
     if (Yii::$app->request->isAjax) {
         return true;
     } else {
         $dataProvider = new ActiveDataProvider(['query' => Images::find()]);
         return $this->render('index', ['dataProvider' => $dataProvider]);
     }
 }
예제 #19
0
파일: view.php 프로젝트: dosh93/shop
    echo Html::a("<span class='glyphicon glyphicon-plus'>", ['create'], ['class' => 'btn btn-success', 'data-toggle' => "tooltip", 'data-placement' => "top", 'title' => "Добавить товар"]);
    ?>
                        <?php 
    echo Html::a("<span class='glyphicon glyphicon-list'>", ['orders', 'id' => $model->id], ['class' => 'btn btn-default', 'data-toggle' => "tooltip", 'data-placement' => "top", 'title' => "Посмотреть купленные купоны"]);
    ?>
                    <?php 
}
?>
                </div>

            </div>
            <div style="margin-top: 30px" class="col-md-7">
                <div class="product-image">

                    <?php 
$images = Images::find()->where(['product_id' => $model->id])->all();
$img = [];
$i = 0;
foreach ($images as $image) {
    $img[$i]['content'] = Html::img('@web/uploads/image_product/sm/' . $image->url_image, ['style' => 'height:300px;margin:auto;']);
    $i++;
}
?>
                    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
                        <!-- Indicators -->
                        <ol class="carousel-indicators">
                            <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
                            <?php 
for ($i = 1; $i < sizeof($images); $i++) {
    ?>
                            <li data-target="#carousel-example-generic" data-slide-to=<?php 
예제 #20
0
파일: Product.php 프로젝트: dosh93/shop
 public function sizeImages()
 {
     $this->images = sizeof(Images::find()->where(['product_id' => $this->id])->all());
     $this->save();
 }
예제 #21
0
파일: _form.php 프로젝트: dosh93/shop
echo $form->field($model, 'description')->widget(CKEditor::className(), ['options' => ['rows' => 6], 'preset' => 'full']);
?>
        </div>
    </div>

        <div class="col-md-12">
            <?php 
echo $form->field($model, 'images[]')->widget(FileInput::classname(), ['showMessage' => false, 'language' => 'ru', 'pluginOptions' => ['showUpload' => false], 'options' => ['accept' => 'image/*', 'multiple' => true]]);
?>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <?php 
if (!$model->isNewRecord && sizeof($images = Images::find()->where(['product_id' => $model->id])->all()) > 0) {
    $i = 0;
    ?>
                <table class="table table-bordered">
                    <caption>Ранее добавленые изображения</caption>
                    <tr>
                        <th>Картинка</th>
                        <th>Удалить</th>
                    </tr>
                    <?php 
    foreach ($images as $image) {
        echo "<tr>";
        echo "<td>";
        echo Html::img('@web/uploads/image_product/xm/' . $image->url_image, ['style' => ' max-height:100px;']);
        echo "</td>";
        echo "<td>";
예제 #22
0
 /**
  * 多态关联
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * A model relation B model  and  A model relation C model
  * demo:ImagesModel  User Goods
  * 从 A model 读取 B OR C 的字段值
  */
 public function morphTo()
 {
     $obj = new Images();
     $rows = $obj->find(1)->relation->toarray();
     print_r($rows);
     return view('index');
 }