/** * 获取单个column数据 * @param $columnId * @return ShopColumn * @throws DeepInException */ public function find($columnId) { $column = ShopColumn::find($columnId); if (!$column instanceof ShopColumn) { throw new DeepInException("找不到id为{$columnId}的数~!"); } return $column; }
/** * 获取列表所属的专题/栏目 * @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())); }