Example #1
0
 public function actionChange()
 {
     $id = $this->_get('id');
     if ($id) {
         $model = Dynamic::model()->findByPk($id);
         if ($_POST['Dynamic']) {
             $accessKey = Yii::app()->params['qiniu']['accessKey'];
             $secretKey = Yii::app()->params['qiniu']['secretKey'];
             $auth = new Auth($accessKey, $secretKey);
             $bucket = 'urtime1';
             $token = $auth->uploadToken($bucket);
             $uploadMgr = new UploadManager();
             $_POST['Dynamic']['dy_type'] = 2;
             if ($_FILES['upImage']['name'] != null) {
                 $images = $this->setImageInformation($_FILES, $token, $uploadMgr);
                 if ($images) {
                     //$images_str = implode(',',$images);
                     $_POST['Dynamic']['dy_images'] = json_encode($images);
                     //$images_str;
                 }
             }
             $model->attributes = $_POST['Dynamic'];
             if ($model->validate() && $model->save()) {
                 //$this->redirect('site/index');
                 Yii::app()->user->setFlash('dynamic', '修改成功');
                 // Yii::app()->end();
                 $this->redirect(array('/dynamic/index'));
             }
         }
         $images = array();
         if ($model->dy_images) {
             $image = json_decode($model->dy_images);
             foreach ($image as $key => $val) {
                 $images[] = Yii::app()->params['qiniu']['host'] . $val;
             }
         }
         $stores = Store::model()->getName();
         $this->render('change', ['model' => $model, 'images' => $images, 'stores' => $stores]);
     } else {
         $this->redirect(array('/site/index'));
     }
 }
Example #2
0
 public function actionUpImages()
 {
     if (($return = $this->verify()) == true) {
         $accessKey = Yii::app()->params['qiniu']['accessKey'];
         $secretKey = Yii::app()->params['qiniu']['secretKey'];
         $auth = new Auth($accessKey, $secretKey);
         $bucket = 'urtime1';
         $token = $auth->uploadToken($bucket);
         $uploadMgr = new UploadManager();
         //上传介绍图片
         //if ($_FILES['upImage']['name'] != null) {
         $images = $this->setImageInformation($_FILES, $token, $uploadMgr);
         if ($images) {
             //$images_str = implode(',',$images);
             $this->notice('OK', 0, '上传成功', $images);
             Yii::app()->end();
         } else {
             $this->notice('ERR', 307, $this->API_ERRORS[307]);
         }
         /*} else {
               $this->notice('ERR', 301, $this->API_ERRORS[301]);
           }*/
     }
 }
Example #3
0
 public function actionChange()
 {
     $id = $this->_get('id');
     if ($id) {
         $accessKey = Yii::app()->params['qiniu']['accessKey'];
         $secretKey = Yii::app()->params['qiniu']['secretKey'];
         $auth = new Auth($accessKey, $secretKey);
         $bucket = 'urtime1';
         $token = $auth->uploadToken($bucket);
         $uploadMgr = new UploadManager();
         $model = Store::model()->findByPk($id);
         $bussiness_license = array();
         $images = array();
         if ($model->bussiness_license) {
             $bussiness_license = json_decode($model->bussiness_license);
         }
         if ($model->images_str) {
             $image = json_decode($model->images_str);
             if ($image) {
                 foreach ($image as $key => $val) {
                     $images = Yii::app()->params['qiniu']['host'] . $val;
                 }
             }
         }
         if ($_POST['Store']) {
             //上传logo
             if ($_FILES['image']['name'] != null) {
                 $images = array($_FILES['image']);
                 $images = $this->setImageInformation($images, $token, $uploadMgr);
                 if ($images) {
                     $_POST['Store']['image'] = $images[0];
                 }
                 unset($_FILES['image']);
             } else {
                 unset($_FILES['image']);
             }
             //上传营业执照
             if ($_FILES['bussiness_license1']['name'] != null || $_FILES['bussiness_license2']['name'] != null) {
                 if ($model->bussiness_license) {
                     if ($_FILES['bussiness_license1']['name'] != null || $_FILES['bussiness_license2']['name'] == null) {
                         $bussiness = json_decode($model->bussiness_license);
                         $images = array($_FILES['bussiness_license1']);
                         $images = $this->setImageInformation($images, $token, $uploadMgr);
                         $bussiness[0] = $images[0];
                         $_POST['Store']['bussiness_license'] = json_encode($bussiness);
                         //$images_str;
                     } else {
                         if ($_FILES['bussiness_license1']['name'] == null || $_FILES['bussiness_license2']['name'] != null) {
                             $bussiness = json_decode($model->bussiness_license);
                             $images = array($_FILES['bussiness_license2']);
                             $images = $this->setImageInformation($images, $token, $uploadMgr);
                             $bussiness[1] = $images[0];
                             $_POST['Store']['bussiness_license'] = json_encode($bussiness);
                             //$images_str;
                         } else {
                             $images = array($_FILES['bussiness_license1'], $_FILES['bussiness_license2']);
                             $images = $this->setImageInformation($images, $token, $uploadMgr);
                             if ($images) {
                                 // $images_str = implode(',',$images);
                                 $_POST['Store']['bussiness_license'] = json_encode($images);
                                 //$images_str;
                             }
                         }
                     }
                 } else {
                     $images = array($_FILES['bussiness_license1'], $_FILES['bussiness_license2']);
                     $images = $this->setImageInformation($images, $token, $uploadMgr);
                     if ($images) {
                         // $images_str = implode(',',$images);
                         $_POST['Store']['bussiness_license'] = json_encode($images);
                         //$images_str;
                     }
                 }
                 unset($_FILES['bussiness_license1']);
                 unset($_FILES['bussiness_license2']);
             } else {
                 unset($_FILES['bussiness_license1']);
                 unset($_FILES['bussiness_license2']);
             }
             //上传介绍图片
             if ($_FILES['upImage']['name'] != null) {
                 $images = $this->setImageInformation($images, $token, $uploadMgr);
                 if ($images) {
                     //$images_str = implode(',',$images);
                     $_POST['Store']['images_str'] = json_encode($images);
                     //$images_str;
                 }
             }
             $model->attributes = $_POST['Store'];
             if ($model->validate() && $model->save()) {
                 //$this->redirect('site/index');
                 Yii::app()->user->setFlash('create', '成功', '失败');
                 // Yii::app()->end();
                 $this->redirect(array('/store/view'));
             }
         }
         $is_manager = Yii::app()->user->getState("info")->authority >= 1 ? 1 : 0;
         //             var_dump($images);
         //             exit;
         $managers = Managers::model()->loadStaffAllModel();
         $this->render('change', ['model' => $model, 'bussiness_license' => $bussiness_license, 'images' => $images, 'managers' => $managers, 'is_manager' => $is_manager]);
     } else {
         $this->redirect(array('/site/index'));
     }
 }