auth->id ?? -1; $page = $this->request->get('page', 1); $page_size = $this->request->get('pageSize', 10); $where = [ 'to_user_id' => $user_id ]; $unreadCount = MessageService::where($where + ['is_read' => CommonService::STATUS_OFF])->count(); $list = MessageService::getList($where, $page_size, 'id desc')->toArray(); $list['unread_count'] = $unreadCount; $this->success('', $list); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } /** * 详情 * @return void */ public function detail() { $user_id = $this->auth->id ?? -1; $id = $this->request->get('id', 0); $info = MessageService::getOne(['id' => $id, 'to_user_id' => $user_id]); $this->success('success', $info); } /** * @return void */ public function setRead() { try { $user_id = $this->auth->id ?? -1; $id = $this->request->post('id', 0); $isAll = $this->request->post('isAll', 0); $where = ['id' => $id, 'to_user_id' => $user_id]; if ($isAll) { unset($where['id']); } $res = MessageService::where($where)->update(['is_read' => CommonService::STATUS_ON]); if ($res === false) { exception('操作失败'); } $this->success('操作成功'); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } }