Esempio n. 1
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();
 }
Esempio n. 2
0
 private function add($pid, $slug, $sort, $sortpath)
 {
     $level = 0;
     if ($pid != 0) {
         $pcate = Category::find($pid);
         $level = $pcate->levels;
     }
     //找出父类别
     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);
     $tpcate = Category::where("slug", "=", $slug)->count();
     if ($tpcate >= 1) {
         return;
     }
     $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();
 }
Esempio n. 3
0
 public function showDemand($id)
 {
     try {
         $demand = Demand::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return Redirect::to('/')->withInput()->withErrors('竞购信息不存在或已被删除!');
     }
     $onecate = $demand->cat1;
     $twocate = $demand->cat2;
     $tricate = $demand->cat3;
     $path = array();
     if ($onecate != 0) {
         $cinfo = Category::find($onecate);
         if ($cinfo) {
             $path[] = array('id' => $cinfo->id, 'name' => $cinfo->slug);
         }
     }
     if ($twocate != 0) {
         $cinfo = Category::find($twocate);
         if ($cinfo) {
             $path[] = array('id' => $cinfo->id, 'name' => $cinfo->slug);
         }
     }
     if ($tricate != 0) {
         $cinfo = Category::find($tricate);
         if ($cinfo) {
             $path[] = array('id' => $cinfo->id, 'name' => $cinfo->slug);
         }
     }
     // print_r($demand);
     $bids = $demand->bids;
     $myBid = null;
     $bidinfo = $this->getbidinfo($demand);
     $lowprice = $bidinfo['lowprice'];
     if (isset(Auth::user()->id)) {
         foreach ($bids as $bid) {
             if ($bid->user_id == Auth::user()->id) {
                 $myBid = $bid;
                 break;
             }
         }
     }
     $data = array('demand' => $demand, 'bids' => $bids, 'myBid' => $myBid, 'lowprice' => $lowprice, 'path' => $path);
     if ($this->ismobile()) {
         return view('demand.mobile.show', $data);
     } else {
         return view('demand.show', $data);
     }
 }