Пример #1
0
 /**
  * Updates an existing Attribute model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('attribute/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', '编辑成功');
         return $this->redirect(['index']);
     } else {
         $GoodsType = new GoodsType();
         $dropList = $GoodsType->dropList(false);
         Yii::$app->view->params['meta_title'] = '编辑属性';
         return $this->render('update', ['model' => $model, 'dropList' => $dropList]);
     }
 }
Пример #2
0
 /**
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     if (!$this->is_access('goods/update')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = $this->findModel($id);
     $GoodsGallery = new GoodsGallery();
     $post = Yii::$app->request->post();
     if ($model->load($post)) {
         $GoodsGallery->load($post);
         if ($model->validate() && $GoodsGallery->validate()) {
             // 商品封面图片
             if ($_FILES['Goods']['error']['goods_img'] === 0) {
                 $model->goods_img = File::uploadImage($model, 'goods_img', 'shop');
                 $model->goods_thumb = Images::thumb('./' . $model->goods_img, 250, 250);
             }
             if ($model->save(false)) {
                 // 商品相册
                 if ($_FILES['GoodsGallery']['error']['img_url'][0] === 0) {
                     $img_url = File::uploadImages($GoodsGallery, 'img_url', 'goods');
                     $GoodsGallery->addData($model->goods_id, $img_url);
                 }
                 // 商品属性
                 GoodsAttr::addData($model->goods_id);
             }
             Yii::$app->session->setFlash('success', '编辑成功');
         }
         return $this->redirect(['index']);
     } else {
         // 商品分类
         $Category = new Category();
         $categoryList = $Category->parent(0, false);
         // 品牌
         $Brand = new Brand();
         $brandList = $Brand->getLists();
         // 商品类型
         $GoodsType = new GoodsType();
         $goodsTypeList = $GoodsType->dropList();
         // 相册
         $goodsGalleryList = $GoodsGallery->getGoodsGallery($id);
         Yii::$app->view->params['meta_title'] = '编辑商品';
         return $this->render('update', ['model' => $model, 'GoodsGallery' => $GoodsGallery, 'categoryList' => $categoryList, 'brandList' => $brandList, 'goodsTypeList' => $goodsTypeList, 'goodsGalleryList' => $goodsGalleryList]);
     }
 }