Ejemplo n.º 1
0
 public function deleteCat($catId)
 {
     $model = MaterialCategory::findOne($catId);
     if (!$model) {
         return false;
     }
     if ($model->delete()) {
         return true;
     }
     return false;
 }
 public function actionMaterialmanger()
 {
     $user = new AdminUser();
     if (!$user->checkUserIsLogin()) {
         $this->redirect(Variable::$home_url);
         return;
     }
     $query = MaterialCategory::find();
     $pagination = new Pagination(['defaultPageSize' => 8, 'totalCount' => $query->count()]);
     $countries = $query->orderBy('addTime DESC')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render(Variable::$materialManger_view, ['countries' => $countries, 'pagination' => $pagination]);
 }
 public function actionAddproductimages()
 {
     $user = new AdminUser();
     if (!$user->checkUserIsLogin()) {
         $this->redirect(Variable::$home_url);
         return;
     }
     $req = Yii::$app->request;
     $useId = trim($req->get('id'));
     $materialModel = Material::find()->where(['useId' => $useId, 'type' => 0, 'materialId' => 5])->orderBy('addTime DESC')->all();
     $materialCatModel = MaterialCategory::find()->all();
     $addForm = new AddProductImagesForm();
     $addForm->materialId = 5;
     //产品轮播图片
     if ($addForm->load($req->post()) && $addForm->validate()) {
         $logoPath = 'uploads/';
         if (!file_exists($logoPath)) {
             mkdir($logoPath, true);
         }
         $image = UploadedFile::getInstance($addForm, 'productImage');
         if (!($image instanceof UploadedFile && $image->error != UPLOAD_ERR_NO_FILE)) {
             $addForm->addError('productImage', '请输入符合格式要求的图片');
             return $this->render(Variable::$addProductImages_view, ['materialModel' => $materialModel, 'model' => $addForm, 'useId' => $useId, 'materialCatModel' => $materialCatModel]);
         }
         $ext = $image->getExtension();
         $imageName = 'productImage_' . $useId . '_' . time() . rand(100, 999) . '.' . $ext;
         $isUpLoad = $image->saveAs($logoPath . $imageName);
         if (!$isUpLoad) {
             return $this->render(Variable::$addProductImages_view, ['materialModel' => $materialModel, 'model' => $addForm, 'error' => '图片上传失败', 'useId' => $useId, 'materialCatModel' => $materialCatModel]);
         }
         $addForm->productImage = '/' . $logoPath . $imageName;
         if (!(new Material())->addOneImage(0, $addForm->materialId, $useId, $addForm->productImage)) {
             $this->redirect(Variable::$productManger_url);
             return;
         }
         $this->refresh();
     }
     return $this->render(Variable::$addProductImages_view, ['materialModel' => $materialModel, 'model' => $addForm, 'useId' => $useId, 'materialCatModel' => $materialCatModel]);
 }