/**
  * @param ShopSlider $slider
  * @param string $local
  * @throws DeepInException
  */
 protected function checkLocal($slider, $local)
 {
     if ($slider->itemType() == 1) {
         //应用
         if ($this->appHasLocal($slider->itemId(), $local) == false) {
             throw new DeepInException("专题地区与应用专题对应不上~!");
         }
     } else {
         //专题
         $topic = ShopTopic::find($slider->itemId());
         if (!$topic instanceof ShopTopic) {
             throw new DeepInException("选择的专题不存在");
         }
         if (strcmp($topic->local(), $local) !== 0) {
             throw new DeepInException("专题地区与slider地区无法对应");
         }
     }
 }
 /**
  * slider迁徙
  * @param DeepInUpload $upload
  */
 protected function slider(DeepInUpload $upload)
 {
     $sliders = ShopSlider::all();
     foreach ($sliders as $item) {
         if (!$item instanceof ShopSlider) {
             continue;
         }
         $banner = $item->sliderPic();
         if (empty($banner)) {
             continue;
         }
         $response = $upload->getUpYunUrl($banner);
         $responseValue = $response->getResponseValue();
         if ($responseValue instanceof UpYunResponseValue) {
             $this->addToMap($banner, $responseValue->getLocation());
         }
     }
 }
 /**
  * 保存修改
  * @throws DeepInException
  * @throws DeepInHtmlException
  */
 public function save()
 {
     $id = intval(\Input::get("sliderid"));
     $pos = intval(\Input::get("pos"));
     $slider = null;
     //新增或者编辑的对象
     if ($id > 0) {
         //编辑
         $slider = $this->find($id);
         if (!$slider instanceof ShopSlider) {
             throw new DeepInHtmlException("当前编辑的数据可能已经被删除~!");
         }
         try {
             $uploadInfo = DeepInUtil::upload(array("sliderpic"));
             //上传信息
             if (isset($uploadInfo["sliderpic"])) {
                 $url = $uploadInfo["sliderpic"];
                 // TODO 删除之前的老图片
                 $oldPic = $slider->sliderPic();
                 //之前的老图片
                 $slider->sliderPic($url);
             }
         } catch (DeepInException $e) {
             //没有上传图片
             throw new DeepInHtmlException($e->getMessage());
         }
         $category = $slider->sliderCategory();
         $itemId = $slider->itemId();
         $itemType = $slider->itemType();
         $local = $slider->local();
         $pos = $slider->pos();
     } else {
         $category = \Input::get("slidercategory");
         //slider类别
         $category = intval($category);
         $itemType = intval(\Input::get("itemtype"));
         //连接的类型
         $itemId = intval(\Input::get("itemid"));
         //连接到对应的id
         $local = \Input::get("local");
         //地区
         if ($category < 1 || $itemId < 1 || $itemType < 1) {
             throw new DeepInHtmlException("参数不完整~!" . $category . "#" . $itemId . "#" . $itemType);
         }
         //新增
         $slider = new ShopSlider();
         try {
             $uploadInfo = DeepInUtil::upload(array("sliderpic"));
             //上传信息
             if (isset($uploadInfo['sliderpic']) == false) {
                 throw new DeepInHtmlException("请选择要上传的背景图片");
             }
             $url = $uploadInfo["sliderpic"];
             $slider->sliderPic($url);
         } catch (\Exception $e) {
             throw new DeepInHtmlException($e->getMessage());
         }
     }
     if ($category == 1) {
         //app
         $app = ShopApps::find($itemId);
         if (!$app instanceof ShopApps) {
             throw new DeepInHtmlException("找不到应用");
         }
         //            if ($app->inuse() != 1) {
         //                throw new DeepInHtmlException("该应用属于下线的状态,无法选择~!");
         //            }
         if ($this->appHasLocal($itemId, $local) == false) {
             throw new DeepInHtmlException("slider所在的地区与应用地区对应不上~!");
         }
     } elseif ($category == 2) {
         //专题
         $topic = ShopTopic::find($itemId);
         if (!$topic instanceof ShopTopic) {
             throw new DeepInHtmlException("找不到id为{$itemId}的专题~!");
         }
         if ($topic->inuse() != 1) {
             throw new DeepInHtmlException("你选择的专题已经下线,无法选择~!");
         }
         if (strcmp($topic->local(), $local) !== 0) {
             throw new DeepInHtmlException("slider所在的地区与专题地区对应不上~!");
         }
     } else {
         throw new DeepInHtmlException("错误的category" . $category . "~!");
     }
     //检查是否选择了地区对应不上的应用
     $slider->sliderCategory($category);
     $slider->itemType($itemType);
     $slider->itemId($itemId);
     $slider->local($local);
     $slider->pos($pos);
     if ($slider->save() == false) {
         throw new DeepInHtmlException("保存失败~!");
     }
     return $this->success("操作成功~!", "/admin/slider");
 }
Example #4
0
 /**
  * slider引用检查
  * @param $appId
  * @param $local
  * @throws DeepInException
  */
 protected function checkSliderReferred($appId, $local)
 {
     $slider = ShopSlider::whereRaw("itemtype=1 and itemid=:itemid", array(":itemid" => $appId))->get();
     $locals = array();
     foreach ($slider as $v) {
         if ($v instanceof ShopSlider) {
             $locals[] = $v->local();
         }
     }
     if (in_array($local, $locals)) {
         throw new DeepInException("大图轮播里面提交引用到该应用~!");
     }
 }