request->post(['shareId', 'spm', 'page', 'query', 'from', 'platform']); // 验证参数 $validate = new ShareValidate(); if (!$validate->scene('add')->check($params)) { $this->error($validate->getError()); } $user = auth_user(); if (!$user) { $this->error('用户未登录'); } // 使用服务类添加分享记录 $shareInfo = ShareService::addShareLog($user->id, $params); if ($shareInfo) { $this->success('添加分享记录成功', $shareInfo); } else { $this->error('添加分享记录失败'); } } /** * 查看分享记录 */ public function index() { $user = auth_user(); $pageSize = $this->request->param('page_size', 10); $type = $this->request->param('type', 'received'); // received=我收到的分享, shared=我分享的 // 使用服务类获取分享记录 $logs = ShareService::getUserShareLogs($user->id, $pageSize, $type); $this->success('获取成功', $logs); } /** * 获取分享统计数据 */ public function stats() { $user = auth_user(); // 使用服务类获取分享统计 $stats = ShareService::getUserShareStats($user->id); $this->success('获取成功', $stats); } /** * 查看分享记录详情 */ public function detail() { $user = auth_user(); $shareLogId = $this->request->param('id/d'); if (!$shareLogId) { $this->error('参数错误'); } // 使用服务类获取分享详情 $shareLog = ShareService::getShareLogDetail($shareLogId, $user->id); if (!$shareLog) { $this->error('记录不存在或无权限访问'); } $this->success('获取成功', $shareLog); } }