api.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. /**
  2. * API 接口配置文件
  3. */
  4. // 开发环境和生产环境的 API 基础地址
  5. // 所有请求通过网关转发
  6. const BASE_URL = process.env.NODE_ENV === 'development'
  7. ? 'https://api.zhongruanke.cn/api' // 开发环境 - 通过网关
  8. : 'https://api.zhongruanke.cn/api' // 生产环境
  9. /**
  10. * 封装 uni.request
  11. */
  12. const request = (options) => {
  13. return new Promise((resolve, reject) => {
  14. const token = uni.getStorageSync('token')
  15. const headers = {
  16. 'Content-Type': 'application/json'
  17. }
  18. if (token) {
  19. headers['Authorization'] = token
  20. }
  21. uni.request({
  22. url: (/^https?:\/\//.test(options.url) ? options.url : (BASE_URL + options.url)),
  23. method: options.method || 'GET',
  24. data: options.data || {},
  25. header: headers,
  26. dataType: 'json',
  27. success: (res) => {
  28. if (res.statusCode === 200) {
  29. // 根据后端约定的数据格式处理
  30. if (res.data.code === 200 || res.data.code === 0 || res.data.success) {
  31. resolve(res.data.data || res.data)
  32. } else if (res.data.code === 403) {
  33. // 业务层面的403错误,清除token并跳转登录
  34. uni.removeStorageSync('token')
  35. uni.removeStorageSync('userInfo')
  36. uni.showToast({
  37. title: res.data.message || res.data.msg || '拒绝访问,请重新登录',
  38. icon: 'none'
  39. })
  40. uni.navigateTo({
  41. url: '/pages/page3/page3'
  42. })
  43. reject(res.data)
  44. } else {
  45. uni.showToast({
  46. title: res.data.message || res.data.msg || '请求失败',
  47. icon: 'none'
  48. })
  49. reject(res.data)
  50. }
  51. } else if (res.statusCode === 401) {
  52. // 未授权,跳转登录
  53. uni.removeStorageSync('token')
  54. uni.removeStorageSync('userInfo')
  55. uni.showToast({
  56. title: '未授权,请重新登录',
  57. icon: 'none'
  58. })
  59. uni.navigateTo({
  60. url: '/pages/page3/page3'
  61. })
  62. reject(res)
  63. } else if (res.statusCode === 403) {
  64. // 拒绝访问,清除token并跳转登录
  65. uni.removeStorageSync('token')
  66. uni.removeStorageSync('userInfo')
  67. uni.showToast({
  68. title: '拒绝访问,请重新登录',
  69. icon: 'none'
  70. })
  71. uni.navigateTo({
  72. url: '/pages/page3/page3'
  73. })
  74. reject(res)
  75. } else {
  76. uni.showToast({
  77. title: '网络请求失败',
  78. icon: 'none'
  79. })
  80. reject(res)
  81. }
  82. },
  83. fail: (err) => {
  84. console.error('API请求失败:', options.url, '错误信息:', err)
  85. uni.showToast({
  86. title: (err && err.errMsg) ? err.errMsg.replace('request:','') : '网络连接失败',
  87. icon: 'none'
  88. })
  89. reject(err)
  90. }
  91. })
  92. })
  93. }
  94. /**
  95. * API 接口列表
  96. */
  97. export default {
  98. // 地区
  99. area: {
  100. // 获取省份列表
  101. getProvinces: () => request({ url: '/recommend/area/provinces' }),
  102. // 获取城市列表(可选省份ID)
  103. getCities: (provinceId) => {
  104. const url = provinceId ? `/recommend/area/cities?provinceId=${provinceId}` : '/recommend/area/cities'
  105. return request({ url })
  106. },
  107. // 获取区域列表(根据城市ID)
  108. getAreas: (cityId) => request({ url: `/recommend/area/areas?cityId=${cityId}` })
  109. },
  110. // 用户相关
  111. user: {
  112. // 获取用户信息
  113. getInfo: () => request({ url: '/user/info' }),
  114. // 获取指定用户的详细信息(包含简介和照片)
  115. getDetailInfo: (userId) => request({
  116. url: `/user/info?userId=${userId}`
  117. }),
  118. // 查询用户是否为红娘
  119. getMatchmakerStatus: (userId) => request({
  120. url: `/user/matchmaker-status?userId=${userId}`
  121. }),
  122. // 获取今日匹配数
  123. getMatchCount: () => request({ url: '/user/match-count' }),
  124. // 更新用户基本信息(昵称、头像等)
  125. updateInfo: (data) => request({
  126. url: '/user/basic',
  127. method: 'PUT',
  128. data
  129. }),
  130. // 更新单个字段
  131. updateField: (userId, fieldName, fieldValue) => request({
  132. url: `/user/basic/field?userId=${userId}&fieldName=${fieldName}&fieldValue=${encodeURIComponent(fieldValue)}`,
  133. method: 'PUT'
  134. })
  135. },
  136. // 认证相关
  137. auth: {
  138. // 密码登录(手机号+密码)
  139. loginByPassword: (phone, password) => request({
  140. // 直连 login 服务(开发环境),避免网关未配置导致未路由
  141. url: 'http://localhost:8087/api/login/password',
  142. method: 'POST',
  143. data: { phone, password }
  144. }),
  145. // 发送登录验证码(走网关 -> 登录服务)
  146. sendCode: (phone) => request({
  147. url: '/login/send-code',
  148. method: 'POST',
  149. data: { phone }
  150. }),
  151. // 验证码登录(走网关 -> 登录服务)
  152. smsLogin: (phone, code) => request({
  153. url: '/login/sms-login',
  154. method: 'POST',
  155. data: { phone, code }
  156. }),
  157. // 微信登录(直连 login 服务)
  158. wechatLogin: (data) => request({
  159. url: 'https://api.zhongruanke.cn/api/login/wechat/login',
  160. method: 'POST',
  161. data: data // ✅ 传递完整的登录数据对象(包含code, nickname, avatarUrl, phoneCode)
  162. }),
  163. // 获取微信手机号(直连 login 服务)
  164. wechatPhone: (code) => request({
  165. url: 'https://api.zhongruanke.cn/api/login/wechat/phone',
  166. method: 'POST',
  167. data: { code }
  168. })
  169. },
  170. // 首页相关
  171. home: {
  172. // 获取轮播图
  173. getBanners: () => request({ url: '/home/banners' }),
  174. // 获取公告列表
  175. getNotices: () => request({ url: '/announcement/active' }),
  176. // 获取首页金刚区功能列表
  177. getFunctionGrid: () => request({ url: '/home/function-grid' }),
  178. // 根据类型获取金刚区功能列表
  179. getFunctionGridByType: (type) => request({ url: `/home/function-grid/type?type=${type}` }),
  180. // 获取未读消息数
  181. getUnreadCount: () => request({ url: '/home/unread-count' })
  182. },
  183. // 成功案例
  184. successCase: {
  185. // 获取成功案例列表
  186. getList: (params) => request({
  187. url: '/success-case/list',
  188. method: 'GET',
  189. data: params
  190. }),
  191. // 获取成功案例详情
  192. getDetail: (caseNo) => request({
  193. url: `/success-case/detail/${caseNo}`,
  194. method: 'GET'
  195. }),
  196. // 获取案例时间线
  197. getTimeline: (caseNo) => request({
  198. url: `/success-case/timeline/${caseNo}`,
  199. method: 'GET'
  200. })
  201. },
  202. // 活动相关
  203. activity: {
  204. // 获取活动列表
  205. getList: (params) => request({
  206. url: '/activity/list',
  207. method: 'GET',
  208. data: params
  209. }),
  210. // 获取活动详情
  211. getDetail: (id) => request({
  212. url: `/activity/detail/${id}`,
  213. method: 'GET'
  214. }),
  215. // 报名活动
  216. register: (activityId, userId) => request({
  217. url: `/activity/register/${activityId}?userId=${userId}`,
  218. method: 'POST'
  219. }),
  220. // 取消报名
  221. cancelRegister: (activityId) => request({
  222. url: `/activity/cancel/${activityId}`,
  223. method: 'POST'
  224. }),
  225. // 获取我的活动列表
  226. getMyActivities: (params) => request({
  227. url: '/activity/my',
  228. method: 'GET',
  229. data: params
  230. }),
  231. // 创建活动订单并获取支付参数
  232. createOrder: (userId, activityId, activityName, price) => request({
  233. url: '/activity-order/create',
  234. method: 'POST',
  235. data: {
  236. userId,
  237. activityId,
  238. activityName,
  239. price
  240. }
  241. })
  242. },
  243. // 课程相关
  244. course: {
  245. // 获取课程列表
  246. getList: (params) => request({
  247. url: '/course/list',
  248. method: 'GET',
  249. data: params
  250. }),
  251. // 获取课程详情(带学习进度)
  252. getDetail: (courseId, makerId) => request({
  253. url: `/course/detail/${courseId}${makerId ? '?makerId=' + makerId : ''}`,
  254. method: 'GET'
  255. }),
  256. // 更新学习进度
  257. updateProgress: (makerId, courseId, progress) => request({
  258. url: '/course/progress',
  259. method: 'POST',
  260. data: { makerId, courseId, progress }
  261. }),
  262. // 完成课程(领取积分)
  263. complete: (makerId, courseId) => request({
  264. url: '/course/complete',
  265. method: 'POST',
  266. data: { makerId, courseId }
  267. }),
  268. // 获取我的学习记录
  269. getMyProgress: (makerId) => request({
  270. url: `/course/my-progress?makerId=${makerId}`,
  271. method: 'GET'
  272. }),
  273. // 购买课程(旧接口-模拟)
  274. purchase: (courseId, data) => request({
  275. url: `/course/purchase/${courseId}`,
  276. method: 'POST',
  277. data
  278. }),
  279. // 积分兑换课程(红娘端 - 旧接口,已废弃)
  280. exchange: (data) => request({
  281. url: '/course/exchange',
  282. method: 'POST',
  283. data
  284. }),
  285. // 获取已兑换的课程列表(红娘端 - 旧接口,已废弃)
  286. getPurchasedList: (makerId) => request({
  287. url: `/course/purchased?makerId=${makerId}`,
  288. method: 'GET'
  289. })
  290. },
  291. // 红娘课程相关(独立于用户课程)
  292. matchmakerCourse: {
  293. // 获取红娘课程列表
  294. getList: (params = {}) => request({
  295. url: '/matchmaker-course/list',
  296. method: 'GET',
  297. data: params
  298. }),
  299. // 根据分类获取红娘课程列表
  300. getListByCategory: (categoryName) => request({
  301. url: `/matchmaker-course/list/category?categoryName=${encodeURIComponent(categoryName)}`,
  302. method: 'GET'
  303. }),
  304. // 获取所有课程分类
  305. getCategories: () => request({
  306. url: '/matchmaker-course/categories',
  307. method: 'GET'
  308. }),
  309. // 获取红娘课程详情
  310. getDetail: (id) => request({
  311. url: `/matchmaker-course/detail/${id}`,
  312. method: 'GET'
  313. }),
  314. // 检查是否已兑换
  315. checkExchanged: (makerId, courseId) => request({
  316. url: `/matchmaker-course/check-exchanged?makerId=${makerId}&courseId=${courseId}`,
  317. method: 'GET'
  318. }),
  319. // 积分兑换课程
  320. exchange: (data) => request({
  321. url: '/matchmaker-course/exchange',
  322. method: 'POST',
  323. data
  324. }),
  325. // 获取已兑换的课程列表
  326. getPurchasedList: (makerId) => request({
  327. url: `/matchmaker-course/purchased?makerId=${makerId}`,
  328. method: 'GET'
  329. })
  330. },
  331. // 课程订单相关(微信支付)
  332. courseOrder: {
  333. // 购买课程(获取微信支付参数)
  334. purchase: (data) => request({
  335. url: '/course-order/purchase',
  336. method: 'POST',
  337. data
  338. }),
  339. // 检查是否已购买课程
  340. checkPurchased: (userId, courseId) => request({
  341. url: `/course-order/check?userId=${userId}&courseId=${courseId}`,
  342. method: 'GET'
  343. }),
  344. // 获取已购买的课程列表
  345. getPurchasedCourses: (userId) => request({
  346. url: `/course-order/purchased?userId=${userId}`,
  347. method: 'GET'
  348. })
  349. },
  350. // 红娘相关
  351. matchmaker: {
  352. // 获取红娘列表
  353. getList: (params) => request({
  354. url: '/matchmaker/list',
  355. method: 'POST',
  356. data: params
  357. }),
  358. // 获取全职红娘列表
  359. getFormalList: (pageNum, pageSize) => request({
  360. url: `/matchmaker/formal?pageNum=${pageNum}&pageSize=${pageSize}`
  361. }),
  362. // 获取红娘详情
  363. getDetail: (id) => request({
  364. url: `/matchmaker/detail/${id}`
  365. }),
  366. // 根据userId查询红娘信息
  367. getByUserId: (userId) => request({
  368. url: `/matchmaker/by-user/${userId}`
  369. }),
  370. // 预约红娘
  371. book: (matchmakerId, data) => request({
  372. url: `/matchmaker/book/${matchmakerId}`,
  373. method: 'POST',
  374. data
  375. }),
  376. // 提交红娘申请
  377. submitApply: (data) => request({
  378. url: '/matchmaker-apply/submit',
  379. method: 'POST',
  380. data
  381. }),
  382. // 查询红娘申请状态
  383. getApplyStatus: (userId) => request({
  384. url: `/matchmaker-apply/status?userId=${userId}`,
  385. method: 'GET'
  386. }),
  387. // 工作台相关
  388. getWorkbenchData: () => request({ url: '/matchmaker/workbench/data' }),
  389. // 获取我的资源
  390. getMyResources: (params) => request({
  391. url: '/matchmaker/resources',
  392. method: 'GET',
  393. data: params
  394. }),
  395. // 获取排行榜数据(总排行榜)
  396. getRankingData: (params) => request({
  397. url: '/matchmaker/ranking',
  398. method: 'GET',
  399. data: params
  400. }),
  401. // 获取本周排行榜(按点赞数和成功人数平均数排名)
  402. getWeeklyRanking: (params) => request({
  403. url: '/matchmaker/weekly-ranking',
  404. method: 'GET',
  405. data: params
  406. }),
  407. // 给红娘点赞(一周只能给同一红娘点赞一次)
  408. likeMatchmaker: (userId, matchmakerId) => request({
  409. url: `/matchmaker/like?userId=${userId}&matchmakerId=${matchmakerId}`,
  410. method: 'POST'
  411. }),
  412. // 检查是否已点赞
  413. checkLikeStatus: (userId, matchmakerId) => request({
  414. url: `/matchmaker/check-like?userId=${userId}&matchmakerId=${matchmakerId}`,
  415. method: 'GET'
  416. }),
  417. // 签到相关
  418. checkinStatus: (makerId) => request({
  419. url: `/matchmaker/checkin/status?makerId=${makerId}`
  420. }),
  421. checkinStats: (makerId) => request({
  422. url: `/matchmaker/checkin/stats?makerId=${makerId}`
  423. }),
  424. doCheckin: (makerId) => request({
  425. url: `/matchmaker/checkin/do?makerId=${makerId}`,
  426. method: 'POST'
  427. }),
  428. // 获取签到信息,包括当月已签到日期
  429. checkinInfo: (makerId, year, month) => request({
  430. url: `/matchmaker/checkin/info?makerId=${makerId}&year=${year}&month=${month}`
  431. }),
  432. // 更新红娘资料(编辑资料页使用)
  433. updateProfile: (matchmakerId, data) => request({
  434. url: `/matchmaker/update/${matchmakerId}`,
  435. method: 'PUT',
  436. data
  437. }),
  438. // 获取本月签到记录
  439. checkinList: (makerId, year, month) => request({
  440. url: `/matchmaker/checkin/list?makerId=${makerId}&year=${year}&month=${month}`
  441. })
  442. },
  443. // 推荐相关
  444. recommend: {
  445. // 获取推荐用户列表(网关转发到推荐服务)
  446. getUsers: ({ userId, oppoOnly = 1, limit = 20, excludeIds }) => {
  447. let url = `/recommend/users?userId=${userId}&oppoOnly=${oppoOnly}&limit=${limit}`;
  448. if (excludeIds) {
  449. url += `&excludeIds=${excludeIds}`;
  450. }
  451. return request({ url });
  452. },
  453. // 行为反馈:like/dislike
  454. feedback: ({ userId, targetUserId, type }) => request({
  455. url: `/recommend/feedback?userId=${userId}&targetUserId=${targetUserId}&type=${type}`
  456. }),
  457. // 曝光上报
  458. exposure: ({ userId, shownUserIds }) => request({
  459. url: `/recommend/exposure?userId=${userId}&shownUserIds=${encodeURIComponent(shownUserIds)}`
  460. }),
  461. // 规则检索
  462. search: (query) => request({
  463. url: '/recommend/search',
  464. method: 'POST',
  465. data: query
  466. }),
  467. // 获取今日推荐
  468. getTodayRecommend: () => request({
  469. url: '/recommend/today'
  470. }),
  471. // 获取用户喜欢的列表
  472. getLikedUsers: (userId, limit, offset) => request({
  473. url: `/recommend/liked-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  474. }),
  475. // 获取用户喜欢的用户数量
  476. getLikedUsersCount: (userId) => request({
  477. url: `/recommend/liked-users-count?userId=${userId}`
  478. }),
  479. // 获取喜欢我的用户列表
  480. getLikedMeUsers: (userId, limit, offset) => request({
  481. url: `/recommend/liked-me-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  482. }),
  483. // 获取喜欢我的用户数量
  484. getLikedMeUsersCount: (userId) => request({
  485. url: `/recommend/liked-me-users-count?userId=${userId}`
  486. }),
  487. // 保存用户浏览记录
  488. saveUserLook: (userId, lookUserId) => request({
  489. url: `/recommend/save-look?userId=${userId}&lookUserId=${lookUserId}`,
  490. method: 'POST'
  491. }),
  492. // 获取用户浏览记录列表
  493. getBrowseHistory: (userId, limit, offset) => request({
  494. url: `/recommend/browse-history?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  495. }),
  496. // 获取用户浏览记录数量
  497. getBrowseHistoryCount: (userId) => request({
  498. url: `/recommend/browse-history-count?userId=${userId}`
  499. })
  500. },
  501. // 消息相关
  502. message: {
  503. // 获取消息列表
  504. getList: (params) => request({
  505. url: '/message/list',
  506. data: params
  507. }),
  508. // 获取会话列表
  509. getConversations: () => request({
  510. url: '/message/conversations'
  511. }),
  512. // 发送消息
  513. send: (data) => request({
  514. url: '/message/send',
  515. method: 'POST',
  516. data
  517. }),
  518. // ===== 系统消息 =====
  519. getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
  520. const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
  521. // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
  522. return res.data || res
  523. },
  524. getSystemUnreadCount: async (userId) => {
  525. const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
  526. return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
  527. },
  528. markSystemRead: (id) => request({
  529. url: `/message/system/read/${id}`,
  530. method: 'POST'
  531. }),
  532. getSystemDetail: async (id) => {
  533. const res = await request({ url: `/message/system/detail/${id}` })
  534. return res.data || res
  535. },
  536. markAllSystemRead: (userId) => request({
  537. url: `/message/system/read-all?userId=${userId}`,
  538. method: 'POST'
  539. })
  540. },
  541. // 动态相关
  542. dynamic: {
  543. // 获取推荐动态列表(广场)
  544. getRecommendList: (params) => request({
  545. url: '/dynamic/recommend',
  546. data: params
  547. }),
  548. // 获取动态列表
  549. getList: (params) => request({
  550. url: '/dynamic/list',
  551. data: params
  552. }),
  553. // 获取动态详情
  554. getDetail: (dynamicId, userId) => request({
  555. url: `/dynamic/detail/${dynamicId}`,
  556. data: { userId }
  557. }),
  558. // 发表评论
  559. addComment: (dynamicId, content, images, parentCommentId = 0) => request({
  560. url: `/dynamic/comment`,
  561. method: 'POST',
  562. data: { dynamicId, content, images, parentCommentId, userId: 1 },
  563. header: { 'Content-Type': 'application/json' }
  564. }),
  565. // 评论列表
  566. getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
  567. url: `/dynamic/comment/list/${dynamicId}`,
  568. data: { pageNum, pageSize }
  569. }),
  570. // 评论点赞/取消
  571. likeComment: (commentId, userId) => {
  572. // 如果没有传入userId,从本地存储获取
  573. if (!userId) {
  574. const userInfo = uni.getStorageSync('userInfo');
  575. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  576. }
  577. if (!userId) {
  578. return Promise.reject(new Error('用户未登录'));
  579. }
  580. return request({
  581. url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
  582. method: 'POST'
  583. });
  584. },
  585. unlikeComment: (commentId, userId) => {
  586. // 如果没有传入userId,从本地存储获取
  587. if (!userId) {
  588. const userInfo = uni.getStorageSync('userInfo');
  589. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  590. }
  591. if (!userId) {
  592. return Promise.reject(new Error('用户未登录'));
  593. }
  594. return request({
  595. url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
  596. method: 'DELETE'
  597. });
  598. },
  599. // 获取用户动态列表
  600. getUserDynamics: (userId, params) => {
  601. const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
  602. let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
  603. if (currentUserId) {
  604. url += `&currentUserId=${currentUserId}`
  605. }
  606. return request({
  607. url: url,
  608. method: 'GET'
  609. })
  610. },
  611. // 点赞动态
  612. like: (dynamicId, userId) => {
  613. // 如果没有传入userId,从本地存储获取
  614. if (!userId) {
  615. const userInfo = uni.getStorageSync('userInfo');
  616. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  617. }
  618. if (!userId) {
  619. return Promise.reject(new Error('用户未登录'));
  620. }
  621. return request({
  622. url: `/dynamic/like?dynamicId=${dynamicId}&userId=${userId}`,
  623. method: 'POST'
  624. });
  625. },
  626. // 取消点赞
  627. unlike: (dynamicId, userId) => {
  628. // 如果没有传入userId,从本地存储获取
  629. if (!userId) {
  630. const userInfo = uni.getStorageSync('userInfo');
  631. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  632. }
  633. if (!userId) {
  634. return Promise.reject(new Error('用户未登录'));
  635. }
  636. return request({
  637. url: `/dynamic/like/${dynamicId}?userId=${userId}`,
  638. method: 'DELETE'
  639. });
  640. },
  641. // 收藏动态
  642. favorite: (dynamicId, userId) => {
  643. // 如果没有传入userId,从本地存储获取
  644. if (!userId) {
  645. const userInfo = uni.getStorageSync('userInfo');
  646. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  647. }
  648. if (!userId) {
  649. return Promise.reject(new Error('用户未登录'));
  650. }
  651. return request({
  652. url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
  653. method: 'POST'
  654. });
  655. },
  656. // 取消收藏
  657. unfavorite: (dynamicId, userId) => {
  658. // 如果没有传入userId,从本地存储获取
  659. if (!userId) {
  660. const userInfo = uni.getStorageSync('userInfo');
  661. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  662. }
  663. if (!userId) {
  664. return Promise.reject(new Error('用户未登录'));
  665. }
  666. return request({
  667. url: `/dynamic/favorite/${dynamicId}?userId=${userId}`,
  668. method: 'DELETE'
  669. });
  670. },
  671. // 创建个人动态
  672. createUserDynamic: (payload) => request({
  673. url: '/dynamic/user',
  674. method: 'POST',
  675. data: payload,
  676. header: { 'Content-Type': 'application/json' }
  677. }),
  678. // 更新个人动态
  679. updateUserDynamic: (dynamicId, userId, payload) => request({
  680. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  681. method: 'PUT',
  682. data: payload,
  683. header: { 'Content-Type': 'application/json' }
  684. }),
  685. // 删除个人动态
  686. deleteUserDynamic: (dynamicId, userId) => request({
  687. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  688. method: 'DELETE'
  689. }),
  690. // 删除动态(旧接口,保留兼容)
  691. delete: (dynamicId) => request({
  692. url: `/dynamic/${dynamicId}`,
  693. method: 'DELETE'
  694. }),
  695. // 发布动态(文本或已存在的媒体URL列表)
  696. publish: (payload) => request({
  697. url: '/dynamic/publish',
  698. method: 'POST',
  699. data: payload,
  700. header: { 'Content-Type': 'application/json' }
  701. }),
  702. // 单个文件上传方法
  703. uploadSingle: (filePath) => {
  704. return new Promise((resolve, reject) => {
  705. uni.uploadFile({
  706. url: BASE_URL + '/dynamic/publish/upload',
  707. filePath: filePath,
  708. name: 'file',
  709. success: (res) => {
  710. try {
  711. const data = JSON.parse(res.data)
  712. if (data.code === 200 || data.code === 0 || data.success) {
  713. resolve(data.data)
  714. } else {
  715. console.error('上传失败,服务器返回错误:', data)
  716. reject(new Error(data.message || '上传失败'))
  717. }
  718. } catch (e) {
  719. console.error('解析响应数据失败:', e, '原始响应:', res.data)
  720. reject(new Error('解析响应数据失败'))
  721. }
  722. },
  723. fail: (error) => {
  724. console.error('上传请求失败:', error)
  725. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  726. }
  727. })
  728. })
  729. },
  730. // 批量上传多个文件(遍历调用单个上传)
  731. uploadBatch: (filePaths) => {
  732. return new Promise(async (resolve, reject) => {
  733. const urls = []
  734. try {
  735. for (let filePath of filePaths) {
  736. const url = await new Promise((resolveUpload, rejectUpload) => {
  737. uni.uploadFile({
  738. url: BASE_URL + '/dynamic/publish/upload',
  739. filePath: filePath,
  740. name: 'file',
  741. success: (res) => {
  742. try {
  743. const data = JSON.parse(res.data)
  744. if (data.code === 200 || data.code === 0 || data.success) {
  745. resolveUpload(data.data)
  746. } else {
  747. rejectUpload(data)
  748. }
  749. } catch (e) {
  750. rejectUpload(e)
  751. }
  752. },
  753. fail: rejectUpload
  754. })
  755. })
  756. urls.push(url)
  757. }
  758. resolve(urls)
  759. } catch (e) {
  760. reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
  761. }
  762. })
  763. },
  764. // 提交举报
  765. submitReport: (data) => request({
  766. url: '/dynamic/report',
  767. method: 'POST',
  768. data
  769. }),
  770. // 获取用户收藏列表
  771. getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
  772. url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  773. }),
  774. // 获取用户点赞列表
  775. getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
  776. url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  777. }),
  778. // 获取用户浏览记录列表
  779. getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
  780. url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  781. }),
  782. // 清空用户浏览记录
  783. clearBrowseHistory: (userId) => request({
  784. url: `/dynamic/browse-history?userId=${userId}`,
  785. method: 'DELETE'
  786. })
  787. },
  788. // VIP相关
  789. vip: {
  790. // 获取VIP信息(状态、套餐等)
  791. getInfo: (userId) => request({
  792. url: `/vip/info?userId=${userId}`
  793. }),
  794. // 获取VIP套餐列表
  795. getPackages: () => request({
  796. url: '/vip/packages'
  797. }),
  798. // 购买VIP套餐(获取支付参数)
  799. purchase: (userId, packageId) => request({
  800. url: '/vip/purchase',
  801. method: 'POST',
  802. data: { userId, packageId }
  803. }),
  804. // 查询订单状态
  805. getOrderStatus: (orderNo) => request({
  806. url: `/vip/order/status?orderNo=${orderNo}`
  807. }),
  808. // 新增:查询支付状态(userId + packageId)
  809. checkPayStatus: (userId, packageId) => request({
  810. url: '/vip/checkPayStatus',
  811. method: 'GET',
  812. data: { userId, packageId }
  813. })
  814. },
  815. // 用户反馈
  816. feedback: {
  817. // 提交用户反馈
  818. submit: (data) => request({
  819. url: '/feedback/submit',
  820. method: 'POST',
  821. data
  822. }),
  823. // 上传反馈图片
  824. uploadImage: (filePath) => {
  825. return new Promise((resolve, reject) => {
  826. uni.uploadFile({
  827. url: BASE_URL + '/feedback/upload',
  828. filePath: filePath,
  829. name: 'file',
  830. success: (res) => {
  831. try {
  832. const data = JSON.parse(res.data)
  833. if (data.code === 200 || data.code === 0 || data.success) {
  834. resolve(data.data)
  835. } else {
  836. reject(new Error(data.message || '上传失败'))
  837. }
  838. } catch (e) {
  839. reject(new Error('解析响应数据失败'))
  840. }
  841. },
  842. fail: (error) => {
  843. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  844. }
  845. })
  846. })
  847. }
  848. },
  849. // 积分商城相关
  850. pointsMall: {
  851. // 获取商品列表
  852. getProducts: (params) => request({
  853. url: '/points/products',
  854. method: 'GET',
  855. data: params
  856. }),
  857. // 获取推荐商品
  858. getRecommendProducts: (limit = 10) => request({
  859. url: `/points/products/recommend?limit=${limit}`,
  860. method: 'GET'
  861. }),
  862. // 获取商品详情
  863. getProductDetail: (id) => request({
  864. url: `/points/products/${id}`,
  865. method: 'GET'
  866. }),
  867. // 获取积分余额
  868. getBalance: (makerId) => request({
  869. url: `/points/balance?makerId=${makerId}`,
  870. method: 'GET'
  871. }),
  872. // 获取积分明细
  873. getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
  874. url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
  875. method: 'GET'
  876. }),
  877. // 获取积分规则
  878. getRules: () => request({
  879. url: '/points/rules',
  880. method: 'GET'
  881. }),
  882. // 兑换商品
  883. exchange: (data) => request({
  884. url: '/points/exchange',
  885. method: 'POST',
  886. data
  887. }),
  888. // 获取订单列表
  889. getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
  890. let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  891. if (status !== undefined && status !== null) {
  892. url += `&status=${status}`
  893. }
  894. return request({ url, method: 'GET' })
  895. },
  896. // 获取订单详情
  897. getOrderDetail: (orderNo) => request({
  898. url: `/points/orders/${orderNo}`,
  899. method: 'GET'
  900. }),
  901. // 增加积分(签到等)
  902. addPoints: (makerId, ruleType, reason) => request({
  903. url: '/points/add',
  904. method: 'POST',
  905. data: { makerId, ruleType, reason }
  906. })
  907. },
  908. // 我的资源相关(通过网关访问8081服务)
  909. myResource: {
  910. // 获取资源列表
  911. getList: (matchmakerId, keyword, pageNum = 1, pageSize = 10) => {
  912. let url = `/my-resource/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  913. if (keyword) {
  914. url += `&keyword=${encodeURIComponent(keyword)}`
  915. }
  916. return request({ url })
  917. },
  918. // 搜索资源(按姓名或手机号)
  919. search: (matchmakerId, keyword, gender) => {
  920. let url = `/my-resource/search?matchmakerId=${matchmakerId}`
  921. if (keyword) {
  922. url += `&keyword=${encodeURIComponent(keyword)}`
  923. }
  924. if (gender) {
  925. url += `&gender=${gender}`
  926. }
  927. return request({ url })
  928. },
  929. // 获取资源下拉列表
  930. getDropdown: (matchmakerId, gender) => {
  931. let url = `/my-resource/dropdown?matchmakerId=${matchmakerId}`
  932. if (gender) {
  933. url += `&gender=${gender}`
  934. }
  935. return request({ url })
  936. },
  937. // 获取已注册用户的资源下拉列表(user_id不为空)
  938. getRegisteredDropdown: (matchmakerId, gender) => {
  939. let url = `/my-resource/registered-dropdown?matchmakerId=${matchmakerId}`
  940. if (gender) {
  941. url += `&gender=${gender}`
  942. }
  943. return request({ url })
  944. },
  945. // 搜索已注册用户的资源(user_id不为空)
  946. searchRegistered: (matchmakerId, keyword, gender) => {
  947. let url = `/my-resource/registered-search?matchmakerId=${matchmakerId}`
  948. if (keyword) {
  949. url += `&keyword=${encodeURIComponent(keyword)}`
  950. }
  951. if (gender) {
  952. url += `&gender=${gender}`
  953. }
  954. return request({ url })
  955. }
  956. },
  957. // 撮合成功案例上传相关(通过网关访问1004服务)
  958. successCaseUpload: {
  959. // 提交成功案例
  960. submit: (data) => request({
  961. url: '/success-case-upload/submit',
  962. method: 'POST',
  963. data
  964. }),
  965. // 获取成功案例列表
  966. getList: (matchmakerId, pageNum = 1, pageSize = 10) => request({
  967. url: `/success-case-upload/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  968. }),
  969. // 获取审核记录列表
  970. getAuditRecords: (matchmakerId, auditStatus, pageNum = 1, pageSize = 20) => {
  971. let url = `/success-case-upload/audit-records?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  972. if (auditStatus !== null && auditStatus !== undefined) {
  973. url += `&auditStatus=${auditStatus}`
  974. }
  975. return request({ url })
  976. },
  977. // 获取审核记录详情
  978. getAuditRecordDetail: (id) => request({
  979. url: `/success-case-upload/audit-records/${id}`
  980. }),
  981. // 标记审核记录为已读
  982. markAsRead: (id) => request({
  983. url: `/success-case-upload/audit-records/${id}/read`,
  984. method: 'POST'
  985. }),
  986. // 获取未读审核记录数量
  987. getUnreadCount: (matchmakerId) => request({
  988. url: `/success-case-upload/audit-records/unread-count?matchmakerId=${matchmakerId}`
  989. })
  990. }
  991. }
  992. // 导出 request 函数供其他模块使用
  993. export { request }