Example #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;
 }
Example #2
0
 public function editDemand($id)
 {
     $demand = Demand::findOrFail($id);
     $cattree = $this->InitClassSelectOption(0, $demand->category_id);
     $cates = Category::where('parent_id', '=', 0)->orderby('id', 'desc')->get();
     $user = User::whereRaw('id=' . $demand->user_id)->get()->first();
     $brands = Brand::where("cateid", '=', $demand->category_id)->orderBy('id', 'desc')->get();
     //  var_dump($brands);exit();
     $dc = new DemandController();
     $bidinfo = $bidinfo = $dc->getbidinfo($demand);
     $deli = delivery::whereRaw('deid=' . $demand->id)->get()->first();
     $data = array('demand' => $demand, 'cates' => $cates, 'user' => $user, 'bids' => $bidinfo['bids'], 'bidinfo' => $bidinfo, 'deli' => $deli, 'catetree' => $cattree, 'brands' => $brands);
     return view("admin.edemand")->with($data);
 }
Example #3
0
 public function eidtCategory($cid, $pid, $slug, $sort)
 {
     $level = 0;
     $sortpath = "0,";
     if ($pid != 0) {
         $pcate = Category::find($pid);
         $level = $pcate->levels;
         $sortpath = $pcate->sortpath;
     }
     //找出父类别
     if ($level == 0) {
         $cateid = 10;
     }
     if ($level == 1) {
         $cateid = $pid * 100;
     }
     //第二级
     if ($level == 2) {
         $cateid = $pid * 1000;
     }
     //第三级
     if ($level == 3) {
         $cateid = $pid * 1000;
     }
     //第三级
     //找出当前的编号
     $findid = Category::where("levels", "=", $level + 1)->where("id", ">=", $cateid)->max("id");
     //echo "the find id is:".$findid."<br />";
     if ($findid) {
         $cateid = $findid + 1;
     }
     //在当前的编号上加1
     //  echo "the cateid is:".$cateid."<br />";
     $pinyin = CUtf8_PY::encode($slug);
     $cate = new Category();
     $cate->id = $cateid;
     $cate->parent_id = $pid;
     $cate->name = $pinyin;
     $cate->slug = $slug;
     $cate->sort = $sort;
     $cate->levels = $level + 1;
     $cate->sortpath = $sortpath . $cateid . ",";
     $cate->save();
     $oldcate = Category::find($cid);
     $allcateneedmodify = Category::where("sortpath", 'like', $oldcate->sortpath)->select();
     foreach ($allcateneedmodify as $key => $val) {
         $newsortpath = str_replace($val->oldpath, $cate->sortpath, $val->sortpath);
         $val::update(['sortpath' => $newsortpath]);
     }
     //    $uinfos=array(
     //       "sortpath"=>"replace(sortpath,'".$oldcate->sortpath."','".$cate->sortpath
     //            ."')"
     //    );
     //    $cate::where("sortpath",'like',$oldcate->sortpath)->update($uinfos);
     //   DB::statement("update categories set sortpath=replace(sortpath,'".$oldcate->sortpath."','".$cate->sortpath
     //      ."') where sortpath like '".$oldcate->sortpath."'");
     //   $cate::statement("update categories set sortpath=");
     //   $cate::where("sortpath",'like','%,'.$cid.',%')->update($uinfos);
     $cate::where("id", '=', $cid)->delete();
 }