/**
  *
  * @param $id
  * @return ShopTopicBanner
  * @throws DeepInException
  */
 public function findBanner($id)
 {
     $banner = ShopTopicBanner::find($id);
     if ($banner instanceof ShopTopicBanner) {
         return $banner;
     }
     throw new DeepInException("找不到id为" . $id . '的数据');
 }
 /**
  * 专题
  * @param DeepInUpload $upload
  */
 protected function topic(DeepInUpload $upload)
 {
     $topicBanner = ShopTopicBanner::all();
     foreach ($topicBanner as $item) {
         if (!$item instanceof ShopTopicBanner) {
             continue;
         }
         $banner = $item->banner();
         if (empty($banner)) {
             continue;
         }
         $response = $upload->getUpYunUrl($banner);
         $responseValue = $response->getResponseValue();
         if ($responseValue instanceof UpYunResponseValue) {
             $this->addToMap($banner, $responseValue->getLocation());
         }
     }
 }
 /**
  * 保存图片
  * @throws DeepInHtmlException
  */
 public function save()
 {
     $topicId = intval(\Input::get("topicid"));
     $lang = \Input::get("lang");
     $bgColor = \Input::get("bgcolor", null);
     $appNameColor = \Input::get("appnamecolor", null);
     $categoryNameColor = \Input::get("categorynamecolor", null);
     if (empty($bgColor)) {
         throw new DeepInHtmlException("请填入背景颜色~!");
     }
     if (empty($appNameColor)) {
         throw new DeepInHtmlException("应用名称颜色不能为空");
     }
     if (empty($categoryNameColor)) {
         throw new DeepInHtmlException("分类名称颜色不能为空~!");
     }
     if (empty($lang)) {
         throw new DeepInHtmlException("请选择语言~!");
     }
     try {
         $this->find($topicId);
     } catch (DeepInException $e) {
         throw new DeepInHtmlException($e->getMessage());
     }
     $bannerId = intval(\Input::get("bannerid"));
     $banner = null;
     if ($bannerId > 0) {
         try {
             $banner = $this->findBanner($bannerId);
         } catch (DeepInException $e) {
             $banner = null;
         }
     }
     $isAdd = false;
     if ($banner == null) {
         $banner = new ShopTopicBanner();
         $isAdd = true;
     }
     $banner->lang($lang);
     //语言
     $banner->topicId($topicId);
     $banner->bgColor($bgColor);
     $banner->appNameColor($appNameColor);
     $banner->categoryNameColor($categoryNameColor);
     $upload = DeepInUtil::upload(array("banner"));
     if (isset($upload["banner"])) {
         $banner->banner($upload["banner"]);
     } else {
         if ($isAdd) {
             throw new DeepInHtmlException("请上传背景图片~!");
         }
     }
     if ($banner->save() == false) {
         throw new DeepInHtmlException("操作失败~!");
     }
     return $this->success("操作成功~!");
 }
 /**
  * 删除数据
  * @param $id
  * @return \Illuminate\Http\JsonResponse
  * @throws DeepInException
  * @throws \Exception
  */
 public function delete($id)
 {
     try {
         $topic = $this->find($id);
     } catch (DeepInException $e) {
         throw new DeepInHtmlException($e->getMessage());
     }
     if ($topic->inuse() == 1) {
         throw new DeepInHtmlException("专题属于上线状态,无法删除~!");
     }
     //删除其选择的应用列表
     ShopAppsList::whereRaw("listtype=2 and itemid=:itemid", array(":itemid" => $topic->topicId()))->delete();
     //删除对应的背景图片数据
     ShopTopicBanner::whereRaw("topicid=:topicid", array(":topicid" => $topic->topicId()))->delete();
     if ($topic->delete() == false) {
         throw new DeepInHtmlException("删除失败~!");
     }
     return $this->success("删除成功~!");
 }