|
|
|
|
@ -226,9 +226,11 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
SupplyDemand::where('id', $all['supply_demand_id'])->increment('view_count');
|
|
|
|
|
}
|
|
|
|
|
// 判断是否有会话,没有则创建
|
|
|
|
|
$dialogue = Dialogue::where('user_id', $this->getUserId())
|
|
|
|
|
->where('to_user_id', $all['to_user_id'])
|
|
|
|
|
->first();
|
|
|
|
|
$dialogue = Dialogue::where(function ($query) use ($all) {
|
|
|
|
|
$query->where('user_id', $this->getUserId())->where('to_user_id', $all['to_user_id']);
|
|
|
|
|
})->orWhere(function ($query) use ($all) {
|
|
|
|
|
$query->where('user_id', $all['to_user_id'])->where('to_user_id', $this->getUserId());
|
|
|
|
|
})->first();
|
|
|
|
|
if (empty($dialogue)) {
|
|
|
|
|
// 创建一条会话
|
|
|
|
|
$dialogue = Dialogue::create([
|
|
|
|
|
@ -248,10 +250,12 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
// 有且仅有自己发的信息,则不能发再
|
|
|
|
|
$myMessage = Message::where('user_id', $this->getUserId())
|
|
|
|
|
->where('to_user_id', $all['to_user_id'])
|
|
|
|
|
->where('dialogue_id', $dialogue->id)
|
|
|
|
|
->first();
|
|
|
|
|
// 对方的信息
|
|
|
|
|
$otherMessage = Message::where('user_id', $all['to_user_id'])
|
|
|
|
|
->where('user_id', $this->getUserId())
|
|
|
|
|
->where('dialogue_id', $dialogue->id)
|
|
|
|
|
->first();
|
|
|
|
|
if ($myMessage && empty($otherMessage)) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '对方回复以后才可以再次发送消息']);
|
|
|
|
|
|