api.js 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  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. // 消息相关
  489. message: {
  490. // 获取消息列表
  491. getList: (params) => request({
  492. url: '/message/list',
  493. data: params
  494. }),
  495. // 获取会话列表
  496. getConversations: () => request({
  497. url: '/message/conversations'
  498. }),
  499. // 发送消息
  500. send: (data) => request({
  501. url: '/message/send',
  502. method: 'POST',
  503. data
  504. }),
  505. // ===== 系统消息 =====
  506. getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
  507. const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
  508. // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
  509. return res.data || res
  510. },
  511. getSystemUnreadCount: async (userId) => {
  512. const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
  513. return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
  514. },
  515. markSystemRead: (id) => request({
  516. url: `/message/system/read/${id}`,
  517. method: 'POST'
  518. }),
  519. getSystemDetail: async (id) => {
  520. const res = await request({ url: `/message/system/detail/${id}` })
  521. return res.data || res
  522. },
  523. markAllSystemRead: (userId) => request({
  524. url: `/message/system/read-all?userId=${userId}`,
  525. method: 'POST'
  526. })
  527. },
  528. // 动态相关
  529. dynamic: {
  530. // 获取推荐动态列表(广场)
  531. getRecommendList: (params) => request({
  532. url: '/dynamic/recommend',
  533. data: params
  534. }),
  535. // 获取动态列表
  536. getList: (params) => request({
  537. url: '/dynamic/list',
  538. data: params
  539. }),
  540. // 获取动态详情
  541. getDetail: (dynamicId, userId) => request({
  542. url: `/dynamic/detail/${dynamicId}`,
  543. data: { userId }
  544. }),
  545. // 发表评论
  546. addComment: (dynamicId, content, images, parentCommentId = 0) => request({
  547. url: `/dynamic/comment`,
  548. method: 'POST',
  549. data: { dynamicId, content, images, parentCommentId, userId: 1 },
  550. header: { 'Content-Type': 'application/json' }
  551. }),
  552. // 评论列表
  553. getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
  554. url: `/dynamic/comment/list/${dynamicId}`,
  555. data: { pageNum, pageSize }
  556. }),
  557. // 评论点赞/取消
  558. likeComment: (commentId, userId) => {
  559. // 如果没有传入userId,从本地存储获取
  560. if (!userId) {
  561. const userInfo = uni.getStorageSync('userInfo');
  562. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  563. }
  564. if (!userId) {
  565. return Promise.reject(new Error('用户未登录'));
  566. }
  567. return request({
  568. url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
  569. method: 'POST'
  570. });
  571. },
  572. unlikeComment: (commentId, userId) => {
  573. // 如果没有传入userId,从本地存储获取
  574. if (!userId) {
  575. const userInfo = uni.getStorageSync('userInfo');
  576. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  577. }
  578. if (!userId) {
  579. return Promise.reject(new Error('用户未登录'));
  580. }
  581. return request({
  582. url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
  583. method: 'DELETE'
  584. });
  585. },
  586. // 获取用户动态列表
  587. getUserDynamics: (userId, params) => {
  588. const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
  589. let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
  590. if (currentUserId) {
  591. url += `&currentUserId=${currentUserId}`
  592. }
  593. return request({
  594. url: url,
  595. method: 'GET'
  596. })
  597. },
  598. // 点赞动态
  599. like: (dynamicId, userId) => {
  600. // 如果没有传入userId,从本地存储获取
  601. if (!userId) {
  602. const userInfo = uni.getStorageSync('userInfo');
  603. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  604. }
  605. if (!userId) {
  606. return Promise.reject(new Error('用户未登录'));
  607. }
  608. return request({
  609. url: `/dynamic/like?dynamicId=${dynamicId}&userId=${userId}`,
  610. method: 'POST'
  611. });
  612. },
  613. // 取消点赞
  614. unlike: (dynamicId, userId) => {
  615. // 如果没有传入userId,从本地存储获取
  616. if (!userId) {
  617. const userInfo = uni.getStorageSync('userInfo');
  618. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  619. }
  620. if (!userId) {
  621. return Promise.reject(new Error('用户未登录'));
  622. }
  623. return request({
  624. url: `/dynamic/like/${dynamicId}?userId=${userId}`,
  625. method: 'DELETE'
  626. });
  627. },
  628. // 收藏动态
  629. favorite: (dynamicId, userId) => {
  630. // 如果没有传入userId,从本地存储获取
  631. if (!userId) {
  632. const userInfo = uni.getStorageSync('userInfo');
  633. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  634. }
  635. if (!userId) {
  636. return Promise.reject(new Error('用户未登录'));
  637. }
  638. return request({
  639. url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
  640. method: 'POST'
  641. });
  642. },
  643. // 取消收藏
  644. unfavorite: (dynamicId, userId) => {
  645. // 如果没有传入userId,从本地存储获取
  646. if (!userId) {
  647. const userInfo = uni.getStorageSync('userInfo');
  648. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  649. }
  650. if (!userId) {
  651. return Promise.reject(new Error('用户未登录'));
  652. }
  653. return request({
  654. url: `/dynamic/favorite/${dynamicId}?userId=${userId}`,
  655. method: 'DELETE'
  656. });
  657. },
  658. // 创建个人动态
  659. createUserDynamic: (payload) => request({
  660. url: '/dynamic/user',
  661. method: 'POST',
  662. data: payload,
  663. header: { 'Content-Type': 'application/json' }
  664. }),
  665. // 更新个人动态
  666. updateUserDynamic: (dynamicId, userId, payload) => request({
  667. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  668. method: 'PUT',
  669. data: payload,
  670. header: { 'Content-Type': 'application/json' }
  671. }),
  672. // 删除个人动态
  673. deleteUserDynamic: (dynamicId, userId) => request({
  674. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  675. method: 'DELETE'
  676. }),
  677. // 删除动态(旧接口,保留兼容)
  678. delete: (dynamicId) => request({
  679. url: `/dynamic/${dynamicId}`,
  680. method: 'DELETE'
  681. }),
  682. // 发布动态(文本或已存在的媒体URL列表)
  683. publish: (payload) => request({
  684. url: '/dynamic/publish',
  685. method: 'POST',
  686. data: payload,
  687. header: { 'Content-Type': 'application/json' }
  688. }),
  689. // 单个文件上传方法
  690. uploadSingle: (filePath) => {
  691. return new Promise((resolve, reject) => {
  692. uni.uploadFile({
  693. url: BASE_URL + '/dynamic/publish/upload',
  694. filePath: filePath,
  695. name: 'file',
  696. success: (res) => {
  697. try {
  698. const data = JSON.parse(res.data)
  699. if (data.code === 200 || data.code === 0 || data.success) {
  700. resolve(data.data)
  701. } else {
  702. console.error('上传失败,服务器返回错误:', data)
  703. reject(new Error(data.message || '上传失败'))
  704. }
  705. } catch (e) {
  706. console.error('解析响应数据失败:', e, '原始响应:', res.data)
  707. reject(new Error('解析响应数据失败'))
  708. }
  709. },
  710. fail: (error) => {
  711. console.error('上传请求失败:', error)
  712. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  713. }
  714. })
  715. })
  716. },
  717. // 批量上传多个文件(遍历调用单个上传)
  718. uploadBatch: (filePaths) => {
  719. return new Promise(async (resolve, reject) => {
  720. const urls = []
  721. try {
  722. for (let filePath of filePaths) {
  723. const url = await new Promise((resolveUpload, rejectUpload) => {
  724. uni.uploadFile({
  725. url: BASE_URL + '/dynamic/publish/upload',
  726. filePath: filePath,
  727. name: 'file',
  728. success: (res) => {
  729. try {
  730. const data = JSON.parse(res.data)
  731. if (data.code === 200 || data.code === 0 || data.success) {
  732. resolveUpload(data.data)
  733. } else {
  734. rejectUpload(data)
  735. }
  736. } catch (e) {
  737. rejectUpload(e)
  738. }
  739. },
  740. fail: rejectUpload
  741. })
  742. })
  743. urls.push(url)
  744. }
  745. resolve(urls)
  746. } catch (e) {
  747. reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
  748. }
  749. })
  750. },
  751. // 提交举报
  752. submitReport: (data) => request({
  753. url: '/dynamic/report',
  754. method: 'POST',
  755. data
  756. }),
  757. // 获取用户收藏列表
  758. getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
  759. url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  760. }),
  761. // 获取用户点赞列表
  762. getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
  763. url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  764. }),
  765. // 获取用户浏览记录列表
  766. getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
  767. url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  768. }),
  769. // 清空用户浏览记录
  770. clearBrowseHistory: (userId) => request({
  771. url: `/dynamic/browse-history?userId=${userId}`,
  772. method: 'DELETE'
  773. })
  774. },
  775. // VIP相关
  776. vip: {
  777. // 获取VIP信息(状态、套餐等)
  778. getInfo: (userId) => request({
  779. url: `/vip/info?userId=${userId}`
  780. }),
  781. // 获取VIP套餐列表
  782. getPackages: () => request({
  783. url: '/vip/packages'
  784. }),
  785. // 购买VIP套餐(获取支付参数)
  786. purchase: (userId, packageId) => request({
  787. url: '/vip/purchase',
  788. method: 'POST',
  789. data: { userId, packageId }
  790. }),
  791. // 查询订单状态
  792. getOrderStatus: (orderNo) => request({
  793. url: `/vip/order/status?orderNo=${orderNo}`
  794. }),
  795. // 新增:查询支付状态(userId + packageId)
  796. checkPayStatus: (userId, packageId) => request({
  797. url: '/vip/checkPayStatus',
  798. method: 'GET',
  799. data: { userId, packageId }
  800. })
  801. },
  802. // 用户反馈
  803. feedback: {
  804. // 提交用户反馈
  805. submit: (data) => request({
  806. url: '/feedback/submit',
  807. method: 'POST',
  808. data
  809. }),
  810. // 上传反馈图片
  811. uploadImage: (filePath) => {
  812. return new Promise((resolve, reject) => {
  813. uni.uploadFile({
  814. url: BASE_URL + '/feedback/upload',
  815. filePath: filePath,
  816. name: 'file',
  817. success: (res) => {
  818. try {
  819. const data = JSON.parse(res.data)
  820. if (data.code === 200 || data.code === 0 || data.success) {
  821. resolve(data.data)
  822. } else {
  823. reject(new Error(data.message || '上传失败'))
  824. }
  825. } catch (e) {
  826. reject(new Error('解析响应数据失败'))
  827. }
  828. },
  829. fail: (error) => {
  830. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  831. }
  832. })
  833. })
  834. }
  835. },
  836. // 积分商城相关
  837. pointsMall: {
  838. // 获取商品列表
  839. getProducts: (params) => request({
  840. url: '/points/products',
  841. method: 'GET',
  842. data: params
  843. }),
  844. // 获取推荐商品
  845. getRecommendProducts: (limit = 10) => request({
  846. url: `/points/products/recommend?limit=${limit}`,
  847. method: 'GET'
  848. }),
  849. // 获取商品详情
  850. getProductDetail: (id) => request({
  851. url: `/points/products/${id}`,
  852. method: 'GET'
  853. }),
  854. // 获取积分余额
  855. getBalance: (makerId) => request({
  856. url: `/points/balance?makerId=${makerId}`,
  857. method: 'GET'
  858. }),
  859. // 获取积分明细
  860. getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
  861. url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
  862. method: 'GET'
  863. }),
  864. // 获取积分规则
  865. getRules: () => request({
  866. url: '/points/rules',
  867. method: 'GET'
  868. }),
  869. // 兑换商品
  870. exchange: (data) => request({
  871. url: '/points/exchange',
  872. method: 'POST',
  873. data
  874. }),
  875. // 获取订单列表
  876. getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
  877. let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  878. if (status !== undefined && status !== null) {
  879. url += `&status=${status}`
  880. }
  881. return request({ url, method: 'GET' })
  882. },
  883. // 获取订单详情
  884. getOrderDetail: (orderNo) => request({
  885. url: `/points/orders/${orderNo}`,
  886. method: 'GET'
  887. }),
  888. // 增加积分(签到等)
  889. addPoints: (makerId, ruleType, reason) => request({
  890. url: '/points/add',
  891. method: 'POST',
  892. data: { makerId, ruleType, reason }
  893. })
  894. },
  895. // 我的资源相关(通过网关访问8081服务)
  896. myResource: {
  897. // 获取资源列表
  898. getList: (matchmakerId, keyword, pageNum = 1, pageSize = 10) => {
  899. let url = `/my-resource/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  900. if (keyword) {
  901. url += `&keyword=${encodeURIComponent(keyword)}`
  902. }
  903. return request({ url })
  904. },
  905. // 搜索资源(按姓名或手机号)
  906. search: (matchmakerId, keyword, gender) => {
  907. let url = `/my-resource/search?matchmakerId=${matchmakerId}`
  908. if (keyword) {
  909. url += `&keyword=${encodeURIComponent(keyword)}`
  910. }
  911. if (gender) {
  912. url += `&gender=${gender}`
  913. }
  914. return request({ url })
  915. },
  916. // 获取资源下拉列表
  917. getDropdown: (matchmakerId, gender) => {
  918. let url = `/my-resource/dropdown?matchmakerId=${matchmakerId}`
  919. if (gender) {
  920. url += `&gender=${gender}`
  921. }
  922. return request({ url })
  923. },
  924. // 获取已注册用户的资源下拉列表(user_id不为空)
  925. getRegisteredDropdown: (matchmakerId, gender) => {
  926. let url = `/my-resource/registered-dropdown?matchmakerId=${matchmakerId}`
  927. if (gender) {
  928. url += `&gender=${gender}`
  929. }
  930. return request({ url })
  931. },
  932. // 搜索已注册用户的资源(user_id不为空)
  933. searchRegistered: (matchmakerId, keyword, gender) => {
  934. let url = `/my-resource/registered-search?matchmakerId=${matchmakerId}`
  935. if (keyword) {
  936. url += `&keyword=${encodeURIComponent(keyword)}`
  937. }
  938. if (gender) {
  939. url += `&gender=${gender}`
  940. }
  941. return request({ url })
  942. }
  943. },
  944. // 撮合成功案例上传相关(通过网关访问1004服务)
  945. successCaseUpload: {
  946. // 提交成功案例
  947. submit: (data) => request({
  948. url: '/success-case-upload/submit',
  949. method: 'POST',
  950. data
  951. }),
  952. // 获取成功案例列表
  953. getList: (matchmakerId, pageNum = 1, pageSize = 10) => request({
  954. url: `/success-case-upload/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  955. }),
  956. // 获取审核记录列表
  957. getAuditRecords: (matchmakerId, auditStatus, pageNum = 1, pageSize = 20) => {
  958. let url = `/success-case-upload/audit-records?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  959. if (auditStatus !== null && auditStatus !== undefined) {
  960. url += `&auditStatus=${auditStatus}`
  961. }
  962. return request({ url })
  963. },
  964. // 获取审核记录详情
  965. getAuditRecordDetail: (id) => request({
  966. url: `/success-case-upload/audit-records/${id}`
  967. }),
  968. // 标记审核记录为已读
  969. markAsRead: (id) => request({
  970. url: `/success-case-upload/audit-records/${id}/read`,
  971. method: 'POST'
  972. }),
  973. // 获取未读审核记录数量
  974. getUnreadCount: (matchmakerId) => request({
  975. url: `/success-case-upload/audit-records/unread-count?matchmakerId=${matchmakerId}`
  976. })
  977. }
  978. }
  979. // 导出 request 函数供其他模块使用
  980. export { request }