diff --git a/app/Endpoint/Api/Http/Controllers/BargainController.php b/app/Endpoint/Api/Http/Controllers/BargainController.php index 19e5e74d..89984052 100644 --- a/app/Endpoint/Api/Http/Controllers/BargainController.php +++ b/app/Endpoint/Api/Http/Controllers/BargainController.php @@ -85,6 +85,7 @@ class BargainController extends Controller 'user_id'=> $userId, ])->where('status', '>', 0) ->where('expire_at', '>', now()) + ->whereNull('order_id') ->orderBy('created_at', 'desc')->first(); if ($order) { return BargainOrderResource::make($order); @@ -105,6 +106,7 @@ class BargainController extends Controller 'id' => $id, ])->where('status', '>', 0) ->where('expire_at', '>', now()) + ->whereNull('order_id') ->orderBy('created_at', 'desc')->first(); if ($order) { return BargainOrderResource::make($order); diff --git a/app/Endpoint/Api/Http/Resources/BargainOrderResource.php b/app/Endpoint/Api/Http/Resources/BargainOrderResource.php index b13634a7..c69a3a67 100644 --- a/app/Endpoint/Api/Http/Resources/BargainOrderResource.php +++ b/app/Endpoint/Api/Http/Resources/BargainOrderResource.php @@ -21,6 +21,7 @@ class BargainOrderResource extends JsonResource 'logs' => BargainOrderLogResource::collection($this->whenLoaded('logs')), 'expire_at'=> $this->expire_at->format('Y-m-d H:i:s'), 'status' => $this->status, + 'user_nickname'=> $this->user->userInfo->nickname ?? '', 'is_owner' => $this->user_id == $userId ? true : false, ]; } diff --git a/app/Models/BargainOrder.php b/app/Models/BargainOrder.php index b50a802e..d7244ba6 100644 --- a/app/Models/BargainOrder.php +++ b/app/Models/BargainOrder.php @@ -23,6 +23,11 @@ class BargainOrder extends Model public const ORDER_STATUS_START = 1; public const ORDER_STATUS_FINISHED = 2; + public function user() + { + return $this->belongsTo(User::class, 'user_id'); + } + public function logs() { return $this->hasMany(BargainOrderLog::class, 'order_id');