diff --git a/app/Http/Controllers/Admin/SupplyDemandController.php b/app/Http/Controllers/Admin/SupplyDemandController.php index aeb55d0..2181644 100755 --- a/app/Http/Controllers/Admin/SupplyDemandController.php +++ b/app/Http/Controllers/Admin/SupplyDemandController.php @@ -196,7 +196,9 @@ class SupplyDemandController extends BaseController * description="", * @OA\Parameter(name="start_date", in="query", @OA\Schema(type="string"), required=true, description="开始日期"), * @OA\Parameter(name="end_date", in="query", @OA\Schema(type="string"), required=true, description="结束日期"), - * @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=true, description="type类型"), + * @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"), + * @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"), * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), * @OA\Response( * response="200", @@ -266,7 +268,18 @@ class SupplyDemandController extends BaseController $messageGrowthRate = $this->calculateGrowthRate($messageCount, $prevMessageCount); $interactionGrowthRate = $this->calculateGrowthRate($interactionCount, $prevInteractionCount); + // 当期供需发布分页 + $list = SupplyDemand::with(['user', 'messages' => function ($query) { + $query->with('user', 'toUser')->limit(2)->orderBy('created_at', 'desc'); + }])->where(function ($query) use ($type) { + if ($type) { + $query->where('type', $type); + } + })->whereBetween('created_at', [$startDate, $endDate]) + ->paginate($all['page_size'] ?? 20); + return $this->success([ + 'list' => $list, 'supply_demand_count' => $supplyDemandCount, 'prev_supply_demand_count' => $prevSupplyDemandCount, 'supply_demand_growth_rate' => $supplyDemandGrowthRate, diff --git a/app/Models/SupplyDemand.php b/app/Models/SupplyDemand.php index 947a3b2..b9c0860 100755 --- a/app/Models/SupplyDemand.php +++ b/app/Models/SupplyDemand.php @@ -17,6 +17,7 @@ class SupplyDemand extends SoftDeletesModel if (empty($this->file_ids)) return []; return Upload::whereIn('id', $this->file_ids)->get(); } + public function user() { return $this->hasOne(User::class, 'id', 'user_id'); @@ -27,5 +28,11 @@ class SupplyDemand extends SoftDeletesModel return $this->hasMany(SupplyDemandKeep::class, 'supply_demand_id', 'id'); } + + public function messages() + { + return $this->hasMany(Message::class, 'supply_demand_id', 'id'); + } + }