Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions app/Http/Controllers/Product/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
);
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/Bid/BidRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions app/Repositories/User_Bid/UserBidRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion app/Repositories/User_Bid/UserBidRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
namespace App\Repositories\User_Bid;

interface UserBidRepositoryInterface {

function getBidHistory($bidId);
}
4 changes: 3 additions & 1 deletion config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
});
});
Expand Down
5 changes: 4 additions & 1 deletion resources/assets/js/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
});
});
Expand Down
37 changes: 23 additions & 14 deletions resources/views/bid/bid-history-item.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<li class="list-group-item user-bid-info">
<div class="row">
<div class="col-xs-6">
<img src="http://dummyimage.com/800x600/4d494d/686a82.gif&text=placeholder+image" alt="placeholder+image" class="avatar img-circle">
<span>Dang hoang Linh</span>

@foreach($userBids as $userBid)
<li class="list-group-item user-bid-info">
<div class="row">
<div class="col-xs-6">
<img src="http://dummyimage.com/800x600/4d494d/686a82.gif&text=placeholder+image" alt="placeholder+image" class="avatar img-circle">
<span>{{$userBid->nickname}}</span>
</div>
<div class="col-xs-2">
<span class="bid_amount">{{$userBid->bid_amount}}</span>
</div>
<div class="col-xs-4">
@if (empty($userBid->updated_at))
<p class="time-hour">{{$userBid->created_at->format('H:i:s')}}</p>
<p class="time-day">{{$userBid->created_at->format('Y-m-d')}}</p>
@else
<p class="time-hour">{{$userBid->updated_at->format('H:i:s')}}</p>
<p class="time-day">{{$userBid->updated_at->format('Y-m-d')}}</p>
@endif

</div>
</div>
<div class="col-xs-2">
<span class="cost">770K</span>
</div>
<div class="col-xs-4">
<p class="time-hour">14:47:09</p>
<p class="time-day">07/08/2017</p>
</div>
</div>
</li>
</li>
@endforeach
8 changes: 3 additions & 5 deletions resources/views/bid/bid_detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
<div class="bid">
@yield('bid')
<div class="bid-history">
<h3 class="title">Lịch sử đấu giá (15)</h3>
<ul class="list-group">
@for($i=1; $i<10; $i++)
@include('bid.bid-history-item')
@endfor
<h3 class="title">Lịch sử đấu giá </h3>
<ul class="list-group" id="bid-history">
@include('bid.bid-history-item')
</ul>
</div>
</div>
Expand Down