/**
  * 获取单个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()));
 }
 /**
  * 新增数据的保存
  * @return \Illuminate\Http\JsonResponse
  * @throws DeepInHtmlException
  */
 public function save()
 {
     $columnName = \Input::get("columnname");
     $enColumnName = \Input::get("encolumnname");
     $local = \Input::get("local");
     $pos = intval(\Input::get("pos"));
     if (empty($columnName) || empty($local) || empty($enColumnName)) {
         throw new DeepInHtmlException("参数不完整~!");
     }
     $column = new ShopColumn();
     $column->columnName($columnName);
     $column->local($local);
     $column->inuse(0);
     //默认是不上架的
     $column->pos($pos);
     $column->enColumnName($enColumnName);
     if ($column->save() == false) {
         throw new DeepInHtmlException("专题数据新增失败~!");
     }
     return $this->success("新增成功", "/admin/column");
 }
 /**
  *根据选择项显示不同的下拉选择项目
  * @return \Illuminate\Http\JsonResponse
  * @throws DeepInException
  */
 public function getItemIds()
 {
     $type = intval(\Input::get("type"));
     $checkVal = intval(\Input::get("check_val"));
     //对应的类型(1栏目 2专题类别 3slider)
     $data = array();
     $data[1] = function () {
         //栏目
         return ShopColumn::all();
     };
     $data[2] = function () {
         return ShopTopicCategory::all();
     };
     $data[3] = function () {
         return ShopSliderCategory::all();
     };
     if (!isset($data[$type])) {
         throw new DeepInException("错误的type" . $type);
     }
     return $this->successJSON(array("option" => $this->formatToOption($data[$type](), $checkVal)));
 }
Esempio n. 6
0
 /**
  * 检查专题栏目引用
  * @param $appId
  * @param $local
  * @throws DeepInException
  */
 protected function checkAppsListReferred($appId, $local)
 {
     $appListItem = ShopAppsList::whereRaw("appid=:appid", array(":appid" => $appId))->get();
     $data = array();
     foreach ($appListItem as $v) {
         if ($v instanceof ShopAppsList) {
             if (isset($data[$v->listType()])) {
                 $data[$v->listType()] = array();
             }
             $data[$v->listType()][] = $v->itemId();
         }
     }
     $locals = array();
     if (isset($data[1])) {
         //栏目
         $colnumList = ShopColumn::whereRaw("columnid in (:columnid)", array(":columnid" => implode(",", $data[1])))->get();
         foreach ($colnumList as $v) {
             if ($v instanceof ShopColumn) {
                 $locals[] = $v->local();
             }
         }
     }
     if (in_array($local, $locals)) {
         throw new DeepInException("无法取消,在栏目里面引用到该应用了。");
     }
     if (isset($data[2])) {
         //专题
         $topicList = ShopTopic::whereRaw("topicid=:topicid", array(":topicid" => implode(",", $data[2])))->get();
         foreach ($topicList as $v) {
             if ($v instanceof ShopTopic) {
                 $locals[] = $v->local();
             }
         }
     }
     if (in_array($local, $locals)) {
         throw new DeepInException("无法取消,在专题里面引用到该应用了。");
     }
 }