/**
  * 产品预览
  * @param  array $_POST 产品相关信息
  * @return array $model  显示产品相关信息
  */
 public function actionPreview()
 {
     $form = Yii::$app->request->post('extra');
     //数据过滤
     $tmp = isset($form['detail']) ? $form['detail'] : '';
     $form = array_map('trim', $form);
     $form = array_map('strip_tags', $form);
     $form = array_map('htmlspecialchars', $form);
     $form['detail'] = $tmp;
     // <script>alert('zhanglu');</script>
     //bug处理 限定name 和summary长度
     $form['name'] = mb_substr($form['name'], 0, 20, 'utf-8');
     $form['summary'] = mb_substr($form['summary'], 0, 100, 'utf-8');
     //获取hash值
     $formhash = Yii::$app->request->post('formhash', false);
     //formhash验证
     if (!PublicLibrary::verifyFormhash($formhash)) {
         echo '<script>alert("非法提交!");window.close;</script>';
         exit;
     } else {
         $session = Yii::$app->session;
         $session->isActive ? '' : $session->open();
         $session->set('formhash', $formhash);
         $session->close();
     }
     $user = PublicLibrary::is_login();
     //判断是否登陆
     if (!$user) {
         $this->redirect(['user/login', 'act' => base64_encode("home-page/lists")]);
     }
     //判断产品是否是该用户的
     $mIProductBase = new IProductBase();
     $res = $mIProductBase->isMyProduct($user['uid'], intval($form['id']));
     if (empty($res)) {
         return $this->redirect(['index']);
         exit;
     }
     //判断产品是否是该用户的
     $mIProductBase = new IProductBase();
     if (!$mIProductBase->isMyProduct($user['uid'], $form['id'])) {
         $this->redirect(['home-page/lists', 'uid' => $user['uid']]);
     }
     if (empty($form['summary']) || empty($form['name'])) {
         echo '<script>alert("产品名和简介都不能为空!");window.history.back(-1);</script>';
         exit;
     } else {
         //对i_product_extra表的插入或修改
         $model = IProductExtra::findOne(['product_id' => $form['id']]);
         if ($model == null) {
             $model = new IProductExtra();
             $model->create_time = time();
         }
         $model->product_id = intval($form['id']);
         $model->summary = strip_tags($form['summary']);
         $model->video_url = strip_tags($form['video_url']);
         $model->detail = $form['detail'];
         $model->update_time = time();
         $model->save();
         //对i_product_base表的插入或修改
         $model_base = IProductBase::findOne(['id' => $form['id']]);
         $model_base->update_time = time();
         $model_base->save();
         //album图片上传
         $album = UploadedFile::getInstanceByName('album');
         //试取图片album
         if ($album !== null) {
             //判断图片大小是否符合规定
             if ($album->size > 1048576 || $album->error != 0) {
                 echo '<script>alert("封面图片格式不对或大于1M!");window.history.back(-1);</script>';
                 exit;
             }
             //判断封面图片是否存在,或是修改
             $model = IProductBase::findOne(['id' => $form['id']]);
             $albumPath = $model->album;
             if (!$albumPath) {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片公有名
                 $albumPath = $rootpath . $randname;
                 //封面图路径
             }
             //缩略图入库用
             $tmp = $albumPath;
             $thumbPath = $albumPath . ProductImage::THUMB_SIZE_ONE;
             //缩略图路径
             //生成缩略图
             $width = 312;
             $height = 196;
             $thumbPath = '@frontend/web/' . $thumbPath . '.jpg';
             Image::thumbnail($album->tempName, $width, $height)->save(Yii::getAlias($thumbPath), ['quality' => 100]);
             //原图上传
             $album->saveAs($albumPath . '.jpg');
             $model->album = $albumPath;
             $model->name = strip_tags($form['name']);
             $model->price = strip_tags($form['price']);
             //原价
             $model->status = IProductBase::STATUS_INVALID;
             $model->save();
             //缩略图入库image表
             $mProductImage = new ProductImage();
             $re = $mProductImage->getByTypeAndPid(ProductImage::TYPE_ALBUM, $form['id']);
             //判断图片表中有没有该产品缩略图
             if (empty($re)) {
                 $content = ['product_id' => $form['id'], 'type' => ProductImage::TYPE_ALBUM, 'url' => $tmp, 'create_time' => time()];
                 $mProductImage->imageSave($content);
             }
         } else {
             $model = IProductBase::findOne(['id' => $form['id']]);
             if ($model->album !== '') {
                 $albumPath = $model->album . '.jpg';
                 $thumbPath = $model->album . ProductImage::THUMB_SIZE_ONE . '.jpg';
                 file_exists($albumPath) && unlink($albumPath);
                 file_exists($thumbPath) && unlink($thumbPath);
                 $model->album = '';
             }
             $model->name = strip_tags($form['name']);
             $model->price = strip_tags($form['price']);
             //原价
             $model->status = IProductBase::STATUS_INVALID;
             $model->save();
             //删除缩略图
             $mProductImage = new ProductImage();
             //判断图片表中有没有该产品缩略图
             $re = $mProductImage->getByTypeAndPid(ProductImage::TYPE_ALBUM, $form['id']);
             if (!empty($re)) {
                 $mProductImage->delBypk($re[0]['id']);
             }
         }
         //图片1上传
         $banner1 = UploadedFile::getInstanceByName('bigbanner1');
         //试取图片album
         if ($banner1 !== null) {
             //判断图片大小是否符合规定
             if ($banner1->size > 1048576 * 2 || $banner1->error != 0) {
                 echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>';
                 exit;
             }
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]);
             if ($model !== null) {
                 $banner1->saveAs($model->url . '.jpg');
             } else {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片名
                 $bannerPath = $rootpath . $randname;
                 //封面图路径
                 $banner1->saveAs($bannerPath . '.jpg');
                 //保存图片
                 //插入数据
                 $model = new ProductImage();
                 $model->product_id = $form['id'];
                 $model->url = $bannerPath;
                 $model->create_time = time();
                 $model->type = ProductImage::TYPE_BANNER;
                 $model->pos_id = 1;
                 $model->save();
             }
         } else {
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]);
             if ($model !== null) {
                 file_exists($model->url . '.jpg') && unlink($model->url . '.jpg');
                 $model->delete();
             }
         }
         //图片1在i_product_base 中是否存在
         $modelImage = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]);
         $modelBase = IProductBase::findOne(['id' => $form['id']]);
         if ($modelImage !== null) {
             $modelBase->banner_image = $modelImage->url;
             $modelBase->save();
         } else {
             $modelBase->banner_image = '';
             $modelBase->save();
         }
         //图片2上传
         $banner2 = UploadedFile::getInstanceByName('bigbanner2');
         //试取图片album
         if ($banner2 !== null) {
             //判断图片大小是否符合规定
             if ($banner2->size > 1048576 * 2 || $banner2->error != 0) {
                 echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>';
                 exit;
             }
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 2]);
             if ($model !== null) {
                 $banner2->saveAs($model->url . '.jpg');
             } else {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片名
                 $bannerPath = $rootpath . $randname;
                 //封面图路径
                 $banner2->saveAs($bannerPath . '.jpg');
                 //保存图片
                 //插入数据
                 $model = new ProductImage();
                 $model->product_id = $form['id'];
                 $model->url = $bannerPath;
                 $model->create_time = time();
                 $model->type = ProductImage::TYPE_BANNER;
                 $model->pos_id = 2;
                 $model->save();
             }
         } else {
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 2]);
             if ($model !== null) {
                 file_exists($model->url . '.jpg') && unlink($model->url . '.jpg');
                 $model->delete();
             }
         }
         //图片3上传
         $banner3 = UploadedFile::getInstanceByName('bigbanner3');
         //试取图片album
         if ($banner3 !== null) {
             //判断图片大小是否符合规定
             if ($banner3->size > 1048576 * 2 || $banner3->error != 0) {
                 echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>';
                 exit;
             }
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 3]);
             if ($model !== null) {
                 $banner3->saveAs($model->url . '.jpg');
             } else {
                 $rootpath = 'uploads/' . date('Y/m/d') . '/';
                 //图片保存路径
                 file_exists($rootpath) or mkdir($rootpath, 0700, true);
                 //生成图片路径
                 $randname = time() . rand(0, 500);
                 //图片名
                 $bannerPath = $rootpath . $randname;
                 //封面图路径
                 $banner3->saveAs($bannerPath . '.jpg');
                 //保存图片
                 //插入数据
                 $model = new ProductImage();
                 $model->product_id = $form['id'];
                 $model->url = $bannerPath;
                 $model->create_time = time();
                 $model->type = ProductImage::TYPE_BANNER;
                 $model->pos_id = 3;
                 $model->save();
             }
         } else {
             $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 3]);
             if ($model !== null) {
                 file_exists($model->url . '.jpg') && unlink($model->url . '.jpg');
                 $model->delete();
             }
         }
     }
     return $this->redirect(['product/view', 'id' => $form['id']]);
     //跳转到完善信息
 }