|
|
|
|
@ -48,7 +48,7 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
$supplyDemands = SupplyDemand::with([
|
|
|
|
|
'user' => function ($query) {
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl','username');
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl', 'username');
|
|
|
|
|
}
|
|
|
|
|
])->where(function ($query) use ($all) {
|
|
|
|
|
if (isset($all['type'])) {
|
|
|
|
|
@ -197,7 +197,7 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
* summary="发送消息",
|
|
|
|
|
* description="",
|
|
|
|
|
* @OA\Parameter(name="supply_demand_id", in="query", @OA\Schema(type="string"), required=true, description="供需信息id"),
|
|
|
|
|
* @OA\Parameter(name="supply_demand_id", in="query", @OA\Schema(type="string"), required=true, description="供需信息id(选填)"),
|
|
|
|
|
* @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), required=true, description="内容"),
|
|
|
|
|
* @OA\Parameter(name="to_user_id", in="query", @OA\Schema(type="string"), required=true, description="接收人用户id"),
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
@ -211,35 +211,30 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
{
|
|
|
|
|
$all = \request()->all();
|
|
|
|
|
$messages = [
|
|
|
|
|
'supply_demand_id.required' => '供需信息id必填',
|
|
|
|
|
'content.required' => '内容必填',
|
|
|
|
|
'to_user_id.required' => '接收人必填',
|
|
|
|
|
];
|
|
|
|
|
$validator = Validator::make($all, [
|
|
|
|
|
'supply_demand_id' => 'required',
|
|
|
|
|
'content' => 'required',
|
|
|
|
|
'to_user_id' => 'required'
|
|
|
|
|
], $messages);
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
}
|
|
|
|
|
$model = SupplyDemand::find($all['supply_demand_id']);
|
|
|
|
|
if (empty($model)) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '供需数据不存在']);
|
|
|
|
|
if (isset($all['supply_demand_id']) && !empty($all['supply_demand_id'])) {
|
|
|
|
|
// 增加view_count
|
|
|
|
|
SupplyDemand::where('id', $all['supply_demand_id'])->increment('view_count');
|
|
|
|
|
}
|
|
|
|
|
// 增加view_count
|
|
|
|
|
$model->increment('contact_count');
|
|
|
|
|
$model->save();
|
|
|
|
|
// 判断是否有会话,没有则创建
|
|
|
|
|
$dialogue = Dialogue::where('user_id', $this->getUserId())
|
|
|
|
|
->where('supply_demand_id', $all['supply_demand_id'])
|
|
|
|
|
->where('to_user_id', $all['to_user_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']
|
|
|
|
|
'to_user_id' => $all['to_user_id'],
|
|
|
|
|
'supply_demand_id' => $all['supply_demand_id'] ?? 0
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
// 每天限制私信次数限制
|
|
|
|
|
@ -252,11 +247,11 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
}
|
|
|
|
|
// 有且仅有自己发的信息,则不能发再
|
|
|
|
|
$myMessage = Message::where('user_id', $this->getUserId())
|
|
|
|
|
->where('supply_demand_id', $all['supply_demand_id'])
|
|
|
|
|
->where('to_user_id', $all['to_user_id'])
|
|
|
|
|
->first();
|
|
|
|
|
// 对方的信息
|
|
|
|
|
$otherMessage = Message::where('user_id', $all['to_user_id'])
|
|
|
|
|
->where('supply_demand_id', $all['supply_demand_id'])
|
|
|
|
|
->where('user_id', $this->getUserId())
|
|
|
|
|
->first();
|
|
|
|
|
if ($myMessage && empty($otherMessage)) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '对方回复以后才可以再次发送消息']);
|
|
|
|
|
@ -266,7 +261,7 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
'dialogue_id' => $dialogue->id,
|
|
|
|
|
'user_id' => $this->getUserId(),
|
|
|
|
|
'to_user_id' => $all['to_user_id'],
|
|
|
|
|
'supply_demand_id' => $all['supply_demand_id'],
|
|
|
|
|
'supply_demand_id' => $all['supply_demand_id'] ?? 0,
|
|
|
|
|
'content' => $all['content'],
|
|
|
|
|
'is_read' => 0
|
|
|
|
|
]);
|
|
|
|
|
@ -284,8 +279,7 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
* summary="消息列表",
|
|
|
|
|
* description="",
|
|
|
|
|
* @OA\Parameter(name="dialogue_id", in="query", @OA\Schema(type="string"), required=true, description="会话id(二选一)"),
|
|
|
|
|
* @OA\Parameter(name="supply_demand_id", in="query", @OA\Schema(type="string"), required=true, description="供需信息id(二选一)"),
|
|
|
|
|
* @OA\Parameter(name="to_user_id", in="query", @OA\Schema(type="string"), required=true, description="对方的用户id"),
|
|
|
|
|
* @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="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
|
|
@ -300,22 +294,31 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
public function messageList()
|
|
|
|
|
{
|
|
|
|
|
$all = \request()->all();
|
|
|
|
|
$messages = [
|
|
|
|
|
'to_user_id.required' => '接收人必填',
|
|
|
|
|
];
|
|
|
|
|
$validator = Validator::make($all, [
|
|
|
|
|
'to_user_id' => 'required'
|
|
|
|
|
], $messages);
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
}
|
|
|
|
|
// 获取会话id
|
|
|
|
|
$dialogue = Dialogue::where('user_id', $this->getUserId())
|
|
|
|
|
->where('to_user_id', $all['to_user_id'])
|
|
|
|
|
->first();
|
|
|
|
|
if (empty($dialogue)) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '会话不存在']);
|
|
|
|
|
}
|
|
|
|
|
$message = Message::with([
|
|
|
|
|
'user' => function ($query) {
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl','username');
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl', 'username');
|
|
|
|
|
},
|
|
|
|
|
'toUser' => function ($query) {
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl','username');
|
|
|
|
|
}
|
|
|
|
|
])->where(function ($query) use ($all) {
|
|
|
|
|
if (isset($all['dialogue_id'])) {
|
|
|
|
|
$query->where('dialogue_id', $all['dialogue_id']);
|
|
|
|
|
}
|
|
|
|
|
if (isset($all['supply_demand_id'])) {
|
|
|
|
|
$query->whereHas('dialogue', function ($query) use ($all) {
|
|
|
|
|
$query->where('supply_demand_id', $all['supply_demand_id']);
|
|
|
|
|
});
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl', 'username');
|
|
|
|
|
}
|
|
|
|
|
])->where(function ($query) use ($dialogue) {
|
|
|
|
|
$query->where('dialogue_id', $dialogue->id);
|
|
|
|
|
})->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')
|
|
|
|
|
->paginate($all['page_size'] ?? 20);
|
|
|
|
|
return $this->success(compact('message'));
|
|
|
|
|
@ -343,10 +346,10 @@ class SupplyDemandController extends CommonController
|
|
|
|
|
$all = \request()->all();
|
|
|
|
|
$dialogue = Dialogue::with(['supplyDemand',
|
|
|
|
|
'user' => function ($query) {
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl','username');
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl', 'username');
|
|
|
|
|
},
|
|
|
|
|
'toUser' => function ($query) {
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl','username');
|
|
|
|
|
$query->select('id', 'nickname', 'name', 'headimgurl', 'username');
|
|
|
|
|
}
|
|
|
|
|
])->where(function ($query) use ($all) {
|
|
|
|
|
$query->where('user_id', $this->getUserId())->orWhere('to_user_id', $this->getUserId());
|
|
|
|
|
|