Пример #1
0
 public function addBid(Request $request)
 {
     $this->validate($request, Bid::addRules());
     if (!isset(Auth::user()->id)) {
         return Redirect::to('/auth/login')->withErrors('你没有登录,请登录后再出价!');
     }
     $cert = Certification::where('user_id', '=', Auth::user()->id)->first();
     if ($cert == null) {
         return Redirect::to('auth/cert')->with('cert', $cert)->withErrors('你没有通过审核,请审核后再出价!');
     }
     if ($cert->is_identity == "1" && $cert->is_license == "1") {
         $user = User::where("id", "=", Auth::user()->id)->get()->first();
         if ($user->deposit == "0") {
             $demand = new Demand();
             $demand->title = "商家" . $user->username . "支付保证金 - ";
             $lastPrice = 2000;
             $showtitle = "支付保证金";
             $step = 3;
             //商家的保证金为3
             $purl = "/pay/payorder/bidder";
             return view('pay.demand', ['demand' => $demand, 'lastPrice' => $lastPrice, 'showtitle' => $showtitle, 'step' => $step, 'purl' => $purl])->withErrors('请缴纳保证金后出价!');
         }
     } else {
         return Redirect::to('auth/cert')->with('cert', $cert)->withErrors('你没有通过审核,请审核后再出价!');
     }
     //       return Redirect::to('/auth/cert')
     //          ->withErrors('删除成功!');
     if ($request->bid_id == 0) {
         $bid = new Bid();
         $bid->user_id = Auth::user()->id;
         $bid->demand_id = $request->get('demand_id');
         $helper = new Helper();
         $bid->sn = 'DE' . time() . $helper->mt_rand_str(4, '0123456789');
         //单号算法:DE+当前时间戳10位数字+4位随机数
         $bid->url = $request->get('url');
         $bid->price = $request->get('price');
         $bid->details = $request->get('details');
         $bid->area_id = 110000;
         $bid->save();
     } else {
         $bid = Bid::find($request->bid_id);
         $bid->price = $request->get('price');
         $bid->details = $request->get('details');
         $bid->url = $request->get('url');
         $bid->save();
     }
     return Redirect::to('demand/show/' . $bid->demand_id);
 }