public function actionProbanner() { $user = new AdminUser(); if (!$user->checkUserIsLogin()) { $this->redirect(Variable::$home_url); return; } $query = Material::find()->where(['materialId' => Variable::$materialId_proBanner]); $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $query->count()]); $countries = $query->orderBy('addTime DESC')->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render(Variable::$proBanner_view, ['countries' => $countries, 'pagination' => $pagination]); }
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]); }