Example #1
0
 public function addOneImage($type = 0, $materialId, $useId, $address, $isDefault = 0, $isShow = 0, $width = 200, $height = 200)
 {
     $model = new Material();
     $model->type = $type;
     $model->materialId = $materialId;
     $model->useId = $useId;
     $model->address = $address;
     $model->isDefault = $isDefault;
     $model->isShow = $isShow;
     $model->width = $width;
     $model->height = $height;
     $model->addTime = date('Y-m-d H:i:s', time());
     $model->addUser = Yii::$app->session->get(Variable::$session_userId_str);
     if ($model->save() > 0) {
         return true;
     }
     return false;
 }
Example #2
0
 public function updateMaterial($id, $materialId, $address, $isShow, $sort, $pcUrl, $wapUrl = '')
 {
     $model = Material::findOne($id);
     if (!$model) {
         return false;
     }
     $model->materialId = $materialId;
     $model->address = $address;
     //            $model->isDefault=$isDefault;
     $model->isShow = $isShow;
     $model->sort = $sort;
     $model->pcUrl = $pcUrl;
     if ($wapUrl) {
         $model->wapUrl = $wapUrl;
     }
     $model->addTime = date('Y-m-d H:i:s', time());
     $model->addUser = Yii::$app->session->get(Variable::$session_userId_str);
     if ($model->save()) {
         return true;
     }
     return false;
 }
 public function actionEditprobanner()
 {
     $user = new AdminUser();
     if (!$user->checkUserIsLogin()) {
         $this->redirect(Variable::$home_url);
         return;
     }
     $req = Yii::$app->request;
     //创建一个请求对象
     $form = new MaterialForm();
     $form->setScenario('probanner');
     $id = trim($req->get('id'));
     if (!is_numeric($id) || $id == 0) {
         $this->redirect(Variable::$setting_url);
         return;
     }
     $materialModel = Material::findOne($id);
     $form->materialId = $materialModel->materialId;
     //修改
     if ($form->load($req->post()) && $form->validate()) {
         $isSuccess = (new Material())->updateMaterial($id, $form->materialId, $form->address, $form->isShow, $form->sort, $form->pcUrl, $form->wapUrl);
         if ($isSuccess) {
             Yii::$app->session->setFlash(Variable::$flash_success, '资料更新成功');
         } else {
             Yii::$app->session->setFlash(Variable::$flash_error, '资料更新失败,请刷新重试');
         }
         $this->redirect(Variable::$proBanner_url);
         return;
     }
     $materialModel = Material::findOne($id);
     $form->materialId = $materialModel->materialId;
     $form->id = $materialModel->id;
     $form->address = $materialModel->address;
     $form->isShow = $materialModel->isShow;
     $form->sort = $materialModel->sort;
     $form->pcUrl = $materialModel->pcUrl;
     $form->wapUrl = $materialModel->wapUrl;
     return $this->render(Variable::$editProBanner_view, ['model' => $form, 'materialModel' => $materialModel]);
 }
 public function actionUploadnetvideo()
 {
     $videoLink = trim(Yii::$app->request->post('videoLink'));
     if (!isset($videoLink) || empty($videoLink)) {
         JsonParser::GenerateJsonResult('_0001', '不合法的视频链接');
         exit;
     }
     $ss = 'video/';
     if (!strpos($videoLink, $ss)) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $videoLink);
         //不下载
         curl_setopt($ch, CURLOPT_NOBODY, 1);
         //设置超时
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
         curl_setopt($ch, CURLOPT_TIMEOUT, 3);
         curl_exec($ch);
         $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         if ($http_code == 200) {
             $model = Material::find()->where(['materialId' => Variable::$materialId_productVideo])->one();
             if ($model) {
                 $model->address = $videoLink;
                 if ($model->save()) {
                     JsonParser::GenerateJsonResult('_0000', '上传成功');
                     exit;
                 }
             } else {
                 $model = new Material();
                 $model->type = 2;
                 $model->materialId = Variable::$materialId_productVideo;
                 $model->address = $videoLink;
                 if ($model->save()) {
                     JsonParser::GenerateJsonResult('_0000', '上传成功');
                     exit;
                 }
             }
         }
         JsonParser::GenerateJsonResult('_0001', '不合法的视频链接');
         exit;
     }
     JsonParser::GenerateJsonResult('_0000', '上传成功');
     exit;
 }
 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]);
 }