diff --git a/app/Models/Dialogue.php b/app/Models/Dialogue.php new file mode 100644 index 0000000..19b3fd0 --- /dev/null +++ b/app/Models/Dialogue.php @@ -0,0 +1,22 @@ +hasOne(User::class, 'id', 'user_id'); + } + + public function toUser() + { + return $this->hasOne(User::class, 'id', 'to_user_id'); + } + + public function supplyDemand(){ + return $this->hasOne(SupplyDemand::class, 'id', 'supply_demand_id'); + } + +} diff --git a/app/Models/Message.php b/app/Models/Message.php index 3c7c290..46564f8 100755 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -19,5 +19,9 @@ class Message extends SoftDeletesModel return $this->hasOne(User::class, 'id', 'to_user_id'); } + public function supplyDemand(){ + return $this->hasOne(SupplyDemand::class, 'id', 'supply_demand_id'); + } + } diff --git a/database/migrations/2025_06_20_101705_create_messages_table.php b/database/migrations/2025_06_20_101705_create_messages_table.php index 28d1305..13296ef 100644 --- a/database/migrations/2025_06_20_101705_create_messages_table.php +++ b/database/migrations/2025_06_20_101705_create_messages_table.php @@ -15,6 +15,7 @@ return new class extends Migration { Schema::create('messages', function (Blueprint $table) { $table->comment('消息表'); $table->id(); + $table->integer('dialogue_id')->nullable()->comment('对话id'); // 用户id $table->integer('user_id')->nullable()->comment('用户id'); // 接收人id diff --git a/database/migrations/2025_06_25_132911_alert_dialogues_table.php b/database/migrations/2025_06_25_132911_alert_dialogues_table.php new file mode 100644 index 0000000..1329df9 --- /dev/null +++ b/database/migrations/2025_06_25_132911_alert_dialogues_table.php @@ -0,0 +1,43 @@ +comment('会话列表'); + $table->id(); + // 用户id + $table->integer('user_id')->nullable()->comment('用户id'); + // 接收人id + $table->integer('to_user_id')->nullable()->comment('接收人id'); + // 需求id + $table->integer('supply_demand_id')->nullable()->comment('需求id'); + // 消息内容 + $table->text('last_content')->nullable()->comment('最后一条消息消息内容'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('dialogues', function (Blueprint $table) { + // + }); + } +}; diff --git a/routes/api.php b/routes/api.php index 3604d3d..87cce0b 100755 --- a/routes/api.php +++ b/routes/api.php @@ -250,9 +250,13 @@ Route::group(["namespace" => "Mobile", "prefix" => "mobile"], function () { Route::get('supply-demand/detail', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "detail"]); Route::post('supply-demand/save', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "save"]); Route::get('supply-demand/destroy', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "destroy"]); + // 供需信息留言 Route::get('supply-demand/send-message', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "sendMessage"]); Route::get('supply-demand/message-list', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "messageList"]); + Route::get('supply-demand/message-list', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "messageList"]); + + // 供需信息收藏 Route::get('supply-demand/keep-index', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "keepIndex"]); Route::get('supply-demand/keep-supply-demand', [\App\Http\Controllers\Mobile\SupplyDemandController::class, "keepSupplyDemand"]);