master
lion 5 days ago
parent 150d46b08b
commit cee071aa4e

@ -107,6 +107,9 @@ class SupplyDemandController extends CommonController
$query->select('id', 'nickname', 'name', 'headimgurl', 'username');
}
])->find($all['id']);
if (!$detail) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '供需信息不存在或已删除']);
}
// 增加view_count
$detail->increment('view_count');
$detail->save();
@ -237,6 +240,10 @@ class SupplyDemandController extends CommonController
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
// 无论是否已有会话,都禁止给自己发送消息。
if ((string) $all['to_user_id'] === (string) $this->getUserId()) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '不能给自己发信息']);
}
// 判断是否有会话,没有则创建
$dialogue = Dialogue::where(function ($query) use ($all) {
$query->where('user_id', $this->getUserId())->where('to_user_id', $all['to_user_id']);
@ -258,7 +265,7 @@ class SupplyDemandController extends CommonController
$now = date('Y-m-d');
// 过期数据不能私信
$supplyDemand = SupplyDemand::find($all['supply_demand_id']);
if (isset($supplyDemand->expire_time) && $supplyDemand->expire_time > $now) {
if (isset($supplyDemand->expire_time) && $supplyDemand->expire_time < date('Y-m-d H:i:s')) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '该信息已过期,不能私信']);
}
if ($dialogue->supply_demand_id != $all['supply_demand_id']) {
@ -273,7 +280,8 @@ class SupplyDemandController extends CommonController
$messageToday = Message::where('user_id', $this->getUserId())
->where('created_at', 'like', '%' . date('Y-m-d') . '%')
->get();
if ($messageToday->count() > $message_limit) {
// 未配置或非正数时不启用每日限额。
if (is_numeric($message_limit) && $message_limit > 0 && $messageToday->count() >= $message_limit) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '今天私信次数已达上限']);
}
// 有且仅有自己发的信息,则不能发再
@ -336,6 +344,9 @@ class SupplyDemandController extends CommonController
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
if ((string) $all['to_user_id'] === (string) $this->getUserId()) {
return $this->fail([ResponseCode::ERROR_BUSINESS, '不能给自己发信息']);
}
// 获取会话id
$dialogue = Dialogue::where(function ($query) use ($all) {
$query->where('user_id', $this->getUserId())->where('to_user_id', $all['to_user_id']);
@ -350,6 +361,7 @@ class SupplyDemandController extends CommonController
]);
}
$message = Message::with([
'supplyDemand',
'user' => function ($query) {
$query->select('id', 'nickname', 'name', 'headimgurl', 'username');
},
@ -360,7 +372,9 @@ class SupplyDemandController extends CommonController
$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'));
// 返回会话最近关联的信息,兼容从私信列表进入。
$supplyDemand = $dialogue->supplyDemand;
return $this->success(compact('message', 'supplyDemand'));
}
/**

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save