コード例 #1
0
 /**
  * 根据appid获取应用在商店的数据
  * @param int $appId 应用id
  * @return ShopApps
  * @throws DeepInException
  */
 protected function find($appId)
 {
     $app = ShopApps::find($appId);
     if (!$app instanceof ShopApps) {
         throw new DeepInException("找不到{$appId}的应用数据~!");
     }
     return $app;
 }
コード例 #2
0
 /**
  * 选择应用
  * @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()));
 }
コード例 #3
0
 /**
  * 保存数据
  * @return \Illuminate\View\View
  * @throws DeepInHtmlException
  */
 public function save()
 {
     $rankId = intval(\Input::get("rankid"));
     $rank = null;
     if ($rankId > 0) {
         try {
             $rank = $this->find($rankId);
         } catch (DeepInException $e) {
         }
     }
     if (!$rank instanceof ShopRank) {
         $rank = new ShopRank();
     }
     //判断选在的应用的合法性
     $appId = intval(\Input::get("appid"));
     if ($appId < 1) {
         throw new DeepInHtmlException("请选在应用~!");
     }
     //判断榜单类别的合法性
     $categoryId = intval(\Input::get("categoryid"));
     if ($categoryId < 1) {
         throw new DeepInHtmlException("请选择榜单的类型~!");
     }
     $ranking = intval(\Input::get("ranking"));
     if ($ranking < 1) {
         throw new DeepInHtmlException("名次必须是正整数~!");
     }
     $app = ShopApps::find($appId);
     if (!$app instanceof ShopApps) {
         throw new DeepInHtmlException("选择的应用不存在~!");
     }
     if ($app->inuse() != 1) {
         throw new DeepInHtmlException("选择的应用属于下架状态~!");
     }
     $rankCategory = ShopRankCategory::find($categoryId);
     if (!$rankCategory instanceof ShopRankCategory) {
         throw new DeepInHtmlException("选择的榜单类型不存在~!");
     }
     $rank->appId($appId);
     $rank->appName($app->appName());
     $rank->categoryId($categoryId);
     $rank->ranking($ranking);
     if ($rank->save() == false) {
         throw new DeepInHtmlException("保存失败,请检查名次是否重复~!");
     }
     return $this->success("保存成功~!");
 }
コード例 #4
0
 /**
  * 保存修改
  * @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");
 }