diff --git a/app/Http/Controllers/Product/ProductController.php b/app/Http/Controllers/Product/ProductController.php index 7ef58b6..3928809 100644 --- a/app/Http/Controllers/Product/ProductController.php +++ b/app/Http/Controllers/Product/ProductController.php @@ -32,8 +32,11 @@ public function __construct(BidRepositoryInterface $bidRepository,UserBidReposit */ public function getBid($id) { $bid = $this->bidRepository->find($id); - return view('bid.bid_current',['bid'=>$bid]); + $userBids = $this->user_bidRepository->getBidHistory($id); + //dd($userBids); + return view('bid.bid_current')->with(compact('bid'))->with(compact('userBids')); } + /** * @param $request{user_id, real_bid_amound} * @return $current_price @@ -43,27 +46,40 @@ public function postBid(Request $request, $id) { $bid = $this->bidRepository->getBid($id); if(!$bid){ + $userBids = $this->user_bidRepository->getBidHistory($id); + $historyView = view('bid.bid-history-item')->with(compact('userBids'))->render(); return array( 'type'=> 'error', - 'data' => 'bid not valid' + 'data' => 'bid not valid', + 'bid_history' => $historyView, ); } + //return $bid->current_highest_bidder_id == null ? 1:0; if($bid->current_highest_bidder_id == null) { if($request->real_bid_amount < $bid->cost_begin){ + + $userBids = $this->user_bidRepository->getBidHistory($id); + $historyView = view('bid.bid-history-item')->with(compact('userBids'))->render(); + return array( 'type'=> 'error', - 'data' => 'bid must more than cost begin' + 'data' => 'bid must more than cost begin', + 'bid_history' => $historyView, ); } //return "nguoi tra gia lan dau"; $this->amountFirst($bid, $request); - } else{ + } else { if ($request->real_bid_amount < ($bid->current_price+$this->bid_amount_step)) { + + $userBids = $this->user_bidRepository->getBidHistory($id); + $historyView = view('bid.bid-history-item')->with(compact('userBids'))->render(); return array( 'type'=> 'error', - 'data' => 'bid must more than current price' + 'data' => 'bid must more than current price', + 'bid_history' => $historyView, ); } @@ -86,13 +102,18 @@ public function postBid(Request $request, $id) { } } + + $userBids = $this->user_bidRepository->getBidHistory($id); + $historyView = view('bid.bid-history-item')->with(compact('userBids'))->render(); + $respont = array( 'type' => 'success', 'data' => array( 'current_highest_bidder_id'=> $bid->current_highest_bidder_id, 'current_highest_bidder_name'=>$bid->current_highest_bidder_name, 'current_price'=> $bid->current_price, - ) + ), + 'bid_history' => $historyView, ); return $respont; diff --git a/app/Repositories/Bid/BidRepository.php b/app/Repositories/Bid/BidRepository.php index ca4ef47..cf5e44f 100644 --- a/app/Repositories/Bid/BidRepository.php +++ b/app/Repositories/Bid/BidRepository.php @@ -29,7 +29,7 @@ public function getCurrentBids() { $now = Carbon::now(); $bids = Bid::where('time_begin', '<', $now) ->where('time_end', '>', $now) - ->paginate(Config::get('constants.number_item_per_page.success_bids')); + ->paginate(Config::get('constants.number_item_per_page.current_bids')); return $bids; } @@ -43,7 +43,7 @@ public function getSuccessBids() { ->where('time_end', '<', $now) ->where('current_highest_bidder_id', '!=', null) ->latest('time_begin') - ->paginate(Config::get('constants.number_item_per_page.current_bids')); + ->paginate(Config::get('constants.number_item_per_page.success_bids')); return $bids; } diff --git a/app/Repositories/User_Bid/UserBidRepository.php b/app/Repositories/User_Bid/UserBidRepository.php index cf65d9f..5e83219 100644 --- a/app/Repositories/User_Bid/UserBidRepository.php +++ b/app/Repositories/User_Bid/UserBidRepository.php @@ -2,6 +2,7 @@ namespace App\Repositories\User_Bid; use App\Models\User_Bid; +use App\Models\UserBid; use Carbon\Carbon; use Illuminate\Container\Container as App; use Illuminate\Support\Facades\Config; @@ -13,4 +14,13 @@ class UserBidRepository extends BaseRepository implements UserBidRepositoryInter public function __construct(User_Bid $user_bid) { parent::__construct($user_bid); } + + public function getBidHistory($bidId) { + $rows = UserBid::join('users', 'user_bid.user_id', '=', 'users.id') + ->select(DB::raw('user_bid.*, users.nickname as nickname')) + ->where('bid_id', '=', $bidId) + ->orderBy('id', 'desc') + ->get(); + return $rows; + } } diff --git a/app/Repositories/User_Bid/UserBidRepositoryInterface.php b/app/Repositories/User_Bid/UserBidRepositoryInterface.php index 129a3da..7cd34f1 100644 --- a/app/Repositories/User_Bid/UserBidRepositoryInterface.php +++ b/app/Repositories/User_Bid/UserBidRepositoryInterface.php @@ -3,5 +3,5 @@ namespace App\Repositories\User_Bid; interface UserBidRepositoryInterface { - + function getBidHistory($bidId); } diff --git a/config/constants.php b/config/constants.php index 7d43b8c..e5b3f6e 100644 --- a/config/constants.php +++ b/config/constants.php @@ -47,8 +47,10 @@ 'number_item_per_page' => array( 'success_bids' => 8, - 'current_bids' => 8, 'fail-bid' => 8, + 'current_bids' => 16, + 'end' => 16, + 'all' => 16, ), 'japan_prefectures' => array( diff --git a/public/js/app.js b/public/js/app.js index a02356d..216f00c 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -35778,7 +35778,9 @@ $(function () { return; } - $.post("/bid-current/" + bidId, { + var url = $(location).attr('href'); + console.log(url); + $.post(url, { user_name: name, user_id: id, real_bid_amount: amount @@ -35790,6 +35792,7 @@ $(function () { $('.hightest-bid-user').html(respont.data.current_highest_bidder_name); $('.input-bid input[name="amount"]').val(""); $('.input-bid input[name="amount"]').attr('placeholder', 'Đặt giá tối thiểu từ ' + respont.data.current_price + ' hoặc hơn'); + $('#bid-history').html(respont.bid_history); } }); }); diff --git a/resources/assets/js/bid.js b/resources/assets/js/bid.js index e56022e..050963d 100644 --- a/resources/assets/js/bid.js +++ b/resources/assets/js/bid.js @@ -16,7 +16,9 @@ $(function(){ return; } - $.post("/bid-current/"+bidId, + var url = $(location).attr('href'); + console.log(url); + $.post(url, { user_name: name, user_id: id, @@ -30,6 +32,7 @@ $(function(){ $('.hightest-bid-user').html(respont.data.current_highest_bidder_name); $('.input-bid input[name="amount"]').val(""); $('.input-bid input[name="amount"]').attr('placeholder','Đặt giá tối thiểu từ '+respont.data.current_price+' hoặc hơn') + $('#bid-history').html(respont.bid_history); } }); }); diff --git a/resources/views/bid/bid-history-item.blade.php b/resources/views/bid/bid-history-item.blade.php index 9e31396..67a9856 100644 --- a/resources/views/bid/bid-history-item.blade.php +++ b/resources/views/bid/bid-history-item.blade.php @@ -1,15 +1,24 @@ -
  • -
    -
    - placeholder+image - Dang hoang Linh + +@foreach($userBids as $userBid) +
  • +
    +
    + placeholder+image + {{$userBid->nickname}} +
    +
    + {{$userBid->bid_amount}} +
    +
    + @if (empty($userBid->updated_at)) +

    {{$userBid->created_at->format('H:i:s')}}

    +

    {{$userBid->created_at->format('Y-m-d')}}

    + @else +

    {{$userBid->updated_at->format('H:i:s')}}

    +

    {{$userBid->updated_at->format('Y-m-d')}}

    + @endif + +
    -
    - 770K -
    -
    -

    14:47:09

    -

    07/08/2017

    -
    - -
  • + +@endforeach \ No newline at end of file diff --git a/resources/views/bid/bid_detail.blade.php b/resources/views/bid/bid_detail.blade.php index 131ec6b..62b7cbf 100644 --- a/resources/views/bid/bid_detail.blade.php +++ b/resources/views/bid/bid_detail.blade.php @@ -28,11 +28,9 @@
    @yield('bid')
    -

    Lịch sử đấu giá (15)

    -