public function index(Request $request, $id = 0) { header("Content-Type:text/html;charset=utf-8"); $condition = " status=0 and is_pay=1 "; if ($request->get('s') != '') { $condition .= " and title like '%" . urldecode($request->get('s')) . "%' and status != -1 and deposit!=0"; // $demands = Demand::whereRaw('title like ? and status != -1 and deposit!=0', ['%' . $request->get('s') . '%'])->orderBy('id', 'desc')->get(); } else { $condition .= 'and status != -1 and deposit!=0'; } $condition .= " and expire_time>now()"; // echo $condition."<br />"; if ($id != 0) { $allcatids = ""; $allcat = Category::whereRaw("parent_id={$id} or id={$id}")->get(); foreach ($allcat as $onecate) { $allcatids .= $onecate->id . ","; } $allcatids = substr($allcatids, 0, -1); $condition .= " and (category_id in({$allcatids}) or cat1={$id} or cat2={$id} or cat3={$id} ) "; } if ($id == 0) { $brands = array(); } else { $brands = Brand::select("bname", "id")->where('cateid', '=', $id)->orderBy("id", 'desc')->get(); } $bid = $request->input("bid"); if ($bid) { $condition .= " and bid=" . $bid; } $demands = Demand::whereRaw($condition)->orderBy('is_top', 'desc')->orderBy('is_recommend', 'desc')->orderBy('is_hot', 'desc')->orderBy('id', 'desc')->paginate(15); //$cates = Category::where("parent_id", "=", $catid)->orderBy("id", "desc")->get(); $cates = $this->getallcate(0); $data = array('brands' => $brands, "cates" => $cates, 'hcateid' => $id); if ($this->ismobile()) { $view = view("demand.mobile.list")->with($data); } else { // $view = view("demand.list")->with($data); $view = view("demand.atest")->with($data); } if ($id != 0) { $pcate = Category::where("id", "=", $id)->orderby("sort", "asc")->get(); $pone = $pcate[0]; } else { $pone = new Category(); $pone->slug = "不限"; $pone->id = 0; $pone->parent_id = 0; } $view = $view->with('pcate', $pone); $view = $view->with('demands', $demands); return $view; }
public function cate(Request $request, $id = 0) { header("Expires:-1"); header("Cache-Control:no-cache"); header("Pragma:no-cache"); header("Content-Type:text/html;charset=utf-8"); if ($request->method() == "POST") { if ($request->input("action") == "delete") { $ids = implode(",", $request->input("catids")); Category::whereRaw("id in ({$ids})")->delete(); return redirect()->back()->withInput()->withErrors('删除成功。'); } } if ($request->method() == "GET") { $cates = Category::whereRaw("parent_id={$id}")->orderBy('sort', 'asc', "id", "desc")->select('id as switchs', 'id', 'name', 'slug', 'sort', 'sortpath')->get(); $data = array('cates' => $cates, "sid" => $id); return view('admin.cates', $data); } }