/**
  * 集合列表页面显示的数据 [选择的应用,和还未被选在的应用]
  * @param $type
  * @param $id
  * @return \Illuminate\View\View
  * @throws DeepInException
  * @throws DeepInHtmlException
  */
 public function index($type, $id)
 {
     if ($this->checkAppList($type, $id) == false) {
         //错误的type和id
         throw new DeepInHtmlException("错误的参数~!");
     }
     if ($type == 1) {
         //栏目
         $column = ShopColumn::find($id);
         if (!$column instanceof ShopColumn) {
             throw new DeepInException("{$id}栏目不存在");
         }
         $local = $column->local();
     } else {
         //专题
         $topic = ShopTopic::find($id);
         if (!$topic instanceof ShopTopic) {
             throw new DeepInException("{$id}专题不存在");
         }
         $local = $topic->local();
     }
     $canDisplayApps = array();
     $appLocals = ShopAppsLocal::whereRaw("local=:local", array(":local" => $local))->get();
     foreach ($appLocals as $v) {
         if ($v instanceof ShopAppsLocal) {
             $canDisplayApps[] = $v->appId();
         }
     }
     //指定列表下的所有的应用列表集合
     $list = $this->findByTypeAndItem($type, $id);
     $ids = array();
     $newList = array();
     //最终已选择信息的组合
     foreach ($list as $v) {
         $ids[] = $v->appId();
         $newList[$v->appId] = $v->toArray();
     }
     unset($list);
     //删掉老数据
     $pageSize = 16;
     $packageId = \Input::get("packageid", null);
     //查询未被选择应用
     if (empty($ids) == false) {
         //还未被选选择的应用
         $where = "appid not in (" . implode(",", $ids) . ") and inuse=1";
         $bind = array();
         if (empty($packageId) == false) {
             $where .= " and packageid LIKE \"%{$packageId}%\"";
         }
         $unSelectApps = ShopApps::whereRaw($where, $bind)->whereIn("appid", $canDisplayApps)->paginate($pageSize);
         $selectedApps = ShopApps::whereRaw("appid  in (" . implode(",", $ids) . ")", array())->get();
     } else {
         $where = " inuse=1 ";
         $bind = array();
         if (empty($packageId) == false) {
             $where .= " and packageid LIKE \"%{$packageId}%\"";
         }
         $unSelectApps = ShopApps::whereRaw($where, $bind)->whereIn("appid", $canDisplayApps)->paginate($pageSize);
         $selectedApps = array();
     }
     //两者的数据合并
     foreach ($selectedApps as $v) {
         $v = $v->toArray();
         $newList[$v["appId"]] = array_merge($v, $newList[$v["appId"]]);
     }
     //排序
     usort($newList, function ($a, $b) {
         $diff = intval($a["pos"]) - intval($b["pos"]);
         if ($diff == 0) {
             return 0;
         }
         if ($diff < 0) {
             return 1;
         }
         return -1;
     });
     unset($selectedApps);
     return view("admin.applist.index", array("unselect" => $unSelectApps, "selected" => $newList, "type" => $type, "id" => $id));
 }
예제 #2
0
 /**
  * 选择应用
  * @return \Illuminate\View\View
  * @throws DeepInException
  */
 public function select()
 {
     $id = \Input::get("packageid");
     if (!$id) {
         throw new DeepInException("参数不完整");
     }
     //判断用户是否在应用里面
     $app = ShopApps::whereRaw("packageid=:packageid", array(":packageid" => $id))->first();
     if (!$app instanceof ShopApps) {
         //不存在在应用商店里面,属于新增一行数据到应用商店里面
         //拉取仓库里面的数据,部分数据是需要冗余的
         $responseValue = OpenApi::metadataInfo($id);
         if ($responseValue->getStatusCode() != 0) {
             throw new DeepInException("拉取仓库数据失败~!", $responseValue->getStatusMessage());
         }
         $data = $responseValue->getData();
         $app = new ShopApps();
         $app->packageId($id);
         $app->appName($id);
         //$data["name"]
         if ($app->save() == false) {
             throw new DeepInException("数据移进商店失败~!");
         }
         $appId = $app->appId();
         //创建两行宣传语的数据[默认新增两行]
         $inserted = ShopAppsTranslation::insert(array(array("appid" => $appId, "lang" => "zh_CN"), array("appid" => $appId, "lang" => "en_US")));
         if ($inserted == false) {
             throw new DeepInException("翻译数据新增失败~!");
         }
         return $this->successJSON();
     }
 }
 /**
  * 移除/移入 仓库数据到商店
  * @return \Illuminate\Http\JsonResponse
  * @throws DeepInException
  * @throws \Exception
  */
 public function select()
 {
     $id = \Input::get("packageid");
     if (!$id) {
         throw new DeepInException("参数不完整");
     }
     //判断用户是否在应用里面
     $app = ShopApps::whereRaw("packageid=:packageid", array(":packageid" => $id))->first();
     if (!$app instanceof ShopApps) {
         //不存在在应用商店里面,属于新增一行数据到应用商店里面
         //拉取仓库里面的数据,部分数据是需要冗余的
         $responseValue = OpenApi::metadataInfo($id);
         if ($responseValue->getStatusCode() != 0) {
             throw new DeepInException("拉取仓库数据失败~!", $responseValue->getStatusMessage());
         }
         $data = $responseValue->getData();
         $app = new ShopApps();
         $app->packageId($id);
         $app->appName($id);
         //$data["name"]
         if ($app->save() == false) {
             throw new DeepInException("数据移进商店失败~!");
         }
         $appId = $app->appId();
         //创建两行宣传语的数据[默认新增两行]
         $inserted = ShopAppsTranslation::insert(array(array("appid" => $appId, "lang" => "zh_CN"), array("appid" => $appId, "lang" => "en_US")));
         if ($inserted == false) {
             throw new DeepInException("翻译数据新增失败~!");
         }
     }
     return $this->successJSON();
     //        else {
     //            //应用在商店里面,需要判断该应用是否被栏目或者专题选用,如果被选用,则无法从商店里面remove掉该应用
     //
     //
     ////            $this->checkAppReferred($app->appId());
     ////            if ($app->inuse() == 1) {
     ////                throw new DeepInException("数据属于上架状态,无法移除商店~!");
     ////            }
     //            $applocalList = ShopAppsLocal::whereRaw("appid=:appid", array(":appid" => $appId))->get();
     //            if (count($applocalList) > 0) {
     //                throw new DeepInException("数据属于上架状态,无法移除商店~!");
     //            }
     //
     //            //删掉shop-app里面的数据
     //            if ($app->delete() == false) {
     //                throw new DeepInException("移除数据错误~!");
     //            }
     //
     //            //宣传语的翻译也要删掉
     //
     //            //对应的区域数据也要删掉
     //
     //
     //            return $this->successJSON();
     //        }
 }