Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public function brand(Request $request)
 {
     if ($request->method() == "POST") {
         $brandname = $request->input("brandname");
         $catid = intval($request->input("cateid"));
         if (!$brandname) {
             echo "品牌名称不能为空";
         }
         $brandname = trim($brandname);
         if (strpos($brandname, "\n") === false) {
             $abrand = new Brand();
             $abrand->bname = $brandname;
             $abrand->cateid = $catid;
             $abrand->save();
         } else {
             $names = explode("\n", $brandname);
             foreach ($names as $bname) {
                 $bname = trim($bname);
                 if (!$bname) {
                     continue;
                 }
                 $abrand = new Brand();
                 $abrand->bname = $bname;
                 $abrand->cateid = $catid;
                 $abrand->save();
             }
         }
         return redirect()->back()->withErrors('添加品牌成功。');
     }
     $brands = Brand::whereRaw('1=1')->orderBy('id', 'desc')->get();
     $catree = $this->InitClassSelectOption(0, 0);
     $data = array('brands' => $brands, 'catetree' => $catree);
     return view("admin.brand")->with($data);
 }
Esempio n. 3
0
 public function brand(Request $request)
 {
     $brand = Brand::select("id", 'bname')->where("cateid", '=', $request->input('cateid'))->orderBy('id', 'desc')->get();
     return json_encode($brand);
 }