Esempio n. 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;
 }
 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;
 }