Example #1
0
 public function getDemands($idstr, $bids = "", $key = "")
 {
     $ids = explode(",", $idstr);
     $conditions = " 1!=1";
     foreach ($ids as $id) {
         $id = trim($id);
         if (empty($id)) {
             continue;
         }
         $conditions .= " or sortpath like  '%," . $id . ",%' ";
     }
     $catemodel = new Category();
     $catarray = $catemodel->getbysql2array($conditions);
     if (!$catarray) {
         return;
     }
     $cateids = implode(",", $catarray);
     //TODO:去掉注释
     $condition = "  1=1 ";
     $condition = " status=0 and is_pay=1 ";
     //  $condition.='and status != -1 and deposit!=0';
     $condition .= " and category_id in ( {$cateids}  )";
     $condition .= " and expire_time>now()";
     if (substr($bids, -1) == ',') {
         $bids = substr($bids, 0, -1);
     }
     if (!empty($bids)) {
         $condition .= " and  bid in ( {$bids} )  ";
     }
     if (!empty($key)) {
         $condition .= " and  title like '%" . urldecode($key) . "%'  ";
     }
     //echo "condition =$condition";exit();
     return $this->whereRaw($condition)->orderby("id", "desc")->get()->toArray();
 }
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();
 }
Example #4
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);
     }
 }
Example #5
0
 function ajax_brand()
 {
     header("Content-Type:text/html;charset=utf-8");
     if (!isset($_GET['id']) || empty($_GET['id'])) {
         echo $this->ecm_json_encode(false);
         return;
     }
     $id = $_GET['id'];
     $id = intval($id);
     //  var_dump($_GET);exit();
     $catemodel = new Category();
     $cate = $catemodel->getbrand($id);
     //   var_dump($cate);exit();
     $data = array();
     foreach ($cate as $key => $val) {
         $onedata = array();
         $onedata['cate_name'] = $val['slug'];
         $onedata['cate_id'] = $val['id'];
         $data[] = $onedata;
     }
     echo $this->ecm_json_encode(array_values($data));
     return;
 }