예제 #1
0
 /**
  * 查找特定的专题信息
  * @param $topicId
  * @return ShopTopic
  * @throws DeepInException
  */
 public function find($topicId)
 {
     $topic = ShopTopic::find($topicId);
     if (!$topic instanceof ShopTopic) {
         throw new DeepInException("找不到id为" . $topicId . "的数据~!");
     }
     return $topic;
 }
예제 #2
0
 /**
  * @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地区无法对应");
         }
     }
 }
예제 #3
0
 /**
  * 获取列表所属的专题/栏目
  * @param $type
  * @param $id
  * @return null
  * @throws DeepInHtmlException
  */
 protected function getApplistParent($type, $id)
 {
     //列表集合类型(1栏目下的应用集合 2专题下的应用集合)
     if ($type == 1) {
         $column = ShopColumn::find($id);
         if (!$column instanceof ShopColumn) {
             return null;
         }
         return $column;
     } elseif ($type == 2) {
         $topic = ShopTopic::find($id);
         if (!$topic instanceof ShopTopic) {
             return null;
         }
         return $topic;
     } else {
         throw new DeepInHtmlException("未知的type" . $type);
     }
 }
 /**
  * 选择应用
  * @return \Illuminate\Http\JsonResponse
  * @throws DeepInException
  * @throws DeepInHtmlException
  */
 public function select()
 {
     $listType = intval(\Input::get("listtype", 0));
     //类型
     $itemId = intval(\Input::get("itemid", 0));
     //类型下面对应的id
     $appId = intval(\Input::get("appid", 0));
     //选在的appid
     if ($listType < 1 || $itemId < 0) {
         throw new DeepInException("参数错误~!");
     }
     if ($appId < 1) {
         throw new DeepInException("请选择应用~!");
     }
     //判断应用是否存在
     $app = ShopApps::find($appId);
     if (!$app instanceof ShopApps) {
         throw new DeepInException("选择的应用不存在~!");
     }
     $appLocals = $app->localList()->getResults();
     if ($listType == 1) {
         //栏目
         $colunmn = ShopColumn::find($itemId);
         if (!$colunmn instanceof ShopColumn) {
             throw new DeepInException("专题不存在");
         }
         $local = $colunmn->local();
     } else {
         $topic = ShopTopic::find($itemId);
         if (!$topic instanceof ShopTopic) {
             throw new DeepInException("专题不存在~!");
         }
         $local = $topic->local();
     }
     $isFindLocal = false;
     foreach ($appLocals as $item) {
         if ($item instanceof ShopAppsLocal) {
             if (strcmp($local, $item->local()) === 0) {
                 $isFindLocal = true;
             }
         }
     }
     if ($isFindLocal == false) {
         throw new DeepInException("区域不对~!");
     }
     //        print_r($appLocals);
     //        exit;
     //判断listtype和itemid是否正确
     if ($this->checkAppList($listType, $itemId) == false) {
         throw new DeepInException("listType和itemId参数非法~!");
     }
     $parent = $this->getApplistParent($listType, $itemId);
     if ($parent == null) {
         throw new DeepInException("找不到对应的数据~!");
     }
     $canLocal = $parent->local();
     //只查询该地区下面的应用列表
     if ($this->appHasLocal($appId, $canLocal) == false) {
         throw new DeepInException("应用" . $app->appName() . "不属于" . $canLocal . "地区");
     }
     //创建一行数据加入到数据库中
     $appList = new ShopAppsList();
     $appList->listType($listType);
     $appList->itemId($itemId);
     $appList->appId($appId);
     $appList->pos(0);
     if ($appList->save() == false) {
         throw new DeepInException("新增数据错误~!");
     }
     $appList->pos($appList->id());
     $appList->save();
     //保存位置信息,如果知道不报错。
     return $this->successJSON(array("id" => $appList->id()));
 }
 /**
  * 保存修改
  * @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");
 }