|
|
|
|
@ -223,6 +223,21 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
if (empty($model)) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '供需数据不存在']);
|
|
|
|
|
}
|
|
|
|
|
// 增加view_count
|
|
|
|
|
$model->increment('contact_count');
|
|
|
|
|
$model->save();
|
|
|
|
|
// 判断是否有会话,没有则创建
|
|
|
|
|
$dialogue = Dialogue::where('user_id', $this->getUserId())
|
|
|
|
|
->where('supply_demand_id', $all['supply_demand_id'])
|
|
|
|
|
->first();
|
|
|
|
|
if (empty($dialogue)) {
|
|
|
|
|
// 创建一条会话
|
|
|
|
|
$dialogue = Dialogue::create([
|
|
|
|
|
'user_id' => $this->getUserId(),
|
|
|
|
|
'to_user_id' => $model->user_id,
|
|
|
|
|
'supply_demand_id' => $all['supply_demand_id']
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
// 每天限制私信次数限制
|
|
|
|
|
$message_limit = Config::getValueByKey('message_limit');
|
|
|
|
|
$messageToday = Message::where('user_id', $this->getUserId())
|
|
|
|
|
@ -244,19 +259,17 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
}
|
|
|
|
|
// 创建消息
|
|
|
|
|
Message::create([
|
|
|
|
|
'dialogue_id' => $dialogue->id,
|
|
|
|
|
'user_id' => $this->getUserId(),
|
|
|
|
|
'to_user_id' => $all['to_user_id'],
|
|
|
|
|
'supply_demand_id' => $all['supply_demand_id'],
|
|
|
|
|
'content' => $all['content'],
|
|
|
|
|
'is_read' => 0
|
|
|
|
|
]);
|
|
|
|
|
// 增加view_count
|
|
|
|
|
$model->increment('contact_count');
|
|
|
|
|
$model->save();
|
|
|
|
|
// 创建会话
|
|
|
|
|
$where = [];
|
|
|
|
|
$data = [];
|
|
|
|
|
Dialogue::updateOrCreate([]);
|
|
|
|
|
// 更新会话最后发言
|
|
|
|
|
$dialogue->last_content = $all['content'];
|
|
|
|
|
$dialogue->last_datetime = date('Y-m-d H:i:s');
|
|
|
|
|
$dialogue->save();
|
|
|
|
|
return $this->success('删除成功');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -332,7 +345,7 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl');
|
|
|
|
|
}
|
|
|
|
|
])->where(function ($query) use ($all) {
|
|
|
|
|
|
|
|
|
|
$query->where('user_id',$this->getUserId())->orWhere('to_user_id',$this->getUserId());
|
|
|
|
|
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')
|
|
|
|
|
->paginate($all['page_size'] ?? 20);
|
|
|
|
|
return $this->success(compact('dialogue'));
|
|
|
|
|
|